[cairo-commit] pycairo/test isurface_get_data.py, NONE, 1.1 Makefile.am, 1.6, 1.7

Steve Chaplin commit at pdx.freedesktop.org
Mon Nov 20 03:21:03 PST 2006


Committed by: stevech1097

Update of /cvs/cairo/pycairo/test
In directory kemper:/tmp/cvs-serv10555/test

Modified Files:
	Makefile.am 
Added Files:
	isurface_get_data.py 
Log Message:
'SC'

--- NEW FILE: isurface_get_data.py ---
#!/usr/bin/env python
"""
Test ImageSurface.get_data()
"""

import cairo

filename_base = "/tmp/file"

# create an test image and save as PNG
width, height = 300, 200
surface1 = cairo.ImageSurface (cairo.FORMAT_ARGB32, width, height)
ctx = cairo.Context (surface1)
ctx.scale (width, height)

ctx.set_source_rgb (1, 1, 1)
ctx.set_operator (cairo.OPERATOR_SOURCE)
ctx.paint()

ctx.move_to (0.0, 0.0)
ctx.line_to (1.0, 1.0)
ctx.set_line_width (0.05)
ctx.set_source_rgb (0, 0, 1)
ctx.stroke()

ctx.select_font_face ("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
ctx.set_font_size (0.08)
ctx.move_to (0.05, 0.5)
ctx.set_source_rgb (0.0, 0.0, 0.0)
ctx.show_text ("get_data test")
surface1.write_to_png (filename_base + "get_data_test1.png")

# get data from the Surface and use to create a new Surface
buf = surface1.get_data()

# alternative which should work (?) but reports
# TypeError: buffer is read-only
# - is a Python bug?
#buf = buffer (surface1)

surface2 = cairo.ImageSurface.create_for_data (
    buf, cairo.FORMAT_ARGB32, surface1.get_width(), surface1.get_height(),
    surface1.get_stride()
    )
surface2.write_to_png (filename_base + "get_data_test2.png")
# need to visually check the two files created are the same.

Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/pycairo/test/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Makefile.am	3 Jul 2006 03:30:07 -0000	1.6
+++ Makefile.am	20 Nov 2006 11:21:00 -0000	1.7
@@ -5,6 +5,7 @@
 	isurface_create_for_data3.py \
 	isurface_create_from_png.py \
 	isurface_get_data_as_rgba.py \
+	isurface_get_data.py \
 	surface_create_for_stream.py \
 	surface_write_to_png.py \
 	test.py \



More information about the cairo-commit mailing list