Modify to get the size of the cropped image and modify to check wrong parameter 77/158477/2
authorJiyong Min <jiyong.min@samsung.com>
Wed, 1 Nov 2017 07:26:32 +0000 (16:26 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Wed, 1 Nov 2017 23:13:25 +0000 (08:13 +0900)
Cause: Cropping dosen't use gstreamer but getting the size is based
  on gstreamer. So the size of the cropped image is not matched with
  getting the size by mm_util_get_image_size().

Solution: The function to get the size of cropped image has been added.
  Generally, getting image size should be seperated for libraries.

Change-Id: If8086bf1a03b6fd0a8eb56d94bb05a355d902cb8
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
imgp/mm_util_imgp.c
packaging/libmm-utility.spec

index 0ad1b29841c68672e620545c511723dba9762450..30d8bbb1559c38def87297f101e9152cd9844bcb 100755 (executable)
@@ -244,6 +244,101 @@ static gboolean __mm_is_rgb_format(mm_util_img_format format)
        return FALSE;
 }
 
+static int __mm_util_get_crop_image_size(mm_util_img_format format, unsigned int width, unsigned int height, unsigned int *imgsize)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       unsigned char x_chroma_shift = 0;
+       unsigned char y_chroma_shift = 0;
+       int size, w2, h2, size2;
+       int stride, stride2;
+
+       TTRACE_BEGIN("MM_UTILITY:IMGP:GET_SIZE");
+
+       if (!imgsize) {
+               mm_util_error("imgsize can't be null");
+               TTRACE_END();
+               return MM_UTIL_ERROR_NO_SUCH_FILE;
+       }
+
+       *imgsize = 0;
+
+       if (check_valid_picture_size(width, height) < 0) {
+               mm_util_error("invalid width and height");
+               TTRACE_END();
+               return MM_UTIL_ERROR_INVALID_PARAMETER;
+       }
+
+       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 = width * 2;
+               size = stride * height;
+               *imgsize = size;
+               break;
+
+       case MM_UTIL_IMG_FMT_RGB888:
+               stride = 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", format, *imgsize);
+
+       TTRACE_END();
+       return ret;
+}
+
 int __mm_util_get_buffer_size(mm_util_img_format format, unsigned int width, unsigned int height, unsigned int *imgsize)
 {
        int ret = MM_UTIL_ERROR_NONE;
@@ -964,7 +1059,7 @@ static int __mm_util_processing(mm_util_s *handle)
        memcpy(dst_buf[src_index], handle->src, handle->src_buf_size);
        if (handle->set_crop) {
                dst_index++;
-               mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
+               __mm_util_get_crop_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
                dst_buf[dst_index] = g_malloc(dst_buf_size);
                if (dst_buf[dst_index] == NULL) {
                        mm_util_error("[multi func] memory allocation error");
@@ -1178,7 +1273,7 @@ static int __mm_create_media_packet_with_buffer(media_format_h fmt, void *buffer
        uint64_t size = 0;
        void *ptr = NULL;
 
-       if ((fmt == NULL) || (pkt == NULL) || (ptr == NULL) || (size == 0)) {
+       if ((fmt == NULL) || (pkt == NULL) || (buffer == NULL) || (buffer_size == 0)) {
                mm_util_error("Invalid parameter");
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
@@ -1196,8 +1291,8 @@ static int __mm_create_media_packet_with_buffer(media_format_h fmt, void *buffer
                return MM_UTIL_ERROR_INVALID_OPERATION;
        }
 
-       if (size < buffer_size) {
-               mm_util_error("The buffer(%lu) of media_packet is smaller than result(%d)", size, buffer_size);
+       if (size < (uint64_t)buffer_size) {
+               mm_util_error("The buffer(%lu) of media_packet is smaller than result(%u)", size, buffer_size);
                media_packet_destroy(*pkt);
                return MM_UTIL_ERROR_INVALID_OPERATION;
        }
@@ -1235,12 +1330,14 @@ static int __mm_util_transform_exec(mm_util_s *handle, media_packet_h src_packet
        mm_util_debug("src: %p (%u X %u)", src_packet, handle->src_width, handle->src_height);
 
        ret = __mm_util_processing(handle);
-
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_util_processing failed");
                handle->dst_packet = NULL;
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
+       mm_util_debug("handle->src_packet: %p [%d] %d X %d (%d) => handle->dst_packet: %p [%d] %d X %d (%d)",
+               handle->src_packet, handle->src_format, handle->src_width, handle->src_height, handle->src_buf_size,
+               handle->dst_packet, handle->dst_format, handle->dst_width, handle->dst_height, handle->dst_buf_size);
 
        ret = __mm_create_media_format(src_fmt, handle->dst_format_mime, handle->dst_width, handle->dst_height, &dst_fmt);
        if (ret != MM_UTIL_ERROR_NONE) {
@@ -1259,10 +1356,6 @@ static int __mm_util_transform_exec(mm_util_s *handle, media_packet_h src_packet
                return ret;
        }
 
-       mm_util_debug("handle->src_packet: %p [%d] %d X %d (%d) => handle->dst_packet: %p [%d] %d X %d (%d)",
-               handle->src_packet, handle->src_format, handle->src_width, handle->src_height, handle->src_buf_size,
-               handle->dst_packet, handle->dst_format, handle->dst_width, handle->dst_height, handle->dst_buf_size);
-
        media_format_unref(dst_fmt);
        IMGP_FREE(handle->dst);
 
index e2b2d6cc7064274032a7fdac767c9ed99da32ad5..16d26c585464deec2144241cb512a23655371d84 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.44
+Version:    0.45
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0