<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt">Hello,<br><br>PNG is directly supported via cairo_image_surface_create_from_png. 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?<br><br><span>BTW, I am using Cairo with a FreeBASIC (<a target="_blank" href="http://www.freebasic.net">http://www.freebasic.net</a> -- a free and open dialect of BASIC; think of FreePascal). Using C-libraries is as simple as translating only the header files then FreeBASIC can easily use the pre-compiled lib files</span> (.a, .lib)<br><span>For sample codes and test renders of Cairo on FreeBASIC, see: <a target="_blank"
href="http://konsolscript.org/%7Emjmendoza/freebasic/cairo/">http://konsolscript.org/~mjmendoza/freebasic/cairo/</a></span><br><br>FreeBASIC already have 'standalone' reusable functions that loads JPG/TGA (BMP is internally supported via BLoad). However, when I pass the loaded image to cairo, it has an offset of 8-pixels. See this image to see what I mean.<br><span><a target="_blank" href="http://konsolscript.org/%7Emjmendoza/freebasic/cairo/bmp-problem.png">http://konsolscript.org/~mjmendoza/freebasic/cairo/bmp-problem.png</a></span><br><div><br>The original file is on the left-side while the right-side shows how cairo renders the loaded image. Below is the code that loaded and passed the BMP file to Cairo.<br><font size="2"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">Dim imgCairo As Cairo_Surface_T</span><br style="font-family: Courier
New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">Dim imgBMP As Integer Ptr</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"></span></font><font size="2"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">'1. read the width and height of the BMP file from the BMP file header</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">Dim As Integer f = FreeFile<br></span></font><font size="2"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">Dim As Integer</span> </font><font size="2"><span style="font-family: Courier
New,courier,monaco,monospace,sans-serif;">wid</span></font>, <font size="2"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">hgt</span></font><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><font size="2"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"></span><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">Open "file.bmp" For Binary Access Read As #f</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> Get #f, 19, wid</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;"> Get #f, 23, hgt</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier
New,courier,monaco,monospace,sans-serif;">Close #f</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">'2. allocate a memory of that size</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">imgBMP = ImageCreate(wid, hgt, RGBA(0, 0, 0, 0), 32)</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">'3. load the BMP file to the allocated memory</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">BLoad
"file.bmp", imgBMP</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">'4. pass the memory to a Cairo Surface</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">imgCairo = Cairo_Image_Surface_Create_For_Data(imgBMP, CAIRO_FORMAT_ARGB32, wid, hgt, wid * Len(Integer))</span></font><br><br>I know that I should also inform the FreeBASIC developers and/or community, I am just hoping that some of cairo users could have already written a non-official patch to directly load BMP/JPG/TGA on a Cairo Surface (ex. cairo_image_surface_create_from_bmp, cairo_image_surface_create_from_jpg, or cairo_image_surface_create_from_tga)<br><br><br></div>Regards.<br><br>Mj Mendoza IV,<br>Developer,
KonsolScript<br><a rel="nofollow" target="_blank" href="http://www.konsolscript.org">http://www.konsolscript.org</a></div><br></body></html>