Trouble displaying a jpeg image
Jeffrey Britton <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CAJTKU_h6YF6e-5uG_VP5PgdTaryxmT6zvKaKiLe54cDuGvy9hg@mail.gmail.com> |
I am trying to read a jpg from file and display it.
I am using Python with pyCairo.
I have the following code that works with some help from PIL, but it is
slow.
I feel that there must be a more direct route.
There is an example at this link: http://cairographics.org/pythoncairopil/
but it does not work.
img = Image.open('image.jpg')
# The next 3 lines are to get the data to pass to Image.frombuffer
# I need to convert rgb to bgra.
l = [struct.pack('BBBB', b, g, r, 0xFF) for (r,g,b) in img.getdata()]
# runs over whole image to convert to string
s = string.join(l, '')
# runs over whole image again to get a writable buffer
data = array.array('B', s)
im1 = Image.frombuffer("RGBA", img.size, data, "raw", "RGBA", 0, 1)
# runs over whole image twice
self.img = array.array('B', im1.tostring())
stride = cairo.ImageSurface.format_stride_for_width(cairo.FORMAT_ARGB32,
self.width())
self.img_surface = cairo.ImageSurface.create_for_data (self.img,
cairo.FORMAT_ARGB32, self.width(), self.height(), stride)
Yikes that is bad.
Once I have the surface, then I do
ctx.set_source_surface(surface, self.x, self.y)
make_rectangle_path(ctx, self.x, self.y, self.width(), self.height())
ctx.fill()
Help!
--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo