Beispiel #1
0
def simple_composite_test_one(interp_type, source_pixel, source_alpha,
                              destination_pixel, destination_alpha,
                              expected_result):
    print "simple_composite_test_one (%s, %s, %s, %s, %s, %s)" % \
     (interp_type, source_pixel, source_alpha, destination_pixel,
     destination_alpha, expected_result)

    source_pixbuf = GdkPixbuf.GdkPixbufBlank(GdkPixbuf.COLORSPACE_RGB,
                                             source_alpha, 8, 32, 32)
    destination_pixbuf = GdkPixbuf.GdkPixbufBlank(GdkPixbuf.COLORSPACE_RGB,
                                                  destination_alpha, 8, 32, 32)
    fill_with_pixel(source_pixbuf, source_pixel)
    fill_with_pixel(destination_pixbuf, destination_pixel)

    GdkPixbuf.pixbuf_composite(source_pixbuf, destination_pixbuf, 0, 0, 32, 32,
                               0, 0, 1, 1, interp_type, 0xFF)

    result_pixel = load_pixel (destination_pixbuf.get_pixels(),
       16 * destination_pixbuf.get_rowstride() + \
       16 * destination_pixbuf.get_n_channels(),
       destination_alpha)

    if result_pixel != expected_result:
        if type == GdkPixbuf.INTERP_NEAREST:
            interpolation_type = "GdkPixbuf.INTERP_NEAREST"
        elif type == GdkPixbuf.INTERP_TILES:
            interpolation_type = "GdkPixbuf.INTERP_TILES"
        elif type == GdkPixbuf.INTERP_BILINEAR:
            interpolation_type = "GdkPixbuf.INTERP_BILINEAR"
        elif type == GdkPixbuf.INTERP_HYPER:
            interpolation_type = "GdkPixbuf.INTERP_HYPER"
        else:
            interpolation_type = "???"

        if source_alpha:
            source_string = "0x%08X" % source_pixel
        else:
            source_string = "0x%06X" % source_pixel

        if destination_alpha:
            destination_string = "0x%08X" % destination_pixel
            result_string = "0x%08X" % result_pixel
            expected_string = "0x%08X" % expected_result
        else:
            destination_string = "0x%06X" % destination_pixel
            result_string = "0x%06X" % result_pixel
            expected_string = "0x%06X" % expected_result
        print "ERROR **"
        return FALSE

    return TRUE
def expose_cb(widget, event):
    global pixbuf, interp_type, overall_alpha
    # gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
    event_x, event_y, event_width, event_height = event.area
    widget_alloc = widget.get_allocation()
    widget_alloc_width = widget_alloc[2]
    widget_alloc_height = widget_alloc[3]

    dest = GdkPixbuf.GdkPixbufBlank(GdkPixbuf.COLORSPACE_RGB, FALSE, 8,
                                    event_width, event_height)

    GdkPixbuf.pixbuf_composite_color(
        pixbuf, dest, 0, 0, event_width, event_height, -event_x, -event_y,
        widget_alloc_width / pixbuf.get_width() + 0.0,
        widget_alloc_height / pixbuf.get_height() + 0.0, interp_type,
        overall_alpha, event_x, event_y, 16, 0xaaaaaa, 0x555555)

    dest.render_to_drawable(widget.get_window(),
                            widget.get_style().fg_gc[STATE_NORMAL], 0, 0,
                            event_x, event_y, event_width, event_height,
                            GDK.RGB_DITHER_NORMAL, event_x, event_y)
    del dest

    return TRUE
#!/usr/bin/python
import gtklib
from gtk import *
import GdkPixbuf
from Test import *

pixbuf = GdkPixbuf.GdkPixbufFromFile("pic.png")
show_pixbuf(pixbuf, "pic.png")

#pixbuf_scaled = pixbuf.scale (20, 30, 70, 80,
#			0, 0, 0, 0, GdkPixbuf.INTERP_NEAREST)
pixbuf_scaled = GdkPixbuf.GdkPixbufBlank(0, TRUE, 8, 150, 150)

pixbuf.scale(pixbuf_scaled, 20, 30, 70, 80, 0, 0, 0.5, 0.5,
             GdkPixbuf.INTERP_NEAREST)
show_pixbuf(pixbuf_scaled, "scaled pic.png")

pixbuf_composited = GdkPixbuf.GdkPixbufBlank(0, TRUE, 8, 150, 150)
GdkPixbuf.pixbuf_composite(pixbuf, pixbuf_composited, 20, 20, 100, 80, 0, 0,
                           1.0, 1.0, GdkPixbuf.INTERP_NEAREST, 200)
show_pixbuf(pixbuf_composited, "pixbuf_composited")

pixbuf_composited_color = GdkPixbuf.GdkPixbufBlank(0, TRUE, 8, 150, 150)
GdkPixbuf.pixbuf_composite_color(pixbuf, pixbuf_composited_color, 30, 15, 100,
                                 90, 10, 18, 0.7, 0.7, GdkPixbuf.INTERP_HYPER,
                                 0, 2, 5, 16, 20000, 40000)
show_pixbuf(pixbuf_composited_color, "pixubf_composited_color")

app()
mainloop()
Beispiel #4
0
win.set_usize (200, 200)
button = GtkButton ("quit")
button.connect ("clicked", mainquit)
win.add (button)
win.show_all ()

files = ["pic.jpg", "pic.gif", "pic.xpm", "pic.ppm", "pic.png"]
for file in files:
	pixbuf = GdkPixbuf.GdkPixbufFromFile (file)
	show_pixbuf (pixbuf, file)

pixbuf_copy = pixbuf.copy ()
show_pixbuf (pixbuf_copy, "this is a copy()")

pixbuf = GdkPixbuf.GdkPixbufBlank (colorspace=GdkPixbuf.COLORSPACE_RGB,
				has_alpha=TRUE, bits_per_sample=8,
				width=50, height=50)
show_pixbuf (pixbuf, "new with alpha=TRUE")

pixbuf = GdkPixbuf.GdkPixbufBlank (colorspace=GdkPixbuf.COLORSPACE_RGB,
                                has_alpha=FALSE, bits_per_sample=8,
                                width=50, height=50)
show_pixbuf (pixbuf, "new with alpha=FALSE")

f = open ("pic.ppm", "r")
magic_number = f.readline ()
line = f.readline ()
import string
width, height = string.split (line)
width = string.atoi (width)
height = string.atoi (height)