return _bool;
}
-static int __mm_util_get_crop_image_size(mm_util_color_format_e format, unsigned int width, unsigned int height, size_t *imgsize)
+static int __mm_util_get_image_size(mm_util_color_format_e format, unsigned int width, unsigned int height, bool is_crop, size_t *imgsize)
{
unsigned char x_chroma_shift = 0;
unsigned char y_chroma_shift = 0;
mm_util_fenter();
mm_util_retvm_if(imgsize == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid imgsize");
- mm_util_retvm_if(__check_valid_picture_size(width, height) != MM_UTIL_ERROR_NONE, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid width and height");
-
- *imgsize = 0;
+ mm_util_retvm_if(IS_VALID_COLOR(format) == FALSE, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid format(%u)", format);
+ mm_util_retvm_if(__check_valid_picture_size(width, height) != MM_UTIL_ERROR_NONE, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid width(%u) or height(%u)", width, height);
switch (format) {
case MM_UTIL_COLOR_I420:
break;
case MM_UTIL_COLOR_RGB16:
- stride = width * 2;
+ stride = 2 * (is_crop ? width : MM_UTIL_ROUND_UP_4(width));
size = stride * height;
*imgsize = size;
break;
case MM_UTIL_COLOR_RGB24:
- stride = width * 3;
+ stride = 3 * (is_crop ? width : MM_UTIL_ROUND_UP_4(width));
size = stride * height;
*imgsize = size;
break;
case MM_UTIL_COLOR_NV12:
case MM_UTIL_COLOR_NV12_TILED:
+ case MM_UTIL_COLOR_NV21:
x_chroma_shift = 1;
y_chroma_shift = 1;
stride = MM_UTIL_ROUND_UP_4(width);
break;
default:
- mm_util_error("Not supported format [%d]", format);
+ mm_util_error("Not supported format [%u]", format);
return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
}
- mm_util_debug("format: %d, *imgsize: %zu", format, *imgsize);
+ mm_util_debug("format: %u, *imgsize: %zu", format, *imgsize);
return MM_UTIL_ERROR_NONE;
}
}
}
- __mm_util_get_crop_image_size(_src->color, _width, _height, &_buffer_size);
+ __mm_util_get_image_size(_src->color, _width, _height, true, &_buffer_size);
mm_util_retvm_if(!_buffer_size, MM_UTIL_ERROR_INVALID_OPERATION, "fail to get dst_buf_size");
_buffer = g_malloc0(_buffer_size);
int mm_util_get_image_size(mm_util_color_format_e format, unsigned int width, unsigned int height, size_t *imgsize)
{
- unsigned char x_chroma_shift = 0;
- unsigned char y_chroma_shift = 0;
- unsigned int w2, h2, stride, stride2;
- size_t size, size2;
-
- mm_util_fenter();
-
- mm_util_retvm_if((imgsize == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid imgsize");
- mm_util_retvm_if((IS_VALID_COLOR(format) == FALSE), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid format [%d]", format);
- mm_util_retvm_if((__check_valid_picture_size(width, height) != MM_UTIL_ERROR_NONE), MM_UTIL_ERROR_INVALID_PARAMETER, "image width & height is too big");
-
- *imgsize = 0;
-
- switch (format) {
- case MM_UTIL_COLOR_I420:
- case MM_UTIL_COLOR_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_COLOR_YUV422:
- case MM_UTIL_COLOR_YUYV:
- case MM_UTIL_COLOR_UYVY:
- case MM_UTIL_COLOR_NV16:
- case MM_UTIL_COLOR_NV61:
- stride = MM_UTIL_ROUND_UP_4(width) * 2;
- size = stride * height;
- *imgsize = size;
- break;
-
- case MM_UTIL_COLOR_RGB16:
- stride = MM_UTIL_ROUND_UP_4(width) * 2;
- size = stride * height;
- *imgsize = size;
- break;
-
- case MM_UTIL_COLOR_RGB24:
- stride = MM_UTIL_ROUND_UP_4(width) * 3;
- size = stride * height;
- *imgsize = size;
- break;
-
- case MM_UTIL_COLOR_ARGB:
- case MM_UTIL_COLOR_BGRA:
- case MM_UTIL_COLOR_RGBA:
- case MM_UTIL_COLOR_BGRX:
- stride = width * 4;
- size = stride * height;
- *imgsize = size;
- break;
-
- case MM_UTIL_COLOR_NV12:
- case MM_UTIL_COLOR_NV12_TILED:
- case MM_UTIL_COLOR_NV21:
- 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 [%d]", format);
- return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- }
-
- mm_util_debug("format: %u, *imgsize: %zu", format, *imgsize);
-
- return MM_UTIL_ERROR_NONE;
+ return __mm_util_get_image_size(format, width, height, false, imgsize);
}
-