diff options
author | Philipp Tomsich <philipp.tomsich@theobroma-systems.com> | 2017-08-23 20:29:24 +0200 |
---|---|---|
committer | Philipp Tomsich <philipp.tomsich@theobroma-systems.com> | 2017-08-23 20:29:24 +0200 |
commit | 8912bd593db027797f77cd8d40e6deaa4d520442 (patch) | |
tree | 6de6c57164414ee08b6c7b211d121161bf3c388c |
-rwxr-xr-x | Android.mk | 51 | ||||
-rwxr-xr-x | iep.h | 210 | ||||
-rwxr-xr-x | iep_api.cpp | 1524 | ||||
-rwxr-xr-x | iep_api.h | 199 | ||||
-rwxr-xr-x | iep_func_test.cpp | 655 |
5 files changed, 2639 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk new file mode 100755 index 0000000..843064f --- /dev/null +++ b/Android.mk @@ -0,0 +1,51 @@ +LOCAL_PATH := $(call my-dir) + +# +# libiep.so +# +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + iep_api.cpp + +LOCAL_CFLAGS := \ + $(CFLAGS) \ + -Wall \ + -Wextra \ + -DLOG_TAG=\"libiep\" + +LOCAL_C_INCLUDES += $(TOP)/hardware/libhardware/include +LOCAL_LDFLAGS := \ + -Wl,-z,defs + +LOCAL_SHARED_LIBRARIES := \ + libcutils + +LOCAL_MODULE := libiep +LOCAL_MODULE_TAGS := optional +LOCAL_PRELINK_MODULE := false + +include $(BUILD_SHARED_LIBRARY) + +# +# iep_func_test +# +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + iep_func_test.cpp + +#LOCAL_C_INCLUDES += kernel/include + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libiep \ + libvpu + +#LOCAL_LDLIBS += -lpthread + +LOCAL_MODULE := iep_func_test +LOCAL_MODULE_TAGS := optional tests +LOCAL_PRELINK_MODULE := false + +#include $(BUILD_EXECUTABLE) @@ -0,0 +1,210 @@ +#ifndef _IEP_H_ +#define _IEP_H_ + +#include <sys/ioctl.h> + +/* Capability for current iep version +using by userspace to determine iep features */ +struct IEP_CAP { + uint8_t scaling_supported; + uint8_t i4_deinterlace_supported; + uint8_t i2_deinterlace_supported; + uint8_t compression_noise_reduction_supported; + uint8_t sampling_noise_reduction_supported; + uint8_t hsb_enhancement_supported; + uint8_t cg_enhancement_supported; + uint8_t direct_path_supported; + uint16_t max_dynamic_width; + uint16_t max_dynamic_height; + uint16_t max_static_width; + uint16_t max_static_height; + uint8_t max_enhance_radius; +}; + +#define IEP_IOC_MAGIC 'i' + +#define IEP_SET_PARAMETER_REQ _IOW(IEP_IOC_MAGIC, 1, unsigned long) +#define IEP_SET_PARAMETER_DEINTERLACE _IOW(IEP_IOC_MAGIC, 2, unsigned long) +#define IEP_SET_PARAMETER_ENHANCE _IOW(IEP_IOC_MAGIC, 3, unsigned long) +#define IEP_SET_PARAMETER_CONVERT _IOW(IEP_IOC_MAGIC, 4, unsigned long) +#define IEP_SET_PARAMETER_SCALE _IOW(IEP_IOC_MAGIC, 5, unsigned long) +#define IEP_GET_RESULT_SYNC _IOW(IEP_IOC_MAGIC, 6, unsigned long) +#define IEP_GET_RESULT_ASYNC _IOW(IEP_IOC_MAGIC, 7, unsigned long) +#define IEP_SET_PARAMETER _IOW(IEP_IOC_MAGIC, 8, unsigned long) +#define IEP_RELEASE_CURRENT_TASK _IOW(IEP_IOC_MAGIC, 9, unsigned long) +#define IEP_GET_IOMMU_STATE _IOR(IEP_IOC_MAGIC,10, unsigned long) +#define IEP_QUERY_CAP _IOR(IEP_IOC_MAGIC, 11, struct IEP_CAP) + +enum { + yuv2rgb_BT_601_l = 0x0, /* BT.601_1 */ + yuv2rgb_BT_601_f = 0x1, /* BT.601_f */ + yuv2rgb_BT_709_l = 0x2, /* BT.709_1 */ + yuv2rgb_BT_709_f = 0x3, /* BT.709_f */ +}; + +enum +{ + rgb2yuv_BT_601_l = 0x0, /* BT.601_1 */ + rgb2yuv_BT_601_f = 0x1, /* BT.601_f */ + rgb2yuv_BT_709_l = 0x2, /* BT.709_1 */ + rgb2yuv_BT_709_f = 0x3, /* BT.709_f */ +}; + +enum { + dein_mode_bypass_dis = 0x0, + dein_mode_I4O2 = 0x1, + dein_mode_I4O1B = 0x2, + dein_mode_I4O1T = 0x3, + dein_mode_I2O1B = 0x4, + dein_mode_I2O1T = 0x5, + dein_mode_bypass = 0x6, +}; + +enum { + rgb_enhance_bypass = 0x0, + rgb_enhance_denoise = 0x1, + rgb_enhance_detail = 0x2, + rgb_enhance_edge = 0x3, +};//for rgb_enhance_mode + +enum +{ + rgb_contrast_CC_P_DDE = 0x0, //cg prior to dde + rgb_contrast_DDE_P_CC = 0x1, //dde prior to cg +}; //for rgb_contrast_enhance_mode + +enum { + black_screen = 0x0, + blue_screen = 0x1, + color_bar = 0x2, + normal_mode = 0x3, +}; //for video mode + +/* +// Alpha Red Green Blue +{ 4, 32, {{32,24, 24,16, 16, 8, 8, 0 }}, GGL_RGBA }, // IEP_FORMAT_ARGB_8888 +{ 4, 32, {{32,24, 8, 0, 16, 8, 24,16 }}, GGL_RGB }, // IEP_FORMAT_ABGR_8888 +{ 4, 32, {{ 8, 0, 32,24, 24,16, 16, 8 }}, GGL_RGB }, // IEP_FORMAT_RGBA_8888 +{ 4, 32, {{ 8, 0, 16, 8, 24,16, 32,24 }}, GGL_BGRA }, // IEP_FORMAT_BGRA_8888 +{ 2, 16, {{ 0, 0, 16,11, 11, 5, 5, 0 }}, GGL_RGB }, // IEP_FORMAT_RGB_565 +{ 2, 16, {{ 0, 0, 5, 0, 11, 5, 16,11 }}, GGL_RGB }, // IEP_FORMAT_RGB_565 +*/ +enum { + IEP_FORMAT_ARGB_8888 = 0x0, + IEP_FORMAT_ABGR_8888 = 0x1, + IEP_FORMAT_RGBA_8888 = 0x2, + IEP_FORMAT_BGRA_8888 = 0x3, + IEP_FORMAT_RGB_565 = 0x4, + IEP_FORMAT_BGR_565 = 0x5, + + IEP_FORMAT_YCbCr_422_SP = 0x10, + IEP_FORMAT_YCbCr_422_P = 0x11, + IEP_FORMAT_YCbCr_420_SP = 0x12, + IEP_FORMAT_YCbCr_420_P = 0x13, + IEP_FORMAT_YCrCb_422_SP = 0x14, + IEP_FORMAT_YCrCb_422_P = 0x15,//same as IEP_FORMAT_YCbCr_422_P + IEP_FORMAT_YCrCb_420_SP = 0x16, + IEP_FORMAT_YCrCb_420_P = 0x17,//same as IEP_FORMAT_YCbCr_420_P +}; //for format + +typedef struct iep_img { + uint16_t act_w; // act_width + uint16_t act_h; // act_height + int16_t x_off; // x offset for the vir,word unit + int16_t y_off; // y offset for the vir,word unit + + uint16_t vir_w; //unit :pix + uint16_t vir_h; //unit :pix + uint32_t format; + uint32_t mem_addr; + uint32_t uv_addr; + uint32_t v_addr; + + uint8_t rb_swap;//not be used + uint8_t uv_swap;//not be used + + uint8_t alpha_swap;//not be used +} iep_img; + + +typedef struct IEP_MSG { + iep_img src; // src active window + iep_img dst; // src virtual window + + iep_img src1; + iep_img dst1; + + iep_img src_itemp; + iep_img src_ftemp; + + iep_img dst_itemp; + iep_img dst_ftemp; + + uint8_t dither_up_en; + uint8_t dither_down_en;//not to be used + + uint8_t yuv2rgb_mode; + uint8_t rgb2yuv_mode; + + uint8_t global_alpha_value; + + uint8_t rgb2yuv_clip_en; + uint8_t yuv2rgb_clip_en; + + uint8_t lcdc_path_en; + int32_t off_x; + int32_t off_y; + int32_t width; + int32_t height; + int32_t layer; + + uint8_t yuv_3D_denoise_en; + + /// yuv color enhance + uint8_t yuv_enhance_en; + int32_t sat_con_int; + int32_t contrast_int; + int32_t cos_hue_int; + int32_t sin_hue_int; + int8_t yuv_enh_brightness;//-32<brightness<31 + uint8_t video_mode;//0-3 + uint8_t color_bar_y;//0-127 + uint8_t color_bar_u;//0-127 + uint8_t color_bar_v;//0-127 + + + uint8_t rgb_enhance_en;//i don't konw what is used + + uint8_t rgb_color_enhance_en;//sw_rgb_color_enh_en + uint32_t rgb_enh_coe; + + uint8_t rgb_enhance_mode;//sw_rgb_enh_sel,dde sel + + uint8_t rgb_cg_en;//sw_rgb_con_gam_en + uint32_t cg_tab[192]; + + uint8_t rgb_contrast_enhance_mode;//sw_con_gam_order;0 cg prior to dde,1 dde prior to cg + + int32_t enh_threshold; + int32_t enh_alpha; + int32_t enh_radius; + + uint8_t scale_up_mode; + + uint8_t field_order; + uint8_t dein_mode; + //DIL HF + uint8_t dein_high_fre_en; + uint8_t dein_high_fre_fct; + //DIL EI + uint8_t dein_ei_mode; + uint8_t dein_ei_smooth; + uint8_t dein_ei_sel; + uint8_t dein_ei_radius;//when dein_ei_sel=0 will be used + + uint8_t vir_addr_enable; + + void *base; +} IEP_MSG; + +#endif diff --git a/iep_api.cpp b/iep_api.cpp new file mode 100755 index 0000000..7100950 --- /dev/null +++ b/iep_api.cpp @@ -0,0 +1,1524 @@ +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <memory.h> +#include <unistd.h> +#include <signal.h> +#include <pthread.h> +#include <cutils/properties.h> +#include "cutils/log.h" +#include "iep_api.h" +#include "rga.h" + +#define PI (3.1415926) + +#define X (-1) +static int enh_alpha_table[][25] = { + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 + /*0*/ {X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X }, + /*1*/ {0, 8, 12, 16, 20, 24, 28, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X }, + /*2*/ {0, 4, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, X, X, X, X, X, X, X, X, X, X, X, X }, + /*3*/ {0, X, X, 8, X, X, 12, X, X, 16, X, X, 20, X, X, 24, X, X, 28, X, X, X, X, X, X }, + /*4*/ {0, 2, 4, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 }, + /*5*/ {0, X, X, X, X, 8, X, X, X, X, 12, X, X, X, X, 16, X, X, X, X, 20, X, X, X, X }, + /*6*/ {0, X, X, 4, X, X, 8, X, X, 10, X, X, 12, X, X, 14, X, X, 16, X, X, 18, X, X, 20 }, + /*7*/ {0, X, X, X, X, X, X, 8, X, X, X, X, X, X, 12, X, X, X, X, X, X, 16, X, X, X }, + /*8*/ {0, 1, 2, 3, 4, 5, 6, 7, 8, X, 9, X, 10, X, 11, X, 12, X, 13, X, 14, X, 15, X, 16 } +}; + +// rr = 1.7 rg = 1 rb = 0.6 +static unsigned int cg_tab[] = +{ +0x01010100, 0x03020202, 0x04030303, 0x05040404, +0x05050505, 0x06060606, 0x07070606, 0x07070707, +0x08080807, 0x09080808, 0x09090909, 0x0a090909, +0x0a0a0a0a, 0x0b0a0a0a, 0x0b0b0b0b, 0x0c0b0b0b, +0x0c0c0c0c, 0x0c0c0c0c, 0x0d0d0d0d, 0x0d0d0d0d, +0x0e0e0d0d, 0x0e0e0e0e, 0x0e0e0e0e, 0x0f0f0f0f, +0x0f0f0f0f, 0x10100f0f, 0x10101010, 0x10101010, +0x11111110, 0x11111111, 0x11111111, 0x12121212, +0x12121212, 0x12121212, 0x13131313, 0x13131313, +0x13131313, 0x14141414, 0x14141414, 0x14141414, +0x15151515, 0x15151515, 0x15151515, 0x16161615, +0x16161616, 0x16161616, 0x17161616, 0x17171717, +0x17171717, 0x17171717, 0x18181818, 0x18181818, +0x18181818, 0x19191818, 0x19191919, 0x19191919, +0x19191919, 0x1a1a1a19, 0x1a1a1a1a, 0x1a1a1a1a, +0x1a1a1a1a, 0x1b1b1b1b, 0x1b1b1b1b, 0x1b1b1b1b, +0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c, +0x13121110, 0x17161514, 0x1b1a1918, 0x1f1e1d1c, +0x23222120, 0x27262524, 0x2b2a2928, 0x2f2e2d2c, +0x33323130, 0x37363534, 0x3b3a3938, 0x3f3e3d3c, +0x43424140, 0x47464544, 0x4b4a4948, 0x4f4e4d4c, +0x53525150, 0x57565554, 0x5b5a5958, 0x5f5e5d5c, +0x63626160, 0x67666564, 0x6b6a6968, 0x6f6e6d6c, +0x73727170, 0x77767574, 0x7b7a7978, 0x7f7e7d7c, +0x83828180, 0x87868584, 0x8b8a8988, 0x8f8e8d8c, +0x93929190, 0x97969594, 0x9b9a9998, 0x9f9e9d9c, +0xa3a2a1a0, 0xa7a6a5a4, 0xabaaa9a8, 0xafaeadac, +0xb3b2b1b0, 0xb7b6b5b4, 0xbbbab9b8, 0xbfbebdbc, +0xc3c2c1c0, 0xc7c6c5c4, 0xcbcac9c8, 0xcfcecdcc, +0xd3d2d1d0, 0xd7d6d5d4, 0xdbdad9d8, 0xdfdedddc, +0xe3e2e1e0, 0xe7e6e5e4, 0xebeae9e8, 0xefeeedec, +0xf3f2f1f0, 0xf7f6f5f4, 0xfbfaf9f8, 0xfffefdfc, +0x06030100, 0x1b150f0a, 0x3a322922, 0x63584e44, +0x95887b6f, 0xcebfb0a2, 0xfffeedde, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, +0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff +}; + +#define IEP_DEB(fmt, args...) do { \ + if (g_log_level > 0) { \ + ALOGD(__FILE__ ",%s,:%d: " fmt, __func__, __LINE__, ## args); \ + } \ + } while (0) + +#define IEP_ERR(fmt, args...) ALOGE(__FILE__ ",%s,:%d: " fmt, __func__, __LINE__, ## args) + +class iep_api : public iep_interface { +private: + IEP_MSG *msg; + int fd; + pthread_t td_notify; + iep_notify notify; + int pid; + int rga_fd; + int iommu; + +public: + iep_api(); + ~iep_api(); + + virtual int init(iep_img *src, iep_img *dst); + virtual int config_src_dst(iep_img *src, iep_img *dst); + virtual int config_yuv_enh(); + virtual int config_yuv_enh(iep_param_YUV_color_enhance_t *yuv_enh); + virtual int config_color_enh(); + virtual int config_color_enh(iep_param_RGB_color_enhance_t *rgb_enh); + virtual int config_scale(); + virtual int config_scale(iep_param_scale *scale); + virtual int config_yuv_denoise(); + virtual int config_yuv_denoise(iep_img *src_itemp, iep_img *src_ftemp, + iep_img *dst_itemp, iep_img *dst_ftemp); + virtual int config_yuv_deinterlace(); + virtual int config_yuv_deinterlace(iep_param_yuv_deinterlace_t *yuv_dil); + virtual int config_yuv_dil_src_dst(iep_img *src1, iep_img *dst1); + virtual int config_yuv_deinterlace(iep_param_yuv_deinterlace_t *yuv_dil, + iep_img *src1, iep_img *dst1); + virtual int config_color_space_convertion(); + virtual int config_color_space_convertion( + iep_param_color_space_convertion_t *clr_convert); + virtual int config_direct_lcdc_path( + iep_param_direct_path_interface_t *dpi); + virtual int run_sync(); + virtual int run_async(iep_notify notify); + virtual int poll(); + virtual struct IEP_CAP* query(); + virtual IEP_QUERY_INTERLACE query_interlace(); + virtual IEP_QUERY_DIMENSION query_dimension(); + +private: + static void* notify_func(void *param); + + int yuv_enh_sanity_check(iep_param_YUV_color_enhance_t *yuv_enh); + int rgb_enh_sanity_check(iep_param_RGB_color_enhance_t *rgb_enh); + int direct_lcdc_path_sanity_check(iep_param_direct_path_interface_t *dpi); + int yuv_denoise_sanity_check(iep_img *src_itemp, iep_img *src_ftemp, iep_img *dst_itemp, iep_img *dst_ftemp); + int dil_src_dst_sanity_check(iep_img *src1, iep_img *dst1); + int deinterlace_sanity_check(iep_param_yuv_deinterlace_t *yuv_dil, iep_img *src1, iep_img *dst1); + int color_space_convertion_sanity_check(iep_param_color_space_convertion_t *clr_convert); + int init_sanity_check(iep_img *src, iep_img *dst); + void recover_image(struct rga_req *req, iep_img *dst); + void recover_image1(struct rga_req *req); +}; + +static int g_mode = 0; +static int g_log_level = 0; +static pthread_once_t g_get_env_value_once = PTHREAD_ONCE_INIT; +static struct IEP_CAP cap; + +static void get_env_value() +{ + char prop_value[PROPERTY_VALUE_MAX]; + + if (property_get("iep.mode.control", prop_value, NULL)) + g_mode = atoi(prop_value); + + if (property_get("iep.log_level.control", prop_value, NULL)) + g_log_level = atoi(prop_value); +} + +iep_api::iep_api() : rga_fd(-1) +{ + //pthread_once(&g_get_env_value_once, get_env_value); + get_env_value(); + + ALOGD("g_mode %d, g_log_level %d\n", g_mode, g_log_level); + + msg = new IEP_MSG(); + if (msg == NULL) { + IEP_ERR("memory allocated failed\n"); + abort(); + } + + memset(msg, 0, sizeof(IEP_MSG)); + + fd = open("/dev/iep", O_RDWR); + if (fd < 0) { + IEP_ERR("file open failed\n"); + abort(); + } + pid = getpid(); + + IEP_DEB("query capabilities\n"); + if (0 > ioctl(fd, IEP_QUERY_CAP, &cap)) { + IEP_DEB("Query IEP capability failed, using default cap\n"); + cap.scaling_supported = 0; + cap.i4_deinterlace_supported = 1; + cap.i2_deinterlace_supported = 1; + cap.compression_noise_reduction_supported = 1; + cap.sampling_noise_reduction_supported = 1; + cap.hsb_enhancement_supported = 1; + cap.cg_enhancement_supported = 1; + cap.direct_path_supported = 1; + cap.max_dynamic_width = 1920; + cap.max_dynamic_height = 1088; + cap.max_static_width = 8192; + cap.max_static_height = 8192; + cap.max_enhance_radius = 3; + } + + iommu = 0; + if (0 > ioctl(fd, IEP_GET_IOMMU_STATE, &iommu)) { + IEP_DEB("Get iommu state failed, mismatch library and driver, disable contrast mode\n"); + g_mode = 0; + } + + if (g_mode) { + rga_fd = open("/dev/rga", O_RDWR); + if (rga_fd < 0) { + IEP_ERR("rga device open failed\n"); + abort(); + } + } +} + +iep_api::~iep_api() +{ + if (msg->lcdc_path_en) { + iep_param_direct_path_interface_t dpi; + dpi.enable = 0; + config_direct_lcdc_path(&dpi); + run_sync(); + } + + if (fd > 0) { + close(fd); + } + + if (rga_fd > 0) { + close(rga_fd); + } + + if (msg) { + delete msg; + } +} + +int iep_api::config_yuv_enh() +{ + msg->yuv_enhance_en = 1; + + msg->sat_con_int = 0x80; + msg->contrast_int = 0x80; + // hue_angle = 0 + msg->cos_hue_int = 0x00; + msg->sin_hue_int = 0x80; + + msg->yuv_enh_brightness = 0x00; + + msg->video_mode = IEP_VIDEO_MODE_NORMAL_VIDEO; + + msg->color_bar_u = 0; + msg->color_bar_v = 0; + msg->color_bar_y = 0; + + return 0; +} + +int iep_api::config_yuv_enh(iep_param_YUV_color_enhance_t *yuv_enh) +{ + do { + if (0 > yuv_enh_sanity_check(yuv_enh)) { + break; + } + + msg->yuv_enhance_en = 1; + + msg->sat_con_int = + (int)(yuv_enh->yuv_enh_saturation * + yuv_enh->yuv_enh_contrast * 128); + msg->contrast_int = + (int)(yuv_enh->yuv_enh_contrast * 128); + msg->cos_hue_int = + (int)(cos(yuv_enh->yuv_enh_hue_angle) * 128.0); + msg->sin_hue_int = + (int)(sin(yuv_enh->yuv_enh_hue_angle) * 128.0); + msg->yuv_enh_brightness = + yuv_enh->yuv_enh_brightness >= 0 ? + yuv_enh->yuv_enh_brightness : (yuv_enh->yuv_enh_brightness + 64); + + msg->video_mode = yuv_enh->video_mode; + msg->color_bar_y = yuv_enh->color_bar_y; + msg->color_bar_u = yuv_enh->color_bar_u; + msg->color_bar_v = yuv_enh->color_bar_v; + + return 0; + } + while (0); + + return -1; +} + +int iep_api::config_color_enh() +{ + //int i; + + msg->rgb_color_enhance_en = 1; + + msg->rgb_enh_coe = 32; + msg->rgb_contrast_enhance_mode = IEP_RGB_COLOR_ENHANCE_MODE_DETAIL_ENHANCE; + msg->rgb_cg_en = 0; + msg->enh_threshold = 255; + msg->enh_alpha = 8; + msg->enh_radius = 3; + + /*for (i=0; i<sizeof(cg_tab)/sizeof(unsigned int); i++) { + msg->cg_tab[i] = cg_tab[i]; + }*/ + + return 0; +} + +int iep_api::config_color_enh(iep_param_RGB_color_enhance_t *rgb_enh) +{ + do { + int i; + unsigned int rgb_0, rgb_1, rgb_2, rgb_3; + unsigned int cg_0, cg_1, cg_2, cg_3; + unsigned int tab_0, tab_1, tab_2, tab_3; + unsigned int conf_value; + + if (0 > rgb_enh_sanity_check(rgb_enh)) { + break; + } + + msg->rgb_color_enhance_en = 1; + msg->rgb_enh_coe = (unsigned int)(rgb_enh->rgb_enh_coe * 32); + msg->rgb_contrast_enhance_mode = rgb_enh->rgb_contrast_enhance_mode; + msg->rgb_cg_en = rgb_enh->rgb_cg_en; + msg->rgb_enhance_mode = rgb_enh->rgb_enhance_mode; + + msg->enh_threshold = rgb_enh->enh_threshold; + msg->enh_alpha = + enh_alpha_table[rgb_enh->enh_alpha_base][rgb_enh->enh_alpha_num]; + msg->enh_radius = rgb_enh->enh_radius - 1; + + if (rgb_enh->rgb_cg_en) { + //for b + for (i = 0; i < 64; i++) { + rgb_0 = 4 * i; + rgb_1 = 4 * i + 1; + rgb_2 = 4 * i + 2; + rgb_3 = 4 * i + 3; + + /// need modify later + cg_0 = pow(rgb_0, rgb_enh->cg_rb); + cg_1 = pow(rgb_1, rgb_enh->cg_rb); + cg_2 = pow(rgb_2, rgb_enh->cg_rb); + cg_3 = pow(rgb_3, rgb_enh->cg_rb); + + if (cg_0 > 255) cg_0 = 255; + if (cg_1 > 255) cg_1 = 255; + if (cg_2 > 255) cg_2 = 255; + if (cg_3 > 255) cg_3 = 255; + + tab_0 = (unsigned int)cg_0; + tab_1 = (unsigned int)cg_1; + tab_2 = (unsigned int)cg_2; + tab_3 = (unsigned int)cg_3; + + conf_value = + (tab_3 << 24) + (tab_2 << 16) + (tab_1 << 8) + tab_0; + msg->cg_tab[i] = conf_value; + } + + //for g + for (i = 0; i < 64; i++) { + rgb_0 = 4 * i; + rgb_1 = 4 * i + 1; + rgb_2 = 4 * i + 2; + rgb_3 = 4 * i + 3; + + /// need to modify later + cg_0 = pow(rgb_0, rgb_enh->cg_rg); + cg_1 = pow(rgb_1, rgb_enh->cg_rg); + cg_2 = pow(rgb_2, rgb_enh->cg_rg); + cg_3 = pow(rgb_3, rgb_enh->cg_rg); + + if (cg_0 > 255) cg_0 = 255; + if (cg_1 > 255) cg_1 = 255; + if (cg_2 > 255) cg_2 = 255; + if (cg_3 > 255) cg_3 = 255; + + tab_0 = (unsigned int)cg_0; + tab_1 = (unsigned int)cg_1; + tab_2 = (unsigned int)cg_2; + tab_3 = (unsigned int)cg_3; + + conf_value = + (tab_3 << 24) + (tab_2 << 16) + (tab_1 << 8) + tab_0; + msg->cg_tab[64+i] = conf_value; + } + + //for r + for (i = 0; i <= 63; i = i + 1) { + rgb_0 = 4 * i; + rgb_1 = 4 * i + 1; + rgb_2 = 4 * i + 2; + rgb_3 = 4 * i + 3; + + // need to modify later + cg_0 = pow(rgb_0, rgb_enh->cg_rr); + cg_1 = pow(rgb_1, rgb_enh->cg_rr); + cg_2 = pow(rgb_2, rgb_enh->cg_rr); + cg_3 = pow(rgb_3, rgb_enh->cg_rr); + + if (cg_0 > 255) cg_0 = 255; + if (cg_1 > 255) cg_1 = 255; + if (cg_2 > 255) cg_2 = 255; + if (cg_3 > 255) cg_3 = 255; + + tab_0 = (unsigned int)cg_0; + tab_1 = (unsigned int)cg_1; + tab_2 = (unsigned int)cg_2; + tab_3 = (unsigned int)cg_3; + + conf_value = + (tab_3 << 24) + (tab_2 << 16) + (tab_1 << 8) + tab_0; + msg->cg_tab[2*64+i] = conf_value; + } + } + + return 0; + } + while (0); + + return -1; +} + +int iep_api::config_scale() +{ + msg->scale_up_mode = IEP_SCALE_UP_MODE_CATROM; + + return 0; +} + +int iep_api::config_scale(iep_param_scale *scale) +{ + do { + if (scale == NULL) { + IEP_ERR("Invalidate parameter!\n"); + break; + } + + msg->scale_up_mode = scale->scale_up_mode; + + return 0; + } + while (0); + + return -1; +} + +int iep_api::config_yuv_denoise() +{ + /*do { + msg->yuv_3D_denoise_en = 1; + + return 0; + } + while (0);*/ + IEP_ERR("NOT available in this version\n"); + + return -1; +} + +int iep_api::config_yuv_denoise(iep_img *src_itemp, iep_img *src_ftemp, + iep_img *dst_itemp, iep_img *dst_ftemp) +{ + do { + if (0 > yuv_denoise_sanity_check(src_itemp, src_ftemp, + dst_itemp, dst_ftemp)) { + break; + } + + memcpy(&msg->src_itemp, src_itemp, sizeof(iep_img)); + memcpy(&msg->src_ftemp, src_ftemp, sizeof(iep_img)); + memcpy(&msg->dst_itemp, dst_itemp, sizeof(iep_img)); + memcpy(&msg->dst_ftemp, dst_ftemp, sizeof(iep_img)); + + if (g_mode) { + msg->src_itemp.act_w /= 2; + msg->src_ftemp.act_w /= 2; + msg->dst_itemp.act_w /= 2; + msg->dst_ftemp.act_w /= 2; + msg->src_itemp.x_off = msg->src_itemp.act_w; + msg->src_ftemp.x_off = msg->src_ftemp.act_w; + msg->dst_itemp.x_off = msg->dst_itemp.act_w; + msg->dst_ftemp.x_off = msg->dst_ftemp.act_w; + } + + msg->yuv_3D_denoise_en = 1; + + return 0; + } while (0); + + return -1; +} + +int iep_api::config_yuv_deinterlace() +{ + msg->dein_high_fre_en = 0; + msg->dein_mode = IEP_DEINTERLACE_MODE_I2O1; + msg->field_order = FIELD_ORDER_BOTTOM_FIRST; + msg->dein_ei_mode = 0; + msg->dein_ei_sel = 0; + msg->dein_ei_radius = 0; + msg->dein_ei_smooth = 0; + msg->dein_high_fre_fct = 0; + + return 0; +} + +int iep_api::config_yuv_deinterlace(iep_param_yuv_deinterlace_t *yuv_dil) +{ + do { + if (yuv_dil == NULL) { + break; + } + + msg->dein_high_fre_en = yuv_dil->high_freq_en; + msg->dein_mode = yuv_dil->dil_mode; + msg->field_order = yuv_dil->field_order; + msg->dein_ei_mode = yuv_dil->dil_ei_mode; + msg->dein_ei_sel = yuv_dil->dil_ei_sel; + msg->dein_ei_radius = yuv_dil->dil_ei_radius; + msg->dein_ei_smooth = yuv_dil->dil_ei_smooth; + msg->dein_high_fre_fct = yuv_dil->dil_high_freq_fct; + + return 0; + } + while (0); + + return -1; +} + +int iep_api::config_yuv_dil_src_dst(iep_img *src1, iep_img *dst1) +{ + do { + if (0 > dil_src_dst_sanity_check(src1, dst1)) { + break; + } + + if (src1 != NULL) { + memcpy(&msg->src1, src1, sizeof(iep_img)); + } + + if (dst1 != NULL) { + memcpy(&msg->dst1, dst1, sizeof(iep_img)); + } + + if (g_mode) { + msg->src1.act_w /= 2; + msg->dst1.act_w /= 2; + msg->src1.x_off = msg->src1.act_w; + msg->dst1.x_off = msg->dst1.act_w; + } + + return 0; + } + while (0); + + return -1; +} + +int iep_api::config_yuv_deinterlace(iep_param_yuv_deinterlace_t *yuv_dil, + iep_img *src1, iep_img *dst1) +{ + do { + if (0 > deinterlace_sanity_check(yuv_dil, src1, dst1)) { + break; + } + + msg->dein_high_fre_en = yuv_dil->high_freq_en; + msg->dein_mode = yuv_dil->dil_mode; + msg->field_order = yuv_dil->field_order; + msg->dein_ei_mode = yuv_dil->dil_ei_mode; + msg->dein_ei_sel = yuv_dil->dil_ei_sel; + msg->dein_ei_radius = yuv_dil->dil_ei_radius; + msg->dein_ei_smooth = yuv_dil->dil_ei_smooth; + msg->dein_high_fre_fct = yuv_dil->dil_high_freq_fct; + + if (src1 != NULL) { + memcpy(&msg->src1, src1, sizeof(iep_img)); + } + + if (dst1 != NULL) { + memcpy(&msg->dst1, dst1, sizeof(iep_img)); + } + + if (g_mode) { + msg->src1.act_w /= 2; + msg->dst1.act_w /= 2; + msg->src1.x_off = msg->src1.act_w; + msg->dst1.x_off = msg->dst1.act_w; + } + + return 0; + } + while (0); + + return -1; +} + +int iep_api::config_color_space_convertion() +{ + msg->rgb2yuv_mode = IEP_COLOR_CONVERT_MODE_BT601_L; + msg->yuv2rgb_mode = IEP_COLOR_CONVERT_MODE_BT601_L; + + msg->rgb2yuv_clip_en = 0; + msg->yuv2rgb_clip_en = 0; + + msg->global_alpha_value = 0; + + msg->dither_up_en = 1; + msg->dither_down_en = 1; + + return 0; +} + +int iep_api::config_color_space_convertion( + iep_param_color_space_convertion_t *clr_convert) +{ + do { + if (0 > color_space_convertion_sanity_check(clr_convert)) { + break; + } + + msg->rgb2yuv_mode = clr_convert->rgb2yuv_mode; + msg->yuv2rgb_mode = clr_convert->yuv2rgb_mode; + msg->rgb2yuv_clip_en = clr_convert->rgb2yuv_input_clip; + msg->yuv2rgb_clip_en = clr_convert->yuv2rgb_input_clip; + msg->global_alpha_value = clr_convert->global_alpha_value; + msg->dither_up_en = clr_convert->dither_up_en; + msg->dither_down_en = clr_convert->dither_down_en; + + return 0; + } + while (0); + + return -1; +} + +int iep_api::config_direct_lcdc_path(iep_param_direct_path_interface_t *dpi) +{ + do { + if (0 > direct_lcdc_path_sanity_check(dpi)) { + break; + } + + msg->lcdc_path_en = dpi->enable; + msg->off_x = dpi->off_x; + msg->off_y = dpi->off_y; + msg->width = dpi->width; + msg->height = dpi->height; + msg->layer = dpi->layer; + + return 0; + } + while (0); + + return -1; +} + +int iep_api::config_src_dst(iep_img *src, iep_img *dst) +{ + do { + if (0 > init_sanity_check(src, dst)) { + break; + } + + memcpy(&msg->src, src, sizeof(iep_img)); + memcpy(&msg->dst, dst, sizeof(iep_img)); + + if (g_mode) { + msg->src.act_w /= 2; + msg->src.x_off = msg->src.act_w; + msg->dst.act_w /= 2; + msg->dst.x_off = msg->dst.act_w; + } + + if ((src->format == IEP_FORMAT_YCbCr_420_P + || src->format == IEP_FORMAT_YCbCr_420_SP + || src->format == IEP_FORMAT_YCbCr_422_P + || src->format == IEP_FORMAT_YCbCr_422_SP + || src->format == IEP_FORMAT_YCrCb_420_P + || src->format == IEP_FORMAT_YCrCb_420_SP + || src->format == IEP_FORMAT_YCrCb_422_P + || src->format == IEP_FORMAT_YCrCb_422_SP) && + msg->dein_mode == IEP_DEINTERLACE_MODE_DISABLE) { + msg->dein_mode = IEP_DEINTERLACE_MODE_BYPASS; + } + + return 0; + } + while (0); + + return -1; +} + +int iep_api::init(iep_img *src, iep_img *dst) +{ + do { + if (0 > init_sanity_check(src, dst)) { + break; + } + + memset(msg, 0, sizeof(IEP_MSG)); + + memcpy(&msg->src, src, sizeof(iep_img)); + memcpy(&msg->dst, dst, sizeof(iep_img)); + + if (g_mode) { + msg->src.act_w /= 2; + msg->src.x_off = msg->src.act_w; + msg->dst.act_w /= 2; + msg->dst.x_off = msg->dst.act_w; + } + + if ((src->format == IEP_FORMAT_YCbCr_420_P + || src->format == IEP_FORMAT_YCbCr_420_SP + || src->format == IEP_FORMAT_YCbCr_422_P + || src->format == IEP_FORMAT_YCbCr_422_SP + || src->format == IEP_FORMAT_YCrCb_420_P + || src->format == IEP_FORMAT_YCrCb_420_SP + || src->format == IEP_FORMAT_YCrCb_422_P + || src->format == IEP_FORMAT_YCrCb_422_SP) && + msg->dein_mode == IEP_DEINTERLACE_MODE_DISABLE) { + msg->dein_mode = IEP_DEINTERLACE_MODE_BYPASS; + } + + return 0; + } + while (0); + + return -1; +} + +void iep_api::recover_image(struct rga_req *req, iep_img *dst) +{ + if (iommu) { + req->src.yrgb_addr = msg->src.mem_addr; + req->src.uv_addr = 0;//msg->src.uv_addr; + req->src.v_addr = 0;//msg->src.v_addr; + } else { + req->src.yrgb_addr = 0; + req->src.uv_addr = msg->src.mem_addr; + req->src.v_addr = 0; + } + req->src.vir_w = msg->src.vir_w; + req->src.vir_h = msg->src.vir_h; + req->src.format = RK_FORMAT_YCbCr_420_SP; + req->src.alpha_swap |= 0; + + req->src.act_w = msg->src.act_w; + req->src.act_h = msg->src.act_h; + req->src.x_offset = 0; + req->src.y_offset = 0; + + if (iommu) { + req->dst.yrgb_addr = dst->mem_addr; + req->dst.uv_addr = 0;//msg->dst.uv_addr; + req->dst.v_addr = 0;//msg->dst.v_addr; + } else { + req->dst.yrgb_addr = 0; + req->dst.uv_addr = dst->mem_addr; + req->dst.v_addr = 0; + } + req->dst.vir_w = dst->vir_w; + req->dst.vir_h = dst->vir_h; + req->dst.format = RK_FORMAT_YCbCr_420_SP; + req->clip.xmin = 0; + req->clip.xmax = dst->vir_w - 1; + req->clip.ymin = 0; + req->clip.ymax = dst->vir_h - 1; + req->dst.alpha_swap |= 0; + + req->dst.act_w = dst->act_w; + req->dst.act_h = dst->act_h; + req->dst.x_offset = 0; + req->dst.y_offset = 0; + + IEP_DEB("src y %x u %x v %x, dst y %x u %x v %x\n", + req->src.yrgb_addr, req->src.uv_addr, req->src.v_addr, + req->dst.yrgb_addr, req->dst.uv_addr, req->dst.v_addr); + + IEP_DEB("src vir %d x %d, dst vir %d x %d\n", req->src.vir_w, + req->src.vir_h, req->dst.vir_w, req->dst.vir_h); + + IEP_DEB("src act %d x %d, offset (%d, %d), dst act %d x %d, offset (%d, %d)\n", + req->src.act_w, req->src.act_h, req->src.x_offset, req->src.y_offset, + req->dst.act_w, req->dst.act_h, req->dst.x_offset, req->dst.y_offset); +} + +int iep_api::run_sync() +{ + do { + struct rga_req req; + + if (0 > ioctl(fd, IEP_SET_PARAMETER, (void *)msg)) { + IEP_ERR("ioctl IEP_SET_PARAMETER failure\n"); + break; + } + + if (g_mode) { + memset(&req, 0, sizeof(struct rga_req)); + + recover_image(&req, &msg->dst); + + if (iommu) { + req.mmu_info.mmu_en = 1; + req.mmu_info.mmu_flag = 1 | (1 << 8) | (1 << 10) | (1 << 31); + } else { + req.mmu_info.mmu_en = 0; + } + if (0 > ioctl(rga_fd, RGA_BLIT_SYNC, &req)) { + IEP_ERR("RGA_BLIT_SYNC failed\n"); + } + + if (msg->dein_mode == IEP_DEINTERLACE_MODE_I4O2) { + memset(&req, 0, sizeof(struct rga_req)); + recover_image(&req, &msg->dst1); + if (iommu) { + req.mmu_info.mmu_en = 1; + req.mmu_info.mmu_flag = 1 | (1 << 8) | (1 << 10) | (1 << 31); + } else { + req.mmu_info.mmu_en = 0; + } + if (0 > ioctl(rga_fd, RGA_BLIT_SYNC, &req)) { + IEP_ERR("RGA_BLIT_SYNC failed\n"); + } + } + } + + if (0 > ioctl(fd, IEP_GET_RESULT_SYNC, 0)) { + IEP_ERR("%d, failure\n", pid); + break; + } + + return 0; + } + while (0); + + return -1; +} + +void* iep_api::notify_func(void *param) +{ + iep_api *api = (iep_api *)param; + int result = 0; + + fd_set rfds; + struct timespec tv; + int status; + sigset_t set; + + FD_ZERO(&rfds); + FD_SET(api->fd, &rfds); + tv.tv_sec = 0; + tv.tv_nsec = 2e9; + sigemptyset(&set); + sigaddset(&set, SIGALRM); + status = pselect(api->fd + 1, &rfds, NULL, NULL, &tv, &set); + + if (0 == status) { + IEP_ERR("%d, timeout\n", api->pid); + ioctl(api->fd, IEP_GET_RESULT_SYNC, NULL); + result = -1; + } else if (-1 == status) { + IEP_ERR("%d, error\n", api->pid); + ioctl(api->fd, IEP_RELEASE_CURRENT_TASK, NULL); + result = -2; + } else if (FD_ISSET(api->fd, &rfds)) { + IEP_DEB("%d, success\n", api->pid); + result = 0; + } + + api->notify(result); + + return NULL; +} + +int iep_api::run_async(iep_notify notify) +{ + do { + + if (notify != NULL) { + this->notify = notify; + if (0 != pthread_create(&td_notify, NULL, iep_api::notify_func, this)) { + IEP_ERR("internal error\n"); + break; + } + } + + if (0 > ioctl(fd, IEP_SET_PARAMETER, msg)) { + IEP_ERR("ioctl IEP_SET_PARAMETER failure\n"); + break; + } + + if (0 > ioctl(fd, IEP_GET_RESULT_ASYNC, 0)) { + IEP_ERR("%d, failure\n", pid); + break; + } + + return 0; + } + while (0); + + return -1; +} + +int iep_api::poll() +{ + int result = 0; + + fd_set rfds; + struct timespec tv; + int status; + sigset_t set; + + FD_ZERO(&rfds); + FD_SET(this->fd, &rfds); + tv.tv_sec = 0; + tv.tv_nsec = 2e9; + sigemptyset(&set); + sigaddset(&set, SIGALRM); + status = pselect(this->fd + 1, &rfds, NULL, NULL, &tv, &set); + + if (0 == status) { + IEP_ERR("%d, timeout\n", this->pid); + ioctl(this->fd, IEP_GET_RESULT_SYNC, NULL); + result = -1; + } else if (-1 == status) { + IEP_ERR("%d, error\n", this->pid); + ioctl(this->fd, IEP_RELEASE_CURRENT_TASK, NULL); + result = -2; + } else if (FD_ISSET(this->fd, &rfds)) { + IEP_DEB("%d, success\n", this->pid); + result = 0; + } + + return result; +} + +int iep_api::yuv_enh_sanity_check(iep_param_YUV_color_enhance_t *yuv_enh) { + do { + if (yuv_enh == NULL) { + IEP_ERR("Invalidate parameter!\n"); + break; + } + + if (yuv_enh->yuv_enh_saturation < 0 || yuv_enh->yuv_enh_saturation > 1.992) { + IEP_ERR("Invalidate parameter, yuv_enh_saturation!\n"); + break; + } + + if (yuv_enh->yuv_enh_contrast < 0 || yuv_enh->yuv_enh_contrast > 1.992) { + IEP_ERR("Invalidate parameter, yuv_enh_contrast!\n"); + break; + } + + if (yuv_enh->yuv_enh_brightness < -32 || yuv_enh->yuv_enh_brightness > 31) { + IEP_ERR("Invalidate parameter, yuv_enh_brightness!\n"); + break; + } + + if (yuv_enh->yuv_enh_hue_angle < -30 || yuv_enh->yuv_enh_hue_angle > 30) { + IEP_ERR("Invalidate parameter, yuv_enh_hue_angle!\n"); + break; + } + + if (yuv_enh->video_mode < 0 || yuv_enh->video_mode > 3) { + IEP_ERR("Invalidate parameter, video_mode!\n"); + break; + } + + if (yuv_enh->color_bar_y > 127 || yuv_enh->color_bar_u > 127 || yuv_enh->color_bar_v > 127) { + IEP_ERR("Invalidate parameter, color_bar_*!\n"); + break; + } + + if (msg->src.format >= 1 && msg->src.format <= 5 && msg->dst.format >= 1 && msg->dst.format <= 5) { + IEP_ERR("Invalidate parameter, contradition between in/out format and yuv enhance\n"); + break; + } + + return 0; + } + while (0); + + return -1; +} + +int iep_api::rgb_enh_sanity_check(iep_param_RGB_color_enhance_t *rgb_enh) +{ + do { + if (rgb_enh == NULL) { + IEP_ERR("Invalidate parameter!\n"); + break; + } + + if (rgb_enh->enh_alpha_base > 8 || rgb_enh->enh_alpha_base < 0 + || rgb_enh->enh_alpha_num < 0 || rgb_enh->enh_alpha_num > 24) { + IEP_ERR("Invalidate parameter, enh_alpha_base or enh_alpha_num!\n"); + break; + } + + if (enh_alpha_table[rgb_enh->enh_alpha_base][rgb_enh->enh_alpha_num] == -1) { + IEP_ERR("Invalidate parameter, enh_alpha_base or enh_alpha_num!\n"); + break; + } + + if (rgb_enh->enh_threshold > 255 || rgb_enh->enh_threshold < 0) { + IEP_ERR("Invalidate parameter, enh_threshold!\n"); + break; + } + + if (rgb_enh->enh_radius > 4 || rgb_enh->enh_radius < 1) { + IEP_ERR("Invalidate parameter, enh_radius!\n"); + break; + } + + if (rgb_enh->rgb_contrast_enhance_mode < 0 || rgb_enh->rgb_contrast_enhance_mode > 1) { + IEP_ERR("Invalidate parameter, rgb_contrast_enhance_mode!\n"); + break; + } + + if (rgb_enh->rgb_enhance_mode < 0 || rgb_enh->rgb_enhance_mode > 3) { + IEP_ERR("Invalidate parameter, rgb_enhance_mode!\n"); + break; + } + + if (rgb_enh->rgb_enh_coe > 3.96875 || rgb_enh->rgb_enh_coe < 0) { + IEP_ERR("Invalidate parameter, rgb_enh_coe!\n"); + break; + } + + if (msg->src.format >= 10 && msg->src.format <= 17 && msg->dst.format >= 10 && msg->dst.format <= 17) { + IEP_ERR("Invalidate parameter, contradition between in/out format and yuv enhance\n"); + break; + } + + return 0; + } + while (0); + + return -1; +} + +int iep_api::color_space_convertion_sanity_check(iep_param_color_space_convertion_t *clr_convert) +{ + do { + if (clr_convert == NULL) { + IEP_ERR("Invalidate parameter!\n"); + break; + } + + if (clr_convert->dither_up_en && msg->src.format != IEP_FORMAT_RGB_565) { + IEP_ERR("Invalidate parameter, contradiction between dither up enable and source image format!\n"); + break; + } + + if (clr_convert->dither_down_en && msg->dst.format != IEP_FORMAT_RGB_565) { + IEP_ERR("Invalidate parameter, contradiction between dither down enable and destination image format!\n"); + break; + } + + return 0; + } + while (0); + + return -1; +} + +int iep_api::yuv_denoise_sanity_check(iep_img *src_itemp, iep_img *src_ftemp, iep_img *dst_itemp, iep_img *dst_ftemp) +{ + do { + if (src_itemp == NULL || src_ftemp == NULL || dst_itemp == NULL || dst_ftemp == NULL) { + IEP_ERR("Invalidate parameter!\n"); + break; + } + + return 0; + } while (0); + + return -1; +} + +int iep_api::dil_src_dst_sanity_check(iep_img *src1, iep_img *dst1) +{ + do { + switch (msg->dein_mode) { + case IEP_DEINTERLACE_MODE_I4O2: + if (dst1 == NULL) { + IEP_ERR("Invalidate parameter!\n"); + goto err; + } else if (!g_mode && (dst1->act_w != msg->dst.act_w || dst1->act_h != msg->dst.act_h)) { + IEP_ERR("Invalidate parameter, contradiction between two destination image size!\n"); + goto err; + } + case IEP_DEINTERLACE_MODE_I4O1: + if (src1 == NULL) { + IEP_ERR("Invalidate parameter!\n"); + goto err; + } else if (!g_mode && (src1->act_w != msg->src.act_w || src1->act_h != msg->src.act_h)) { + IEP_ERR("Invalidate parameter, contradiction between two source image size!\n"); + goto err; + } + case IEP_DEINTERLACE_MODE_I2O1: + if (msg->src.act_w > 1920) { + goto err; + } + break; + default: + ; + } + + return 0; + } + while (0); + +err: + return -1; +} + +int iep_api::deinterlace_sanity_check(iep_param_yuv_deinterlace_t *yuv_dil, iep_img *src1, iep_img *dst1) +{ + do { + if (yuv_dil == NULL) { + IEP_ERR("Invalidate parameter!\n"); + break; + } + + if (yuv_dil->dil_mode == IEP_DEINTERLACE_MODE_I4O2 && msg->lcdc_path_en) { + IEP_ERR("Contradiction between dpi enable and deinterlace mode i4o2\n"); + break; + } + + switch (yuv_dil->dil_mode) { + case IEP_DEINTERLACE_MODE_I4O2: + if (dst1 == NULL) { + IEP_ERR("Invalidate parameter!\n"); + goto err; + } else if (!g_mode && (dst1->act_w != msg->dst.act_w || dst1->act_h != msg->dst.act_h)) { + IEP_ERR("Invalidate parameter, contradiction between two destination image size!\n"); + goto err; + } + case IEP_DEINTERLACE_MODE_I4O1: + if (src1 == NULL) { + IEP_ERR("Invalidate parameter!\n"); + goto err; + } else if (!g_mode && (src1->act_w != msg->src.act_w || src1->act_h != msg->src.act_h)) { + IEP_ERR("Invalidate parameter, contradiction between two source image size!\n"); + goto err; + } + case IEP_DEINTERLACE_MODE_I2O1: + if (msg->src.act_w > 1920) { + goto err; + } + break; + default: + ; + } + + return 0; + } + while (0); + +err: + return -1; +} + +int iep_api::direct_lcdc_path_sanity_check(iep_param_direct_path_interface_t *dpi) +{ + do { + int fmt; + + if (dpi == NULL) { + IEP_ERR("Invalid parameter\n"); + break; + } + + if (msg->dein_mode == IEP_DEINTERLACE_MODE_I4O2) { + IEP_ERR("Contradiction between dpi enable and deinterlace mode i4o2\n"); + break; + } + + fmt = msg->dst.format; + + switch (fmt) { + case IEP_FORMAT_YCbCr_422_P: + case IEP_FORMAT_YCrCb_422_SP: + case IEP_FORMAT_YCrCb_422_P: + case IEP_FORMAT_YCrCb_420_SP: + case IEP_FORMAT_YCbCr_420_P: + case IEP_FORMAT_YCrCb_420_P: + case IEP_FORMAT_RGBA_8888: + case IEP_FORMAT_BGR_565: + IEP_ERR("Contradiction between dpi and destination format\n"); + break; + default: + return 0; + } + } + while (0); + + return -1; +} + +int iep_api::init_sanity_check(iep_img *src, iep_img *dst) +{ + do { + int scl_fct_v, scl_fct_h; + + if (src == NULL || dst == NULL) { + IEP_ERR("Invalidate parameter!\n"); + break; + } + + if ((src->format > 0x05 && src->format < 0x10) || src->format > 0x17) { + IEP_ERR("Invalidate parameter, i/o format!\n"); + break; + } + + if (src->act_w > 4096 || src->act_h > 8192) { + IEP_ERR("Invalidate parameter, source image size!\n"); + break; + } + + if (dst->act_w > 4096 || dst->act_h > 4096) { + IEP_ERR("Invalidate parameter, destination image size!\n"); + break; + } + + scl_fct_h = src->act_w > dst->act_w ? (src->act_w * 1000 / dst->act_w) : (dst->act_w * 1000 / src->act_w); + scl_fct_v = src->act_h > dst->act_h ? (src->act_h * 1000 / dst->act_h) : (dst->act_h * 1000 / src->act_h); + + if (scl_fct_h > 16000 || scl_fct_v > 16000) { + IEP_ERR("Invalidate parameter, scale factor!\n"); + break; + } + + return 0; + } + while (0); + + return -1; +} + +struct IEP_CAP* iep_api::query() +{ + return ∩ +} + +IEP_QUERY_INTERLACE iep_api::query_interlace() +{ + if (cap.i4_deinterlace_supported) { + return IEP_QUERY_INTERLACE_FULL_FUNC; + } else if (cap.i2_deinterlace_supported) { + return IEP_QUERY_INTERLACE_I2O1_ONLY; + } else { + return IEP_QUERY_INTERLACE_UNSUPPORTED; + } +} + +IEP_QUERY_DIMENSION iep_api::query_dimension() +{ + if (cap.max_dynamic_width > 1920) { + return IEP_QUERY_DIMENSION_4096; + } else { + return IEP_QUERY_DIMENSION_1920; + } +} + +iep_interface* iep_interface::create_new() +{ + return new iep_api(); +} + +void iep_interface::reclaim(iep_interface *iep_inf) +{ + if (iep_inf) { + delete iep_inf; + iep_inf = NULL; + } +} + +iep_interface* iep_interface_create_new() +{ + return iep_interface::create_new(); +} + +void iep_interface_reclaim(iep_interface *iep_inf) +{ + iep_interface::reclaim(iep_inf); +} + +extern "C" +void* iep_ops_claim() +{ + return iep_interface::create_new(); +} + +extern "C" +int iep_ops_init(void *iep_obj, iep_img *src, iep_img *dst) +{ + return ((iep_interface*)iep_obj)->init(src, dst); +} + +extern "C" +int iep_ops_init_discrete(void *iep_obj, + int32_t src_act_w, int32_t src_act_h, + int32_t src_x_off, int32_t src_y_off, + int32_t src_vir_w, int32_t src_vir_h, + int32_t src_format, + uint32_t src_mem_addr, uint32_t src_uv_addr, uint32_t src_v_addr, + int32_t dst_act_w, int32_t dst_act_h, + int32_t dst_x_off, int32_t dst_y_off, + int32_t dst_vir_w, int32_t dst_vir_h, + int32_t dst_format, + uint32_t dst_mem_addr, uint32_t dst_uv_addr, uint32_t dst_v_addr) +{ + iep_img src; + iep_img dst; + + src.act_w = src_act_w; + src.act_h = src_act_h; + src.x_off = src_x_off; + src.y_off = src_y_off; + src.vir_w = src_vir_w; + src.vir_h = src_vir_h; + src.format = src_format; + src.mem_addr = src_mem_addr; + src.uv_addr = src_uv_addr; + src.v_addr = src_v_addr; + + dst.act_w = dst_act_w; + dst.act_h = dst_act_h; + dst.x_off = dst_x_off; + dst.y_off = dst_y_off; + dst.vir_w = dst_vir_w; + dst.vir_h = dst_vir_h; + dst.format = dst_format; + dst.mem_addr = dst_mem_addr; + dst.uv_addr = dst_uv_addr; + dst.v_addr = dst_v_addr; + + ALOGE("%s, (%d, %d), (%d, %d), (%d, %d), %d, %x, %x, %x\n", __func__, + src.act_w, src.act_h, src.x_off, src.y_off, + src.vir_w, src.vir_h, src.format, + src.mem_addr, src.uv_addr, src.v_addr); + + ALOGE("%s, (%d, %d), (%d, %d), (%d, %d), %d, %x, %x, %x\n", __func__, + dst.act_w, dst.act_h, dst.x_off, dst.y_off, + dst.vir_w, dst.vir_h, dst.format, + dst.mem_addr, dst.uv_addr, dst.v_addr); + + return ((iep_interface*)iep_obj)->init(&src, &dst); +} + +extern "C" +int iep_ops_config_src_dst(void *iep_obj, iep_img *src, iep_img *dst) +{ + return ((iep_interface*)iep_obj)->config_src_dst(src, dst); +} + +extern "C" +int iep_ops_config_yuv_enh(void *iep_obj) +{ + return ((iep_interface*)iep_obj)->config_yuv_enh(); +} + +extern "C" +int iep_ops_config_yuv_enh_param(void *iep_obj, iep_param_YUV_color_enhance_t *yuv_enh) +{ + return ((iep_interface*)iep_obj)->config_yuv_enh(yuv_enh); +} + +extern "C" +int iep_ops_config_color_enh(void *iep_obj) +{ + return ((iep_interface*)iep_obj)->config_color_enh(); +} + +extern "C" +int iep_ops_config_color_enh_param(void *iep_obj, iep_param_RGB_color_enhance_t *rgb_enh) +{ + return ((iep_interface*)iep_obj)->config_color_enh(rgb_enh); +} + +extern "C" +int iep_ops_config_scale(void *iep_obj) +{ + return ((iep_interface*)iep_obj)->config_scale(); +} + +extern "C" +int iep_ops_config_scale_param(void *iep_obj, iep_param_scale_t *scale) +{ + return ((iep_interface*)iep_obj)->config_scale(scale); +} + +extern "C" +int iep_ops_config_yuv_denoise(void *iep_obj) +{ + return ((iep_interface*)iep_obj)->config_yuv_denoise(); +} + +extern "C" +int iep_ops_config_yuv_deinterlace(void *iep_obj) +{ + return ((iep_interface*)iep_obj)->config_yuv_deinterlace(); +} + +extern "C" +int iep_ops_config_yuv_deinterlace_param1(void *iep_obj, iep_param_yuv_deinterlace_t *yuv_dil) +{ + return ((iep_interface*)iep_obj)->config_yuv_deinterlace(yuv_dil); +} + +extern "C" +int iep_ops_config_yuv_dil_src_dst(void *iep_obj, iep_img *src1, iep_img *dst1) +{ + return ((iep_interface*)iep_obj)->config_yuv_dil_src_dst(src1, dst1); +} + +extern "C" +int iep_ops_config_yuv_deinterlace_param2(void *iep_obj, iep_param_yuv_deinterlace_t *yuv_dil, iep_img *src1, iep_img *dst1) +{ + return ((iep_interface*)iep_obj)->config_yuv_deinterlace(yuv_dil, src1, dst1); +} + +extern "C" +int iep_ops_config_color_space_convertion(void *iep_obj) +{ + return ((iep_interface*)iep_obj)->config_color_space_convertion(); +} + +extern "C" +int iep_ops_config_color_space_convertion_param(void *iep_obj, iep_param_color_space_convertion_t *clr_convert) +{ + return ((iep_interface*)iep_obj)->config_color_space_convertion(clr_convert); +} + +extern "C" +int iep_ops_config_direct_lcdc_path(void *iep_obj, iep_param_direct_path_interface_t *dpi) +{ + return ((iep_interface*)iep_obj)->config_direct_lcdc_path(dpi); +} + +extern "C" +int iep_ops_run_sync(void *iep_obj) +{ + return ((iep_interface*)iep_obj)->run_sync(); +} + +extern "C" +int iep_ops_run_async_ncb(void *iep_obj) +{ + return ((iep_interface*)iep_obj)->run_async(NULL); +} + +extern "C" +int iep_ops_run_async(void *iep_obj, iep_notify notify) +{ + return ((iep_interface*)iep_obj)->run_async(notify); +} + +extern "C" +int iep_ops_poll(void *iep_obj) +{ + return ((iep_interface*)iep_obj)->poll(); +} + +extern "C" +void iep_ops_reclaim(void *iep_obj) +{ + iep_interface::reclaim((iep_interface*)iep_obj); +} + +struct iep_ops* alloc_iep_ops() +{ + struct iep_ops *ops = (struct iep_ops*)malloc(sizeof(struct iep_ops)); + + if (ops == NULL) { + IEP_ERR("allocate structure iep_ops failure\n"); + return NULL; + } + + ops->claim = iep_ops_claim; + ops->init = iep_ops_init; + ops->config_src_dst = iep_ops_config_src_dst; + ops->config_yuv_enh = iep_ops_config_yuv_enh; + ops->config_yuv_enh_param = iep_ops_config_yuv_enh_param; + ops->config_color_enh = iep_ops_config_color_enh; + ops->config_color_enh_param = iep_ops_config_color_enh_param; + ops->config_scale = iep_ops_config_scale; + ops->config_scale_param = iep_ops_config_scale_param; + ops->config_yuv_denoise = iep_ops_config_yuv_denoise; + ops->config_yuv_deinterlace = iep_ops_config_yuv_deinterlace; + ops->config_yuv_deinterlace_param1 = iep_ops_config_yuv_deinterlace_param1; + ops->config_yuv_dil_src_dst = iep_ops_config_yuv_dil_src_dst; + ops->config_yuv_deinterlace_param2 = iep_ops_config_yuv_deinterlace_param2; + ops->config_color_space_convertion = iep_ops_config_color_space_convertion; + ops->config_color_space_convertion_param = iep_ops_config_color_space_convertion_param; + ops->config_direct_lcdc_path = iep_ops_config_direct_lcdc_path; + ops->run_sync = iep_ops_run_sync; + ops->run_async = iep_ops_run_async; + ops->poll = iep_ops_poll; + ops->reclaim = iep_ops_reclaim; + + return ops; +} + +void free_iep_ops(struct iep_ops *ops) +{ + if (ops != NULL) { + free(ops); + } +} + diff --git a/iep_api.h b/iep_api.h new file mode 100755 index 0000000..092bc19 --- /dev/null +++ b/iep_api.h @@ -0,0 +1,199 @@ +#ifndef IEP_API_H_
+#define IEP_API_H_
+
+#include "iep.h"
+
+typedef enum IEP_VIDEO_MODE {
+ IEP_VIDEO_MODE_BLACK_SCREEN,
+ IEP_VIDEO_MODE_BLUE_SCREEN,
+ IEP_VIDEO_MODE_COLOR_BAR,
+ IEP_VIDEO_MODE_NORMAL_VIDEO
+} IEP_VIDEO_MODE_t;
+
+typedef struct iep_param_YUV_color_enhance {
+ float yuv_enh_saturation; // [0, 1.992]
+ float yuv_enh_contrast; // [0, 1.992]
+ signed char yuv_enh_brightness; // [-32, 31]
+ float yuv_enh_hue_angle; // [-30, 30]
+ IEP_VIDEO_MODE_t video_mode;
+ unsigned char color_bar_y; // [0, 127]
+ unsigned char color_bar_u; // [0, 127]
+ unsigned char color_bar_v; // [0, 127]
+} iep_param_YUV_color_enhance_t;
+
+typedef enum IEP_RGB_COLOR_ENHANCE_MODE {
+ IEP_RGB_COLOR_ENHANCE_MODE_NO_OPERATION,
+ IEP_RGB_COLOR_ENHANCE_MODE_DENOISE,
+ IEP_RGB_COLOR_ENHANCE_MODE_DETAIL_ENHANCE,
+ IEP_RGB_COLOR_ENHANCE_MODE_EDGE_ENHANCE
+} IEP_RGB_COLOR_ENHANCE_MODE_t;
+
+typedef enum IEP_RGB_COLOR_ENHANCE_ORDER {
+ IEP_RGB_COLOR_ENHANCE_ORDER_CG_DDE, // CG(Contrast & Gammar) prior to DDE (De-noise, Detail & Edge Enhance)
+ IEP_RGB_COLOR_ENHANCE_ORDER_DDE_CG // DDE prior to CG
+} IEP_RGB_COLOR_ENHANCE_ORDER_t;
+
+typedef struct iep_param_RGB_color_enhance {
+ float rgb_enh_coe; // [0, 3.96875]
+ IEP_RGB_COLOR_ENHANCE_MODE_t rgb_enhance_mode;
+ uint8_t rgb_cg_en; //sw_rgb_con_gam_en
+ double cg_rr;
+ double cg_rg;
+ double cg_rb;
+ IEP_RGB_COLOR_ENHANCE_ORDER_t rgb_contrast_enhance_mode;
+
+ /// more than this value considered as detail, and less than this value considered as noise.
+ int enh_threshold; // [0, 255]
+
+ /// combine the original pixel and enhanced pixel
+ /// if (enh_alpha_num / enh_alpha_base <= 1 ) enh_alpha_base = 8, else enh_alpha_base = 4
+ /// (1/8 ... 8/8) (5/4 ... 24/4)
+ int enh_alpha_num; // [0, 24]
+ int enh_alpha_base; // {4, 8}
+ int enh_radius; // [1, 4]
+} iep_param_RGB_color_enhance_t;
+
+typedef enum IEP_SCALE_UP_MODE {
+ IEP_SCALE_UP_MODE_HERMITE,
+ IEP_SCALE_UP_MODE_SPLINE,
+ IEP_SCALE_UP_MODE_CATROM,
+ IEP_SCALE_UP_MODE_MITCHELL
+} IEP_SCALE_UP_MODE_t;
+
+typedef struct iep_param_scale {
+ IEP_SCALE_UP_MODE_t scale_up_mode;
+ //unsigned int dst_width_tile0; // [0, 4095]
+ //unsigned int dst_width_tile1; // [0, 4095]
+ //unsigned int dst_width_tile2; // [0, 4095]
+ //unsigned int dst_width_tile3; // [0, 4095]
+} iep_param_scale_t;
+
+typedef enum IEP_FIELD_ORDER
+{
+ FIELD_ORDER_TOP_FIRST,
+ FIELD_ORDER_BOTTOM_FIRST
+} IEP_FIELD_ORDER_t;
+
+typedef enum IEP_YUV_DEINTERLACE_MODE {
+ IEP_DEINTERLACE_MODE_DISABLE,
+ IEP_DEINTERLACE_MODE_I2O1,
+ IEP_DEINTERLACE_MODE_I4O1,
+ IEP_DEINTERLACE_MODE_I4O2,
+ IEP_DEINTERLACE_MODE_BYPASS
+} IEP_YUV_DEINTERLACE_MODE_t;
+
+typedef struct iep_param_yuv_deinterlace {
+ uint8_t high_freq_en;
+ IEP_YUV_DEINTERLACE_MODE_t dil_mode;
+ IEP_FIELD_ORDER_t field_order;
+ uint8_t dil_high_freq_fct; // [0, 127]
+ uint8_t dil_ei_mode; // deinterlace edge interpolation 0: disable, 1: enable
+ uint8_t dil_ei_smooth; // deinterlace edge interpolation for smooth effect 0: disable, 1: enable
+ uint8_t dil_ei_sel; // deinterlace edge interpolation select
+ uint8_t dil_ei_radius; // deinterlace edge interpolation radius [0, 3]
+} iep_param_yuv_deinterlace_t;
+
+typedef enum IEP_COLOR_CONVERT_MODE {
+ IEP_COLOR_CONVERT_MODE_BT601_L,
+ IEP_COLOR_CONVERT_MODE_BT601_F,
+ IEP_COLOR_CONVERT_MODE_BT709_L,
+ IEP_COLOR_CONVERT_MODE_BT709_F
+} IEP_COLOR_CONVERT_MODE_t;
+
+typedef struct iep_param_color_space_convertion {
+ IEP_COLOR_CONVERT_MODE_t rgb2yuv_mode;
+ IEP_COLOR_CONVERT_MODE_t yuv2rgb_mode;
+ unsigned char rgb2yuv_input_clip; // 0:R/G/B [0, 255], 1:R/G/B [16, 235]
+ unsigned char yuv2rgb_input_clip; // 0:Y/U/V [0, 255], 1:Y [16, 235] U/V [16, 240]
+ unsigned char global_alpha_value; // global alpha value for output ARGB
+ unsigned char dither_up_en;
+ unsigned char dither_down_en;
+} iep_param_color_space_convertion_t;
+
+typedef struct iep_param_direct_path_interface {
+ uint8_t enable;
+ int off_x;
+ int off_y;
+ int width;
+ int height;
+ uint8_t layer;
+} iep_param_direct_path_interface_t;
+
+typedef enum IEP_QUERY_INTERLACE {
+ IEP_QUERY_INTERLACE_UNSUPPORTED,
+ IEP_QUERY_INTERLACE_I2O1_ONLY,
+ IEP_QUERY_INTERLACE_FULL_FUNC
+} IEP_QUERY_INTERLACE;
+
+typedef enum IEP_QUERY_DIMENSION {
+ IEP_QUERY_DIMENSION_1920,
+ IEP_QUERY_DIMENSION_4096
+} IEP_QUERY_DIMENSION;
+
+typedef void (*iep_notify)(int result);
+
+class iep_interface {
+public:
+ virtual ~iep_interface() {;}
+
+ virtual int init(iep_img *src, iep_img *dst) = 0;
+ virtual int config_src_dst(iep_img *src, iep_img *dst) = 0;
+ virtual int config_yuv_enh() = 0;
+ virtual int config_yuv_enh(iep_param_YUV_color_enhance_t *yuv_enh) = 0;
+ virtual int config_color_enh() = 0;
+ virtual int config_color_enh(iep_param_RGB_color_enhance_t *rgb_enh) = 0;
+ virtual int config_scale() = 0;
+ virtual int config_scale(iep_param_scale_t *scale) = 0;
+ virtual int config_yuv_denoise() = 0;
+ virtual int config_yuv_denoise(iep_img *src_itemp, iep_img *src_ftemp, iep_img *dst_itemp, iep_img *dst_ftemp) = 0;
+ virtual int config_yuv_deinterlace() = 0;
+ virtual int config_yuv_deinterlace(iep_param_yuv_deinterlace_t *yuv_dil) = 0;
+ virtual int config_yuv_dil_src_dst(iep_img *src1, iep_img *dst1) = 0;
+ virtual int config_yuv_deinterlace(iep_param_yuv_deinterlace_t *yuv_dil, iep_img *src1, iep_img *dst1) = 0;
+ virtual int config_color_space_convertion() = 0;
+ virtual int config_color_space_convertion(iep_param_color_space_convertion_t *clr_convert) = 0;
+ virtual int config_direct_lcdc_path(iep_param_direct_path_interface_t *dpi) = 0;
+ virtual int run_sync() = 0;
+ virtual int run_async(iep_notify notify) = 0;
+ virtual int poll() = 0;
+ virtual struct IEP_CAP* query() = 0;
+ virtual IEP_QUERY_INTERLACE query_interlace() = 0;
+ virtual IEP_QUERY_DIMENSION query_dimension() = 0;
+
+ static iep_interface* create_new();
+ static void reclaim(iep_interface *iep_inf);
+};
+
+/// for dlopen
+iep_interface* iep_interface_create_new();
+void iep_interface_reclaim(iep_interface *iep_inf);
+
+/// for "C"
+struct iep_ops {
+ void* (*claim)();
+ int (*init)(void *iep_obj, iep_img *src, iep_img *dst);
+ int (*config_src_dst)(void *iep_obj, iep_img *src, iep_img *dst);
+ int (*config_yuv_enh)(void *iep_obj);
+ int (*config_yuv_enh_param)(void *iep_obj, iep_param_YUV_color_enhance_t *yuv_enh);
+ int (*config_color_enh)(void *iep_obj);
+ int (*config_color_enh_param)(void *iep_obj, iep_param_RGB_color_enhance_t *rgb_enh);
+ int (*config_scale)(void *iep_obj);
+ int (*config_scale_param)(void *iep_obj, iep_param_scale_t *scale);
+ int (*config_yuv_denoise)(void *iep_obj);
+ int (*config_yuv_deinterlace)(void *iep_obj);
+ int (*config_yuv_deinterlace_param1)(void *iep_obj, iep_param_yuv_deinterlace_t *yuv_dil);
+ int (*config_yuv_dil_src_dst)(void *iep_obj, iep_img *src1, iep_img *dst1);
+ int (*config_yuv_deinterlace_param2)(void *iep_obj, iep_param_yuv_deinterlace_t *yuv_dil, iep_img *src1, iep_img *dst1);
+ int (*config_color_space_convertion)(void *iep_obj);
+ int (*config_color_space_convertion_param)(void *iep_obj, iep_param_color_space_convertion_t *clr_convert);
+ int (*config_direct_lcdc_path)(void *iep_obj, iep_param_direct_path_interface_t *dpi);
+ int (*run_sync)(void *iep_obj);
+ int (*run_async)(void *iep_obj, iep_notify notify);
+ int (*poll)(void *iep_obj);
+ void (*reclaim)(void *iep_obj);
+};
+
+struct iep_ops* alloc_iep_ops();
+void free_iep_ops(struct iep_ops *ops);
+
+#endif
diff --git a/iep_func_test.cpp b/iep_func_test.cpp new file mode 100755 index 0000000..ea3ebe3 --- /dev/null +++ b/iep_func_test.cpp @@ -0,0 +1,655 @@ +#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <memory.h>
+
+#include <sys/mman.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+
+#include <inttypes.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include "cutils/log.h"
+
+#include "iep_api.h"
+#include "iep.h"
+#include "../librkvpu/vpu_mem.h"
+
+typedef enum {
+ TEST_CASE_NONE,
+ TEST_CASE_YUVENHANCE,
+ TEST_CASE_RGBENHANCE,
+ TEST_CASE_DENOISE,
+ TEST_CASE_DEINTERLACE
+} TEST_CASE;
+
+typedef struct mem_region {
+ int phy_src;
+ int phy_reg;
+ int phy_dst;
+
+ int len_src;
+ int len_reg;
+ int len_dst;
+
+ uint8_t *vir_src;
+ uint8_t *vir_reg;
+ uint8_t *vir_dst;
+
+ int src_fmt;
+ int src_w;
+ int src_h;
+ char src_url[100];
+
+ int dst_fmt;
+ int dst_w;
+ int dst_h;
+ char dst_url[100];
+
+ TEST_CASE testcase;
+ char cfg_url[100];
+} mem_region_t;
+
+static int64_t GetTime() {
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return((int64_t)now.tv_sec) * 1000000 + ((int64_t)now.tv_usec);
+}
+
+static int read_line(FILE *file, char *str) {
+ int ch;
+ int i = 0;
+
+ while (1) {
+ ch = fgetc(file);
+ if (ch == EOF || feof(file)) {
+ return -1;
+ } else if (ch == '\n') {
+ break;
+ }
+
+ str[i++] = ch;
+ }
+
+ return 0;
+}
+
+static int parse_cfg_file(FILE *file, void *param) {
+ char str[100];
+
+ fseek(file, 0, SEEK_SET);
+ memset(str, 0, sizeof(str));
+ read_line(file, str);
+
+ ALOGD("cfg title %s\n", str);
+
+ if (strncmp(str, "deinterlace", strlen("deinterlace")) == 0) {
+ iep_param_yuv_deinterlace_t *arg = (iep_param_yuv_deinterlace_t*)param;
+ int ret;
+
+ do {
+ memset(str, 0, sizeof(str));
+ ret = read_line(file, str);
+ if (strncmp(str, "high_freq_en", strlen("high_freq_en")) == 0) {
+ sscanf(str, "high_freq_en %d", (int*)&arg->high_freq_en);
+ } else if (strncmp(str, "dil_mode", strlen("dil_mode")) == 0) {
+ sscanf(str, "dil_mode %d", (int*)&arg->dil_mode);
+ } else if (strncmp(str, "dil_high_freq_fct", strlen("dil_high_freq_fct")) == 0) {
+ sscanf(str, "dil_high_freq_fct %d", (int*)&arg->dil_high_freq_fct);
+ } else if (strncmp(str, "dil_ei_mode", strlen("dil_ei_mode")) == 0) {
+ sscanf(str, "dil_ei_mode %d", (int*)&arg->dil_ei_mode);
+ } else if (strncmp(str, "dil_ei_smooth", strlen("dil_ei_smooth")) == 0) {
+ sscanf(str, "dil_ei_smooth %d", (int*)&arg->dil_ei_smooth);
+ } else if (strncmp(str, "dil_ei_sel", strlen("dil_ei_sel")) == 0) {
+ sscanf(str, "dil_ei_sel %d", (int*)&arg->dil_ei_sel);
+ } else if (strncmp(str, "dil_ei_radius", strlen("dil_ei_radius")) == 0) {
+ sscanf(str, "dil_ei_radius %d", (int*)&arg->dil_ei_radius);
+ }
+ }
+ while (ret == 0);
+ } else if (strncmp(str, "yuv enhance", strlen("yuv enhance")) == 0) {
+ iep_param_YUV_color_enhance_t *arg = (iep_param_YUV_color_enhance_t*)param;
+ int ret;
+
+ do {
+ memset(str, 0, sizeof(str));
+ ret = read_line(file, str);
+ ALOGD("parameter %s\t", str);
+ if (strncmp(str, "yuv_enh_saturation", strlen("yuv_enh_saturation")) == 0) {
+ sscanf(str, "yuv_enh_saturation %f", &arg->yuv_enh_saturation);
+ ALOGD("value %f\n", arg->yuv_enh_saturation);
+ } else if (strncmp(str, "yuv_enh_contrast", strlen("yuv_enh_contrast")) == 0) {
+ sscanf(str, "yuv_enh_contrast %f", &arg->yuv_enh_contrast);
+ ALOGD("value %f\n", arg->yuv_enh_contrast);
+ } else if (strncmp(str, "yuv_enh_brightness", strlen("yuv_enh_brightness")) == 0) {
+ sscanf(str, "yuv_enh_brightness %d", (int*)&arg->yuv_enh_brightness);
+ ALOGD("value %d\n", arg->yuv_enh_brightness);
+ } else if (strncmp(str, "yuv_enh_hue_angle", strlen("yuv_enh_hue_angle")) == 0) {
+ sscanf(str, "yuv_enh_hue_angle %d", (int*)&arg->yuv_enh_hue_angle);
+ ALOGD("value %d\n", arg->yuv_enh_hue_angle);
+ } else if (strncmp(str, "video_mode", strlen("video_mode")) == 0) {
+ sscanf(str, "video_mode %d", (int*)&arg->video_mode);
+ ALOGD("value %d\n", arg->video_mode);
+ } else if (strncmp(str, "color_bar_y", strlen("color_bar_y")) == 0) {
+ sscanf(str, "color_bar_y %d", (int*)&arg->color_bar_y);
+ ALOGD("value %d\n", arg->color_bar_y);
+ } else if (strncmp(str, "color_bar_u", strlen("color_bar_u")) == 0) {
+ sscanf(str, "color_bar_u %d", (int*)&arg->color_bar_u);
+ ALOGD("value %d\n", arg->color_bar_u);
+ } else if (strncmp(str, "color_bar_v", strlen("color_bar_v")) == 0) {
+ sscanf(str, "color_bar_v %d", (int*)&arg->color_bar_v);
+ ALOGD("value %d\n", arg->color_bar_v);
+ }
+ }
+ while (ret == 0);
+ } else if (strncmp(str, "rgb enhance", strlen("rgb enhance")) == 0) {
+ iep_param_RGB_color_enhance_t *arg = (iep_param_RGB_color_enhance_t*)param;
+ int ret;
+
+ do {
+ memset(str, 0, sizeof(str));
+ ret = read_line(file, str);
+ ALOGD("parameter %s\t", str);
+ if (strncmp(str, "rgb_enh_coe", strlen("rgb_enh_coe")) == 0) {
+ sscanf(str, "rgb_enh_coe %f", &arg->rgb_enh_coe);
+ ALOGD("value %f\n", arg->rgb_enh_coe);
+ } else if (strncmp(str, "rgb_enhance_mode", strlen("rgb_enhance_mode")) == 0) {
+ sscanf(str, "rgb_enhance_mode %d", (int*)&arg->rgb_enhance_mode);
+ ALOGD("value %d\n", arg->rgb_enhance_mode);
+ } else if (strncmp(str, "rgb_cg_en", strlen("rgb_cg_en")) == 0) {
+ sscanf(str, "rgb_cg_en %d", (int*)&arg->rgb_cg_en);
+ ALOGD("value %d\n", arg->rgb_cg_en);
+ } else if (strncmp(str, "cg_rr", strlen("cg_rr")) == 0) {
+ sscanf(str, "cg_rr %lf", &arg->cg_rr);
+ ALOGD("value %f\n", arg->cg_rr);
+ } else if (strncmp(str, "cg_rg", strlen("cg_rg")) == 0) {
+ sscanf(str, "cg_rg %lf", &arg->cg_rg);
+ ALOGD("value %f\n", arg->cg_rg);
+ } else if (strncmp(str, "cg_rb", strlen("cg_rb")) == 0) {
+ sscanf(str, "cg_rb %lf", &arg->cg_rb);
+ ALOGD("value %f\n", arg->cg_rb);
+ } else if (strncmp(str, "rgb_contrast_enhance_mode", strlen("rgb_contrast_enhance_mode")) == 0) {
+ sscanf(str, "rgb_contrast_enhance_mode %d", (int*)&arg->rgb_contrast_enhance_mode);
+ ALOGD("value %d\n", (int*)arg->rgb_contrast_enhance_mode);
+ } else if (strncmp(str, "enh_threshold", strlen("enh_threshold")) == 0) {
+ sscanf(str, "enh_threshold %d", (int*)&arg->enh_threshold);
+ ALOGD("value %d\n", arg->enh_threshold);
+ } else if (strncmp(str, "enh_alpha_num", strlen("enh_alpha_num")) == 0) {
+ sscanf(str, "enh_alpha_num %d", (int*)&arg->enh_alpha_num);
+ ALOGD("value %d\n", arg->enh_alpha_num);
+ } else if (strncmp(str, "enh_alpha_base", strlen("enh_alpha_base")) == 0) {
+ sscanf(str, "enh_alpha_base %d", (int*)&arg->enh_alpha_base);
+ ALOGD("value %d\n", arg->enh_alpha_base);
+ } else if (strncmp(str, "enh_radius", strlen("enh_radius")) == 0) {
+ sscanf(str, "enh_radius %d", (int*)&arg->enh_radius);
+ ALOGD("value %d\n", arg->enh_radius);
+ }
+ }
+ while (ret == 0);
+ } else if (strncmp(str, "scale", strlen("scale")) == 0) {
+ iep_param_scale_t *arg = (iep_param_scale_t*)param;
+ int ret;
+
+ do {
+ memset(str, 0, sizeof(str));
+ ret = read_line(file, str);
+ if (strncmp(str, "scale_up_mode", strlen("scale_up_mode")) == 0) {
+ sscanf(str, "scale_up_mode %d", (int*)&arg->scale_up_mode);
+ }
+ }
+ while (ret == 0);
+ } else if (strncmp(str, "color space convertion", strlen("color space convertion")) == 0) {
+ iep_param_color_space_convertion_t *arg = (iep_param_color_space_convertion_t*)param;
+ int ret;
+
+ do {
+ memset(str, 0, sizeof(str));
+ ret = read_line(file, str);
+ if (strncmp(str, "rgb2yuv_mode", strlen("rgb2yuv_mode")) == 0) {
+ sscanf(str, "rgb2yuv_mode %d", (int*)&arg->rgb2yuv_mode);
+ } else if (strncmp(str, "yuv2rgb_mode", strlen("yuv2rgb_mode")) == 0) {
+ sscanf(str, "yuv2rgb_mode %d", (int*)&arg->yuv2rgb_mode);
+ } else if (strncmp(str, "rgb2yuv_input_clip", strlen("rgb2yuv_input_clip")) == 0) {
+ sscanf(str, "rgb2yuv_input_clip %d", (int*)&arg->rgb2yuv_input_clip);
+ } else if (strncmp(str, "yuv2rgb_input_clip", strlen("yuv2rgb_input_clip")) == 0) {
+ sscanf(str, "yuv2rgb_input_clip %d", (int*)&arg->yuv2rgb_input_clip);
+ } else if (strncmp(str, "global_alpha_value", strlen("global_alpha_value")) == 0) {
+ sscanf(str, "global_alpha_value %d", (int*)&arg->global_alpha_value);
+ } else if (strncmp(str, "dither_up_en", strlen("dither_up_en")) == 0) {
+ sscanf(str, "dither_up_en %d", (int*)&arg->dither_up_en);
+ } else if (strncmp(str, "dither_down_en", strlen("dither_down_en")) == 0) {
+ sscanf(str, "dither_down_en %d", (int*)&arg->dither_down_en);
+ }
+ }
+ while (ret == 0);
+ } else if (strncmp(str, "direct lcdc path", strlen("direct lcdc path")) == 0) {
+ iep_param_direct_path_interface_t *arg = (iep_param_direct_path_interface_t*)param;
+ int ret;
+
+ do {
+ memset(str, 0, sizeof(str));
+ ret = read_line(file, str);
+ if (strncmp(str, "enable", strlen("enable")) == 0) {
+ sscanf(str, "enable %d", (int*)&arg->enable);
+ } else if (strncmp(str, "off_x", strlen("off_x")) == 0) {
+ sscanf(str, "off_x %d", &arg->off_x);
+ } else if (strncmp(str, "off_y", strlen("off_y")) == 0) {
+ sscanf(str, "off_y %d", &arg->off_y);
+ } else if (strncmp(str, "width", strlen("width")) == 0) {
+ sscanf(str, "width %d", &arg->width);
+ } else if (strncmp(str, "height", strlen("height")) == 0) {
+ sscanf(str, "height %d", &arg->height);
+ } else if (strncmp(str, "layer", strlen("layer")) == 0) {
+ sscanf(str, "layer %d", (int*)&arg->layer);
+ }
+ }
+ while (ret == 0);
+ }
+
+ return 0;
+}
+
+static void* iep_process_thread(void *param)
+{
+ int i, cnt = 0;
+
+ mem_region_t *mr = (mem_region_t*)param;
+
+ uint32_t phy_src, phy_reg, phy_dst;
+ int len_src, len_reg, len_dst;
+ uint8_t *vir_reg, *vir_src, *vir_dst;
+ iep_img src;
+ iep_img dst;
+
+ int datalen = 0;
+
+ len_reg = mr->len_reg;
+ len_src = mr->len_src;
+ len_dst = mr->len_dst;
+
+ phy_reg = mr->phy_reg;
+ phy_src = mr->phy_src;
+ phy_dst = mr->phy_dst;
+
+ vir_reg = mr->vir_reg;
+ vir_src = mr->vir_src;
+ vir_dst = mr->vir_dst;
+
+ iep_interface *api = iep_interface::create_new();
+
+ FILE *srcfile = fopen(mr->src_url, "rb");
+ FILE *dstfile = fopen(mr->dst_url, "wb");
+
+ switch (mr->src_fmt) {
+ case IEP_FORMAT_ABGR_8888:
+ case IEP_FORMAT_ARGB_8888:
+ case IEP_FORMAT_BGRA_8888:
+ case IEP_FORMAT_RGBA_8888:
+ datalen = mr->src_w * mr->src_h * 4;
+ break;
+ case IEP_FORMAT_BGR_565:
+ case IEP_FORMAT_RGB_565:
+ case IEP_FORMAT_YCbCr_422_P:
+ case IEP_FORMAT_YCbCr_422_SP:
+ case IEP_FORMAT_YCrCb_422_P:
+ case IEP_FORMAT_YCrCb_422_SP:
+ datalen = mr->src_w * mr->src_h * 2;
+ src.v_addr = phy_src + mr->src_w * mr->src_h + mr->src_w * mr->src_h / 2;
+ break;
+ case IEP_FORMAT_YCbCr_420_P:
+ case IEP_FORMAT_YCbCr_420_SP:
+ case IEP_FORMAT_YCrCb_420_P:
+ case IEP_FORMAT_YCrCb_420_SP:
+ datalen = mr->src_w * mr->src_h * 3 / 2;
+ src.v_addr = phy_src + mr->src_w * mr->src_h + mr->src_w * mr->src_h / 4;
+ break;
+ default:
+ ;
+ }
+
+ ALOGD("%s %d\n", __func__, __LINE__);
+
+ fread(vir_src, 1, datalen, srcfile);
+
+ int64_t intime = GetTime();
+
+ src.act_w = mr->src_w;
+ src.act_h = mr->src_h;
+ src.x_off = 0;
+ src.y_off = 0;
+ src.vir_w = mr->src_w;
+ src.vir_h = mr->src_h;
+ src.format = mr->src_fmt;
+ src.mem_addr = phy_src;
+ src.uv_addr = phy_src + mr->src_w * mr->src_h;
+
+ switch (mr->dst_fmt) {
+ case IEP_FORMAT_ABGR_8888:
+ case IEP_FORMAT_ARGB_8888:
+ case IEP_FORMAT_BGRA_8888:
+ case IEP_FORMAT_RGBA_8888:
+ datalen = mr->dst_w * mr->dst_h * 4;
+ break;
+ case IEP_FORMAT_BGR_565:
+ case IEP_FORMAT_RGB_565:
+ case IEP_FORMAT_YCbCr_422_P:
+ case IEP_FORMAT_YCbCr_422_SP:
+ case IEP_FORMAT_YCrCb_422_P:
+ case IEP_FORMAT_YCrCb_422_SP:
+ datalen = mr->dst_w * mr->dst_h * 2;
+ dst.v_addr = phy_dst + mr->dst_w * mr->dst_h + mr->dst_w * mr->dst_h / 2;
+ break;
+ case IEP_FORMAT_YCbCr_420_P:
+ case IEP_FORMAT_YCbCr_420_SP:
+ case IEP_FORMAT_YCrCb_420_P:
+ case IEP_FORMAT_YCrCb_420_SP:
+ datalen = mr->dst_w * mr->dst_h * 3 / 2;
+ dst.v_addr = phy_dst + mr->dst_w * mr->dst_h + mr->dst_w * mr->dst_h / 4;
+ break;
+ default:
+ ;
+ }
+
+ dst.act_w = mr->dst_w;
+ dst.act_h = mr->dst_h;
+ dst.x_off = 0;
+ dst.y_off = 0;
+ dst.vir_w = mr->dst_w;
+ dst.vir_h = mr->dst_h;
+ dst.format = mr->dst_fmt;
+ dst.mem_addr = phy_dst;
+ dst.uv_addr = phy_dst + mr->dst_w * mr->dst_h;
+
+ api->init(&src, &dst);
+
+ switch (mr->testcase) {
+ case TEST_CASE_DENOISE:
+ {
+ FILE *cfgfile = fopen(mr->cfg_url, "r");
+
+ if (cfgfile == NULL) {
+ api->config_yuv_denoise();
+ } else {
+ ;
+ }
+ }
+ break;
+ case TEST_CASE_YUVENHANCE:
+ {
+ FILE *cfgfile = fopen(mr->cfg_url, "r");
+
+ if (cfgfile == NULL) {
+ api->config_yuv_enh();
+ } else {
+ iep_param_YUV_color_enhance_t yuvparam;
+ parse_cfg_file(cfgfile, &yuvparam);
+ api->config_yuv_enh(&yuvparam);
+ fclose(cfgfile);
+ }
+ }
+ break;
+ case TEST_CASE_RGBENHANCE:
+ {
+ FILE *cfgfile = fopen(mr->cfg_url, "r");
+
+ if (cfgfile == NULL) {
+ api->config_color_enh();
+ } else {
+ iep_param_RGB_color_enhance_t rgbparam;
+ parse_cfg_file(cfgfile, &rgbparam);
+ api->config_color_enh(&rgbparam);
+ fclose(cfgfile);
+ }
+ }
+ break;
+ case TEST_CASE_DEINTERLACE:
+ {
+ iep_img src1;
+ iep_img dst1;
+ iep_param_yuv_deinterlace_t yuv_dil;
+
+ fread(vir_src + datalen, 1, datalen, srcfile);
+
+ src1.act_w = mr->src_w;
+ src1.act_h = mr->src_h;
+ src1.x_off = 0;
+ src1.y_off = 0;
+ src1.vir_w = mr->src_w;
+ src1.vir_h = mr->src_h;
+ src1.format = mr->src_fmt;
+ src1.mem_addr = phy_src + datalen;
+ src1.uv_addr = phy_src + datalen + mr->src_w * mr->src_h;
+
+ dst1.act_w = mr->dst_w;
+ dst1.act_h = mr->dst_h;
+ dst1.x_off = 0;
+ dst1.y_off = 0;
+ dst1.vir_w = mr->dst_w;
+ dst1.vir_h = mr->dst_h;
+ dst1.format = mr->dst_fmt;
+ dst1.mem_addr = phy_dst + datalen;
+ dst1.uv_addr = phy_dst + datalen + mr->dst_w * mr->dst_h;
+
+ FILE *cfgfile = fopen(mr->cfg_url, "r");
+
+ if (cfgfile == NULL) {
+ yuv_dil.high_freq_en = 1;
+ yuv_dil.dil_mode = IEP_DEINTERLACE_MODE_I4O1;
+ yuv_dil.field_order = FIELD_ORDER_BOTTOM_FIRST;
+ yuv_dil.dil_ei_mode = 0;
+ yuv_dil.dil_ei_smooth = 0;
+ yuv_dil.dil_ei_sel = 0;
+ yuv_dil.dil_ei_radius = 0;
+ } else {
+ parse_cfg_file(cfgfile, &yuv_dil);
+ fclose(cfgfile);
+ }
+
+ api->config_yuv_deinterlace(&yuv_dil, &src1, &dst1);
+ }
+ break;
+ default:
+ ;
+ }
+
+#if 0
+ iep_param_direct_path_interface_t dpi;
+
+ dpi.enable = 1;
+ dpi.off_x = 0;
+ dpi.off_y = 0;
+ dpi.width = mr->dst_w;
+ dpi.height = mr->dst_h;
+ dpi.layer = 1;
+
+ if (0 > api->config_direct_lcdc_path(&dpi)) {
+ ALOGE("Failure to Configure DIRECT LCDC PATH\n");
+ }
+#endif
+
+ if (0 == api->run_sync()) {
+ ALOGD("%d success\n", getpid());
+ } else {
+ ALOGE("%d failure\n", getpid());
+ }
+
+ ALOGD("%s consume %lld\n", __func__, GetTime() - intime);
+
+ fwrite(vir_dst, 1, datalen, dstfile);
+
+ fclose(srcfile);
+ fclose(dstfile);
+
+ iep_interface::reclaim(api);
+
+ return NULL;
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+ pthread_t td;
+ int ch;
+
+ int pmem_phy_head;
+ uint8_t *pmem_vir_head;
+
+ VPUMemLinear_t vpumem;
+ mem_region_t mr;
+
+ mr.src_fmt = IEP_FORMAT_YCbCr_420_SP;
+ mr.src_w = 640;
+ mr.src_h = 480;
+
+ mr.dst_fmt = IEP_FORMAT_YCbCr_420_SP;
+ mr.dst_w = 640;
+ mr.dst_h = 480;
+
+ /// get options
+ opterr = 0;
+ while ((ch = getopt(argc, argv, "f:w:h:c:F:W:H:C:t:x:")) != -1) {
+ switch (ch) {
+ case 'w':
+ mr.src_w = atoi(optarg);
+ break;
+ case 'h':
+ mr.src_h = atoi(optarg);
+ break;
+ case 'c':
+ if (strcmp(optarg, "argb8888") == 0) {
+ mr.src_fmt = IEP_FORMAT_ARGB_8888;
+ } else if (strcmp(optarg, "abgr8888") == 0) {
+ mr.src_fmt = IEP_FORMAT_ABGR_8888;
+ } else if (strcmp(optarg, "rgba8888") == 0) {
+ mr.src_fmt = IEP_FORMAT_BGRA_8888;
+ } else if (strcmp(optarg, "bgra8888") == 0) {
+ mr.src_fmt = IEP_FORMAT_BGRA_8888;
+ } else if (strcmp(optarg, "rgb565") == 0) {
+ mr.src_fmt = IEP_FORMAT_RGB_565;
+ } else if (strcmp(optarg, "bgr565") == 0) {
+ mr.src_fmt = IEP_FORMAT_BGR_565;
+ } else if (strcmp(optarg, "yuv422sp") == 0) {
+ mr.src_fmt = IEP_FORMAT_YCbCr_422_SP;
+ } else if (strcmp(optarg, "yuv422p") == 0) {
+ mr.src_fmt = IEP_FORMAT_YCbCr_422_P;
+ } else if (strcmp(optarg, "yuv420sp") == 0) {
+ mr.src_fmt = IEP_FORMAT_YCbCr_420_SP;
+ } else if (strcmp(optarg, "yuv420p") == 0) {
+ mr.src_fmt = IEP_FORMAT_YCbCr_420_P;
+ } else if (strcmp(optarg, "yvu422sp") == 0) {
+ mr.src_fmt = IEP_FORMAT_YCrCb_422_SP;
+ } else if (strcmp(optarg, "yvu422p") == 0) {
+ mr.src_fmt = IEP_FORMAT_YCrCb_422_P;
+ } else if (strcmp(optarg, "yvu420sp") == 0) {
+ mr.src_fmt = IEP_FORMAT_YCrCb_420_SP;
+ } else if (strcmp(optarg, "yvu420p") == 0) {
+ mr.src_fmt = IEP_FORMAT_YCrCb_420_P;
+ }
+ break;
+ case 'W':
+ mr.dst_w = atoi(optarg);
+ break;
+ case 'H':
+ mr.dst_h = atoi(optarg);
+ break;
+ case 'C':
+ if (strcmp(optarg, "argb8888") == 0) {
+ mr.dst_fmt = IEP_FORMAT_ARGB_8888;
+ } else if (strcmp(optarg, "abgr8888") == 0) {
+ mr.dst_fmt = IEP_FORMAT_ABGR_8888;
+ } else if (strcmp(optarg, "rgba8888") == 0) {
+ mr.dst_fmt = IEP_FORMAT_BGRA_8888;
+ } else if (strcmp(optarg, "bgra8888") == 0) {
+ mr.dst_fmt = IEP_FORMAT_BGRA_8888;
+ } else if (strcmp(optarg, "rgb565") == 0) {
+ mr.dst_fmt = IEP_FORMAT_RGB_565;
+ } else if (strcmp(optarg, "bgr565") == 0) {
+ mr.dst_fmt = IEP_FORMAT_BGR_565;
+ } else if (strcmp(optarg, "yuv422sp") == 0) {
+ mr.dst_fmt = IEP_FORMAT_YCbCr_422_SP;
+ } else if (strcmp(optarg, "yuv422p") == 0) {
+ mr.dst_fmt = IEP_FORMAT_YCbCr_422_P;
+ } else if (strcmp(optarg, "yuv420sp") == 0) {
+ mr.dst_fmt = IEP_FORMAT_YCbCr_420_SP;
+ } else if (strcmp(optarg, "yuv420p") == 0) {
+ mr.dst_fmt = IEP_FORMAT_YCbCr_420_P;
+ } else if (strcmp(optarg, "yvu422sp") == 0) {
+ mr.dst_fmt = IEP_FORMAT_YCrCb_422_SP;
+ } else if (strcmp(optarg, "yvu422p") == 0) {
+ mr.dst_fmt = IEP_FORMAT_YCrCb_422_P;
+ } else if (strcmp(optarg, "yvu420sp") == 0) {
+ mr.dst_fmt = IEP_FORMAT_YCrCb_420_SP;
+ } else if (strcmp(optarg, "yvu420p") == 0) {
+ mr.dst_fmt = IEP_FORMAT_YCrCb_420_P;
+ }
+ break;
+ case 'f':
+ ALOGD("input filename: %s\n", optarg);
+ strcpy(mr.src_url, optarg);
+ break;
+ case 'F':
+ ALOGD("output filename: %s\n", optarg);
+ strcpy(mr.dst_url, optarg);
+ break;
+ case 't':
+ if (strcmp(optarg, "denoise") == 0) {
+ mr.testcase = TEST_CASE_DENOISE;
+ } else if (strcmp(optarg, "yuvenhance") == 0) {
+ mr.testcase = TEST_CASE_YUVENHANCE;
+ } else if (strcmp(optarg, "rgbenhance") == 0) {
+ mr.testcase = TEST_CASE_RGBENHANCE;
+ } else if (strcmp(optarg, "deinterlace") == 0) {
+ mr.testcase = TEST_CASE_DEINTERLACE;
+ } else {
+ mr.testcase = TEST_CASE_NONE;
+ }
+ break;
+ case 'x':
+ ALOGD("configure filename: %s\n", optarg);
+ strcpy(mr.cfg_url, optarg);
+ break;
+ default:
+ ;
+ }
+ }
+
+
+ /// allocate in/out memory and initialize memory address
+ VPUMallocLinear(&vpumem, 12<<20);
+
+ pmem_phy_head = vpumem.phy_addr;//region.offset;
+ pmem_vir_head = (uint8_t*)vpumem.vir_addr;
+
+ mr.len_reg = 0x100;
+ mr.len_src = 5<<20;
+ mr.len_dst = 5<<20;
+
+ mr.phy_reg = vpumem.phy_addr;
+ pmem_phy_head += mr.len_reg;
+ mr.phy_src = pmem_phy_head;
+ pmem_phy_head += mr.len_src;
+ mr.phy_dst = pmem_phy_head;
+ pmem_phy_head += mr.len_dst;
+
+ mr.vir_reg = (uint8_t*)vpumem.vir_addr;
+ pmem_vir_head += mr.len_reg;
+ mr.vir_src = pmem_vir_head;
+ pmem_vir_head += mr.len_src;
+ mr.vir_dst = pmem_vir_head;
+ pmem_vir_head += mr.len_dst;
+
+ pthread_create(&td, NULL, iep_process_thread, &mr);
+
+ pthread_join(td, NULL);
+
+ VPUFreeLinear(&vpumem);
+
+ return 0;
+}
+
|