ret = MM_UTIL_ERROR_NONE;
error:
- if(screen_buffer) {
- if(screen_buffer[0])
+ if (screen_buffer) {
+ if (screen_buffer[0])
(void)free(screen_buffer[0]);
for (i = 1; i < GifFile->SHeight; i++) {
- if(screen_buffer[i])
+ if (screen_buffer[i])
(void)free(screen_buffer[i]);
}
(void)free(screen_buffer);
{
mm_util_debug("Enter _convert_hsv_to_rgb");
- CvMat *mat1 = cvCreateMat(1,1,CV_8UC3);
+ CvMat *mat1 = cvCreateMat(1, 1 , CV_8UC3);
cvSet2D(mat1, 0, 0, cvScalar((double)hVal, (double)sVal, (double)vVal, 0.0));
- CvMat *mat2 = cvCreateMat(1,1,CV_8UC3);
+ CvMat *mat2 = cvCreateMat(1, 1, CV_8UC3);
cvCvtColor(mat1, mat2, CV_HSV2BGR);
int vVal = 0;
float rVal = 0.f;
- float gVal = 0.f;
- float bVal = 0.f;
+ float gVal = 0.f;
+ float bVal = 0.f;
unsigned int maxBinVal = 0;
int max_bin_idx[3] = {-1, -1, -1};
return MM_UTIL_ERROR_INVALID_OPERATION;
}
- IplImage *planes [] = {hImg, sImg, vImg};
+ IplImage *planes[] = {hImg, sImg, vImg};
cvCvtColor(handle->inImg, hsvImg, CV_RGB2HSV);
cvSplit(hsvImg, hImg, sImg, vImg, NULL);
cvCalcHist(planes, hist, 0, NULL);
- for (nh=0; nh<(handle->hBins); nh++) {
- for (ns=0; ns<(handle->sBins); ns++) {
- for (nv=0; nv<(handle->vBins); nv++) {
- unsigned int binVal = (unsigned int)cvGetReal3D( (hist)->bins, nh, ns, nv);
+ for (nh = 0; nh < (handle->hBins); nh++) {
+ for (ns = 0; ns < (handle->sBins); ns++) {
+ for (nv = 0; nv < (handle->vBins); nv++) {
+ unsigned int binVal = (unsigned int)cvGetReal3D((hist)->bins, nh, ns, nv);
if (binVal > maxBinVal) {
maxBinVal = binVal;
max_bin_idx[0] = nh;
unsigned char *img_buffer;
unsigned int img_buffer_size;
- char filename [MAX_FILENAME_LEN];
+ char filename[MAX_FILENAME_LEN];
if (argc < 1) {
fprintf(stderr, "Usage: ./mm_imgcv_testsuite filename(jpg format only)\n");
#define MM_UTIL_ROUND_UP_8(num) (((num)+7)&~7)
#define MM_UTIL_ROUND_UP_16(num) (((num)+15)&~15)
#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 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*, const unsigned char*, unsigned char*, imgp_plugin_type_e);
static int check_valid_picture_size(int width, int height)
{
- if((int)width>0 && (int)height>0 && (width+128)*(unsigned long long)(height+128) < INT_MAX/4) {
+ if ((int)width > 0 && (int)height > 0 && (width + 128)*(unsigned long long)(height + 128) < INT_MAX/4) {
return MM_UTIL_ERROR_NONE;
}
{
int i = 0;
- for(i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i++) {
IMGP_FREE(buffer[i]);
}
}
-static gboolean __mm_cannot_convert_format(mm_util_img_format src_format, mm_util_img_format dst_format )
+static gboolean __mm_cannot_convert_format(mm_util_img_format src_format, mm_util_img_format dst_format)
{
- gboolean _bool=FALSE;
+ gboolean _bool = FALSE;
mm_util_debug("src_format: %d, dst_format:%d", src_format, dst_format);
- if((dst_format == MM_UTIL_IMG_FMT_NV16) || (dst_format == MM_UTIL_IMG_FMT_NV61) ||
+ if ((dst_format == MM_UTIL_IMG_FMT_NV16) || (dst_format == MM_UTIL_IMG_FMT_NV61) ||
((src_format == MM_UTIL_IMG_FMT_YUV422) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
((src_format == MM_UTIL_IMG_FMT_NV12) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
((src_format == MM_UTIL_IMG_FMT_UYVY) && (dst_format == MM_UTIL_IMG_FMT_NV12_TILED)) ||
((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_YUYV)) ||
((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_RGBA8888)) ||
- ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_BGRX8888)) ) {
+ ((src_format == MM_UTIL_IMG_FMT_NV12_TILED) && (dst_format == MM_UTIL_IMG_FMT_BGRX8888))) {
_bool = TRUE;
}
{
gboolean _bool = FALSE;
- mm_util_debug("Format label: %s",__format_label);
+ mm_util_debug("Format label: %s", __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
+ 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, "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;
+ _bool = TRUE;
}
return _bool;
mm_util_debug("Format label: %s boolean: %d", __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 ) {
+ 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;
+ _bool = TRUE;
}
- mm_util_debug("boolean: %d",_bool);
+ mm_util_debug("boolean: %d", _bool);
return _bool;
}
-static gboolean __mm_select_convert_plugin(mm_util_img_format src_format, mm_util_img_format dst_format )
+static gboolean __mm_select_convert_plugin(mm_util_img_format src_format, mm_util_img_format dst_format)
{
- gboolean _bool=FALSE;
+ gboolean _bool = FALSE;
mm_util_debug("src_format: %d, dst_format:%d", src_format, dst_format);
- if(((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
+ if (((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_NV12)) ||
((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_RGB565)) ||
((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_RGB888)) ||
((src_format == MM_UTIL_IMG_FMT_YUV420) && (dst_format == MM_UTIL_IMG_FMT_ARGB8888)) ||
mm_util_debug("_format: %d (angle: %d)", _format, angle);
if ((_format == MM_UTIL_IMG_FMT_YUV420) || (_format == MM_UTIL_IMG_FMT_I420) || (_format == MM_UTIL_IMG_FMT_NV12)
- ||(_format == MM_UTIL_IMG_FMT_RGB888 ||_format == MM_UTIL_IMG_FMT_RGB565)) {
+ || (_format == MM_UTIL_IMG_FMT_RGB888 || _format == MM_UTIL_IMG_FMT_RGB565)) {
return TRUE;
}
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- switch (format)
- {
+ switch (format) {
case MM_UTIL_IMG_FMT_I420:
case MM_UTIL_IMG_FMT_YUV420:
x_chroma_shift = 1;
y_chroma_shift = 1;
- stride = MM_UTIL_ROUND_UP_4 (width);
- h2 = ROUND_UP_X (height, x_chroma_shift);
+ stride = MM_UTIL_ROUND_UP_4(width);
+ h2 = ROUND_UP_X(height, x_chroma_shift);
size = stride * h2;
- w2 = DIV_ROUND_UP_X (width, x_chroma_shift);
- stride2 = MM_UTIL_ROUND_UP_4 (w2);
- h2 = DIV_ROUND_UP_X (height, y_chroma_shift);
+ w2 = DIV_ROUND_UP_X(width, x_chroma_shift);
+ stride2 = MM_UTIL_ROUND_UP_4(w2);
+ h2 = DIV_ROUND_UP_X(height, y_chroma_shift);
size2 = stride2 * h2;
*imgsize = size + 2 * size2;
break;
case MM_UTIL_IMG_FMT_UYVY:
case MM_UTIL_IMG_FMT_NV16:
case MM_UTIL_IMG_FMT_NV61:
- stride = MM_UTIL_ROUND_UP_4 (width) * 2;
+ stride = MM_UTIL_ROUND_UP_4(width) * 2;
size = stride * height;
*imgsize = size;
break;
case MM_UTIL_IMG_FMT_RGB565:
- stride = MM_UTIL_ROUND_UP_4 (width) * 2;
+ stride = MM_UTIL_ROUND_UP_4(width) * 2;
size = stride * MM_UTIL_ROUND_UP_2(height);
*imgsize = size;
break;
case MM_UTIL_IMG_FMT_RGB888:
- stride = MM_UTIL_ROUND_UP_4 (width) * 3;
+ stride = MM_UTIL_ROUND_UP_4(width) * 3;
size = stride * MM_UTIL_ROUND_UP_2(height);
*imgsize = size;
break;
case MM_UTIL_IMG_FMT_NV12_TILED:
x_chroma_shift = 1;
y_chroma_shift = 1;
- stride = MM_UTIL_ROUND_UP_4 (width);
- h2 = ROUND_UP_X (height, y_chroma_shift);
+ stride = MM_UTIL_ROUND_UP_4(width);
+ h2 = ROUND_UP_X(height, y_chroma_shift);
size = stride * h2;
- w2 = 2 * DIV_ROUND_UP_X (width, x_chroma_shift);
- stride2 = MM_UTIL_ROUND_UP_4 (w2);
- h2 = DIV_ROUND_UP_X (height, y_chroma_shift);
+ w2 = 2 * DIV_ROUND_UP_X(width, x_chroma_shift);
+ stride2 = MM_UTIL_ROUND_UP_4(w2);
+ h2 = DIV_ROUND_UP_X(height, y_chroma_shift);
size2 = stride2 * h2;
*imgsize = size + size2;
break;
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- switch(angle) {
+ switch (angle) {
case MM_UTIL_ROTATE_0:
case MM_UTIL_ROTATE_180:
case MM_UTIL_ROTATE_FLIP_HORZ:
case MM_UTIL_ROTATE_FLIP_VERT:
- if(*dst_width != src_width) {
+ if (*dst_width != src_width) {
mm_util_debug("*dst_width: %d", *dst_width);
*dst_width = src_width;
mm_util_debug("#Confirmed# *dst_width: %d", *dst_width);
}
- if(*dst_height != src_height) {
+ if (*dst_height != src_height) {
mm_util_debug("*dst_height: %d", *dst_height);
*dst_height = src_height;
mm_util_debug("#Confirmed# *dst_height: %d", *dst_height);
break;
case MM_UTIL_ROTATE_90:
case MM_UTIL_ROTATE_270:
- if(*dst_width != src_height) {
+ if (*dst_width != src_height) {
mm_util_debug("*dst_width: %d", *dst_width);
*dst_width = src_height;
mm_util_debug("#Confirmed# *dst_width: %d", *dst_width);
}
- if(*dst_height != src_width) {
+ if (*dst_height != src_width) {
mm_util_debug("*dst_height: %d", *dst_height);
*dst_height = src_width;
mm_util_debug("#Confirmed# *dst_height: %d", *dst_height);
int ret = MM_UTIL_ERROR_NONE;
char *src_fmt_lable = NULL;
char *dst_fmt_lable = NULL;
- if(_imgp_info_s == NULL) {
+ if (_imgp_info_s == NULL) {
mm_util_error("_imgp_info_s: 0x%2x", _imgp_info_s);
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- switch(src_format) {
+ switch (src_format) {
case MM_UTIL_IMG_FMT_YUV420:
src_fmt_lable = (char *)"YV12";
break;
break;
}
- switch(dst_format) {
+ switch (dst_format) {
case MM_UTIL_IMG_FMT_YUV420:
dst_fmt_lable = (char *)"YV12";
break;
break;
}
- if(src_fmt_lable && dst_fmt_lable) {
+ if (src_fmt_lable && dst_fmt_lable) {
mm_util_debug("src_fmt_lable: %s dst_fmt_lable: %s", src_fmt_lable, dst_fmt_lable);
_imgp_info_s->input_format_label = (char*)malloc(strlen(src_fmt_lable) + 1);
- if(_imgp_info_s->input_format_label == NULL) {
+ if (_imgp_info_s->input_format_label == NULL) {
mm_util_error("[input] input_format_label is null");
return MM_UTIL_ERROR_OUT_OF_MEMORY;
}
strncpy(_imgp_info_s->input_format_label, src_fmt_lable, strlen(src_fmt_lable));
_imgp_info_s->output_format_label = (char*)malloc(strlen(dst_fmt_lable) + 1);
- if(_imgp_info_s->output_format_label == NULL) {
+ if (_imgp_info_s->output_format_label == NULL) {
mm_util_error("[input] input_format_label is null");
IMGP_FREE(_imgp_info_s->input_format_label);
return MM_UTIL_ERROR_OUT_OF_MEMORY;
strncpy(_imgp_info_s->output_format_label, dst_fmt_lable, strlen(dst_fmt_lable));
mm_util_debug("input_format_label: %s output_format_label: %s", _imgp_info_s->input_format_label, _imgp_info_s->output_format_label);
- }else {
+ } else {
mm_util_error("[error] src_fmt_lable && dst_fmt_lable");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
{
int ret = MM_UTIL_ERROR_NONE;
- if(_imgp_info_s == NULL) {
+ if (_imgp_info_s == NULL) {
mm_util_error("_imgp_info_s is NULL");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
ret = __mm_set_format_label(_imgp_info_s, src_format, dst_format);
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("[input] mm_set_format_label error");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
_imgp_info_s->src_format = src_format;
_imgp_info_s->src_width = src_width;
- _imgp_info_s->src_height= src_height;
+ _imgp_info_s->src_height = src_height;
_imgp_info_s->dst_format = dst_format;
_imgp_info_s->dst_width = dst_width;
_imgp_info_s->dst_height = dst_height;
_imgp_info_s->buffer_size = 0;
- _imgp_info_s->angle= angle;
+ _imgp_info_s->angle = angle;
mm_util_debug("[input] format label: %s width: %d height: %d [output] format label: %s width: %d height: %d rotation_value: %d",
_imgp_info_s->input_format_label, _imgp_info_s->src_width, _imgp_info_s->src_height,
GModule *module = NULL;
mm_util_fenter();
- if( _imgp_plugin_type_e == IMGP_NEON ) {
+ if (_imgp_plugin_type_e == IMGP_NEON) {
module = g_module_open(PATH_NEON_LIB, G_MODULE_BIND_LAZY);
- }else if( _imgp_plugin_type_e == IMGP_GSTCS) {
+ } else if (_imgp_plugin_type_e == IMGP_GSTCS) {
module = g_module_open(PATH_GSTCS_LIB, G_MODULE_BIND_LAZY);
}
- if( module == NULL ) {
+ if (module == NULL) {
mm_util_error("%s | %s module open failed", PATH_NEON_LIB, PATH_GSTCS_LIB);
return NULL;
}
- mm_util_debug("module: %p, g_module_name: %s", module, g_module_name (module));
+ mm_util_debug("module: %p, g_module_name: %s", module, g_module_name(module));
return module;
}
IMGPInfoFunc mm_util_imgp_func = NULL;
mm_util_fenter();
- if(module == NULL) {
+ if (module == NULL) {
mm_util_error("module is NULL");
return NULL;
}
{
int ret = MM_UTIL_ERROR_NONE;
- if(module) {
+ if (module) {
mm_util_debug("module : %p", module);
- g_module_close( module );
+ g_module_close(module);
mm_util_debug("#End g_module_close#");
module = NULL;
- }else {
+ } else {
mm_util_error("#module is NULL#");
ret = MM_UTIL_ERROR_INVALID_PARAMETER;
}
static bool __mm_util_check_resolution(unsigned int width, unsigned int height)
{
- if(width == 0)
- {
+ if (width == 0) {
mm_util_error("invalid width [%d]", width);
return FALSE;
}
- if(height == 0)
- {
+ if (height == 0) {
mm_util_error("invalid height [%d]", height);
return FALSE;
}
{
media_format_mimetype_e mimetype = -1;
- switch(format) {
- case MM_UTIL_IMG_FMT_NV12 :
+ switch (format) {
+ case MM_UTIL_IMG_FMT_NV12:
mimetype = MEDIA_FORMAT_NV12;
break;
- case MM_UTIL_IMG_FMT_NV16 :
+ case MM_UTIL_IMG_FMT_NV16:
mimetype = MEDIA_FORMAT_NV16;
break;
- case MM_UTIL_IMG_FMT_YUYV :
+ case MM_UTIL_IMG_FMT_YUYV:
mimetype = MEDIA_FORMAT_YUYV;
break;
- case MM_UTIL_IMG_FMT_UYVY :
+ case MM_UTIL_IMG_FMT_UYVY:
mimetype = MEDIA_FORMAT_UYVY;
break;
- case MM_UTIL_IMG_FMT_YUV422 :
+ case MM_UTIL_IMG_FMT_YUV422:
mimetype = MEDIA_FORMAT_422P;
break;
- case MM_UTIL_IMG_FMT_I420 :
+ case MM_UTIL_IMG_FMT_I420:
mimetype = MEDIA_FORMAT_I420;
break;
- case MM_UTIL_IMG_FMT_YUV420 :
+ case MM_UTIL_IMG_FMT_YUV420:
mimetype = MEDIA_FORMAT_YV12;
break;
- case MM_UTIL_IMG_FMT_RGB565 :
+ case MM_UTIL_IMG_FMT_RGB565:
mimetype = MEDIA_FORMAT_RGB565;
break;
- case MM_UTIL_IMG_FMT_RGB888 :
+ case MM_UTIL_IMG_FMT_RGB888:
mimetype = MEDIA_FORMAT_RGB888;
break;
- case MM_UTIL_IMG_FMT_RGBA8888 :
+ case MM_UTIL_IMG_FMT_RGBA8888:
mimetype = MEDIA_FORMAT_RGBA;
break;
- case MM_UTIL_IMG_FMT_ARGB8888 :
+ case MM_UTIL_IMG_FMT_ARGB8888:
mimetype = MEDIA_FORMAT_ARGB;
break;
- case MM_UTIL_IMG_FMT_NV12_TILED :
+ case MM_UTIL_IMG_FMT_NV12_TILED:
mimetype = MEDIA_FORMAT_NV12T;
break;
default:
{
mm_util_img_format format = -1;
- switch(mimetype) {
- case MEDIA_FORMAT_NV12 :
+ switch (mimetype) {
+ case MEDIA_FORMAT_NV12:
format = MM_UTIL_IMG_FMT_NV12;
break;
- case MEDIA_FORMAT_NV16 :
+ case MEDIA_FORMAT_NV16:
format = MM_UTIL_IMG_FMT_NV16;
break;
- case MEDIA_FORMAT_YUYV :
+ case MEDIA_FORMAT_YUYV:
format = MM_UTIL_IMG_FMT_YUYV;
break;
- case MEDIA_FORMAT_UYVY :
+ case MEDIA_FORMAT_UYVY:
format = MM_UTIL_IMG_FMT_UYVY;
break;
- case MEDIA_FORMAT_422P :
+ case MEDIA_FORMAT_422P:
format = MM_UTIL_IMG_FMT_YUV422;
break;
- case MEDIA_FORMAT_I420 :
+ case MEDIA_FORMAT_I420:
format = MM_UTIL_IMG_FMT_I420;
break;
- case MEDIA_FORMAT_YV12 :
+ case MEDIA_FORMAT_YV12:
format = MM_UTIL_IMG_FMT_YUV420;
break;
- case MEDIA_FORMAT_RGB565 :
+ case MEDIA_FORMAT_RGB565:
format = MM_UTIL_IMG_FMT_RGB565;
break;
- case MEDIA_FORMAT_RGB888 :
+ case MEDIA_FORMAT_RGB888:
format = MM_UTIL_IMG_FMT_RGB888;
break;
- case MEDIA_FORMAT_RGBA :
+ case MEDIA_FORMAT_RGBA:
format = MM_UTIL_IMG_FMT_RGBA8888;
break;
- case MEDIA_FORMAT_ARGB :
+ case MEDIA_FORMAT_ARGB:
format = MM_UTIL_IMG_FMT_ARGB8888;
break;
- case MEDIA_FORMAT_NV12T :
+ case MEDIA_FORMAT_NV12T:
format = MM_UTIL_IMG_FMT_NV12_TILED;
break;
default:
while (!handle->is_finish) {
end_time = g_get_monotonic_time() + 1 * G_TIME_SPAN_SECOND;
mm_util_debug("waiting...");
- g_mutex_lock (&(handle->thread_mutex));
+ g_mutex_lock(&(handle->thread_mutex));
g_cond_wait_until(&(handle->thread_cond), &(handle->thread_mutex), end_time);
mm_util_debug("<=== get run transform thread signal");
- g_mutex_unlock (&(handle->thread_mutex));
+ g_mutex_unlock(&(handle->thread_mutex));
if (handle->is_finish) {
mm_util_debug("exit loop");
media_packet_h pop_data = (media_packet_h) g_async_queue_try_pop(handle->queue);
- if(!pop_data) {
+ if (!pop_data) {
mm_util_error("[NULL] Queue data");
} else {
ret = __mm_util_transform_exec(handle, pop_data); /* Need to block */
- if(ret == MM_UTIL_ERROR_NONE) {
+ if (ret == MM_UTIL_ERROR_NONE) {
mm_util_debug("Success - transform_exec");
} else{
mm_util_error("Error - transform_exec");
}
- if(handle->_util_cb->completed_cb) {
+ if (handle->_util_cb->completed_cb) {
mm_util_debug("completed_cb");
handle->_util_cb->completed_cb(&handle->dst_packet, ret, handle->_util_cb->user_data);
mm_util_debug("completed_cb %p", &handle->dst);
g_mutex_init(&(handle->thread_mutex));
/*These are a communicator for thread*/
- if(!handle->queue) {
+ if (!handle->queue) {
handle->queue = g_async_queue_new();
} else {
mm_util_error("ERROR - async queue is already created");
/*create threads*/
handle->thread = g_thread_new("transform_thread", (GThreadFunc)_mm_util_thread_repeate, (gpointer)handle);
- if(!handle->thread) {
+ if (!handle->thread) {
mm_util_error("ERROR - create thread");
return MM_UTIL_ERROR_INVALID_OPERATION;
}
mm_util_img_format src_format;
unsigned int src_index = 0, dst_index = 0;
- if(handle == NULL) {
- mm_util_error ("Invalid arguments [tag null]");
+ if (handle == NULL) {
+ mm_util_error("Invalid arguments [tag null]");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(handle->src_packet == NULL) {
- mm_util_error ("[src] media_packet_h");
+ if (handle->src_packet == NULL) {
+ mm_util_error("[src] media_packet_h");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(handle->dst_packet == NULL) {
- mm_util_error ("[dst] media_packet_h");
+ if (handle->dst_packet == NULL) {
+ mm_util_error("[dst] media_packet_h");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(handle->src_buf_size) {
+ if (handle->src_buf_size) {
handle->src = NULL;
- if(media_packet_get_buffer_data_ptr(handle->src_packet, &handle->src) != MM_UTIL_ERROR_NONE) {
- mm_util_error ("[src] media_packet_get_extra");
+ if (media_packet_get_buffer_data_ptr(handle->src_packet, &handle->src) != MM_UTIL_ERROR_NONE) {
+ mm_util_error("[src] media_packet_get_extra");
IMGP_FREE(handle->src);
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
mm_util_debug("src buffer pointer: %p", handle->src);
}
- if(handle->dst_buf_size) {
+ if (handle->dst_buf_size) {
handle->dst = NULL;
- if(media_packet_get_buffer_data_ptr(handle->dst_packet, &handle->dst) != MM_UTIL_ERROR_NONE) {
+ if (media_packet_get_buffer_data_ptr(handle->dst_packet, &handle->dst) != MM_UTIL_ERROR_NONE) {
IMGP_FREE(handle->src);
IMGP_FREE(handle->dst);
- mm_util_error ("[dst] media_packet_get_extra");
+ mm_util_error("[dst] media_packet_get_extra");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
}
src_height = handle->src_height;
src_format = handle->src_format;
if (dst_buf[src_index] == NULL) {
- mm_util_error ("[multi func] memory allocation error");
+ mm_util_error("[multi func] memory allocation error");
IMGP_FREE(handle->src);
IMGP_FREE(handle->dst);
return MM_UTIL_ERROR_INVALID_OPERATION;
mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
dst_buf[dst_index] = g_malloc(dst_buf_size);
if (dst_buf[dst_index] == NULL) {
- mm_util_error ("[multi func] memory allocation error");
+ mm_util_error("[multi func] memory allocation error");
IMGP_FREE(handle->src);
IMGP_FREE(handle->dst);
__mm_destroy_temp_buffer(dst_buf);
mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
dst_buf[dst_index] = g_malloc(dst_buf_size);
if (dst_buf[dst_index] == NULL) {
- mm_util_error ("[multi func] memory allocation error");
+ mm_util_error("[multi func] memory allocation error");
IMGP_FREE(handle->src);
IMGP_FREE(handle->dst);
__mm_destroy_temp_buffer(dst_buf);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
- ret = mm_util_resize_image(dst_buf[src_index], src_width, src_height,src_format, dst_buf[dst_index], &handle->dst_width, &handle->dst_height);
+ ret = mm_util_resize_image(dst_buf[src_index], src_width, src_height, src_format, dst_buf[dst_index], &handle->dst_width, &handle->dst_height);
if (ret != MM_UTIL_ERROR_NONE) {
IMGP_FREE(handle->src);
IMGP_FREE(handle->dst);
mm_util_get_image_size(handle->dst_format, handle->dst_width, handle->dst_height, &dst_buf_size);
dst_buf[dst_index] = g_malloc(dst_buf_size);
if (dst_buf[dst_index] == NULL) {
- mm_util_error ("[multi func] memory allocation error");
+ mm_util_error("[multi func] memory allocation error");
IMGP_FREE(handle->src);
IMGP_FREE(handle->dst);
__mm_destroy_temp_buffer(dst_buf);
if (handle->set_rotate) {
dst_index++;
- if(handle->set_resize || handle->set_crop) {
+ if (handle->set_resize || handle->set_crop) {
unsigned int temp_swap = 0;
- switch(handle->dst_rotation) {
+ switch (handle->dst_rotation) {
case MM_UTIL_ROTATION_90:
case MM_UTIL_ROTATION_270:
temp_swap = handle->dst_width;
mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
dst_buf[dst_index] = g_malloc(dst_buf_size);
if (dst_buf[dst_index] == NULL) {
- mm_util_error ("[multi func] memory allocation error");
+ mm_util_error("[multi func] memory allocation error");
IMGP_FREE(handle->src);
IMGP_FREE(handle->dst);
__mm_destroy_temp_buffer(dst_buf);
unsigned int dst_width = 0, dst_height = 0;
uint64_t size = 0;
- if(media_packet_get_format(src_packet, &src_fmt) != MM_UTIL_ERROR_NONE) {
+ if (media_packet_get_format(src_packet, &src_fmt) != MM_UTIL_ERROR_NONE) {
mm_util_error("Imedia_packet_get_format)");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_get_video_info(src_fmt, &src_mimetype, &src_width, &src_height, &src_avg_bps, &src_max_bps) == MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_get_video_info(src_fmt, &src_mimetype, &src_width, &src_height, &src_avg_bps, &src_max_bps) == MEDIA_FORMAT_ERROR_NONE) {
mm_util_debug("[Fotmat: %d] W x H : %d x %d", src_mimetype, src_width, src_height);
}
- if(__mm_util_check_resolution(src_width, src_height)) {
+ if (__mm_util_check_resolution(src_width, src_height)) {
/* src */
handle->src_packet = src_packet;
mm_util_debug("src_packet: %p handle->src_packet: %p 0x%2x [W X H] %d X %d", src_packet, handle->src_packet, src_fmt, src_width, src_height);
- if(handle->src_packet) {
+ if (handle->src_packet) {
handle->src_format = __mm_util_mapping_mime_format_to_imgp(src_mimetype);
handle->src_width = src_width;
handle->src_height = src_height;
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_packet_get_buffer_size(handle->src_packet, &size) == MM_UTIL_ERROR_NONE) {
+ if (media_packet_get_buffer_size(handle->src_packet, &size) == MM_UTIL_ERROR_NONE) {
handle->src_buf_size = (guint)size;
mm_util_debug("src buffer(%p) %d size: %d", handle->src_packet, handle->src_packet, handle->src_buf_size);
} else {
mm_util_error("Error buffer size");
}
- if(handle->dst_format == MM_UTIL_IMG_FMT_NUM) {
+ if (handle->dst_format == MM_UTIL_IMG_FMT_NUM) {
mm_util_debug("dst format is changed");
handle->dst_format = handle->src_format;
handle->dst_format_mime = src_mimetype;
mm_util_debug("src: %p handle->src_packet: %p (%d),(%d X %d)", src_packet, handle->src_packet, handle->src_packet, handle->src_width, handle->src_height);
if (handle->set_rotate) {
if ((handle->set_crop) || (handle->set_resize)) {
- switch(handle->dst_rotation) {
+ switch (handle->dst_rotation) {
case MM_UTIL_ROTATION_90:
case MM_UTIL_ROTATION_270:
dst_width = handle->dst_height;
break;
}
} else {
- switch(handle->dst_rotation) {
+ switch (handle->dst_rotation) {
case MM_UTIL_ROTATION_90:
case MM_UTIL_ROTATION_270:
dst_width = handle->dst_width = handle->src_height;
}
}
mm_util_debug("dst (%d X %d)", dst_width, dst_height);
- if(media_format_make_writable(src_fmt, &dst_fmt) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_make_writable(src_fmt, &dst_fmt) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(src_fmt);
mm_util_error("[Error] Writable - dst format");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_set_video_mime(dst_fmt, handle->dst_format_mime) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_mime(dst_fmt, handle->dst_format_mime) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(src_fmt);
media_format_unref(dst_fmt);
mm_util_error("[Error] Set - video mime");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_set_video_width(dst_fmt, dst_width) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_width(dst_fmt, dst_width) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(src_fmt);
media_format_unref(dst_fmt);
mm_util_error("[Error] Set - video width");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_set_video_height(dst_fmt, dst_height) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_height(dst_fmt, dst_height) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(src_fmt);
media_format_unref(dst_fmt);
mm_util_error("[Error] Set - video height");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_set_video_avg_bps(dst_fmt, src_avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_avg_bps(dst_fmt, src_avg_bps) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(src_fmt);
media_format_unref(dst_fmt);
mm_util_error("[Error] Set - video avg bps");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_set_video_max_bps(dst_fmt, src_max_bps) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_max_bps(dst_fmt, src_max_bps) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(src_fmt);
media_format_unref(dst_fmt);
mm_util_error("[Error] Set - video max bps");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_packet_create_alloc(dst_fmt, (media_packet_finalize_cb)_mm_util_transform_packet_finalize_callback, NULL, &handle->dst_packet) != MM_UTIL_ERROR_NONE) {
+ if (media_packet_create_alloc(dst_fmt, (media_packet_finalize_cb)_mm_util_transform_packet_finalize_callback, NULL, &handle->dst_packet) != MM_UTIL_ERROR_NONE) {
mm_util_error("[Error] Create allocation memory");
media_format_unref(src_fmt);
media_format_unref(dst_fmt);
return MM_UTIL_ERROR_INVALID_PARAMETER;
} else {
mm_util_debug("Success - dst media packet");
- if(media_packet_get_buffer_size(handle->dst_packet, &size) != MM_UTIL_ERROR_NONE) {
+ if (media_packet_get_buffer_size(handle->dst_packet, &size) != MM_UTIL_ERROR_NONE) {
mm_util_error("Imedia_packet_get_format)");
media_format_unref(src_fmt);
media_format_unref(dst_fmt);
handle->dst_buf_size = (guint)size;
mm_util_debug("handle->src_packet: %p [%d] %d X %d (%d) => handle->dst_packet: %p [%d] %d X %d (%d)",
handle->src_packet, handle->src_format, handle->src_width, handle->src_height, handle->src_buf_size,
- handle->dst_packet, handle->dst_format,dst_width, dst_height, handle->dst_buf_size);
+ handle->dst_packet, handle->dst_format, dst_width, dst_height, handle->dst_buf_size);
}
- }else {
+ } else {
mm_util_error("%d %d", src_width, src_height);
media_format_unref(src_fmt);
return MM_UTIL_ERROR_INVALID_PARAMETER;
ret = __mm_util_processing(handle);
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_util_processing failed");
IMGP_FREE(handle);
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
/* g_thread_exit(handle->thread); */
- if(handle->thread) {
+ if (handle->thread) {
handle->is_finish = TRUE;
- g_mutex_lock (&(handle->thread_mutex));
+ g_mutex_lock(&(handle->thread_mutex));
g_cond_signal(&(handle->thread_cond));
mm_util_debug("===> send signal(finish) to transform_thread");
- g_mutex_unlock (&(handle->thread_mutex));
+ g_mutex_unlock(&(handle->thread_mutex));
g_thread_join(handle->thread);
}
- if(handle->queue) {
+ if (handle->queue) {
g_async_queue_unref(handle->queue);
handle->queue = NULL;
}
TTRACE_BEGIN("MM_UTILITY:IMGP:CREATE");
- if(MMHandle == NULL) {
- mm_util_error ("Invalid arguments [tag null]");
+ if (MMHandle == NULL) {
+ mm_util_error("Invalid arguments [tag null]");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- mm_util_s *handle = calloc(1,sizeof(mm_util_s));
+ mm_util_s *handle = calloc(1, sizeof(mm_util_s));
if (!handle) {
mm_util_error("[ERROR] - _handle");
ret = MM_UTIL_ERROR_INVALID_OPERATION;
}
- ret = __mm_util_handle_init (handle);
- if(ret != MM_UTIL_ERROR_NONE) {
+ ret = __mm_util_handle_init(handle);
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("_mm_util_handle_init failed");
IMGP_FREE(handle);
TTRACE_END();
}
ret = __mm_util_create_thread(handle);
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("ERROR - Create thread");
TTRACE_END();
return ret;
return MM_UTIL_ERROR_INVALID_OPERATION;
}
- if(!src_packet) {
+ if (!src_packet) {
mm_util_error("[ERROR] - src_packet");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
mm_util_debug("src: %p", src_packet);
}
- if(!completed_callback) {
+ if (!completed_callback) {
mm_util_error("[ERROR] - completed_callback");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
IMGP_FREE(handle->_util_cb);
handle->_util_cb = (mm_util_cb_s *)malloc(sizeof(mm_util_cb_s));
- if(handle->_util_cb) {
- handle->_util_cb->completed_cb= completed_callback;
+ if (handle->_util_cb) {
+ handle->_util_cb->completed_cb = completed_callback;
handle->_util_cb->user_data = user_data;
} else {
mm_util_error("[ERROR] _util_cb_s");
}
- if(handle->queue) {
+ if (handle->queue) {
mm_util_debug("g_async_queue_push");
- g_async_queue_push (handle->queue, GINT_TO_POINTER(src_packet));
- g_mutex_lock (&(handle->thread_mutex));
+ g_async_queue_push(handle->queue, GINT_TO_POINTER(src_packet));
+ g_mutex_lock(&(handle->thread_mutex));
g_cond_signal(&(handle->thread_cond));
mm_util_debug("===> send signal to transform_thread");
- g_mutex_unlock (&(handle->thread_mutex));
+ g_mutex_unlock(&(handle->thread_mutex));
}
TTRACE_END();
}
/* Close */
- if(_mm_util_handle_finalize(handle) != MM_UTIL_ERROR_NONE) {
+ if (_mm_util_handle_finalize(handle) != MM_UTIL_ERROR_NONE) {
mm_util_error("_mm_util_handle_finalize)");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
mm_util_debug("[src] 0x%2x (%d x %d) [dst] 0x%2x", src, src_width, src_height, dst);
- imgp_info_s* _imgp_info_s=(imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
+ imgp_info_s* _imgp_info_s = (imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
if (_imgp_info_s == NULL) {
mm_util_error("ERROR - alloc handle");
TTRACE_END();
_module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
mm_util_debug("__mm_util_imgp_initialize: %p", _module);
- if(_module == NULL) { /* when IMGP_NEON is NULL */
+ if (_module == NULL) { /* when IMGP_NEON is NULL */
_imgp_plugin_type_e = IMGP_GSTCS;
mm_util_debug("You use %s module", PATH_GSTCS_LIB);
_module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
mm_util_debug("mm_util_imgp_func: %p", _module);
ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, dst_format, src_width, src_height, MM_UTIL_ROTATE_0);
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_set_imgp_info_s failed");
__mm_util_imgp_finalize(_module, _imgp_info_s);
TTRACE_END();
mm_util_debug("Sucess __mm_util_imgp_process");
if (_mm_util_imgp_func) {
- ret=_mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_CSC);
- if (ret != MM_UTIL_ERROR_NONE)
- {
+ ret = _mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_CSC);
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("image processing failed");
__mm_util_imgp_finalize(_module, _imgp_info_s);
IMGP_FREE(output_buffer);
if ((_imgp_info_s->dst_width != _imgp_info_s->output_stride || _imgp_info_s->dst_height != _imgp_info_s->output_elevation) && __mm_is_rgb_format(src_format)) {
ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, dst_format, 0, 0, &_imgp_info_s->dst_width, &_imgp_info_s->dst_height, dst);
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_util_imgp_finalize failed");
IMGP_FREE(output_buffer);
TTRACE_END();
/* Finalize */
ret = __mm_util_imgp_finalize(_module, _imgp_info_s);
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_util_imgp_finalize failed");
IMGP_FREE(output_buffer);
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if (!dst_width || !dst_height ) {
+ if (!dst_width || !dst_height) {
mm_util_error("#ERROR# dst width/height buffer is NULL");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
mm_util_debug("[src] 0x%2x (%d x %d) [dst] 0x%2x", src, src_width, src_height, dst);
- imgp_info_s* _imgp_info_s=(imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
- if(_imgp_info_s == NULL) {
+ imgp_info_s* _imgp_info_s = (imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
+ if (_imgp_info_s == NULL) {
mm_util_error("ERROR - alloc handle");
TTRACE_END();
return MM_UTIL_ERROR_OUT_OF_MEMORY;
imgp_plugin_type_e _imgp_plugin_type_e = 0;
/* Initialize */
- if(__mm_select_resize_plugin(src_format)) {
+ if (__mm_select_resize_plugin(src_format)) {
_imgp_plugin_type_e = IMGP_NEON;
- }else {
+ } else {
_imgp_plugin_type_e = IMGP_GSTCS;
}
mm_util_debug("plugin type: %d", _imgp_plugin_type_e);
_module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
mm_util_debug("__mm_util_imgp_initialize: %p", _module);
- if(_module == NULL) /* when IMGP_NEON is NULL */
- {
+ /* when IMGP_NEON is NULL */
+ if (_module == NULL) {
_imgp_plugin_type_e = IMGP_GSTCS;
mm_util_debug("You use %s module", PATH_GSTCS_LIB);
_module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
}
mm_util_debug("__mm_set_imgp_info_s");
- ret =__mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, MM_UTIL_ROTATE_0);
- if(ret != MM_UTIL_ERROR_NONE) {
+ ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, MM_UTIL_ROTATE_0);
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_set_imgp_info_s failed [%d]", ret);
__mm_util_imgp_finalize(_module, _imgp_info_s);
TTRACE_END();
mm_util_debug("Sucess __mm_set_imgp_info_s");
- if(g_strrstr(g_module_name (_module), GST)) {
- if(__mm_gst_can_resize_format(_imgp_info_s->input_format_label) == FALSE) {
+ if (g_strrstr(g_module_name(_module), GST)) {
+ if (__mm_gst_can_resize_format(_imgp_info_s->input_format_label) == FALSE) {
mm_util_error("[%s][%05d] #RESIZE ERROR# IMAGE_NOT_SUPPORT_FORMAT");
__mm_util_imgp_finalize(_module, _imgp_info_s);
TTRACE_END();
_mm_util_imgp_func = __mm_util_imgp_process(_module);
mm_util_debug("Sucess __mm_util_imgp_process");
if (_mm_util_imgp_func) {
- ret=_mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_RSZ);
+ ret = _mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_RSZ);
mm_util_debug("_mm_util_imgp_func, ret: %d", ret);
- if (ret != MM_UTIL_ERROR_NONE)
- {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("image processing failed");
__mm_util_imgp_finalize(_module, _imgp_info_s);
IMGP_FREE(output_buffer);
/* Finalize */
ret = __mm_util_imgp_finalize(_module, _imgp_info_s);
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_util_imgp_finalize failed");
IMGP_FREE(output_buffer);
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if ( !dst_width || !dst_height ) {
+ if (!dst_width || !dst_height) {
mm_util_error("#ERROR# dst width/height buffer is NUL");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if ( !src_width || !src_height) {
+ if (!src_width || !src_height) {
mm_util_error("#ERROR# src_width || src_height value is 0 ");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
mm_util_debug("[src] 0x%2x (%d x %d) [dst] 0x%2x", src, src_width, src_height, dst);
- imgp_info_s* _imgp_info_s=(imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
- if(_imgp_info_s == NULL) {
+ imgp_info_s* _imgp_info_s = (imgp_info_s*)g_malloc0(sizeof(imgp_info_s));
+ if (_imgp_info_s == NULL) {
mm_util_error("ERROR - alloc handle");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
imgp_plugin_type_e _imgp_plugin_type_e = 0;
/* Initialize */
- if( __mm_select_rotate_plugin(src_format, src_width, src_height, angle)) {
+ if (__mm_select_rotate_plugin(src_format, src_width, src_height, angle)) {
_imgp_plugin_type_e = IMGP_NEON;
- }else {
+ } else {
_imgp_plugin_type_e = IMGP_GSTCS;
}
mm_util_debug("plugin type: %d", _imgp_plugin_type_e);
_module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
mm_util_debug("__mm_util_imgp_initialize: %p", _module);
- if(_module == NULL) { /* when IMGP_NEON is NULL */
+ if (_module == NULL) { /* when IMGP_NEON is NULL */
_imgp_plugin_type_e = IMGP_GSTCS;
mm_util_debug("You use %s module", PATH_GSTCS_LIB);
_module = __mm_util_imgp_initialize(_imgp_plugin_type_e);
mm_util_debug("__mm_confirm_dst_width_height");
ret = __mm_confirm_dst_width_height(src_width, src_height, dst_width, dst_height, angle);
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("dst_width || dest_height size Error");
__mm_util_imgp_finalize(_module, _imgp_info_s);
TTRACE_END();
ret = __mm_set_imgp_info_s(_imgp_info_s, src_format, src_width, src_height, src_format, *dst_width, *dst_height, angle);
mm_util_debug("__mm_set_imgp_info_s");
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_set_imgp_info_s failed");
__mm_util_imgp_finalize(_module, _imgp_info_s);
TTRACE_END();
}
mm_util_debug("Sucess __mm_set_imgp_info_s");
- if(g_strrstr(g_module_name (_module), GST)) {
- if(__mm_gst_can_rotate_format(_imgp_info_s->input_format_label) == FALSE) {
+ if (g_strrstr(g_module_name(_module), GST)) {
+ if (__mm_gst_can_rotate_format(_imgp_info_s->input_format_label) == FALSE) {
mm_util_error("[%s][%05d] #gstreamer ROTATE ERROR# IMAGE_NOT_SUPPORT_FORMAT");
__mm_util_imgp_finalize(_module, _imgp_info_s);
TTRACE_END();
_mm_util_imgp_func = __mm_util_imgp_process(_module);
mm_util_debug("Sucess __mm_util_imgp_process");
if (_mm_util_imgp_func) {
- ret=_mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_ROT);
- if (ret!= MM_UTIL_ERROR_NONE) {
+ ret = _mm_util_imgp_func(_imgp_info_s, src, output_buffer, IMGP_ROT);
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("image processing failed");
__mm_util_imgp_finalize(_module, _imgp_info_s);
IMGP_FREE(output_buffer);
/* Finalize */
ret = __mm_util_imgp_finalize(_module, _imgp_info_s);
- if(ret != MM_UTIL_ERROR_NONE) {
+ if (ret != MM_UTIL_ERROR_NONE) {
mm_util_error("__mm_util_imgp_finalize failed");
IMGP_FREE(output_buffer);
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM) ) {
+ if ((src_format < MM_UTIL_IMG_FMT_YUV420) || (src_format > MM_UTIL_IMG_FMT_NUM)) {
mm_util_error("#ERROR# src_format value");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (crop_start_x +*crop_dest_width > src_width) || (crop_start_y +*crop_dest_height > src_height) ) {
+ if ((crop_start_x + *crop_dest_width > src_width) || (crop_start_y + *crop_dest_height > src_height)) {
mm_util_error("#ERROR# dest width | height value");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
case MM_UTIL_IMG_FMT_I420:
case MM_UTIL_IMG_FMT_YUV420: {
- if((*crop_dest_width %2) !=0) {
+ if ((*crop_dest_width % 2) != 0) {
mm_util_warn("#YUV Width value(%d) must be even at least# ", *crop_dest_width);
*crop_dest_width = ((*crop_dest_width+1)>>1)<<1;
- mm_util_debug("Image isplay is suceeded when YUV crop width value %d ",*crop_dest_width);
+ mm_util_debug("Image isplay is suceeded when YUV crop width value %d", *crop_dest_width);
}
- if((*crop_dest_height%2) !=0) { /* height value must be also even when crop yuv image */
+ if ((*crop_dest_height % 2) != 0) { /* height value must be also even when crop yuv image */
mm_util_warn("#YUV Height value(%d) must be even at least# ", *crop_dest_height);
*crop_dest_height = ((*crop_dest_height+1)>>1)<<1;
- mm_util_debug("Image isplay is suceeded when YUV crop height value %d ",*crop_dest_height);
+ mm_util_debug("Image isplay is suceeded when YUV crop height value %d", *crop_dest_height);
}
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);
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- switch (format)
- {
+ switch (format) {
case MM_UTIL_IMG_FMT_I420:
case MM_UTIL_IMG_FMT_YUV420:
x_chroma_shift = 1;
y_chroma_shift = 1;
- stride = MM_UTIL_ROUND_UP_4 (width);
- h2 = ROUND_UP_X (height, x_chroma_shift);
+ stride = MM_UTIL_ROUND_UP_4(width);
+ h2 = ROUND_UP_X(height, x_chroma_shift);
size = stride * h2;
- w2 = DIV_ROUND_UP_X (width, x_chroma_shift);
- stride2 = MM_UTIL_ROUND_UP_4 (w2);
- h2 = DIV_ROUND_UP_X (height, y_chroma_shift);
+ w2 = DIV_ROUND_UP_X(width, x_chroma_shift);
+ stride2 = MM_UTIL_ROUND_UP_4(w2);
+ h2 = DIV_ROUND_UP_X(height, y_chroma_shift);
size2 = stride2 * h2;
*imgsize = size + 2 * size2;
break;
case MM_UTIL_IMG_FMT_UYVY:
case MM_UTIL_IMG_FMT_NV16:
case MM_UTIL_IMG_FMT_NV61:
- stride = MM_UTIL_ROUND_UP_4 (width) * 2;
+ stride = MM_UTIL_ROUND_UP_4(width) * 2;
size = stride * height;
*imgsize = size;
break;
case MM_UTIL_IMG_FMT_RGB565:
- stride = MM_UTIL_ROUND_UP_4 (width) * 2;
+ stride = MM_UTIL_ROUND_UP_4(width) * 2;
size = stride * height;
*imgsize = size;
break;
case MM_UTIL_IMG_FMT_RGB888:
- stride = MM_UTIL_ROUND_UP_4 (width) * 3;
+ stride = MM_UTIL_ROUND_UP_4(width) * 3;
size = stride * height;
*imgsize = size;
break;
case MM_UTIL_IMG_FMT_NV12_TILED:
x_chroma_shift = 1;
y_chroma_shift = 1;
- stride = MM_UTIL_ROUND_UP_4 (width);
- h2 = ROUND_UP_X (height, y_chroma_shift);
+ stride = MM_UTIL_ROUND_UP_4(width);
+ h2 = ROUND_UP_X(height, y_chroma_shift);
size = stride * h2;
- w2 = 2 * DIV_ROUND_UP_X (width, x_chroma_shift);
- stride2 = MM_UTIL_ROUND_UP_4 (w2);
- h2 = DIV_ROUND_UP_X (height, y_chroma_shift);
+ w2 = 2 * DIV_ROUND_UP_X(width, x_chroma_shift);
+ stride2 = MM_UTIL_ROUND_UP_4(w2);
+ h2 = DIV_ROUND_UP_X(height, y_chroma_shift);
size2 = stride2 * h2;
*imgsize = size + size2;
break;
int dst_width, dst_height, dst_avg_bps, dst_max_bps;
char *output_fmt = NULL;
- if(error == MM_UTIL_ERROR_NONE) {
+ if (error == MM_UTIL_ERROR_NONE) {
mm_util_debug("completed");
output_fmt = (char*)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
- if(output_fmt) {
- if(media_packet_get_format(*packet, &dst_fmt) != MM_UTIL_ERROR_NONE) {
+ if (output_fmt) {
+ if (media_packet_get_format(*packet, &dst_fmt) != MM_UTIL_ERROR_NONE) {
mm_util_error("Imedia_packet_get_format");
IMGP_FREE(output_fmt);
return FALSE;
}
- if(media_format_get_video_info(dst_fmt, &dst_mimetype, &dst_width, &dst_height, &dst_avg_bps, &dst_max_bps) ==MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_get_video_info(dst_fmt, &dst_mimetype, &dst_width, &dst_height, &dst_avg_bps, &dst_max_bps) == MEDIA_FORMAT_ERROR_NONE) {
memset(output_fmt, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
- if(dst_mimetype ==MEDIA_FORMAT_YV12 || dst_mimetype == MEDIA_FORMAT_422P ||dst_mimetype == MEDIA_FORMAT_I420
- || dst_mimetype == MEDIA_FORMAT_NV12 || dst_mimetype == MEDIA_FORMAT_UYVY ||dst_mimetype == MEDIA_FORMAT_YUYV) {
+ if (dst_mimetype == MEDIA_FORMAT_YV12 || dst_mimetype == MEDIA_FORMAT_422P || dst_mimetype == MEDIA_FORMAT_I420
+ || dst_mimetype == MEDIA_FORMAT_NV12 || dst_mimetype == MEDIA_FORMAT_UYVY || dst_mimetype == MEDIA_FORMAT_YUYV) {
strncpy(output_fmt, "yuv", strlen("yuv"));
} else {
- strncpy(output_fmt,"rgb", strlen("rgb"));
+ strncpy(output_fmt, "rgb", strlen("rgb"));
}
mm_util_debug("[mimetype: %d] W x H : %d x %d", dst_mimetype, dst_width, dst_height);
- snprintf(output_file, 25, "result_%dx%d.%s", dst_width,dst_height, output_fmt);
+ snprintf(output_file, 25, "result_%dx%d.%s", dst_width, dst_height, output_fmt);
}
}
FILE *fpout = fopen(output_file, "w");
- if(fpout) {
+ if (fpout) {
media_packet_get_buffer_size(*packet, &size);
void *dst = NULL;
- if(media_packet_get_buffer_data_ptr(*packet, &dst) != MM_UTIL_ERROR_NONE) {
+ if (media_packet_get_buffer_data_ptr(*packet, &dst) != MM_UTIL_ERROR_NONE) {
IMGP_FREE(dst);
IMGP_FREE(output_fmt);
fclose(fpout);
- mm_util_error ("[dst] media_packet_get_extra");
+ mm_util_error("[dst] media_packet_get_extra");
return FALSE;
}
mm_util_debug("dst: %p [%d]", dst, size);
}
/* Create Transform */
- ret = mm_util_create (&MMHandle);
- if(ret == MM_UTIL_ERROR_NONE) {
+ ret = mm_util_create(&MMHandle);
+ if (ret == MM_UTIL_ERROR_NONE) {
mm_util_debug("Success - Create Transcode Handle [MMHandle: 0x%2x]", MMHandle);
} else {
mm_util_debug("ERROR - Create Transcode Handle");
handle = (mm_util_s*) MMHandle;
media_format_h fmt;
- if(media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) {
- if(media_format_set_video_mime(fmt, MEDIA_FORMAT_I420) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_mime(fmt, MEDIA_FORMAT_I420) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(fmt);
mm_util_error("[Error] Set - video mime");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_set_video_width(fmt, 320) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_width(fmt, 320) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(fmt);
mm_util_error("[Error] Set - video width");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_set_video_height(fmt, 240) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_height(fmt, 240) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(fmt);
mm_util_error("[Error] Set - video height");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_set_video_avg_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_avg_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(fmt);
mm_util_error("[Error] Set - video avg bps");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(media_format_set_video_max_bps(fmt, 20000000) != MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_set_video_max_bps(fmt, 20000000) != MEDIA_FORMAT_ERROR_NONE) {
media_format_unref(fmt);
mm_util_error("[Error] Set - video max bps");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
mm_util_debug("media_format_set_video_info success! w:320, h:240, MEDIA_FORMAT_I420\n");
- }
- else {
+ } else {
mm_util_error("media_format_create failed...");
}
ret = media_packet_create_alloc(fmt, (media_packet_finalize_cb)packet_finalize_callback, NULL, &src_packet);
- if(ret == MM_UTIL_ERROR_NONE) {
+ if (ret == MM_UTIL_ERROR_NONE) {
mm_util_debug("Success - Create Media Packet(%p)", src_packet);
- uint64_t size =0;
+ uint64_t size = 0;
if (media_packet_get_buffer_size(src_packet, &size) == MEDIA_PACKET_ERROR_NONE) {
ptr = malloc(size);
if (ptr == NULL) {
mm_util_debug("\tmemory allocation failed\n");
return MM_UTIL_ERROR_INVALID_OPERATION;
}
- if(fread(src, 1, (int)size, fp)) {
+ if (fread(src, 1, (int)size, fp)) {
mm_util_debug("#Success# fread");
memcpy(ptr, src, (int)size);
mm_util_debug("memcpy");
/* Set Source */
ret = mm_util_set_hardware_acceleration(MMHandle, atoi(argv[2]));
- if(ret == MM_UTIL_ERROR_NONE) {
+ if (ret == MM_UTIL_ERROR_NONE) {
mm_util_debug("Success - Set hardware_acceleration");
} else {
mm_util_debug("ERROR - Set hardware_acceleration");
}
ret = mm_util_set_resolution(MMHandle, 176, 144);
- if(ret == MM_UTIL_ERROR_NONE) {
+ if (ret == MM_UTIL_ERROR_NONE) {
mm_util_debug("Success - Set Convert Info");
} else {
media_format_unref(fmt);
/* Transform */
ret = mm_util_transform(MMHandle, src_packet, (mm_util_completed_callback) transform_completed_cb, handle);
- if(ret == MM_UTIL_ERROR_NONE) {
+ if (ret == MM_UTIL_ERROR_NONE) {
mm_util_debug("Success - Transform");
} else {
media_format_unref(fmt);
while (false == completed) {} // polling
ret = mm_util_destroy(MMHandle);
- if(ret == MM_UTIL_ERROR_NONE) {
+ if (ret == MM_UTIL_ERROR_NONE) {
mm_util_debug("Success - Destroy");
} else {
media_format_unref(fmt);
mm_util_error(fmt" : standard error= [%s]", buf); \
} while (0)
-#define IMG_JPEG_FREE(src) { if(src != NULL) {free(src); src = NULL;} }
+#define IMG_JPEG_FREE(src) { if (src != NULL) {free(src); src = NULL; } }
#if LIBJPEG_TURBO
#define PAD(v, p) ((v+(p)-1)&(~((p)-1)))
-#define _throwtj() {printf("TurboJPEG ERROR:\n%s\n", tjGetErrorStr());}
-#define _tj(f) {if((f)==-1) _throwtj();}
+#define _throwtj() {printf("TurboJPEG ERROR:\n%s\n", tjGetErrorStr()); }
+#define _tj(f) {if ((f) == -1) _throwtj(); }
-const char *subName[TJ_NUMSAMP]={"444", "422", "420", "GRAY", "440"};
+const char *subName[TJ_NUMSAMP] = {"444", "422", "420", "GRAY", "440"};
void initBuf(unsigned char *buf, int w, int h, int pf, int flags)
{
- int roffset=tjRedOffset[pf];
- int goffset=tjGreenOffset[pf];
- int boffset=tjBlueOffset[pf];
- int ps=tjPixelSize[pf];
- int index, row, col, halfway=16;
+ int roffset = tjRedOffset[pf];
+ int goffset = tjGreenOffset[pf];
+ int boffset = tjBlueOffset[pf];
+ int ps = tjPixelSize[pf];
+ int index, row, col, halfway = 16;
memset(buf, 0, w*h*ps);
- if(pf==TJPF_GRAY) {
- for(row=0; row<h; row++) {
- for(col=0; col<w; col++) {
- if(flags&TJFLAG_BOTTOMUP) index=(h-row-1)*w+col;
- else index=row*w+col;
- if(((row/8)+(col/8))%2==0) buf[index]=(row<halfway)? 255:0;
- else buf[index]=(row<halfway)? 76:226;
+ if (pf == TJPF_GRAY) {
+ for (row = 0; row < h; row++) {
+ for (col = 0; col < w; col++) {
+ if (flags&TJFLAG_BOTTOMUP) index = (h-row-1)*w+col;
+ else index = row*w+col;
+ if (((row/8) + (col/8)) % 2 == 0) buf[index] = (row < halfway) ? 255 : 0;
+ else buf[index] = (row < halfway) ? 76 : 226;
}
}
} else {
- for(row=0; row<h; row++) {
- for(col=0; col<w; col++) {
- if(flags&TJFLAG_BOTTOMUP) index=(h-row-1)*w+col;
- else index=row*w+col;
- if(((row/8)+(col/8))%2==0) {
- if(row<halfway) {
- buf[index*ps+roffset]=255;
- buf[index*ps+goffset]=255;
- buf[index*ps+boffset]=255;
+ for (row = 0; row < h; row++) {
+ for (col = 0; col < w; col++) {
+ if (flags&TJFLAG_BOTTOMUP) index = (h-row-1)*w+col;
+ else index = row*w+col;
+ if (((row/8) + (col/8))%2 == 0) {
+ if (row < halfway) {
+ buf[index*ps+roffset] = 255;
+ buf[index*ps+goffset] = 255;
+ buf[index*ps+boffset] = 255;
}
} else {
- buf[index*ps+roffset]=255;
- if(row>=halfway) buf[index*ps+goffset]=255;
+ buf[index*ps+roffset] = 255;
+ if (row >= halfway) buf[index*ps + goffset] = 255;
}
}
}
}
}
-static void
-mm_image_codec_writeJPEG(unsigned char *jpegBuf, unsigned long jpegSize, char *filename)
+static void mm_image_codec_writeJPEG(unsigned char *jpegBuf, unsigned long jpegSize, char *filename)
{
- FILE *file=fopen(filename, "wb");
- if(!file || fwrite(jpegBuf, jpegSize, 1, file)!=1) {
+ FILE *file = fopen(filename, "wb");
+ if (!file || fwrite(jpegBuf, jpegSize, 1, file) != 1) {
mm_util_error("ERROR: Could not write to %s", filename);
mm_util_stderror("ERROR: Could not write");
}
- if(file) fclose(file);
+ if (file) fclose(file);
}
-static void
-_mm_decode_libjpeg_turbo_decompress(tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, int TD_BU,mm_util_jpeg_yuv_data* decoded_data, mm_util_jpeg_yuv_format input_fmt)
+static void _mm_decode_libjpeg_turbo_decompress(tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, int TD_BU, mm_util_jpeg_yuv_data* decoded_data, mm_util_jpeg_yuv_format input_fmt)
{
- int _hdrw=0, _hdrh=0, _hdrsubsamp=-1;
- int scaledWidth=0;
- int scaledHeight=0;
- unsigned long dstSize=0;
- int i=0,n=0;
+ int _hdrw = 0, _hdrh = 0, _hdrsubsamp = -1;
+ int scaledWidth = 0;
+ int scaledHeight = 0;
+ unsigned long dstSize = 0;
+ int i = 0, n = 0;
tjscalingfactor _sf;
- tjscalingfactor*sf=tjGetScalingFactors(&n), sf1={1, 1};
+ tjscalingfactor*sf = tjGetScalingFactors(&n), sf1 = {1, 1};
- if(jpegBuf == NULL) {
+ if (jpegBuf == NULL) {
mm_util_error("jpegBuf is NULL");
return;
}
_tj(tjDecompressHeader2(handle, jpegBuf, jpegSize, &_hdrw, &_hdrh, &_hdrsubsamp));
- if(!sf || !n) {
+ if (!sf || !n) {
mm_util_error(" scaledfactor is NULL");
return;
}
- if((_hdrsubsamp==TJSAMP_444 || _hdrsubsamp==TJSAMP_GRAY) || input_fmt==MM_UTIL_JPEG_FMT_RGB888) {
- _sf= sf[i];
+ if ((_hdrsubsamp == TJSAMP_444 || _hdrsubsamp == TJSAMP_GRAY) || input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
+ _sf = sf[i];
} else {
- _sf=sf1;
+ _sf = sf1;
}
- scaledWidth=TJSCALED(_hdrw, _sf);
- scaledHeight=TJSCALED(_hdrh, _sf);
- mm_util_debug("_hdrw:%d _hdrh:%d, _hdrsubsamp:%d, scaledWidth:%d, scaledHeight:%d", _hdrw, _hdrh, _hdrsubsamp, scaledWidth, scaledHeight);
+ scaledWidth = TJSCALED(_hdrw, _sf);
+ scaledHeight = TJSCALED(_hdrh, _sf);
+ mm_util_debug("_hdrw:%d _hdrh:%d, _hdrsubsamp:%d, scaledWidth:%d, scaledHeight:%d", _hdrw, _hdrh, _hdrsubsamp, scaledWidth, scaledHeight);
- if(input_fmt==MM_UTIL_JPEG_FMT_YUV420 || input_fmt==MM_UTIL_JPEG_FMT_YUV422) {
+ if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422) {
mm_util_debug("JPEG -> YUV %s ... ", subName[_hdrsubsamp]);
- } else if(input_fmt==MM_UTIL_JPEG_FMT_RGB888) {
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
mm_util_debug("JPEG -> RGB %d/%d ... ", _sf.num, _sf.denom);
}
- if(input_fmt==MM_UTIL_JPEG_FMT_YUV420 || input_fmt==MM_UTIL_JPEG_FMT_YUV422) {
- dstSize=TJBUFSIZEYUV(_hdrw, _hdrh, _hdrsubsamp);
- mm_util_debug("MM_UTIL_JPEG_FMT_YUV420 dstSize: %d _hdrsubsamp:%d TJBUFSIZEYUV(w, h, _hdrsubsamp): %d",
+ if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422) {
+ dstSize = TJBUFSIZEYUV(_hdrw, _hdrh, _hdrsubsamp);
+ mm_util_debug("MM_UTIL_JPEG_FMT_YUV420 dstSize: %d _hdrsubsamp:%d TJBUFSIZEYUV(w, h, _hdrsubsamp): %d",
dstSize, _hdrsubsamp, TJBUFSIZEYUV(_hdrw, _hdrh, _hdrsubsamp));
- }
- else if(input_fmt==MM_UTIL_JPEG_FMT_RGB888)
- {
- dstSize=scaledWidth*scaledHeight*tjPixelSize[TJPF_RGB];
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
+ dstSize = scaledWidth*scaledHeight*tjPixelSize[TJPF_RGB];
mm_util_debug("MM_UTIL_JPEG_FMT_RGB888 dstSize: %d _hdrsubsamp:%d", dstSize, _hdrsubsamp);
}
- if((decoded_data->data=(void*)malloc(dstSize))==NULL) {
+ if ((decoded_data->data = (void*)malloc(dstSize)) == NULL) {
mm_util_error("dstBuf is NULL");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
mm_util_debug("dstBuf:%p", decoded_data->data);
- if(input_fmt==MM_UTIL_JPEG_FMT_YUV420 || input_fmt==MM_UTIL_JPEG_FMT_YUV422) {
+ if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422) {
_tj(tjDecompressToYUV(handle, jpegBuf, jpegSize, decoded_data->data, TD_BU));
mm_util_debug("MM_UTIL_JPEG_FMT_YUV420, dstBuf: %d", decoded_data->data);
- decoded_data->format=input_fmt;
- }
- else if(input_fmt==MM_UTIL_JPEG_FMT_RGB888) {
+ decoded_data->format = input_fmt;
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
_tj(tjDecompress2(handle, jpegBuf, jpegSize, decoded_data->data, scaledWidth, 0, scaledHeight, TJPF_RGB, TD_BU));
mm_util_debug("MM_UTIL_JPEG_FMT_RGB888, dstBuf: %p", decoded_data->data);
- decoded_data->format=MM_UTIL_JPEG_FMT_RGB888;
+ decoded_data->format = MM_UTIL_JPEG_FMT_RGB888;
} else {
mm_util_error("[%s][%05d] We can't support the IMAGE format");
return;
}
- decoded_data->size=dstSize;
- if(input_fmt==MM_UTIL_JPEG_FMT_RGB888)
- {
- decoded_data->width=scaledWidth;
- decoded_data->height=scaledHeight;
+ decoded_data->size = dstSize;
+ if (input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
+ decoded_data->width = scaledWidth;
+ decoded_data->height = scaledHeight;
decoded_data->size = dstSize;
- }
- else if(input_fmt==MM_UTIL_JPEG_FMT_YUV420 ||input_fmt==MM_UTIL_JPEG_FMT_YUV422)
- {
- if(_hdrsubsamp == TJSAMP_422) {
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422) {
+ if (_hdrsubsamp == TJSAMP_422) {
mm_util_debug("_hdrsubsamp == TJSAMP_422", decoded_data->width, _hdrw);
- decoded_data->width=MM_JPEG_ROUND_UP_2(_hdrw);
+ decoded_data->width = MM_JPEG_ROUND_UP_2(_hdrw);
} else {
- if(_hdrw% 4 != 0) {
- decoded_data->width=MM_JPEG_ROUND_UP_4(_hdrw);
+ if (_hdrw % 4 != 0) {
+ decoded_data->width = MM_JPEG_ROUND_UP_4(_hdrw);
} else {
- decoded_data->width=_hdrw;
+ decoded_data->width = _hdrw;
}
}
- if(_hdrsubsamp == TJSAMP_420) {
+ if (_hdrsubsamp == TJSAMP_420) {
mm_util_debug("_hdrsubsamp == TJSAMP_420", decoded_data->width, _hdrw);
- if(_hdrh% 4 != 0) {
- decoded_data->height=MM_JPEG_ROUND_UP_4(_hdrh);
+ if (_hdrh % 4 != 0) {
+ decoded_data->height = MM_JPEG_ROUND_UP_4(_hdrh);
} else {
- decoded_data->height=_hdrh;
+ decoded_data->height = _hdrh;
}
} else {
- decoded_data->height=_hdrh;
+ decoded_data->height = _hdrh;
}
decoded_data->size = dstSize;
}
}
-static int
-mm_image_decode_from_jpeg_file_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decoded_data, const char *pFileName, mm_util_jpeg_yuv_format input_fmt)
+static int mm_image_decode_from_jpeg_file_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decoded_data, const char *pFileName, mm_util_jpeg_yuv_format input_fmt)
{
int iErrorCode = MM_UTIL_ERROR_NONE;
- tjhandle dhandle=NULL;
- unsigned char *srcBuf=NULL;
+ tjhandle dhandle = NULL;
+ unsigned char *srcBuf = NULL;
int jpegSize;
- int TD_BU=0;
+ int TD_BU = 0;
- void *src = fopen(pFileName, "rb" );
- if(src == NULL) {
+ void *src = fopen(pFileName, "rb");
+ if (src == NULL) {
mm_util_error("Error [%s] failed", pFileName);
mm_util_stderror("Error file open failed");
return MM_UTIL_ERROR_NO_SUCH_FILE;
}
- fseek (src, 0, SEEK_END);
+ fseek(src, 0, SEEK_END);
jpegSize = ftell(src);
rewind(src);
- if((dhandle=tjInitDecompress())==NULL) {
+ if ((dhandle = tjInitDecompress()) == NULL) {
fclose(src);
mm_util_error("dhandle=tjInitDecompress()) is NULL");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- srcBuf=(unsigned char *)malloc(sizeof(char) * jpegSize);
- if(srcBuf==NULL) {
+ srcBuf = (unsigned char *)malloc(sizeof(char) * jpegSize);
+ if (srcBuf == NULL) {
fclose(src);
tjDestroy(dhandle);
mm_util_error("srcBuf is NULL");
return MM_UTIL_ERROR_OUT_OF_MEMORY;
}
- fread(srcBuf,1, jpegSize, src);
+ fread(srcBuf, 1, jpegSize, src);
mm_util_debug("srcBuf[0]: 0x%2x, srcBuf[1]: 0x%2x, jpegSize:%d", srcBuf[0], srcBuf[1], jpegSize);
_mm_decode_libjpeg_turbo_decompress(dhandle, srcBuf, jpegSize, TD_BU, decoded_data, input_fmt);
fclose(src);
mm_util_debug("fclose");
- if(dhandle) {
+ if (dhandle) {
tjDestroy(dhandle);
}
- if(srcBuf) {
+ if (srcBuf) {
tjFree(srcBuf);
}
return iErrorCode;
}
-static int
-mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decoded_data, void *src, int size, mm_util_jpeg_yuv_format input_fmt)
+static int mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(mm_util_jpeg_yuv_data * decoded_data, void *src, int size, mm_util_jpeg_yuv_format input_fmt)
{
int iErrorCode = MM_UTIL_ERROR_NONE;
- tjhandle dhandle=NULL;
- unsigned char *srcBuf=NULL;
- int TD_BU=0;
+ tjhandle dhandle = NULL;
+ unsigned char *srcBuf = NULL;
+ int TD_BU = 0;
- if((dhandle=tjInitDecompress())==NULL) {
+ if ((dhandle = tjInitDecompress()) == NULL) {
mm_util_error("dhandle=tjInitDecompress()) is NULL");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- srcBuf=(unsigned char *)malloc(sizeof(char) * size);
- if(srcBuf==NULL) {
+ srcBuf = (unsigned char *)malloc(sizeof(char) * size);
+ if (srcBuf == NULL) {
fclose(src);
tjDestroy(dhandle);
mm_util_error("srcBuf is NULL");
mm_util_debug("srcBuf[0]: 0x%2x, srcBuf[1]: 0x%2x, jpegSize:%d", srcBuf[0], srcBuf[1], size);
_mm_decode_libjpeg_turbo_decompress(dhandle, src, size, TD_BU, decoded_data, input_fmt);
- if(dhandle) {
+ if (dhandle) {
tjDestroy(dhandle);
}
- if(srcBuf) {
+ if (srcBuf) {
tjFree(srcBuf);
}
return iErrorCode;
}
-static void
-_mm_encode_libjpeg_turbo_compress(tjhandle handle, void *src, unsigned char **dstBuf, unsigned long *dstSize, int w, int h, int jpegQual, int flags, mm_util_jpeg_yuv_format fmt)
+static void _mm_encode_libjpeg_turbo_compress(tjhandle handle, void *src, unsigned char **dstBuf, unsigned long *dstSize, int w, int h, int jpegQual, int flags, mm_util_jpeg_yuv_format fmt)
{
- unsigned char *srcBuf=NULL;
- unsigned long jpegSize=0;
+ unsigned char *srcBuf = NULL;
+ unsigned long jpegSize = 0;
- jpegSize=w*h*tjPixelSize[TJPF_RGB];
- srcBuf=(unsigned char *)malloc(jpegSize);
+ jpegSize = w*h*tjPixelSize[TJPF_RGB];
+ srcBuf = (unsigned char *)malloc(jpegSize);
- if(srcBuf==NULL) {
+ if (srcBuf == NULL) {
mm_util_error("srcBuf is NULL");
return;
} else {
mm_util_debug("srcBuf: 0x%2x", srcBuf);
- if(fmt==MM_UTIL_JPEG_FMT_RGB888) {
+ if (fmt == MM_UTIL_JPEG_FMT_RGB888) {
initBuf(srcBuf, w, h, TJPF_RGB, flags);
- } else if(fmt==MM_UTIL_JPEG_FMT_YUV420 || fmt==MM_UTIL_JPEG_FMT_YUV422) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_YUV420 || fmt == MM_UTIL_JPEG_FMT_YUV422) {
initBuf(srcBuf, w, h, TJPF_GRAY, flags);
} else {
IMG_JPEG_FREE(srcBuf);
memcpy(srcBuf, src, jpegSize);
}
- if(*dstBuf && *dstSize>0) memset(*dstBuf, 0, *dstSize);
+ if (*dstBuf && *dstSize > 0) memset(*dstBuf, 0, *dstSize);
mm_util_debug("Done.");
- *dstSize=TJBUFSIZE(w, h);
- if(fmt==MM_UTIL_JPEG_FMT_RGB888) {
+ *dstSize = TJBUFSIZE(w, h);
+ if (fmt == MM_UTIL_JPEG_FMT_RGB888) {
_tj(tjCompress2(handle, srcBuf, w, 0, h, TJPF_RGB, dstBuf, dstSize, TJPF_RGB, jpegQual, flags));
mm_util_debug("*dstSize: %d", *dstSize);
- } else if(fmt==MM_UTIL_JPEG_FMT_YUV420) {
- *dstSize=TJBUFSIZEYUV(w, h, TJSAMP_420);
+ } else if (fmt == MM_UTIL_JPEG_FMT_YUV420) {
+ *dstSize = TJBUFSIZEYUV(w, h, TJSAMP_420);
_tj(tjEncodeYUV2(handle, srcBuf, w, 0, h, TJPF_RGB, *dstBuf, TJSAMP_420, flags));
mm_util_debug("*dstSize: %d \t decode_yuv_subsample: %d TJBUFSIZE(w, h):%d", *dstSize, TJSAMP_420, TJBUFSIZE(w, h));
- } else if(fmt==MM_UTIL_JPEG_FMT_YUV422) {
- *dstSize=TJBUFSIZEYUV(w, h, TJSAMP_422);
+ } else if (fmt == MM_UTIL_JPEG_FMT_YUV422) {
+ *dstSize = TJBUFSIZEYUV(w, h, TJSAMP_422);
_tj(tjEncodeYUV2(handle, srcBuf, w, 0, h, TJPF_RGB, *dstBuf, TJSAMP_422, flags));
mm_util_debug("*dstSize: %d \t decode_yuv_subsample: %d TJBUFSIZE(w, h):%d", *dstSize, TJSAMP_422, TJBUFSIZE(w, h));
} else {
- mm_util_error("fmt:%d is wrong", fmt);
+ mm_util_error("fmt:%d is wrong", fmt);
}
IMG_JPEG_FREE(srcBuf);
}
-static int
-mm_image_encode_to_jpeg_file_with_libjpeg_turbo(char *filename, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
+static int mm_image_encode_to_jpeg_file_with_libjpeg_turbo(char *filename, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
{
int iErrorCode = MM_UTIL_ERROR_NONE;
- tjhandle chandle=NULL;
- unsigned char *dstBuf=NULL;
- unsigned long size=0;
- int TD_BU=0;
- FILE *fout=fopen(filename, "w+");
- if(fout == NULL) {
+ tjhandle chandle = NULL;
+ unsigned char *dstBuf = NULL;
+ unsigned long size = 0;
+ int TD_BU = 0;
+ FILE *fout = fopen(filename, "w+");
+ if (fout == NULL) {
mm_util_error("FILE OPEN FAIL [%s] failed", filename);
mm_util_stderror("FILE OPEN FAIL");
return MM_UTIL_ERROR_NO_SUCH_FILE;
}
mm_util_debug("fmt: %d", fmt);
- size=TJBUFSIZE(width, height);
- if((dstBuf=(unsigned char *)tjAlloc(size))==NULL) {
+ size = TJBUFSIZE(width, height);
+ if ((dstBuf = (unsigned char *)tjAlloc(size)) == NULL) {
fclose(fout);
mm_util_error("dstBuf is NULL");
return MM_UTIL_ERROR_OUT_OF_MEMORY;
}
- if((chandle=tjInitCompress())==NULL) {
+ if ((chandle = tjInitCompress()) == NULL) {
fclose(fout);
tjFree(dstBuf);
mm_util_error("dstBuf is NULL");
mm_util_debug("dstBuf: %p\t size: %d", dstBuf, size);
fwrite(dstBuf, 1, size, fout);
fclose(fout);
- if(chandle) {
+ if (chandle) {
tjDestroy(chandle);
}
- if(dstBuf) {
+ if (dstBuf) {
tjFree(dstBuf);
}
mm_util_debug("Done");
return iErrorCode;
}
-static int
-mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(void **mem, int *csize, void *rawdata, int w, int h, mm_util_jpeg_yuv_format fmt,int quality)
+static int mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(void **mem, int *csize, void *rawdata, int w, int h, mm_util_jpeg_yuv_format fmt, int quality)
{
int iErrorCode = MM_UTIL_ERROR_NONE;
- tjhandle chandle=NULL;
- int TD_BU=0;
+ tjhandle chandle = NULL;
+ int TD_BU = 0;
- *csize=TJBUFSIZE(w, h);
- if(fmt==MM_UTIL_JPEG_FMT_RGB888) {
+ *csize = TJBUFSIZE(w, h);
+ if (fmt == MM_UTIL_JPEG_FMT_RGB888) {
mm_util_debug("MM_UTIL_JPEG_FMT_RGB888 size: %d", *csize);
- }else if(fmt==MM_UTIL_JPEG_FMT_YUV420 ||fmt==MM_UTIL_JPEG_FMT_YUV422) {
- mm_util_debug("TJSAMP_420 ||TJSAMP_422 size: %d",*csize);
- }else {
+ } else if (fmt == MM_UTIL_JPEG_FMT_YUV420 || fmt == MM_UTIL_JPEG_FMT_YUV422) {
+ mm_util_debug("TJSAMP_420 ||TJSAMP_422 size: %d", *csize);
+ } else {
mm_util_error("We can't support the IMAGE format");
return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
}
- if((*mem=(unsigned char *)tjAlloc(*csize))==NULL) {
+ if ((*mem = (unsigned char *)tjAlloc(*csize)) == NULL) {
mm_util_error("dstBuf is NULL");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if((chandle=tjInitCompress())==NULL) {
+ if ((chandle = tjInitCompress()) == NULL) {
tjFree(*mem);
mm_util_error("chandle is NULL");
return MM_UTIL_ERROR_INVALID_PARAMETER;
mm_util_debug("width: %d height: %d, size: %d", w, h, *csize);
_mm_encode_libjpeg_turbo_compress(chandle, rawdata, mem, csize, w, h, quality, TD_BU, fmt);
mm_util_debug("dstBuf: %p &dstBuf:%p size: %d", *mem, mem, *csize);
- if(chandle) {
+ if (chandle) {
tjDestroy(chandle);
}
return iErrorCode;
#endif
/* OPEN SOURCE */
-struct my_error_mgr_s
-{
+struct my_error_mgr_s {
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
} my_error_mgr_s;
JOCTET * buffer; /* start of buffer */
} my_destination_mgr_s;
-typedef struct my_destination_mgr_s * my_dest_ptr;
+typedef struct my_destination_mgr_s * my_dest_ptr;
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
typedef struct my_mem_destination_mgr * my_mem_dest_ptr;
-static void
-my_error_exit (j_common_ptr cinfo)
+static void my_error_exit(j_common_ptr cinfo)
{
my_error_ptr myerr = (my_error_ptr) cinfo->err; /* cinfo->err really points to a my_error_mgr_s struct, so coerce pointer */
- (*cinfo->err->output_message) (cinfo); /* Always display the message. We could postpone this until after returning, if we chose. */
- longjmp(myerr->setjmp_buffer, 1); /* Return control to the setjmp point */
+ (*cinfo->err->output_message) (cinfo); /* Always display the message. We could postpone this until after returning, if we chose. */
+ longjmp(myerr->setjmp_buffer, 1); /* Return control to the setjmp point */
}
static int mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, void *rawdata, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
int i, j, flag, _height;
FILE * fpWriter;
- JSAMPROW y[16],cb[16],cr[16]; /* y[2][5] = color sample of row 2 and pixel column 5; (one plane) */
+ JSAMPROW y[16], cb[16], cr[16]; /* y[2][5] = color sample of row 2 and pixel column 5; (one plane) */
JSAMPARRAY data[3]; /* t[0][2][5] = color sample 0 of row 2 and column 5 */
- if(!pFileName) {
+ if (!pFileName) {
mm_util_error("pFileName");
return MM_UTIL_ERROR_NO_SUCH_FILE;
}
jpeg_stdio_dest(&cinfo, fpWriter);
cinfo.image_width = width;
cinfo.image_height = height;
- if (fmt ==MM_UTIL_JPEG_FMT_YUV420 ||fmt ==MM_UTIL_JPEG_FMT_YUV422 || fmt ==MM_UTIL_JPEG_FMT_UYVY) {
+ if (fmt == MM_UTIL_JPEG_FMT_YUV420 || fmt == MM_UTIL_JPEG_FMT_YUV422 || fmt == MM_UTIL_JPEG_FMT_UYVY) {
mm_util_debug("[mm_image_encode_to_jpeg_file_with_libjpeg] jpeg_stdio_dest for YUV");
mm_util_debug("[Height] %d", height);
_height = MM_JPEG_ROUND_DOWN_16(height);
jpeg_set_defaults(&cinfo);
mm_util_debug("jpeg_set_defaults");
- cinfo.raw_data_in = TRUE; /* Supply downsampled data */
+ cinfo.raw_data_in = TRUE; /* Supply downsampled data */
cinfo.do_fancy_downsampling = FALSE;
cinfo.comp_info[0].h_samp_factor = 2;
- if (fmt ==MM_UTIL_JPEG_FMT_YUV420) {
+ if (fmt == MM_UTIL_JPEG_FMT_YUV420) {
cinfo.comp_info[0].v_samp_factor = 2;
- } else if (fmt ==MM_UTIL_JPEG_FMT_YUV422 || fmt ==MM_UTIL_JPEG_FMT_UYVY) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_YUV422 || fmt == MM_UTIL_JPEG_FMT_UYVY) {
cinfo.comp_info[0].v_samp_factor = 1;
}
cinfo.comp_info[1].h_samp_factor = 1;
jpeg_start_compress(&cinfo, TRUE);
mm_util_debug("jpeg_start_compress");
- if(flag) {
- void *large_rect = malloc (width);
- void *small_rect = malloc (width);
- if(large_rect) {
+ if (flag) {
+ void *large_rect = malloc(width);
+ void *small_rect = malloc(width);
+ if (large_rect) {
memset(large_rect, 0x10, width);
} else {
IMG_JPEG_FREE(small_rect);
mm_util_error("large rectangle memory");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(small_rect) {
+ if (small_rect) {
memset(small_rect, 0x80, width);
} else {
IMG_JPEG_FREE(large_rect);
jpeg_destroy_compress(&cinfo);
mm_util_debug("jpeg_destroy_compress");
- }
+ }
- else if (fmt == MM_UTIL_JPEG_FMT_RGB888 ||fmt == MM_UTIL_JPEG_FMT_GraySacle || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ else if (fmt == MM_UTIL_JPEG_FMT_RGB888 || fmt == MM_UTIL_JPEG_FMT_GraySacle || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
JSAMPROW row_pointer[1];
int iRowStride = 0;
- if(fmt == MM_UTIL_JPEG_FMT_RGB888) {
+ if (fmt == MM_UTIL_JPEG_FMT_RGB888) {
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
mm_util_debug("JCS_RGB");
- } else if(fmt == MM_UTIL_JPEG_FMT_GraySacle) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_GraySacle) {
cinfo.input_components = 1; /* one colour component */
cinfo.in_color_space = JCS_GRAYSCALE;
mm_util_debug("JCS_GRAYSCALE");
- } else if(fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
cinfo.input_components = 4; /* one colour component */
cinfo.in_color_space = JCS_EXT_RGBA;
mm_util_debug("JCS_EXT_RGBA");
- } else if(fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
cinfo.input_components = 4;
cinfo.in_color_space = JCS_EXT_BGRA;
mm_util_debug("JCS_EXT_BGRA");
- } else if(fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
cinfo.input_components = 4;
cinfo.in_color_space = JCS_EXT_ARGB;
mm_util_debug("JCS_EXT_ARGB");
mm_util_debug("jpeg_set_quality");
jpeg_start_compress(&cinfo, TRUE);
mm_util_debug("jpeg_start_compress");
- if(fmt == MM_UTIL_JPEG_FMT_RGB888) {
+ if (fmt == MM_UTIL_JPEG_FMT_RGB888) {
iRowStride = width * 3;
- } else if(fmt == MM_UTIL_JPEG_FMT_GraySacle) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_GraySacle) {
iRowStride = width;
- } else if(fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
iRowStride = width * 4;
}
return iErrorCode;
}
-static int
-mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdata, int width, int height, mm_util_jpeg_yuv_format fmt,int quality)
+static int mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, int *csize, void *rawdata, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
{
int iErrorCode = MM_UTIL_ERROR_NONE;
- JSAMPROW y[16],cb[16],cr[16]; /* y[2][5] = color sample of row 2 and pixel column 5; (one plane) */
- JSAMPARRAY data[3]; /* t[0][2][5] = color sample 0 of row 2 and column 5 */
+ JSAMPROW y[16], cb[16], cr[16]; /* y[2][5] = color sample of row 2 and pixel column 5; (one plane) */
+ JSAMPARRAY data[3]; /* t[0][2][5] = color sample 0 of row 2 and column 5 */
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
mm_util_debug("#Before Enter#, mem: %p\t rawdata:%p\t width: %d\t height: %d\t fmt: %d\t quality: %d"
, mem, rawdata, width, height, fmt, quality);
- if(rawdata == NULL) {
+ if (rawdata == NULL) {
mm_util_error("Exit on error -rawdata");
return MM_UTIL_ERROR_OUT_OF_MEMORY;
}
jpeg_mem_dest(&cinfo, (unsigned char **)mem, &size);
cinfo.image_width = width;
cinfo.image_height = height;
- if (fmt ==MM_UTIL_JPEG_FMT_YUV420 ||fmt ==MM_UTIL_JPEG_FMT_YUV422 || fmt ==MM_UTIL_JPEG_FMT_UYVY) {
+ if (fmt == MM_UTIL_JPEG_FMT_YUV420 || fmt == MM_UTIL_JPEG_FMT_YUV422 || fmt == MM_UTIL_JPEG_FMT_UYVY) {
mm_util_debug("[mm_image_encode_to_jpeg_file_with_libjpeg] jpeg_stdio_dest for YUV");
_height = MM_JPEG_ROUND_DOWN_16(height);
flag = height - _height;
cinfo.do_fancy_downsampling = FALSE;
cinfo.comp_info[0].h_samp_factor = 2;
- if (fmt ==MM_UTIL_JPEG_FMT_YUV420) {
+ if (fmt == MM_UTIL_JPEG_FMT_YUV420) {
cinfo.comp_info[0].v_samp_factor = 2;
- } else if (fmt ==MM_UTIL_JPEG_FMT_YUV422 || fmt ==MM_UTIL_JPEG_FMT_UYVY) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_YUV422 || fmt == MM_UTIL_JPEG_FMT_UYVY) {
cinfo.comp_info[0].v_samp_factor = 1;
}
cinfo.comp_info[1].h_samp_factor = 1;
jpeg_start_compress(&cinfo, TRUE);
mm_util_debug("jpeg_start_compress");
- if(flag) {
- void *large_rect = malloc (width);
- void *small_rect = malloc (width);
- if(large_rect) {
+ if (flag) {
+ void *large_rect = malloc(width);
+ void *small_rect = malloc(width);
+ if (large_rect) {
memset(large_rect, 0x10, width);
} else {
IMG_JPEG_FREE(small_rect);
mm_util_error("large rectangle memory");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(small_rect) {
+ if (small_rect) {
memset(small_rect, 0x80, width);
} else {
IMG_JPEG_FREE(large_rect);
mm_util_debug("Exit jpeg_destroy_compress, mem: %p\t size:%d", *mem, *csize);
}
- else if (fmt == MM_UTIL_JPEG_FMT_RGB888 ||fmt == MM_UTIL_JPEG_FMT_GraySacle || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ else if (fmt == MM_UTIL_JPEG_FMT_RGB888 || fmt == MM_UTIL_JPEG_FMT_GraySacle || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
JSAMPROW row_pointer[1];
int iRowStride = 0;
mm_util_debug("MM_UTIL_JPEG_FMT_RGB888");
- if(fmt == MM_UTIL_JPEG_FMT_RGB888) {
+ if (fmt == MM_UTIL_JPEG_FMT_RGB888) {
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
mm_util_debug("JCS_RGB");
- } else if(fmt == MM_UTIL_JPEG_FMT_GraySacle) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_GraySacle) {
cinfo.input_components = 1; /* one colour component */
cinfo.in_color_space = JCS_GRAYSCALE;
mm_util_debug("JCS_GRAYSCALE");
- } else if(fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
cinfo.input_components = 4;
cinfo.in_color_space = JCS_EXT_RGBA;
mm_util_debug("JCS_EXT_RGBA");
- } else if(fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
cinfo.input_components = 4;
cinfo.in_color_space = JCS_EXT_BGRA;
mm_util_debug("JCS_EXT_BGRA");
- } else if(fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
cinfo.input_components = 4;
cinfo.in_color_space = JCS_EXT_ARGB;
mm_util_debug("JCS_EXT_ARGB");
mm_util_debug("jpeg_set_quality");
jpeg_start_compress(&cinfo, TRUE);
mm_util_debug("jpeg_start_compress");
- if(fmt == MM_UTIL_JPEG_FMT_RGB888) {
+ if (fmt == MM_UTIL_JPEG_FMT_RGB888) {
iRowStride = width * 3;
- } else if(fmt == MM_UTIL_JPEG_FMT_GraySacle) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_GraySacle) {
iRowStride = width;
- } else if(fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
iRowStride = width * 4;
}
return iErrorCode;
}
-static int
-mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data, const char *pFileName, mm_util_jpeg_yuv_format input_fmt, mm_util_jpeg_decode_downscale downscale)
+static int mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data, const char *pFileName, mm_util_jpeg_yuv_format input_fmt, mm_util_jpeg_decode_downscale downscale)
{
int iErrorCode = MM_UTIL_ERROR_NONE;
FILE *infile = NULL;
mm_util_debug("Enter");
- if(!pFileName) {
+ if (!pFileName) {
mm_util_error("pFileName");
return MM_UTIL_ERROR_NO_SUCH_FILE;
}
- if(decoded_data == NULL) {
+ if (decoded_data == NULL) {
mm_util_error("decoded_data");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(decoded_data) {
+ if (decoded_data) {
decoded_data->data = NULL;
}
infile = fopen(pFileName, "rb");
- if(infile == NULL) {
+ if (infile == NULL) {
mm_util_error("[infile] file open [%s]", pFileName);
mm_util_stderror("file open failed");
return MM_UTIL_ERROR_NO_SUCH_FILE;
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- mm_util_debug("if(setjmp)");
+ mm_util_debug("if (setjmp)");
/* Now we can initialize the JPEG decompression object. */
jpeg_create_decompress(&dinfo);
mm_util_debug("jpeg_create_decompress");
jpeg_read_header(&dinfo, TRUE);
#if PARTIAL_DECODE
mm_util_debug("image width: %d height: %d", dinfo.image_width, dinfo.image_height);
- if(dinfo.image_width > ENC_MAX_LEN || dinfo.image_height > ENC_MAX_LEN) {
+ if (dinfo.image_width > ENC_MAX_LEN || dinfo.image_height > ENC_MAX_LEN) {
dinfo.scale_num = 1;
dinfo.scale_denom = 8;
dinfo.do_fancy_upsampling = FALSE;
/* set parameters for decompression */
if (input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
- dinfo.out_color_space=JCS_RGB;
- mm_util_debug("cinfo.out_color_space=JCS_RGB");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
- dinfo.out_color_space=JCS_YCbCr;
- mm_util_debug("cinfo.out_color_space=JCS_YCbCr");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
- dinfo.out_color_space=JCS_GRAYSCALE;
- mm_util_debug("cinfo.out_color_space=JCS_GRAYSCALE");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
- dinfo.out_color_space=JCS_EXT_RGBA;
- mm_util_debug("cinfo.out_color_space=JCS_EXT_RGBA");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
- dinfo.out_color_space=JCS_EXT_BGRA;
- mm_util_debug("cinfo.out_color_space=JCS_EXT_BGRA");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
- dinfo.out_color_space=JCS_EXT_ARGB;
- mm_util_debug("cinfo.out_color_space=JCS_EXT_ARGB");
+ dinfo.out_color_space = JCS_RGB;
+ mm_util_debug("cinfo.out_color_space = JCS_RGB");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
+ dinfo.out_color_space = JCS_YCbCr;
+ mm_util_debug("cinfo.out_color_space = JCS_YCbCr");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
+ dinfo.out_color_space = JCS_GRAYSCALE;
+ mm_util_debug("cinfo.out_color_space = JCS_GRAYSCALE");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
+ dinfo.out_color_space = JCS_EXT_RGBA;
+ mm_util_debug("cinfo.out_color_space = JCS_EXT_RGBA");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
+ dinfo.out_color_space = JCS_EXT_BGRA;
+ mm_util_debug("cinfo.out_color_space = JCS_EXT_BGRA");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ dinfo.out_color_space = JCS_EXT_ARGB;
+ mm_util_debug("cinfo.out_color_space = JCS_EXT_ARGB");
}
decoded_data->format = input_fmt;
/* byte-align for YUV format */
if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422) {
- if(dinfo.output_width% 2 != 0) {
+ if (dinfo.output_width % 2 != 0) {
dinfo.output_width = MM_JPEG_ROUND_DOWN_2(dinfo.output_width);
}
- if(dinfo.output_height% 2 != 0) {
+ if (dinfo.output_height % 2 != 0) {
dinfo.output_height = MM_JPEG_ROUND_DOWN_2(dinfo.output_height);
}
}
buffer = (*dinfo.mem->alloc_sarray) ((j_common_ptr) &dinfo, JPOOL_IMAGE, row_stride, 1);
mm_util_debug("JPOOL_IMAGE BUFFER");
decoded_data->width = dinfo.output_width;
- decoded_data->height= dinfo.output_height;
- if(input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
- decoded_data->size= dinfo.output_height * row_stride;
- } else if(input_fmt == MM_UTIL_JPEG_FMT_YUV420) {
- decoded_data->size= dinfo.output_height * row_stride / 2;
- } else if(input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
- decoded_data->size= dinfo.output_height * dinfo.output_width * 2;
- } else if(input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
- decoded_data->size= dinfo.output_height * dinfo.output_width;
+ decoded_data->height = dinfo.output_height;
+ if (input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ decoded_data->size = dinfo.output_height * row_stride;
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_YUV420) {
+ decoded_data->size = dinfo.output_height * row_stride / 2;
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
+ decoded_data->size = dinfo.output_height * dinfo.output_width * 2;
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
+ decoded_data->size = dinfo.output_height * dinfo.output_width;
} else{
jpeg_destroy_decompress(&dinfo);
mm_util_error("[%d] We can't decode the IMAGE format", input_fmt);
return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
}
- decoded_data->data= (void*) g_malloc0(decoded_data->size);
+ decoded_data->data = (void*) g_malloc0(decoded_data->size);
decoded_data->format = input_fmt;
- if(decoded_data->data == NULL) {
+ if (decoded_data->data == NULL) {
jpeg_destroy_decompress(&dinfo);
mm_util_error("decoded_data->data is NULL");
fclose(infile);
}
mm_util_debug("decoded_data->data");
- if(input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
+ if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
image = decoded_data->data;
u_image = image + (dinfo.output_width * dinfo.output_height);
v_image = u_image + (dinfo.output_width*dinfo.output_height) / 4;
- row= buffer[0];
+ row = buffer[0];
int i = 0;
int y = 0;
while (dinfo.output_scanline < dinfo.output_height) {
jpeg_read_scanlines(&dinfo, buffer, 1);
for (i = 0; i < row_stride; i += 3) {
- image[i/3]=row[i];
+ image[i/3] = row[i];
if (i & 1) {
- u_image[(i/3)/2]=row[i+1];
- v_image[(i/3)/2]=row[i+2];
+ u_image[(i/3)/2] = row[i+1];
+ v_image[(i/3)/2] = row[i+2];
}
}
image += row_stride/3;
v_image += dinfo.output_width / 2;
}
}
- }else if(input_fmt == MM_UTIL_JPEG_FMT_RGB888 ||input_fmt == MM_UTIL_JPEG_FMT_GraySacle || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_GraySacle || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
int state = 0;
/* while (scan lines remain to be read) jpeg_read_scanlines(...); */
while (dinfo.output_scanline < dinfo.output_height) {
return iErrorCode;
}
-static int
-mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data, void *src, int size, mm_util_jpeg_yuv_format input_fmt, mm_util_jpeg_decode_downscale downscale)
+static int mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data * decoded_data, void *src, int size, mm_util_jpeg_yuv_format input_fmt, mm_util_jpeg_decode_downscale downscale)
{
int iErrorCode = MM_UTIL_ERROR_NONE;
struct jpeg_decompress_struct dinfo;
mm_util_debug("Enter");
- if(src == NULL) {
+ if (src == NULL) {
mm_util_error("[infile] Exit on error");
return MM_UTIL_ERROR_NO_SUCH_FILE;
}
mm_util_debug("infile");
- if(decoded_data == NULL) {
+ if (decoded_data == NULL) {
mm_util_error("decoded_data");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(decoded_data) {
+ if (decoded_data) {
decoded_data->data = NULL;
}
return MM_UTIL_ERROR_NO_SUCH_FILE;
}
- mm_util_debug("if(setjmp)");
+ mm_util_debug("if (setjmp)");
/* Now we can initialize the JPEG decompression object. */
jpeg_create_decompress(&dinfo);
mm_util_debug("jpeg_create_decompress");
mm_util_debug("jpeg_read_header");
#if PARTIAL_DECODE
mm_util_debug("image width: %d height: %d", dinfo.image_width, dinfo.image_height);
- if(dinfo.image_width > ENC_MAX_LEN || dinfo.image_height > ENC_MAX_LEN) {
+ if (dinfo.image_width > ENC_MAX_LEN || dinfo.image_height > ENC_MAX_LEN) {
dinfo.scale_num = 1;
dinfo.scale_denom = 8;
dinfo.do_fancy_upsampling = FALSE;
/* set parameters for decompression */
if (input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
- dinfo.out_color_space=JCS_RGB;
- mm_util_debug("cinfo.out_color_space=JCS_RGB");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
- dinfo.out_color_space=JCS_YCbCr;
- mm_util_debug("cinfo.out_color_space=JCS_YCbCr");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
- dinfo.out_color_space=JCS_GRAYSCALE;
- mm_util_debug("cinfo.out_color_space=JCS_GRAYSCALE");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
- dinfo.out_color_space=JCS_EXT_RGBA;
- mm_util_debug("cinfo.out_color_space=JCS_EXT_RGBA");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
- dinfo.out_color_space=JCS_EXT_BGRA;
- mm_util_debug("cinfo.out_color_space=JCS_EXT_BGRA");
- } else if(input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
- dinfo.out_color_space=JCS_EXT_ARGB;
- mm_util_debug("cinfo.out_color_space=JCS_EXT_ARGB");
+ dinfo.out_color_space = JCS_RGB;
+ mm_util_debug("cinfo.out_color_space = JCS_RGB");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
+ dinfo.out_color_space = JCS_YCbCr;
+ mm_util_debug("cinfo.out_color_space = JCS_YCbCr");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
+ dinfo.out_color_space = JCS_GRAYSCALE;
+ mm_util_debug("cinfo.out_color_space = JCS_GRAYSCALE");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_RGBA8888) {
+ dinfo.out_color_space = JCS_EXT_RGBA;
+ mm_util_debug("cinfo.out_color_space = JCS_EXT_RGBA");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_BGRA8888) {
+ dinfo.out_color_space = JCS_EXT_BGRA;
+ mm_util_debug("cinfo.out_color_space = JCS_EXT_BGRA");
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ dinfo.out_color_space = JCS_EXT_ARGB;
+ mm_util_debug("cinfo.out_color_space = JCS_EXT_ARGB");
}
decoded_data->format = input_fmt;
/* byte-align for YUV format */
if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422) {
- if(dinfo.output_width% 2 != 0) {
+ if (dinfo.output_width % 2 != 0) {
dinfo.output_width = MM_JPEG_ROUND_DOWN_2(dinfo.output_width);
}
- if(dinfo.output_height% 2 != 0) {
+ if (dinfo.output_height % 2 != 0) {
dinfo.output_height = MM_JPEG_ROUND_DOWN_2(dinfo.output_height);
}
}
buffer = (*dinfo.mem->alloc_sarray) ((j_common_ptr) &dinfo, JPOOL_IMAGE, row_stride, 1);
mm_util_debug("JPOOL_IMAGE BUFFER");
decoded_data->width = dinfo.output_width;
- decoded_data->height= dinfo.output_height;
- if(input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
- decoded_data->size= dinfo.output_height * row_stride;
- } else if(input_fmt == MM_UTIL_JPEG_FMT_YUV420) {
- decoded_data->size= dinfo.output_height * row_stride / 2;
- } else if(input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
- decoded_data->size= dinfo.output_height * dinfo.output_width * 2;
- } else if(input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
- decoded_data->size= dinfo.output_height * dinfo.output_width;
+ decoded_data->height = dinfo.output_height;
+ if (input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ decoded_data->size = dinfo.output_height * row_stride;
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_YUV420) {
+ decoded_data->size = dinfo.output_height * row_stride / 2;
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
+ decoded_data->size = dinfo.output_height * dinfo.output_width * 2;
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_GraySacle) {
+ decoded_data->size = dinfo.output_height * dinfo.output_width;
} else{
jpeg_destroy_decompress(&dinfo);
mm_util_error("[%d] We can't decode the IMAGE format", input_fmt);
return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
}
- decoded_data->data= (void*) g_malloc0(decoded_data->size);
+ decoded_data->data = (void*) g_malloc0(decoded_data->size);
decoded_data->format = input_fmt;
- if(decoded_data->data == NULL) {
+ if (decoded_data->data == NULL) {
jpeg_destroy_decompress(&dinfo);
mm_util_error("decoded_data->data is NULL");
return MM_UTIL_ERROR_OUT_OF_MEMORY;
mm_util_debug("decoded_data->data");
/* while (scan lines remain to be read) jpeg_read_scanlines(...); */
- if(input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
+ if (input_fmt == MM_UTIL_JPEG_FMT_YUV420 || input_fmt == MM_UTIL_JPEG_FMT_YUV422 || input_fmt == MM_UTIL_JPEG_FMT_UYVY) {
image = decoded_data->data;
u_image = image + (dinfo.output_width * dinfo.output_height);
v_image = u_image + (dinfo.output_width*dinfo.output_height)/4;
- row= buffer[0];
+ row = buffer[0];
int i = 0;
int y = 0;
while (dinfo.output_scanline < dinfo.output_height) {
jpeg_read_scanlines(&dinfo, buffer, 1);
for (i = 0; i < row_stride; i += 3) {
- image[i/3]=row[i];
+ image[i/3] = row[i];
if (i & 1) {
- u_image[(i/3)/2]=row[i+1];
- v_image[(i/3)/2]=row[i+2];
+ u_image[(i/3)/2] = row[i+1];
+ v_image[(i/3)/2] = row[i+2];
}
}
image += row_stride/3;
v_image += dinfo.output_width / 2;
}
}
- } else if(input_fmt == MM_UTIL_JPEG_FMT_RGB888 ||input_fmt == MM_UTIL_JPEG_FMT_GraySacle || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ } else if (input_fmt == MM_UTIL_JPEG_FMT_RGB888 || input_fmt == MM_UTIL_JPEG_FMT_GraySacle || input_fmt == MM_UTIL_JPEG_FMT_RGBA8888 || input_fmt == MM_UTIL_JPEG_FMT_BGRA8888 || input_fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
int state = 0;
while (dinfo.output_scanline < dinfo.output_height) {
/* jpeg_read_scanlines expects an array of pointers to scanlines. Here the array is only one element long, but you could ask formore than one scanline at a time if that's more convenient. */
}
#if 0
-static int _mm_util_set_exif_entry(ExifData *exif, ExifIfd ifd, ExifTag tag,ExifFormat format, unsigned long components, unsigned char* data)
+static int _mm_util_set_exif_entry(ExifData *exif, ExifIfd ifd, ExifTag tag, ExifFormat format, unsigned long components, unsigned char* data)
{
ExifData *ed = (ExifData *)exif;
ExifEntry *e = NULL;
}
e->size = exif_format_get_size(format) * e->components;
- memcpy(e->data,data,e->size);
+ memcpy(e->data, data, e->size);
exif_content_add_entry(ed->ifd[ifd], e);
exif_entry_unref(e);
}
#endif
-EXPORT_API int
-mm_util_jpeg_encode_to_file(const char *filename, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
+EXPORT_API int mm_util_jpeg_encode_to_file(const char *filename, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
{
int ret = MM_UTIL_ERROR_NONE;
TTRACE_BEGIN("MM_UTILITY:JPEG:ENCODE_TO_FILE");
- if( !filename || !src) {
+ if (!filename || !src) {
mm_util_error("#ERROR# filename || src buffer is NULL");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (width <= 0) || (height <= 0)) {
+ if ((width <= 0) || (height <= 0)) {
mm_util_error("#ERROR# src_width || src_height value ");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
+ if ((fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888)) {
mm_util_error("#ERROR# fmt value");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (quality < 1 ) || (quality>100) ) {
+ if ((quality < 1) || (quality > 100)) {
mm_util_error("#ERROR# quality vaule");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
#if LIBJPEG_TURBO
mm_util_debug("#START# LIBJPEG_TURBO");
- ret=mm_image_encode_to_jpeg_file_with_libjpeg_turbo(filename, src, width, height, fmt, quality);
+ ret = mm_image_encode_to_jpeg_file_with_libjpeg_turbo(filename, src, width, height, fmt, quality);
mm_util_debug("#End# libjpeg, Success!! ret: %d", ret);
#else
mm_util_debug("#START# LIBJPEG");
- if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+ if (fmt == MM_UTIL_JPEG_FMT_NV12) {
unsigned int dst_size = 0;
ret = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, (unsigned int)width, (unsigned int)height, &dst_size);
unsigned char *dst = NULL;
dst = malloc(dst_size);
- if(dst) {
- ret = mm_util_convert_colorspace(src, width, height,MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
+ if (dst) {
+ ret = mm_util_convert_colorspace(src, width, height, MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
ret = mm_image_encode_to_jpeg_file_with_libjpeg(filename, dst, width, height, MM_UTIL_JPEG_FMT_YUV420, quality);
IMG_JPEG_FREE(dst);
} else {
TTRACE_END();
return MM_UTIL_ERROR_OUT_OF_MEMORY;
}
- } else if(fmt == MM_UTIL_JPEG_FMT_NV21) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_NV21) {
TTRACE_END();
return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
} else {
return ret;
}
-EXPORT_API int
-mm_util_jpeg_encode_to_memory(void **mem, int *size, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
+EXPORT_API int mm_util_jpeg_encode_to_memory(void **mem, int *size, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
{
int ret = MM_UTIL_ERROR_NONE;
TTRACE_BEGIN("MM_UTILITY:JPEG:ENCODE_TO_MEMORY");
- if( !mem || !size || !src) {
- mm_util_error("#ERROR# filename ||size || src buffer is NULL");
+ if (!mem || !size || !src) {
+ mm_util_error("#ERROR# filename ||size || src buffer is NULL");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (width <= 0) || (height <= 0)) {
+ if ((width <= 0) || (height <= 0)) {
mm_util_error("#ERROR# src_width || src_height value ");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
+ if ((fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888)) {
mm_util_error("#ERROR# fmt value");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (quality < 1 ) || (quality>100) ) {
+ if ((quality < 1) || (quality > 100)) {
mm_util_error("#ERROR# quality vaule");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
#if LIBJPEG_TURBO
mm_util_debug("#START# libjpeg-turbo");
- ret=mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(mem, size, src, width, height, fmt, quality);
+ ret = mm_image_encode_to_jpeg_memory_with_libjpeg_turbo(mem, size, src, width, height, fmt, quality);
mm_util_debug("#END# libjpeg-turbo, Success!! ret: %d", ret);
#else /* LIBJPEG_TURBO */
mm_util_debug("#START# libjpeg");
- if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+ if (fmt == MM_UTIL_JPEG_FMT_NV12) {
unsigned int dst_size = 0;
ret = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, (unsigned int)width, (unsigned int)height, &dst_size);
unsigned char *dst = NULL;
dst = malloc(dst_size);
- if(dst) {
- ret = mm_util_convert_colorspace(src, width, height,MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
+ if (dst) {
+ ret = mm_util_convert_colorspace(src, width, height, MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
ret = mm_image_encode_to_jpeg_memory_with_libjpeg(mem, size, dst, width, height, MM_UTIL_JPEG_FMT_YUV420, quality);
IMG_JPEG_FREE(dst);
} else {
TTRACE_END();
return MM_UTIL_ERROR_OUT_OF_MEMORY;
}
- } else if(fmt == MM_UTIL_JPEG_FMT_NV21) {
+ } else if (fmt == MM_UTIL_JPEG_FMT_NV21) {
TTRACE_END();
return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
} else {
return ret;
}
-EXPORT_API int
-mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_jpeg_yuv_format fmt)
+EXPORT_API int mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_jpeg_yuv_format fmt)
{
int ret = MM_UTIL_ERROR_NONE;
TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_FILE");
- if( !decoded || !filename) {
+ if (!decoded || !filename) {
mm_util_error("#ERROR# decoded || filename buffer is NULL");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
+ if ((fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888)) {
mm_util_error("#ERROR# fmt value");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
FILE *fp = fopen(filename, "rb");
unsigned char magic[2] = {0};
size_t read_size = 0;
- if(fp) {
+ if (fp) {
read_size = fread((void *)magic, 1, 2, fp);
if (read_size > 0)
mm_util_debug("Success fread");
return MM_UTIL_ERROR_NO_SUCH_FILE;
}
- if(magic[0] == 0xff && magic[1] == 0xd8) {
+ if (magic[0] == 0xff && magic[1] == 0xd8) {
#if LIBJPEG_TURBO
mm_util_debug("#START# LIBJPEG_TURBO");
ret = mm_image_decode_from_jpeg_file_with_libjpeg_turbo(decoded, filename, fmt);
mm_util_debug("#End# LIBJPEG_TURBO, Success!! ret: %d", ret);
#else
mm_util_debug("#START# libjpeg");
- if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+ if (fmt == MM_UTIL_JPEG_FMT_NV12) {
unsigned int dst_size = 0;
ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, MM_UTIL_IMG_FMT_YUV420, downscale);
if (ret == MM_UTIL_ERROR_NONE) {
unsigned char *dst = NULL;
dst = malloc(dst_size);
- if(dst) {
+ if (dst) {
ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
IMG_JPEG_FREE(decoded->data);
decoded->data = malloc(dst_size);
mm_util_debug("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
mm_util_debug("#End# libjpeg, Success!! ret: %d", ret);
#endif
- } else if(magic[0] == 0x47 && magic[1] == 0x49) {
+ } else if (magic[0] == 0x47 && magic[1] == 0x49) {
mm_util_error("Not JPEG IMAGE - GIF");
ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- } else if(magic[0] == 0x89 && magic[1] == 0x50) {
+ } else if (magic[0] == 0x89 && magic[1] == 0x50) {
mm_util_error("Not JPEG IMAGE - PNG");
ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- } else if(magic[0] == 0x49 && magic[1] == 0x49) {
+ } else if (magic[0] == 0x49 && magic[1] == 0x49) {
mm_util_error("Not JPEG IMAGE - TIFF");
ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
} else {
return ret;
}
-EXPORT_API int
-mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data* decoded, void* src, int size, mm_util_jpeg_yuv_format fmt)
+EXPORT_API int mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data* decoded, void* src, int size, mm_util_jpeg_yuv_format fmt)
{
int ret = MM_UTIL_ERROR_NONE;
mm_util_jpeg_decode_downscale downscale = MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1;
- if( !decoded || !src) {
+ if (!decoded || !src) {
mm_util_error("#ERROR# decoded || src buffer is NULL");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(size < 0) {
+ if (size < 0) {
mm_util_error("#ERROR# size");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
+ if ((fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888)) {
mm_util_error("#ERROR# fmt value");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
#else
mm_util_debug("#START# libjpeg");
- if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+ if (fmt == MM_UTIL_JPEG_FMT_NV12) {
unsigned int dst_size = 0;
unsigned char *dst = NULL;
mm_util_error("fail mm_util_get_image_size");
dst = malloc(dst_size);
- if(dst) {
+ if (dst) {
ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
IMG_JPEG_FREE(decoded->data);
decoded->data = malloc(dst_size);
return ret;
}
-EXPORT_API int
-mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale)
+EXPORT_API int mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_data *decoded, const char *filename, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale)
{
int ret = MM_UTIL_ERROR_NONE;
TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_FILE_WITH_DOWNSCALE");
- if( !decoded || !filename) {
+ if (!decoded || !filename) {
mm_util_error("#ERROR# decoded || filename buffer is NULL");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
+ if ((fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888)) {
mm_util_error("#ERROR# fmt value");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
+ if ((downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
&& (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8)) {
mm_util_error("#ERROR# fmt value");
TTRACE_END();
FILE *fp = fopen(filename, "rb");
unsigned char magic[2] = {0};
size_t read_size = 0;
- if(fp) {
+ if (fp) {
read_size = fread((void *)magic, 1, 2, fp);
if (read_size > 0)
mm_util_debug("Success fread");
mm_util_debug("%x %x", magic[0], magic[1]);
fclose(fp);
}
- if(magic[0] == 0xff && magic[1] == 0xd8) {
+ if (magic[0] == 0xff && magic[1] == 0xd8) {
#if LIBJPEG_TURBO
mm_util_debug("#START# LIBJPEG_TURBO");
ret = mm_image_decode_from_jpeg_file_with_libjpeg_turbo(decoded, filename, fmt);
mm_util_debug("#End# LIBJPEG_TURBO, Success!! ret: %d", ret);
#else
mm_util_debug("#START# libjpeg");
- if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+ if (fmt == MM_UTIL_JPEG_FMT_NV12) {
unsigned int dst_size = 0;
ret = mm_image_decode_from_jpeg_file_with_libjpeg(decoded, filename, MM_UTIL_IMG_FMT_YUV420, downscale);
if (ret == MM_UTIL_ERROR_NONE) {
unsigned char *dst = NULL;
dst = malloc(dst_size);
- if(dst) {
+ if (dst) {
ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
IMG_JPEG_FREE(decoded->data);
decoded->data = malloc(dst_size);
mm_util_debug("decoded->data: %p\t width: %d\t height:%d\t size: %d\n", decoded->data, decoded->width, decoded->height, decoded->size);
mm_util_debug("#End# libjpeg, Success!! ret: %d", ret);
#endif
- } else if(magic[0] == 0x47 && magic[1] == 0x49) {
+ } else if (magic[0] == 0x47 && magic[1] == 0x49) {
mm_util_error("Not JPEG IMAGE - GIF");
ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- } else if(magic[0] == 0x89 && magic[1] == 0x50) {
+ } else if (magic[0] == 0x89 && magic[1] == 0x50) {
mm_util_error("Not JPEG IMAGE - PNG");
ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- } else if(magic[0] == 0x49 && magic[1] == 0x49) {
+ } else if (magic[0] == 0x49 && magic[1] == 0x49) {
mm_util_error("Not JPEG IMAGE - TIFF");
ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
} else {
return ret;
}
-EXPORT_API int
-mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data* decoded, void* src, int size, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale)
+EXPORT_API int mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_data* decoded, void* src, int size, mm_util_jpeg_yuv_format fmt, mm_util_jpeg_decode_downscale downscale)
{
int ret = MM_UTIL_ERROR_NONE;
TTRACE_BEGIN("MM_UTILITY:JPEG:DECODE_FROM_JPEG_MEMORY_WITH_DOWNSCALE");
- if( !decoded || !src) {
+ if (!decoded || !src) {
mm_util_error("#ERROR# decoded || src buffer is NULL");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if(size < 0) {
+ if (size < 0) {
mm_util_error("#ERROR# size");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888) ) {
+ if ((fmt < MM_UTIL_JPEG_FMT_YUV420) || (fmt > MM_UTIL_JPEG_FMT_ARGB8888)) {
mm_util_error("#ERROR# fmt value");
TTRACE_END();
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if( (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
+ if ((downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2)
&& (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4) && (downscale != MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8)) {
mm_util_error("#ERROR# fmt value");
TTRACE_END();
#else
mm_util_debug("#START# libjpeg");
- if(fmt == MM_UTIL_JPEG_FMT_NV12) {
+ if (fmt == MM_UTIL_JPEG_FMT_NV12) {
unsigned int dst_size = 0;
unsigned char *dst = NULL;
mm_util_error("fail mm_util_get_image_size");
dst = malloc(dst_size);
- if(dst) {
+ if (dst) {
ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
IMG_JPEG_FREE(decoded->data);
decoded->data = malloc(dst_size);
static inline void flush_stdin()
{
int ch;
- while((ch=getchar()) != EOF && ch != '\n');
+ while ((ch = getchar()) != EOF && ch != '\n');
}
fseek(fp, 0, SEEK_END);
file_size = ftell(fp);
- if(file_size > -1L) {
+ if (file_size > -1L) {
rewind(fp);
*data = (void *)malloc(file_size);
if (*data == NULL) {
fp = NULL;
return FALSE;
} else {
- if(fread(*data, 1, file_size, fp)) {
+ if (fread(*data, 1, file_size, fp)) {
fprintf(stderr, "#Success# fread\n");
} else {
fprintf(stderr, "#Error# fread\n");
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\tERROR is occurred %x\n", ret);
- }else {
+ } else {
fprintf(stderr, "\tJPEG OPERATION SUCCESS\n");
if (!strcmp("encode", argv[1])) {
if (dst) {
fprintf(stderr, "\tENCODED data is NULL\n");
}
} else {
- if(decoded_data.data) {
- fprintf(stderr, "\t##Decoded data##: %p\t width: %d\t height:%d\t size: %d\n",
- decoded_data.data, decoded_data.width, decoded_data.height, decoded_data.size);
+ if (decoded_data.data) {
+ fprintf(stderr, "\t##Decoded data##: %p\t width: %d\t height:%d\t size: %d\n", decoded_data.data, decoded_data.width, decoded_data.height, decoded_data.size);
char filename[BUFFER_SIZE] = {0, };
memset(filename, 0, BUFFER_SIZE);
- if(fmt == MM_UTIL_JPEG_FMT_RGB888 || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
+ if (fmt == MM_UTIL_JPEG_FMT_RGB888 || fmt == MM_UTIL_JPEG_FMT_RGBA8888 || fmt == MM_UTIL_JPEG_FMT_BGRA8888 || fmt == MM_UTIL_JPEG_FMT_ARGB8888) {
snprintf(filename, BUFFER_SIZE, "%s%s", DECODE_RESULT_PATH, "rgb");
- } else if((fmt == MM_UTIL_JPEG_FMT_YUV420) ||
+ } else if ((fmt == MM_UTIL_JPEG_FMT_YUV420) ||
(fmt == MM_UTIL_JPEG_FMT_YUV422) ||
(fmt == MM_UTIL_JPEG_FMT_NV12) ||
(fmt == MM_UTIL_JPEG_FMT_NV21) ||
/**
* Image file format
*/
-typedef enum
-{
- /* Image file format */
- MM_UTILITY_IMAGE_FILE_FMT_NONE, /**< Nothing or not supported image file format */
- MM_UTILITY_IMAGE_FILE_FMT_BMP, /**< Windows bitmap : .bmp, .dib, .rle, .2bp */
- MM_UTILITY_IMAGE_FILE_FMT_GIF, /**< Graphics Interchange Format : .gif, .gfa, .giff */
- MM_UTILITY_IMAGE_FILE_FMT_PNG, /**< Portable Network Graphics : .png */
- MM_UTILITY_IMAGE_FILE_FMT_JPG, /**< Joint Photographic Experts Group : .jpg, .jpeg, .jpe */
+typedef enum {
+ /* Image file format */
+ MM_UTILITY_IMAGE_FILE_FMT_NONE, /**< Nothing or not supported image file format */
+ MM_UTILITY_IMAGE_FILE_FMT_BMP, /**< Windows bitmap : .bmp, .dib, .rle, .2bp */
+ MM_UTILITY_IMAGE_FILE_FMT_GIF, /**< Graphics Interchange Format : .gif, .gfa, .giff */
+ MM_UTILITY_IMAGE_FILE_FMT_PNG, /**< Portable Network Graphics : .png */
+ MM_UTILITY_IMAGE_FILE_FMT_JPG, /**< Joint Photographic Experts Group : .jpg, .jpeg, .jpe */
} mm_utility_image_file_format;
-
/**
* YUV format for gif
*/
-typedef enum
-{
- /* YUV planar format */
- MM_UTILITY_GIF_FMT_YUV420 = 0x00, /**< YUV420 format - planer */
- MM_UTILITY_GIF_FMT_YUV422, /**< YUV422 format - planer */
- /* YUV packed format */
- MM_UTILITY_GIF_FMT_UYVY, /**< UYVY format - YUV packed format */
+typedef enum {
+ /* YUV planar format */
+ MM_UTILITY_GIF_FMT_YUV420 = 0x00, /**< YUV420 format - planer */
+ MM_UTILITY_GIF_FMT_YUV422, /**< YUV422 format - planer */
+ /* YUV packed format */
+ MM_UTILITY_GIF_FMT_UYVY, /**< UYVY format - YUV packed format */
} mm_utility_gif_yuv_format;
/**
* YUV data for gif
*/
-typedef struct
-{
- mm_utility_gif_yuv_format format; /**< pixel format*/
- int width; /**< width */
- int height; /**< heigt */
- int size; /**< size */
- void *data; /**< data */
+typedef struct {
+ mm_utility_gif_yuv_format format; /**< pixel format*/
+ int width; /**< width */
+ int height; /**< heigt */
+ int size; /**< size */
+ void *data; /**< data */
} mm_utility_decoded_data;
-static int get_file_format ( const char * input_file )
+static int get_file_format(const char * input_file)
{
mm_utility_image_file_format file_format = MM_UTILITY_IMAGE_FILE_FMT_NONE;
- if ( g_str_has_suffix( input_file, "bmp" )
- || g_str_has_suffix ( input_file, "dib" )
- || g_str_has_suffix ( input_file, "rle" )
- || g_str_has_suffix ( input_file, "2bp" )
- || g_str_has_suffix( input_file, "BMP" )
- || g_str_has_suffix ( input_file, "DIB" )
- || g_str_has_suffix ( input_file, "RLE" )
- || g_str_has_suffix ( input_file, "2BP" ) )
- {
- printf ( "Image file format is BMP. \n" );
+ if (g_str_has_suffix(input_file, "bmp")
+ || g_str_has_suffix(input_file, "dib")
+ || g_str_has_suffix(input_file, "rle")
+ || g_str_has_suffix(input_file, "2bp")
+ || g_str_has_suffix(input_file, "BMP")
+ || g_str_has_suffix(input_file, "DIB")
+ || g_str_has_suffix(input_file, "RLE")
+ || g_str_has_suffix(input_file, "2BP")) {
+ printf("Image file format is BMP. \n");
file_format = MM_UTILITY_IMAGE_FILE_FMT_BMP;
- }
- else if ( g_str_has_suffix ( input_file, "gif" )
- || g_str_has_suffix ( input_file, "gfa" )
- || g_str_has_suffix ( input_file, "giff" )
- || g_str_has_suffix ( input_file, "GIF" )
- || g_str_has_suffix ( input_file, "GFA" )
- || g_str_has_suffix ( input_file, "GIFF" ))
- {
- printf ( "Image file format is GIF. \n" );
+ } else if (g_str_has_suffix(input_file, "gif")
+ || g_str_has_suffix(input_file, "gfa")
+ || g_str_has_suffix(input_file, "giff")
+ || g_str_has_suffix(input_file, "GIF")
+ || g_str_has_suffix(input_file, "GFA")
+ || g_str_has_suffix(input_file, "GIFF")) {
+ printf("Image file format is GIF. \n");
file_format = MM_UTILITY_IMAGE_FILE_FMT_GIF;
- }
- else if ( g_str_has_suffix ( input_file, "png" )
- || g_str_has_suffix ( input_file, "PNG" ))
- {
- printf ( "Image file format is PNG. \n" );
+ } else if (g_str_has_suffix(input_file, "png")
+ || g_str_has_suffix(input_file, "PNG")) {
+ printf("Image file format is PNG. \n");
file_format = MM_UTILITY_IMAGE_FILE_FMT_PNG;
- }
- else if ( g_str_has_suffix ( input_file, "jpg" )
- || g_str_has_suffix ( input_file, "jpeg" )
- || g_str_has_suffix ( input_file, "jpe" )
- || g_str_has_suffix ( input_file, "JPG" )
- || g_str_has_suffix ( input_file, "JPEG" )
- || g_str_has_suffix ( input_file, "JPE" ) )
- {
- printf ( "Image file format is JPG. \n" );
+ } else if (g_str_has_suffix(input_file, "jpg")
+ || g_str_has_suffix(input_file, "jpeg")
+ || g_str_has_suffix(input_file, "jpe")
+ || g_str_has_suffix(input_file, "JPG")
+ || g_str_has_suffix(input_file, "JPEG")
+ || g_str_has_suffix(input_file, "JPE")) {
+ printf("Image file format is JPG. \n");
file_format = MM_UTILITY_IMAGE_FILE_FMT_JPG;
- }
- else
- {
- printf ( "Not supported image file format. \n" );
+ } else {
+ printf("Not supported image file format. \n");
}
return file_format;
}
-static int malloc_decoded_picture ( SCMN_IMGB * img )
+static int malloc_decoded_picture(SCMN_IMGB * img)
{
int ret = 0;
int malloc_size = 0;
- switch ( img->cs ) {
- case SCMN_CS_YUV444 :
- printf ("colorspace is YUV444.\n");
+ switch (img->cs) {
+ case SCMN_CS_YUV444:
+ printf("colorspace is YUV444.\n");
img->w[1] = img->w[2] = img->w[0];
img->h[1] = img->h[2] = img->h[0];
img->s[0] = img->s[1] = img->s[2] = img->w[0];
break;
- case SCMN_CS_YUV422 :
- printf ("colorspace is YUV422 or YUV422N.\n");
+ case SCMN_CS_YUV422:
+ printf("colorspace is YUV422 or YUV422N.\n");
img->w[1] = img->w[2] = (img->w[0]+1) >> 1;
img->h[1] = img->h[2] = img->h[0];
break;
- case SCMN_CS_YUV422W :
- printf ("colorspace is YUV422W.\n");
+ case SCMN_CS_YUV422W:
+ printf("colorspace is YUV422W.\n");
img->w[1] = img->w[2] = img->w[0];
img->h[1] = img->h[2] = (img->h[0]+1) >> 1;
break;
- case SCMN_CS_YUV420 :
- printf ("colorspace is YUV420.\n");
+ case SCMN_CS_YUV420:
+ printf("colorspace is YUV420.\n");
/* plus 1 for rounding */
img->w[1] = img->w[2] = (img->w[0]+1) >> 1;
break;
- case SCMN_CS_YUV400 :
- printf ("colorspace is YUV400.\n");
+ case SCMN_CS_YUV400:
+ printf("colorspace is YUV400.\n");
img->s[0] = img->w[0];
img->e[0] = img->h[0];
break;
- case SCMN_CS_RGB565 :
- printf ("colorspace is RGB565.\n");
+ case SCMN_CS_RGB565:
+ printf("colorspace is RGB565.\n");
img->s[0] = img->w[0];
img->e[0] = img->h[0];
break;
- case SCMN_CS_RGB888 :
- printf ("colorspace is RGB888.\n");
+ case SCMN_CS_RGB888:
+ printf("colorspace is RGB888.\n");
img->s[0] = img->w[0]*3;
img->e[0] = img->h[0];
- printf ( "%d x %d \n", img->s[0], img->e[0] );
+ printf("%d x %d \n", img->s[0], img->e[0]);
malloc_size = img->s[0]*img->e[0]*sizeof(unsigned char) * 3 ;
break;
- case SCMN_CS_RGBA8888 :
- printf ("colorspace is RGBA8888.\n");
+ case SCMN_CS_RGBA8888:
+ printf("colorspace is RGBA8888.\n");
img->s[0] = img->w[0];
img->e[0] = img->h[0];
break;
- default :
- printf ( "Not supported colorspace[%d].\n", img->cs );
+ default:
+ printf("Not supported colorspace[%d].\n", img->cs);
ret = -1;
break;
}
/* allocate buffer */
- if ( SCMN_CS_IS_YUV ( img->cs ) )
- {
- if(img->cs == SCMN_CS_YUV400) {
+ if (SCMN_CS_IS_YUV(img->cs)) {
+ if (img->cs == SCMN_CS_YUV400) {
img->a[0] = malloc(img->s[0]*img->e[0]*sizeof(unsigned char));
} else {
img->a[0] = malloc(img->s[0]*img->e[0]*sizeof(unsigned char));
img->a[1] = malloc(img->s[1]*img->e[1]*sizeof(unsigned char));
img->a[2] = malloc(img->s[2]*img->e[2]*sizeof(unsigned char));
}
- }
- else if ( SCMN_CS_IS_RGB16_PACK ( img->cs ) )
- {
- img->a[0] = malloc(img->s[0]*img->e[0]*sizeof(unsigned char) * 2 );
- }
- else if ( SCMN_CS_IS_RGB24_PACK ( img->cs ) )
- {
+ } else if (SCMN_CS_IS_RGB16_PACK(img->cs)) {
+ img->a[0] = malloc(img->s[0]*img->e[0]*sizeof(unsigned char) * 2);
+ } else if (SCMN_CS_IS_RGB24_PACK(img->cs)) {
img->a[0] = malloc(img->s[0]*img->e[0]*sizeof(unsigned char) * 3);
- }
- else if ( SCMN_CS_IS_RGB32_PACK ( img->cs ) )
- {
+ } else if (SCMN_CS_IS_RGB32_PACK(img->cs)) {
img->a[0] = malloc(img->s[0]*img->e[0]*sizeof(unsigned char) * 4);
- }
- else
- {
- printf ( "Fail to allocate memory.\n" );
+ } else {
+ printf("Fail to allocate memory.\n");
ret = -1;
}
- if ( !img->a[0] )
+ if (!img->a[0])
ret = -1;
return ret;
}
-static void write_decoded_image ( const char *filename, SCMN_IMGB imgb )
+static void write_decoded_image(const char *filename, SCMN_IMGB imgb)
{
- printf ( "Write decoded image to %s.\n", filename );
+ printf("Write decoded image to %s.\n", filename);
- FILE *fp = fopen( filename, "wb");
- fwrite ( imgb.a[0], sizeof(unsigned char), imgb.s[0]*imgb.e[0], fp );
- fwrite ( imgb.a[1], sizeof(unsigned char), imgb.s[1]*imgb.e[1], fp );
- fwrite ( imgb.a[2], sizeof(unsigned char), imgb.s[2]*imgb.e[2], fp );
+ FILE *fp = fopen(filename, "wb");
+ fwrite(imgb.a[0], sizeof(unsigned char), imgb.s[0]*imgb.e[0], fp);
+ fwrite(imgb.a[1], sizeof(unsigned char), imgb.s[1]*imgb.e[1], fp);
+ fwrite(imgb.a[2], sizeof(unsigned char), imgb.s[2]*imgb.e[2], fp);
- fclose ( fp );
+ fclose(fp);
return;
}
-static int decode_bmp ( const char * input_file, int width, int height, const char * output_file )
+static int decode_bmp(const char * input_file, int width, int height, const char * output_file)
{
- SCMN_IMGB imgb;
+ SCMN_IMGB imgb;
SBMPD_INIT_DSC init_dsc;
- SBMPD bmpd_hnd = NULL;
- SBMPD_STAT bmpd_stat = {0,};
- SBMPD_INFO bmpd_info = {0,};
+ SBMPD bmpd_hnd = NULL;
+ SBMPD_STAT bmpd_stat = {0,};
+ SBMPD_INFO bmpd_info = {0,};
FILE *input_fp = NULL;
- unsigned char *filebuffer = NULL;
- unsigned char *bufp = NULL;
- unsigned int nread = 0, toread = 0, totalread = 0, decoded_size = 0;
- struct stat statbuf;
+ unsigned char *filebuffer = NULL;
+ unsigned char *bufp = NULL;
+ unsigned int nread = 0, toread = 0, totalread = 0, decoded_size = 0;
+ struct stat statbuf;
- int sret = SBMP_OK;
- int ret = 0;
+ int sret = SBMP_OK;
+ int ret = 0;
int err = 0;
+ /* initialize struct variable */
+ memset(&imgb, 0x00, sizeof(SCMN_IMGB));
+ memset(&init_dsc, 0x00, sizeof(SBMPD_INIT_DSC));
+ memset(&bmpd_stat, 0x00, sizeof(SBMPD_STAT));
+ memset(&bmpd_info, 0x00, sizeof(SBMPD_INFO));
- /* initialize struct variable */
- memset(&imgb, 0x00, sizeof(SCMN_IMGB));
- memset(&init_dsc, 0x00, sizeof(SBMPD_INIT_DSC));
- memset(&bmpd_stat, 0x00, sizeof(SBMPD_STAT));
- memset(&bmpd_info, 0x00, sizeof(SBMPD_INFO));
-
- /* init bmp codec */
- sret = sbmp_init();
- if (SBMP_IS_ERR(sret))
- {
- printf ( "Fail to init bmp library\n");
- ret = -1;
- goto exit;
- }
+ /* init bmp codec */
+ sret = sbmp_init();
+ if (SBMP_IS_ERR(sret)) {
+ printf("Fail to init bmp library\n");
+ ret = -1;
+ goto exit;
+ }
- printf ( "Initialize bmp library is success.\n" );
+ printf("Initialize bmp library is success.\n");
- /* read data from gif file */
- input_fp = fopen( input_file, "rb");
- if (input_fp == NULL)
- {
- printf ( "Fail to read bmp file \n" );
- goto exit;
- }
+ /* read data from gif file */
+ input_fp = fopen(input_file, "rb");
+ if (input_fp == NULL) {
+ printf("Fail to read bmp file \n");
+ goto exit;
+ }
fstat(fileno(input_fp), &statbuf);
- if (!(statbuf.st_mode & S_IFREG))
- {
- printf ( "Input file is not regular file\n" );
+ if (!(statbuf.st_mode & S_IFREG)) {
+ printf("Input file is not regular file\n");
ret = -1;
- goto exit;
- }
+ goto exit;
+ }
- filebuffer = malloc(statbuf.st_size);
- if (!filebuffer)
- {
- printf ( "fail to allocate file buffer\n" );
+ filebuffer = malloc(statbuf.st_size);
+ if (!filebuffer) {
+ printf("fail to allocate file buffer\n");
ret = -1;
- goto exit;
- }
+ goto exit;
+ }
toread = statbuf.st_size;
- totalread = 0;
- bufp = filebuffer;
+ totalread = 0;
+ bufp = filebuffer;
- while ((nread = fread(bufp+totalread, 1, toread, input_fp)) > 0)
- {
- totalread += nread;
- toread -= nread;
- }
+ while ((nread = fread(bufp+totalread, 1, toread, input_fp)) > 0) {
+ totalread += nread;
+ toread -= nread;
+ }
- if ( totalread != statbuf.st_size )
- {
- printf ( "BMP read error, file size=%ld, read size=%d\n", statbuf.st_size, totalread );
- ret = -1;
- goto exit;
- }
+ if (totalread != statbuf.st_size) {
+ printf("BMP read error, file size=%ld, read size=%d\n", statbuf.st_size, totalread);
+ ret = -1;
+ goto exit;
+ }
- printf ( "Reading bmp image is success.\n" );
+ printf("Reading bmp image is success.\n");
- /* set init data */
- init_dsc.bitb.addr = filebuffer;
- init_dsc.bitb.size = totalread;
- init_dsc.bitb.mt = SCMN_MT_IMG_BMP;
- init_dsc.use_accel = 0;
+ /* set init data */
+ init_dsc.bitb.addr = filebuffer;
+ init_dsc.bitb.size = totalread;
+ init_dsc.bitb.mt = SCMN_MT_IMG_BMP;
+ init_dsc.use_accel = 0;
/* create BMP decoder's handle */
- /* create BMP decoder's handle */
- bmpd_hnd = sbmpd_create(&init_dsc, &bmpd_info, &err);
- if ( bmpd_hnd == NULL || SBMP_IS_ERR(err))
- {
- printf ( "fail in sbmpd_create, erro=%d\n", err );
- ret = -1;
- goto exit;
- }
+ /* create BMP decoder's handle */
+ bmpd_hnd = sbmpd_create(&init_dsc, &bmpd_info, &err);
+ if (bmpd_hnd == NULL || SBMP_IS_ERR(err)) {
+ printf("fail in sbmpd_create, erro=%d\n", err);
+ ret = -1;
+ goto exit;
+ }
- printf ( "Create bmp decoder is success.\n" );
+ printf("Create bmp decoder is success.\n");
/* malloc for decoded picture */
- if ( ( width > 0 ) && ( height > 0 ) )
- {
+ if ((width > 0) && (height > 0)) {
/* Resize the image */
imgb.w[0] = width;
- imgb.h[0] = height;
- }
- else
- {
+ imgb.h[0] = height;
+ } else {
/* original image size */
imgb.w[0] = bmpd_info.w;
imgb.h[0] = bmpd_info.h;
}
imgb.cs = bmpd_info.cs;
- printf ( "%d x %d --------> %d x %d \n" , bmpd_info.w, bmpd_info.h , imgb.w[0], imgb.h[0] );
+ printf("%d x %d --------> %d x %d \n" , bmpd_info.w, bmpd_info.h , imgb.w[0], imgb.h[0]);
- ret = malloc_decoded_picture ( &imgb );
- if ( ret == -1 )
- {
- printf ( "Fail to malloc decoded data\n");
+ ret = malloc_decoded_picture(&imgb);
+ if (ret == -1) {
+ printf("Fail to malloc decoded data\n");
goto exit;
}
- printf ( "Success to malloc decoded data.\n" );
+ printf("Success to malloc decoded data.\n");
/* decoding gif image */
- sret = sbmpd_decode(bmpd_hnd, &imgb, &bmpd_stat);
- if (SBMP_IS_ERR(sret))
- {
- printf("Fail to decode, erro=%d\n", sret);
- ret = -1;
- goto exit;
- }
-
- if (!bmpd_stat.pa)
- {
- printf("decoded buffer is not available\n");
- ret = -1;
- goto exit;
- }
+ sret = sbmpd_decode(bmpd_hnd, &imgb, &bmpd_stat);
+ if (SBMP_IS_ERR(sret)) {
+ printf("Fail to decode, erro=%d\n", sret);
+ ret = -1;
+ goto exit;
+ }
+
+ if (!bmpd_stat.pa) {
+ printf("decoded buffer is not available\n");
+ ret = -1;
+ goto exit;
+ }
/* Write decoded image if output_file name is set. */
- if ( output_file )
- {
- printf ( "Write decoded image. \n" );
- write_decoded_image ( output_file, imgb );
+ if (output_file) {
+ printf("Write decoded image. \n");
+ write_decoded_image(output_file, imgb);
}
exit:
- if ( bufp ) {
- free ( bufp );
+ if (bufp) {
+ free(bufp);
bufp = NULL;
}
- if ( input_fp )
- fclose ( input_fp );
+ if (input_fp)
+ fclose(input_fp);
- if ( bmpd_hnd )
- sbmpd_delete ( bmpd_hnd );
+ if (bmpd_hnd)
+ sbmpd_delete(bmpd_hnd);
- sbmp_deinit();
+ sbmp_deinit();
- printf("ret=%d\n", ret);
+ printf("ret=%d\n", ret);
return ret;
}
-static int decode_png ( const char * input_file, int width, int height, const char * output_file )
+static int decode_png(const char * input_file, int width, int height, const char * output_file)
{
- SCMN_IMGB imgb;
+ SCMN_IMGB imgb;
SPNGD_INIT_DSC init_dsc;
- SPNGD pngd_hnd = NULL;
- SPNGD_STAT pngd_stat = {0,};
- SPNGD_INFO pngd_info = {0,};
+ SPNGD pngd_hnd = NULL;
+ SPNGD_STAT pngd_stat = {0,};
+ SPNGD_INFO pngd_info = {0,};
FILE *input_fp = NULL;
- unsigned char *filebuffer = NULL;
- unsigned char *bufp = NULL;
- unsigned int nread = 0, toread = 0, totalread = 0, decoded_size = 0;
- struct stat statbuf;
+ unsigned char *filebuffer = NULL;
+ unsigned char *bufp = NULL;
+ unsigned int nread = 0, toread = 0, totalread = 0, decoded_size = 0;
+ struct stat statbuf;
- int sret = SPNG_OK;
- int ret = 0;
+ int sret = SPNG_OK;
+ int ret = 0;
int err = 0;
- /* initialize struct variable */
- memset(&imgb, 0x00, sizeof(SCMN_IMGB));
- memset(&init_dsc, 0x00, sizeof(SPNGD_INIT_DSC));
- memset(&pngd_stat, 0x00, sizeof(SPNGD_STAT));
- memset(&pngd_info, 0x00, sizeof(SPNGD_INFO));
+ /* initialize struct variable */
+ memset(&imgb, 0x00, sizeof(SCMN_IMGB));
+ memset(&init_dsc, 0x00, sizeof(SPNGD_INIT_DSC));
+ memset(&pngd_stat, 0x00, sizeof(SPNGD_STAT));
+ memset(&pngd_info, 0x00, sizeof(SPNGD_INFO));
- /* init png codec */
- sret = spng_init();
- if (SPNG_IS_ERR(sret))
- {
- printf ( "Fail to init png library\n");
- ret = -1;
- goto exit;
- }
+ /* init png codec */
+ sret = spng_init();
+ if (SPNG_IS_ERR(sret)) {
+ printf("Fail to init png library\n");
+ ret = -1;
+ goto exit;
+ }
- printf ( "Initialize png library is success.\n" );
+ printf("Initialize png library is success.\n");
- /* read data from png file */
- input_fp = fopen( input_file, "rb");
- if (input_fp == NULL)
- {
- printf ( "Fail to read png file \n" );
- goto exit;
- }
+ /* read data from png file */
+ input_fp = fopen(input_file, "rb");
+ if (input_fp == NULL) {
+ printf("Fail to read png file \n");
+ goto exit;
+ }
fstat(fileno(input_fp), &statbuf);
- if (!(statbuf.st_mode & S_IFREG))
- {
- printf ( "Input file is not regular file\n" );
- goto exit;
- }
+ if (!(statbuf.st_mode & S_IFREG)) {
+ printf("Input file is not regular file\n");
+ goto exit;
+ }
- filebuffer = malloc(statbuf.st_size);
- if (!filebuffer)
- {
- printf ( "fail to allocate file buffer\n" );
- goto exit;
- }
+ filebuffer = malloc(statbuf.st_size);
+ if (!filebuffer) {
+ printf("fail to allocate file buffer\n");
+ goto exit;
+ }
toread = statbuf.st_size;
- totalread = 0;
- bufp = filebuffer;
+ totalread = 0;
+ bufp = filebuffer;
- while ((nread = fread(bufp+totalread, 1, toread, input_fp)) > 0)
- {
- totalread += nread;
- toread -= nread;
- }
+ while ((nread = fread(bufp+totalread, 1, toread, input_fp)) > 0) {
+ totalread += nread;
+ toread -= nread;
+ }
- if (totalread != statbuf.st_size)
- {
- printf ( "PNG read error, file size=%ld, read size=%d\n", statbuf.st_size, totalread );
- goto exit;
- }
+ if (totalread != statbuf.st_size) {
+ printf("PNG read error, file size=%ld, read size=%d\n", statbuf.st_size, totalread);
+ goto exit;
+ }
- printf ( "Reading png image is success.\n" );
+ printf("Reading png image is success.\n");
- /* set init data */
- init_dsc.bitb.addr = filebuffer;
- init_dsc.bitb.size = totalread;
- init_dsc.bitb.mt = SCMN_MT_IMG_PNG;
- init_dsc.use_accel = 0;
+ /* set init data */
+ init_dsc.bitb.addr = filebuffer;
+ init_dsc.bitb.size = totalread;
+ init_dsc.bitb.mt = SCMN_MT_IMG_PNG;
+ init_dsc.use_accel = 0;
- /* create PNG decoder's handle */
- pngd_hnd = spngd_create(&init_dsc, &pngd_info, &err);
- if (pngd_hnd == NULL || SPNG_IS_ERR(err))
- {
- printf ( "fail in spngd_create, erro=%d\n", err);
- ret = -1;
- goto exit;
- }
+ /* create PNG decoder's handle */
+ pngd_hnd = spngd_create(&init_dsc, &pngd_info, &err);
+ if (pngd_hnd == NULL || SPNG_IS_ERR(err)) {
+ printf("fail in spngd_create, erro=%d\n", err);
+ ret = -1;
+ goto exit;
+ }
- printf ( "Create png decoder is success.\n" );
+ printf("Create png decoder is success.\n");
/* malloc for decoded picture */
- if ( ( width > 0 ) && ( height > 0 ) )
- {
+ if ((width > 0) && (height > 0)) {
/* Resize the image */
imgb.w[0] = width;
- imgb.h[0] = height;
- }
- else
- {
+ imgb.h[0] = height;
+ } else {
/* original image size */
imgb.w[0] = pngd_info.img_dsc[0].w;
imgb.h[0] = pngd_info.img_dsc[0].h;
}
imgb.cs = pngd_info.cs;
- printf ( "%d x %d --------> %d x %d \n" , pngd_info.img_dsc[0].w, pngd_info.img_dsc[0].h, imgb.w[0], imgb.h[0] );
+ printf("%d x %d --------> %d x %d \n" , pngd_info.img_dsc[0].w, pngd_info.img_dsc[0].h, imgb.w[0], imgb.h[0]);
- ret = malloc_decoded_picture ( &imgb );
- if ( ret == -1 )
- {
- printf ( "Fail to malloc decoded data\n");
+ ret = malloc_decoded_picture(&imgb);
+ if (ret == -1) {
+ printf("Fail to malloc decoded data\n");
goto exit;
}
- printf ( "Success to malloc decoded data.\n" );
+ printf("Success to malloc decoded data.\n");
/* decoding png image */
- sret = spngd_decode(pngd_hnd, 0,&imgb, &pngd_stat);
- if (SPNG_IS_ERR(sret))
- {
- printf("Fail to decode, erro=%d\n", sret);
- ret = -1;
- goto exit;
- }
+ sret = spngd_decode(pngd_hnd, 0, &imgb, &pngd_stat);
+ if (SPNG_IS_ERR(sret)) {
+ printf("Fail to decode, erro=%d\n", sret);
+ ret = -1;
+ goto exit;
+ }
- printf("Success to decode, erro=%d\n", sret);
+ printf("Success to decode, erro=%d\n", sret);
- if (!pngd_stat.pa)
- {
- printf("decoded buffer is not available\n");
- ret = -1;
- goto exit;
- }
+ if (!pngd_stat.pa) {
+ printf("decoded buffer is not available\n");
+ ret = -1;
+ goto exit;
+ }
- printf ( "Decoding success.\n" );
+ printf("Decoding success.\n");
/* Write decoded image if output_file name is set. */
- if ( output_file )
- {
- printf ( "Write decoded image. \n" );
- write_decoded_image ( output_file, imgb );
+ if (output_file) {
+ printf("Write decoded image. \n");
+ write_decoded_image(output_file, imgb);
}
exit:
- if ( bufp ) {
- free ( bufp );
+ if (bufp) {
+ free(bufp);
bufp = NULL;
}
- if ( input_fp )
- fclose ( input_fp );
+ if (input_fp)
+ fclose(input_fp);
- if ( pngd_hnd )
- spngd_delete ( pngd_hnd );
+ if (pngd_hnd)
+ spngd_delete(pngd_hnd);
- spng_deinit();
+ spng_deinit();
- printf("ret=%d\n", ret);
+ printf("ret=%d\n", ret);
return ret;
}
-static int decode_gif ( const char * input_file, int width, int height, const char * output_file )
+static int decode_gif(const char * input_file, int width, int height, const char * output_file)
{
- SCMN_IMGB imgb;
+ SCMN_IMGB imgb;
SGIFD_INIT_DSC init_dsc;
- SGIFD gifd_hnd = NULL;
- SGIFD_STAT gifd_stat = {0,};
- SGIFD_INFO gifd_info = {0,};
+ SGIFD gifd_hnd = NULL;
+ SGIFD_STAT gifd_stat = {0,};
+ SGIFD_INFO gifd_info = {0,};
FILE *input_fp = NULL;
- unsigned char *filebuffer = NULL;
- unsigned char *bufp = NULL;
- unsigned int nread = 0, toread = 0, totalread = 0, decoded_size = 0;
- struct stat statbuf;
+ unsigned char *filebuffer = NULL;
+ unsigned char *bufp = NULL;
+ unsigned int nread = 0, toread = 0, totalread = 0, decoded_size = 0;
+ struct stat statbuf;
- int sret = SGIF_OK;
- int ret = 0;
+ int sret = SGIF_OK;
+ int ret = 0;
int err = 0;
- /* initialize struct variable */
- memset(&imgb, 0x00, sizeof(SCMN_IMGB));
- memset(&init_dsc, 0x00, sizeof(SGIFD_INIT_DSC));
- memset(&gifd_stat, 0x00, sizeof(SGIFD_STAT));
- memset(&gifd_info, 0x00, sizeof(SGIFD_INFO));
+ /* initialize struct variable */
+ memset(&imgb, 0x00, sizeof(SCMN_IMGB));
+ memset(&init_dsc, 0x00, sizeof(SGIFD_INIT_DSC));
+ memset(&gifd_stat, 0x00, sizeof(SGIFD_STAT));
+ memset(&gifd_info, 0x00, sizeof(SGIFD_INFO));
- /* init gif codec */
- sret = sgif_init();
- if (SGIF_IS_ERR(sret))
- {
- printf ( "Fail to init gif library\n");
- ret = -1;
- goto exit;
- }
+ /* init gif codec */
+ sret = sgif_init();
+ if (SGIF_IS_ERR(sret)) {
+ printf("Fail to init gif library\n");
+ ret = -1;
+ goto exit;
+ }
- printf ( "Initialize gif library is success.\n" );
+ printf("Initialize gif library is success.\n");
- /* read data from gif file */
- input_fp = fopen( input_file, "rb");
- if (input_fp == NULL)
- {
- printf ( "Fail to read gif file \n" );
- goto exit;
- }
+ /* read data from gif file */
+ input_fp = fopen(input_file, "rb");
+ if (input_fp == NULL) {
+ printf("Fail to read gif file \n");
+ goto exit;
+ }
fstat(fileno(input_fp), &statbuf);
- if (!(statbuf.st_mode & S_IFREG))
- {
- printf ( "Input file is not regular file\n" );
- goto exit;
- }
+ if (!(statbuf.st_mode & S_IFREG)) {
+ printf("Input file is not regular file\n");
+ goto exit;
+ }
- filebuffer = malloc(statbuf.st_size);
- if (!filebuffer)
- {
- printf ( "fail to allocate file buffer\n" );
- goto exit;
- }
+ filebuffer = malloc(statbuf.st_size);
+ if (!filebuffer) {
+ printf("fail to allocate file buffer\n");
+ goto exit;
+ }
toread = statbuf.st_size;
- totalread = 0;
- bufp = filebuffer;
+ totalread = 0;
+ bufp = filebuffer;
- while ((nread = fread(bufp+totalread, 1, toread, input_fp)) > 0)
- {
- totalread += nread;
- toread -= nread;
- }
+ while ((nread = fread(bufp+totalread, 1, toread, input_fp)) > 0) {
+ totalread += nread;
+ toread -= nread;
+ }
- if (totalread != statbuf.st_size)
- {
- printf ( "GIF read error, file size=%ld, read size=%d\n", statbuf.st_size, totalread );
- goto exit;
- }
+ if (totalread != statbuf.st_size) {
+ printf("GIF read error, file size=%ld, read size=%d\n", statbuf.st_size, totalread);
+ goto exit;
+ }
- printf ( "Reading gif image is success.\n" );
+ printf("Reading gif image is success.\n");
- /* set init data */
- init_dsc.bitb.addr = filebuffer;
- init_dsc.bitb.size = totalread;
- init_dsc.bitb.mt = SCMN_MT_IMG_GIF;
- init_dsc.use_accel = 0;
+ /* set init data */
+ init_dsc.bitb.addr = filebuffer;
+ init_dsc.bitb.size = totalread;
+ init_dsc.bitb.mt = SCMN_MT_IMG_GIF;
+ init_dsc.use_accel = 0;
- /* create GIF decoder's handle */
- gifd_hnd = sgifd_create(&init_dsc, &gifd_info, &err);
- if (gifd_hnd == NULL || SGIF_IS_ERR(err))
- {
- printf ( "fail in sgifd_create, erro=%d\n", err);
- ret = -1;
- goto exit;
- }
+ /* create GIF decoder's handle */
+ gifd_hnd = sgifd_create(&init_dsc, &gifd_info, &err);
+ if (gifd_hnd == NULL || SGIF_IS_ERR(err)) {
+ printf("fail in sgifd_create, erro=%d\n", err);
+ ret = -1;
+ goto exit;
+ }
- printf ( "Create gif decoder is success.\n" );
+ printf("Create gif decoder is success.\n");
/* malloc for decoded picture */
- if ( ( width > 0 ) && ( height > 0 ) )
- {
+ if ((width > 0) && (height > 0)) {
/* Resize the image */
imgb.w[0] = width;
- imgb.h[0] = height;
- }
- else
- {
+ imgb.h[0] = height;
+ } else {
/* original image size */
imgb.w[0] = gifd_info.w;
imgb.h[0] = gifd_info.h;
}
imgb.cs = gifd_info.cs;
- printf ( "%d x %d --------> %d x %d \n" , gifd_info.w, gifd_info.h , imgb.w[0], imgb.h[0] );
+ printf("%d x %d --------> %d x %d \n" , gifd_info.w, gifd_info.h , imgb.w[0], imgb.h[0]);
- ret = malloc_decoded_picture ( &imgb );
- if ( ret == -1 )
- {
- printf ( "Fail to malloc decoded data\n");
+ ret = malloc_decoded_picture(&imgb);
+ if (ret == -1) {
+ printf("Fail to malloc decoded data\n");
goto exit;
}
- printf ( "Success to malloc decoded data.\n" );
+ printf("Success to malloc decoded data.\n");
/* decoding gif image */
- sret = sgifd_decode(gifd_hnd, 0,&imgb, &gifd_stat);
- if (SGIF_IS_ERR(sret))
- {
- printf("Fail to decode, erro=%d\n", sret);
- ret = -1;
- goto exit;
- }
+ sret = sgifd_decode(gifd_hnd, 0, &imgb, &gifd_stat);
+ if (SGIF_IS_ERR(sret)) {
+ printf("Fail to decode, erro=%d\n", sret);
+ ret = -1;
+ goto exit;
+ }
- printf("Success to decode, erro=%d\n", sret);
+ printf("Success to decode, erro=%d\n", sret);
- if (!gifd_stat.pa)
- {
- printf("decoded buffer is not available\n");
- ret = -1;
- goto exit;
- }
+ if (!gifd_stat.pa) {
+ printf("decoded buffer is not available\n");
+ ret = -1;
+ goto exit;
+ }
/* Write decoded image if output_file name is set. */
- if ( output_file )
- {
- printf ( "Write decoded image. \n" );
- write_decoded_image ( output_file, imgb );
+ if (output_file) {
+ printf("Write decoded image. \n");
+ write_decoded_image(output_file, imgb);
}
exit:
- if ( bufp ) {
- free ( bufp );
+ if (bufp) {
+ free(bufp);
bufp = NULL;
}
- if ( input_fp )
- fclose ( input_fp );
+ if (input_fp)
+ fclose(input_fp);
- if ( gifd_hnd )
- sgifd_delete ( gifd_hnd );
+ if (gifd_hnd)
+ sgifd_delete(gifd_hnd);
- sgif_deinit();
+ sgif_deinit();
- printf("ret=%d\n", ret);
+ printf("ret=%d\n", ret);
return ret;
}
-static int decode_jpg ( const char * input_file, int width, int height, const char * output_file )
+static int decode_jpg(const char * input_file, int width, int height, const char * output_file)
{
- SCMN_IMGB imgb;
+ SCMN_IMGB imgb;
SJPGD_INIT_DSC init_dsc;
- SJPGD jpgd_hnd = NULL;
- SJPGD_STAT jpgd_stat = {0,};
- SJPGD_INFO jpgd_info = {0,};
+ SJPGD jpgd_hnd = NULL;
+ SJPGD_STAT jpgd_stat = {0,};
+ SJPGD_INFO jpgd_info = {0,};
FILE *input_fp = NULL;
- unsigned char *filebuffer = NULL;
- unsigned char *bufp = NULL;
- unsigned int nread = 0, toread = 0, totalread = 0, decoded_size = 0;
- struct stat statbuf;
+ unsigned char *filebuffer = NULL;
+ unsigned char *bufp = NULL;
+ unsigned int nread = 0, toread = 0, totalread = 0, decoded_size = 0;
+ struct stat statbuf;
- int sret = SJPG_OK;
- int ret = 0;
+ int sret = SJPG_OK;
+ int ret = 0;
int err = 0;
- /* initialize struct variable */
- memset(&imgb, 0x00, sizeof(SCMN_IMGB));
- memset(&init_dsc, 0x00, sizeof(SJPGD_INIT_DSC));
- memset(&jpgd_stat, 0x00, sizeof(SJPGD_STAT));
- memset(&jpgd_info, 0x00, sizeof(SJPGD_INFO));
+ /* initialize struct variable */
+ memset(&imgb, 0x00, sizeof(SCMN_IMGB));
+ memset(&init_dsc, 0x00, sizeof(SJPGD_INIT_DSC));
+ memset(&jpgd_stat, 0x00, sizeof(SJPGD_STAT));
+ memset(&jpgd_info, 0x00, sizeof(SJPGD_INFO));
- /* init jpg codec */
- sret = sjpg_init();
- if (SJPG_IS_ERR(sret))
- {
- printf ( "Fail to init jpg library\n");
- ret = -1;
- goto exit;
- }
+ /* init jpg codec */
+ sret = sjpg_init();
+ if (SJPG_IS_ERR(sret)) {
+ printf("Fail to init jpg library\n");
+ ret = -1;
+ goto exit;
+ }
- printf ( "Initialize jpg library is success.\n" );
+ printf("Initialize jpg library is success.\n");
- /* read data from jpg file */
- input_fp = fopen( input_file, "rb");
- if (input_fp == NULL)
- {
- printf ( "Fail to read jpg file \n" );
- goto exit;
- }
+ /* read data from jpg file */
+ input_fp = fopen(input_file, "rb");
+ if (input_fp == NULL) {
+ printf("Fail to read jpg file \n");
+ goto exit;
+ }
fstat(fileno(input_fp), &statbuf);
- if (!(statbuf.st_mode & S_IFREG))
- {
- printf ( "Input file is not regular file\n" );
- goto exit;
- }
+ if (!(statbuf.st_mode & S_IFREG)) {
+ printf("Input file is not regular file\n");
+ goto exit;
+ }
- filebuffer = malloc(statbuf.st_size);
- if (!filebuffer)
- {
- printf ( "fail to allocate file buffer\n" );
- goto exit;
- }
+ filebuffer = malloc(statbuf.st_size);
+ if (!filebuffer) {
+ printf("fail to allocate file buffer\n");
+ goto exit;
+ }
toread = statbuf.st_size;
- totalread = 0;
- bufp = filebuffer;
+ totalread = 0;
+ bufp = filebuffer;
- while ((nread = fread(bufp+totalread, 1, toread, input_fp)) > 0)
- {
- totalread += nread;
- toread -= nread;
- }
+ while ((nread = fread(bufp+totalread, 1, toread, input_fp)) > 0) {
+ totalread += nread;
+ toread -= nread;
+ }
- if (totalread != statbuf.st_size)
- {
- printf ( "JPG read error, file size=%ld, read size=%d\n", statbuf.st_size, totalread );
- goto exit;
- }
+ if (totalread != statbuf.st_size) {
+ printf("JPG read error, file size=%ld, read size=%d\n", statbuf.st_size, totalread);
+ goto exit;
+ }
- printf ( "Reading jpg image is success.\n" );
+ printf("Reading jpg image is success.\n");
- /* set init data */
- init_dsc.bitb.addr = filebuffer;
- init_dsc.bitb.size = totalread;
- init_dsc.bitb.mt = SCMN_MT_IMG_JPG;
- init_dsc.use_accel = 0;
+ /* set init data */
+ init_dsc.bitb.addr = filebuffer;
+ init_dsc.bitb.size = totalread;
+ init_dsc.bitb.mt = SCMN_MT_IMG_JPG;
+ init_dsc.use_accel = 0;
- /* create JPG decoder's handle */
- jpgd_hnd = sjpgd_create(&init_dsc, &jpgd_info, &err);
- if (jpgd_hnd == NULL || SJPG_IS_ERR(err))
- {
- printf ( "fail in sjpgd_create, erro=%d\n", err);
- ret = -1;
- goto exit;
- }
+ /* create JPG decoder's handle */
+ jpgd_hnd = sjpgd_create(&init_dsc, &jpgd_info, &err);
+ if (jpgd_hnd == NULL || SJPG_IS_ERR(err)) {
+ printf("fail in sjpgd_create, erro=%d\n", err);
+ ret = -1;
+ goto exit;
+ }
- printf ( "Create jpg decoder is success.\n" );
+ printf("Create jpg decoder is success.\n");
/* malloc for decoded picture */
- if ( ( width > 0 ) && ( height > 0 ) )
- {
+ if ((width > 0) && (height > 0)) {
/* Resize the image */
imgb.w[0] = width;
- imgb.h[0] = height;
- }
- else
- {
+ imgb.h[0] = height;
+ } else {
/* original image size */
imgb.w[0] = jpgd_info.w;
imgb.h[0] = jpgd_info.h;
}
imgb.cs = jpgd_info.cs;
- printf ( "%d x %d --------> %d x %d \n" , jpgd_info.w, jpgd_info.h , imgb.w[0], imgb.h[0] );
+ printf("%d x %d --------> %d x %d \n" , jpgd_info.w, jpgd_info.h , imgb.w[0], imgb.h[0]);
- ret = malloc_decoded_picture ( &imgb );
- if ( ret == -1 )
- {
- printf ( "Fail to malloc decoded data\n");
+ ret = malloc_decoded_picture(&imgb);
+ if (ret == -1) {
+ printf("Fail to malloc decoded data\n");
goto exit;
}
- printf ( "Success to malloc decoded data.\n" );
+ printf("Success to malloc decoded data.\n");
/* decoding jpg image */
- sret = sjpgd_decode(jpgd_hnd, &imgb, &jpgd_stat);
- if (SJPG_IS_ERR(sret))
- {
- printf("Fail to decode, erro=%d\n", sret);
- ret = -1;
- goto exit;
- }
-
- if (!jpgd_stat.pa)
- {
- printf("decoded buffer is not available\n");
- ret = -1;
- goto exit;
- }
-
- printf ( "jpgd_stat.w=%d, jpgd_stat.h=%d, jpgd_stat.read=%d \n", jpgd_stat.w, jpgd_stat.h, jpgd_stat.read );
+ sret = sjpgd_decode(jpgd_hnd, &imgb, &jpgd_stat);
+ if (SJPG_IS_ERR(sret)) {
+ printf("Fail to decode, erro=%d\n", sret);
+ ret = -1;
+ goto exit;
+ }
- /* Write decoded image if output_file name is set. */
- if ( output_file )
- {
- printf ( "Write decoded image. \n" );
- write_decoded_image ( output_file, imgb );
+ if (!jpgd_stat.pa) {
+ printf("decoded buffer is not available\n");
+ ret = -1;
+ goto exit;
}
+ printf("jpgd_stat.w=%d, jpgd_stat.h=%d, jpgd_stat.read=%d \n", jpgd_stat.w, jpgd_stat.h, jpgd_stat.read);
+
+ /* Write decoded image if output_file name is set. */
+ if (output_file) {
+ printf("Write decoded image. \n");
+ write_decoded_image(output_file, imgb);
+ }
exit:
- if ( bufp ) {
- free ( bufp );
+ if (bufp) {
+ free(bufp);
bufp = NULL;
}
- if ( input_fp )
- fclose ( input_fp );
+ if (input_fp)
+ fclose(input_fp);
- if ( jpgd_hnd )
- sjpgd_delete ( jpgd_hnd );
+ if (jpgd_hnd)
+ sjpgd_delete(jpgd_hnd);
- sjpg_deinit();
+ sjpg_deinit();
- printf("ret=%d\n", ret);
+ printf("ret=%d\n", ret);
return ret;
}
int main(int argc, char *argv[])
{
-
mm_utility_image_file_format file_format;
char *input_file, *output_file;
int output_width, output_height;
- int ret = 0;
+ int ret = 0;
file_format = MM_UTILITY_IMAGE_FILE_FMT_NONE;
input_file = output_file = NULL;
output_width = output_height = 0;
/* Check image file path */
- if ( !argv[1] )
- {
- printf ( "Please input image file path. \n" );
+ if (!argv[1]) {
+ printf("Please input image file path. \n");
goto exit;
}
- input_file = g_strdup ( (const char *) argv[1] );
+ input_file = g_strdup((const char *) argv[1]);
- printf ( "Input file name is %s\n", input_file );
+ printf("Input file name is %s\n", input_file);
/* Check outpue decoded image size. if not set, use original image size. */
- if ( argv[2] && argv[3] )
- {
+ if (argv[2] && argv[3]) {
output_width = atoi(argv[2]);
output_height = atoi(argv[3]);
-
- printf ( "Resize decoded image : %dX%d\n", output_width, output_height );
+
+ printf("Resize decoded image : %dX%d\n", output_width, output_height);
}
/* Check output decoded image file path */
- if ( argc>3 && argv[4] )
- {
- output_file = g_strdup ( (const char *)argv[4] );
- printf ( "Output decoded image file path [%s]. \n", output_file );
+ if (argc > 3 && argv[4]) {
+ output_file = g_strdup((const char *)argv[4]);
+ printf("Output decoded image file path [%s]. \n", output_file);
}
/* Get image file format : bmp, gif, png, jpg */
- file_format = get_file_format ( input_file );
+ file_format = get_file_format(input_file);
/* Decode image file */
- switch ( file_format )
- {
+ switch (file_format) {
case MM_UTILITY_IMAGE_FILE_FMT_BMP:
- ret = decode_bmp ( input_file, output_width, output_height, output_file );
+ ret = decode_bmp(input_file, output_width, output_height, output_file);
break;
case MM_UTILITY_IMAGE_FILE_FMT_GIF:
- ret = decode_gif ( input_file, output_width, output_height, output_file );
+ ret = decode_gif(input_file, output_width, output_height, output_file);
break;
case MM_UTILITY_IMAGE_FILE_FMT_PNG:
- ret = decode_png ( input_file, output_width, output_height, output_file);
+ ret = decode_png(input_file, output_width, output_height, output_file);
break;
case MM_UTILITY_IMAGE_FILE_FMT_JPG:
- ret = decode_jpg ( input_file, output_width, output_height, output_file );
+ ret = decode_jpg(input_file, output_width, output_height, output_file);
break;
default:
- printf ( " This image file is not supported. \n" );
+ printf(" This image file is not supported. \n");
ret = -1;
break;
-
+
}
- if ( ret == -1 )
- printf ( "Fail to decode [%s]. \n", input_file );
+ if (ret == -1)
+ printf("Fail to decode [%s]. \n", input_file);
exit:
- if ( input_file )
- {
- g_free ( input_file );
+ if (input_file) {
+ g_free(input_file);
input_file = NULL;
}
- if ( output_file )
- {
- g_free ( output_file );
+ if (output_file) {
+ g_free(output_file);
output_file = NULL;
}
-
+
return ret;
}