Add new convert API using graphickMagicK mm_util_convert_B_B 13/168213/1
authorhj kim <backto.kim@samsung.com>
Thu, 25 Jan 2018 05:06:52 +0000 (14:06 +0900)
committerhj kim <backto.kim@samsung.com>
Thu, 25 Jan 2018 05:06:52 +0000 (14:06 +0900)
Change-Id: I62fcd62ad171f813d4ef4ec42e88769de451857b

magick/include/mm_util_magick.h
magick/mm_util_magick.c
magick/test/mm_util_magick_testsuite.c
packaging/libmm-utility.spec

index 5000687..be054b3 100755 (executable)
@@ -61,7 +61,6 @@ int mm_util_create_handle(mm_util_image_h *handle, const unsigned char *buffer,
 int mm_util_get_image(mm_util_image_h handle, unsigned char **buffer, unsigned int *width, unsigned int *height, size_t *size, mm_util_magick_format *format);
 int mm_util_destroy_handle(mm_util_image_h handle);
 
-//src path and dst path must be the same format.
 int mm_util_rotate_B_B(mm_util_image_h src_handle, mm_util_magick_rotate_type angle, mm_util_image_h *dst_handle);
 int mm_util_rotate_B_P(mm_util_image_h src_handle, mm_util_magick_rotate_type angle, const char *dst_path);
 int mm_util_rotate_P_B(const char *src_path, mm_util_magick_rotate_type angle, mm_util_magick_format req_format, mm_util_image_h *dst_handle);
@@ -72,4 +71,7 @@ int mm_util_resize_B_P(mm_util_image_h src_handle, unsigned int req_width, unsig
 int mm_util_resize_P_B(const char *src_path, unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format, mm_util_image_h *dst_handle);
 int mm_util_resize_P_P(const char *src_path, unsigned int req_width, unsigned int req_height, const char *dst_path);
 
+int mm_util_convert_B_B(mm_util_image_h src_handle, mm_util_magick_format req_format, mm_util_image_h *dst_handle);
+
+
 #endif /*__MM_UTILITY_MAGICK_H__*/
index 486c4de..dc6fe33 100755 (executable)
@@ -152,6 +152,8 @@ static Image * __mm_util_constitute_image(mm_util_image_h handle, const char *ma
 
        DestroyExceptionInfo(&exception);
 
+       mm_util_fleave();
+
        return _image;
 }
 
@@ -184,6 +186,8 @@ static Image * __mm_util_rotate_image(Image *image, mm_util_magick_rotate_type a
 
        DestroyExceptionInfo(&exception);
 
+       mm_util_fleave();
+
        return _processed_image;
 }
 
@@ -207,6 +211,8 @@ static Image * __mm_util_resize_image(Image *image, unsigned int width, unsigned
 
        DestroyExceptionInfo(&exception);
 
+       mm_util_fleave();
+
        return _processed_image;
 }
 
@@ -240,6 +246,8 @@ static Image * __mm_util_read_image_from_file(const char *path, ImageInfo **imag
 
        DestroyExceptionInfo(&exception);
 
+       mm_util_fleave();
+
        return _image;
 }
 
@@ -268,6 +276,8 @@ static int __mm_util_write_image_to_file(ImageInfo *image_info, Image *image, co
 
        DestroyExceptionInfo(&exception);
 
+       mm_util_fleave();
+
        return ret;
 }
 
@@ -306,6 +316,8 @@ ERROR:
 
        DestroyExceptionInfo(&exception);
 
+       mm_util_fleave();
+
        return pixels;
 }
 
@@ -426,6 +438,8 @@ ERROR:
 
        MMUTIL_SAFE_FREE(map);
 
+       mm_util_fleave();
+
        return ret;
 }
 
@@ -473,6 +487,8 @@ ERROR:
 
        MMUTIL_SAFE_FREE(map);
 
+       mm_util_fleave();
+
        return ret;
 }
 
@@ -531,6 +547,8 @@ ERROR:
 
        MMUTIL_SAFE_FREE(map);
 
+       mm_util_fleave();
+
        return ret;
 }
 
@@ -571,6 +589,8 @@ ERROR:
 
        __mm_util_finalize(_image, _processed_image, _image_info, &exception);
 
+       mm_util_fleave();
+
        return ret;
 }
 
@@ -635,6 +655,8 @@ ERROR:
 
        MMUTIL_SAFE_FREE(map);
 
+       mm_util_fleave();
+
        return ret;
 }
 
@@ -688,6 +710,8 @@ ERROR:
 
        MMUTIL_SAFE_FREE(map);
 
+       mm_util_fleave();
+
        return ret;
 }
 
@@ -752,6 +776,8 @@ ERROR:
 
        MMUTIL_SAFE_FREE(map);
 
+       mm_util_fleave();
+
        return ret;
 }
 
@@ -797,6 +823,66 @@ ERROR:
 
        __mm_util_finalize(_image, _processed_image, _image_info, &exception);
 
+       mm_util_fleave();
+
        return ret;
 }
 
+int mm_util_convert_B_B(mm_util_image_h src_handle, mm_util_magick_format req_format, mm_util_image_h *dst_handle)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       util_image_s *_src_handle = (util_image_s*)src_handle;
+       char *map = NULL;
+       Image *_image = NULL;
+       ExceptionInfo exception;
+       size_t pixels_size = 0;
+       void *pixels = 0;
+
+       mm_util_retvm_if(src_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid handle");
+       mm_util_retvm_if(dst_handle == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid dst_handle");
+
+       mm_util_debug("input format [%d] req_format [%d]", _src_handle->format, req_format);
+
+       ret = __mm_util_get_map(_src_handle->format, &map);
+       mm_util_retvm_if((ret != MM_UTIL_ERROR_NONE) || (map == NULL), ret, "fail to get map");
+
+       __mm_util_init(&exception);
+
+       _image = __mm_util_constitute_image(src_handle, map);
+       if (_image == NULL) {
+               mm_util_error("Error: __mm_util_constitute_image failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       MMUTIL_SAFE_FREE(map);
+
+       ret = __mm_util_get_map(req_format, &map);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               mm_util_error("Error: __mm_util_get_map failed.");
+               goto ERROR;
+       }
+
+       pixels = __mm_util_write_image_to_buffer(_image, _image->columns, _image->rows, map, &pixels_size);
+       if (pixels == NULL) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               ret = MM_UTIL_ERROR_INVALID_OPERATION;
+               goto ERROR;
+       }
+
+       ret = mm_util_create_handle(dst_handle, pixels, _image->columns, _image->rows, pixels_size, _src_handle->format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               mm_util_error("Error: __mm_util_write_image_to_buffer failed.");
+               MagickFree(pixels);
+       }
+
+ERROR:
+
+       __mm_util_finalize(_image, NULL, NULL, &exception);
+
+       MMUTIL_SAFE_FREE(map);
+
+       mm_util_fleave();
+
+       return ret;
+}
index de56704..0171f08 100755 (executable)
@@ -39,6 +39,7 @@ static int _magick_resize_P_P_test(unsigned int req_width, unsigned int req_heig
 static int _magick_resize_P_B_test(unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format);
 static int _magick_resize_B_P_test(unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format);
 static int _magick_resize_B_B_test(unsigned int req_width, unsigned int req_height, mm_util_magick_format req_format);
+static int _magick_convert_B_B_test(mm_util_magick_format in_format, mm_util_magick_format out_format);
 
 static char *__get_dst_path(mm_util_magick_rotate_type angle)
 {
@@ -411,6 +412,54 @@ static int _magick_resize_B_B_test(unsigned int req_width, unsigned int req_heig
        return ret;
 }
 
+static int _magick_convert_B_B_test(mm_util_magick_format in_format, mm_util_magick_format out_format)
+{
+       int ret = MM_UTIL_ERROR_NONE;
+       mm_util_image_h src_handle = NULL;
+       mm_util_image_h dst_handle = NULL;
+       unsigned char *buffer = NULL;
+       unsigned int width = 0;
+       unsigned int height = 0;
+       size_t size = 0;
+       mm_util_magick_format format = MM_UTIL_IMG_FMT_NUM;
+       char dst_path[1024] = {0, };
+       memset(dst_path, 0x00, sizeof(dst_path));
+
+       ret = __get_buffer_for_test(in_format, &buffer, &width, &height, &size, &format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail __get_buffer_for_test [%d]\n", ret);
+               return ret;
+       }
+
+       snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/convert_bb_%d_%d_%d_%d.raw", width, height, in_format, out_format);
+       printf("* Convert B B Test * input_foramt [%d], output_formt [%d] path [%s]\n", in_format, out_format, dst_path);
+
+       ret = mm_util_create_handle(&src_handle, buffer, width, height, size, format);
+       if (ret != MM_UTIL_ERROR_NONE) {
+               printf("Fail mm_util_create_handle [%d]\n", ret);
+               MM_UTIL_SAFE_FREE(buffer);
+               return ret;
+       }
+
+       ret = mm_util_convert_B_B(src_handle, out_format, &dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail mm_util_convert_B_B [%d]\n", ret);
+
+       MM_UTIL_SAFE_FREE(buffer);
+
+       __save_to_file(dst_handle, dst_path);
+
+       ret = mm_util_destroy_handle(src_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail destroy src_handle [%d]\n", ret);
+
+       ret = mm_util_destroy_handle(dst_handle);
+       if (ret != MM_UTIL_ERROR_NONE)
+               printf("Fail destroy dst_handle [%d]\n", ret);
+
+       return ret;
+}
+
 int main(int argc, char *argv[])
 {
        int ret = MM_UTIL_ERROR_NONE;
@@ -481,6 +530,11 @@ int main(int argc, char *argv[])
                ret = _magick_resize_B_B_test(10000, 999, MM_UTIL_IMG_FMT_RGBA8888);
 
        } else if (strcmp(argv[1], "9") == 0) {
+               ret = _magick_convert_B_B_test(MM_UTIL_IMG_FMT_RGB888, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_convert_B_B_test(MM_UTIL_IMG_FMT_ARGB8888, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_convert_B_B_test(MM_UTIL_IMG_FMT_BGRA8888, MM_UTIL_IMG_FMT_RGBA8888);
+               ret = _magick_convert_B_B_test(MM_UTIL_IMG_FMT_RGBA8888, MM_UTIL_IMG_FMT_RGB888);
+               ret = _magick_convert_B_B_test(MM_UTIL_IMG_FMT_BGRA8888, MM_UTIL_IMG_FMT_RGB888);
 
        } else {
                printf("Invalid parameter\n");
index a62db13..ec19684 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-utility
 Summary:    Multimedia Framework Utility Library
-Version:    0.1.5
+Version:    0.1.6
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0