Fix that artwork did not resize 00/84200/2
authorJiyong Min <jiyong.min@samsung.com>
Wed, 17 Aug 2016 08:50:32 +0000 (17:50 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Wed, 17 Aug 2016 08:54:02 +0000 (17:54 +0900)
Change-Id: I9351c627577b0a6d5be2d4d96a9ac50225e15ead
Signed-off-by: jiyong min <jiyong.min@samsung.com>
src/common/media-svc-util.c

index a1da9fc..428af4e 100755 (executable)
@@ -33,7 +33,6 @@
 #include <sys/vfs.h>
 #include <glib/gstdio.h>
 #include <sys/stat.h>
-#include <string.h>
 #include <dirent.h>
 #include <ctype.h>
 #include <aul/aul.h>
@@ -629,14 +628,15 @@ static char *__media_svc_get_thumb_path(uid_t uid)
 static int __media_svc_encode_jpeg(unsigned char *src, unsigned long width, unsigned long height, image_util_colorspace_e colorspace, int quality, unsigned char **dst, unsigned long long *dst_size) {
        int res = IMAGE_UTIL_ERROR_NONE;
        image_util_encode_h encoder = NULL;
+       unsigned char *encoded_data = NULL;
        res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
        if (res != IMAGE_UTIL_ERROR_NONE) {
                media_svc_error("image_util_encode_create failed! (%d)", res);
                return MS_MEDIA_ERR_INTERNAL;
        }
-       res = image_util_encode_set_input_buffer(encoder, src);
+       res = image_util_encode_set_resolution(encoder, width, height);
        if (res != IMAGE_UTIL_ERROR_NONE) {
-               media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
+               media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
                image_util_encode_destroy(encoder);
                return MS_MEDIA_ERR_INTERNAL;
        }
@@ -646,19 +646,19 @@ static int __media_svc_encode_jpeg(unsigned char *src, unsigned long width, unsi
                image_util_encode_destroy(encoder);
                return MS_MEDIA_ERR_INTERNAL;
        }
-       res = image_util_encode_set_resolution(encoder, width, height);
+       res = image_util_encode_set_quality(encoder, quality);
        if (res != IMAGE_UTIL_ERROR_NONE) {
-               media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
+               media_svc_error("image_util_encode_set_quality failed! (%d)", res);
                image_util_encode_destroy(encoder);
                return MS_MEDIA_ERR_INTERNAL;
        }
-       res = image_util_encode_set_quality(encoder, quality);
+       res = image_util_encode_set_input_buffer(encoder, src);
        if (res != IMAGE_UTIL_ERROR_NONE) {
-               media_svc_error("image_util_encode_set_quality failed! (%d)", res);
+               media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
                image_util_encode_destroy(encoder);
                return MS_MEDIA_ERR_INTERNAL;
        }
-       res = image_util_encode_set_output_buffer(encoder, dst);
+       res = image_util_encode_set_output_buffer(encoder, &encoded_data);
        if (res != IMAGE_UTIL_ERROR_NONE) {
                media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
                image_util_encode_destroy(encoder);
@@ -670,12 +670,21 @@ static int __media_svc_encode_jpeg(unsigned char *src, unsigned long width, unsi
                image_util_encode_destroy(encoder);
                return MS_MEDIA_ERR_INTERNAL;
        }
+       if (encoded_data != NULL) {
+               *dst = (unsigned char *)calloc(1, *dst_size);
+               if (*dst == NULL) {
+                       media_svc_error("memory allocation failed! (%lld)", *dst_size);
+                       image_util_encode_destroy(encoder);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
+               memcpy(*dst, encoded_data, *dst_size);
+       }
        res = image_util_encode_destroy(encoder);
        if (res != IMAGE_UTIL_ERROR_NONE) {
                media_svc_error("image_util_encode_destroy failed! (%d)", res);
                return MS_MEDIA_ERR_INTERNAL;
        }
-
+       SAFE_FREE(encoded_data);
        return MS_MEDIA_ERR_NONE;
 }
 
@@ -711,12 +720,12 @@ static int __media_svc_decode_jpeg(unsigned char *src, unsigned long long size,
                image_util_decode_destroy(decoder);
                return MS_MEDIA_ERR_INTERNAL;
        }
+
        res = image_util_decode_destroy(decoder);
        if (res != IMAGE_UTIL_ERROR_NONE) {
                media_svc_error("image_util_decode_destroy failed! (%d)", res);
                return MS_MEDIA_ERR_INTERNAL;
        }
-
        return MS_MEDIA_ERR_NONE;
 }
 
@@ -793,7 +802,7 @@ static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, c
                SAFE_FREE(raw_image);
 
                /* encoding */
-               ret = __media_svc_encode_jpeg(resized_raw_image, (unsigned long)resized_width, (unsigned long)resized_height, colorspace, 90, resize_image, (unsigned long long *)resize_size);
+               ret = __media_svc_encode_jpeg((unsigned char *)resized_raw_image, (unsigned long)resized_width, (unsigned long)resized_height, colorspace, 90, resize_image, (unsigned long long *)resize_size);
                if (ret != MS_MEDIA_ERR_NONE) {
                        media_svc_error("__media_svc_encode_jpeg failed");
                        *resize_image = image;