This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Steve Chaplin
committed
May 20, 2010
1 parent
4a36f79
commit 2404914
Showing
14 changed files
with
279 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pycairo tests | ||
------------- | ||
|
||
The main test files are the '*_test.py' files. | ||
They use py.test from pylib. | ||
http://codespeak.net/py/dist/ | ||
|
||
$ cd test | ||
$ py.test | ||
|
||
The other files are tests that were used to test/develop specific | ||
functions. They usually require you run the test and then visually examine the | ||
output. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
#!/usr/bin/env python | ||
"""test cairo.ImageSurface.create_for_data() with a numpy array | ||
""" | ||
import tempfile | ||
|
||
import cairo | ||
|
||
import numpy | ||
|
||
dir_ = "/tmp/" | ||
if not (cairo.HAS_IMAGE_SURFACE and cairo.HAS_PNG_FUNCTIONS): | ||
raise SystemExit ('cairo was not compiled with ImageSurface and PNG support') | ||
|
||
h, fileName = tempfile.mkstemp(prefix='pycairo_', suffix='.png') | ||
width, height = 255, 255 | ||
data = numpy.ndarray (shape=(height,width,4), dtype=numpy.uint8) | ||
|
||
for x in range(width): | ||
for y in range(height): | ||
alpha = y | ||
for y in range(height): | ||
alpha = y | ||
|
||
# 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 | ||
# cairo.FORMAT_ARGB32 uses pre-multiplied alpha | ||
data[y][x][0] = int(x * alpha/255.0) # B | ||
data[y][x][1] = int(y * alpha/255.0) # G | ||
data[y][x][2] = 0 # R | ||
data[y][x][3] = alpha # A | ||
|
||
surface = cairo.ImageSurface.create_for_data (data, cairo.FORMAT_ARGB32, | ||
width, height) | ||
ctx = cairo.Context(surface) | ||
surface.write_to_png(dir_ + 'for_data2.png') | ||
surface.write_to_png(fileName) | ||
print "see %s output file" % fileName |
Oops, something went wrong.