Remove image-util dependency 04/134504/5
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 19 Jun 2017 03:55:54 +0000 (12:55 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 19 Jun 2017 04:31:25 +0000 (13:31 +0900)
Remove image-util dependency when create agif thumbnail

Change-Id: Ie6a96e8b5132e4b6be0e86b7cf23e4c29aba65c1
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/libmedia-thumbnail.spec
src/media-thumb-internal.c
test/test-thumb.c

index 3465e78..060b3e3 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmedia-thumbnail
 Summary:    Media thumbnail service library for multimedia applications
-Version: 0.2.8
+Version: 0.2.9
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0 and PD
index 540ea0b..9debe27 100755 (executable)
 
 #define MEDIA_THUMB_ROUND_UP_8(num) (((num)+7)&~7)
 
-int _media_thumb_resize_data(unsigned char *src_data,
-                                                       int src_width,
-                                                       int src_height,
-                                                       mm_util_img_format src_format,
-                                                       media_thumb_info *thumb_info,
-                                                       int dst_width,
-                                                       int dst_height);
-
-int _media_thumb_convert_video(const unsigned char *src_data, const int src_size,
+int _media_thumb_rgb_to_argb(const unsigned char *src_data, const int src_size,
                                                        unsigned char **dst_data,
                                                        unsigned int *buf_size,
                                                        int width,
@@ -84,14 +76,12 @@ int _media_thumb_convert_video(const unsigned char *src_data, const int src_size
                (*dst_data)[i++] = 0x0;
        }
 
-       thumb_dbg("_media_thumb_convert_video success");
+       thumb_dbg("_media_thumb_rgb_to_argb success");
 
        return err;
 }
 
-int _media_thumb_resize_video_with_evas(const void *image,
-                                       int thumb_width, int thumb_height,
-                                       media_thumb_info *thumb_info)
+int _media_thumb_resize_with_evas(const void *image, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
 {
        Ecore_Evas *resize_img_ee;
 
@@ -202,7 +192,7 @@ int _media_thumb_resize_video_with_evas(const void *image,
        ecore_evas_free(target_ee);
        ecore_evas_free(resize_img_ee);
 
-       thumb_dbg("_media_thumb_resize_video_with_evas success");
+       thumb_dbg("_media_thumb_resize_with_evas success");
 
        return MS_MEDIA_ERR_NONE;
 }
@@ -578,59 +568,6 @@ int _media_thumb_get_thumb_from_exif(ExifData *ed,
        return err;
 }
 
-int _media_thumb_resize_data(unsigned char *src_data,
-                                                       int src_width,
-                                                       int src_height,
-                                                       mm_util_img_format src_format,
-                                                       media_thumb_info *thumb_info,
-                                                       int dst_width,
-                                                       int dst_height)
-{
-       int thumb_width = dst_width;
-       int thumb_height = dst_height;
-       unsigned int buf_size = 0;
-
-       if (mm_util_get_image_size(src_format, thumb_width, thumb_height, &buf_size) < 0) {
-               thumb_err("Failed to get buffer size");
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       thumb_dbg("mm_util_get_image_size : %d", buf_size);
-
-       unsigned char *dst = (unsigned char *)malloc(buf_size);
-
-       if (dst == NULL) {
-               thumb_err("malloc fails");
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
-
-       if (mm_util_resize_image((unsigned char *)src_data, src_width,
-                       src_height, src_format,
-                       dst, (unsigned int *)&thumb_width,
-                       (unsigned int *)&thumb_height) < 0) {
-               thumb_err("Failed to resize the thumbnails");
-
-               SAFE_FREE(dst);
-
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       thumb_info->size = buf_size;
-       thumb_info->width = thumb_width;
-       thumb_info->height = thumb_height;
-       thumb_info->data = malloc(buf_size);
-       if (thumb_info->data != NULL) {
-               memcpy(thumb_info->data, dst, buf_size);
-       } else {
-               thumb_err("malloc fails");
-               SAFE_FREE(dst);
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
-       SAFE_FREE(dst);
-
-       return MS_MEDIA_ERR_NONE;
-}
-
 int _media_thumb_get_wh_with_evas(const char *origin_path, int *width, int *height)
 {
        /* using evas to get w/h */
@@ -841,22 +778,29 @@ int _media_thumb_convert_data(media_thumb_info *thumb_info, int thumb_width, int
 }
 
 int _media_thumb_agif(const char *origin_path,
-                                       int image_width,
-                                       int image_height,
                                        int thumb_width,
                                        int thumb_height,
                                        media_thumb_info *thumb_info)
 {
        int err = MS_MEDIA_ERR_NONE;
        unsigned int *thumb = NULL;
+       unsigned char *dst_image = NULL;
+       unsigned int dst_size = 0;
+       unsigned int thumb_size = 0;
 
-       thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_width, image_height);
-
+       thumb = ImgGetFirstFrameAGIFAtSize(origin_path, thumb_info->origin_width, thumb_info->origin_height);
        if (!thumb) {
                thumb_err("Frame data is NULL!!");
                return MS_MEDIA_ERR_INTERNAL;
        }
 
+       err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, thumb_info->origin_width, thumb_info->origin_height, &thumb_size);
+       if (err != MS_MEDIA_ERR_NONE) {
+               thumb_err("mm_util_get_image_size failed: %d", err);
+               SAFE_FREE(thumb);
+               return err;
+       }
+
        err = _media_thumb_get_proper_thumb_size(thumb_info->origin_width, thumb_info->origin_height, &thumb_width, &thumb_height);
        if (err != MS_MEDIA_ERR_NONE) {
                thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
@@ -864,29 +808,23 @@ int _media_thumb_agif(const char *origin_path,
                return err;
        }
 
-       err = _media_thumb_resize_data((unsigned char *)thumb,
-                                                                       image_width,
-                                                                       image_height,
-                                                                       MM_UTIL_IMG_FMT_RGB888,
-                                                                       thumb_info,
-                                                                       thumb_width,
-                                                                       thumb_height);
-
+       err = _media_thumb_rgb_to_argb((unsigned char *) thumb, thumb_size, &dst_image, &dst_size, thumb_info->origin_width, thumb_info->origin_height);
        if (err != MS_MEDIA_ERR_NONE) {
-               thumb_err("_media_thumb_resize_data failed: %d", err);
+               thumb_err("_media_thumb_convert_data falied: %d", err);
                SAFE_FREE(thumb);
                return err;
        }
 
-       SAFE_FREE(thumb);
-
-       err = _media_thumb_convert_data(thumb_info, thumb_info->width, thumb_info->height);
+       err = _media_thumb_resize_with_evas(dst_image, thumb_width, thumb_height, thumb_info);
        if (err != MS_MEDIA_ERR_NONE) {
-               thumb_err("_media_thumb_convert_data falied: %d", err);
+               thumb_err("_media_thumb_resize_data failed: %d", err);
                SAFE_FREE(thumb_info->data);
+               SAFE_FREE(thumb);
                return err;
        }
 
+       SAFE_FREE(thumb);
+
        return err;
 }
 
@@ -1056,7 +994,7 @@ int _media_thumb_image(const char *origin_path,
        }
 
        if (image_type == IMG_CODEC_AGIF) {
-               err = _media_thumb_agif(origin_path, origin_w, origin_h, thumb_width, thumb_height, thumb_info);
+               err = _media_thumb_agif(origin_path, thumb_width, thumb_height, thumb_info);
        } else if (image_type == IMG_CODEC_JPEG) {
                err = _media_thumb_jpeg(origin_path, thumb_path, thumb_width, thumb_height, thumb_info);
        } else if (image_type == IMG_CODEC_PNG) {
@@ -1224,7 +1162,7 @@ int _media_thumb_video(const char *origin_path,
 
                unsigned int new_size = 0;
                unsigned char *new_frame = NULL;
-               err = _media_thumb_convert_video(frame, size, &new_frame, &new_size, width, height);
+               err = _media_thumb_rgb_to_argb(frame, size, &new_frame, &new_size, width, height);
                if ((err != MS_MEDIA_ERR_NONE) || (new_frame == NULL)) {
                        thumb_err("_media_thumb_convert_video falied: %d", err);
                        mm_file_destroy_content_attrs(content);
@@ -1235,7 +1173,7 @@ int _media_thumb_video(const char *origin_path,
                thumb_dbg("original size - width:%d, height:%d", width, height);
                thumb_dbg("proper thumb size - width:%d, height:%d", thumb_width, thumb_height);
                if (width > thumb_width || height > thumb_height) {
-                       err = _media_thumb_resize_video_with_evas(new_frame, thumb_width, thumb_height, thumb_info);
+                       err = _media_thumb_resize_with_evas(new_frame, thumb_width, thumb_height, thumb_info);
                        if (err != MS_MEDIA_ERR_NONE) {
                                thumb_err("_media_thumb_resize_video_with_evas falied: %d", err);
                                SAFE_FREE(new_frame);
index 6ab7657..4c4a3ff 100755 (executable)
@@ -25,8 +25,6 @@
 #include <pthread.h>
 #include <Evas.h>
 #include <Ecore_Evas.h>
-#include <mm_util_imgp.h>
-#include <mm_util_jpeg.h>
 
 #include "media-thumbnail.h"
 #include "thumb-server-internal.h"
@@ -57,40 +55,23 @@ int save_to_file_with_evas(unsigned char *data, int w, int h, int is_bgra)
        evas_object_image_fill_set(img, 0, 0, w, h);
 
        if (!is_bgra) {
-       unsigned char *m = NULL;
-       m = evas_object_image_data_get(img, 1);
-#if 1                          /* Use self-logic to convert from RGB888 to RGBA */
-       int i = 0, j;
-       for (j = 0; j < w * 3 * h;
-               j += 3) {
-               m[i++] = (data[j + 2]);
-               m[i++] = (data[j + 1]);
-               m[i++] = (data[j]);
-               m[i++] = 0x0;
-       }
-
-#else                          /* Use mmf api to convert from RGB888 to RGBA */
-       int mm_ret = 0;
-       if ((mm_ret =
-               mm_util_convert_colorspace(data,
-                                       w,
-                                       h,
-                                       MM_UTIL_IMG_FMT_RGB888,
-                                       m,
-                                       MM_UTIL_IMG_FMT_BGRA8888))
-               < 0) {
-               printf
-                       ("Failed to change from rgb888 to argb8888 %d\n",
-                       mm_ret);
-               return -1;
-       }
-#endif                         /* End of use mmf api to convert from RGB888 to RGBA */
+               unsigned char *m = NULL;
+               m = evas_object_image_data_get(img, 1);
+               /* Use self-logic to convert from RGB888 to RGBA */
+               int i = 0, j;
+               for (j = 0; j < w * 3 * h;
+                       j += 3) {
+                       m[i++] = (data[j + 2]);
+                       m[i++] = (data[j + 1]);
+                       m[i++] = (data[j]);
+                       m[i++] = 0x0;
+               }
 
-       evas_object_image_data_set(img, m);
-       evas_object_image_data_update_add(img, 0, 0, w, h);
+               evas_object_image_data_set(img, m);
+               evas_object_image_data_update_add(img, 0, 0, w, h);
        } else {
-       evas_object_image_data_set(img, data);
-       evas_object_image_data_update_add(img, 0, 0, w, h);
+               evas_object_image_data_set(img, data);
+               evas_object_image_data_update_add(img, 0, 0, w, h);
        }
 
        if (evas_object_image_save
@@ -163,9 +144,7 @@ int main(int argc, char *argv[])
                //long end = thumb_get_debug_time();
                //printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));
 #endif
-       } else if (origin_path && mode == 4) {
-               printf("Success!!\n");
-       } else if (mode == 6) {
+       } else if (mode == 2) {
                printf("Test thumbnail_request_cancel_media\n");
 
                err = thumbnail_request_cancel_media(req_id, origin_path);
@@ -175,7 +154,7 @@ int main(int argc, char *argv[])
                } else {
                        printf("thumbnail_request_cancel_media success!\n");
                }
-       } else if (mode == 7) {
+       } else if (mode == 3) {
                printf("Test thumbnail_request_cancel_all\n");
 
                err = thumbnail_request_cancel_all(true);