Trouble displaying a jpeg image

Vicky Tux <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAJosQWMeNv9TyjUAGay4NO+8cVFEQ-ANVHMHP43arks63VEcnA@mail.gmail.com>
 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 <[email protected]>
> Subject: [cairo] Trouble displaying a jpeg image
> To: [email protected]
> Message-ID:
>        <CAJTKU_h6YF6e-5uG_VP5PgdTaryxmT6zvKaKiLe54cDuGvy9hg@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
> >
>
>

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.