free(bitmap);
}
-static int read_bmp(mm_util_bmp_data * decoded, const char *filename, void *memory, unsigned long long src_size)
+static int read_bmp(mm_util_bmp_data *decoded, const char *filename, void *memory, unsigned long long src_size)
{
bmp_bitmap_callback_vt bitmap_callbacks = {
bitmap_create,
return res;
}
-int mm_util_decode_from_bmp_file(mm_util_bmp_data * decoded, const char *filename)
+int mm_util_decode_from_bmp_file(mm_util_bmp_data *decoded, const char *filename)
{
int ret;
return ret;
}
-int mm_util_decode_from_bmp_memory(mm_util_bmp_data * decoded, void **memory, unsigned long long src_size)
+int mm_util_decode_from_bmp_memory(mm_util_bmp_data *decoded, void **memory, unsigned long long src_size)
{
int ret;
return ret;
}
-unsigned long mm_util_decode_get_width(mm_util_bmp_data * data)
+unsigned long mm_util_decode_get_width(mm_util_bmp_data *data)
{
return data->width;
}
-unsigned long mm_util_decode_get_height(mm_util_bmp_data * data)
+unsigned long mm_util_decode_get_height(mm_util_bmp_data *data)
{
return data->height;
}
-unsigned long long mm_util_decode_get_size(mm_util_bmp_data * data)
+unsigned long long mm_util_decode_get_size(mm_util_bmp_data *data)
{
return data->size;
}
-int mm_util_encode_bmp_to_file(mm_util_bmp_data * encoded, const char *filename)
+int mm_util_encode_bmp_to_file(mm_util_bmp_data *encoded, const char *filename)
{
bmpfile_t *bmp;
rgb_pixel_t pixel = { 0, 0, 0, 0 };
return MM_UTIL_ERROR_NONE;
}
-void mm_util_bmp_encode_set_width(mm_util_bmp_data * data, unsigned long width)
+void mm_util_bmp_encode_set_width(mm_util_bmp_data *data, unsigned long width)
{
data->width = width;
}
-void mm_util_bmp_encode_set_height(mm_util_bmp_data * data, unsigned long height)
+void mm_util_bmp_encode_set_height(mm_util_bmp_data *data, unsigned long height)
{
data->height = height;
}
bmp/Makefile
bmp/test/Makefile
bmp/mmutil-bmp.pc
- test/Makefile
])
AC_OUTPUT
unsigned long long size;
} write_data;
-static int convert_gif_to_rgba(mm_util_gif_data * decoded, ColorMapObject * color_map, GifRowType * screen_buffer, unsigned long width, unsigned long height)
+static int convert_gif_to_rgba(mm_util_gif_data *decoded, ColorMapObject *color_map, GifRowType *screen_buffer, unsigned long width, unsigned long height)
{
unsigned long i, j;
GifRowType gif_row;
return MM_UTIL_ERROR_NONE;
}
-static int read_function(GifFileType * gft, GifByteType * data, int size)
+static int read_function(GifFileType *gft, GifByteType *data, int size)
{
read_data *read_data_ptr = (read_data *) gft->UserData;
return size;
}
-int read_gif(mm_util_gif_data * decoded, const char *filename, void *memory)
+int read_gif(mm_util_gif_data *decoded, const char *filename, void *memory)
{
int ExtCode, i, j, Row, Col, Width, Height;
unsigned long Size;
return ret;
}
-int mm_util_decode_from_gif_file(mm_util_gif_data * decoded, const char *fpath)
+int mm_util_decode_from_gif_file(mm_util_gif_data *decoded, const char *fpath)
{
int ret;
return ret;
}
-int mm_util_decode_from_gif_memory(mm_util_gif_data * decoded, void **memory)
+int mm_util_decode_from_gif_memory(mm_util_gif_data *decoded, void **memory)
{
int ret;
return ret;
}
-unsigned long mm_util_decode_get_width(mm_util_gif_data * data)
+unsigned long mm_util_decode_get_width(mm_util_gif_data *data)
{
return data->width;
}
-unsigned long mm_util_decode_get_height(mm_util_gif_data * data)
+unsigned long mm_util_decode_get_height(mm_util_gif_data *data)
{
return data->height;
}
-unsigned long long mm_util_decode_get_size(mm_util_gif_data * data)
+unsigned long long mm_util_decode_get_size(mm_util_gif_data *data)
{
return data->size;
}
-static void load_rgb_from_buffer(GifByteType * buffer, GifByteType ** red, GifByteType ** green, GifByteType ** blue, unsigned long width, unsigned long height)
+static void load_rgb_from_buffer(GifByteType *buffer, GifByteType **red, GifByteType **green, GifByteType **blue, unsigned long width, unsigned long height)
{
unsigned long i, j;
unsigned long Size;
return;
}
-static int save_buffer_to_gif(GifFileType * GifFile, GifByteType * OutputBuffer, unsigned long width, unsigned long height, unsigned long long delay_time)
+static int save_buffer_to_gif(GifFileType *GifFile, GifByteType *OutputBuffer, unsigned long width, unsigned long height, unsigned long long delay_time)
{
unsigned long i;
GifByteType *Ptr = OutputBuffer;
return MM_UTIL_ERROR_NONE;
}
-static void outputbuffer_free(GifByteType ** OutputBuffer, unsigned int image_count)
+static void outputbuffer_free(GifByteType **OutputBuffer, unsigned int image_count)
{
unsigned int j;
free(OutputBuffer);
}
-static int write_function(GifFileType * gft, const GifByteType * data, int size)
+static int write_function(GifFileType *gft, const GifByteType *data, int size)
{
write_data *write_data_ptr = (write_data *) gft->UserData;
return size;
}
-int write_gif(mm_util_gif_data * encoded, const char *filename, void **data)
+int write_gif(mm_util_gif_data *encoded, const char *filename, void **data)
{
int ColorMapSize;
unsigned int i = 0;
return MM_UTIL_ERROR_NONE;
}
-int mm_util_encode_gif_to_file(mm_util_gif_data * encoded, const char *fpath)
+int mm_util_encode_gif_to_file(mm_util_gif_data *encoded, const char *fpath)
{
int ret;
return ret;
}
-int mm_util_encode_gif_to_memory(mm_util_gif_data * encoded, void **data)
+int mm_util_encode_gif_to_memory(mm_util_gif_data *encoded, void **data)
{
int ret;
return ret;
}
-void mm_util_gif_encode_set_width(mm_util_gif_data * data, unsigned long width)
+void mm_util_gif_encode_set_width(mm_util_gif_data *data, unsigned long width)
{
data->width = width;
}
-void mm_util_gif_encode_set_height(mm_util_gif_data * data, unsigned long height)
+void mm_util_gif_encode_set_height(mm_util_gif_data *data, unsigned long height)
{
data->height = height;
}
-void mm_util_gif_encode_set_image_count(mm_util_gif_data * data, unsigned int image_count)
+void mm_util_gif_encode_set_image_count(mm_util_gif_data *data, unsigned int image_count)
{
data->image_count = image_count;
}
-void mm_util_gif_encode_set_frame_delay_time(mm_util_gif_frame_data * frame, unsigned long long delay_time)
+void mm_util_gif_encode_set_frame_delay_time(mm_util_gif_frame_data *frame, unsigned long long delay_time)
{
frame->delay_time = delay_time;
}
#include <ttrace.h>
#define TTRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_IMAGE, NAME)
#define TTRACE_END() traceEnd(TTRACE_TAG_IMAGE)
-#else //ENABLE_TTRACE
+#else /* ENABLE_TTRACE */
#define TTRACE_BEGIN(NAME)
#define TTRACE_END()
-#endif //ENABLE_TTRACE
+#endif /* ENABLE_TTRACE */
#define RGB_COLOR_CHANNELS 3
#define HSV_COLOR_CHANNELS 3
handle->height = height;
handle->inImg = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, RGB_COLOR_CHANNELS);
- if (handle->inImg == NULL) {
+ if (handle->inImg == NULL)
return MM_UTIL_ERROR_INVALID_OPERATION;
- }
handle->hBins = DEFAULT_NUM_HBINS;
handle->sBins = DEFAULT_NUM_SBINS;
mm_util_debug("image_buffer [%p], width [%d]", buffer, handle->width);
cvSetData(handle->inImg, buffer, RGB_COLOR_CHANNELS*(handle->width));
- if (handle->inImg == NULL) {
+ if (handle->inImg == NULL)
return MM_UTIL_ERROR_INVALID_OPERATION;
- }
mm_util_debug("Leave _mm_util_imgcv_set_buffer");
cvCvtColor(handle->inImg, hsvImg, CV_RGB2HSV);
cvSplit(hsvImg, hImg, sImg, vImg, NULL);
- float * ranges[] = {handle->hRanges, handle->sRanges, handle->vRanges};
+ float *ranges[] = {handle->hRanges, handle->sRanges, handle->vRanges};
int histsize[] = {handle->sizeOfHist[0], handle->sizeOfHist[1], handle->sizeOfHist[2]};
/* create histogram*/
CvHistogram *hist = cvCreateHist(HISTOGRAM_CHANNELS, histsize, CV_HIST_ARRAY, ranges, 1);
- if (hist == NULL) {
+ if (hist == NULL)
return MM_UTIL_ERROR_INVALID_OPERATION;
- }
cvCalcHist(planes, hist, 0, NULL);
unsigned char rgb_r, rgb_g, rgb_b;
ret = mm_util_cv_extract_representative_color(img_buffer, width, height, &rgb_r, &rgb_g, &rgb_b);
- if (!ret) {
+ if (!ret)
fprintf(stderr, "Success - R[%d], G[%d], B[%d]", rgb_r, rgb_g, rgb_b);
- } else {
+ else
fprintf(stderr, "Error - fail to extract color");
- }
free(img_buffer);
img_buffer = NULL;
#include <ttrace.h>
#define TTRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_IMAGE, NAME)
#define TTRACE_END() traceEnd(TTRACE_TAG_IMAGE)
-#else //ENABLE_TTRACE
+#else /* ENABLE_TTRACE */
#define TTRACE_BEGIN(NAME)
#define TTRACE_END()
-#endif //ENABLE_TTRACE
+#endif /* ENABLE_TTRACE */
#define MM_UTIL_ROUND_UP_2(num) (((num)+1)&~1)
#define MM_UTIL_ROUND_UP_4(num) (((num)+3)&~3)
#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 __mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet);
+typedef gboolean(*IMGPInfoFunc) (imgp_info_s *, const unsigned char *, unsigned char *, imgp_plugin_type_e);
+static int __mm_util_transform_exec(mm_util_s *handle, media_packet_h src_packet);
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;
- }
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
{
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)
return _bool;
}
-static gboolean __mm_gst_can_resize_format(char* __format_label)
+static gboolean __mm_gst_can_resize_format(char *__format_label)
{
gboolean _bool = FALSE;
return _bool;
}
-static gboolean __mm_gst_can_rotate_format(const char* __format_label)
+static gboolean __mm_gst_can_rotate_format(const char *__format_label)
{
gboolean _bool = FALSE;
mm_util_debug("_format: %d", _format);
- if ((_format == MM_UTIL_IMG_FMT_UYVY) || (_format == MM_UTIL_IMG_FMT_YUYV) || (_format == MM_UTIL_IMG_FMT_RGBA8888) || (_format == MM_UTIL_IMG_FMT_BGRX8888)) {
+ if ((_format == MM_UTIL_IMG_FMT_UYVY) || (_format == MM_UTIL_IMG_FMT_YUYV) ||
+ (_format == MM_UTIL_IMG_FMT_RGBA8888) || (_format == MM_UTIL_IMG_FMT_BGRX8888))
_bool = FALSE;
- } else {
+ else
_bool = TRUE;
- }
return _bool;
}
}
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);
- 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);
- size2 = stride2 * h2;
- *imgsize = size + 2 * size2;
- break;
- case MM_UTIL_IMG_FMT_YUV422:
- case MM_UTIL_IMG_FMT_YUYV:
- 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;
- size = stride * height;
- *imgsize = size;
- break;
-
- case MM_UTIL_IMG_FMT_RGB565:
- 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;
- size = stride * MM_UTIL_ROUND_UP_2(height);
- *imgsize = size;
- break;
-
- case MM_UTIL_IMG_FMT_ARGB8888:
- case MM_UTIL_IMG_FMT_BGRA8888:
- case MM_UTIL_IMG_FMT_RGBA8888:
- case MM_UTIL_IMG_FMT_BGRX8888:
- stride = width * 4;
- size = stride * MM_UTIL_ROUND_UP_2(height);
- *imgsize = size;
- break;
-
-
- case MM_UTIL_IMG_FMT_NV12:
- 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);
- 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);
- size2 = stride2 * h2;
- *imgsize = size + size2;
- break;
-
- default:
- mm_util_error("Not supported format");
- TTRACE_END();
- return MM_UTIL_ERROR_NOT_SUPPORTED_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);
+ 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);
+ size2 = stride2 * h2;
+ *imgsize = size + 2 * size2;
+ break;
+ case MM_UTIL_IMG_FMT_YUV422:
+ case MM_UTIL_IMG_FMT_YUYV:
+ 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;
+ size = stride * height;
+ *imgsize = size;
+ break;
+
+ case MM_UTIL_IMG_FMT_RGB565:
+ 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;
+ size = stride * MM_UTIL_ROUND_UP_2(height);
+ *imgsize = size;
+ break;
+
+ case MM_UTIL_IMG_FMT_ARGB8888:
+ case MM_UTIL_IMG_FMT_BGRA8888:
+ case MM_UTIL_IMG_FMT_RGBA8888:
+ case MM_UTIL_IMG_FMT_BGRX8888:
+ stride = width * 4;
+ size = stride * MM_UTIL_ROUND_UP_2(height);
+ *imgsize = size;
+ break;
+
+
+ case MM_UTIL_IMG_FMT_NV12:
+ 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);
+ 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);
+ size2 = stride2 * h2;
+ *imgsize = size + size2;
+ break;
+
+ default:
+ mm_util_error("Not supported format");
+ TTRACE_END();
+ return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
}
mm_util_debug("format: %d, *imgsize: %d\n", format, *imgsize);
}
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) {
- 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) {
- 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) {
- 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) {
- mm_util_debug("*dst_height: %d", *dst_height);
- *dst_height = src_width;
- mm_util_debug("#Confirmed# *dst_height: %d", *dst_height);
- }
- break;
+ 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) {
+ 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) {
+ 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) {
+ 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) {
+ mm_util_debug("*dst_height: %d", *dst_height);
+ *dst_height = src_width;
+ mm_util_debug("#Confirmed# *dst_height: %d", *dst_height);
+ }
+ break;
- default:
- mm_util_error("Not supported rotate value");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
+ default:
+ mm_util_error("Not supported rotate value");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
}
return ret;
}
-static int __mm_set_format_label(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, mm_util_img_format dst_format)
+static int __mm_set_format_label(imgp_info_s *_imgp_info_s, mm_util_img_format src_format, mm_util_img_format dst_format)
{
int ret = MM_UTIL_ERROR_NONE;
char *src_fmt_lable = NULL;
}
switch (src_format) {
- case MM_UTIL_IMG_FMT_YUV420:
- src_fmt_lable = (char *)"YV12";
- break;
- case MM_UTIL_IMG_FMT_YUV422:
- src_fmt_lable = (char *)"Y42B";
- break;
- case MM_UTIL_IMG_FMT_I420:
- src_fmt_lable = (char *)"I420";
- break;
- case MM_UTIL_IMG_FMT_NV12:
- src_fmt_lable = (char *)"NV12";
- break;
- case MM_UTIL_IMG_FMT_UYVY:
- src_fmt_lable = (char *)"UYVY";
- break;
- case MM_UTIL_IMG_FMT_YUYV:
- src_fmt_lable = (char *)"YUYV";
- break;
- case MM_UTIL_IMG_FMT_RGB565:
- src_fmt_lable = (char *)"RGB565";
- break;
- case MM_UTIL_IMG_FMT_RGB888:
- src_fmt_lable = (char *)"RGB888";
- break;
- case MM_UTIL_IMG_FMT_ARGB8888:
- src_fmt_lable = (char *)"ARGB8888";
- break;
- case MM_UTIL_IMG_FMT_BGRA8888:
- src_fmt_lable = (char *)"BGRA8888";
- break;
- case MM_UTIL_IMG_FMT_RGBA8888:
- src_fmt_lable = (char *)"RGBA8888";
- break;
- case MM_UTIL_IMG_FMT_BGRX8888:
- src_fmt_lable = (char *)"BGRX";
- break;
- default:
- mm_util_debug("[%d] Not supported format", src_fmt_lable);
- break;
+ case MM_UTIL_IMG_FMT_YUV420:
+ src_fmt_lable = (char *)"YV12";
+ break;
+ case MM_UTIL_IMG_FMT_YUV422:
+ src_fmt_lable = (char *)"Y42B";
+ break;
+ case MM_UTIL_IMG_FMT_I420:
+ src_fmt_lable = (char *)"I420";
+ break;
+ case MM_UTIL_IMG_FMT_NV12:
+ src_fmt_lable = (char *)"NV12";
+ break;
+ case MM_UTIL_IMG_FMT_UYVY:
+ src_fmt_lable = (char *)"UYVY";
+ break;
+ case MM_UTIL_IMG_FMT_YUYV:
+ src_fmt_lable = (char *)"YUYV";
+ break;
+ case MM_UTIL_IMG_FMT_RGB565:
+ src_fmt_lable = (char *)"RGB565";
+ break;
+ case MM_UTIL_IMG_FMT_RGB888:
+ src_fmt_lable = (char *)"RGB888";
+ break;
+ case MM_UTIL_IMG_FMT_ARGB8888:
+ src_fmt_lable = (char *)"ARGB8888";
+ break;
+ case MM_UTIL_IMG_FMT_BGRA8888:
+ src_fmt_lable = (char *)"BGRA8888";
+ break;
+ case MM_UTIL_IMG_FMT_RGBA8888:
+ src_fmt_lable = (char *)"RGBA8888";
+ break;
+ case MM_UTIL_IMG_FMT_BGRX8888:
+ src_fmt_lable = (char *)"BGRX";
+ break;
+ default:
+ mm_util_debug("[%d] Not supported format", src_fmt_lable);
+ break;
}
switch (dst_format) {
- case MM_UTIL_IMG_FMT_YUV420:
- dst_fmt_lable = (char *)"YV12";
- break;
- case MM_UTIL_IMG_FMT_YUV422:
- dst_fmt_lable = (char *)"Y42B";
- break;
- case MM_UTIL_IMG_FMT_I420:
- dst_fmt_lable = (char *)"I420";
- break;
- case MM_UTIL_IMG_FMT_NV12:
- dst_fmt_lable = (char *)"NV12";
- break;
- case MM_UTIL_IMG_FMT_UYVY:
- dst_fmt_lable = (char *)"UYVY";
- break;
- case MM_UTIL_IMG_FMT_YUYV:
- dst_fmt_lable = (char *)"YUYV";
- break;
- case MM_UTIL_IMG_FMT_RGB565:
- dst_fmt_lable = (char *)"RGB565";
- break;
- case MM_UTIL_IMG_FMT_RGB888:
- dst_fmt_lable = (char *)"RGB888";
- break;
- case MM_UTIL_IMG_FMT_ARGB8888:
- dst_fmt_lable = (char *)"ARGB8888";
- break;
- case MM_UTIL_IMG_FMT_BGRA8888:
- dst_fmt_lable = (char *)"BGRA8888";
- break;
- case MM_UTIL_IMG_FMT_RGBA8888:
- dst_fmt_lable = (char *)"RGBA8888";
- break;
- case MM_UTIL_IMG_FMT_BGRX8888:
- dst_fmt_lable = (char *)"BGRX";
- break;
- default:
- mm_util_error("[%d] Not supported format", dst_format);
- break;
+ case MM_UTIL_IMG_FMT_YUV420:
+ dst_fmt_lable = (char *)"YV12";
+ break;
+ case MM_UTIL_IMG_FMT_YUV422:
+ dst_fmt_lable = (char *)"Y42B";
+ break;
+ case MM_UTIL_IMG_FMT_I420:
+ dst_fmt_lable = (char *)"I420";
+ break;
+ case MM_UTIL_IMG_FMT_NV12:
+ dst_fmt_lable = (char *)"NV12";
+ break;
+ case MM_UTIL_IMG_FMT_UYVY:
+ dst_fmt_lable = (char *)"UYVY";
+ break;
+ case MM_UTIL_IMG_FMT_YUYV:
+ dst_fmt_lable = (char *)"YUYV";
+ break;
+ case MM_UTIL_IMG_FMT_RGB565:
+ dst_fmt_lable = (char *)"RGB565";
+ break;
+ case MM_UTIL_IMG_FMT_RGB888:
+ dst_fmt_lable = (char *)"RGB888";
+ break;
+ case MM_UTIL_IMG_FMT_ARGB8888:
+ dst_fmt_lable = (char *)"ARGB8888";
+ break;
+ case MM_UTIL_IMG_FMT_BGRA8888:
+ dst_fmt_lable = (char *)"BGRA8888";
+ break;
+ case MM_UTIL_IMG_FMT_RGBA8888:
+ dst_fmt_lable = (char *)"RGBA8888";
+ break;
+ case MM_UTIL_IMG_FMT_BGRX8888:
+ dst_fmt_lable = (char *)"BGRX";
+ break;
+ default:
+ mm_util_error("[%d] Not supported format", dst_format);
+ break;
}
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);
+ _imgp_info_s->input_format_label = (char *)malloc(strlen(src_fmt_lable) + 1);
if (_imgp_info_s->input_format_label == NULL) {
mm_util_error("[input] input_format_label is null");
return MM_UTIL_ERROR_OUT_OF_MEMORY;
memset(_imgp_info_s->input_format_label, 0, strlen(src_fmt_lable) + 1);
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);
+ _imgp_info_s->output_format_label = (char *)malloc(strlen(dst_fmt_lable) + 1);
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 ret;
}
-static int __mm_set_imgp_info_s(imgp_info_s * _imgp_info_s, mm_util_img_format src_format, unsigned int src_width, unsigned int src_height, mm_util_img_format dst_format, unsigned int dst_width, unsigned int dst_height, mm_util_img_rotate_type angle)
+static int __mm_set_imgp_info_s(imgp_info_s *_imgp_info_s, mm_util_img_format src_format, unsigned int src_width, unsigned int src_height, mm_util_img_format dst_format, unsigned int dst_width, unsigned int dst_height, mm_util_img_rotate_type angle)
{
int ret = MM_UTIL_ERROR_NONE;
return ret;
}
-static GModule * __mm_util_imgp_initialize(imgp_plugin_type_e _imgp_plugin_type_e)
+static GModule *__mm_util_imgp_initialize(imgp_plugin_type_e _imgp_plugin_type_e)
{
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) {
mm_util_error("%s | %s module open failed", PATH_NEON_LIB, PATH_GSTCS_LIB);
return NULL;
}
- g_module_symbol(module, IMGP_FUNC_NAME, (gpointer*)&mm_util_imgp_func);
+ g_module_symbol(module, IMGP_FUNC_NAME, (gpointer *)&mm_util_imgp_func);
mm_util_debug("mm_util_imgp_func: %p", mm_util_imgp_func);
return mm_util_imgp_func;
}
-static int _mm_util_transform_packet_finalize_callback(media_packet_h packet, int err, void* userdata)
+static int _mm_util_transform_packet_finalize_callback(media_packet_h packet, int err, void *userdata)
{
mm_util_debug("==> finalize callback func is called [%d] \n", err);
return MEDIA_PACKET_FINALIZE;
media_format_mimetype_e mimetype = -1;
switch (format) {
- case MM_UTIL_IMG_FMT_NV12:
- mimetype = MEDIA_FORMAT_NV12;
- break;
- case MM_UTIL_IMG_FMT_NV16:
- mimetype = MEDIA_FORMAT_NV16;
- break;
- case MM_UTIL_IMG_FMT_YUYV:
- mimetype = MEDIA_FORMAT_YUYV;
- break;
- case MM_UTIL_IMG_FMT_UYVY:
- mimetype = MEDIA_FORMAT_UYVY;
- break;
- case MM_UTIL_IMG_FMT_YUV422:
- mimetype = MEDIA_FORMAT_422P;
- break;
- case MM_UTIL_IMG_FMT_I420:
- mimetype = MEDIA_FORMAT_I420;
- break;
- case MM_UTIL_IMG_FMT_YUV420:
- mimetype = MEDIA_FORMAT_YV12;
- break;
- case MM_UTIL_IMG_FMT_RGB565:
- mimetype = MEDIA_FORMAT_RGB565;
- break;
- case MM_UTIL_IMG_FMT_RGB888:
- mimetype = MEDIA_FORMAT_RGB888;
- break;
- case MM_UTIL_IMG_FMT_RGBA8888:
- mimetype = MEDIA_FORMAT_RGBA;
- break;
- case MM_UTIL_IMG_FMT_ARGB8888:
- mimetype = MEDIA_FORMAT_ARGB;
- break;
- case MM_UTIL_IMG_FMT_NV12_TILED:
- mimetype = MEDIA_FORMAT_NV12T;
- break;
- default:
- mimetype = -1;
- mm_util_error("Not Supported Format [%d]", format);
- break;
+ case MM_UTIL_IMG_FMT_NV12:
+ mimetype = MEDIA_FORMAT_NV12;
+ break;
+ case MM_UTIL_IMG_FMT_NV16:
+ mimetype = MEDIA_FORMAT_NV16;
+ break;
+ case MM_UTIL_IMG_FMT_YUYV:
+ mimetype = MEDIA_FORMAT_YUYV;
+ break;
+ case MM_UTIL_IMG_FMT_UYVY:
+ mimetype = MEDIA_FORMAT_UYVY;
+ break;
+ case MM_UTIL_IMG_FMT_YUV422:
+ mimetype = MEDIA_FORMAT_422P;
+ break;
+ case MM_UTIL_IMG_FMT_I420:
+ mimetype = MEDIA_FORMAT_I420;
+ break;
+ case MM_UTIL_IMG_FMT_YUV420:
+ mimetype = MEDIA_FORMAT_YV12;
+ break;
+ case MM_UTIL_IMG_FMT_RGB565:
+ mimetype = MEDIA_FORMAT_RGB565;
+ break;
+ case MM_UTIL_IMG_FMT_RGB888:
+ mimetype = MEDIA_FORMAT_RGB888;
+ break;
+ case MM_UTIL_IMG_FMT_RGBA8888:
+ mimetype = MEDIA_FORMAT_RGBA;
+ break;
+ case MM_UTIL_IMG_FMT_ARGB8888:
+ mimetype = MEDIA_FORMAT_ARGB;
+ break;
+ case MM_UTIL_IMG_FMT_NV12_TILED:
+ mimetype = MEDIA_FORMAT_NV12T;
+ break;
+ default:
+ mimetype = -1;
+ mm_util_error("Not Supported Format [%d]", format);
+ break;
}
mm_util_debug("imgp fmt: %d mimetype fmt: %d", format, mimetype);
mm_util_img_format format = -1;
switch (mimetype) {
- case MEDIA_FORMAT_NV12:
- format = MM_UTIL_IMG_FMT_NV12;
- break;
- case MEDIA_FORMAT_NV16:
- format = MM_UTIL_IMG_FMT_NV16;
- break;
- case MEDIA_FORMAT_YUYV:
- format = MM_UTIL_IMG_FMT_YUYV;
- break;
- case MEDIA_FORMAT_UYVY:
- format = MM_UTIL_IMG_FMT_UYVY;
- break;
- case MEDIA_FORMAT_422P:
- format = MM_UTIL_IMG_FMT_YUV422;
- break;
- case MEDIA_FORMAT_I420:
- format = MM_UTIL_IMG_FMT_I420;
- break;
- case MEDIA_FORMAT_YV12:
- format = MM_UTIL_IMG_FMT_YUV420;
- break;
- case MEDIA_FORMAT_RGB565:
- format = MM_UTIL_IMG_FMT_RGB565;
- break;
- case MEDIA_FORMAT_RGB888:
- format = MM_UTIL_IMG_FMT_RGB888;
- break;
- case MEDIA_FORMAT_RGBA:
- format = MM_UTIL_IMG_FMT_RGBA8888;
- break;
- case MEDIA_FORMAT_ARGB:
- format = MM_UTIL_IMG_FMT_ARGB8888;
- break;
- case MEDIA_FORMAT_NV12T:
- format = MM_UTIL_IMG_FMT_NV12_TILED;
- break;
- default:
- format = -1;
- mm_util_error("Not Supported Format [%d]", mimetype);
- break;
+ case MEDIA_FORMAT_NV12:
+ format = MM_UTIL_IMG_FMT_NV12;
+ break;
+ case MEDIA_FORMAT_NV16:
+ format = MM_UTIL_IMG_FMT_NV16;
+ break;
+ case MEDIA_FORMAT_YUYV:
+ format = MM_UTIL_IMG_FMT_YUYV;
+ break;
+ case MEDIA_FORMAT_UYVY:
+ format = MM_UTIL_IMG_FMT_UYVY;
+ break;
+ case MEDIA_FORMAT_422P:
+ format = MM_UTIL_IMG_FMT_YUV422;
+ break;
+ case MEDIA_FORMAT_I420:
+ format = MM_UTIL_IMG_FMT_I420;
+ break;
+ case MEDIA_FORMAT_YV12:
+ format = MM_UTIL_IMG_FMT_YUV420;
+ break;
+ case MEDIA_FORMAT_RGB565:
+ format = MM_UTIL_IMG_FMT_RGB565;
+ break;
+ case MEDIA_FORMAT_RGB888:
+ format = MM_UTIL_IMG_FMT_RGB888;
+ break;
+ case MEDIA_FORMAT_RGBA:
+ format = MM_UTIL_IMG_FMT_RGBA8888;
+ break;
+ case MEDIA_FORMAT_ARGB:
+ format = MM_UTIL_IMG_FMT_ARGB8888;
+ break;
+ case MEDIA_FORMAT_NV12T:
+ format = MM_UTIL_IMG_FMT_NV12_TILED;
+ break;
+ default:
+ format = -1;
+ mm_util_error("Not Supported Format [%d]", mimetype);
+ break;
}
mm_util_debug("mimetype: %d imgp fmt: %d", mimetype, format);
gpointer _mm_util_thread_repeate(gpointer data)
{
- mm_util_s* handle = (mm_util_s*) data;
+ mm_util_s *handle = (mm_util_s *) data;
int ret = MM_UTIL_ERROR_NONE;
gint64 end_time = 0;
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{
+ else
mm_util_error("Error - transform_exec");
- }
+
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);
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 {
+ else
mm_util_error("ERROR - async queue is already created");
- }
g_cond_init(&(handle->thread_cond));
if (handle->set_resize || handle->set_crop) {
unsigned int temp_swap = 0;
switch (handle->dst_rotation) {
- case MM_UTIL_ROTATION_90:
- case MM_UTIL_ROTATION_270:
- temp_swap = handle->dst_width;
- handle->dst_width = handle->dst_height;
- handle->dst_height = temp_swap;
- break;
- default:
- break;
+ case MM_UTIL_ROTATION_90:
+ case MM_UTIL_ROTATION_270:
+ temp_swap = handle->dst_width;
+ handle->dst_width = handle->dst_height;
+ handle->dst_height = temp_swap;
+ break;
+ default:
+ break;
}
}
mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
return ret;
}
-static int __mm_util_transform_exec(mm_util_s * handle, media_packet_h src_packet)
+static int __mm_util_transform_exec(mm_util_s *handle, media_packet_h src_packet)
{
int ret = MM_UTIL_ERROR_NONE;
media_format_h src_fmt;
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)) {
/* src */
if (handle->set_rotate) {
if ((handle->set_crop) || (handle->set_resize)) {
switch (handle->dst_rotation) {
- case MM_UTIL_ROTATION_90:
- case MM_UTIL_ROTATION_270:
- dst_width = handle->dst_height;
- dst_height = handle->dst_width;
- break;
- default:
- dst_width = handle->dst_width;
- dst_height = handle->dst_height;
- break;
+ case MM_UTIL_ROTATION_90:
+ case MM_UTIL_ROTATION_270:
+ dst_width = handle->dst_height;
+ dst_height = handle->dst_width;
+ break;
+ default:
+ dst_width = handle->dst_width;
+ dst_height = handle->dst_height;
+ break;
}
} else {
switch (handle->dst_rotation) {
- case MM_UTIL_ROTATION_90:
- case MM_UTIL_ROTATION_270:
- dst_width = handle->dst_width = handle->src_height;
- dst_height = handle->dst_height = handle->src_width;
- break;
- case MM_UTIL_ROTATION_NONE:
- case MM_UTIL_ROTATION_180:
- case MM_UTIL_ROTATION_FLIP_HORZ:
- case MM_UTIL_ROTATION_FLIP_VERT:
- dst_width = handle->dst_width = handle->src_width;
- dst_height = handle->dst_height = handle->src_height;
- break;
- default:
- mm_util_error("[Error] Wrong dst_rotation");
- break;
+ case MM_UTIL_ROTATION_90:
+ case MM_UTIL_ROTATION_270:
+ dst_width = handle->dst_width = handle->src_height;
+ dst_height = handle->dst_height = handle->src_width;
+ break;
+ case MM_UTIL_ROTATION_NONE:
+ case MM_UTIL_ROTATION_180:
+ case MM_UTIL_ROTATION_FLIP_HORZ:
+ case MM_UTIL_ROTATION_FLIP_VERT:
+ dst_width = handle->dst_width = handle->src_width;
+ dst_height = handle->dst_height = handle->src_height;
+ break;
+ default:
+ mm_util_error("[Error] Wrong dst_rotation");
+ break;
}
}
} else {
TTRACE_BEGIN("MM_UTILITY:IMGP:SET_CROP_AREA");
- unsigned int dest_width = end_x -start_x;
+ unsigned int dest_width = end_x - start_x;
unsigned int dest_height = end_y - start_y;
if (!handle) {
return ret;
}
-int mm_util_transform(mm_util_imgp_h imgp_handle, media_packet_h src_packet, mm_util_completed_callback completed_callback, void * user_data)
+int mm_util_transform(mm_util_imgp_h imgp_handle, media_packet_h src_packet, mm_util_completed_callback completed_callback, void *user_data)
{
int ret = MM_UTIL_ERROR_NONE;
mm_util_s *handle = (mm_util_s *) imgp_handle;
int mm_util_destroy(mm_util_imgp_h imgp_handle)
{
int ret = MM_UTIL_ERROR_NONE;
- mm_util_s *handle = (mm_util_s*) imgp_handle;
+ mm_util_s *handle = (mm_util_s *) imgp_handle;
TTRACE_BEGIN("MM_UTILITY:IMGP:DESTROY");
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();
imgp_plugin_type_e _imgp_plugin_type_e = 0;
/* Initialize */
- if (__mm_select_convert_plugin(src_format, dst_format)) {
+ if (__mm_select_convert_plugin(src_format, dst_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);
return ret;
}
- output_buffer = (unsigned char*)malloc(output_buffer_size);
+ output_buffer = (unsigned char *) malloc(output_buffer_size);
if (output_buffer == NULL) {
mm_util_error("malloc failed");
__mm_util_imgp_finalize(_module, _imgp_info_s);
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();
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);
return ret;
}
- output_buffer = (unsigned char*)malloc(output_buffer_size);
+ output_buffer = (unsigned char *) malloc(output_buffer_size);
if (output_buffer == NULL) {
mm_util_error("malloc failed");
__mm_util_imgp_finalize(_module, _imgp_info_s);
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();
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);
return ret;
}
- output_buffer = (unsigned char*)malloc(output_buffer_size);
+ output_buffer = (unsigned char *) malloc(output_buffer_size);
if (output_buffer == NULL) {
mm_util_error("malloc failed");
__mm_util_imgp_finalize(_module, _imgp_info_s);
}
switch (src_format) {
- case MM_UTIL_IMG_FMT_RGB888: {
- ret = __mm_util_crop_rgb888(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
- break;
- }
- case MM_UTIL_IMG_FMT_RGB565: {
- ret = __mm_util_crop_rgb565(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
- break;
- }
- case MM_UTIL_IMG_FMT_ARGB8888:
- case MM_UTIL_IMG_FMT_BGRA8888:
- case MM_UTIL_IMG_FMT_RGBA8888:
- case MM_UTIL_IMG_FMT_BGRX8888: {
- ret = __mm_util_crop_rgba32(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
- break;
- }
- case MM_UTIL_IMG_FMT_I420:
- case MM_UTIL_IMG_FMT_YUV420: {
- if ((*crop_dest_width % 2) != 0) {
- 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);
- }
+ case MM_UTIL_IMG_FMT_RGB888: {
+ ret = __mm_util_crop_rgb888(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ break;
+ }
+ case MM_UTIL_IMG_FMT_RGB565: {
+ ret = __mm_util_crop_rgb565(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ break;
+ }
+ case MM_UTIL_IMG_FMT_ARGB8888:
+ case MM_UTIL_IMG_FMT_BGRA8888:
+ case MM_UTIL_IMG_FMT_RGBA8888:
+ case MM_UTIL_IMG_FMT_BGRX8888: {
+ ret = __mm_util_crop_rgba32(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ break;
+ }
+ case MM_UTIL_IMG_FMT_I420:
+ case MM_UTIL_IMG_FMT_YUV420: {
+ if ((*crop_dest_width % 2) != 0) {
+ 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);
+ }
- 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);
- }
+ 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);
+ }
- ret = __mm_util_crop_yuv420(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
- break;
- }
- default:
- mm_util_debug("Not supported format");
- ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+ ret = __mm_util_crop_yuv420(src, src_width, src_height, src_format, crop_start_x, crop_start_y, *crop_dest_width, *crop_dest_height, dst);
+ break;
+ }
+ default:
+ mm_util_debug("Not supported format");
+ ret = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
}
TTRACE_END();
}
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);
- 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);
- size2 = stride2 * h2;
- *imgsize = size + 2 * size2;
- break;
- case MM_UTIL_IMG_FMT_YUV422:
- case MM_UTIL_IMG_FMT_YUYV:
- 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;
- size = stride * height;
- *imgsize = size;
- break;
-
- case MM_UTIL_IMG_FMT_RGB565:
- 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;
- size = stride * height;
- *imgsize = size;
- break;
-
- case MM_UTIL_IMG_FMT_ARGB8888:
- case MM_UTIL_IMG_FMT_BGRA8888:
- case MM_UTIL_IMG_FMT_RGBA8888:
- case MM_UTIL_IMG_FMT_BGRX8888:
- stride = width * 4;
- size = stride * height;
- *imgsize = size;
- break;
-
-
- case MM_UTIL_IMG_FMT_NV12:
- 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);
- 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);
- size2 = stride2 * h2;
- *imgsize = size + size2;
- break;
-
- default:
- mm_util_error("Not supported format");
- TTRACE_END();
- return MM_UTIL_ERROR_NOT_SUPPORTED_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);
+ 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);
+ size2 = stride2 * h2;
+ *imgsize = size + 2 * size2;
+ break;
+ case MM_UTIL_IMG_FMT_YUV422:
+ case MM_UTIL_IMG_FMT_YUYV:
+ 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;
+ size = stride * height;
+ *imgsize = size;
+ break;
+
+ case MM_UTIL_IMG_FMT_RGB565:
+ 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;
+ size = stride * height;
+ *imgsize = size;
+ break;
+
+ case MM_UTIL_IMG_FMT_ARGB8888:
+ case MM_UTIL_IMG_FMT_BGRA8888:
+ case MM_UTIL_IMG_FMT_RGBA8888:
+ case MM_UTIL_IMG_FMT_BGRX8888:
+ stride = width * 4;
+ size = stride * height;
+ *imgsize = size;
+ break;
+
+
+ case MM_UTIL_IMG_FMT_NV12:
+ 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);
+ 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);
+ size2 = stride2 * h2;
+ *imgsize = size + size2;
+ break;
+
+ default:
+ mm_util_error("Not supported format");
+ TTRACE_END();
+ return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
}
mm_util_debug("format: %d, *imgsize: %d\n", format, *imgsize);
return mimetype;
}
-int _packet_finalize_callback(media_packet_h packet, int err, void* user_data)
+int _packet_finalize_callback(media_packet_h packet, int err, void *user_data)
{
mm_util_debug("==> finalize callback func is called [%d] \n", err);
return MEDIA_PACKET_FINALIZE;
void *src;
unsigned char *dst = NULL;
- if (argc < 9) {
+ if (argc < 12) {
fprintf(stderr, "Usage: mm_util_imgp_testsuite sync {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format roation crop_start_x crop_start_y \n");
fprintf(stderr, "Usage: mm_util_imgp_testsuite async {filename} {command} src_width src_height src_foramt dst_width dst_height dst_format roation crop_start_x crop_start_y \n");
- fprintf(stderr, "ex: mm_util_imgp_testsuite s test.rgb resize 1920 1080 7 1280 720 7 0 0 0 \n");
+ fprintf(stderr, "ex: mm_util_imgp_testsuite sync test.rgb resize 1920 1080 7 1280 720 7 0 0 0 \n");
return ret;
}
uint64_t src_size = 0;
uint64_t dst_size = 0;
- bool sync_mode = (strcmp(argv[1], "sync") == 0)?TRUE:FALSE;
+ bool sync_mode = (strcmp(argv[1], "sync") == 0) ? TRUE : FALSE;
char *command = NULL;
unsigned int src_width = atoi(argv[4]);
unsigned int src_height = atoi(argv[5]);
mm_util_debug("command: %s src_width: %d, src_height: %d, src_format: %d, dst_width: %d, dst_height: %d, dst_format:%d, rotation:%d", command, src_width, src_height, src_format, dst_width, dst_height, dst_format, rotation);
- // mem allocation for src dst buffer
+ /* mem allocation for src dst buffer */
mm_util_get_image_size(src_format, src_width, src_height, &size);
src_size = (uint64_t)size;
mm_util_get_image_size(dst_format, dst_width, dst_height, &size);
src = malloc(src_size);
dst = malloc(dst_size);
- { // read input file
+ { /* read input file */
FILE *fp = fopen(argv[2], "r");
if (fp == NULL) {
mm_util_debug("\tfile open failed %d\n", errno);
goto TEST_FAIL;
}
- if(fread(src, 1, (int)src_size, fp)) {
+ if (fread(src, 1, (int)src_size, fp))
mm_util_debug("#Success# fread");
- } else {
+ else
mm_util_error("#Error# fread");
- }
if (src == NULL || src_size <= 0) {
mm_util_error("#Error# fread");
}
- { // ready output file
- char *output_fmt = (char*)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
+ { /* ready output file */
+ char *output_fmt = (char *) g_malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
memset(output_fmt, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
- if(dst_format == MM_UTIL_IMG_FMT_YUV420 ||
+ if (dst_format == MM_UTIL_IMG_FMT_YUV420 ||
dst_format == MM_UTIL_IMG_FMT_YUV422 ||
dst_format == MM_UTIL_IMG_FMT_I420) {
strncpy(output_fmt, "yuv", strlen("yuv"));
} else {
- strncpy(output_fmt,"rgb", strlen("rgb"));
+ strncpy(output_fmt, "rgb", strlen("rgb"));
}
snprintf(output_file, 40, "result_%s_%dx%d.%s", command, dst_width, dst_height, output_fmt);
}
if (sync_mode) {
mm_util_debug("SYNC");
- if (strcmp(command, "convert") == 0) {
+ if (strcmp(command, "convert") == 0)
ret = mm_util_convert_colorspace(src, src_width, src_height, src_format, dst, dst_format);
- } else if (strcmp(command, "resize") == 0) {
+ else if (strcmp(command, "resize") == 0)
ret = mm_util_resize_image(src, src_width, src_height, src_format, dst, &dst_width, &dst_height);
- } else if (strcmp(command, "rotate") == 0) {
+ else if (strcmp(command, "rotate") == 0)
ret = mm_util_rotate_image(src, src_width, src_height, src_format, dst, &dst_width, &dst_height, rotation);
- } else if (strcmp(command, "crop") == 0) {
+ else if (strcmp(command, "crop") == 0)
ret = mm_util_crop_image(src, src_width, src_height, src_format, start_x, start_y, &dst_width, &dst_height, dst);
- }
- if(ret == MM_UTIL_ERROR_NONE) {
+ if (ret == MM_UTIL_ERROR_NONE) {
mm_util_debug("Success - %s", command);
} else {
mm_util_debug("ERROR - %s", command);
goto TEST_FAIL;
}
- { // write output file
+ { /* write output file */
FILE *fpout = fopen(output_file, "w");
- if(fpout) {
+ if (fpout) {
mm_util_debug("dst: %p [%d]", dst, dst_size);
fwrite(dst, 1, dst_size, fpout);
mm_util_debug("FREE");
#include <ttrace.h>
#define TTRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_IMAGE, NAME)
#define TTRACE_END() traceEnd(TTRACE_TAG_IMAGE)
-#else //ENABLE_TTRACE
+#else /* ENABLE_TTRACE */
#define TTRACE_BEGIN(NAME)
#define TTRACE_END()
-#endif //ENABLE_TTRACE
+#endif /* ENABLE_TTRACE */
#ifndef YUV420_SIZE
#define YUV420_SIZE(width, height) (width*height*3>>1)
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) {
mm_util_error("jpegBuf is NULL");
return;
}
- if ((_hdrsubsamp == TJSAMP_444 || _hdrsubsamp == TJSAMP_GRAY) || input_fmt == MM_UTIL_JPEG_FMT_RGB888) {
+ if ((_hdrsubsamp == TJSAMP_444 || _hdrsubsamp == TJSAMP_GRAY) || input_fmt == MM_UTIL_JPEG_FMT_RGB888)
_sf = sf[i];
- } else {
+ else
_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);
- 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_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("_hdrsubsamp == TJSAMP_422", decoded_data->width, _hdrw);
decoded_data->width = MM_JPEG_ROUND_UP_2(_hdrw);
} else {
- if (_hdrw % 4 != 0) {
+ if (_hdrw % 4 != 0)
decoded_data->width = MM_JPEG_ROUND_UP_4(_hdrw);
- } else {
+ else
decoded_data->width = _hdrw;
- }
}
if (_hdrsubsamp == TJSAMP_420) {
mm_util_debug("_hdrsubsamp == TJSAMP_420", decoded_data->width, _hdrw);
- if (_hdrh % 4 != 0) {
+ if (_hdrh % 4 != 0)
decoded_data->height = MM_JPEG_ROUND_UP_4(_hdrh);
- } else {
- decoded_data->height = _hdrh;
- }
+ else
+ decoded_data->height = _hdrh;
} else {
decoded_data->height = _hdrh;
}
}
}
-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;
mm_util_error("dhandle=tjInitDecompress()) is NULL");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- srcBuf = (unsigned char *)malloc(sizeof(char) * jpegSize);
+ srcBuf = (unsigned char *) malloc(sizeof(char) * jpegSize);
if (srcBuf == NULL) {
fclose(src);
tjDestroy(dhandle);
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;
mm_util_error("dhandle=tjInitDecompress()) is NULL");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- srcBuf = (unsigned char *)malloc(sizeof(char) * size);
+ srcBuf = (unsigned char *) malloc(sizeof(char) * size);
if (srcBuf == NULL) {
fclose(src);
tjDestroy(dhandle);
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;
}
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;
}
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
jmp_buf setjmp_buffer; /* for return to caller */
} my_error_mgr_s;
-typedef struct my_error_mgr_s * my_error_ptr;
+typedef struct my_error_mgr_s *my_error_ptr;
struct {
struct jpeg_destination_mgr pub; /* public fields */
- FILE * outfile; /* target stream */
- JOCTET * buffer; /* start of buffer */
+ FILE *outfile; /* target stream */
+ 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 */
struct {
struct jpeg_destination_mgr pub; /* public fields */
- unsigned char ** outbuffer; /* target buffer */
- unsigned long * outsize;
- unsigned char * newbuffer; /* newly allocated buffer */
- JOCTET * buffer; /* start of buffer */
+ unsigned char **outbuffer; /* target buffer */
+ unsigned long *outsize;
+ unsigned char *newbuffer; /* newly allocated buffer */
+ JOCTET *buffer; /* start of buffer */
size_t bufsize;
} my_mem_destination_mgr;
-typedef struct my_mem_destination_mgr * my_mem_dest_ptr;
+typedef struct my_mem_destination_mgr *my_mem_dest_ptr;
static void my_error_exit(j_common_ptr cinfo)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
int i, j, flag, _height;
- FILE * fpWriter;
+ FILE *fpWriter;
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 */
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;
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1;
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;
- }
JSAMPLE *image_buffer = (JSAMPLE *)rawdata;
while (cinfo.next_scanline < cinfo.image_height) {
- //row_pointer[0] = (JSAMPROW)&rawdata[cinfo.next_scanline * iRowStride];
- row_pointer[0] = & image_buffer[cinfo.next_scanline * iRowStride];
+ row_pointer[0] = &image_buffer[cinfo.next_scanline * iRowStride];
jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
mm_util_debug("while");
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;
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1;
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;
- }
JSAMPLE *image_buffer = (JSAMPLE *)rawdata;
while (cinfo.next_scanline < cinfo.image_height) {
- //row_pointer[0] = (JSAMPROW)&rawdata[cinfo.next_scanline * iRowStride];
- row_pointer[0] = & image_buffer[cinfo.next_scanline * iRowStride];
+ row_pointer[0] = &image_buffer[cinfo.next_scanline * iRowStride];
jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
mm_util_debug("while");
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_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) {
/* 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);
- }
}
/* JSAMPLEs per row in output buffer */
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) {
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_error("decoded_data");
return MM_UTIL_ERROR_INVALID_PARAMETER;
}
- if (decoded_data) {
+ if (decoded_data)
decoded_data->data = NULL;
- }
/* allocate and initialize JPEG decompression object We set up the normal JPEG error routines, then override error_exit. */
dinfo.err = jpeg_std_error(&jerr.pub);
/* 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);
- }
}
/* JSAMPLEs per row in output buffer */
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) {
return iErrorCode;
}
-#if 0
-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;
-
- if (exif == NULL || format <= 0 || components <= 0 || data == NULL) {
- mm_util_error("invalid argument exif = %p format = %d, components = %lu data = %p!",
- exif, format, components, data);
- return -1;
- }
-
- /*remove same tag in EXIF*/
- exif_content_remove_entry(ed->ifd[ifd], exif_content_get_entry(ed->ifd[ifd], tag));
-
- /*create new tag*/
- e = exif_entry_new();
- if (e == NULL) {
- mm_util_error("entry create error!");
- return -1;
- }
-
- exif_entry_initialize(e, tag);
-
- e->tag = tag;
- e->format = format;
- e->components = components;
-
- if (e->size == 0) {
- e->data = NULL;
- e->data = malloc(exif_format_get_size(format) * e->components);
- if (!e->data) {
- exif_entry_unref(e);
- return -1;
- }
-
- if (format == EXIF_FORMAT_ASCII) {
- memset(e->data, '\0', exif_format_get_size(format) * e->components);
- }
- }
-
- e->size = exif_format_get_size(format) * e->components;
- memcpy(e->data, data, e->size);
- exif_content_add_entry(ed->ifd[ifd], e);
- exif_entry_unref(e);
-
- return 0;
-}
-#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)
{
int ret = MM_UTIL_ERROR_NONE;
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;
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;
Name: libmm-utility
Summary: Multimedia Framework Utility Library
-Version: 0.20
+Version: 0.21
Release: 0
Group: System/Libraries
License: Apache-2.0
mm_util_error("%s", warning_msg);
}
-static void dec_set_prop(mm_util_png_data * decoded, png_structp png_ptr, png_infop info)
+static void dec_set_prop(mm_util_png_data *decoded, png_structp png_ptr, png_infop info)
{
png_color_16 my_background, *image_background;
}
}
-int read_png(mm_util_png_data * decoded, FILE * fp, void *memory)
+int read_png(mm_util_png_data *decoded, FILE * fp, void *memory)
{
png_structp png_ptr;
png_infop info_ptr;
{
png_bytep row_pointers[decoded->height];
- for (row_index = 0; row_index < decoded->height; row_index++) {
+ for (row_index = 0; row_index < decoded->height; row_index++)
row_pointers[row_index] = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));
- }
png_read_image(png_ptr, row_pointers);
mm_util_debug("and we are done reading this image");
}
-int read_png_progressive(mm_util_png_data * decoded, FILE * fp, void **memory, unsigned long long src_size)
+int read_png_progressive(mm_util_png_data *decoded, FILE * fp, void **memory, unsigned long long src_size)
{
png_structp png_ptr;
png_infop info_ptr;
return MM_UTIL_ERROR_NONE;
}
-int mm_util_decode_from_png_file(mm_util_png_data * decoded, const char *fpath)
+int mm_util_decode_from_png_file(mm_util_png_data *decoded, const char *fpath)
{
int ret = MM_UTIL_ERROR_NONE;
FILE *fp;
return ret;
}
-int mm_util_decode_from_png_memory(mm_util_png_data * decoded, void **memory, unsigned long long src_size)
+int mm_util_decode_from_png_memory(mm_util_png_data *decoded, void **memory, unsigned long long src_size)
{
int ret = MM_UTIL_ERROR_NONE;
return ret;
}
-void mm_util_init_decode_png(mm_util_png_data * data)
+void mm_util_init_decode_png(mm_util_png_data *data)
{
mm_util_debug("mm_util_init_decode_png");
data->png.progressive = 0;
data->png.transform = MM_UTIL_PNG_TRANSFORM_IDENTITY;
}
-void mm_util_png_decode_set_progressive(mm_util_png_data * data, int progressive)
+void mm_util_png_decode_set_progressive(mm_util_png_data *data, int progressive)
{
data->png.progressive = progressive;
}
-void mm_util_png_decode_set_progressive_bytes(mm_util_png_data * data, int progressive_bytes)
+void mm_util_png_decode_set_progressive_bytes(mm_util_png_data *data, int progressive_bytes)
{
data->png.progressive_bytes = progressive_bytes;
}
-void mm_util_png_decode_set_transform(mm_util_png_data * data, int transform)
+void mm_util_png_decode_set_transform(mm_util_png_data *data, int transform)
{
data->png.transform = transform;
}
-png_uint_32 mm_util_png_decode_get_width(mm_util_png_data * data)
+png_uint_32 mm_util_png_decode_get_width(mm_util_png_data *data)
{
return data->width;
}
-png_uint_32 mm_util_png_decode_get_height(mm_util_png_data * data)
+png_uint_32 mm_util_png_decode_get_height(mm_util_png_data *data)
{
return data->height;
}
-int mm_util_png_decode_get_bit_depth(mm_util_png_data * data)
+int mm_util_png_decode_get_bit_depth(mm_util_png_data *data)
{
return data->png.bit_depth;
}
-png_uint_32 mm_util_png_decode_get_size(mm_util_png_data * data)
+png_uint_32 mm_util_png_decode_get_size(mm_util_png_data *data)
{
return data->size;
}
}
}
-int write_png(void **data, mm_util_png_data * encoded, FILE * fp)
+int write_png(void **data, mm_util_png_data *encoded, FILE *fp)
{
png_structp png_ptr;
png_infop info_ptr;
return MM_UTIL_ERROR_NONE;
}
-int mm_util_encode_to_png_file(void **data, mm_util_png_data * encoded, const char *fpath)
+int mm_util_encode_to_png_file(void **data, mm_util_png_data *encoded, const char *fpath)
{
int ret = MM_UTIL_ERROR_NONE;
FILE *fp;
return ret;
}
-int mm_util_encode_to_png_memory(void **data, mm_util_png_data * encoded)
+int mm_util_encode_to_png_memory(void **data, mm_util_png_data *encoded)
{
int ret;
return ret;
}
-void mm_util_init_encode_png(mm_util_png_data * data)
+void mm_util_init_encode_png(mm_util_png_data *data)
{
mm_util_debug("mm_util_init_encode_png");
data->png.compression_level = MM_UTIL_COMPRESSION_6;
data->png.bit_depth = MM_UTIL_BIT_DEPTH_8;
}
-void mm_util_png_encode_set_compression_level(mm_util_png_data * data, mm_util_png_compression compression_level)
+void mm_util_png_encode_set_compression_level(mm_util_png_data *data, mm_util_png_compression compression_level)
{
data->png.compression_level = compression_level;
}
-void mm_util_png_encode_set_filter(mm_util_png_data * data, mm_util_png_filter filter)
+void mm_util_png_encode_set_filter(mm_util_png_data *data, mm_util_png_filter filter)
{
data->png.filter = filter;
}
-void mm_util_png_encode_set_color_type(mm_util_png_data * data, mm_util_png_color_type color_type)
+void mm_util_png_encode_set_color_type(mm_util_png_data *data, mm_util_png_color_type color_type)
{
data->png.color_type = color_type;
}
-void mm_util_png_encode_set_filter_type(mm_util_png_data * data, mm_util_png_filter_type filter_type)
+void mm_util_png_encode_set_filter_type(mm_util_png_data *data, mm_util_png_filter_type filter_type)
{
data->png.filter_type = filter_type;
}
-void mm_util_png_encode_set_interlace_type(mm_util_png_data * data, mm_util_png_interlace_type interlace_type)
+void mm_util_png_encode_set_interlace_type(mm_util_png_data *data, mm_util_png_interlace_type interlace_type)
{
data->png.interlace_type = interlace_type;
}
-void mm_util_png_encode_set_width(mm_util_png_data * data, png_uint_32 width)
+void mm_util_png_encode_set_width(mm_util_png_data *data, png_uint_32 width)
{
data->width = width;
}
-void mm_util_png_encode_set_height(mm_util_png_data * data, png_uint_32 height)
+void mm_util_png_encode_set_height(mm_util_png_data *data, png_uint_32 height)
{
data->height = height;
}
-void mm_util_png_encode_set_bit_depth(mm_util_png_data * data, mm_util_png_bit_depth bit_depth)
+void mm_util_png_encode_set_bit_depth(mm_util_png_data *data, mm_util_png_bit_depth bit_depth)
{
data->png.bit_depth = bit_depth;
}
+++ /dev/null
-bin_PROGRAMS = mm_utility_testsuite
-
-mm_utility_testsuite_SOURCES = mm_utility_testsuite.c
-
-mm_utility_testsuite_CFLAGS = -I$(srcdir)/../include \
- -fPIE -pie
+++ /dev/null
-/*
- * libmm-utility
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: YoungHun Kim <yh8004.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdio.h>
-#include <glib/gstdio.h>
-
-#include <scmn_base.h>
-/**
- * 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 */
-} 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 */
-} 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 */
-} mm_utility_decoded_data;
-
-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");
- 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");
- 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");
- 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");
- file_format = MM_UTILITY_IMAGE_FILE_FMT_JPG;
- } else {
- printf("Not supported image file format. \n");
- }
-
- return file_format;
-
-}
-
-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");
- 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];
- img->e[0] = img->e[1] = img->e[2] = img->h[0];
-
- malloc_size = img->s[0]*img->e[0]*sizeof(unsigned char) * 3;
-
- break;
-
- 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];
- img->s[0] = img->w[0];
- img->s[1] = img->s[2] = (img->w[0]+1) >> 1;
- img->e[0] = img->e[1] = img->e[2] = img->h[0];
-
- malloc_size = img->s[0]*img->e[0]*sizeof(unsigned char) * 3 >> 1;
-
- break;
-
- 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;
- img->s[0] = img->s[1] = img->s[2] = img->w[0];
- img->e[0] = img->h[0];
- img->e[1] = img->e[2] = (img->h[0]+1) >> 1;
-
- malloc_size = img->s[0]*img->e[0]*sizeof(unsigned char) * 3 >> 1;
-
- break;
-
- case SCMN_CS_YUV420:
- printf("colorspace is YUV420.\n");
-
- /* plus 1 for rounding */
- img->w[1] = img->w[2] = (img->w[0]+1) >> 1;
- img->h[1] = img->h[2] = (img->h[0]+1) >> 1;
- img->s[0] = img->w[0];
- img->s[1] = img->s[2] = (img->w[0]+1) >> 1;
- img->e[0] = img->h[0];
- img->e[1] = img->e[2] = (img->h[0]+1) >> 1;
-
- malloc_size = img->s[0]*img->e[0]*sizeof(unsigned char) * 3 >> 1;
-
- break;
-
- case SCMN_CS_YUV400:
- printf("colorspace is YUV400.\n");
-
- img->s[0] = img->w[0];
- img->e[0] = img->h[0];
-
- malloc_size = img->s[0]*img->e[0]*sizeof(unsigned char);
-
- break;
-
- case SCMN_CS_RGB565:
- printf("colorspace is RGB565.\n");
-
- img->s[0] = img->w[0];
- img->e[0] = img->h[0];
-
- malloc_size = img->s[0]*img->e[0]*sizeof(unsigned char) * 3 >> 1;
-
- break;
-
- 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]);
- malloc_size = img->s[0]*img->e[0]*sizeof(unsigned char) * 3 ;
-
- break;
-
- case SCMN_CS_RGBA8888:
- printf("colorspace is RGBA8888.\n");
-
- img->s[0] = img->w[0];
- img->e[0] = img->h[0];
-
- malloc_size = img->s[0]*img->e[0]*sizeof(unsigned char) * 4 ;
-
- break;
-
- 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) {
- 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)) {
- img->a[0] = malloc(img->s[0]*img->e[0]*sizeof(unsigned char) * 3);
- } 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");
- ret = -1;
- }
-
- if (!img->a[0])
- ret = -1;
-
- return ret;
-}
-
-
-static void write_decoded_image(const char *filename, SCMN_IMGB imgb)
-{
- 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);
-
- fclose(fp);
-
- return;
-}
-
-
-static int decode_bmp(const char * input_file, int width, int height, const char * output_file)
-{
- SCMN_IMGB imgb;
- SBMPD_INIT_DSC init_dsc;
- 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;
-
- 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));
-
- /* 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");
-
- /* 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");
- ret = -1;
- goto exit;
- }
-
- filebuffer = malloc(statbuf.st_size);
- if (!filebuffer) {
- printf("fail to allocate file buffer\n");
- ret = -1;
- goto exit;
- }
-
- toread = statbuf.st_size;
- totalread = 0;
- bufp = filebuffer;
-
- 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;
- }
-
- 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;
-
- /* 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;
- }
-
- printf("Create bmp decoder is success.\n");
-
- /* malloc for decoded picture */
- if ((width > 0) && (height > 0)) {
- /* Resize the image */
- imgb.w[0] = width;
- 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]);
-
-
- ret = malloc_decoded_picture(&imgb);
- if (ret == -1) {
- printf("Fail to malloc decoded data\n");
- goto exit;
- }
-
- 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;
- }
-
-
- /* 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);
- bufp = NULL;
- }
-
- if (input_fp)
- fclose(input_fp);
-
- if (bmpd_hnd)
- sbmpd_delete(bmpd_hnd);
-
-
- sbmp_deinit();
-
- printf("ret=%d\n", ret);
-
- return ret;
-}
-
-static int decode_png(const char * input_file, int width, int height, const char * output_file)
-{
- SCMN_IMGB imgb;
- SPNGD_INIT_DSC init_dsc;
- 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;
-
- 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));
-
- /* 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");
-
- /* 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;
- }
-
- filebuffer = malloc(statbuf.st_size);
- if (!filebuffer) {
- printf("fail to allocate file buffer\n");
- goto exit;
- }
-
- toread = statbuf.st_size;
- totalread = 0;
- bufp = filebuffer;
-
- 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;
- }
-
- 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;
-
- /* 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");
-
- /* malloc for decoded picture */
- if ((width > 0) && (height > 0)) {
- /* Resize the image */
- imgb.w[0] = width;
- 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]);
-
-
- ret = malloc_decoded_picture(&imgb);
- if (ret == -1) {
- printf("Fail to malloc decoded data\n");
- goto exit;
- }
-
-
- 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;
- }
-
- printf("Success to decode, erro=%d\n", sret);
-
- if (!pngd_stat.pa) {
- printf("decoded buffer is not available\n");
- ret = -1;
- goto exit;
- }
-
- 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);
- }
-
-
-exit:
-
- if (bufp) {
- free(bufp);
- bufp = NULL;
- }
-
- if (input_fp)
- fclose(input_fp);
-
- if (pngd_hnd)
- spngd_delete(pngd_hnd);
-
-
- spng_deinit();
-
- printf("ret=%d\n", ret);
-
- return ret;
-}
-
-static int decode_gif(const char * input_file, int width, int height, const char * output_file)
-{
- SCMN_IMGB imgb;
- SGIFD_INIT_DSC init_dsc;
- 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;
-
- 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));
-
- /* 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");
-
- /* 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;
- }
-
- filebuffer = malloc(statbuf.st_size);
- if (!filebuffer) {
- printf("fail to allocate file buffer\n");
- goto exit;
- }
-
- toread = statbuf.st_size;
- totalread = 0;
- bufp = filebuffer;
-
- 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;
- }
-
- 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;
-
- /* 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");
-
- /* malloc for decoded picture */
- if ((width > 0) && (height > 0)) {
- /* Resize the image */
- imgb.w[0] = width;
- 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]);
-
-
- ret = malloc_decoded_picture(&imgb);
- if (ret == -1) {
- printf("Fail to malloc decoded data\n");
- goto exit;
- }
-
- 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;
- }
-
- printf("Success to decode, erro=%d\n", sret);
-
- 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);
- }
-
-
-exit:
-
- if (bufp) {
- free(bufp);
- bufp = NULL;
- }
-
- if (input_fp)
- fclose(input_fp);
-
- if (gifd_hnd)
- sgifd_delete(gifd_hnd);
-
-
- sgif_deinit();
-
- printf("ret=%d\n", ret);
-
- return ret;
-
-}
-static int decode_jpg(const char * input_file, int width, int height, const char * output_file)
-{
- SCMN_IMGB imgb;
- SJPGD_INIT_DSC init_dsc;
- 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;
-
- 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));
-
- /* 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");
-
- /* 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;
- }
-
- filebuffer = malloc(statbuf.st_size);
- if (!filebuffer) {
- printf("fail to allocate file buffer\n");
- goto exit;
- }
-
- toread = statbuf.st_size;
- totalread = 0;
- bufp = filebuffer;
-
- 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;
- }
-
- 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;
-
- /* 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");
-
- /* malloc for decoded picture */
- if ((width > 0) && (height > 0)) {
- /* Resize the image */
- imgb.w[0] = width;
- 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]);
-
-
- ret = malloc_decoded_picture(&imgb);
- if (ret == -1) {
- printf("Fail to malloc decoded data\n");
- goto exit;
- }
-
- 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);
-
- /* 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);
- bufp = NULL;
- }
-
- if (input_fp)
- fclose(input_fp);
-
- if (jpgd_hnd)
- sjpgd_delete(jpgd_hnd);
-
-
- sjpg_deinit();
-
- 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;
-
- 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");
- goto exit;
- }
-
- input_file = g_strdup((const char *) argv[1]);
-
- 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]) {
- output_width = atoi(argv[2]);
- output_height = atoi(argv[3]);
-
- 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);
- }
-
- /* Get image file format : bmp, gif, png, jpg */
- file_format = get_file_format(input_file);
-
-
- /* Decode image file */
- switch (file_format) {
- case MM_UTILITY_IMAGE_FILE_FMT_BMP:
- 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);
- break;
- case MM_UTILITY_IMAGE_FILE_FMT_PNG:
- 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);
- break;
- default:
- printf(" This image file is not supported. \n");
- ret = -1;
- break;
-
- }
-
- if (ret == -1)
- printf("Fail to decode [%s]. \n", input_file);
-
-exit:
- if (input_file) {
- g_free(input_file);
- input_file = NULL;
- }
-
- if (output_file) {
- g_free(output_file);
- output_file = NULL;
- }
-
- return ret;
-
-}
-