#include <Ecore_Evas.h>
#include <libexif/exif-data.h>
+#include <mm_util_magick.h>
+
#define MEDIA_THUMB_ROUND_UP_8(num) (((num)+7)&~7)
static int __media_thumb_get_buffer_size(image_util_colorspace_e format, unsigned int width, unsigned int height, unsigned int *imgsize)
return err;
}
-int _media_thumb_video(const char *origin_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
+int _media_thumb_video(const char *origin_path, const char *thumb_path, int thumb_width, int thumb_height, media_thumb_info *thumb_info)
{
int err = MS_MEDIA_ERR_NONE;
MMHandleType content = (MMHandleType) NULL;
+ MMHandleType tag = (MMHandleType) NULL;
+
+ char *p = NULL;
+ int cdis_value = 0;
void *frame = NULL;
int video_track_num = 0;
char *err_msg = NULL;
int size = 0;
int width = 0;
int height = 0;
+ mm_util_image_h img = NULL;
+ mm_util_image_h resize_img = NULL;
+ mm_util_image_h dst_img = NULL;
- /* Get Content Tag attribute for orientatin */
- MMHandleType tag = (MMHandleType) NULL;
- char *p = NULL;
- int cdis_value = 0;
+ unsigned char *res_buf = NULL;
+ size_t res_size = 0;
+ unsigned int res_width = 0;
+ unsigned int res_height = 0;
+ mm_util_magick_format res_format;
+
+ /* Get Content Tag attribute for orientation */
err = mm_file_create_tag_attrs(&tag, origin_path);
- image_util_rotation_e rot_type = IMAGE_UTIL_ROTATION_NONE;
+ mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
if (err == FILEINFO_ERROR_NONE) {
err = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
if (err == FILEINFO_ERROR_NONE && size >= 0) {
if (p == NULL) {
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
} else {
if (strncmp(p, "90", size) == 0) {
- rot_type = IMAGE_UTIL_ROTATION_90;
+ rot_type = MM_UTIL_ROTATE_90;
} else if (strncmp(p, "180", size) == 0) {
- rot_type = IMAGE_UTIL_ROTATION_180;
+ rot_type = MM_UTIL_ROTATE_180;
} else if (strncmp(p, "270", size) == 0) {
- rot_type = IMAGE_UTIL_ROTATION_270;
+ rot_type = MM_UTIL_ROTATE_270;
} else {
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
}
}
thumb_dbg("There is tag rotate : %d", rot_type);
} else {
thumb_dbg("There is NOT tag rotate");
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
SAFE_FREE(err_msg);
}
}
} else {
- rot_type = IMAGE_UTIL_ROTATION_NONE;
+ rot_type = MM_UTIL_ROTATE_0;
cdis_value = 0;
}
if (err != FILEINFO_ERROR_NONE) {
thumb_err("mm_file_get_attrs fails : %s", err_msg);
SAFE_FREE(err_msg);
- mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
}
if (video_track_num > 0) {
if (err != FILEINFO_ERROR_NONE) {
thumb_err("mm_file_get_attrs fails : %s", err_msg);
SAFE_FREE(err_msg);
- mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
}
- thumb_dbg("video width: %d", width);
- thumb_dbg("video height: %d", height);
- thumb_dbg("thumbnail size: %d", size);
- thumb_dbg("frame: %p", frame);
- thumb_dbg("orientation: %d", rot_type);
-
+ thumb_dbg("W[%d] H[%d] Size[%d] Frame[%p] Rotate[%d]", width, height, size, frame, rot_type);
if (frame == NULL || width == 0 || height == 0) {
thumb_err("Failed to get frame data");
- mm_file_destroy_content_attrs(content);
- return MS_MEDIA_ERR_INTERNAL;
+ goto ERROR;
}
- thumb_info->origin_width = width;
- thumb_info->origin_height = height;
+ thumb_info->is_saved = true;
err = _media_thumb_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
-
- unsigned int new_size = 0;
- unsigned char *new_frame = NULL;
- 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);
- SAFE_FREE(new_frame);
- return err;
+ if (thumb_width <= 0 || thumb_height <= 0) {
+ thumb_err("Failed to get thumb size");
+ goto ERROR;
}
- mm_file_destroy_content_attrs(content);
- thumb_dbg("original size - width:%d, height:%d", width, height);
- thumb_dbg("proper thumb size - width:%d, height:%d", thumb_width, thumb_height);
+ thumb_dbg("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", width, height, thumb_width, thumb_height);
+
+ err = mm_util_create_handle(&img, (unsigned char *)frame, width, height, size, MM_UTIL_IMG_FMT_RGB888);
if (width > thumb_width || height > thumb_height) {
- 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);
- return err;
+ if (rot_type != MM_UTIL_ROTATE_0) {
+ if (STRING_VALID(thumb_path)) {
+ err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ err = mm_util_rotate_B_P(resize_img, rot_type, thumb_path);
+ } else {
+ err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ err = mm_util_rotate_B_B(resize_img, rot_type, &dst_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ mm_util_get_image(dst_img, &res_buf, &res_width, &res_height, &res_size, &res_format);
+ thumb_info->data = calloc(1, res_size);
+ memcpy(thumb_info->data, res_buf, res_size);
+ thumb_info->size = res_size;
+ thumb_info->width = res_width;
+ thumb_info->height = res_height;
+ SAFE_FREE(res_buf);
+ }
+ } else {
+ if (STRING_VALID(thumb_path)) {
+ err = mm_util_resize_B_P(img, thumb_width, thumb_height, thumb_path);
+ } else {
+ err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ mm_util_get_image(resize_img, &res_buf, &res_width, &res_height, &res_size, &res_format);
+ thumb_info->data = calloc(1, res_size);
+ memcpy(thumb_info->data, res_buf, res_size);
+ thumb_info->size = res_size;
+ thumb_info->width = res_width;
+ thumb_info->height = res_height;
+ SAFE_FREE(res_buf);
+ }
}
} else {
- thumb_info->size = new_size;
- thumb_info->width = width;
- thumb_info->height = height;
- thumb_info->data = malloc(new_size);
- if (thumb_info->data == NULL) {
- thumb_err("memory allcation failed");
- SAFE_FREE(new_frame);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- memcpy(thumb_info->data, new_frame, new_size);
- }
- SAFE_FREE(new_frame);
-
- if (rot_type == IMAGE_UTIL_ROTATION_90 || rot_type == IMAGE_UTIL_ROTATION_180 || rot_type == IMAGE_UTIL_ROTATION_270) {
- err = _media_thumb_rotate_thumb(thumb_info->data, thumb_info->size, &(thumb_info->width), &(thumb_info->height), rot_type, IMAGE_UTIL_COLORSPACE_BGRA8888);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_rotate_thumb falied: %d", err);
- SAFE_FREE(thumb_info->data);
- return err;
+ if (rot_type != MM_UTIL_ROTATE_0) {
+ if (STRING_VALID(thumb_path)) {
+ err = mm_util_rotate_B_P(img, rot_type, thumb_path);
+ } else {
+ err = mm_util_rotate_B_B(img, rot_type, &dst_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+ mm_util_get_image(dst_img, &res_buf, &res_width, &res_height, &res_size, &res_format);
+ thumb_info->data = calloc(1, res_size);
+ memcpy(thumb_info->data, res_buf, res_size);
+ thumb_info->size = res_size;
+ thumb_info->width = res_width;
+ thumb_info->height = res_height;
+ SAFE_FREE(res_buf);
+ }
+ } else {
+ if (STRING_VALID(thumb_path)) {
+ err = mm_util_resize_B_P(img, width, height, thumb_path);
+ } else {
+ thumb_info->data = calloc(1, size);
+ memcpy(thumb_info->data, frame, size);
+ thumb_info->size = size;
+ thumb_info->width = width;
+ thumb_info->height = height;
+ }
}
}
- } else {
- thumb_dbg("no contents information");
- frame = NULL;
- mm_file_destroy_content_attrs(content);
-
- return MS_MEDIA_ERR_INTERNAL;
}
+ERROR:
+ mm_util_destroy_handle(img);
+ mm_util_destroy_handle(resize_img);
+ mm_util_destroy_handle(dst_img);
+ mm_file_destroy_content_attrs(content);
+
return err;
}
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
-#include <Evas.h>
-#include <Ecore_Evas.h>
#include "media-thumbnail.h"
#include "thumb-server-internal.h"
#include "media-thumb-ipc.h"
#include "media-thumb-util.h"
-int save_to_file_with_evas(unsigned char *data, int w, int h, int is_bgra)
-{
- ecore_evas_init();
-
- Ecore_Evas *ee =
- ecore_evas_buffer_new(w, h);
- Evas *evas = ecore_evas_get(ee);
-
- Evas_Object *img = NULL;
- img = evas_object_image_add(evas);
-
- if (img == NULL) {
- printf("image object is NULL\n");
- ecore_evas_free(ee);
- ecore_evas_shutdown();
- return -1;
- }
-
- evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
- evas_object_image_size_set(img, w, h);
- 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);
- /* 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);
- } else {
- evas_object_image_data_set(img, data);
- evas_object_image_data_update_add(img, 0, 0, w, h);
- }
-
- if (evas_object_image_save
- (img, "/mnt/nfs/test.jpg", NULL,
- "quality=50 compress=2")) {
- printf("evas_object_image_save success\n");
- } else {
- printf("evas_object_image_save failed\n");
- }
-
- ecore_evas_shutdown();
-
- return 0;
-}
-
int main(int argc, char *argv[])
{
int mode;
if (origin_path && (mode == 1)) {
printf("Test _thumbnail_get_data\n");
#if 0
- unsigned char *data = NULL;
- int thumb_size = 0;
- int thumb_w = 0;
- int thumb_h = 0;
- int origin_w = 0;
- int origin_h = 0;
- int alpha = FALSE;
- bool is_saved = FALSE;
char *thumb_path = "thumbnail_path.jpg";
- int is_bgra = 1;
- //int is_bgra = 0;
-
//long start = thumb_get_debug_time();
- err = _thumbnail_get_data(origin_path, thumb_path, &data, &thumb_size, &thumb_w, &thumb_h, &origin_w, &origin_h, &alpha, &is_saved);
+ err = _thumbnail_get_data(origin_path, thumb_path);
if (err < 0) {
printf("_thumbnail_get_data failed - %d\n", err);
return -1;
}
- printf("Size : %d, W:%d, H:%d\n", thumb_size, thumb_w, thumb_h);
- printf("Origin W:%d, Origin H:%d\n", origin_w, origin_h);
-
- if (is_saved == FALSE) {
- err = save_to_file_with_evas(data, thumb_w, thumb_h, is_bgra);
- if (err < 0) {
- printf("save_to_file_with_evas failed - %d\n", err);
- return -1;
- } else {
- printf("file save success\n");
- }
- }
-
- SAFE_FREE(data);
-
//long end = thumb_get_debug_time();
//printf("Time : %f\n", ((double)(end - start) / (double)CLOCKS_PER_SEC));
#endif