[cairo-commit] pycairo/test isurface_create_for_array.py, NONE, 1.1 isurface_create_for_data1.py, NONE, 1.1 isurface_create_for_data2.py, NONE, 1.1 isurface_create_for_data3.py, NONE, 1.1

Steve Chaplin commit at pdx.freedesktop.org
Wed Jun 21 21:55:35 PDT 2006


Committed by: stevech1097

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

Added Files:
	isurface_create_for_array.py isurface_create_for_data1.py 
	isurface_create_for_data2.py isurface_create_for_data3.py 
Log Message:
'SC'

--- NEW FILE: isurface_create_for_array.py ---
#!/usr/bin/env python

import Numeric

import cairo

# create an array
array = Numeric.zeros((80,80,4), Numeric.UInt8)
for i in range(80):
    for j in range(80):
        array[i][j][0] = chr(255-3*i)        # B
        array[i][j][1] = chr(255-3*abs(i-j)) # G
        array[i][j][2] = chr(255-3*j)        # R
        array[i][j][3] = 255                 # Alpha

surface = cairo.ImageSurface.create_for_array(array)
ctx = cairo.Context(surface)

surface.write_to_png('cairo_image_surface_create_for_array.png')

--- NEW FILE: isurface_create_for_data1.py ---
#!/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)

ctx.rectangle (0,0,1,1)
ctx.set_source (pat)
ctx.fill ()

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)

ctx.set_source (pat)
ctx.arc (0.5, 0.5, 0.3, 0, 2 * math.pi)
ctx.fill ()

surface.write_to_png ('for_data1.png')

--- NEW FILE: isurface_create_for_data2.py ---
#!/usr/bin/env python
"""
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)

ctx.rectangle (0,0,1,1)
ctx.set_source (pat)
ctx.fill ()

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)

ctx.set_source (pat)
ctx.arc (0.5, 0.5, 0.3, 0, 2 * math.pi)
ctx.fill ()

surface.write_to_png ('for_data2.png')

--- NEW FILE: isurface_create_for_data3.py ---
#!/usr/bin/env python
"""
use ImageSurface.create_for_data() to access numarray, using the buffer
protocol
"""
import math

import cairo
import numarray

width, height = 30*16, 30*9

data = numarray.zeros ((width,height,4), numarray.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)

ctx.rectangle (0,0,1,1)
ctx.set_source (pat)
ctx.fill ()

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)

ctx.set_source (pat)
ctx.arc (0.5, 0.5, 0.3, 0, 2 * math.pi)
ctx.fill ()

surface.write_to_png ('for_data3.png')



More information about the cairo-commit mailing list