#include <media-util.h>
#include <uuid/uuid.h>
#include <img-codec-parser.h>
-#include <image_util.h>
-#include <image_util_internal.h>
+#include <mm_util_magick.h>
#include "media-util-err.h"
#include "media-svc-util.h"
#include "media-svc-db-utils.h"
return MS_MEDIA_ERR_NONE;
}
-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_resolution(encoder, width, height);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
- image_util_encode_destroy(encoder);
- return MS_MEDIA_ERR_INTERNAL;
- }
- res = image_util_encode_set_colorspace(encoder, colorspace);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
- image_util_encode_destroy(encoder);
- return MS_MEDIA_ERR_INTERNAL;
- }
- res = image_util_encode_set_quality(encoder, quality);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- 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_input_buffer(encoder, src);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- 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, &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);
- return MS_MEDIA_ERR_INTERNAL;
- }
- res = image_util_encode_run(encoder, dst_size);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- media_svc_error("image_util_encode_run failed! (%d)", res);
- 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;
-}
-
-static int __media_svc_decode_jpeg(unsigned char *src, unsigned long long size, image_util_colorspace_e colorspace, unsigned char **dst, unsigned long *width, unsigned long *height, unsigned long long *dst_size)
-{
- int res = IMAGE_UTIL_ERROR_NONE;
- image_util_decode_h decoder = NULL;
- res = image_util_decode_create(&decoder);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- media_svc_error("image_util_decode_create failed! (%d)", res);
- return MS_MEDIA_ERR_INTERNAL;
- }
- res = image_util_decode_set_input_buffer(decoder, src, size);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
- image_util_decode_destroy(decoder);
- return MS_MEDIA_ERR_INTERNAL;
- }
- res = image_util_decode_set_colorspace(decoder, colorspace);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
- image_util_decode_destroy(decoder);
- return MS_MEDIA_ERR_INTERNAL;
- }
- res = image_util_decode_set_output_buffer(decoder, dst);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
- image_util_decode_destroy(decoder);
- return MS_MEDIA_ERR_INTERNAL;
- }
- res = image_util_decode_run(decoder, width, height, dst_size);
- if (res != IMAGE_UTIL_ERROR_NONE) {
- media_svc_error("image_util_decode_run failed! (%d)", res);
- 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;
-}
-
-static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
+static int __media_svc_resize_artwork(const char *path, const char *img_format)
{
int ret = MS_MEDIA_ERR_NONE;
- unsigned char *raw_image = NULL;
- int width = 0;
- int height = 0;
- unsigned long long raw_size = 0;
- void *resized_raw_image = NULL;
- int resized_width = 0;
- int resized_height = 0;
- unsigned int buf_size = 0;
- image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ unsigned int resized_width = 0;
+ unsigned int resized_height = 0;
+ ImgCodecType img_type = IMG_CODEC_NONE;
if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
- media_svc_debug("type [jpeg] size [%d]", size);
- /* decoding */
- ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, &raw_size);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("__media_svc_decode_jpeg failed");
- *resize_image = image;
- *resize_size = size;
- return MS_MEDIA_ERR_NONE;
- }
+ media_svc_debug("type [jpeg]");
- if (raw_image == NULL) {
- media_svc_error("raw_image is null");
- *resize_image = image;
- *resize_size = size;
- return MS_MEDIA_ERR_NONE;
- }
+ ImgGetImageInfo(path, &img_type, &width, &height);
if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
media_svc_debug("No need resizing");
- *resize_image = image;
- *resize_size = size;
- SAFE_FREE(raw_image);
return MS_MEDIA_ERR_NONE;
}
+
/* resizing */
if (width > height) {
resized_height = MEDIA_SVC_ARTWORK_SIZE;
resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
}
- image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
-
- resized_raw_image = malloc(buf_size);
+ ret = mm_util_resize_P_P(path, resized_width, resized_height, path);
- if (resized_raw_image == NULL) {
- media_svc_error("malloc failed");
- *resize_image = image;
- *resize_size = size;
- SAFE_FREE(raw_image);
- return MS_MEDIA_ERR_NONE;
- }
-
- memset(resized_raw_image, 0, buf_size);
-
- ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("image_util_resize failed");
- *resize_image = image;
- *resize_size = size;
- SAFE_FREE(raw_image);
- SAFE_FREE(resized_raw_image);
- return MS_MEDIA_ERR_NONE;
- }
- SAFE_FREE(raw_image);
-
- /* encoding */
- 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;
- *resize_size = size;
- SAFE_FREE(resized_raw_image);
- return MS_MEDIA_ERR_NONE;
- }
- SAFE_FREE(resized_raw_image);
-
- if (*resize_image == NULL) {
- media_svc_error("*resize_image is null");
- *resize_image = image;
- *resize_size = size;
- return MS_MEDIA_ERR_NONE;
- }
} else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
- media_svc_debug("type [png] size [%d]", size);
- *resize_image = image;
- *resize_size = size;
-
+ media_svc_debug("type [png]");
} else {
media_svc_debug("Not proper img format");
- *resize_image = image;
- *resize_size = size;
}
return ret;
int album_id = 0;
int ret = MS_MEDIA_ERR_NONE;
int cdis_value = 0;
- unsigned int resize_size = 0;
- unsigned char *resize_image = NULL;
/*Get Content Tag attribute ===========*/
mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
} else {
/*media_svc_debug("artwork size2 [%d]", size); */
}
+
if (image != NULL && size > 0) {
char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
int artwork_mime_size = -1;
ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
if (ret != MS_MEDIA_ERR_NONE)
media_svc_error("Fail to Get Thumbnail Path");
- /* albumart resizing */
- __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
+
+ if (strlen(thumb_path) > 0) {
+ ret = __media_svc_save_image(image, size, thumb_path, uid);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to Save Image");
+ } else {
+ /* albumart resizing */
+ ret = __media_svc_resize_artwork(thumb_path, p);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to Make Thumbnail Image");
+ _media_svc_remove_file(thumb_path);
+
+ } else {
+ content_info->thumbnail_path = g_strdup(thumb_path);
+ }
+ }
+ }
} else {
SAFE_FREE(err_attr_name);
}
-
- if (strlen(thumb_path) > 0) {
- ret = __media_svc_save_image(resize_image, resize_size, thumb_path, uid);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("Fail to Save Thumbnail Image");
- else
- content_info->thumbnail_path = g_strdup(thumb_path);
- }
-
- if (size != resize_size) {
- media_svc_error("Albumart is resized");
- SAFE_FREE(resize_image);
- }
}
}