bug fix. add the set of yuv colorspace for jpeg 03/260803/2 accepted/tizen/6.5/unified/20211028.115657 accepted/tizen/unified/20210707.070854 submit/tizen/20210706.071755 submit/tizen_6.5/20211028.162401 tizen_6.5.m2_release
authorJiyong Min <jiyong.min@samsung.com>
Fri, 2 Jul 2021 04:11:36 +0000 (13:11 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Mon, 5 Jul 2021 02:16:42 +0000 (11:16 +0900)
  [Problem]
    Decoding jpeg with yuv colorspace return broken image.
  [Cause]
    The j_color_space for yuv was not set.
  [Solution]
    We add the set of yuv colorspace for jpeg.

Change-Id: Ie5567948802c999ebdfddd998c02cee5edf3f03c

jpeg/mm_util_jpeg.c
packaging/libmm-utility.spec

index 284e17a..35a4873 100644 (file)
@@ -108,34 +108,54 @@ static int __jpeg_set_error_handler(my_error_ptr jerr, jpeg_error_ptr *err)
        return MM_UTIL_ERROR_NONE;
 }
 
-static void __jpeg_convert_rgb_colorspace(mm_util_color_format_e mm_color_format, J_COLOR_SPACE *j_color_space, int *j_color_comp)
+static int __jpeg_convert_colorspace(mm_util_color_format_e mm_color_format, J_COLOR_SPACE *j_color_space, int *j_color_comp)
 {
        int pixel_depth = 0;
 
-       if (mm_color_format == MM_UTIL_COLOR_RGB24) {
+       mm_util_retvm_if(!j_color_space, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid j_color_space");
+
+       switch(mm_color_format) {
+       case MM_UTIL_COLOR_RGB24:
                pixel_depth = 3;
                *j_color_space = JCS_RGB;
                mm_util_debug("JCS_RGB");
-       } else if (mm_color_format == MM_UTIL_COLOR_GRAYSCALE) {
+               break;
+       case MM_UTIL_COLOR_GRAYSCALE:
                pixel_depth = 1; /* one colour component */
                *j_color_space = JCS_GRAYSCALE;
                mm_util_debug("JCS_GRAYSCALE");
-       } else if (mm_color_format == MM_UTIL_COLOR_RGBA) {
+               break;
+       case MM_UTIL_COLOR_RGBA:
                pixel_depth = 4;
                *j_color_space = JCS_EXT_RGBA;
                mm_util_debug("JCS_EXT_RGBA");
-       } else if (mm_color_format == MM_UTIL_COLOR_BGRA) {
+               break;
+       case MM_UTIL_COLOR_BGRA:
                pixel_depth = 4;
                *j_color_space = JCS_EXT_BGRA;
                mm_util_debug("JCS_EXT_BGRA");
-       } else if (mm_color_format == MM_UTIL_COLOR_ARGB) {
+               break;
+       case MM_UTIL_COLOR_ARGB:
                pixel_depth = 4;
                *j_color_space = JCS_EXT_ARGB;
                mm_util_debug("JCS_EXT_ARGB");
+               break;
+       case MM_UTIL_COLOR_YUV420:
+       case MM_UTIL_COLOR_YUV422:
+       case MM_UTIL_COLOR_UYVY:
+               pixel_depth = 3;
+               *j_color_space = JCS_YCbCr;
+               mm_util_debug("JCS_YCbCr");
+               break;
+       default:
+               mm_util_error("not supported format [%d]", mm_color_format);
+               return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
        }
 
        if (j_color_comp)
                *j_color_comp = pixel_depth;
+
+       return MM_UTIL_ERROR_NONE;
 }
 
 static void __jpeg_encode_open(j_compress_ptr cinfo, mm_util_jpeg_ctrl_format_e control_format, FILE *fp, void **mem, unsigned long *size)
@@ -289,9 +309,15 @@ static int __mm_util_jpeg_encode(mm_util_jpeg_ctrl_format_e control_format, mm_u
 
        _width = cinfo.image_width = _decoded->width;
        _height = cinfo.image_height = _decoded->height;
+       ret = __jpeg_convert_colorspace(_decoded->color, &(cinfo.in_color_space), &(cinfo.input_components));
+       if (ret != MM_UTIL_ERROR_NONE) {
+               mm_util_error("__jpeg_convert_colorspace failed %d", ret);
+               jpeg_destroy_compress(&cinfo);
+               mm_util_debug("jpeg_destroy_compress");
+               return ret;
+       }
+
        if (_decoded->color == MM_UTIL_COLOR_YUV420 || _decoded->color == MM_UTIL_COLOR_YUV422 || _decoded->color == MM_UTIL_COLOR_UYVY) {
-               cinfo.input_components = 3;
-               cinfo.in_color_space = JCS_YCbCr;
                jpeg_set_defaults(&cinfo);
                mm_util_debug("jpeg_set_defaults");
 
@@ -318,14 +344,11 @@ static int __mm_util_jpeg_encode(mm_util_jpeg_ctrl_format_e control_format, mm_u
                ret = __jpeg_encode_yuv(&cinfo, _width, _height, decoded);
                if (ret != MM_UTIL_ERROR_NONE)
                        mm_util_error("__jpeg_encode_yuv failed");
-       }
-
-       else if (_decoded->color == MM_UTIL_COLOR_RGB24 || _decoded->color == MM_UTIL_COLOR_GRAYSCALE || _decoded->color == MM_UTIL_COLOR_RGBA || _decoded->color == MM_UTIL_COLOR_BGRA || _decoded->color == MM_UTIL_COLOR_ARGB) {
+       } else if (_decoded->color == MM_UTIL_COLOR_RGB24 || _decoded->color == MM_UTIL_COLOR_GRAYSCALE || _decoded->color == MM_UTIL_COLOR_RGBA || _decoded->color == MM_UTIL_COLOR_BGRA || _decoded->color == MM_UTIL_COLOR_ARGB) {
                unsigned int row_stride = 0;
                JSAMPROW row_pointer[1];
                JSAMPLE *image_buffer = (JSAMPLE *)_decoded->data;
 
-               __jpeg_convert_rgb_colorspace(_decoded->color, &(cinfo.in_color_space), &(cinfo.input_components));
                row_stride = _width * cinfo.input_components;
 
                jpeg_set_defaults(&cinfo);
@@ -339,11 +362,6 @@ static int __mm_util_jpeg_encode(mm_util_jpeg_ctrl_format_e control_format, mm_u
                        row_pointer[0] = &image_buffer[cinfo.next_scanline * row_stride];
                        jpeg_write_scanlines(&cinfo, row_pointer, 1);
                }
-       } else {
-               mm_util_error("We can't encode the IMAGE format");
-               jpeg_destroy_compress(&cinfo);
-               mm_util_debug("jpeg_destroy_compress");
-               return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
        }
 
        jpeg_finish_compress(&cinfo);
@@ -395,7 +413,11 @@ static int __mm_util_jpeg_decode(mm_util_jpeg_ctrl_format_e control_format, FILE
 
        /* set parameters for decompression */
        __jpeg_decode_set_common_params(&dinfo, color_format, downscale);
-       __jpeg_convert_rgb_colorspace(color_format, &dinfo.out_color_space, NULL);
+       ret = __jpeg_convert_colorspace(color_format, &dinfo.out_color_space, NULL);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               mm_util_error("__jpeg_convert_colorspace failed %d", ret);
+               goto END;
+       }
 
        /* Start decompressor */
        jpeg_start_decompress(&dinfo);
index 85e6c93..1094f73 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.3.0
+Version:    0.3.1
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0