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;
_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;
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)
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);
}