From 94fe7dabe63144d7592e72ec49138d768e2598fb Mon Sep 17 00:00:00 2001 From: Jiyong Date: Thu, 25 Apr 2024 10:59:19 +0900 Subject: [PATCH] Add NV12 format support for cropping image Change-Id: I5f111bd4bc014647f29c48ce5f85af5c18e60b12 --- imgp/mm_util_imgp.c | 44 ++++++++++++++++++++++++++++-------- packaging/libmm-utility.spec | 2 +- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c index b8ab524..9774f23 100644 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -283,6 +283,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(GModule **module) { GModule *_module = NULL; @@ -585,12 +610,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); } } @@ -601,26 +626,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); diff --git a/packaging/libmm-utility.spec b/packaging/libmm-utility.spec index 8978779..ae00c9c 100644 --- a/packaging/libmm-utility.spec +++ b/packaging/libmm-utility.spec @@ -1,6 +1,6 @@ Name: libmm-utility Summary: Multimedia Framework Utility Library -Version: 0.4.12 +Version: 0.4.13 Release: 0 Group: System/Libraries License: Apache-2.0 -- 2.34.1