From a12dabd6202b12795957f5fcb9efef7271c9e25d Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Fri, 12 Oct 2018 10:39:43 +0900 Subject: [PATCH] Seperate mm_util_gif_encode_gif to `mm_util_encode_to_gif_file` and `mm_util_encode_to_gif_memory` Change-Id: I7dd685405ce87e6f7d32ef10eb777a056d743719 --- gif/include/mm_util_gif.h | 196 +------------------------------------- gif/mm_util_gif.c | 37 ++++++- 2 files changed, 40 insertions(+), 193 deletions(-) diff --git a/gif/include/mm_util_gif.h b/gif/include/mm_util_gif.h index 8957d6f..0d482e5 100755 --- a/gif/include/mm_util_gif.h +++ b/gif/include/mm_util_gif.h @@ -55,215 +55,27 @@ typedef void* mm_gif_file_h; int mm_util_decode_from_gif_file(const char *filename, mm_image_info_s * decoded); int mm_util_decode_from_gif_memory(void *memory, mm_image_info_s * decoded); +int mm_util_encode_to_gif_file(mm_gif_file_h gif_file_h, const char *path); +int mm_util_encode_to_gif_memory(mm_gif_file_h gif_file_h, void **buffer, size_t *size); -/** - * This function creates the handle of the single image(frame). - * - * @param gif_file_h [in] the handle of the gif data. - * @param gif_image_h [out] the handle of the single image. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_image_destory - * @post mm_util_gif_image_destory - */ +/* a-gif extras */ int mm_util_gif_image_create(mm_gif_file_h gif_file_h, mm_gif_image_h *gif_image_h); - -/** - * This function sets the position of the single image(frame). - * - * @param gif_image_h [in] the handle of the single image. - * @param left [in] the left of the single image. - * @param top [in] the top of the single image. - * @param width [in] the width of the single image. - * @param height [in] the height of the single image. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_image_create - * @pre mm_util_gif_image_create - */ int mm_util_gif_image_set_position(mm_gif_image_h gif_image_h, const int left, const int top, const int width, const int height); - -/** - * This function sets the delay time of the single image(frame). - * - * @param gif_image_h [in] the handle of the single image. - * @param delay_time [in] the delay time of the single image. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_image_create - * @pre mm_util_gif_image_create - */ int mm_util_gif_image_set_delay_time(mm_gif_image_h gif_image_h, const int delay_time); - -/** - * This function sets the buffer of the single image(frame). - * - * @param gif_image_h [in] the handle of the single image. - * @param image_data [in] the buffer which has image data. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_image_create - * @pre mm_util_gif_image_create - */ int mm_util_gif_image_set_image(mm_gif_image_h gif_image_h, const unsigned char *image_data); - -/** - * This function destroys the handle of the single image(frame). - * - * @param gif_image_h [in] the handle of the single image. - * @return None. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_image_create - * @pre mm_util_gif_image_create - */ void mm_util_gif_image_destory(mm_gif_image_h gif_image_h); -/** - * This function creates the handle of gif data. - * - * @param gif_file_h [in] the handle of the gif data. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_destroy - * @post mm_util_gif_encode_destroy - */ int mm_util_gif_encode_create(mm_gif_file_h *gif_file_h); - -/** - * This function sets the filepath to save encoded gif. - * - * @param gif_file_h [in] the handle of the gif data. - * @param file_name [in] the filepath to save encoded image. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @pre mm_util_gif_encode_create - */ int mm_util_gif_encode_set_file(mm_gif_file_h gif_file_h, const char *file_name); - -/** - * This function sets the buffer to save encoded gif. - * - * @param gif_file_h [in] the handle of the gif data. - * @param data [in] the buffer to save encoded image. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @pre mm_util_gif_encode_create - */ int mm_util_gif_encode_set_mem(mm_gif_file_h gif_file_h, void **data, size_t *data_size); - -/** - * This function sets the resolution(width, height) for gif. - * - * @param gif_file_h [in] the handle of the gif data. - * @param width [in] the width of the image to encode. - * @param height [in] the height of the image to encode. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @pre mm_util_gif_encode_create - */ int mm_util_gif_encode_set_resolution(mm_gif_file_h gif_file_h, const int width, const int height); - -/** - * This function starts encoding image. - * - * @param gif_file_h [in] the handle of the gif data. - * @param bg_color [in] the background color of the image to encode. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @post mm_util_gif_encode_add_image - */ int mm_util_gif_encode_start(mm_gif_file_h gif_file_h); - -/** - * This function encodes the single image(frame). - * - * @param gif_file_h [in] the handle of the gif data. - * @param gif_image_h [in] the handle of the single image to encode. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @pre mm_util_gif_encode_start - * @post mm_util_gif_encode_save - */ int mm_util_gif_encode_add_image(mm_gif_file_h gif_file_h, mm_gif_image_h gif_image_h); - -/** - * This function saves encoded image. - * - * @param gif_file_h [in] the handle of the gif data. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @pre mm_util_gif_encode_add_image - */ int mm_util_gif_encode_save(mm_gif_file_h gif_file_h); - -/** - * This function sets image into gif handle, the image will be encoded when @mm_util_gif_encode() is called. - * - * @param gif_file_h [in] the handle of the gif data. - * @param gif_image_h [in] the handle of the image to set into gif handle. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @pre mm_util_gif_encode_add_image - */ int mm_util_gif_enocde_set_image_handle(mm_gif_file_h gif_file_h, mm_gif_image_h gif_image_h); - -/** - * This function gets image from gif handle, can change the values in image after call this function. - * - * @param gif_file_h [in] the handle of the gif data. - * @param gif_file_h [in] the index of the image. - * @param gif_image_h [out] the handle of the image to get from gif handle. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @pre mm_util_gif_encode_add_image - */ int mm_util_gif_enocde_get_image_handle(mm_gif_file_h gif_file_h, const int index, mm_gif_image_h *gif_image_h); - -/** - * This function encodes gif image with images set into gif handle. - * - * @param gif_file_h [in] the handle of the gif data. - * @return This function returns zero on success, or negative value with error code. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @pre mm_util_gif_encode_add_image - */ -int mm_util_gif_encode(mm_gif_file_h gif_file_h); - -/** - * This function destroys the handle of gif data. - * - * @param gif_image_h [in] the handle of gif data. - * @return None. - * @remark - * @since R1, 2.0 - * @see mm_util_gif_encode_create - * @pre mm_util_gif_encode_create - */ void mm_util_gif_encode_destroy(mm_gif_file_h gif_file_h); +/* a-gif extras */ #ifdef __cplusplus } diff --git a/gif/mm_util_gif.c b/gif/mm_util_gif.c index 0ce9736..4a5080f 100755 --- a/gif/mm_util_gif.c +++ b/gif/mm_util_gif.c @@ -996,7 +996,7 @@ int mm_util_gif_enocde_get_image_handle(mm_gif_file_h gif_file_h, const int inde return MM_UTIL_ERROR_NONE; } -int mm_util_gif_encode(mm_gif_file_h gif_file_h) +int mm_util_encode_to_gif_file(mm_gif_file_h gif_file_h, const char *path) { int ret = MM_UTIL_ERROR_NONE; int i = 0; @@ -1007,6 +1007,41 @@ int mm_util_gif_encode(mm_gif_file_h gif_file_h) mm_util_retvm_if(gif_file == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); mm_util_retvm_if(gif_file->saved_image == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "Invalid parameter"); + ret = mm_util_gif_encode_set_file(gif_file, path); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_gif_encode_set_file failed %d", ret); + + /* this way is for image_util_encode_run(), remove it later */ + ret = mm_util_gif_encode_start(gif_file_h); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_gif_encode_start failed"); + + for (i = 0; i < gif_file->saved_image_count; i++) { + gif_image = (mm_gif_image_h)gif_file->saved_image[i]; + ret = mm_util_gif_encode_add_image(gif_file_h, gif_image); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_gif_encode_add_image failed"); + mm_util_gif_image_destory(gif_image); + } + MMUTIL_SAFE_FREE(gif_file->saved_image); + + ret = mm_util_gif_encode_save(gif_file_h); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_gif_encode_save failed"); + + return MM_UTIL_ERROR_NONE; +} + +int mm_util_encode_to_gif_memory(mm_gif_file_h gif_file_h, void **buffer, size_t *size) +{ + int ret = MM_UTIL_ERROR_NONE; + int i = 0; + + gif_file_s *gif_file = (gif_file_s *)gif_file_h; + mm_gif_image_h gif_image = NULL; + + mm_util_retvm_if(gif_file == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + mm_util_retvm_if(gif_file->saved_image == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "Invalid parameter"); + + ret = mm_util_gif_encode_set_mem(gif_file, buffer, size); + mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_gif_encode_set_mem failed %d", ret); + /* this way is for image_util_encode_run(), remove it later */ ret = mm_util_gif_encode_start(gif_file_h); mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "mm_util_gif_encode_start failed"); -- 2.34.1