A.7 Graphics File Handling

Different graphics file formats are best at handling different types of images. PNG's are the only format that has a built-in alpha channel. JPG's provide excellent compression for photographic images. BMP's don't have an alpha channel, and don't have compression, so there's seldom any reason to use them except perhaps for very tiny images. Also, the image reading functions provided by PModeLib are much more full-featured for PNG's and JPG's than for BMP's.

However, the only format currently supported by PModeLib for saving images is BMP.

A.7.1 LoadPNG()

Usage

bool LoadPNG(char *Filename, void *ImageBuf, int *Width, int *Height);

Purpose

Reads a PNG (Portable Network Graphics) image into a 32 BPP (RGBA) buffer.

Inputs

Filename, (pathname) of the PNG file.

ImageBuf, starting address of 32 BPP image buffer to read image into.

Outputs

Width, the width of the loaded image, in pixels.

Height, the height of the loaded image, in pixels.

Returns 1 on error, 0 on success.

Notes

Assumes destination image buffer is large enough to hold entire loaded 32 BPP image.

Some outputs are passed as parameters; pass the address of a variable, and after a successful call, the variable will be filled with the output information. If an output is not desired, pass 0 as the address.

A.7.2 LoadPNG_Sel()

Usage

bool LoadPNG_Sel(char *Filename, short ImageSel, void *ImageBuf, int *Width, int *Height);

Purpose

Reads a PNG (Portable Network Graphics) image into a 32 BPP (RGBA) buffer.

Inputs

Filename, (pathname) of the PNG file.

ImageSel, selector of memory segment containing image buffer.

ImageBuf, starting address (within memory segment selected by ImageSel) of 32 BPP image buffer to read image into.

Outputs

Width, the width of the loaded image, in pixels.

Height, the height of the loaded image, in pixels.

Returns 1 on error, 0 on success.

Notes

Assumes destination image buffer is large enough to hold entire loaded 32 BPP image.

Some outputs are passed as parameters; pass the address of a variable, and after a successful call, the variable will be filled with the output information. If an output is not desired, pass 0 as the address.

A.7.3 LoadJPG()

Usage

bool LoadJPG(char *Filename, void *ImageBuf, int *Width, int *Height);

Purpose

Reads a JPG (or JPEG) image into a 32 BPP (RGBx) buffer.

Inputs

Filename, (pathname) of the JPG file.

ImageBuf, starting address of 32 BPP image buffer to read image into.

Outputs

Width, the width of the loaded image, in pixels.

Height, the height of the loaded image, in pixels.

Returns 1 on error, 0 on success.

Notes

Assumes destination image buffer is large enough to hold entire loaded 32 BPP image.

Some outputs are passed as parameters; pass the address of a variable, and after a successful call, the variable will be filled with the output information. If an output is not desired, pass 0 as the address.

A.7.4 LoadBMP()

Usage

bool LoadBMP(char *Filename, void *ImageBuf);

Purpose

Reads an 8-bits-per-pixel or 24 BPP BMP (Windows Bitmap) image into a 32 BPP (RGBx) buffer.

Inputs

Filename, (pathname) of the BMP file.

ImageBuf, starting address of 32 BPP image buffer to read image into.

Outputs

Returns nonzero on error, 0 on success.

Notes

Assumes destination image buffer is large enough to hold entire loaded 32 BPP image.

Doesn't return size of loaded image (e.g., width and height).

A.7.5 LoadBMP_Sel()

Usage

bool LoadBMP_Sel(char *Filename, short ImageSel, void *ImageBuf);

Purpose

Reads an 8-bits-per-pixel or 24 BPP BMP (Windows Bitmap) image into a 32 BPP (RGBx) buffer.

Inputs

Filename, (pathname) of the BMP file.

ImageSel, selector of memory segment containing image buffer.

ImageBuf, starting address (within memory segment selected by ImageSel) of 32 BPP image buffer to read image into.

Outputs

Returns nonzero on error, 0 on success.

Notes

Assumes destination image buffer is large enough to hold entire loaded 32 BPP image.

Doesn't return size of loaded image (e.g., width and height).

A.7.6 SaveBMP()

Usage

bool SaveBMP(char *Filename, void *ImageBuf, int Width, int Height);

Purpose

Saves a 32 BPP (RGBx) image into a 24 BPP BMP (Windows Bitmap) file.

Inputs

Filename, (path)name of the BMP file.

ImageBuf, starting address of 32 BPP image buffer containing image to save.

Width, the width of the image, in pixels.

Height, the height of the image, in pixels.

Outputs

Returns nonzero on error, 0 on success.

A.7.7 SaveBMP_Sel()

Usage

bool SaveBMP_Sel(char *Filename, short ImageSel, void *ImageBuf, int Width, int Height);

Purpose

Saves a 32 BPP (RGBx) image into a 24 BPP BMP (Windows Bitmap) file.

Inputs

Filename, (path)name of the BMP file.

ImageSel, selector of memory segment containing image buffer.

ImageBuf, starting address (within memory segment selected by ImageSel) of 32 BPP image buffer containing image to save.

Width, the width of the image, in pixels.

Height, the height of the image, in pixels.

Outputs

Returns nonzero on error, 0 on success.