2 Copyright (C) 2009-2010 ProFUSION embedded systems
3 Copyright (C) 2009-2010 Samsung Electronics
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
26 #include <eina_safety_checks.h>
29 * Converts an image from cairo_surface to the Evas_Object.
31 * @param canvas display canvas
32 * @param surface cairo representation of an image
33 * @return converted cairo_surface object to the Evas_Object
35 Evas_Object* ewk_util_image_from_cairo_surface_add(Evas* canvas, cairo_surface_t* surface)
38 cairo_status_t status;
39 cairo_surface_type_t type;
40 cairo_format_t format;
46 EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
47 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, 0);
49 status = cairo_surface_status(surface);
50 if (status != CAIRO_STATUS_SUCCESS)
53 type = cairo_surface_get_type(surface);
54 if (type != CAIRO_SURFACE_TYPE_IMAGE)
57 format = cairo_image_surface_get_format(surface);
58 if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24)
61 w = cairo_image_surface_get_width(surface);
62 h = cairo_image_surface_get_height(surface);
63 stride = cairo_image_surface_get_stride(surface);
64 if (w <= 0 || h <= 0 || stride <= 0)
67 src = cairo_image_surface_get_data(surface);
71 image = evas_object_image_filled_add(canvas);
75 evas_object_image_colorspace_set(image, EVAS_COLORSPACE_ARGB8888);
76 evas_object_image_size_set(image, w, h);
77 evas_object_image_alpha_set(image, format == CAIRO_FORMAT_ARGB32);
79 if (evas_object_image_stride_get(image) != stride) {
80 evas_object_del(image);
84 dst = evas_object_image_data_get(image, EINA_TRUE);
85 memcpy(dst, src, h * stride);
86 evas_object_image_data_set(image, dst);
88 evas_object_resize(image, w, h); // helpful but not really required