[cairo-commit] pycairo/test isurface_create_for_data1.py,1.1,1.2

Steve Chaplin commit at pdx.freedesktop.org
Thu Dec 7 06:39:20 PST 2006


Committed by: stevech1097

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

Modified Files:
	isurface_create_for_data1.py 
Log Message:
'SC'

Index: isurface_create_for_data1.py
===================================================================
RCS file: /cvs/cairo/pycairo/test/isurface_create_for_data1.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- isurface_create_for_data1.py	22 Jun 2006 04:55:33 -0000	1.1
+++ isurface_create_for_data1.py	7 Dec 2006 14:39:16 -0000	1.2
@@ -1,36 +1,26 @@
 #!/usr/bin/env python
 
 import array
-import math
 
 import cairo
 
-width, height = 30*16, 30*9
-
-data = array.array('c', 'a' * width * height * 4)
-stride = width * 4
-surface = cairo.ImageSurface.create_for_data (data, cairo.FORMAT_ARGB32,
-                                              width, height, stride);
-del data  # to test that create_for_data() references 'data'
-ctx = cairo.Context (surface)
-
-ctx.scale (width, height)
-
-pat = cairo.LinearGradient (0.0, 0.0, 0.0, 1.0)
-pat.add_color_stop_rgba (1, 0, 0, 0, 1)
-pat.add_color_stop_rgba (0, 1, 1, 1, 1)
+imgW, imgH = 255, 255
 
-ctx.rectangle (0,0,1,1)
-ctx.set_source (pat)
-ctx.fill ()
+data = array.array('B', [0] * imgW * imgH * 4)
 
-pat = cairo.RadialGradient (0.45, 0.4, 0.1,
-                            0.4,  0.4, 0.5)
-pat.add_color_stop_rgba (0, 1, 1, 1, 1)
-pat.add_color_stop_rgba (1, 0, 0, 0, 1)
+for y in range(imgH):
+    for x in range(imgW):
+        offset = (x + (y * imgW)) * 4
+        alpha = y
 
-ctx.set_source (pat)
-ctx.arc (0.5, 0.5, 0.3, 0, 2 * math.pi)
-ctx.fill ()
+        data[offset+0] = int((x * alpha)/255)
+        data[offset+1] = int((y * alpha)/255)
+        data[offset+2] = 0
+        data[offset+3] = alpha
 
+stride = imgW * 4
+surface = cairo.ImageSurface.create_for_data (data, cairo.FORMAT_ARGB32,
+                                              imgW, imgH, stride)
+del data  # to test that create_for_data() references 'data'
+ctx = cairo.Context (surface)
 surface.write_to_png ('for_data1.png')



More information about the cairo-commit mailing list