4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (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 "evas_render.h"
24 #include "paper_size.h"
25 #include "pgen_debug.h"
26 #include "preview_util.h"
28 #include "image_scaler.h"
30 #define DOWNSCALE_LEVEL 2
32 int downscale_image(const char *fname, const char *outfname_ppm,
33 const struct size_px *available_size)
38 struct size_pts rsize;
39 struct size_px pic_size = {400, 400};
40 struct size_px size_limits;
43 PTS_RETV_IF(fname == NULL || outfname_ppm == NULL || available_size == NULL, -1, "Invalid argument");
45 PGEN_DEBUG("available_size(%d,%d)",available_size->x, available_size->y);
47 size_limits.x = available_size->x / DOWNSCALE_LEVEL;
48 size_limits.y = available_size->y / DOWNSCALE_LEVEL;
50 if (get_image_resolution(fname, &rw, &rh) < 0) {
55 PTS_RETV_IF(rw <= 0 || rh <= 0, -1, "Failed to get resolution");
59 PGEN_DEBUG("size_limits before: (%d, %d)",
60 size_limits.x, size_limits.y);
61 if (rsize.x > rsize.y) {
62 if (size_limits.x < size_limits.y) {
63 switch_size_px_coords(&size_limits);
65 } else if (size_limits.x > size_limits.y) {
66 switch_size_px_coords(&size_limits);
68 PGEN_DEBUG("size_limits after: (%d, %d)",
69 size_limits.x, size_limits.y);
70 pts_size2px(&rsize, &size_limits, &pic_size);
72 PGEN_DEBUG("new canvas");
73 PGEN_DEBUG("canvas init, (%d; %d)", pic_size.x, pic_size.y);
75 canvas = create_canvas(&pic_size);
76 PTS_RETV_IF(canvas == NULL, -1, "canvas is NULL");
78 /*PGEN_DEBUG("new image");*/
79 img = evas_object_image_filled_add(canvas);
81 destroy_canvas(canvas);
85 /*PGEN_DEBUG("setting image file %s", fname);*/
86 evas_object_image_file_set(img, fname, NULL);
88 evas_object_resize(img, pic_size.x, pic_size.y);
89 evas_object_move(img, 0, 0);
90 evas_object_show(img);
92 /*PGEN_DEBUG("canvas draw");*/
94 /*PGEN_DEBUG("saving canvas in %s", outfname_ppm);*/
95 save_scene(canvas, outfname_ppm);
96 destroy_canvas(canvas);