Short: Load LUT8,RGB24,RGBA32 pics via Datatypes Author: Andreas R. Kleinert Uploader: info ar-kleinert de Type: util/libs Version: 3.3 (27.1.2008) Architecture: m68k-amigaos >= 3.1.0; ppc-morphos >= 1.4.5 ************************************************************************** ************************************************************************** dtimage.library - Freeware. This library is freely redistributable and usable upon the conditions that this notice remains intact and that modified versions of this archive are not distributed in any way. The author makes no warranty of any kind with respect to this product and explicitly disclaims any implied warranties of merchantability or fitness for any particular purpose. If you are going to use dtimage.library within one of your programs and include it into your program's distribution, feel free to do so. In this case you have to add the following statement into your program's documentation: "This program makes use of dtimage.library @ 2007-2008 by Andreas R. Kleinert". ************************************************************************************ dtimage.library currently only has two functions: 1. Read Image as 32 Bit RGBA ---------------------------- ULONG DTI_ReadPic32(CONST_STRPTR filename, UBYTE **image, ULONG *width, ULONG *height, APTR future); A typical call would look like this: { ULONG bool, width, height; UBYTE *buffer = NULL; bool = DTI_ReadPic32("RAM:dummy.png", &buffer, &width, &height, NULL); if(bool && buffer) { // do something with RGBA32 buffer consisting of R,G,B,A bytes (width*4 bytes per line) FreeVec(buffer); }else { ; } // check IoErr() } The special thing here is, that every kind of image, including 8 bit images and single-color transparency (like e.g. with GIF or PNG) is converted to 32 Bit RGBA data. Let's say you have a 256 color GIF file with color #0 being fully transparent and a 32 Bit PNG file with several colors transparent - it does not matter, since everything becomes direct RGBA information. About the data buffer format: UBYTE rgba = { R0, G0, B0, A0, R1, G1, B1, A1, etc. } Here R,G,B = [0..255] where { 0,0,0 } = black and { 255,255,255 } = white and A = [0..255] where 0x00 == fully transparent and 0xFF == fully opaque. A sample C program is included which dumps the R,G,B bytes into a P6 PPM file and the A bytes into a grayscale P5 PGM file. This way you can easily check if your datatypes are working properly. Use "32" as commandline option. 2. Read Image as 8..24 Bit with optional alpha channel or transparent color index --------------------------------------------------------------------------------- ULONG DTI_ReadPic(CONST_STRPTR filename, UBYTE **image, ULONG *width, ULONG *height, ULONG *depth, LONG *transcolor, UBYTE **transmap, APTR future); A typical call would look like this: { ULONG bool, width, height, depth; LONG transcolor; UBYTE *buffer = NULL, *map = NULL; bool = DTI_ReadPic("RAM:dummy.png", &buffer, &width, &height, &depth, &transcolor, &map, NULL); if(bool && buffer) { if(depth <= 8) // can only be 1..8 or 24 { UBYTE *colormap = map; // do something with LUT8 buffer consisting of indices (width bytes per line) if(transcolor != -1) ; // then transcolor is index of transparent color if(colormap) ; // then this is our colormap[256][3] RGB LUT index table }else { UBYTE *transmap = map; // do something with RGB24 buffer consisting of R,G,B bytes (width*3 bytes per line) if(transcolor == -2) ; // then transmap is pointer to alpha channel buffer { if(transmap) ; // then this is our alpha[width*height] transparency information } } if(transmap) FreeVec(transmap); FreeVec(buffer); }else { ; } // check IoErr() } The issue here is, that either 24 Bit RGB data with or without alpha channel or 8 Bit LUT data with colormap and optional transparent color may be returned, About the data buffer format for 8 bit: UBYTE lut = { I0, I1, I2, etc. } Here "In" is an index into a colormap[256][3] array with 256 RGB entries where R,G,B = [0..255] with { 0,0,0 } = black and { 255,255,255 } = white. About the data buffer format for 24 bit: UBYTE rgb = { R0, G0, B0, R1, G1, B1, etc. } Here R,G,B = [0..255] where { 0,0,0 } = black and { 255,255,255 } = white. For transcolor == -2 a transcolor map for each color is returned, which contains as many entries as pixels with alpha (A) values with A = [0..255] where 0x00 == fully transparent and 0xFF == fully opaque. A sample C program is included which for 24/32 bit dumps the R,G,B bytes into a P6 PPM file and the A bytes into a grayscale P5 PGM file. For 8 bit it does a 8->24 bit conversion and dumps the result as P6, in addition to the LUT itself which is dumped as P5. This way you can easily check if your datatypes are working properly. Use "8" as commandline option. ************************************************************************************ Warning: There is at least one V45 version of picture.datatype in some OS version which does NOT support alpha channel export (always returns fixed value for alpha byte, no matter what is set by the corresponding image Datatype). ************************************************************************************ Main changes since previous versions: V3.3 (27.1.2007): - now sets PDTA_Remap and new() time to avoid problems with some AfaOS versions (-> Bernd Roesch) - fixed 3.2 version string - fixed V3.2 history V3.2 (26.1.2007): - now always sets PDTA_DitherQuality to 0 (-> Thomas Klein) V3.1 (5.1.2007): - bumped main version for easier distinction - added comments in includes regarding V1/V2/V3 differences - fixed minor bug in 8->32 bit conversion V2.3 (4.1.2007): - added MOS .elf version - added MOS ppcline .h files (-> Stefan Haubenthal) - fixed bug (file resources/handle not released) (-> Stefan Haubenthal) ************************************************************************************ © 2007-2008 by Dipl.-Ing. Andreas Kleinert. All rights reserved.