[cairo] How to load a BMP/JPG/TGA to a Surface?

Adrian Lopez adrianlopezroche at gmail.com
Tue Jun 1 13:41:27 PDT 2010


Something I forgot to add concerning the use of DevIL with Cairo: While
Cairo's ARGB32 format uses premultiplied alpha [1], DevIL's format does not.
Thus, when converting from DevIL's format to Cairo's format you first have
to multiply the R, G and B components by the pixel's normalized alpha value
(which is A / 255.0 for an 8-bit alpha value).

[1] http://www.gimp.org/docs/plug-in/appendix-alpha.html

On Tue, Jun 1, 2010 at 4:09 PM, Adrian Lopez <adrianlopezroche at gmail.com>wrote:

> On Tue, Jun 1, 2010 at 12:35 AM, Mj Mendoza IV <mjmendoza at konsolscript.org
> > wrote:
>
>> Is there any way that I could load BMP/JPG/TGA without being tied to a
>> specific library to avoid bloat? Is there a minimalist reusable 'standalone'
>> function that directly loads a BMP/JPG/TGA into the memory which cairo could
>> use?
>>
>
> I load images into memory using DevIL [1] and copy them from memory onto a
> Cairo image surface, translating from DevIL's IL_RGBA format to Cairo's
> CAIRO_FORMAT_ARGB32 [2]. Cairo has no built-in support for most image
> formats, so your only options are to use a third party library like DevIL or
> write your own image loading routines.
>
> [1] http://openil.sourceforge.net/
> [2] Something to look out for if you decide to do this: While the order of
> pixel components in Cairo's image format is affected by endianness, the
> order of components in DevIL is not. Thus, on x86 systems it turns out that
> while DevIL's format looks like (R, G, B, A), Cairo's format actually looks
> like (B, G, R, A).
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20100601/64cb001e/attachment.htm>


More information about the cairo mailing list