<br> As per my understanding there is no jpeg image decoder in cairo. only png surfaces were supported.<div>-vicky<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Message: 1<br>
Date: Thu, 5 Jan 2012 18:35:51 -0800<br>
From: Jeffrey Britton <<a href="mailto:jeffb0098@gmail.com">jeffb0098@gmail.com</a>><br>
Subject: [cairo] Trouble displaying a jpeg image<br>
To: <a href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><br>
Message-ID:<br>
<<a href="mailto:CAJTKU_h6YF6e-5uG_VP5PgdTaryxmT6zvKaKiLe54cDuGvy9hg@mail.gmail.com">CAJTKU_h6YF6e-5uG_VP5PgdTaryxmT6zvKaKiLe54cDuGvy9hg@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
I am trying to read a jpg from file and display it.<br>
I am using Python with pyCairo.<br>
<br>
I have the following code that works with some help from PIL, but it is<br>
slow.<br>
I feel that there must be a more direct route.<br>
<br>
There is an example at this link: <a href="http://cairographics.org/pythoncairopil/" target="_blank">http://cairographics.org/pythoncairopil/</a><br>
but it does not work.<br>
<br>
<br>
img = Image.open('image.jpg')<br>
<br>
# The next 3 lines are to get the data to pass to Image.frombuffer<br>
# I need to convert rgb to bgra.<br>
l = [struct.pack('BBBB', b, g, r, 0xFF) for (r,g,b) in img.getdata()]<br>
<br>
# runs over whole image to convert to string<br>
s = string.join(l, '')<br>
<br>
# runs over whole image again to get a writable buffer<br>
data = array.array('B', s)<br>
<br>
im1 = Image.frombuffer("RGBA", img.size, data, "raw", "RGBA", 0, 1)<br>
<br>
# runs over whole image twice<br>
self.img = array.array('B', im1.tostring())<br>
<br>
stride = cairo.ImageSurface.format_stride_for_width(cairo.FORMAT_ARGB32,<br>
self.width())<br>
self.img_surface = cairo.ImageSurface.create_for_data (self.img,<br>
cairo.FORMAT_ARGB32, self.width(), self.height(), stride)<br>
<br>
Yikes that is bad.<br>
<br>
Once I have the surface, then I do<br>
ctx.set_source_surface(surface, self.x, self.y)<br>
make_rectangle_path(ctx, self.x, self.y, self.width(), self.height())<br>
ctx.fill()<br>
<br>
Help!<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.cairographics.org/archives/cairo/attachments/20120105/0b6018f2/attachment.htm" target="_blank">http://lists.cairographics.org/archives/cairo/attachments/20120105/0b6018f2/attachment.htm</a>><br>
<br></blockquote></div></div>