From: Jiyong Date: Tue, 5 Dec 2023 08:12:04 +0000 (+0900) Subject: Add new mm_image_create_image2() using weak copy X-Git-Tag: accepted/tizen/unified/20240129.163408^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F11%2F302311%2F5;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Add new mm_image_create_image2() using weak copy Change-Id: I96f0f4372eef5213164b6f47e63e8d33baa16445 --- diff --git a/common/include/mm_util_image.h b/common/include/mm_util_image.h index fbeb21f..018e8ba 100755 --- a/common/include/mm_util_image.h +++ b/common/include/mm_util_image.h @@ -33,6 +33,9 @@ void mm_image_debug_image(mm_util_image_h image, const char *message); int mm_image_create_image(unsigned int width, unsigned int height, mm_util_color_format_e color, const unsigned char *data, size_t size, mm_util_image_h *image); +int mm_image_create_image2(unsigned int width, unsigned int height, + mm_util_color_format_e color, const unsigned char *data, size_t size, + mm_util_image_h *image); int mm_image_clone_image(mm_util_image_h src, mm_util_image_h *dst); int mm_image_set_delay_time(mm_util_image_h image, unsigned int delay_time); int mm_image_get_delay_time(mm_util_image_h image, unsigned int *delay_time); diff --git a/common/include/mm_util_type.h b/common/include/mm_util_type.h index ecd773c..3b997e8 100755 --- a/common/include/mm_util_type.h +++ b/common/include/mm_util_type.h @@ -22,6 +22,7 @@ #ifndef __MM_UTIL_TYPE_H__ #define __MM_UTIL_TYPE_H__ +#include #include #ifdef __cplusplus @@ -111,6 +112,7 @@ typedef struct { unsigned int width; unsigned int height; mm_util_color_format_e color; + bool is_allocated; void *data; size_t size; unsigned int delay_time; diff --git a/common/mm_util_image.c b/common/mm_util_image.c index cfd9f40..ff3df6c 100755 --- a/common/mm_util_image.c +++ b/common/mm_util_image.c @@ -37,17 +37,14 @@ void mm_image_debug_image(mm_util_image_h image, const char *message) mm_util_retm_if(image == NULL, "Invalid image"); - if (message) - mm_util_sec_debug("[%s] w [%u], h [%u], color [%u], data [%p], size [%zu]", message, - _image->width, _image->height, _image->color, _image->data, _image->size); - else - mm_util_sec_debug("w [%u], h [%u], color [%u], data [%p], size [%zu]", - _image->width, _image->height, _image->color, _image->data, _image->size); + mm_util_sec_debug("[%s] w [%u], h [%u], color [%u], data [%p], size [%zu], is_allocated [%d]", + message ? message : "none", _image->width, _image->height, _image->color, + _image->data, _image->size, _image->is_allocated); } -int mm_image_create_image(unsigned int width, unsigned int height, +static int __create_new_image(unsigned int width, unsigned int height, mm_util_color_format_e color, const unsigned char *data, size_t size, - mm_util_image_h *image) + bool deep_copy, mm_util_image_h *image) { mm_image_info_s *_image = NULL; @@ -61,17 +58,16 @@ int mm_image_create_image(unsigned int width, unsigned int height, _image = g_new0(mm_image_info_s, 1); - /* Just TEMP_DATA_SIZE has been used internally. - * It will be removed after removing deprecated CAPIs. */ - if (size == TEMP_DATA_SIZE) - _image->data = (unsigned char *)data; - else + if (deep_copy) _image->data = g_memdup2(data, size); + else + _image->data = (void *)data; _image->size = size; _image->width = width; _image->height = height; _image->color = color; + _image->is_allocated = deep_copy; *image = (mm_util_image_h)_image; @@ -80,29 +76,33 @@ int mm_image_create_image(unsigned int width, unsigned int height, return MM_UTIL_ERROR_NONE; } +int mm_image_create_image(unsigned int width, unsigned int height, + mm_util_color_format_e color, const unsigned char *data, size_t size, + mm_util_image_h *image) +{ + /* Just TEMP_DATA_SIZE has been used internally. + * It will be removed after removing deprecated CAPIs. */ + if (size == TEMP_DATA_SIZE) + return __create_new_image(width, height, color, data, size, false, image); + + return __create_new_image(width, height, color, data, size, true, image); +} + +int mm_image_create_image2(unsigned int width, unsigned int height, + mm_util_color_format_e color, const unsigned char *data, size_t size, + mm_util_image_h *image) +{ + return __create_new_image(width, height, color, data, size, false, image); +} + int mm_image_clone_image(mm_util_image_h src, mm_util_image_h *dst) { mm_image_info_s *_src = (mm_image_info_s *)src; - mm_image_info_s *_dst = NULL; mm_util_retvm_if(!src, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src"); mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst"); - _dst = g_new0(mm_image_info_s, 1); - - _dst->width = _src->width; - _dst->height = _src->height; - _dst->color = _src->color; - _dst->size = _src->size; - - if (_src->size == TEMP_DATA_SIZE) - _dst->data = _src->data; - else - _dst->data = g_memdup2(_src->data, _dst->size); - - *dst = (mm_util_image_h)_dst; - - return MM_UTIL_ERROR_NONE; + return __create_new_image(_src->width, _src->height, _src->color, _src->data, _src->size, _src->is_allocated, dst); } int mm_image_set_delay_time(mm_util_image_h image, unsigned int delay_time) @@ -163,9 +163,7 @@ void mm_image_destroy_image(mm_util_image_h image) if (!image) return; - /* Just TEMP_DATA_SIZE has been used internally. - * It will be removed after removing deprecated CAPIs. */ - if (_image->size != TEMP_DATA_SIZE) + if (_image->is_allocated) g_free(_image->data); g_free(_image); }