4 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: YoungHun Kim <yh8004.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #include <magick/api.h>
24 #include "mm_util_private.h"
25 #include "mm_util_magick.h"
27 static bool __mm_util_check_angle(mm_util_magick_rotate_type angle);
29 static void __mm_util_magick_log_method(const ExceptionType excep, const char *message)
31 /* To exclude time, user time and pid */
32 unsigned int start_idx = 31;
34 if ((message == NULL) || (strlen(message) < start_idx)) {
38 if (excep >= ErrorException)
39 mm_util_error("[GM][Ex:%3u] %s", excep, message + start_idx);
40 else if (excep >= WarningException)
41 mm_util_warn("[GM][Ex:%3u] %s", excep, message + start_idx);
43 mm_util_debug("[GM][Ex:%3u] %s", excep, message + start_idx);
46 static void __mm_util_magick_error_handler(const ExceptionType excep, const char *reason, const char *message)
48 if (excep >= ErrorException)
49 mm_util_error("[GM][Ex:%3u][Rs:%s] %s", excep, reason, message);
51 mm_util_warn("[GM][Ex:%3u][Rs:%s] %s", excep, reason, message);
54 static void __mm_util_init(ExceptionInfo *exception)
56 InitializeMagick(NULL);
57 if (exception != NULL)
58 GetExceptionInfo(exception);
60 /* set LogEventMask to show like "all" or "warning, error" */
61 /* <LogEventMask List>
62 * "none", "information", "warning", "error", "fatalerror", "configure", "annotate",
63 * "render", "transform", "locale", "coder", "x11", "cache", "blob", "deprecate",
64 * "user", "resource", "temporaryfile", "exception", "option", "all"
66 #if (GMAGICK_DEBUG == 1)
67 SetLogEventMask("all");
69 SetLogEventMask("warning, error, fatalerror, exception");
71 SetLogMethod(__mm_util_magick_log_method);
72 SetErrorHandler(__mm_util_magick_error_handler);
73 SetFatalErrorHandler(__mm_util_magick_error_handler);
74 SetWarningHandler(__mm_util_magick_error_handler);
79 static void __mm_util_finalize(Image *image_1, Image *image_2, ImageInfo *imageInfo, ExceptionInfo *exception)
83 DestroyImage(image_1);
86 DestroyImage(image_2);
88 if (imageInfo != NULL)
89 DestroyImageInfo(imageInfo);
91 if (exception != NULL)
92 DestroyExceptionInfo(exception);
99 static int __mm_util_get_map(mm_util_color_format_e format, char **map)
101 mm_util_retvm_if(map == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid map");
104 case MM_UTIL_COLOR_RGB24:
105 *map = g_strdup("RGB");
107 case MM_UTIL_COLOR_ARGB:
108 *map = g_strdup("ARGB");
110 case MM_UTIL_COLOR_BGRA:
111 *map = g_strdup("BGRA");
113 case MM_UTIL_COLOR_RGBA:
114 *map = g_strdup("RGBA");
117 mm_util_error("Not supported format. [%d]", format);
118 return MM_UTIL_ERROR_INVALID_PARAMETER;
121 return MM_UTIL_ERROR_NONE;
124 static Image * __mm_util_constitute_image(mm_util_image_h handle, const char *map)
126 mm_image_info_s *_handle = (mm_image_info_s*)handle;
127 Image *_image = NULL;
128 ExceptionInfo exception;
132 mm_util_retvm_if(handle == NULL, NULL, "invalid handle");
133 mm_util_retvm_if(!MMUTIL_STRING_VALID(map), NULL, "invalid map");
135 GetExceptionInfo(&exception);
137 /* Read image from buffer */
138 _image = ConstituteImage(_handle->width, _handle->height, map, CharPixel, _handle->data, &exception);
139 if (_image == NULL) {
140 mm_util_error("Error: Getting Image failed.");
141 if (exception.severity != UndefinedException)
142 CatchException(&exception);
145 DestroyExceptionInfo(&exception);
152 static Image * __mm_util_rotate_image(Image *image, mm_util_magick_rotate_type angle)
154 Image *_processed_image = NULL;
155 ExceptionInfo exception;
159 mm_util_retvm_if(image == NULL, NULL, "invalid image");
161 GetExceptionInfo(&exception);
163 if (angle <= MM_UTIL_ROTATE_270) {
164 _processed_image = RotateImage(image, angle, &exception);
165 } else if (angle == MM_UTIL_ROTATE_FLIP_HORZ) {
166 _processed_image = FlopImage(image, &exception);
167 } else if (angle == MM_UTIL_ROTATE_FLIP_VERT) {
168 _processed_image = FlipImage(image, &exception);
170 mm_util_error("Invalid angle. [%d]", angle);
173 if (_processed_image == NULL) {
174 mm_util_error("Error: Image processing failed.");
175 if (exception.severity != UndefinedException)
176 CatchException(&exception);
179 DestroyExceptionInfo(&exception);
183 return _processed_image;
186 static Image * __mm_util_resize_image(Image *image, unsigned int width, unsigned int height)
188 Image *_processed_image = NULL;
189 Image *_sampled_image = NULL;
190 ExceptionInfo exception;
191 unsigned int check_factor = 3;
192 unsigned int sample_factor = 2;
196 mm_util_retvm_if(image == NULL, NULL, "invalid image");
198 GetExceptionInfo(&exception);
200 if ((image->columns > width * check_factor) && (image->rows > height * check_factor)) {
201 _sampled_image = SampleImage(image, width * sample_factor, height * sample_factor, &exception);
202 if (_sampled_image == (Image *) NULL)
203 mm_util_error("Error: Sampling Image failed.");
206 if (_sampled_image != NULL)
207 _processed_image = ScaleImage(_sampled_image, width, height, &exception);
209 _processed_image = ScaleImage(image, width, height, &exception);
211 if (_processed_image == NULL) {
212 mm_util_error("Error: Resizing Image failed.");
213 if (exception.severity != UndefinedException)
214 CatchException(&exception);
217 if (_sampled_image != NULL)
218 DestroyImage(_sampled_image);
220 DestroyExceptionInfo(&exception);
224 return _processed_image;
227 static Image * __mm_util_read_image_from_file(const char *path, ImageInfo **image_info)
229 ImageInfo *_image_info = NULL;
230 Image *_image = NULL;
231 ExceptionInfo exception;
235 mm_util_retvm_if(!MMUTIL_STRING_VALID(path), NULL, "invalid path");
236 mm_util_retvm_if(image_info == NULL, NULL, "invalid image_info");
238 GetExceptionInfo(&exception);
240 _image_info = CloneImageInfo(0);
241 g_strlcpy(_image_info->filename, path, sizeof(_image_info->filename));
243 AddDefinition(_image_info, "jpeg", "dct-method", "FASTEST", &exception);
244 AddDefinition(_image_info, "jpeg", "block-smoothing", "FALSE", &exception);
245 AddDefinition(_image_info, "jpeg", "fancy-upsampling", "FALSE", &exception);
247 _image = ReadImage(_image_info, &exception);
249 if (_image == NULL) {
250 mm_util_error("Error: Reading Image failed.");
251 if (exception.severity != UndefinedException)
252 CatchException(&exception);
254 DestroyImageInfo(_image_info);
256 *image_info = _image_info;
259 DestroyExceptionInfo(&exception);
266 static int __mm_util_write_image_to_file(ImageInfo *image_info, Image *image, const char *out_path)
268 int ret = MM_UTIL_ERROR_NONE;
269 ExceptionInfo exception;
273 mm_util_retvm_if(image_info == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image_info");
274 mm_util_retvm_if(image == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image");
275 mm_util_retvm_if(!MMUTIL_STRING_VALID(out_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid out_path");
277 GetExceptionInfo(&exception);
279 SAFE_STRLCPY(image->filename, out_path, sizeof(image->filename));
280 image->filename[MaxTextExtent-1] = '\0';
282 AddDefinition(image_info, "jpeg", "dct-method", "FASTEST", &exception);
283 AddDefinition(image_info, "jpeg", "optimize-coding", "FALSE", &exception);
284 //DeleteImageProfile(image, "EXIF");
285 DeleteImageProfile(image, "8BIM");
286 DeleteImageProfile(image, "ICM");
287 DeleteImageProfile(image, "IPTC");
288 DeleteImageProfile(image, "XMP");
290 if (WriteImage (image_info, image) == MagickFalse) {
291 mm_util_error("Error: Writing Image failed.");
292 if (exception.severity != UndefinedException)
293 CatchException(&exception);
295 ret = MM_UTIL_ERROR_INVALID_OPERATION;
298 DestroyExceptionInfo(&exception);
305 static void * __mm_util_write_image_to_buffer(Image *image, unsigned int width, unsigned int height, const char *map, size_t *pixels_size)
307 int ret = MM_UTIL_ERROR_NONE;
308 ExceptionInfo exception;
309 size_t _pixels_size = 0;
314 mm_util_retvm_if(image == NULL, NULL, "invalid image");
315 mm_util_retvm_if(!MMUTIL_STRING_VALID(map), NULL, "invalid map");
317 GetExceptionInfo(&exception);
319 _pixels_size = sizeof(unsigned char) * strlen(map) * width *height;
320 pixels = MagickMalloc(_pixels_size);
322 if (pixels == NULL) {
323 mm_util_error("Error: calloc failed.");
327 ret = DispatchImage(image, 0, 0, width, height, map, CharPixel, pixels, &exception);
328 if (ret == MagickFail) {
329 mm_util_error("Failed to Dispatch Image into dst buffer");
335 *pixels_size = _pixels_size;
338 DestroyExceptionInfo(&exception);
345 static bool __mm_util_check_angle(mm_util_magick_rotate_type angle)
347 if ((angle == MM_UTIL_ROTATE_0) || (angle == MM_UTIL_ROTATE_90) || (angle == MM_UTIL_ROTATE_180) || (angle == MM_UTIL_ROTATE_270) ||
348 (angle == MM_UTIL_ROTATE_FLIP_HORZ) || (angle == MM_UTIL_ROTATE_FLIP_VERT))
354 int mm_util_rotate_B_B(mm_util_image_h src_handle, mm_util_magick_rotate_type angle, mm_util_image_h *dst_handle)
356 int ret = MM_UTIL_ERROR_NONE;
357 mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
359 Image *_image = NULL;
360 Image *_processed_image = NULL;
361 ExceptionInfo exception;
362 size_t pixels_size = 0;
365 mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
366 mm_util_retvm_if(!__mm_util_check_angle(angle), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle);
367 mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
369 mm_util_debug("angle [%d]", angle);
371 ret = __mm_util_get_map(_src_handle->color, &map);
372 mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
374 __mm_util_init(&exception);
376 _image = __mm_util_constitute_image(src_handle, map);
377 if (_image == NULL) {
378 mm_util_error("Error: __mm_util_constitute_image failed.");
379 ret = MM_UTIL_ERROR_INVALID_OPERATION;
383 _processed_image = __mm_util_rotate_image(_image, angle);
384 if (_processed_image == NULL) {
385 mm_util_error("Error: __mm_util_rotate_image failed.");
386 ret = MM_UTIL_ERROR_INVALID_OPERATION;
390 pixels = __mm_util_write_image_to_buffer(_processed_image, _processed_image->columns, _processed_image->rows, map, &pixels_size);
391 if (pixels == NULL) {
392 mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
393 ret = MM_UTIL_ERROR_INVALID_OPERATION;
397 ret = mm_image_create_image(_processed_image->columns, _processed_image->rows, _src_handle->color, pixels, pixels_size, dst_handle);
398 if (ret != MM_UTIL_ERROR_NONE)
399 mm_util_error("Error: mm_image_create_image failed.");
405 __mm_util_finalize(_image, _processed_image, NULL, &exception);
407 MMUTIL_SAFE_FREE(map);
414 int mm_util_rotate_B_P(mm_util_image_h src_handle, mm_util_magick_rotate_type angle, const char *dst_path)
416 int ret = MM_UTIL_ERROR_NONE;
417 mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
419 Image *_image = NULL;
420 Image *_processed_image = NULL;
421 ImageInfo *_image_info = NULL;
422 ExceptionInfo exception;
424 mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
425 mm_util_retvm_if(!__mm_util_check_angle(angle), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle);
426 mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
428 mm_util_sec_debug("angle [%d] dst_path [%s]", angle, dst_path);
430 ret = __mm_util_get_map(_src_handle->color, &map);
431 mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
433 __mm_util_init(&exception);
435 _image = __mm_util_constitute_image(src_handle, map);
436 if (_image == NULL) {
437 mm_util_error("Error: __mm_util_constitute_image failed.");
438 ret = MM_UTIL_ERROR_INVALID_OPERATION;
442 _processed_image = __mm_util_rotate_image(_image, angle);
443 if (_processed_image == NULL) {
444 mm_util_error("Error: __mm_util_rotate_image failed.");
445 ret = MM_UTIL_ERROR_INVALID_OPERATION;
449 _image_info = CloneImageInfo(0);
450 ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path);
454 __mm_util_finalize(_image, _processed_image, _image_info, &exception);
456 MMUTIL_SAFE_FREE(map);
463 int mm_util_rotate_P_B(const char *src_path, mm_util_magick_rotate_type angle, mm_util_color_format_e req_format, mm_util_image_h *dst_handle)
465 int ret = MM_UTIL_ERROR_NONE;
467 Image *_image = NULL;
468 Image *_processed_image = NULL;
469 ImageInfo *_image_info = NULL;
470 ExceptionInfo exception;
471 size_t pixels_size = 0;
474 mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
475 mm_util_retvm_if(!__mm_util_check_angle(angle), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle);
476 mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
478 mm_util_sec_debug("src_path [%s] angle [%d] req_format [%d]", src_path, angle, req_format);
480 ret = __mm_util_get_map(req_format, &map);
481 mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
483 __mm_util_init(&exception);
485 _image = __mm_util_read_image_from_file(src_path, &_image_info);
486 if (_image == NULL) {
487 mm_util_error("Error: __mm_util_read_image_from_file failed.");
488 ret = MM_UTIL_ERROR_INVALID_OPERATION;
492 _processed_image = __mm_util_rotate_image(_image, angle);
493 if (_processed_image == NULL) {
494 mm_util_error("Error: __mm_util_rotate_image failed.");
495 ret = MM_UTIL_ERROR_INVALID_OPERATION;
499 pixels = __mm_util_write_image_to_buffer(_processed_image, _processed_image->columns, _processed_image->rows, map, &pixels_size);
500 if (pixels == NULL) {
501 mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
502 ret = MM_UTIL_ERROR_INVALID_OPERATION;
506 ret = mm_image_create_image(_processed_image->columns, _processed_image->rows, req_format, pixels, pixels_size, dst_handle);
507 if (ret != MM_UTIL_ERROR_NONE)
508 mm_util_error("Error: mm_image_create_image failed.");
514 __mm_util_finalize(_image, _processed_image, _image_info, &exception);
516 MMUTIL_SAFE_FREE(map);
524 int mm_util_rotate_P_P(const char *src_path, mm_util_magick_rotate_type angle, const char *dst_path)
526 int ret = MM_UTIL_ERROR_NONE;
527 Image *_image = NULL;
528 Image *_processed_image = NULL;
529 ImageInfo *_image_info = NULL;
530 ExceptionInfo exception;
532 mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
533 mm_util_retvm_if(!__mm_util_check_angle(angle), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid angle [%d]", angle);
534 mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
536 mm_util_sec_debug("src_path [%s] angle [%d] dst_path [%s]", src_path, angle, dst_path);
538 __mm_util_init(&exception);
540 _image = __mm_util_read_image_from_file(src_path, &_image_info);
541 if (_image == NULL) {
542 mm_util_error("Error: __mm_util_read_image_from_file failed.");
543 ret = MM_UTIL_ERROR_INVALID_OPERATION;
547 _processed_image = __mm_util_rotate_image(_image, angle);
548 if (_processed_image == NULL) {
549 mm_util_error("Error: __mm_util_rotate_image failed.");
550 ret = MM_UTIL_ERROR_INVALID_OPERATION;
554 ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path);
558 __mm_util_finalize(_image, _processed_image, _image_info, &exception);
565 int mm_util_resize_B_B(mm_util_image_h src_handle, unsigned int req_width, unsigned int req_height, mm_util_image_h *dst_handle)
567 int ret = MM_UTIL_ERROR_NONE;
568 mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
570 Image *_image = NULL;
571 Image *_processed_image = NULL;
572 ExceptionInfo exception;
573 size_t pixels_size = 0;
576 mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
577 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);
578 mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
580 mm_util_debug("req_width [%u] req_height [%u]", req_width, req_height);
582 ret = __mm_util_get_map(_src_handle->color, &map);
583 mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
585 __mm_util_init(&exception);
587 _image = __mm_util_constitute_image(src_handle, map);
588 if (_image == NULL) {
589 mm_util_error("Error: __mm_util_constitute_image failed.");
590 ret = MM_UTIL_ERROR_INVALID_OPERATION;
594 if ((_image->columns < req_width) || (_image->rows < req_height)) {
595 mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
596 ret = MM_UTIL_ERROR_INVALID_PARAMETER;
600 _processed_image = __mm_util_resize_image(_image, req_width, req_height);
601 if (_processed_image == NULL) {
602 mm_util_error("Error: __mm_util_resize_image failed.");
603 ret = MM_UTIL_ERROR_INVALID_OPERATION;
607 pixels = __mm_util_write_image_to_buffer(_processed_image, _processed_image->columns, _processed_image->rows, map, &pixels_size);
608 if (pixels == NULL) {
609 mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
610 ret = MM_UTIL_ERROR_INVALID_OPERATION;
614 ret = mm_image_create_image(_processed_image->columns, _processed_image->rows, _src_handle->color, pixels, pixels_size, dst_handle);
615 if (ret != MM_UTIL_ERROR_NONE)
616 mm_util_error("Error: mm_image_create_image failed.");
622 __mm_util_finalize(_image, _processed_image, NULL, &exception);
624 MMUTIL_SAFE_FREE(map);
631 int mm_util_resize_B_P(mm_util_image_h src_handle, unsigned int req_width, unsigned int req_height, const char *dst_path)
633 int ret = MM_UTIL_ERROR_NONE;
634 mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
636 Image *_image = NULL;
637 Image *_processed_image = NULL;
638 ImageInfo *_image_info = NULL;
639 ExceptionInfo exception;
641 mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
642 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);
643 mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
645 mm_util_sec_debug("req_width [%u] req_height [%u] dst_path [%s]", req_width, req_height, dst_path);
647 ret = __mm_util_get_map(_src_handle->color, &map);
648 mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
650 __mm_util_init(&exception);
652 _image = __mm_util_constitute_image(src_handle, map);
653 if (_image == NULL) {
654 mm_util_error("Error: __mm_util_constitute_image failed.");
655 ret = MM_UTIL_ERROR_INVALID_OPERATION;
659 if ((_image->columns < req_width) || (_image->rows < req_height)) {
660 mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
661 ret = MM_UTIL_ERROR_INVALID_PARAMETER;
665 _processed_image = __mm_util_resize_image(_image, req_width, req_height);
666 if (_processed_image == NULL) {
667 mm_util_error("Error: __mm_util_resize_image failed.");
668 ret = MM_UTIL_ERROR_INVALID_OPERATION;
672 _image_info = CloneImageInfo(0);
673 ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path);
677 __mm_util_finalize(_image, _processed_image, _image_info, &exception);
679 MMUTIL_SAFE_FREE(map);
686 int mm_util_resize_P_B(const char *src_path, unsigned int req_width, unsigned int req_height, mm_util_color_format_e req_format, mm_util_image_h *dst_handle)
688 int ret = MM_UTIL_ERROR_NONE;
690 Image *_image = NULL;
691 Image *_processed_image = NULL;
692 ImageInfo *_image_info = NULL;
693 ExceptionInfo exception;
694 size_t pixels_size = 0;
697 mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
698 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);
699 mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
701 mm_util_sec_debug("src_path [%s] req_width [%u] req_height [%u]", src_path, req_width, req_height);
703 ret = __mm_util_get_map(req_format, &map);
704 mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
706 __mm_util_init(&exception);
708 _image = __mm_util_read_image_from_file(src_path, &_image_info);
709 if (_image == NULL) {
710 mm_util_error("Error: __mm_util_read_image_from_file failed.");
711 ret = MM_UTIL_ERROR_INVALID_OPERATION;
715 if ((_image->columns < req_width) || (_image->rows < req_height)) {
716 mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
717 ret = MM_UTIL_ERROR_INVALID_PARAMETER;
721 _processed_image = __mm_util_resize_image(_image, req_width, req_height);
722 if (_processed_image == NULL) {
723 mm_util_error("Error: __mm_util_resize_image failed.");
724 ret = MM_UTIL_ERROR_INVALID_OPERATION;
728 pixels = __mm_util_write_image_to_buffer(_processed_image, _processed_image->columns, _processed_image->rows, map, &pixels_size);
729 if (pixels == NULL) {
730 mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
731 ret = MM_UTIL_ERROR_INVALID_OPERATION;
735 ret = mm_image_create_image(_processed_image->columns, _processed_image->rows, req_format, pixels, pixels_size, dst_handle);
736 if (ret != MM_UTIL_ERROR_NONE)
737 mm_util_error("Error: mm_image_create_image failed.");
743 __mm_util_finalize(_image, _processed_image, _image_info, &exception);
745 MMUTIL_SAFE_FREE(map);
752 int mm_util_resize_P_P(const char *src_path, unsigned int req_width, unsigned int req_height, const char *dst_path)
754 int ret = MM_UTIL_ERROR_NONE;
755 Image *_image = NULL;
756 Image *_processed_image = NULL;
757 ImageInfo *_image_info = NULL;
758 ExceptionInfo exception;
760 mm_util_retvm_if(!MMUTIL_STRING_VALID(src_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_path");
761 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);
762 mm_util_retvm_if(!MMUTIL_STRING_VALID(dst_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_path");
764 mm_util_sec_debug("src_path [%s] req_width [%u] req_height [%u] dst_path [%s]", src_path, req_width, req_height, dst_path);
766 __mm_util_init(&exception);
768 _image = __mm_util_read_image_from_file(src_path, &_image_info);
769 if (_image == NULL) {
770 mm_util_error("Error: __mm_util_read_image_from_file failed.");
771 ret = MM_UTIL_ERROR_INVALID_OPERATION;
775 if ((_image->columns < req_width) || (_image->rows < req_height)) {
776 mm_util_error("Wrong Size. image [%lu * %lu], request [%u * %u]", _image->columns, _image->rows, req_width, req_height);
777 ret = MM_UTIL_ERROR_INVALID_PARAMETER;
781 _processed_image = __mm_util_resize_image(_image, req_width, req_height);
782 if (_processed_image == NULL) {
783 mm_util_error("Error: __mm_util_resize_image failed.");
784 ret = MM_UTIL_ERROR_INVALID_OPERATION;
788 ret = __mm_util_write_image_to_file(_image_info, _processed_image, dst_path);
792 __mm_util_finalize(_image, _processed_image, _image_info, &exception);
799 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)
801 int ret = MM_UTIL_ERROR_NONE;
802 mm_image_info_s *_src_handle = (mm_image_info_s*)src_handle;
804 Image *_image = NULL;
805 ExceptionInfo exception;
806 size_t pixels_size = 0;
809 mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
810 mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
812 mm_util_debug("input format [%d] req_format [%d]", _src_handle->color, req_format);
814 ret = __mm_util_get_map(_src_handle->color, &map);
815 mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
817 __mm_util_init(&exception);
819 _image = __mm_util_constitute_image(src_handle, map);
820 if (_image == NULL) {
821 mm_util_error("Error: __mm_util_constitute_image failed.");
822 ret = MM_UTIL_ERROR_INVALID_OPERATION;
826 MMUTIL_SAFE_FREE(map);
828 ret = __mm_util_get_map(req_format, &map);
829 if (ret != MM_UTIL_ERROR_NONE) {
830 mm_util_error("Error: __mm_util_get_map failed.");
834 pixels = __mm_util_write_image_to_buffer(_image, _image->columns, _image->rows, map, &pixels_size);
835 if (pixels == NULL) {
836 mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
837 ret = MM_UTIL_ERROR_INVALID_OPERATION;
841 ret = mm_image_create_image(_image->columns, _image->rows, _src_handle->color, pixels, pixels_size, dst_handle);
842 if (ret != MM_UTIL_ERROR_NONE)
843 mm_util_error("Error: mm_image_create_image failed.");
849 __mm_util_finalize(_image, NULL, NULL, &exception);
851 MMUTIL_SAFE_FREE(map);