Add NV12 format support for cropping image 80/310280/1 accepted/tizen_unified accepted/tizen_unified_toolchain accepted/tizen_unified_x tizen accepted/tizen/unified/20240502.044626 accepted/tizen/unified/toolchain/20240507.011831 accepted/tizen/unified/x/20240503.091134
authorJiyong <jiyong.min@samsung.com>
Thu, 25 Apr 2024 01:59:19 +0000 (10:59 +0900)
committerJiyong <jiyong.min@samsung.com>
Thu, 25 Apr 2024 01:59:19 +0000 (10:59 +0900)
Change-Id: I5f111bd4bc014647f29c48ce5f85af5c18e60b12

imgp/mm_util_imgp.c
packaging/libmm-utility.spec

index 7bd0c75..7967d56 100644 (file)
@@ -277,6 +277,31 @@ unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_wid
        }
 }
 
+static void __mm_util_crop_nv12(const unsigned char *src, unsigned int src_width, unsigned int src_height,
+unsigned int crop_start_x, unsigned int crop_start_y, unsigned int crop_dest_width, unsigned int crop_dest_height, unsigned char *dst)
+{
+       unsigned int idx = 0;
+       unsigned int start_x = crop_start_x;
+       unsigned int start_y = crop_start_y;
+
+       const unsigned char *_src = src + start_y * src_width + start_x;
+
+       /* Y */
+       for (idx = 0; idx < crop_dest_height; idx++) {
+               memcpy(dst, _src, crop_dest_width);
+               _src += src_width;
+               dst += crop_dest_width;
+       }
+
+       /* UV */
+       _src = src + src_height * src_width + (start_y / 2) * src_width + start_x;
+       for (idx = 0; idx < crop_dest_height / 2; idx++) {
+               memcpy(dst, _src, crop_dest_width);
+               _src += src_width;
+               dst += crop_dest_width;
+       }
+}
+
 static IMGPInfoFunc __mm_util_initialize(void **module)
 {
        void *_module = NULL;
@@ -578,12 +603,12 @@ int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int s
 
        if (_src->color == MM_UTIL_COLOR_I420 || _src->color == MM_UTIL_COLOR_YUV420) {
                if ((_width % 2) != 0) {
-                       _width = ((_width+1)>>1)<<1;
+                       _width = ((_width + 1) >> 1) << 1;
                        mm_util_warn("width must be even. change from [%d] to [%d]", width, _width);
                }
 
                if ((_height % 2) != 0) {
-                       _height = ((_height+1)>>1)<<1;
+                       _height = ((_height + 1) >> 1) << 1;
                        mm_util_warn("height must be even. change from [%d] to [%d]", height, _height);
                }
        }
@@ -594,26 +619,25 @@ int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int s
        _buffer = g_malloc0(_buffer_size);
 
        switch (_src->color) {
-       case MM_UTIL_COLOR_RGB16: {
+       case MM_UTIL_COLOR_RGB16:
                __mm_util_crop_rgb16(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer);
                break;
-               }
-       case MM_UTIL_COLOR_RGB24: {
+       case MM_UTIL_COLOR_RGB24:
                __mm_util_crop_rgb24(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer);
                break;
-               }
        case MM_UTIL_COLOR_ARGB:
        case MM_UTIL_COLOR_BGRA:
        case MM_UTIL_COLOR_RGBA:
-       case MM_UTIL_COLOR_BGRX: {
+       case MM_UTIL_COLOR_BGRX:
                __mm_util_crop_rgb32(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer);
                break;
-               }
        case MM_UTIL_COLOR_I420:
-       case MM_UTIL_COLOR_YUV420: {
+       case MM_UTIL_COLOR_YUV420:
                __mm_util_crop_yuv420(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer);
                break;
-               }
+       case MM_UTIL_COLOR_NV12:
+               __mm_util_crop_nv12(_src->data, _src->width, _src->height, start_x, start_y, _width, _height, _buffer);
+               break;
        default:
                mm_util_error("Not supported format [%d]", _src->color);
                g_free(_buffer);
index b81c860..98f1af8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.4.22
+Version:    0.4.23
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0