From: Minje Ahn Date: Fri, 15 May 2020 06:39:57 +0000 (+0900) Subject: Add rotation for thumbnail X-Git-Tag: submit/tizen_5.5/20200602.012702^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f3525bd2024f635479d6c0bad2ac2c19666917de;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Add rotation for thumbnail Change-Id: I00be02cf150204986d7ca1ea869b3a9699ec9ac2 Signed-off-by: Minje Ahn --- diff --git a/magick/include/mm_util_magick.h b/magick/include/mm_util_magick.h index 4c54789..b6c4eb4 100755 --- a/magick/include/mm_util_magick.h +++ b/magick/include/mm_util_magick.h @@ -63,6 +63,8 @@ int mm_util_resize_P_P(const char *src_path, unsigned int req_width, unsigned in int mm_util_convert_B_B(mm_util_image_h src_handle, mm_util_color_format_e req_format, mm_util_image_h *dst_handle); +int mm_util_resize_and_rotate_P_P(const char *src_path, unsigned int req_width, unsigned int req_height, const char *dst_path); + int mm_util_extract_image_info(const char *path, mm_util_img_codec_type *type, unsigned int *width, unsigned int *height); #ifdef __cplusplus diff --git a/magick/mm_util_magick.c b/magick/mm_util_magick.c index e9bb9cb..0c8aad8 100644 --- a/magick/mm_util_magick.c +++ b/magick/mm_util_magick.c @@ -20,7 +20,12 @@ */ #include +#include +#include +#include + #include + #include "mm_util_private.h" #include "mm_util_magick.h" @@ -72,25 +77,18 @@ static void __mm_util_init(ExceptionInfo *exception) SetErrorHandler(__mm_util_magick_error_handler); SetFatalErrorHandler(__mm_util_magick_error_handler); SetWarningHandler(__mm_util_magick_error_handler); - - return; } -static void __mm_util_finalize(Image *image_1, Image *image_2, ImageInfo *imageInfo, ExceptionInfo *exception) +static void __mm_util_finalize(Image *image_1, Image *image_2, ExceptionInfo *exception) { DestroyImageList(image_1); DestroyImageList(image_2); - if (imageInfo != NULL) - DestroyImageInfo(imageInfo); - if (exception != NULL) DestroyExceptionInfo(exception); DestroyMagick(); - - return; } static int __mm_util_get_map(mm_util_color_format_e format, char **map) @@ -220,7 +218,7 @@ static Image * __mm_util_resize_image(Image *image, unsigned int width, unsigned return _processed_image; } -static Image * __mm_util_read_image_from_file(const char *path, ImageInfo **image_info) +static Image * __mm_util_read_image_from_file(const char *path) { ImageInfo *_image_info = NULL; Image *_image = NULL; @@ -229,11 +227,11 @@ static Image * __mm_util_read_image_from_file(const char *path, ImageInfo **imag mm_util_fenter(); mm_util_retvm_if(!MMUTIL_STRING_VALID(path), NULL, "invalid path"); - mm_util_retvm_if(image_info == NULL, NULL, "invalid image_info"); GetExceptionInfo(&exception); _image_info = CloneImageInfo(0); + mm_util_retvm_if(!_image_info, NULL, "Error: CloneImageInfo failed."); g_strlcpy(_image_info->filename, path, sizeof(_image_info->filename)); AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", &exception); @@ -246,12 +244,9 @@ static Image * __mm_util_read_image_from_file(const char *path, ImageInfo **imag mm_util_error("Error: Reading Image failed."); if (exception.severity != UndefinedException) CatchException(&exception); - - DestroyImageInfo(_image_info); - } else { - *image_info = _image_info; } + DestroyImageInfo(_image_info); DestroyExceptionInfo(&exception); mm_util_fleave(); @@ -259,31 +254,34 @@ static Image * __mm_util_read_image_from_file(const char *path, ImageInfo **imag return _image; } -static int __mm_util_write_image_to_file(ImageInfo *image_info, Image *image, const char *out_path) +static int __mm_util_write_image_to_file(Image *image, const char *out_path) { int ret = MM_UTIL_ERROR_NONE; + ImageInfo *_image_info = NULL; ExceptionInfo exception; mm_util_fenter(); - mm_util_retvm_if(image_info == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image_info"); mm_util_retvm_if(image == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image"); mm_util_retvm_if(!MMUTIL_STRING_VALID(out_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid out_path"); GetExceptionInfo(&exception); + _image_info = CloneImageInfo(0); + mm_util_retvm_if(_image_info == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "Error: CloneImageInfo failed."); + SAFE_STRLCPY(image->filename, out_path, sizeof(image->filename)); image->filename[MaxTextExtent-1] = '\0'; - AddDefinition(image_info, "jpeg", "dct-method", "FASTEST", &exception); - AddDefinition(image_info, "jpeg", "optimize-coding", "FALSE", &exception); - //DeleteImageProfile(image, "EXIF"); + AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", &exception); + AddDefinition(_image_info, "jpeg", "optimize-coding", "FALSE", &exception); + DeleteImageProfile(image, "EXIF"); DeleteImageProfile(image, "8BIM"); DeleteImageProfile(image, "ICM"); DeleteImageProfile(image, "IPTC"); DeleteImageProfile(image, "XMP"); - if (WriteImage (image_info, image) == MagickFalse) { + if (WriteImage (_image_info, image) == MagickFalse) { mm_util_error("Error: Writing Image failed."); if (exception.severity != UndefinedException) CatchException(&exception); @@ -291,6 +289,7 @@ static int __mm_util_write_image_to_file(ImageInfo *image_info, Image *image, co ret = MM_UTIL_ERROR_INVALID_OPERATION; } + DestroyImageInfo(_image_info); DestroyExceptionInfo(&exception); mm_util_fleave(); @@ -398,7 +397,7 @@ int mm_util_rotate_B_B(mm_util_image_h src_handle, mm_util_magick_rotate_type an ERROR: - __mm_util_finalize(_image, _processed_image, NULL, &exception); + __mm_util_finalize(_image, _processed_image, &exception); MMUTIL_SAFE_FREE(map); @@ -414,7 +413,6 @@ int mm_util_rotate_B_P(mm_util_image_h src_handle, mm_util_magick_rotate_type an char *map = NULL; Image *_image = NULL; Image *_processed_image = NULL; - ImageInfo *_image_info = NULL; ExceptionInfo exception; mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); @@ -442,12 +440,11 @@ int mm_util_rotate_B_P(mm_util_image_h src_handle, mm_util_magick_rotate_type an goto ERROR; } - _image_info = CloneImageInfo(0); - ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path); + ret = __mm_util_write_image_to_file(_processed_image, dst_path); ERROR: - __mm_util_finalize(_image, _processed_image, _image_info, &exception); + __mm_util_finalize(_image, _processed_image, &exception); MMUTIL_SAFE_FREE(map); @@ -462,7 +459,6 @@ int mm_util_rotate_P_B(const char *src_path, mm_util_magick_rotate_type angle, m char *map = NULL; Image *_image = NULL; Image *_processed_image = NULL; - ImageInfo *_image_info = NULL; ExceptionInfo exception; size_t pixels_size = 0; void *pixels = 0; @@ -478,7 +474,7 @@ int mm_util_rotate_P_B(const char *src_path, mm_util_magick_rotate_type angle, m __mm_util_init(&exception); - _image = __mm_util_read_image_from_file(src_path, &_image_info); + _image = __mm_util_read_image_from_file(src_path); if (_image == NULL) { mm_util_error("Error: __mm_util_read_image_from_file failed."); ret = MM_UTIL_ERROR_INVALID_OPERATION; @@ -507,7 +503,7 @@ int mm_util_rotate_P_B(const char *src_path, mm_util_magick_rotate_type angle, m ERROR: - __mm_util_finalize(_image, _processed_image, _image_info, &exception); + __mm_util_finalize(_image, _processed_image, &exception); MMUTIL_SAFE_FREE(map); @@ -522,7 +518,6 @@ int mm_util_rotate_P_P(const char *src_path, mm_util_magick_rotate_type angle, c int ret = MM_UTIL_ERROR_NONE; Image *_image = NULL; Image *_processed_image = NULL; - ImageInfo *_image_info = NULL; ExceptionInfo exception; mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path"); @@ -533,7 +528,7 @@ int mm_util_rotate_P_P(const char *src_path, mm_util_magick_rotate_type angle, c __mm_util_init(&exception); - _image = __mm_util_read_image_from_file(src_path, &_image_info); + _image = __mm_util_read_image_from_file(src_path); if (_image == NULL) { mm_util_error("Error: __mm_util_read_image_from_file failed."); ret = MM_UTIL_ERROR_INVALID_OPERATION; @@ -547,11 +542,11 @@ int mm_util_rotate_P_P(const char *src_path, mm_util_magick_rotate_type angle, c goto ERROR; } - ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path); + ret = __mm_util_write_image_to_file(_processed_image, dst_path); ERROR: - __mm_util_finalize(_image, _processed_image, _image_info, &exception); + __mm_util_finalize(_image, _processed_image, &exception); mm_util_fleave(); @@ -615,7 +610,7 @@ int mm_util_resize_B_B(mm_util_image_h src_handle, unsigned int req_width, unsig ERROR: - __mm_util_finalize(_image, _processed_image, NULL, &exception); + __mm_util_finalize(_image, _processed_image, &exception); MMUTIL_SAFE_FREE(map); @@ -631,7 +626,6 @@ int mm_util_resize_B_P(mm_util_image_h src_handle, unsigned int req_width, unsig char *map = NULL; Image *_image = NULL; Image *_processed_image = NULL; - ImageInfo *_image_info = NULL; ExceptionInfo exception; mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle"); @@ -665,12 +659,11 @@ int mm_util_resize_B_P(mm_util_image_h src_handle, unsigned int req_width, unsig goto ERROR; } - _image_info = CloneImageInfo(0); - ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path); + ret = __mm_util_write_image_to_file(_processed_image, dst_path); ERROR: - __mm_util_finalize(_image, _processed_image, _image_info, &exception); + __mm_util_finalize(_image, _processed_image, &exception); MMUTIL_SAFE_FREE(map); @@ -685,7 +678,6 @@ int mm_util_resize_P_B(const char *src_path, unsigned int req_width, unsigned in char *map = NULL; Image *_image = NULL; Image *_processed_image = NULL; - ImageInfo *_image_info = NULL; ExceptionInfo exception; size_t pixels_size = 0; void *pixels = 0; @@ -701,7 +693,7 @@ int mm_util_resize_P_B(const char *src_path, unsigned int req_width, unsigned in __mm_util_init(&exception); - _image = __mm_util_read_image_from_file(src_path, &_image_info); + _image = __mm_util_read_image_from_file(src_path); if (_image == NULL) { mm_util_error("Error: __mm_util_read_image_from_file failed."); ret = MM_UTIL_ERROR_INVALID_OPERATION; @@ -736,7 +728,7 @@ int mm_util_resize_P_B(const char *src_path, unsigned int req_width, unsigned in ERROR: - __mm_util_finalize(_image, _processed_image, _image_info, &exception); + __mm_util_finalize(_image, _processed_image, &exception); MMUTIL_SAFE_FREE(map); @@ -750,7 +742,6 @@ int mm_util_resize_P_P(const char *src_path, unsigned int req_width, unsigned in int ret = MM_UTIL_ERROR_NONE; Image *_image = NULL; Image *_processed_image = NULL; - ImageInfo *_image_info = NULL; ExceptionInfo exception; mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path"); @@ -761,7 +752,7 @@ int mm_util_resize_P_P(const char *src_path, unsigned int req_width, unsigned in __mm_util_init(&exception); - _image = __mm_util_read_image_from_file(src_path, &_image_info); + _image = __mm_util_read_image_from_file(src_path); if (_image == NULL) { mm_util_error("Error: __mm_util_read_image_from_file failed."); ret = MM_UTIL_ERROR_INVALID_OPERATION; @@ -781,11 +772,11 @@ int mm_util_resize_P_P(const char *src_path, unsigned int req_width, unsigned in goto ERROR; } - ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path); + ret = __mm_util_write_image_to_file(_processed_image, dst_path); ERROR: - __mm_util_finalize(_image, _processed_image, _image_info, &exception); + __mm_util_finalize(_image, _processed_image, &exception); mm_util_fleave(); @@ -842,7 +833,7 @@ int mm_util_convert_B_B(mm_util_image_h src_handle, mm_util_color_format_e req_f ERROR: - __mm_util_finalize(_image, NULL, NULL, &exception); + __mm_util_finalize(_image, NULL, &exception); MMUTIL_SAFE_FREE(map); @@ -850,3 +841,82 @@ ERROR: return ret; } + +int mm_util_resize_and_rotate_P_P(const char *src_path, unsigned int req_width, unsigned int req_height, const char *dst_path) +{ + int ret = MM_UTIL_ERROR_NONE; + Image *_image = NULL; + Image *_resized_image = NULL; + Image *_rotated_image = NULL; + ExceptionInfo exception; + mm_util_magick_rotate_type rotation = MM_UTIL_ROTATE_0; + + mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path"); + mm_util_retvm_if((req_width == 0) || (req_height == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size W[%d] H[%d]", req_width, req_height); + mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path"); + + mm_util_sec_debug("src_path [%s] req_width [%u] req_height [%u] dst_path [%s]", src_path, req_width, req_height, dst_path); + + __mm_util_init(&exception); + + _image = __mm_util_read_image_from_file(src_path); + if (_image == NULL) { + mm_util_error("Error: __mm_util_read_image_from_file failed."); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; + } + + if ((_image->columns < req_width) || (_image->rows < req_height)) { + mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height); + ret = MM_UTIL_ERROR_INVALID_PARAMETER; + goto ERROR; + } + + _resized_image = __mm_util_resize_image(_image, req_width, req_height); + if (_resized_image == NULL) { + mm_util_error("Error: __mm_util_resize_image failed."); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; + } + + switch(_resized_image->orientation) { + case TopRightOrientation: + case RightTopOrientation: + rotation = MM_UTIL_ROTATE_90; + break; + case BottomRightOrientation: + case RightBottomOrientation: + rotation = MM_UTIL_ROTATE_180; + break; + case BottomLeftOrientation: + case LeftBottomOrientation: + rotation = MM_UTIL_ROTATE_270; + break; + case TopLeftOrientation: + case LeftTopOrientation: + break; + default: + mm_util_warn("Not supported orientation %d. so apply MM_UTIL_ROTATE_0", _resized_image->orientation); + break; + } + + if (rotation != MM_UTIL_ROTATE_0) { + _rotated_image = __mm_util_rotate_image(_resized_image, rotation); + if (_rotated_image == NULL) { + mm_util_error("Error: __mm_util_resize_image failed."); + ret = MM_UTIL_ERROR_INVALID_OPERATION; + goto ERROR; + } + } + + ret = __mm_util_write_image_to_file(((_rotated_image) ? _rotated_image : _resized_image), dst_path); + +ERROR: + + DestroyImageList(_image); + __mm_util_finalize(_resized_image, _rotated_image, &exception); + + mm_util_fleave(); + + return ret; +}