[cairo] how to import .BMP without other libs(GTK+ etc)?
linermedia at gmail.com
Wed Feb 4 16:18:33 PST 2009
How did you handle the alpha channel in (for example) gif images?
long x, y;
const PixelPacket *p;
unsigned char *q;
unsigned char *imgbuf;
* Initialize the image info structure and read an image.
exception = AcquireExceptionInfo();
image_info = CloneImageInfo((ImageInfo *) NULL);
image = ReadImage(image_info,exception);
if (exception->severity != UndefinedException)
if (image == (Image *) NULL)
printf("rows = %ld, columns= %ld\n", image->rows, image->columns);
imgbuf = (unsigned char
q = imgbuf;
for(y=0; y < (long) image->rows; y++)
p = GetVirtualPixels(image, 0, y, image->columns, 1, exception);
if( p == (const PixelPacket *)NULL )
for( x = 0; x < (long) image->columns; x++)
*q = ScaleQuantumToChar(p->blue);
*q = ScaleQuantumToChar(p->green);
*q = ScaleQuantumToChar(p->red);
*q = ScaleQuantumToChar(p->opacity);
Is this the right way?
Thomas Stover wrote:
> A similar question came up on the gtk list the other day. Since you are
> looking for a way to do it without using an additional library, this is
> not your answer. However, I have been recommending people try
> ImageMagick http://www.imagemagick.org/script/index.php for "non png"
> file formats and misc raster operations such as resize as a supplement
> to cairo. If you want my demo I can post it here.
> Out of curiosity, what are your reasons for not wanting another library?
> I have seen allot of aversion to mixing libraries lately. As long as
> licenses and technical details work out, to me that's how you bring some
> real alchemy to the table.
>> From: Tor Lillqvist <tml at iki.fi>
>> Subject: Re: [cairo] how to import .BMP without other libs(GTK+ etc)?
>>> we could do it with GTK+. However, is there some other way to import BMP or
>>> dib in cairo without the suppot of other libs?
>> Not as far as I can see.
>>> I had tried to do it whit cairo_image_surface_create_for_data, but failed. I could not see the right image.
>> Are you sure that the .bmp file you are reading actually is in a
>> (sub)format your code can handle? Didn't debugging (or adding
>> printouts...) tell you anything? There must be a lot of sample code
>> that reads .bmp out there, compare to the code of those... I know of
>> io-bmp.c in gtk+/gdk-pixbuf and GIMP's bmp-read.c.
>> A "throwaway" program I wrote to dump the contents of a .bmp file is
>> at http://pastebin.com/m6e96721e . Unfortunately it compiles as such
>> only on Windows.
> cairo mailing list
> cairo at cairographics.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cairo