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
	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 type as 8 bit or 24 bit.
	Reads both yup and ydown files.
	Writes out as 8 bit or 16,24,32 bit.
		Output options: 16,24,32 (default 24)
	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.
	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 <filename> 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.


Colour spaces
-------------

If a light is physically twice as bright, the eye does not necessarily see it
as twice as bright. Also, if a pixel is written onto a monitor screen with
twice the value, the physical intensity of the pixel is not necessarily double.

How exactly should numbers inside a bitmap file relate to physical or
perceived intensitys when displayed on the screen?

In OS/2 PM perceived intensitys are proportional to the values in the bitmap
file. Pixels in such a bitmap are in the 'L* cyclometric' colour space.

Ray Tracers often write pixel values in the bitmap proportional to the physical
intensity computed for that ray. Such data is in the 'intensity' colour space.

Finally, if a bitmap holds values computed in such a way as to compensate for
the gamma of the monitor (ie: intensitys transformed to cancel out the gamma
of the monitor), then the data is in a 'gamma corrected' colour space.

So, if you have some Ray Tracer output, and you wish to display on an 8514
monitor WITHOUT using OS/2 PM, then to get a decent colour rendition, you must
map the bitmap from the 'intensity' to a 'gamma corrected' colour space.
To do this you must know the gamma of the 8514 monitor (which is about 2.1).

Also, if you have some Ray Tracer output, and you wish to display on OS/2 PM,
then to get a decent rendition you must map the bitmap from the 'intensity' to
the 'L* cyclometric' colour space.

GBMGAMMA is a colour mapping program capable of performing mappings between
any 2 of the 3 colour spaces above.

Mapping of this sort should really be done on 24 bit data, before
error-diffusion or halftoning takes place.


Public domain declaration
-------------------------

I wrote all this code in my own time on my own equiptment.
I used public non-confidential information to do so.
I hereby place all this code into the public domain.
Feel free to do whatever you like with it.
No copyright / no royalties / no guarantees / no problem.
Caveat Emptor!


Obtaining this code
-------------------

Internet: ftp.cdrom.com:    /pub/os2/2_x/graphics/gbm.zip
          ftp.cdrom.com:    /pub/os2/2_x/graphics/gbmsrc.zip
          ftp-os2.nmsu.edu: /pub/os2/2_x/graphics/gbm.zip
          ftp-os2.nmsu.edu: /pub/os2/2_x/graphics/gbmsrc.zip
IBM-VNET: REQUEST GBM    FROM AKEY AT HVTVM5
          REQUEST GBMSRC FROM AKEY AT HVTVM5
An earlier release was included on the IBM OS/2 Developer Connection CD-ROM 2.
Also, hopefully on the next Hobbes OS/2 Shareware CD-ROM.


Change Log
----------

11/5/92		Initial general release.

Various dates	Fixed assorted bugs in various parts of GBM.
		Dropped support for 16 bit systems.
		Changed all code to now be compiled multithreaded.
		Changed GBM library to a DLL under OS/2, saved at least 500Kb.
		/NOI now required when linking with GBM.LIB.
		Added textual error messages.
		Accelerated halftoning and error-diffusion.
		Added GIF, X Bitmap and RiscOS Sprite support.
		Extensively improved TIFF file support (now almost Baseline).
		Extensively improved IFF support (HAM6, HAM8 etc.).
		GBM structure enlarged => PLEASE RECOMPILE
		Addition of bitmap transpose (and hence rotate) capability.
		Added GBMV2, the flagship OS/2+PM program to show off GBM.

28/9/93		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.

11/11/93	Added F3 to close GBMV and GBMV2.
		Fixed keyboard scrolling in GBMV2.
		Added general (single level) Undo capability to GBMV2.
		Added GBMWPOBJ.CMD to set up Workplace Shell Objects.

29/11/93	Sanitised documentation
		Copy supplied to IBM OS/2 Developer Connection.

2/6/94		Removed max number of strips limitation in TIFF reader.
		Added TIFF LZW encode option (alpha-level code).
		Added percentage on gbmhdr listing.

1/4/94		Bugfix for speckley IFF file writing.
		Bugfix for map to black and white.
		Added support for PSEGs

{{{ Andy Key

Internet: ak@vnet.ibm.com	# Currently working at IBM until september 94
IBM-VNET: AKEY AT HVTVM5	# so addresses valid at least until then.
