[cairo-commit] pycairo/test isurface_create_for_data1.py, 1.3,
1.4 isurface_create_for_data2.py, 1.1, 1.2 Makefile.am, 1.8, 1.9
Steve Chaplin
commit at pdx.freedesktop.org
Tue Dec 26 23:14:02 PST 2006
Committed by: stevech1097
Update of /cvs/cairo/pycairo/test
In directory kemper:/tmp/cvs-serv20995/test
Modified Files:
isurface_create_for_data1.py isurface_create_for_data2.py
Makefile.am
Log Message:
'SC'
Index: isurface_create_for_data1.py
===================================================================
RCS file: /cvs/cairo/pycairo/test/isurface_create_for_data1.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- isurface_create_for_data1.py 7 Dec 2006 14:40:32 -0000 1.3
+++ isurface_create_for_data1.py 27 Dec 2006 07:13:58 -0000 1.4
@@ -1,11 +1,13 @@
#!/usr/bin/env python
+"""test cairo.ImageSurface.create_for_data() with a Python array
+"""
import array
import cairo
+dir_ = "/tmp/"
imgW, imgH = 255, 255
-
data = array.array('B', [0] * imgW * imgH * 4)
for y in range(imgH):
@@ -13,15 +15,14 @@
offset = (x + (y * imgW)) * 4
alpha = y
- # cairo.FORMAT_ARGB32 use pre-multiplied alpha
- data[offset+0] = int((x * alpha)/255)
- data[offset+1] = int((y * alpha)/255)
- data[offset+2] = 0
- data[offset+3] = alpha
+ # cairo.FORMAT_ARGB32 uses pre-multiplied alpha
+ data[offset+0] = int(x * alpha/255.0) # B
+ data[offset+1] = int(y * alpha/255.0) # G
+ data[offset+2] = 0 # R
+ data[offset+3] = alpha # A
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')
+surface.write_to_png (dir_ + 'for_data1.png')
Index: isurface_create_for_data2.py
===================================================================
RCS file: /cvs/cairo/pycairo/test/isurface_create_for_data2.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- isurface_create_for_data2.py 22 Jun 2006 04:55:33 -0000 1.1
+++ isurface_create_for_data2.py 27 Dec 2006 07:13:58 -0000 1.2
@@ -1,39 +1,26 @@
#!/usr/bin/env python
+"""test cairo.ImageSurface.create_for_data() with a numpy array
"""
-use ImageSurface.create_for_data() to access Numeric, using the buffer
-protocol
-"""
-import math
import cairo
-import Numeric
-
-width, height = 30*16, 30*9
-
-data = Numeric.zeros ((width,height,4), Numeric.UInt8)
-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)
+import numpy
-ctx.rectangle (0,0,1,1)
-ctx.set_source (pat)
-ctx.fill ()
+dir_ = "/tmp/"
+imgW, imgH = 255, 255
+data = numpy.ndarray (shape=(imgH,imgW,4), dtype=numpy.uint8)
-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 x in range(imgW):
+ for y in range(imgH):
+ alpha = y
-ctx.set_source (pat)
-ctx.arc (0.5, 0.5, 0.3, 0, 2 * math.pi)
-ctx.fill ()
+ # cairo.FORMAT_ARGB32 uses pre-multiplied alpha
+ data[y][x][0] = int(x * alpha/255.0)
+ data[y][x][1] = int(y * alpha/255.0)
+ data[y][x][2] = 0
+ data[y][x][3] = alpha
-surface.write_to_png ('for_data2.png')
+stride = imgW * 4
+surface = cairo.ImageSurface.create_for_data (data, cairo.FORMAT_ARGB32,
+ imgW, imgH, stride)
+ctx = cairo.Context (surface)
+surface.write_to_png (dir_ + 'for_data2.png')
Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/pycairo/test/Makefile.am,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Makefile.am 21 Nov 2006 01:46:07 -0000 1.8
+++ Makefile.am 27 Dec 2006 07:13:58 -0000 1.9
@@ -2,7 +2,6 @@
isurface_create_for_array.py \
isurface_create_for_data1.py \
isurface_create_for_data2.py \
- isurface_create_for_data3.py \
isurface_create_from_png.py \
isurface_get_data.py \
surface_create_for_stream.py \
More information about the cairo-commit
mailing list