[cairo] Trouble displaying a jpeg image

Vicky Tux ssseintr2 at gmail.com
Sat Jan 7 01:20:40 PST 2012


 As per my understanding there is no jpeg image decoder in cairo. only png
surfaces were supported.
-vicky

>
> Message: 1
> Date: Thu, 5 Jan 2012 18:35:51 -0800
> From: Jeffrey Britton <jeffb0098 at gmail.com>
> Subject: [cairo] Trouble displaying a jpeg image
> To: cairo at cairographics.org
> Message-ID:
>        <CAJTKU_h6YF6e-5uG_VP5PgdTaryxmT6zvKaKiLe54cDuGvy9hg at mail.gmail.com
> >
> Content-Type: text/plain; charset="iso-8859-1"
>
> 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!
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://lists.cairographics.org/archives/cairo/attachments/20120105/0b6018f2/attachment.htm
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20120107/447568a4/attachment.htm>


More information about the cairo mailing list