Generalised Bitmap Module ========================= Supported File Formats ---------------------- Short name : Long name : File extensions Comments Bitmap : OS/2 1.1, 1.2, 2.0 / Windows 3.0 bitmap : .BMP .VGA .BGA .RLE .DIB .RL4 .RL8 Reads any of the above if uncompressed or run-length compressed. Will not read CCITT G3 MH Fax compressed files. Will not read 24 bit RLE files. If input is an OS/2 bitmaparray file then which bitmap can be specified. Input options: index=# (default: 0) Can be made to write OS/2 1.1 or Windows 3.0 / OS/2 2.0 bitmaps Output options: 1.1,win,2.0 (default: 2.0, note win=2.0) The handling of 1bpp bitmaps is a little complicated. When reading 1bpp bitmaps, the palette is ignored. 1's are considered foreground, and they are considered black. 0's are considered background, and they are considered white. This agrees with WorkPlace Shell WPFolder background mode, and most PM programs, but notably disagrees with Windows PBrush. When writing 1bpp bitmaps, the actual 2 colours in the palette are ignored, and a fixed palette is written. This is so that the resulting bitmap will display black on white when displayed by WPFolder etc.. Foreground and background colours in palette can be inverted on input. Input options: inv Foreground and background colours in palette can be inverted on output. Output options: inv Foreground and background colours in bits can be inverted on input. Input options: invb Foreground and background colours in bits can be inverted on output. Output options: invb GIF : CompuServe Graphics Interchange Format : .GIF Reads 1, bit data files. Reads 2, 3 and 4 bit data files and presents them as 4 bit. Reads 5, 6, 7 and 8 bit data files and presents them as 8 bit. Writes 1, 4 and 8 bit data files. Reads "GIF87a" and "GIF89a" style files. Writes "GIF87a" style files. Should correctly handle deferred clear-code in LZW data stream. Will not generate output with deferred clear-code. ie: should not break older GIF readers. Can specify index of image within file on read. Input option: index=# (default 0) Can specify to return decoded data so far rather than error if corrupt. Input option: errok Can specify screen size to write in output screen descriptor. Output options: xscreen=#,yscreen=# (defaults: image size). Can specify background colour index to write in file BMHD header. Output option: background=# (default: 0) Can specify position information in output image descriptor. Output options: xpos=#,ypos=# (defaults: 0,0). Extensively test on GIF files from a wide variety of sources. Compatibility tested with xloadimage and xv. PCX : ZSoft PC Paintbrush Image format : .PCX Reads and writes 1,4,8 and 24 bit colour files. Subset of plane/bits-per-plane combinations supported. Files are read and written using a run-length coding scheme. Tested using Zsoft originated .PCX files. Compressed runs of pixels are not supposed to straddle scan lines. GBM never does this, but some other applications violate this rule. By default, if GBM finds that a run of pixels is longer than the scan line, it will use the leftover pixels on the next scan line. Some images will not load properly, as they require the loading program to discard those pixels in the run that extend beyond the end of the scan line. This behaviour can be enabled in GBM. Input option: trunc TIFF : Microsoft/Aldus Tagged Image File Format support : .TIF .TIFF Reads and writes 1,4,8 and 24 bit colour files. Can almost read all TIFF 6.0 Baseline compliant files. Can read uncompressed and Packbits images. CCITT Modified huffman compression is the missing peice. Can read some files with extensions to Baseline. Can read 1bpp greyscale and palettised files. Can read Orientation==4 files. Can read PlanarConfiguration==2 files for RGB image data. Can read LZW compressed files too. Can also read CMYK 4 colour seperation files. No JPEG or Y-Cb-Cr support. Writes files that comply with TIFF 6.0 Baseline. Usually writes uncompressed files only. Data is written out as a single large strip. Can specify image within TIFF file with many images Input option: index=# (default: 0) Can write 1bpp as non-Baseline file preserving fg/bg cols Output option: pal1bpp Can ask for LZW compression. Output option: lzw Can specify informational tags to append on output. Output options: artist=,software=,make=,model=,host=,documentname=,pagename=,imagedescription= Targa : Truevision Targa/Vista bitmap : .TGA .VST .AFI Reads any uncompressed/run-length-compressed files. Reads 8 bit and 24 bit files. Can read 8 bit greyscale and 8 bit colour mapped files. Reads both yup and ydown files. Writes out as uncompressed 8 bit or 16,24,32 bit. Output options: 16,24,32 (default 24) 8 bit data is always written out as a colour mapped file. Can be made to write yup and ydown files. Output options: ydown,yup (default: yup) ILBM : Amiga IFF / ILBM Interleaved bitmap format : .IFF .LBM Reads 1 bit palettised files. Reads 2,3 and 4 bit palettised files, returning them as 4 bit. Reads 5,6,7 and 8 bit palettised files, returning them as 8 bit. Reads HAM6, HAM8, SHAM and Extra-Halfbrite images. HAM6, HAM8 and SHAM returned as 24 bit data. Writes 1,4 and 8 bit palettised colour files. Writes 24 bit files by performing simple conversion to HAM6 first. This loses quality but results are still better than 8 bit. Understands the RLE compression scheme used. Uses BMHD, CMAP, CAMG and BODY sections of file only. Only writes BMHD, CMAP, CAMG and BODY sections in output files. Can specify position information in file BHMD header. Output options: xpos=#,ypos=# (defaults: 0,0). Can specify transparent colour to write in file BMHD header. Output option: transcol=# (default: 0) Can specify aspect ratio to write in file BMHD header. Output options: xaspect=#,yaspect=# (defaults: 1,1). Can specify screen size to write in output BMHD header. Output options: xscreen=#,yscreen=# (defaults: image size). Note that when DeluxePaint etc. try to load an 8 bit IFF file, they switch to a 32 colour (5 bit mode) and only read the 5 least significant planes of the file - this generally looks yukky! Tested using DeluxePaint sample bitmaps. YUV12C : YUV12C M-Motion Frame Buffer : .VID Reads files and presents data as 24 bit data. Writes 24 bit data files by converting them into 12 bit YUV. VID files MUST be a multiple of 4 pixels wide. When writing a non-multiple of 4, the last 1, 2 or 3 pixels are lost. Can specify image origin information in YUV12C header. Output options: xpos=#,ypos=# (defaults: 0,0). Tested using M-Control Program 2.0, Browser sample application. Greymap : Portable Greyscale-map (binary P5 type) : .PGM Credit for file format to Jef Poskancer. No palette present in file format. Reads 8 bit grey scale files. Writes red, green, blue plane or greyscale equivelent of 8 bit image. Output options: r,g,b,k (default: k) Pixmap : Portable Pixel-map (binary P6 type) : .PPM Credit for file format to Jef Poskancer. Reads and writes 24 bit unpalettised RGB data files. KIPS : IBM KIPS : .KPS Reads 8 bit palettised files. Will look for palette in .PAL file unless .KPL file specified. Input options: pal,kpl (default: pal) Writes 8 bit palettised files. Will write palette in .PAL file unless .KPL file specified. Output options: pal,kpl (default: pal) IAX : IBM Image Access eXecutive : .IAX Reads array as 8 bit greyscale. File format does not hold image dimensions. Hence code assumes width is 512 pixels unless overridden. Input options: width=# (default: 512) File format does not include palette. Writes red, green, blue plane or greyscale equivelent of 8 bit image. Output options: r,g,b,k (default: k) XBitmap : X Windows bitmap : .XBM Reads 1bpp X bitmaps, presenting 1's as black, 0's as white. Writes 1bpp X bitmaps, darkest colours as 1's, brightest colour as 0's. Tested upon some sample .XBM files. Sprite : Archimedes Sprite format from RiscOS : .SPR .SPRITE Technically sprite files have no extension. But GBM recognises .SPR and .SPRITE for convenience. Reads 1,4 and 8 bit sprites. 'First bit' value in header must be a multiple of 8 (v.likely). Will only read image plane, will ignore any mask plane. Will handle case when no palette present in file. Will default to the default Wimp palette in this case. If input contains more than one sprite then which can be specified. Input options: index=# (default: 0) Will output 1,4 and 8 bit files. Will write a palette in the file. Will only write an image plane, ie: no mask plane. Will write a 16 entry palette for 8 bit data (not 64 entry). Will map to wierd archmedes palette when writing 8 bit data. Tested reading 4bpp sprites with no palette. Tested reading 8bpp sprites with no palette and with 64 entry palette. Sprites generated by GBM have been loaded on RiscOS. Remember: Use SetType to change type of file from PC-file to Sprite, by SetType option of filer menu or "*SetType Sprite". PSEG : IBM Printer Page Segment : .PSE .PSEG .PSEG38PP .PSEG3820 This is a file format used by IBM document/printing systems. It is used to represent a bi-level image to be used in a document. Reads data and presents a 1bpp bitmap. Image is presented 1's as black on 0's as white background. PSEG files should be downloaded from a VM host in binary mode. Some PSEG files have a corrupt record structure. This doesn't cause a problem on VM but can confuse a non-VM reader. GBM can be made to attempt to handle these files. Input option: fixrec Will output 1bpp file. Can specify 2x scale factor. Output option: double Palette in 1bpp data is lost when written to file. The resulting non-VM file has no record structure. So when it is uploaded it must be fixed using FIXL3820 EXEC or similar. Image width is rounded up to next multiple of 8 when written. Sample Applications ------------------- GBMHDR - Display header information from bitmap files usage: gbmhdr [-g] [-s] {fn.ext{,opt}} -g don't guess bitmap format, try each type -s be silent about errors fn.ext{,opt} input filenames (with any format specific options) Bitmap when ext in [BMP VGA BGA RLE DIB RL4 RL8] GIF when ext in [GIF] PCX when ext in [PCX] TIFF when ext in [TIF] Targa when ext in [TGA VST AFI] ILBM when ext in [IFF LBM] YUV12C when ext in [VID] Greymap when ext in [PGM] Pixmap when ext in [PPM] KIPS when ext in [KPS] IAX when ext in [IAX] XBitmap when ext in [XBM] Sprite when ext in [SPR] opt bitmap format specific option to pass to bitmap reader Note that the GBM module only ever surfaces the size and bits per pixel of images (regardless of the other information present in the header). All GBM programs have access to the bitmap file formats documented above, although this list is omitted in subsequent documentation. GBMHDR displays output in the following style :- 384x768 8bpp 51Kb 17% GIF aab.gif 227x254 8bpp 58Kb 102% Bitmap andy.bmp 256x256 24bpp 84Kb 43% TIFF bardot.tif Listed is the size, bits per pixel, Kb size of the file, a percentage value, the file format, and the file name. The percentage is calculated as (filesize*100/datasize) and effectively gives the compression ratio. For example aab.gif is well compressed (to 17% of the theoretical size). andy.bmp gives a >100% value because of the file header. GBMREF - Reflect in horizontal and/or vertical directions usage: gbmref [-h] [-v] [-t] fn1.ext{,opt} [fn2.ext{,opt}] flags: -h reflect horizontally -v reflect vertically -t transpose x for y fn1.ext{,opt} input filename (with any format specific options) fn2.ext{,opt} optional output filename (or will use fn1 if not present) bitmap formats and options as before Certain non-obvious combinations of -h, -v and -t can be very usefull. None of them can be used for just file format translation. -h -v reflect both, equivelent to 180 degree turn -h -t equivelent to 90 degree turn clockwise -v -t equivelent to 90 degree turn anti-clockwise. GBMSUB - Extract a subrectangle of a bitmap usage: gbmsub [-x x] [-y y] [-w w] [-h h] fn1.ext{,opt} [fn2.ext{,opt}] flags: -x x left edge of rectangle (default 0) -y y bottom edge of rectangle (default 0) -w w width of rectangle (default width of image - x) -h h height of rectangle (default height of image - y) fn1.ext{,opt} input filename (with any format specific options) fn2.ext{,opt} optional output filename (or will use fn1 if not present) bitmap formats and options as before If none of the -x,-y,-w and -h options are supplied the defaults cover the whole of the input file. Hence this program will just read one file and write the data as another. Great for format conversion. GBMSIZE - Change the size of a bitmap usage: gbmsize [-w w] [-h h] fn1.ext{,opt} [fn2.ext{,opt}] flags: -w w new width of bitmap (default width of bitmap) -h h new height of bitmap (default height of bitmap) fn1.ext{,opt} input filename (with any format specific options) fn2.ext{,opt} optional output filename (or will use fn1 if not present) bitmap formats and options as before If none of the -w or -h options are supplied, the defaults will be the input image size. Hence this program will just read one file and write the data as another. Great for format conversion. GBMBPP - Do various bits per pixel conversions usage: gbmbpp [-m map] [-e] [-hN] fn1.ext{,opt} [fn2.ext{,opt}] flags: -m map mapping to perform (default 7x8x4) bw black and white vga 16 colour VGA 8 8 colour (in 4 bit file) 4g 4 bit greyscale 7x8x4 7 levels red, 8 green, 4 blue 8514/A 6x6x6 6 levels red, 6 green, 6 blue 8g 8 bit greyscale tripel 64 reds, 64 greens, 64 blues tripel freqR:G:B:N keep R red, G green, b blue bits, and map to N most used colours in 8 bit palette mcutN median cut to N colours R:G:B keep R red, G green, B blue bits (eg: 8:8:8) -e enable error-diffusion (default is to truncate) -e only with -m bw, vga, 4g, 7x8x4, 6x6x6 with no -h -h enable halftoning (default is to truncate) -h only with -m 7x8x4, 6x6x6, 8, vga or R:G:B, with no -e N is a halftoning algorithm number (default 0) fn1.ext{,opt} input filename (with any format specific options) fn2.ext{,opt} optional output filename (or will use fn1 if not present) bitmap formats and options as before This program reads the input bitmap. If it is not 24 bit, then it is expanded to 24 bit per pixel. The data is then processed using the supplied mapping giving a 24,8,4 or 1 bit per pixel image, which is then written to the output bitmap file. The bw mapping produces a 1 bpp output file, vga and 4g gives 4 bit output files, 7x8x4, 6x6x6, 8g, freq and tripel give 8 bit output files. R:G:B (where R,G and B are numbers in the range 0 to 8), gives a 24 bit output file where only the top R bits of red are non-zero, the top G of green and B of blue. The normal way to map is simply to map each colour in the source bitmap to the closest one in the destination bitmap. However if -e is supplied, error diffusion is used to get a smoother result. Also, if -h is supplied halftoning may be used instead. -e and -h are not valid together, and are only valid with certain mappings. GBMGAMMA - Convert between various colour spaces usage: gbmgamma [-m map] [-g gamma] [-s shelf] fn1.ext{,opt} [fn2.ext{,opt}] flags: -m map mapping in the form ?_to_? (default: i_to_l), where ? is i physical intensitys (eg: raytracer output) p gamma corrected for a specific monitor l L* cyclometric linear perceived intensitys (as in PM) -g gamma set monitor gamma (default 2.1) -s shelf set monitor shelf (default 0.0) gamma and shelf only used for mapping to or from p for 8514 monitor gamma=2.3,shelf=0.136 for 8515 monitor gamma=2.1,shelf=0.0 fn1.ext{,opt} input filename (with any format specific options) fn2.ext{,opt} optional output filename (or will use fn1 if not present) bitmap formats and options as before This program reads a bitmap and assumes the pixel values in it are in the input colour space. If the bitmap has a palette it maps each palette entry according to the supplied mapping, otherwise it maps each individual 24 bit pixel. For example, if you get a 24 bit per pixel image from a Windows video capture program, the odds are in may be in a gamma corrected colour space with a gamma of 2.2. You can convert this to the L* cyclometric colour space used by PM by typing "gbmgamma -m p_to_l -g 2.2 captured.bmp nicepm.bmp". The shelf option is primarily for when converting to a gamma corrected colour space for a specific monitor (when you aren't going to use PM to display the bitmap, and the display program doesn't do any correction). Some monitors don't actually start to light up pixels until the pixel values are a certain value. Normally "-s shelf" will not be used. GBMCPAL - Map to Common Palette usage: gbmcpal [-m map] [-v] n1 n2 n3 ifspec{,opt} ofspec{,opt} flags: -m map mapping to perform (default freq6:6:6:256) freqR:G:B:N map all bitmaps to same palette, worked out using frequency of use histogram mcutN map all bitmaps to same palette, worked out using median cut algorithm rofreqR:G:B:N:N2 map each bitmap to frequency palette, reordered to minimise differences between successive bitmaps romcutN:N2 map each bitmap to median cut palette, reordered to minimise differences between successive bitmaps R,G,B are bits of red, green and blue to keep, N is number of unique colours, N2 is extra palette entries -v verbose mode n1 n2 n3 for ( f=n1; f PLEASE RECOMPILE Addition of bitmap transpose (and hence rotate) capability. Added GBMV2.EXE, the flagship OS/2+PM program to show off GBM. Handling of 1bpp data has changed - now honors colours. Windows / (OS/2 2.0 subset) not OS/2 1.1 bitmaps now default. Improved error checking some file readers. Addition of -s and -g options to GBMHDR.EXE. Added GBMWPOBJ.CMD to set up Workplace Shell Objects. 29/11/93 Sanitised documentation Copy supplied to IBM OS/2 Developer Connection. 6/2/94 Removed max number of strips limitation in TIFF reader. Added TIFF LZW encode option (alpha-level code). Added percentage on GBMHDR.EXE listing. 1/4/94 Bugfix for speckley IFF file writing. Bugfix for map to black and white. Added support for PSEGs 18/4/94 Added GBMSCALE.LIB and GBMSIZE.EXE to resize bitmaps. Rewrote a large chunk of GBMV2.EXE. Added Paste, Resize... and Snapshot capability. Added reflect selection only etc. capability Removed Select All (now not required). 3/5/94 Added GBMMCUT.LIB to implement median-cut algorithm. Made GBMBPP.EXE and GBMV2.EXE able to do median-cut. Split GBMHIST.LIB to enable multiple bitmap usage. Added GBMCPAL.EXE to map multiple bitmaps to a common palette. Added GBMVFSA.EXE to view multi-bitmap full screen animations. Added export to PM Metafile (& via clipboard) for GBMV2.EXE. Improved documentation. 27/6/94 -m rofreqR:G:B:N:N2 and -m romcutN:N2 options to GBMCPAL.EXE. RLE colour mapped, RLE RGB and 8bpp grey Targa loading support. Change to Targa file writer to account for CJPEG reader feechur. Commonised up source in GBM.DLL. Bugfix for some widths of IFF/ILBM file. 1/8/94 Faster/better LZW algorithm for GIF and TIFF writers. Future? Palette Manager capability in GBMV.EXE and GBMV2.EXE? Non-scaled and fixed scale print for GBMV2.EXE? Special logic for print to 1bpp and 3bpp printers for GBMV2.EXE? JPEG, Photo-CD, RLE-Bitmap, G3-TIFF, G3-Bitmap for GBM.DLL? {{{ Andy Key Internet: ak@vnet.ibm.com # Currently working at IBM until September 94 IBM-VNET: AKEY AT HVTVM # so addresses valid at least until then.