4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@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.
22 #include "media-thumb-debug.h"
23 #include "media-thumb-util.h"
24 #include "media-thumb-internal.h"
26 #include "AGifFrameInfo.h"
27 #include "IfegDecodeAGIF.h"
28 #include "img-codec.h"
29 #include "img-codec-agif.h"
30 #include "img-codec-common.h"
31 #include "img-codec-osal.h"
32 #include "img-codec-parser.h"
34 #include <sys/types.h>
39 //#include <drm-service.h>
40 #include <drm_client.h>
43 #include <mm_util_imgp.h>
44 #include <mm_util_jpeg.h>
46 #include <Ecore_Evas.h>
47 #include <libexif/exif-data.h>
49 #define MEDA_THUMB_ROUND_UP_4(num) (((num)+3)&~3)
51 int _media_thumb_get_proper_thumb_size(media_thumb_type thumb_type,
52 int orig_w, int orig_h,
53 int *thumb_w, int *thumb_h)
55 thumb_dbg("orig w: %d orig h: %d thumb type: %d", orig_w, orig_h, thumb_type);
57 BOOL portrait = FALSE;
60 if (orig_w < orig_h) {
65 /* Set Lager length to default size */
67 if (orig_h < _media_thumb_get_width(thumb_type)) {
70 *thumb_h = _media_thumb_get_width(thumb_type);
73 ratio = (double)orig_w / (double)orig_h;
74 *thumb_w = *thumb_h * ratio;
76 if (orig_w < _media_thumb_get_width(thumb_type)) {
79 *thumb_w = _media_thumb_get_width(thumb_type);
82 ratio = (double)orig_h / (double)orig_w;
83 *thumb_h = *thumb_w * ratio;
86 /* Set smaller length to default size */
88 if (orig_w < _media_thumb_get_width(thumb_type)) {
91 *thumb_w = _media_thumb_get_width(thumb_type);
94 ratio = (double)orig_h / (double)orig_w;
95 *thumb_h = *thumb_w * ratio;
99 if (orig_h < _media_thumb_get_width(thumb_type)) {
102 *thumb_h = _media_thumb_get_width(thumb_type);
105 ratio = (double)orig_w / (double)orig_h;
106 *thumb_w = *thumb_h * ratio;
110 /* The width of RGB888 raw data has to be rounded by 4 */
111 *thumb_w = MEDA_THUMB_ROUND_UP_4(*thumb_w);
113 thumb_dbg("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
118 int _media_thumb_get_exif_info(ExifData *ed, char *buf, int max_size, int *value,
119 int ifdtype, long tagtype)
132 entry = exif_content_get_entry(ed->ifd[ifd], tag);
134 if (tag == EXIF_TAG_ORIENTATION ||
135 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
136 tag == EXIF_TAG_PIXEL_Y_DIMENSION) {
139 thumb_dbg("value is NULL");
143 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
144 short exif_value = exif_get_short(entry->data, mByteOrder);
145 thumb_dbg("%s : %d", exif_tag_get_name_in_ifd(tag,ifd), exif_value);
146 *value = (int)exif_value;
148 /* Get the contents of the tag in human-readable form */
150 thumb_dbg("buf is NULL");
153 exif_entry_get_value(entry, buf, max_size);
154 buf[strlen(buf)] = '\0';
157 thumb_dbg("%s: %s\n",
158 exif_tag_get_name_in_ifd(tag, ifd), buf);
167 _media_thumb_get_thumb_from_exif(ExifData *ed,
168 const char *file_full_path,
172 media_thumb_info *thumb_info, uid_t uid)
181 int thumb_height = 0;
188 ExifByteOrder byte_order = exif_data_get_byte_order(ed);
191 tag = EXIF_TAG_COMPRESSION;
193 entry = exif_content_get_entry(ed->ifd[ifd], tag);
196 /* Get the contents of the tag in human-readable form */
197 ExifShort value = exif_get_short(entry->data, byte_order);
198 //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
201 thumb_dbg("There's jpeg thumb in this image");
203 thumb_dbg("There's NO jpeg thumb in this image");
207 thumb_dbg("entry is NULL");
211 /* Get width and height of thumbnail */
212 tag = EXIF_TAG_IMAGE_WIDTH;
214 entry = exif_content_get_entry(ed->ifd[ifd], tag);
217 /* Get the contents of the tag in human-readable form */
218 ExifShort value = exif_get_short(entry->data, byte_order);
219 //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
224 tag = EXIF_TAG_IMAGE_LENGTH;
226 entry = exif_content_get_entry(ed->ifd[ifd], tag);
229 /* Get the contents of the tag in human-readable form */
230 ExifShort value = exif_get_short(entry->data, byte_order);
231 //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
233 thumb_height = value;
236 if (ed->data && ed->size) {
237 //thumb_dbg("Size: %d, thumb: 0x%x\n", ed->size, ed->data);
238 thumb = (char *)malloc(ed->size);
241 thumb_dbg("malloc failed!");
245 memcpy(thumb, (void *)ed->data, ed->size);
248 thumb_dbg("data is NULL");
252 /* Get width and height of original image from exif */
254 tag = EXIF_TAG_PIXEL_X_DIMENSION;
255 entry = exif_content_get_entry(ed->ifd[ifd], tag);
258 ExifShort value = exif_get_short(entry->data, byte_order);
259 //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
260 thumb_info->origin_width = value;
262 thumb_dbg("entry is NULL");
265 tag = EXIF_TAG_PIXEL_Y_DIMENSION;
266 entry = exif_content_get_entry(ed->ifd[ifd], tag);
269 ExifShort value = exif_get_short(entry->data, byte_order);
270 //thumb_dbg("%s: %d\n", exif_tag_get_name_in_ifd(tag,ifd), value);
271 thumb_info->origin_height = value;
273 thumb_dbg("entry is NULL");
276 char thumb_path[1024];
279 _media_thumb_get_hash_name(file_full_path,
281 sizeof(thumb_path), uid);
283 thumb_dbg("_media_thumb_get_hash_name failed\n");
288 thumb_dbg("Thumb is :%s", thumb_path);
291 int fd = open(thumb_path, O_RDWR | O_CREAT | O_EXCL | O_SYNC, 0644);
293 if (errno == EEXIST) {
294 thumb_dbg("thumb alread exist!");
296 thumb_dbg("open failed\n");
301 nwrite = write(fd, thumb, size);
303 thumb_dbg("write failed\n");
314 mm_util_jpeg_yuv_data decoded = {0,};
316 err = mm_util_decode_from_jpeg_file(&decoded, thumb_path, MM_UTIL_JPEG_FMT_RGB888);
318 thumb_dbg("mm_util_decode_from_jpeg_turbo_memory failed : %d", err);
322 //thumb_dbg("size:%d, w:%d, h:%d\n", decoded.size, decoded.width, decoded.height);
324 thumb_width = decoded.width;
325 thumb_height = decoded.height;
327 media_thumb_type thumb_type;
329 unsigned int buf_size = decoded.size;
331 if (required_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
332 thumb_type = MEDIA_THUMB_LARGE;
334 thumb_type = MEDIA_THUMB_SMALL;
337 if (thumb_type == MEDIA_THUMB_LARGE) {
338 if (thumb_width < _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
339 thumb_dbg("Thumb data in exif is too small for MEDIA_THUMB_LARGE");
340 SAFE_FREE(decoded.data);
344 if (thumb_width > _media_thumb_get_width(MEDIA_THUMB_SMALL)) {
349 if (need_resize == 1) {
350 int resized_w = _media_thumb_get_width(MEDIA_THUMB_LARGE);
351 int resized_h = _media_thumb_get_height(MEDIA_THUMB_LARGE);
353 err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, resized_w, resized_h, &buf_size);
355 thumb_dbg("mm_util_get_image_size failed : %d", err);
357 SAFE_FREE(decoded.data);
361 //thumb_dbg("size(RGB888) : %d", buf_size);
363 unsigned char *dst = (unsigned char *)malloc(buf_size);
365 thumb_err("Failed to allocate memory!");
366 SAFE_FREE(decoded.data);
370 if (mm_util_resize_image(decoded.data, thumb_width,
371 thumb_height, MM_UTIL_IMG_FMT_RGB888,
372 dst, (unsigned int *)&resized_w,
373 (unsigned int *)&resized_h) < 0) {
374 thumb_err("Failed to resize the thumbnails");
376 SAFE_FREE(decoded.data);
382 SAFE_FREE(decoded.data);
384 decoded.width = thumb_width = resized_w;
385 decoded.height = thumb_height = resized_h;
388 if (orientation == ROT_90 || orientation == ROT_180 || orientation == ROT_270) {
389 /* Start to decode to rotate */
390 unsigned char *rotated = NULL;
391 unsigned int r_w = decoded.height;
392 unsigned int r_h = decoded.width;
393 unsigned int r_size = 0;
394 mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
396 if (orientation == ROT_90) {
397 rot_type = MM_UTIL_ROTATE_90;
398 } else if (orientation == ROT_180) {
399 rot_type = MM_UTIL_ROTATE_180;
401 r_h = decoded.height;
402 } else if (orientation == ROT_270) {
403 rot_type = MM_UTIL_ROTATE_270;
406 err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, r_w, r_h, &r_size);
408 thumb_dbg("mm_util_get_image_size failed : %d", err);
409 SAFE_FREE(decoded.data);
413 //thumb_dbg("Size of Rotated : %d", r_size);
415 rotated = (unsigned char *)malloc(r_size);
416 err = mm_util_rotate_image(decoded.data, decoded.width, decoded.height,
417 MM_UTIL_IMG_FMT_RGB888,
422 thumb_err("mm_util_rotate_image failed : %d", err);
423 SAFE_FREE(decoded.data);
427 thumb_dbg("mm_util_rotate_image succeed");
430 SAFE_FREE(decoded.data);
432 //thumb_dbg("Width : %d, Height : %d", r_w, r_h);
433 thumb_info->data = rotated;
434 thumb_info->size = r_size;
435 thumb_info->width = r_w;
436 thumb_info->height = r_h;
437 } else if (orientation == NORMAL) {
438 thumb_info->data = decoded.data;
439 thumb_info->size = buf_size;
440 thumb_info->width = thumb_width;
441 thumb_info->height = thumb_height;
443 thumb_warn("Unknown orientation");
444 SAFE_FREE(decoded.data);
451 int _media_thumb_resize_data(unsigned char *src_data,
454 mm_util_img_format src_format,
455 media_thumb_info *thumb_info,
459 int thumb_width = dst_width;
460 int thumb_height = dst_height;
461 unsigned int buf_size = 0;
463 if (mm_util_get_image_size(src_format, thumb_width,
464 thumb_height, &buf_size) < 0) {
465 thumb_err("Failed to get buffer size");
466 return MEDIA_THUMB_ERROR_MM_UTIL;
469 thumb_dbg("mm_util_get_image_size : %d", buf_size);
471 unsigned char *dst = (unsigned char *)malloc(buf_size);
473 if (mm_util_resize_image((unsigned char *)src_data, src_width,
474 src_height, src_format,
475 dst, (unsigned int *)&thumb_width,
476 (unsigned int *)&thumb_height) < 0) {
477 thumb_err("Failed to resize the thumbnails");
481 return MEDIA_THUMB_ERROR_MM_UTIL;
484 thumb_info->size = buf_size;
485 thumb_info->width = thumb_width;
486 thumb_info->height = thumb_height;
487 thumb_info->data = malloc(buf_size);
488 memcpy(thumb_info->data, dst, buf_size);
495 int _media_thumb_get_wh_with_evas(const char *origin_path, int *width, int *height)
497 /* using evas to get w/h */
499 ecore_evas_buffer_new(0, 0);
501 thumb_err("ecore_evas_new fails");
504 Evas *evas = ecore_evas_get(ee);
506 thumb_err("ecore_evas_get fails");
511 Evas_Object *image_object =
512 evas_object_image_add(evas);
515 ("evas_object_image_add fails");
520 evas_object_image_file_set(image_object,
523 evas_object_image_size_get(image_object,
526 thumb_dbg("Width:%d, Height:%d", *width, *height);
533 int _media_thumb_decode_with_evas(const char *origin_path,
534 int thumb_width, int thumb_height,
535 media_thumb_info *thumb_info, int need_scale, int orientation)
537 Ecore_Evas *resize_img_ee;
539 ecore_evas_buffer_new(thumb_width, thumb_height);
541 if (!resize_img_ee) {
542 thumb_err("Failed to create a new ecore evas buffer\n");
546 Evas *resize_img_e = ecore_evas_get(resize_img_ee);
548 thumb_err("Failed to ecore_evas_get\n");
549 ecore_evas_free(resize_img_ee);
553 Evas_Object *source_img = evas_object_image_add(resize_img_e);
555 thumb_err("evas_object_image_add failed\n");
556 ecore_evas_free(resize_img_ee);
560 evas_object_image_file_set(source_img, origin_path, NULL);
562 /* Get w/h of original image */
566 evas_object_image_size_get(source_img, &width, &height);
567 thumb_info->origin_width = width;
568 thumb_info->origin_height = height;
569 //thumb_dbg("origin width:%d, origin height:%d", width, height);
571 if ((need_scale == 1) && (width * height > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) {
572 thumb_dbg("This is too large image. so this's scale is going to be down");
573 evas_object_image_load_scale_down_set(source_img, 10);
576 evas_object_image_load_orientation_set(source_img, 1);
578 int rotated_orig_w = 0;
579 int rotated_orig_h = 0;
581 if (orientation == ROT_90 || orientation == ROT_270) {
582 rotated_orig_w = height;
583 rotated_orig_h = width;
585 rotated_orig_w = width;
586 rotated_orig_h = height;
589 //thumb_dbg("rotated - origin width:%d, origin height:%d", rotated_orig_w, rotated_orig_h);
592 media_thumb_type thumb_type;
594 if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
595 thumb_type = MEDIA_THUMB_LARGE;
597 thumb_type = MEDIA_THUMB_SMALL;
600 err = _media_thumb_get_proper_thumb_size(thumb_type,
601 rotated_orig_w, rotated_orig_h,
602 &thumb_width, &thumb_height);
604 thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
605 ecore_evas_free(resize_img_ee);
609 ecore_evas_resize(resize_img_ee, thumb_width, thumb_height);
611 evas_object_image_load_size_set(source_img, thumb_width, thumb_height);
612 evas_object_image_fill_set(source_img,
617 evas_object_image_filled_set(source_img, 1);
618 evas_object_resize(source_img,
621 evas_object_show(source_img);
623 /* Set alpha from original */
624 thumb_info->alpha = evas_object_image_alpha_get(source_img);
626 /* Create target buffer and copy origin resized img to it */
627 Ecore_Evas *target_ee = ecore_evas_buffer_new(
628 thumb_width, thumb_height);
630 thumb_err("Failed to create a ecore evas\n");
631 ecore_evas_free(resize_img_ee);
635 Evas *target_evas = ecore_evas_get(target_ee);
637 thumb_err("Failed to ecore_evas_get\n");
638 ecore_evas_free(resize_img_ee);
639 ecore_evas_free(target_ee);
643 Evas_Object *ret_image =
644 evas_object_image_add(target_evas);
646 evas_object_image_size_set(ret_image,
650 evas_object_image_fill_set(ret_image, 0,
655 evas_object_image_filled_set(ret_image, EINA_TRUE);
656 evas_object_image_data_set(ret_image,
657 (int *)ecore_evas_buffer_pixels_get(resize_img_ee));
658 evas_object_image_data_update_add(ret_image, 0, 0, thumb_width,
661 unsigned int buf_size = 0;
663 if (mm_util_get_image_size(MM_UTIL_IMG_FMT_BGRA8888, thumb_width,
664 thumb_height, &buf_size) < 0) {
665 thumb_err("Failed to get buffer size");
667 ecore_evas_free(resize_img_ee);
668 ecore_evas_free(target_ee);
670 return MEDIA_THUMB_ERROR_MM_UTIL;
673 //thumb_dbg("mm_util_get_image_size : %d", buf_size);
675 thumb_info->size = buf_size;
676 thumb_info->width = thumb_width;
677 thumb_info->height = thumb_height;
678 thumb_info->data = malloc(buf_size);
679 memcpy(thumb_info->data, evas_object_image_data_get(ret_image, 1), buf_size);
681 ecore_evas_free(target_ee);
682 ecore_evas_free(resize_img_ee);
687 mm_util_img_format _media_thumb_get_format(media_thumb_format src_format)
690 case MEDIA_THUMB_BGRA:
691 return MM_UTIL_IMG_FMT_BGRA8888;
692 case MEDIA_THUMB_RGB888:
693 return MM_UTIL_IMG_FMT_RGB888;
700 int _media_thumb_convert_data(media_thumb_info *thumb_info,
703 mm_util_img_format src_format,
704 mm_util_img_format dst_format)
707 unsigned int buf_size = 0;
708 unsigned char *src_data = thumb_info->data;
709 unsigned char *dst_data = NULL;
711 thumb_dbg("src format:%d, dst format:%d", src_format, dst_format);
713 if (mm_util_get_image_size(dst_format, thumb_width,
714 thumb_height, &buf_size) < 0) {
715 thumb_err("Failed to get buffer size");
716 return MEDIA_THUMB_ERROR_MM_UTIL;
719 thumb_dbg("mm_util_get_image_size : %d", buf_size);
721 dst_data = (unsigned char *)malloc(buf_size);
723 if (src_format == MM_UTIL_IMG_FMT_RGB888 &&
724 dst_format == MM_UTIL_IMG_FMT_BGRA8888) {
727 for (j = 0; j < thumb_width * 3 * thumb_height;
729 dst_data[i++] = (src_data[j + 2]);
730 dst_data[i++] = (src_data[j + 1]);
731 dst_data[i++] = (src_data[j]);
736 err = mm_util_convert_colorspace(src_data,
744 thumb_err("Failed to change from rgb888 to argb8888 %d", err);
746 return MEDIA_THUMB_ERROR_MM_UTIL;
750 SAFE_FREE(thumb_info->data);
751 thumb_info->data = dst_data;
752 thumb_info->size = buf_size;
754 thumb_dbg("_media_thumb_convert_data success");
759 int _media_thumb_convert_format(media_thumb_info *thumb_info,
760 media_thumb_format src_format,
761 media_thumb_format dst_format)
765 if (src_format == dst_format) {
766 //thumb_dbg("src_format == dst_format");
770 mm_util_img_format src_mm_format;
771 mm_util_img_format dst_mm_format;
773 src_mm_format = _media_thumb_get_format(src_format);
774 dst_mm_format = _media_thumb_get_format(dst_format);
776 if (src_mm_format == -1 || dst_mm_format == -1) {
777 thumb_err("Format is invalid");
778 return MEDIA_THUMB_ERROR_UNSUPPORTED;
781 err = _media_thumb_convert_data(thumb_info,
788 thumb_err("media_thumb_convert_format failed : %d", err);
795 int _media_thumb_agif(const char *origin_path,
796 ImgImageInfo *image_info,
799 media_thumb_format format,
800 media_thumb_info *thumb_info)
803 unsigned int *thumb = NULL;
804 media_thumb_type thumb_type;
806 thumb = ImgGetFirstFrameAGIFAtSize(origin_path, image_info);
809 thumb_err("Frame data is NULL!!");
810 return MEDIA_THUMB_ERROR_UNSUPPORTED;
813 if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
814 thumb_type = MEDIA_THUMB_LARGE;
816 thumb_type = MEDIA_THUMB_SMALL;
819 err = _media_thumb_get_proper_thumb_size(thumb_type,
820 thumb_info->origin_width, thumb_info->origin_height,
821 &thumb_width, &thumb_height);
823 thumb_err("_media_thumb_get_proper_thumb_size failed: %d", err);
828 err = _media_thumb_resize_data((unsigned char *)thumb,
831 MM_UTIL_IMG_FMT_RGB888,
837 thumb_err("_media_thumb_resize_data failed: %d", err);
844 err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
846 thumb_err("_media_thumb_convert_format falied: %d", err);
847 SAFE_FREE(thumb_info->data);
854 int _media_thumb_png(const char *origin_path,
857 media_thumb_format format,
858 media_thumb_info *thumb_info)
861 err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
864 thumb_err("decode_with_evas failed : %d", err);
868 err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
870 thumb_err("_media_thumb_convert_format falied: %d", err);
871 SAFE_FREE(thumb_info->data);
878 int _media_thumb_bmp(const char *origin_path,
881 media_thumb_format format,
882 media_thumb_info *thumb_info)
885 err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
888 thumb_err("decode_with_evas failed : %d", err);
892 err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
894 thumb_err("_media_thumb_convert_format falied: %d", err);
895 SAFE_FREE(thumb_info->data);
902 int _media_thumb_wbmp(const char *origin_path,
905 media_thumb_format format,
906 media_thumb_info *thumb_info)
909 err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
912 thumb_err("decode_with_evas failed : %d", err);
916 err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
918 thumb_err("_media_thumb_convert_format falied: %d", err);
919 SAFE_FREE(thumb_info->data);
926 int _media_thumb_gif(const char *origin_path,
929 media_thumb_format format,
930 media_thumb_info *thumb_info)
933 err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, NORMAL);
936 thumb_err("decode_with_evas failed : %d", err);
940 err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
942 thumb_err("_media_thumb_convert_format falied: %d", err);
943 SAFE_FREE(thumb_info->data);
950 int _media_thumb_jpeg(const char *origin_path,
953 media_thumb_format format,
954 media_thumb_info *thumb_info,
960 int orientation = NORMAL;
962 /* Load an ExifData object from an EXIF file */
963 ed = exif_data_new_from_file(origin_path);
966 /* First, Get orientation from exif */
967 err = _media_thumb_get_exif_info(ed, NULL, 0, &orientation, EXIF_IFD_0, EXIF_TAG_ORIENTATION);
970 thumb_warn("_media_thumb_get_exif_info failed");
973 /* Second, Get thumb from exif */
974 err = _media_thumb_get_thumb_from_exif(ed, origin_path, orientation, thumb_width, thumb_height, thumb_info, uid);
977 thumb_dbg("_media_thumb_get_thumb_from_exif failed");
980 thumb_dbg("_media_thumb_get_thumb_from_exif succeed");
982 mm_util_img_format dst_format = _media_thumb_get_format(format);
984 err = _media_thumb_convert_data(thumb_info,
987 MM_UTIL_IMG_FMT_RGB888,
991 thumb_err("_media_thumb_convert_data failed : %d", err);
1002 err = _media_thumb_decode_with_evas(origin_path, thumb_width, thumb_height, thumb_info, 0, orientation);
1005 thumb_err("decode_with_evas failed : %d", err);
1009 err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_BGRA, format);
1011 thumb_err("_media_thumb_convert_format falied: %d", err);
1012 SAFE_FREE(thumb_info->data);
1021 _media_thumb_image(const char *origin_path,
1024 media_thumb_format format,
1025 media_thumb_info *thumb_info, uid_t uid)
1031 ImgImageInfo image_info = { 0 };
1033 image_type = ImgGetInfoFile(origin_path, &image_info);
1035 thumb_info->origin_width = origin_w = image_info.width;
1036 thumb_info->origin_height = origin_h = image_info.height;
1038 thumb_dbg("image type is %d\n", image_type);
1040 if ((image_type != IMG_CODEC_JPEG) &&
1041 (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM_FOR_THUMB)) {
1042 thumb_warn("This original image is too big");
1043 return MEDIA_THUMB_ERROR_UNSUPPORTED;
1046 if (image_type == IMG_CODEC_AGIF) {
1047 err = _media_thumb_agif(origin_path, &image_info, thumb_width, thumb_height, format, thumb_info);
1048 } else if (image_type == IMG_CODEC_JPEG) {
1049 err = _media_thumb_jpeg(origin_path, thumb_width, thumb_height, format, thumb_info, uid);
1050 } else if (image_type == IMG_CODEC_PNG) {
1051 err = _media_thumb_png(origin_path, thumb_width, thumb_height, format, thumb_info);
1052 } else if (image_type == IMG_CODEC_GIF) {
1053 err = _media_thumb_gif(origin_path, thumb_width, thumb_height, format, thumb_info);
1054 } else if (image_type == IMG_CODEC_BMP) {
1055 err = _media_thumb_bmp(origin_path, thumb_width, thumb_height, format, thumb_info);
1058 err = _media_thumb_get_file_ext(origin_path, file_ext, sizeof(file_ext));
1060 thumb_warn("_media_thumb_get_file_ext failed");
1062 if (strcasecmp(file_ext, "wbmp") == 0) {
1063 image_type = IMG_CODEC_WBMP;
1065 int wbmp_height = 0;
1067 err = _media_thumb_get_wh_with_evas(origin_path, &wbmp_width, &wbmp_height);
1069 thumb_err("_media_thumb_get_wh_with_evas in WBMP : %d", err);
1073 if (wbmp_width * wbmp_height > THUMB_MAX_ALLOWED_MEM_FOR_THUMB) {
1074 thumb_warn("This original image is too big");
1075 return MEDIA_THUMB_ERROR_UNSUPPORTED;
1078 thumb_info->origin_width = wbmp_width;
1079 thumb_info->origin_height = wbmp_height;
1081 err = _media_thumb_wbmp(origin_path, thumb_width, thumb_height, format, thumb_info);
1087 thumb_warn("Unsupported image type");
1088 return MEDIA_THUMB_ERROR_UNSUPPORTED;
1095 _media_thumb_video(const char *origin_path,
1098 media_thumb_format format,
1099 media_thumb_info *thumb_info,
1104 MMHandleType content = (MMHandleType) NULL;
1106 int video_track_num = 0;
1107 char *err_msg = NULL;
1113 drm_bool_type_e drm_type;
1115 ret = (drm_is_drm_file(origin_path, &drm_type) == 1);
1117 thumb_err("drm_is_drm_file falied : %d", ret);
1118 drm_type = DRM_FALSE;
1122 err = mm_file_create_content_attrs(&content, origin_path);
1125 thumb_err("mm_file_create_content_attrs fails : %d", err);
1126 return MEDIA_THUMB_ERROR_MM_UTIL;
1130 mm_file_get_attrs(content, &err_msg,
1131 MM_FILE_CONTENT_VIDEO_TRACK_COUNT,
1132 &video_track_num, NULL);
1135 thumb_err("mm_file_get_attrs fails : %s", err_msg);
1137 mm_file_destroy_content_attrs(content);
1138 return MEDIA_THUMB_ERROR_MM_UTIL;
1141 /* MMF api handle both normal and DRM video */
1142 if (video_track_num > 0 || is_drm) {
1144 err = mm_file_get_attrs(content, &err_msg,
1145 MM_FILE_CONTENT_VIDEO_WIDTH,
1147 MM_FILE_CONTENT_VIDEO_HEIGHT,
1149 MM_FILE_CONTENT_VIDEO_THUMBNAIL, &frame, /* raw image is RGB888 format */
1153 thumb_err("mm_file_get_attrs fails : %s", err_msg);
1155 mm_file_destroy_content_attrs(content);
1156 return MEDIA_THUMB_ERROR_MM_UTIL;
1159 thumb_dbg("video width: %d", width);
1160 thumb_dbg("video height: %d", height);
1161 thumb_dbg("thumbnail size=%d", size);
1162 thumb_dbg("frame = 0x%x", frame);
1164 if (frame == NULL || width == 0 || height == 0) {
1165 thumb_err("Failed to get frame data");
1166 mm_file_destroy_content_attrs(content);
1167 return MEDIA_THUMB_ERROR_MM_UTIL;
1170 media_thumb_type thumb_type;
1171 if (thumb_width == _media_thumb_get_width(MEDIA_THUMB_LARGE)) {
1172 thumb_type = MEDIA_THUMB_LARGE;
1174 thumb_type = MEDIA_THUMB_SMALL;
1177 thumb_info->origin_width = width;
1178 thumb_info->origin_height = height;
1180 err = _media_thumb_get_proper_thumb_size(thumb_type, width, height, &thumb_width, &thumb_height);
1182 if (width > thumb_width || height > thumb_height) {
1183 err = _media_thumb_resize_data(frame,
1186 MM_UTIL_IMG_FMT_RGB888,
1192 thumb_err("_media_thumb_resize_data failed - %d", err);
1193 SAFE_FREE(thumb_info->data);
1194 mm_file_destroy_content_attrs(content);
1198 thumb_info->size = size;
1199 thumb_info->width = width;
1200 thumb_info->height = height;
1201 thumb_info->data = malloc(size);
1202 memcpy(thumb_info->data, frame, size);
1205 mm_file_destroy_content_attrs(content);
1207 /* Get Content Tag attribute for orientatin */
1208 MMHandleType tag = (MMHandleType) NULL;
1211 err = mm_file_create_tag_attrs(&tag, origin_path);
1212 mm_util_img_rotate_type rot_type = MM_UTIL_ROTATE_0;
1214 if (err == MM_ERROR_NONE) {
1215 err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1216 if (err == MM_ERROR_NONE && size >= 0) {
1219 rot_type = MM_UTIL_ROTATE_0;
1221 if (strncmp(p, "90", size) == 0) {
1222 rot_type = MM_UTIL_ROTATE_90;
1223 } else if(strncmp(p, "180", size) == 0) {
1224 rot_type = MM_UTIL_ROTATE_180;
1225 } else if(strncmp(p, "270", size) == 0) {
1226 rot_type = MM_UTIL_ROTATE_270;
1228 rot_type = MM_UTIL_ROTATE_0;
1232 rot_type = MM_UTIL_ROTATE_0;
1236 rot_type = MM_UTIL_ROTATE_0;
1239 err = mm_file_destroy_tag_attrs(tag);
1240 if (err != MM_ERROR_NONE) {
1241 thumb_err("fail to free tag attr - err(%x)", err);
1244 if (rot_type == MM_UTIL_ROTATE_90 || rot_type == MM_UTIL_ROTATE_180 || rot_type == MM_UTIL_ROTATE_270) {
1245 /* Start to decode to rotate */
1246 unsigned char *rotated = NULL;
1247 unsigned int r_w = thumb_info->height;
1248 unsigned int r_h = thumb_info->width;
1249 unsigned int r_size = 0;
1251 if (rot_type == MM_UTIL_ROTATE_180) {
1252 r_w = thumb_info->width;
1253 r_h = thumb_info->height;
1256 err = mm_util_get_image_size(MM_UTIL_IMG_FMT_RGB888, r_w, r_h, &r_size);
1258 thumb_dbg("mm_util_get_image_size failed : %d", err);
1259 SAFE_FREE(thumb_info->data);
1263 //thumb_dbg("Size of Rotated : %d", r_size);
1264 rotated = (unsigned char *)malloc(r_size);
1265 err = mm_util_rotate_image(thumb_info->data, thumb_info->width, thumb_info->height,
1266 MM_UTIL_IMG_FMT_RGB888,
1267 rotated, &r_w, &r_h,
1271 thumb_err("mm_util_rotate_image failed : %d", err);
1272 SAFE_FREE(thumb_info->data);
1276 thumb_dbg("mm_util_rotate_image succeed");
1279 SAFE_FREE(thumb_info->data);
1281 thumb_info->data = rotated;
1282 thumb_info->size = r_size;
1283 thumb_info->width = r_w;
1284 thumb_info->height = r_h;
1287 err = _media_thumb_convert_format(thumb_info, MEDIA_THUMB_RGB888, format);
1289 thumb_err("_media_thumb_convert_format falied: %d", err);
1290 SAFE_FREE(thumb_info->data);
1294 thumb_dbg("no contents information\n");
1296 mm_file_destroy_content_attrs(content);
1298 return MEDIA_THUMB_ERROR_UNSUPPORTED;