From: jiyong.min Date: Sun, 14 Oct 2018 22:59:28 +0000 (+0900) Subject: Change 'gif_image_s' to 'mm_image_info_s' for the unified raw image structure X-Git-Tag: submit/tizen/20181106.000712^2~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ebd8d1268b1e2f1cace9916812703e1630abe00;p=platform%2Fcore%2Fapi%2Fimage-util.git Change 'gif_image_s' to 'mm_image_info_s' for the unified raw image structure Change-Id: I8965c796fcb598ec5619d98fba600cc6901299ff --- diff --git a/decode-test/image_util_decode_encode_testsuite.c b/decode-test/image_util_decode_encode_testsuite.c index 076fac1..e0cc4ae 100644 --- a/decode-test/image_util_decode_encode_testsuite.c +++ b/decode-test/image_util_decode_encode_testsuite.c @@ -566,11 +566,11 @@ gboolean test_encode_gif() if (g_test_decode[i].decode_result == FALSE) continue; - ret = image_util_encode_set_input_buffer(encoded, g_test_decode[i].decoded); + ret = image_util_encode_set_resolution(encoded, g_test_decode[i].width, g_test_decode[i].height); if (ret != IMAGE_UTIL_ERROR_NONE) continue; - ret = image_util_encode_set_resolution(encoded, g_test_decode[i].width, g_test_decode[i].height); + ret = image_util_encode_set_input_buffer(encoded, g_test_decode[i].decoded); if (ret != IMAGE_UTIL_ERROR_NONE) continue; @@ -636,11 +636,17 @@ gboolean test_encode_gif_frame_by_frame() continue; image_util_frame_h frame = NULL; - ret = image_util_frame_create(encoded, &frame); + ret = image_util_frame_create(&frame); if (ret != IMAGE_UTIL_ERROR_NONE) continue; - ret = image_util_frame_set_frame(frame, g_test_decode[i].decoded); + ret = image_util_frame_set_resolution(frame, g_test_decode[i].width, g_test_decode[i].height); + if (ret != IMAGE_UTIL_ERROR_NONE) { + image_util_frame_destroy(frame); + continue; + } + + ret = image_util_frame_set_frame(frame, g_test_decode[i].decoded, g_test_decode[i].decode_size); if (ret != IMAGE_UTIL_ERROR_NONE) { image_util_frame_destroy(frame); continue; diff --git a/include/image_util_internal.h b/include/image_util_internal.h index d15f6dd..f2b583d 100644 --- a/include/image_util_internal.h +++ b/include/image_util_internal.h @@ -17,6 +17,7 @@ #ifndef __TIZEN_MULTIMEDIA_IMAGE_UTIL_INTERNAL_H__ #define __TIZEN_MULTIMEDIA_IMAGE_UTIL_INTERNAL_H__ +#include #include #ifdef __cplusplus @@ -174,9 +175,13 @@ typedef void *image_util_frame_h; /** * @internal * @brief Creates the handle of the frame to encode. -* @since_tizen 4.0 +* @since_tizen 5.5 * -* @param[in] encode_h The encode handle +* @param[in] width The width of input image +* @param[in] height The height of input image +* @param[in] color The colorspace of input image +* @param[in] data The data of input image +* @param[in] size The size of the data * @param[in, out] frame_h The frame handle created by encode handle * * @return @c 0 on success, @@ -184,23 +189,44 @@ typedef void *image_util_frame_h; * * @retval #IMAGE_UTIL_ERROR_NONE Successful * @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #IMAGE_UTIL_ERROR_OUT_OF_MEMORY Out of memory +* +* @post image_util_encode_frame_destroy() +* @see image_util_encode_frame_destroy() +*/ +int image_util_frame_create(image_util_frame_h *frame_h); + +/** +* @internal +* @brief Creates the handle of the frame to encode. +* @since_tizen 5.5 +* +* @param[in] frame_h The frame handle to encode +* @param[in] width The width of input image +* @param[in] height The height of input image +* +* @return @c 0 on success, +* otherwise a negative error value +* +* @retval #IMAGE_UTIL_ERROR_NONE Successful +* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter * @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation * * @post image_util_encode_frame_destroy() * @see image_util_encode_frame_destroy() */ -int image_util_frame_create(image_util_encode_h handle, image_util_frame_h *frame_h); +int image_util_frame_set_resolution(image_util_frame_h frame_h, unsigned long width, unsigned long height); /** * @internal -* @brief Sets the delay of the gif. +* @brief Sets the frame buffer and size. * @since_tizen 4.0 * -* @remarks The unit of the delay time is 10ms. If the delay time set to 50ms, the value of @delay_time should be 5. -* If the delay time set to 1 sec, the value of @delay_time should be 100. +* @remarks The @a buffer should be released using free(). * * @param[in] frame_h The frame handle to encode -* @param[in] delay_time The delay time of the frame of the gif +* @param[in] buffer The frame buffer to encode +* @param[in] size The buffer size to encode * * @return @c 0 on success, * otherwise a negative error value @@ -212,17 +238,18 @@ int image_util_frame_create(image_util_encode_h handle, image_util_frame_h *fram * @pre image_util_encode_frame_create() * @see image_util_encode_frame_create() */ -int image_util_frame_set_gif_delay(image_util_frame_h frame_h, const int delay_time); +int image_util_frame_set_frame(image_util_frame_h frame_h, unsigned char *buffer, size_t size); /** * @internal -* @brief Sets the frame buffer. +* @brief Sets the delay of the gif. * @since_tizen 4.0 * -* @remarks The @a buffer should be released using free(). +* @remarks The unit of the delay time is 10ms. If the delay time set to 50ms, the value of @delay_time should be 5. +* If the delay time set to 1 sec, the value of @delay_time should be 100. * * @param[in] frame_h The frame handle to encode -* @param[in] buffer The frame buffer to encode +* @param[in] delay_time The delay time of the frame of the gif * * @return @c 0 on success, * otherwise a negative error value @@ -234,7 +261,7 @@ int image_util_frame_set_gif_delay(image_util_frame_h frame_h, const int delay_t * @pre image_util_encode_frame_create() * @see image_util_encode_frame_create() */ -int image_util_frame_set_frame(image_util_frame_h frame_h, unsigned char *buffer); +int image_util_frame_set_gif_delay(image_util_frame_h frame_h, const int delay_time); /** * @internal diff --git a/include/image_util_private.h b/include/image_util_private.h index 015062b..43399b9 100755 --- a/include/image_util_private.h +++ b/include/image_util_private.h @@ -180,10 +180,6 @@ typedef struct { GThread *thread; } decode_s; -typedef struct { - void *frame_h; -} frame_s; - typedef enum { ERR_TYPE_COMMON, ERR_TYPE_TRANSFORM, diff --git a/src/image_util_encode.c b/src/image_util_encode.c index a3c7fa8..9b5389c 100644 --- a/src/image_util_encode.c +++ b/src/image_util_encode.c @@ -23,7 +23,7 @@ #include #include -static int _image_util_encode_get_gif_frame(mm_gif_file_h gif_data, unsigned int index, mm_gif_image_h *frame) +static int _image_util_encode_get_gif_frame(mm_gif_file_h gif_data, unsigned int index, mm_image_info_s **frame) { int err = MM_UTIL_ERROR_NONE; image_util_retvm_if((gif_data == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); @@ -159,7 +159,7 @@ int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long w _handle->height = height; mm_util_gif_encode_set_resolution(gif_data, width, height); } - mm_gif_image_h frame = NULL; + mm_image_info_s * frame = NULL; err = _image_util_encode_get_gif_frame(gif_data, _handle->current_resolution_count, &frame); image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "_image_util_encode_get_gif_frame failed %d", err); @@ -235,7 +235,7 @@ int image_util_encode_set_gif_frame_delay_time(image_util_encode_h handle, unsig image_util_retvm_if((delay_time > INT_MAX), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid delay time"); - mm_gif_image_h frame = NULL; + mm_image_info_s * frame = NULL; err = _image_util_encode_get_gif_frame(gif_data, _handle->current_delay_count, &frame); image_util_retvm_if((err != IMAGE_UTIL_ERROR_NONE), err, "_image_util_encode_get_gif_frame failed %d", err); @@ -257,7 +257,7 @@ int image_util_encode_set_input_buffer(image_util_encode_h handle, const unsigne /* initialize buffer and value for source buffer */ if (_handle->image_type == IMAGE_UTIL_GIF) { mm_gif_file_h gif_data = (mm_gif_file_h) _handle->image_h; - mm_gif_image_h frame = NULL; + mm_image_info_s * frame = NULL; image_util_retvm_if(gif_data == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid gif data"); err = _image_util_encode_get_gif_frame(gif_data, _handle->current_buffer_count, &frame); diff --git a/src/image_util_internal.c b/src/image_util_internal.c index 414ba5a..fc4be80 100644 --- a/src/image_util_internal.c +++ b/src/image_util_internal.c @@ -116,77 +116,63 @@ int image_util_crop(unsigned char *dest, int x, int y, int *width, int *height, return _image_error_capi(ERR_TYPE_TRANSFORM, err); } -int image_util_frame_create(image_util_encode_h handle, image_util_frame_h *frame_h) +int image_util_frame_create(image_util_frame_h *frame_h) { - int ret = MM_UTIL_ERROR_NONE; - - image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - encode_s *image = (encode_s *)handle; - image_util_retvm_if((image->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong"); + mm_image_info_s *_image_info = calloc(1, sizeof(mm_image_info_s)); + image_util_retvm_if(_image_info == NULL, IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed"); - frame_s *frame = calloc(1, sizeof(frame_s)); - if (frame == NULL) { - image_util_error("Memory allocation is failed."); - return IMAGE_UTIL_ERROR_OUT_OF_MEMORY; - } + _image_info->color = IMAGE_UTIL_COLORSPACE_ARGB8888; - if (image->image_type == IMAGE_UTIL_GIF) { - mm_gif_file_h gif_data = (mm_gif_file_h)image->image_h; - mm_gif_image_h gif_frame = NULL; - - ret = mm_util_gif_image_create(gif_data, &gif_frame); - if (ret != MM_UTIL_ERROR_NONE) { - image_util_error("mm_util_gif_image_create is failed(%d).", ret); - IMAGE_UTIL_SAFE_FREE(frame); - return _image_error_capi(ERR_TYPE_ENCODE, ret); - } - frame->frame_h = gif_frame; - } else { - image_util_error("The image type(%d) is not supported.", image->image_type); - IMAGE_UTIL_SAFE_FREE(frame); - return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; - } + *frame_h = (mm_image_info_s *)_image_info; + + return IMAGE_UTIL_ERROR_NONE; +} + +int image_util_frame_set_resolution(image_util_frame_h frame_h, const unsigned long width, const unsigned long height) +{ + image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((width == 0 || height == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + + mm_image_info_s *frame = (mm_image_info_s *)frame_h; - *frame_h = frame; + frame->width = width; + frame->height = height; return IMAGE_UTIL_ERROR_NONE; } int image_util_frame_set_gif_delay(image_util_frame_h frame_h, const int delay_time) { - int ret = MM_UTIL_ERROR_NONE; - image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); image_util_retvm_if((delay_time <= 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Delay Time"); - frame_s *frame = (frame_s *)frame_h; + mm_image_info_s *frame = (mm_image_info_s *)frame_h; - ret = mm_util_gif_image_set_delay_time(frame->frame_h, delay_time); - if (ret != MM_UTIL_ERROR_NONE) { - image_util_error("mm_util_gif_image_set_delay_time is failed(%d).", ret); - return _image_error_capi(ERR_TYPE_ENCODE, ret); - } + frame->delay_time = delay_time; return IMAGE_UTIL_ERROR_NONE; } -int image_util_frame_set_frame(image_util_frame_h frame_h, unsigned char *buffer) +int image_util_frame_set_frame(image_util_frame_h frame_h, unsigned char *buffer, size_t size) { - int ret = MM_UTIL_ERROR_NONE; - image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - image_util_retvm_if((buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Buffer"); + image_util_retvm_if((buffer == NULL || size == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Buffer"); - frame_s *frame = (frame_s *)frame_h; + mm_image_info_s *frame = (mm_image_info_s *)frame_h; - ret = mm_util_gif_image_set_image(frame->frame_h, buffer); - if (ret != MM_UTIL_ERROR_NONE) { - image_util_error("mm_util_gif_image_set_image is failed(%d).", ret); - return _image_error_capi(ERR_TYPE_ENCODE, ret); + frame->data = calloc(1, size); + if (frame->data == NULL) { + image_util_error("Memory allocation failed"); + mm_util_gif_image_destory(frame); + return IMAGE_UTIL_ERROR_OUT_OF_MEMORY; } + memcpy(frame->data, buffer, size); + + frame->size = size; + return IMAGE_UTIL_ERROR_NONE; } @@ -194,9 +180,9 @@ void image_util_frame_destroy(image_util_frame_h frame_h) { image_util_retm_if((frame_h == NULL), "Invalid Handle"); - frame_s *frame = (frame_s *)frame_h; - mm_util_gif_image_destory(frame->frame_h); + mm_image_info_s *frame = (mm_image_info_s *)frame_h; + IMAGE_UTIL_SAFE_FREE(frame->data); IMAGE_UTIL_SAFE_FREE(frame); } @@ -208,10 +194,11 @@ int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h image_util_retvm_if((frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); encode_s *encode = (encode_s *)encode_h; - frame_s *frame = (frame_s *)frame_h; + mm_image_info_s *frame = (mm_image_info_s *)frame_h; image_util_retvm_if((encode->image_h == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong"); image_util_retvm_if((encode->image_type != IMAGE_UTIL_GIF), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "The image type(%d) is not supported.", encode->image_type); - image_util_retvm_if((frame->frame_h == NULL), IMAGE_UTIL_ERROR_INVALID_OPERATION, "The frame handle is wrong"); + image_util_retvm_if((frame->width == 0) || (frame->height == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + image_util_retvm_if(frame->data == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); mm_gif_file_h gif_data = (mm_gif_file_h)encode->image_h; @@ -226,7 +213,7 @@ int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h return _image_error_capi(ERR_TYPE_ENCODE, ret); } - ret = mm_util_gif_encode_add_image(gif_data, (mm_gif_image_h)frame->frame_h); + ret = mm_util_gif_encode_add_image(gif_data, (mm_image_info_s *)frame); if (ret != MM_UTIL_ERROR_NONE) { image_util_error("mm_util_gif_encode_add_image is failed(%d).", ret); return _image_error_capi(ERR_TYPE_ENCODE, ret);