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 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
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")
#!/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()