2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "gtk/gtkpixbuffactory.hpp"
23 #include "cave/helper/colors.hpp"
24 #include "gtk/gtkpixmap.hpp"
26 GTKPixbuf
*GTKPixbufFactory::create_composite_color(const Pixbuf
&src
, const GdColor
&c
, unsigned char alpha
) const {
27 GTKPixbuf
const &srcgtk
= static_cast<GTKPixbuf
const &>(src
);
28 guint32 color
= (c
.get_r()<<16) | (c
.get_g()<<8) | (c
.get_b()<<0);
29 GdkPixbuf
*pb
= gdk_pixbuf_composite_color_simple(srcgtk
.get_gdk_pixbuf(), src
.get_width(), src
.get_height(), GDK_INTERP_NEAREST
, 255-alpha
, 1, color
, color
);
30 return new GTKPixbuf(pb
);
33 GTKPixbuf
*GTKPixbufFactory::create_subpixbuf(Pixbuf
&src
, int x
, int y
, int w
, int h
) const {
34 GTKPixbuf
&srcgtk
= static_cast<GTKPixbuf
&>(src
);
35 GdkPixbuf
*sub
= gdk_pixbuf_new_subpixbuf(srcgtk
.get_gdk_pixbuf(), x
, y
, w
, h
);
37 // gdk references pixbuf automatically, so it won't be cleared until the new GTKPixbuf is deleted, too
38 return new GTKPixbuf(sub
);
41 Pixmap
*GTKPixbufFactory::create_pixmap_from_pixbuf(const Pixbuf
&pb
, bool format_alpha
) const {
42 GTKPixbuf
*scaled
= static_cast<GTKPixbuf
*>(create_scaled(pb
));
47 gdk_pixbuf_render_pixmap_and_mask(scaled
->get_gdk_pixbuf(), &pixmap
, &mask
, 128); // 128 = alpha threshold
49 gdk_pixbuf_render_pixmap_and_mask(scaled
->get_gdk_pixbuf(), &pixmap
, NULL
, 128); // 128 = alpha threshold
54 return new GTKPixmap(pixmap
, mask
);
57 GTKPixbuf
*GTKPixbufFactory::create_rotated(const Pixbuf
&src
, Rotation r
) const {
58 GdkPixbuf
const *srcgtk
= static_cast<GTKPixbuf
const &>(src
).get_gdk_pixbuf();
62 pb
=gdk_pixbuf_rotate_simple(srcgtk
, GDK_PIXBUF_ROTATE_NONE
);
64 case CounterClockWise
:
65 pb
=gdk_pixbuf_rotate_simple(srcgtk
, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
);
68 pb
=gdk_pixbuf_rotate_simple(srcgtk
, GDK_PIXBUF_ROTATE_UPSIDEDOWN
);
71 pb
=gdk_pixbuf_rotate_simple(srcgtk
, GDK_PIXBUF_ROTATE_CLOCKWISE
);
75 return new GTKPixbuf(pb
);
79 GTKPixbufFactory::GTKPixbufFactory(GdScalingType scaling_type_
, bool pal_emulation_
)
80 : PixbufFactory(scaling_type_
, pal_emulation_
) {
84 GTKPixbuf
*GTKPixbufFactory::create(int w
, int h
) const {
85 return new GTKPixbuf(w
, h
);
89 GTKPixbuf
*GTKPixbufFactory::create_from_inline(int length
, unsigned char const *data
) const {
90 return new GTKPixbuf(length
, data
);
94 GTKPixbuf
*GTKPixbufFactory::create_from_file(const char *filename
) const {
95 return new GTKPixbuf(filename
);