summaryrefslogtreecommitdiff
path: root/imgp
diff options
context:
space:
mode:
authorYoungHun Kim <yh8004.kim@samsung.com>2012-08-21 21:24:45 +0900
committerYoungHun Kim <yh8004.kim@samsung.com>2012-08-21 21:24:45 +0900
commitbe5403d5c62de8963eed132d4358a768c3810428 (patch)
tree3888e74ae0e9cf5f4d6b4cd156a26f1c7054363a /imgp
parent4a2aab80077345c78eaa492dd20f4fd95598d74f (diff)
downloadlibmm-utility-master.tar.gz
libmm-utility-master.tar.bz2
libmm-utility-master.zip
Diffstat (limited to 'imgp')
-rwxr-xr-ximgp/include/mm_util_imgp.h21
-rwxr-xr-ximgp/mm_util_imgp.c229
-rwxr-xr-ximgp/test/mm_util_imgp_testsuite.c253
3 files changed, 371 insertions, 132 deletions
diff --git a/imgp/include/mm_util_imgp.h b/imgp/include/mm_util_imgp.h
index dc7de34..20e4055 100755
--- a/imgp/include/mm_util_imgp.h
+++ b/imgp/include/mm_util_imgp.h
@@ -157,8 +157,27 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
unsigned char *dst, unsigned int *dst_width, unsigned int *dst_height, mm_util_img_rotate_type angle);
/**
- @}
+ * This function crop the source image.
+ *
+ * @param src [in] pointer of source image data
+ * @param src_width [in] pixel size of source image width
+ * @param src_height [in] pixel size of source image height
+ * @param src_format [in] pixel format of source image
+ * @param crop_start_x [in] pixel point of cropped image
+ * @param crop_start_y [in] pixel point of cropped image
+ * @param crop_dest_width [in/out] cropped image width (value is changed when yuv image width is odd)
+ * @param crop_dest_height [in/out] cropped image height
+
+ * @param dst [in/out] pointer of destination image data
+ *
+ * @return This function returns zero on success, or negative value with error code.
+ * @remark
+ * @see mm_util_img_format, mm_util_img_rotate_type
+ * @since R1, 1.0
*/
+int
+mm_util_crop_image(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_width, unsigned int *crop_dest_height, unsigned char *dst);
#ifdef __cplusplus
}
diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c
index d281235..148151f 100755
--- a/imgp/mm_util_imgp.c
+++ b/imgp/mm_util_imgp.c
@@ -32,12 +32,13 @@
#define GEN_MASK(x) ((1<<(x))-1)
#define ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) & ~GEN_MASK(x))
#define DIV_ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) >> (x))
+#define GST "gstcs"
typedef gboolean(*IMGPInfoFunc) (imgp_info_s*, imgp_plugin_type_e);
/*########################################################################################*/
#define setup_image_size_I420(width, height) { \
int size=0; \
- size = (MM_UTIL_ROUND_UP_4 (width) * MM_UTIL_ROUND_UP_2 (height) + MM_UTIL_ROUND_UP_8 (width) * MM_UTIL_ROUND_UP_2 (height) /2); \
+ size = (MM_UTIL_ROUND_UP_4 (width) * MM_UTIL_ROUND_UP_2 (height) + MM_UTIL_ROUND_UP_4 (width) * MM_UTIL_ROUND_UP_2 (height) /2); \
return size; \
}
@@ -143,7 +144,7 @@ _mm_setup_image_size(const char* _format_label, int width, int height)
}else if(strcmp(_format_label, "Y444") == 0) {
setup_image_size_Y444(width, height); //width * height *3;
}else if(strcmp(_format_label, "YV12") == 0) {
- setup_image_size_YV12(width, height); //width * height *1;
+ setup_image_size_YV12(width, height); //width * height *1.5; width must be 8 multiple
}else if(strcmp(_format_label, "NV12") == 0) {
setup_image_size_NV12(width, height) //width * height *1.5;
}else if(strcmp(_format_label, "ST12") == 0) {
@@ -204,6 +205,39 @@ _mm_cannot_convert_format(mm_util_img_format src_format, mm_util_img_format dst_
}
static gboolean
+_mm_gst_can_resize_format(char* __format_label)
+{
+ gboolean _bool = FALSE;
+ mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] Format label: %s", __func__, __LINE__,__format_label);
+ if(strcmp(__format_label, "AYUV") == 0
+ || strcmp(__format_label, "UYVY") == 0 ||strcmp(__format_label, "Y800") == 0 || strcmp(__format_label, "I420") == 0 || strcmp(__format_label, "YV12") == 0
+ || strcmp(__format_label, "RGB888") == 0 || strcmp(__format_label, "RGB565") == 0 || strcmp(__format_label, "BGR888") == 0 || strcmp(__format_label, "RGBA8888") == 0
+ || strcmp(__format_label, "ARGB8888") == 0 ||strcmp(__format_label, "BGRA8888") == 0 ||strcmp(__format_label, "ABGR8888") == 0 ||strcmp(__format_label, "RGBX") == 0
+ ||strcmp(__format_label, "XRGB") == 0 ||strcmp(__format_label, "BGRX") == 0 ||strcmp(__format_label, "XBGR") == 0 ||strcmp(__format_label, "Y444") == 0
+ ||strcmp(__format_label, "Y42B") == 0 ||strcmp(__format_label, "YUY2") == 0 ||strcmp(__format_label, "YUYV") == 0 ||strcmp(__format_label, "UYVY") == 0
+ ||strcmp(__format_label, "Y41B") == 0 ||strcmp(__format_label, "Y16") == 0 ||strcmp(__format_label, "Y800") == 0 ||strcmp(__format_label, "Y8") == 0
+ ||strcmp(__format_label, "GREY") == 0 ||strcmp(__format_label, "AY64") == 0 || strcmp(__format_label, "YUV422") == 0) {
+
+ _bool=TRUE;
+ }
+ return _bool;
+}
+
+static gboolean
+_mm_gst_can_rotate_format(const char* __format_label)
+{
+ gboolean _bool = FALSE;
+ mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] Format label: %s boolean: %d", __func__, __LINE__,__format_label, _bool);
+ if(strcmp(__format_label, "I420") == 0 ||strcmp(__format_label, "YV12") == 0 || strcmp(__format_label, "IYUV") == 0
+ || strcmp(__format_label, "RGB888") == 0||strcmp(__format_label, "BGR888") == 0 ||strcmp(__format_label, "RGBA8888") == 0
+ || strcmp(__format_label, "ARGB8888") == 0 ||strcmp(__format_label, "BGRA8888") == 0 ||strcmp(__format_label, "ABGR8888") == 0 ) {
+ _bool=TRUE;
+ }
+ mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] boolean: %d", __func__, __LINE__,_bool);
+ return _bool;
+}
+
+static gboolean
_mm_select_convert_plugin(mm_util_img_format src_format, mm_util_img_format dst_format )
{
gboolean _bool=FALSE;
@@ -337,7 +371,7 @@ _mm_set_format_label(char* format_label, mm_util_img_format _format)
}
if(_format == MM_UTIL_IMG_FMT_YUV420) {
- strncpy(format_label, "I420", IMAGE_FORMAT_LABEL_BUFFER_SIZE);
+ strncpy(format_label, "YV12", IMAGE_FORMAT_LABEL_BUFFER_SIZE);
}else if(_format == MM_UTIL_IMG_FMT_YUV422) {
strncpy(format_label, "Y42B", IMAGE_FORMAT_LABEL_BUFFER_SIZE);
}else if(_format == MM_UTIL_IMG_FMT_I420) {
@@ -451,7 +485,7 @@ _mm_util_imgp_initialize(imgp_plugin_type_e _imgp_plugin_type_e)
mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] %s | %s module open failed", __func__, __LINE__, PATH_NEON_LIB, PATH_GSTCS_LIB);
return NULL;
}
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] module: %p, g_module_name: %s", __func__, __LINE__, module, g_module_name (module));
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] module: %p, g_module_name: %s", __func__, __LINE__, module, g_module_name (module));
return module;
}
@@ -506,6 +540,108 @@ _mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s)
return ret;
}
+static int
+_mm_util_crop_rgba32(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst)
+{
+ int ret = MM_ERROR_NONE;
+ int i;
+ int start_x = (src_width - crop_dest_width) / 2;
+ int start_y = (src_height - crop_dest_height) / 2;
+ int src_bytesperline = src_width * 4;
+ int dst_bytesperline = crop_dest_width * 4;
+
+ src += start_y * src_bytesperline + 3 * start_x;
+
+ for (i = 0; i < crop_dest_height; i++) {
+ memcpy(dst, src, dst_bytesperline);
+ src += src_bytesperline;
+ dst += dst_bytesperline;
+ }
+
+ return ret;
+}
+
+static int
+_mm_util_crop_rgb888(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst)
+{
+ int ret = MM_ERROR_NONE;
+ int i;
+ int start_x = (src_width - crop_dest_width) / 2;
+ int start_y = (src_height - crop_dest_height) / 2;
+ int src_bytesperline = src_width * 3;
+ int dst_bytesperline = crop_dest_width * 3;
+
+ src += start_y * src_bytesperline + 3 * start_x;
+
+ for (i = 0; i < crop_dest_height; i++) {
+ memcpy(dst, src, dst_bytesperline);
+ src += src_bytesperline;
+ dst += dst_bytesperline;
+ }
+
+ return ret;
+}
+
+static int
+_mm_util_crop_rgb565(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst)
+{
+ int ret = MM_ERROR_NONE;
+ int i;
+ int start_x = (src_width - crop_dest_width) / 2;
+ int start_y = (src_height - crop_dest_height) / 2;
+ int src_bytesperline = src_width * 2;
+ int dst_bytesperline = crop_dest_width * 2;
+
+ src += start_y * src_bytesperline + 3 * start_x;
+
+ for (i = 0; i < crop_dest_height; i++) {
+ memcpy(dst, src, dst_bytesperline);
+ src += src_bytesperline;
+ dst += dst_bytesperline;
+ }
+
+ return ret;
+}
+
+static int
+_mm_util_crop_yuv420(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst)
+{
+ int ret = MM_ERROR_NONE;
+ int i;
+ int start_x = ((src_width - crop_dest_width) / 2) & ~1;
+ int start_y = ((src_height - crop_dest_height) / 2) & ~1;
+ unsigned char *_src = src + start_y * src_width + start_x;
+
+ /* Y */
+ for (i = 0; i < crop_dest_height; i++) {
+ memcpy(dst, _src, crop_dest_width);
+ _src += src_width;
+ dst += crop_dest_width;
+ }
+
+ /* U */
+ _src = src + src_height * src_width + (start_y / 2) * src_width / 2 + start_x / 2;
+ for (i = 0; i < crop_dest_height / 2; i++) {
+ memcpy(dst, _src, crop_dest_width / 2);
+ _src += src_width / 2;
+ dst += crop_dest_width / 2;
+ }
+
+ /* V */
+ _src = src + src_height * src_width * 5 / 4 + (start_y / 2) * src_width / 2 + start_x / 2;
+ for (i = 0; i < crop_dest_height / 2; i++) {
+ memcpy(dst, _src, crop_dest_width / 2);
+ _src += src_width / 2;
+ dst += crop_dest_width / 2;
+ }
+
+ return ret;
+}
+
EXPORT_API int
mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format, unsigned char *dst, mm_util_img_format dst_format)
{
@@ -535,7 +671,7 @@ mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned
imgp_info_s* _imgp_info_s=(imgp_info_s*)malloc(sizeof(imgp_info_s));
unsigned int dst_size=0;
- IMGPInfoFunc _mm_util_imgp_func = NULL;
+ IMGPInfoFunc _mm_util_imgp_func = NULL;
GModule *_module = NULL;
imgp_plugin_type_e _imgp_plugin_type_e=-1;
@@ -550,7 +686,7 @@ mm_util_convert_colorspace(unsigned char *src, unsigned int src_width, unsigned
if(_module == NULL) { //when IMGP_NEON is NULL
_imgp_plugin_type_e = IMGP_GSTCS;
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] You use %s module", __func__, __LINE__, PATH_GSTCS_LIB);
- _module = _mm_util_imgp_initialize(_imgp_plugin_type_e);
+ _module = _mm_util_imgp_initialize(_imgp_plugin_type_e);
}
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] _mm_util_imgp_func: %p", __func__, __LINE__, _module);
ret=_mm_set_imgp_info_s(_imgp_info_s, src, src_format, src_width, src_height, dst_format, src_width, src_height, MM_UTIL_ROTATE_0);
@@ -634,7 +770,7 @@ mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int sr
{
_imgp_plugin_type_e = IMGP_GSTCS;
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] You use %s module", __func__, __LINE__, PATH_GSTCS_LIB);
- _module = _mm_util_imgp_initialize(_imgp_plugin_type_e);
+ _module = _mm_util_imgp_initialize(_imgp_plugin_type_e);
}
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] _mm_set_imgp_info_s", __func__, __LINE__);
ret=_mm_set_imgp_info_s(_imgp_info_s, src, src_format, src_width, src_height, src_format, *dst_width, *dst_height, MM_UTIL_ROTATE_0);
@@ -645,6 +781,14 @@ mm_util_resize_image(unsigned char *src, unsigned int src_width, unsigned int sr
}
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Sucess _mm_set_imgp_info_s", __func__, __LINE__);
+ if(g_strrstr(g_module_name (_module), GST)) {
+ if(_mm_gst_can_resize_format(_imgp_info_s->input_format_label) == FALSE) {
+ mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] #RESIZE ERROR# IMAGE_NOT_SUPPORT_FORMAT", __func__, __LINE__);
+ _mm_util_imgp_finalize(_module, _imgp_info_s);
+ return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
+ }
+ }
+
/* image processing */
_mm_util_imgp_func = _mm_util_imgp_process(_module);
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Sucess _mm_util_imgp_process", __func__, __LINE__);
@@ -714,8 +858,8 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] #START#", __func__, __LINE__);
imgp_info_s* _imgp_info_s=(imgp_info_s*)malloc(sizeof(imgp_info_s));
unsigned int dst_size=0;
- IMGPInfoFunc _mm_util_imgp_func = NULL;
- GModule *_module = NULL;
+ IMGPInfoFunc _mm_util_imgp_func = NULL;
+ GModule *_module = NULL;
imgp_plugin_type_e _imgp_plugin_type_e=-1;
/* Initialize */
@@ -724,12 +868,12 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
}else {
_imgp_plugin_type_e = IMGP_GSTCS;
}
- _module = _mm_util_imgp_initialize(_imgp_plugin_type_e);
+ _module = _mm_util_imgp_initialize(_imgp_plugin_type_e);
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] _mm_util_imgp_func: %p", __func__, __LINE__, _module);
if(_module == NULL) { //when IMGP_NEON is NULL
_imgp_plugin_type_e = IMGP_GSTCS;
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] You use %s module", __func__, __LINE__, PATH_GSTCS_LIB);
- _module = _mm_util_imgp_initialize(_imgp_plugin_type_e);
+ _module = _mm_util_imgp_initialize(_imgp_plugin_type_e);
}
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] _mm_set_imgp_info_s", __func__, __LINE__);
ret=_mm_confirm_dst_width_height(src_width, src_height, dst_width, dst_height, angle);
@@ -746,6 +890,14 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
}
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Sucess _mm_set_imgp_info_s", __func__, __LINE__);
+ if(g_strrstr(g_module_name (_module), GST)) {
+ if(_mm_gst_can_rotate_format(_imgp_info_s->input_format_label) == FALSE) {
+ mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] #gstreamer ROTATE ERROR# IMAGE_NOT_SUPPORT_FORMAT", __func__, __LINE__);
+ _mm_util_imgp_finalize(_module, _imgp_info_s);
+ return MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT;
+ }
+ }
+
/* image processing */
_mm_util_imgp_func = _mm_util_imgp_process(_module);
mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Sucess _mm_util_imgp_process", __func__, __LINE__);
@@ -780,6 +932,61 @@ mm_util_rotate_image(unsigned char *src, unsigned int src_width, unsigned int sr
}
EXPORT_API int
+mm_util_crop_image(unsigned char *src, unsigned int src_width, unsigned int src_height, mm_util_img_format src_format,
+unsigned int crop_start_x, unsigned int crop_start_y, unsigned int *crop_dest_width, unsigned int *crop_dest_height, unsigned char *dst)
+{
+ int ret = MM_ERROR_NONE;
+
+ if (!src || !dst) {
+ mmf_debug (MMF_DEBUG_ERROR, "[%s][%05d] invalid argument\n", __func__, __LINE__);
+ return MM_ERROR_IMAGE_INVALID_VALUE;
+ }
+
+ if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) ) {
+ mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] #ERROR# src_format value", __func__, __LINE__);
+ return MM_ERROR_IMAGE_INVALID_VALUE;
+ }
+
+ if( (*crop_dest_width < 0) || (*crop_dest_height < 0) || (crop_start_x +*crop_dest_width > src_width) || (crop_start_y +*crop_dest_height > src_height) ) {
+ mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] #ERROR# dest width | height value", __func__, __LINE__);
+ return MM_ERROR_IMAGE_INVALID_VALUE;
+ }
+
+ switch (src_format) {
+ case MM_UTIL_IMG_FMT_RGB888: {
+ ret = _mm_util_crop_rgb888(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ break;
+ }
+ case MM_UTIL_IMG_FMT_RGB565: {
+ ret = _mm_util_crop_rgb565(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ break;
+ }
+ case MM_UTIL_IMG_FMT_ARGB8888:
+ case MM_UTIL_IMG_FMT_BGRA8888:
+ case MM_UTIL_IMG_FMT_RGBA8888:
+ case MM_UTIL_IMG_FMT_BGRX8888: {
+ ret = _mm_util_crop_rgba32(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ break;
+ }
+ case MM_UTIL_IMG_FMT_I420:
+ case MM_UTIL_IMG_FMT_YUV420: {
+ if( (*crop_dest_width %2) !=0 ) {
+ mmf_debug(MMF_DEBUG_WARNING, "[%s][%05d] #YUV Width value(%d) must be even at least# ", __func__, __LINE__, *crop_dest_width);
+ *crop_dest_width = ((*crop_dest_width+1)>>1)<<1;
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Image isplay is suceeded when YUV crop width value %d ", __func__, __LINE__,*crop_dest_width);
+ }
+
+ ret = _mm_util_crop_yuv420(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ break;
+ }
+ default:
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Not supported format", __func__, __LINE__);
+ }
+
+ return ret;
+}
+
+EXPORT_API int
mm_util_get_image_size(mm_util_img_format format, unsigned int width, unsigned int height, unsigned int *imgsize)
{
int ret = MM_ERROR_NONE;
diff --git a/imgp/test/mm_util_imgp_testsuite.c b/imgp/test/mm_util_imgp_testsuite.c
index 1a62b3b..ebf528d 100755
--- a/imgp/test/mm_util_imgp_testsuite.c
+++ b/imgp/test/mm_util_imgp_testsuite.c
@@ -22,142 +22,155 @@
#include <stdlib.h>
#include "mm_util_imgp.h"
+#include "mm_util_imgp_internal.h"
#include "mm_log.h"
#include "mm_debug.h"
#include <mm_ta.h>
#include <unistd.h>
-#define _ROTATE_ 1
+#include <mm_error.h>
+#define _CROP_ 0
+#define _ROTATE_ 0
#define _RESIZE_ 0
-#define _CONVERT_ 0
+#define _CONVERT_ 1
#define ONE_ALL 0
int main(int argc, char *argv[])
{
- unsigned char *src = NULL;
- unsigned char *dst = NULL;
- unsigned int src_width = 0;
- unsigned int src_height = 0;
- unsigned int dst_width = 0;
- unsigned int dst_height = 0;
- char output_file[25];
- unsigned int src_size = 0;
- unsigned int dst_size = 0;
- if (argc < 6) {
- mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] Usage: ./mm_image_testsuite filename [yuv420 | yuv420p | yuv422 | uyvy | vyuy | nv12 | nv12t | rgb565 | rgb888 | argb | jpeg] width height\n", __func__, __LINE__);
- exit (0);
- }
+ unsigned char *src = NULL;
+ unsigned char *dst = NULL;
+ unsigned int src_width = 0;
+ unsigned int src_height = 0;
+ unsigned int dst_width = 0;
+ unsigned int dst_height = 0;
+ char output_file[25];
+ unsigned int src_size = 0;
+ unsigned int dst_size = 0;
+ int src_cs;
+ int dst_cs;
+ int ret = 0;
+ int cnt = 0;
+ char fmt[IMAGE_FORMAT_LABEL_BUFFER_SIZE];
+
+ if (argc < 6) {
+ mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] Usage: ./mm_image_testsuite filename [yuv420 | yuv420p | yuv422 | uyvy | vyuy | nv12 | nv12t | rgb565 | rgb888 | argb | jpeg] width height\n", __func__, __LINE__);
+ exit (0);
+ }
- int src_cs =atoi(argv[6]);
- #if _CONVERT_
- int dst_cs = atoi(argv[7]);
- #endif
- #if _ROTATE_
- mm_util_img_rotate_type angle = atoi(argv[8]);
- #endif
- int ret = 0;
- int cnt = 0;
-
- MMTA_INIT();
- #if ONE_ALL
- while(cnt++ < 10000) {
- #endif
- FILE *fp = fopen(argv[1], "r");
-
- src_width = atoi(argv[2]);
- src_height = atoi(argv[3]);
-
- dst_width = atoi(argv[4]);
- dst_height = atoi(argv[5]);
-
- mm_util_get_image_size(src_cs, src_width, src_height, &src_size);
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] convert src buffer size=%d\n", __func__, __LINE__, src_size);
- src = malloc(src_size);
- fread(src, 1, src_size, fp);
-
-#if _ROTATE_
- mm_util_get_image_size(src_cs, dst_width, dst_height, &dst_size);
- dst = malloc(dst_size);
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] dst: %p", __func__, __LINE__, dst);
-
- __ta__("mm_util_rotate_image",
- ret = mm_util_rotate_image(src, src_width, src_height, src_cs, dst, &dst_width, &dst_height, angle);
- );
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] mm_util_rotate_image dst: %p ret = %d\n", __func__, __LINE__, dst, ret);
- //free(src);
- #if _RESIZE_ || _CONVERT_
- src = dst;
- #endif
-#endif
-#if _RESIZE_
- //scale 1/2
-
- #if _ROTATE_
- src_width = dst_width;
- src_height = dst_height;
- #endif
- dst_width = src_width/2;
- dst_height = src_height/2;
- mm_util_get_image_size(src_cs, dst_width, dst_height, &dst_size);
- dst = malloc(dst_size);
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] dst: %p", __func__, __LINE__, dst);
-
- __ta__("mm_util_resize_image",
- ret = mm_util_resize_image(src, src_width, src_height, src_cs, dst, &dst_width, &dst_height);
- );
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] mm_util_resize_image dst: %p ret = %d", __func__, __LINE__, dst, ret);
- //free(src);
- #if _CONVERT_ && !_ROTATE_
- src = dst;
- #endif
+#if _CROP_
+ src_cs =atoi(argv[4]);
+ dst_cs = src_cs;
+ unsigned int crop_start_x = atoi(argv[5]);
+ unsigned int crop_start_y = atoi(argv[6]);
+ dst_width = atoi(argv[7]);
+ dst_height = atoi(argv[8]);
+#else
+ src_cs =atoi(argv[6]);
+ #if _CONVERT_
+ dst_cs = atoi(argv[7]);
+ #else
+ dst_cs = src_cs;
+ #endif
+
+ #if _ROTATE_
+ mm_util_img_rotate_type angle = atoi(argv[8]);
+ #endif
+
+ MMTA_INIT();
+ #if ONE_ALL
+ while(cnt++ < 10000) {
+ #endif
+
+ dst_width = atoi(argv[4]);
+ dst_height = atoi(argv[5]);
#endif
-#if _CONVERT_
- #if !(_ROTATE_ && _RESIZE_)
- dst_width = src_width;
- dst_height = src_height;
- #endif
- mm_util_get_image_size(dst_cs, dst_width, dst_height, &dst_size);
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] convert dst buffer size=%d\n", __func__, __LINE__, dst_size);
- dst = malloc(dst_size);
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] dst: %p", __func__, __LINE__, dst);
-
- __ta__("mm_util_convert_colorspace",
- ret = mm_util_convert_colorspace(src, src_width, src_height, src_cs, dst, dst_cs);
- );
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] mm_util_convert_colorspace dst:%p ret = %d",__func__, __LINE__, dst, ret);
- MMTA_ACUM_ITEM_END("colorspace", 0);
- MMTA_ACUM_ITEM_SHOW_RESULT();
- MMTA_RELEASE ();
-#endif
- if(ret==0) {
- if(cnt == 0) {
- sprintf(output_file, "result%d_%dx%d.rgb", cnt, dst_width, dst_height);
- FILE *fpout = fopen(output_file, "w");
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] %s = %dx%d dst_size: %d", __func__, __LINE__, output_file, src_width, src_height, dst_size);
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] mm_util_convert_colorspace dst:%p ret = %d",__func__, __LINE__, dst, ret);
- fwrite(dst, 1, dst_size, fpout);
- fflush(fpout);
- if(fpout) fclose(fpout);
+ src_width = atoi(argv[2]);
+ src_height = atoi(argv[3]);
+
+ FILE *fp = fopen(argv[1], "r");
+ ret = mm_util_get_image_size(src_cs, src_width, src_height, &src_size);
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] convert src buffer size=%d\n", __func__, __LINE__, src_size);
+ src = malloc(src_size);
+ fread(src, 1, src_size, fp);
+
+ ret = mm_util_get_image_size(dst_cs, dst_width, dst_height, &dst_size);
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] dst_cs: %d dst_width: %d dst_height: %d dst buffer size=%d\n", __func__, __LINE__, dst_cs, dst_width, dst_height, dst_size);
+ dst = malloc(dst_size);
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] dst: %p", __func__, __LINE__, dst);
+
+ #if _CROP_
+ __ta__("mm_util_crop_image",
+ ret = mm_util_crop_image(src, src_width, src_height, src_cs, crop_start_x, crop_start_y, &dst_width, &dst_height, dst);
+ );
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] mm_util_crop_image dst: %p ret = %d\n", __func__, __LINE__, dst, ret);
+ #endif
+
+ #if _ROTATE_
+ __ta__("mm_util_rotate_image",
+ ret = mm_util_rotate_image(src, src_width, src_height, src_cs, dst, &dst_width, &dst_height, angle);
+ );
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] mm_util_rotate_image dst: %p ret = %d\n", __func__, __LINE__, dst, ret);
+ #endif
+
+ #if _RESIZE_
+ __ta__("mm_util_resize_image",
+ ret = mm_util_resize_image(src, src_width, src_height, src_cs, dst, &dst_width, &dst_height);
+ );
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] mm_util_resize_image dst: %p ret = %d", __func__, __LINE__, dst, ret);
+ #endif
+
+ #if _CONVERT_
+ __ta__("mm_util_convert_colorspace",
+ ret = mm_util_convert_colorspace(src, src_width, src_height, src_cs, dst, dst_cs);
+ );
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] mm_util_convert_colorspace dst:%p ret = %d",__func__, __LINE__, dst, ret);
+ MMTA_ACUM_ITEM_END("colorspace", 0);
+ MMTA_ACUM_ITEM_SHOW_RESULT();
+ MMTA_RELEASE ();
+ #endif
+ FILE *fpout;
+
+ if(ret==MM_ERROR_NONE) {
+ if(cnt == 0) {
+ if(dst_cs ==MM_UTIL_IMG_FMT_YUV420 || dst_cs == MM_UTIL_IMG_FMT_YUV422 ||dst_cs == MM_UTIL_IMG_FMT_I420
+ || dst_cs == MM_UTIL_IMG_FMT_NV12 || dst_cs == MM_UTIL_IMG_FMT_UYVY ||dst_cs == MM_UTIL_IMG_FMT_YUYV) {
+ strncpy(fmt, "yuv", IMAGE_FORMAT_LABEL_BUFFER_SIZE);
+ } else {
+ strncpy(fmt,"rgb", IMAGE_FORMAT_LABEL_BUFFER_SIZE);
}
+ sprintf(output_file, "result%d_%dx%d.%s", cnt, dst_width, dst_height, fmt);
+ fpout = fopen(output_file, "w");
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] %s = %dx%d dst_size: %d", __func__, __LINE__, output_file, dst_width, dst_height, dst_size);
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] dst:%p ret = %d",__func__, __LINE__, dst, ret);
+ fwrite(dst, 1, dst_size, fpout);
+ fflush(fpout);
}
if(fp) {
- fclose(fp);
- }
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] src: %p",__func__, __LINE__, src);
- if(src) {
- free(src); src = NULL;
- }
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] dst: %p",__func__, __LINE__,dst);
- if(dst) {
- free(dst); dst = NULL;
- }
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Success - free src & dst",__func__, __LINE__);
+ fclose(fp);
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] fclose(fp) fp: 0x%2x",__func__, __LINE__, fp);
+ }
- #if ONE_ALL
- mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] cnt: %d",__func__, __LINE__, cnt);
- }
- #endif
+ if(fpout) {
+ fclose(fpout);
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] fclose(fp) fpout: 0x%2x",__func__, __LINE__, fpout);
+ }
+
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] src: %p",__func__, __LINE__, src);
+ if(src) {
+ free(src); src = NULL;
+ }
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] dst: %p",__func__, __LINE__,dst);
+ if(dst) {
+ free(dst); dst = NULL;
+ }
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Success - free src & dst",__func__, __LINE__);
+
+ #if ONE_ALL
+ mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] cnt: %d",__func__, __LINE__, cnt);
+ }
+ #endif
+ }
- return ret;
+ return ret;
}