4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://floralicense.org/license/
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <Ecore_Evas.h>
24 //#include <Evas_Engine_Buffer.h>
26 #include "pgen_debug.h"
28 #include "preview_util.h"
31 int get_image_resolution(const char *path, int *resx, int *resy)
42 PGEN_RETV_IF(path == NULL || resx == NULL || resy == NULL, -1 , "Invalid argument");
44 ee = ecore_evas_buffer_new(1, 1);
45 PGEN_RETV_IF(ee == NULL, -1 , "ee is NULL");
47 canvas = ecore_evas_get(ee);
48 img = evas_object_image_add(canvas);
50 evas_object_image_file_set(img, NULL, NULL);
51 evas_object_image_load_orientation_set(img, EINA_TRUE);
52 evas_object_image_load_scale_down_set(img, 0);
54 evas_object_image_file_set(img, path, NULL);
55 Evas_Load_Error error = evas_object_image_load_error_get(img);
56 if (error != EVAS_LOAD_ERROR_NONE) {
57 PGEN_DEBUG("Decoding Error(%d) : %s", error, path);
63 evas_object_image_size_get(img, &width, &height);
65 evas_object_image_file_set(img, NULL, NULL);
73 PGEN_DEBUG("width & height is [%d, %d]", width, height);
81 * @brief Rotate image on 90 degrees
82 * @param[in] img image to rotate
84 int rotate90_image(Evas_Object *img)
88 int *outp; /* current writing pointer */
92 int off; /* offset from output beginning */
98 PGEN_RETV_IF(img == NULL, -1, "Invalid argument");
100 /* allocate temporary memory */
101 evas_object_image_size_get(img, &w, &h);
102 PGEN_RETV_IF(w == 0 || h == 0 , -1, "Failed to allocate memory");
103 PGEN_DEBUG("w = %d h = %d", w, h);
106 old_data = evas_object_image_data_get(img, EINA_FALSE);
107 PGEN_RETV_IF(old_data == NULL, -1 , "Failed to get image data");
109 new_data = malloc(sizeof(int) * (data_size + 1));
110 PGEN_RETV_IF(new_data == NULL, -1 , "Failed to malloc");
112 /* write rotated image data */
113 for (iy = 0; iy < h; ++iy)
114 for (ix = 0; ix < w; ++ix) {
115 off = h * (ix + 1) - 1 - iy;
116 if (off < 0 || off >= data_size) {
117 PGEN_DEBUG("ERROR: off = %d, lim: %d", off, data_size);
119 outp = new_data + off;
120 *outp = old_data[ix + w * iy];
123 /* store rotated image */
124 evas_object_image_size_set(img, h, w);
125 evas_object_image_data_copy_set(img, new_data);
126 PGEN_IF_FREE_MEM(new_data);