Interface Reference

This reference describes the interfaces provided by the classes in paintlib. It is sorted by class name. You can jump to a particular entry by using the links below.

[ CAnyBmp | CAnyPicDecoder | CBmp | CBmpDecoder | CDataSource | CDIBSection | CFileSource | CJPEGDecoder | CObject | CPicDecoder | CPictDecoder | CPNGDecoder | CResourceSource | CTextException | CTGADecoder | CTIFFDecoder | CWinBmp | Globals ]


CAnyBmp

#include "anybmp.h"

Derived from: public CBmp

Manipulates uncompressed device- and platform-independent bitmaps. Supported data formats are 8 and 32 bpp. The data is stored sequentially without padding in the bitmap. The class implements exactly the interface defined by CBmp without additions.

Public Members

CAnyBmp ();

Creates an empty bitmap.

virtual ~CAnyBmp ();

Destroys the bitmap.

long GetMemUsed ();

Returns the amount of memory used by the object.

long GetBytesPerLine ();

Returns number of bytes used per line.

static long GetMemNeeded ( LONG width, LONG height, WORD BitsPerPixel );

Returns memory needed by a bitmap with the specified attributes.

static long GetBitsMemNeeded ( LONG width, LONG height, WORD BitsPerPixel );

Returns memory needed by bitmap bits.


CAnyPicDecoder

#include "anydec.h"

Derived from: public CPicDecoder

Class which decodes pictures with any known format. It auto-detects the format to use and delegates the work to one of the other decoder classes.

The interface to CAnyPicDecoder is the same as CPicDecoder.

Public Members

CAnyPicDecoder ();

Creates a decoder.

~CAnyPicDecoder ();

Destroys the decoder.

void MakeBmp ( CDataSource * pDataSrc, CBmp * pBmp, int BPPWanted );

Decodes a picture in a block of memory.


CBmp

#include "bitmap.h"

Derived from: public CObject

Device- and OS-independent bitmap class. Manipulates uncompressed bitmaps of all color depths.

This class is an abstract base class. It exists to define a format-independent interface for bitmap manipulation and to provide common routines. Derived classes must support at least the color depths 8 and 32 bpp. CBmp defines a public interface for general use and a protected interface for use by derived classes.

For 32 bpp, alpha channel information is stored in one byte (RGBA_ALPHA) of each 4-byte pixel. To allow for optimizations when no alpha channel is present, a flag is set whenever the alpha information is valid. The complete alpha channel of a bitmap can be replaced by a different one by calling SetAlphaChannel(). A 0 in an alpha channel entry is completely transparent; a 255 is completely opaque.

Public Members

CBmp ();

Empty constructor. Constructors in derived classes create a small empty bitmap to ensure that the object is always in a sane state.

virtual ~CBmp ();

Empty destructor.

void CreateCopy ( CBmp & rSrcBmp, int BPPWanted = 0 );

Creates a copy of rSrcBmp, converting color depth if nessesary. Supports 8 and 32 BPP. Alpha channel information is preserved.

virtual void Create ( LONG Width, LONG Height, WORD BitsPerPixel, BOOL bAlphaChannel );

Creates a new empty bitmap. Memory for the bits is allocated but not initialized. Previous contents of the bitmap object are discarded. If bAlphaChannel is true, the bitmap is assumed to contain a valid alpha channel.

void SetGrayPalette ();

Fills the color table with a grayscale palette. This function is only useable for bitmaps containing a color table. Index 0 contains black (0) and the last index contains white (255). The alpha channel is set to opaque (255) for every palette entry.

void SetPalette ( RGBAPIXEL * pPal );

Sets the color table to pPal. The contents or pPal are copied.

void SetPaletteEntry ( BYTE Entry, BYTE r, BYTE g, BYTE b, BYTE a );

Sets one entry in the color table. The function may only be called if there is a color table stored with the bitmap. The color table entry is set to the red, green, blue, and alpha values specified.

void SetAlphaChannel ( CBmp * pAlphaBmp );

Replaces the alpha channel of the bitmap with a new one. This only works for bitmaps with 32 bpp. pAlphaBmp must point to an 8 bpp bitmap with the same dimensions as the object. The alpha channel information is physically copied into the bitmap.

int GetWidth ();

int GetHeight ();

virtual long GetMemUsed () = 0;

int GetNumColors ();

int GetBitsPerPixel ();

BOOL HasAlpha ();

virtual long GetBytesPerLine () = 0;

Returns number of bytes used per line.

RGBAPIXEL * GetPalette ();

Returns the address of the color table of the bitmap or NULL if no color table exists. The color table is stored as an array of consecutive RGBAPIXELs.

BYTE ** GetLineArray ();

Returns pointer to an array containing the starting addresses of the bitmap lines. This array should be used whenever the bitmap bits need to be manipulated directly.

Protected Members

virtual void internalCreate ( LONG Width, LONG Height, WORD BitsPerPixel, BOOL bAlphaChannel ) = 0;

Create a new bitmap with uninitialized bits. (Assume no memory is allocated yet.)

virtual void freeMembers () = 0;

Delete memory allocated by member variables.

virtual void initLineArray () = 0;

Initialize internal table of line addresses.

void initLocals ( LONG Width, LONG Height, WORD BitsPerPixel, BOOL bAlphaChannel );

Can be called from internalCreate() to initialize object state.


CBmpDecoder

#include "bmpdec.h"

Derived from: public CPicDecoder

Windows bitmap file decoder. Decodes 1, 4, 8, and 24 bpp bitmap files (compressed and uncompressed). Returns an 8 or 32 bpp bitmap.

Public Members

CBmpDecoder ();

Creates a decoder

virtual ~CBmpDecoder ();

Destroys a decoder

Protected Members

virtual void DoDecode ();

Does the actual decoding of bitmap data.


CDataSource

#include "datasrc.h"

Derived from: public CObject

This is a base class for a source of picture data. It defines methods to open, close, and read from data sources. Does byte-order-conversions in the ReadByte, ReadWord, and ReadLong routines.

Restriction: All picture data is placed into the internal buffer on open so the ReadXxx-routines can be inline'd in this class. The effect is that anything other than memory-mapped files or files already in memory need to be read into memory before decoding can start. Now if someone would implement a smart buffering scheme...

Public Members

CDataSource ();

virtual ~CDataSource ();

virtual void Open ( const char * pszName, BYTE * pData, int FileSize );

virtual void Close ();

char * GetName ();

BYTE * GetBufferPtr ( int MinBytesInBuffer );

int GetFileSize ();

BYTE * ReadEverything ();

BYTE * ReadNBytes ( int n );

BYTE * Read1Byte ();

BYTE * Read2Bytes ();

BYTE * Read4Bytes ();

void AlignToWord ();

void Skip ( int n );

void CheckEOF ();

Test to see if we didn't go past the end of the file


CDIBSection

#include "dibsect.h"

Derived from: public CWinBmp

This is a windows DIBSection wrapped in a CBmp-derived class. It can be used just like a CWinBmp can be used. In addition, CDIBSection can give access to the bitmap as a GDI bitmap handle. This bitmap handle can be selected into a device context. All normal GDI drawing functions can be used to write on the bitmap in this way. Internally, CDIBSections are stored with header and bits in two separate buffers.

Public Members

CDIBSection ();

Creates an empty bitmap.

virtual ~CDIBSection ();

Destroys the bitmap.

virtual void Detach ();

Calling this function causes the windows DIBSection to be detached from the CDIBSection object. This means that the bitmap handle and the bitmap memory must be deleted by some other object. The CDIBSection object is in the same state as after a constructor call after this function is called.

virtual void Draw ( CDC* pDC, int x, int y, DWORD rop = SRCCOPY );

Draws the bitmap on the given device context using BitBlt.

virtual BOOL DrawExtract ( CDC* pDC, CPoint pntDest, CRect rcSrc );

Draws a portion of the bitmap on the given device context

HANDLE GetHandle ();

Returns a GDI handle to the bitmap. This handle can be selected into a DC and used in normal GDI operations. Under Windows NT, GDI operations can be queued. This means that a program running under NT must call GdiFlush() before the DIBSection can be used again after GetHandle() has been called. See the documentation for GdiFlush() for details.

Protected Members

virtual void internalCreate ( LONG Width, LONG Height, WORD BitsPerPixel, BOOL bAlphaChannel );

Create a new empty DIB. Bits are uninitialized. Assumes that no memory is allocated before the call.

virtual void freeMembers ();

Deletes memory allocated by member variables.

virtual HANDLE createCopyHandle ();

Creates a copy of the current bitmap in a global memory block and returns a handle to this block.

virtual void initPointers ();

Set color table pointer & pointer to bits based on m_pBMI.


CFileSource

#include "filesrc.h"

Derived from: public CDataSource

This is a class which takes a file as a source of picture data.

Restriction: If memory-mapped files are not available, this class reads all data into memory _before_ decoding can start.

Public Members

CFileSource ();

virtual ~CFileSource ();

virtual int Open ( const char * pszFName );

virtual void Close ();


CJPEGDecoder

#include "jpegdec.h"

Derived from: public CPicDecoder

JPEG file decoder. Uses the independent JPEG group's library to do the actual conversion.

Public Members

CJPEGDecoder ();

Creates a decoder

~CJPEGDecoder ();

Destroys a decoder

void SetFast ( BOOL bFast );

TRUE (the default) selects fast but sloppy decoding.

Protected Members

void DoDecode ();

Sets up the jpeg library data source and error handler and calls the jpeg decoder.


CObject

#include "stdpch.h"

This class is the base class for all objects used in the library. Its definition is empty for all but Microsoft VC++ compiles.


CPicDecoder

#include "picdec.h"

Derived from: public CObject

CPicDecoder is an abstract base class. It defines common routines for all decoders. Decoders for specific file formats can be derived from this class. Objects of this class interact with a CDataSource to decode bitmaps.

Public Members

CPicDecoder ();

Empty constructor. The actual initialization takes place in a derived class.

virtual ~CPicDecoder ();

Destructor. Frees memory allocated.

virtual void MakeBmpFromFile ( const char * pszFName, CBmp * pBmp, int BPPWanted = 0 );

Decodes a picture in a file and stores the results in pBmp. BPPWanted is the number of bits per pixel in the bitmap returned. Valid values for BPPWanted are 8, 24, and 0. 0 means 'keep the input format'. Decoding a true-color image to 8 bpp is not supported.

void MakeBmpFromResource ( int ResourceID, CBmp * pBmp, int BPPWanted = 0 );

Decodes a picture in a resource by creating a resource data source and calling MakeBmp with this data source. BPPWanted is the number of bits per pixel in the bitmap returned. Valid values for BPPWanted are 8, 24, and 0. 0 means 'keep the input format'. Decoding a true-color image to 8 bpp is not supported.

virtual void MakeBmp ( CDataSource * pDataSrc, CBmp * pBmp, int BPPWanted = 0 );

Decodes a picture by getting the encoded data from pDataSrc. Stores the results in pBmp. BPPWanted is the number of bits per pixel in the bitmap returned. Valid values for BPPWanted are 8, 24, and 0. 0 means 'keep the input format'. Decoding a true-color image to 8 bpp is not supported.

static void SetTraceConfig ( int Level, char * pszFName );

Sets the amount and destination of debug traces output by the debug version. pszFName contains either a valid file name or is NULL. If it contains a file name, this file is used to store debug information. If pszFName is NULL, the destination is either the MSVC debug console or stderr depending on the version of the library. Valid values for Level are:

0: Trace only errors.
1: Trace top-level calls.
2: Trace picture format information
3: Trace all miscellaneous info.

The trace configuration is global to all decoders.

static void Trace ( int TraceLevel, char * pszMessage );

Called to output status messages to the current debug console

Protected Members

virtual void DoDecode ();

Implements the actual decoding process. Uses variables local to the object to retrieve and store the data. Implemented in derived classes.

This routine should never be called. It's here so derived classes can override MakeDIB directly if they want to. (CAnyDecoder does this).


CPictDecoder

#include "pictdec.h"

Derived from: public CPicDecoder

This class decodes macintosh PICT files with 1,2,4,8,16 and 32 bits per pixel as well as PICT/JPEG. If an alpha channel is present in a 32-bit-PICT, it is decoded as well. The PICT format is a general picture file format and can contain a lot of other elements besides bitmaps. These elements are ignored.

There are several opcodes for which I did not find examples. I have marked the appropriate code as "untested". It'll probably work anyway.

Public Members

CPictDecoder ( CJPEGDecoder * pJPEGDecoder );

Creates a decoder. A JPEG decoder is needed to decode PICT files containing JPEGs.

virtual ~CPictDecoder ();

Destroys a decoder.

Protected Members

virtual void DoDecode ();

Does the actual decoding after a data source has been set up.


CPNGDecoder

#include "pngdec.h"

Derived from: public CPicDecoder

PNG file decoder. Uses LibPng to do the actual decoding. PNG supports many pixel formats not supported by paintlib. These pixel formats are converted to the nearest paintlib equivalent. Images with less or more than 8 bits per channel are converted to 8 bits per channel. Images with 16-bit palettes or grayscale images with an alpha channel are returned as full 32-bit RGBA bitmaps.

Public Members

CPNGDecoder ();

Creates a decoder

virtual ~CPNGDecoder ();

Destroys a decoder

Protected Members

virtual void DoDecode ();

Main decoder routine. Reads the header, creates the bitmap, reads the palette, and reads the image data.


CResourceSource

#include "ressrc.h"

Derived from: public CDataSource

This is a class which takes a windows resource as a source of picture data.

Public Members

CResourceSource ();

virtual ~CResourceSource ();

virtual int Open ( int ResourceID, char * pResType = NULL );

virtual void Close ();


CTextException

#include "except.h"

Derived from: public CObject

An object of this class is thrown by other classes when an error occurs. It contains an error code and a string describing the error. The error code is meant to be used internally in the program; the descriptive string can be output to the user. Error codes and strings do not correspond 1:1. The strings are more precise.

Public Members

CTextException ( int Code, const char * pszErr );

Creates an exception.

CTextException ( const CTextException& ex );

Copy constructor.

virtual ~CTextException ();

Destroys an exception

virtual int GetCode () const;

Returns the code of the error that caused the exception. Valid error codes are:

ERR_WRONG_SIGNATURE (1): Expected file signature not found.

ERR_FORMAT_UNKNOWN (2): Unexpected data encountered. This probably indicates a corrupt file or an unknown file sub-format.

ERR_PATH_NOT_FOUND (3), ERR_FILE_NOT_FOUND (4), ERR_ACCESS_DENIED (5): Problems with the file system.

ERR_FORMAT_NOT_SUPPORTED (6): Known but unsupported format.

ERR_INTERNAL (7): Kaputt. Tell me about it.

ERR_UNKNOWN_FILE_TYPE (8): Couldn't recognize the file type.

ERR_DIB_TOO_LARGE (9): Maximum size for 1 bmp was exceeded. (See MAX_BITMAP_SIZE above for an explanation).

ERR_NO_MEMORY (10): Out of memory.

ERR_END_OF_FILE (11): End of file reached before end of image.

virtual operator const char * () const;

This operator allows the exception to be treated as a string whenever needed. The string contains the error message.


CTGADecoder

#include "tgadec.h"

Derived from: public CPicDecoder

Targa file decoder. Decodes 8, 15, 16, 24 and 32 bpp targa files (compressed and uncompressed) and returns an 8 or 32 bpp CBitmap. Preserves the alpha channel.

Public Members

CTGADecoder ();

Creates a decoder

virtual ~CTGADecoder ();

Destroys a decoder

Protected Members

virtual void DoDecode ();

Main decoder routine. Reads the header, Creates the bitmap, reads the palette, and reads the image data.


CTIFFDecoder

#include "tiffdec.h"

Derived from: public CPicDecoder

TIFF file decoder. Uses LIBTIFF to do the actual conversion.

Public Members

CTIFFDecoder ();

Creates a decoder

virtual ~CTIFFDecoder ();

Destroys a decoder

Protected Members

virtual void DoDecode ();

Sets up LIBTIFF environment and calls LIBTIFF to decode an image.


CWinBmp

#include "winbmp.h"

Derived from: public CBmp

This is the windows version of CBmp. The internal storage format is a windows DIB. It supports all color depths allowed by windows: 1, 4, 8, 16, 24, and 32 bpp.

The subset of the windows DIB format supported is as follows: The DIB is stored so that header, palette, and bits are in one buffer. The bottom line is stored first (biHeight must be > 0) and the data is uncompressed (BI_RGB). Color tables for 16, 24, and 32 bpp are not supported. biClrUsed is always 0. The palette mode is DIB_RGB_COLORS. DIB_PAL_COLORS is not supported.

Note that almost all real-life DIBs conform to this subset anyway, so there shouldn't be any problems.

In the current version, some functions (notably CreateCopy) only support 8 and 32 bpp. Sorry!

Public Members

virtual ~CWinBmp ();

Destroys the bitmap.

virtual long GetMemUsed ();

Returns the amount of memory used by the object.

long GetBytesPerLine ();

Returns number of bytes used per line.

virtual void CreateRes ( int ID );

Loads a bitmap from a windows resource (.rc or .res linked to the exe). Fails if the bitmap is compressed.

CSize& GetSize ();

Returns the size of the bitmap in pixels

BITMAPINFOHEADER * GetBMI ();

Access the windows bitmap structure. Using this structure, all standard DIB manipulations can be performed.

void SaveAsBmp ( const char * pszFName );

Saves the DIB in windows bmp format.

virtual void Draw ( CDC* pDC, int x, int y, DWORD rop = SRCCOPY );

Draws the bitmap on the given device context using StretchDIBits.

virtual void StretchDraw ( CDC* pDC, int x, int y, double Factor, DWORD rop = SRCCOPY );

Draws the bitmap on the given device context using StretchDIBits. Scales the bitmap by Factor.

virtual BOOL DrawExtract ( CDC* pDC, CPoint pntDest, CRect rcSrc );

Draws a portion of the bitmap on the given device context

void ToClipBoard ();

Puts a copy of the DIB in the clipboard

static long GetMemNeeded ( LONG width, LONG height, WORD BitsPerPixel );

Returns memory needed by a bitmap with the specified attributes.

static long GetBitsMemNeeded ( LONG width, LONG height, WORD BitsPerPixel );

Returns memory needed by bitmap bits.

Protected Members

virtual void internalCreate ( LONG Width, LONG Height, WORD BitsPerPixel, BOOL bAlphaChannel );

Create a new empty DIB. Bits are uninitialized. Assumes that no memory is allocated before the call.

virtual void internalCreate ( BITMAPINFOHEADER* pBMI );

Creates a CWinBmp from an existing bitmap pointer. Assumes that no memory is allocated before the call.

virtual void freeMembers ();

Deletes memory allocated by member variables.

virtual void initLineArray ();

Initializes internal table of line addresses.


Globals

#include "bitmap.h"
MAX_BITMAP_SIZE

This constant defines the maximum amount of memory that a bitmap may use. If more memory would be used by one bitmap, an exception is raised. If MAX_BITMAP_SIZE isn't defined, no checks for huge bitmaps are performed. This is the current default.

This constant was defined to prevent inefficient virtual memory systems (Windows 95 ;-) from thrashing when huge bitmaps are loaded.

RGBA_BLUE, RGBA_GREEN, RGBA_RED, and RGBA_ALPHA

These constants define the order of the channels in an image. To reference a particular channel in a pixel, add one of these constants to the pixel address. The constants can be changed if nessesary to change the channel ordering. The contents of RGBA_ALPHA are only valid if HasAlpha() is TRUE.

RGBAPIXEL

The data type for a 32-bit pixel. The channels in this pixel are arranged according to the constants RGBA_BLUE, RGBA_GREEN, RGBA_RED, and RGBA_ALPHA.



#include "config.h"

Contains configuration information.



#include "jmemsrc.h"

Defines a custom data source for LIBJPEG



#include "optable.h"

Table of the first 200 or so PICT opcodes with size & description. Mostly stolen from pict2pbm. I hope they don't mind.



#include "qdraw.h"

This file defines the data structures used in pict files. They correspond to the appropriate MAC QuickDraw structs. See QuickDraw docs for an explanation of these structs.



#include "stdpch.h"

Contains most system-specific includes and definitions. On windows systems, it corresponds to stdafx.h. On other systems, the appropriate data types and macros are declared here.

This file defines the basic data types (BOOL, BYTE, WORD,...) and some debug macros.

BOOL, FALSE, TRUE

BOOL is the type for boolean values. Variables of this type should only have the values TRUE (1) and FALSE (0).

BYTE

8 bits of unsigned data.

WORD

An unsigned integer with 16 bits. Due to windows madness, this is not nessesarily the size of a machine word!

LONG

A signed 32-bit integer.

ULONG

An unsigned 32-bit integer.

TRACE (char * pszFormat, ...);

In the debug version (_DEBUG defined), this macro outputs a string to the current debug console. In the release version, it expands to nothing. The parameters correspond to those of printf.

ASSERT (BOOL b);

This is an assert for debug purposes. In the debug version (_DEBUG defined), it causes a program halt if b is FALSE. In the release version, nothing is done. (Note: The parameter is not evaluated in release mode, so constructs like ASSERT (pF = fopen ("bla")) will not do what is expected.)



#include "tga.h"

Defines structures and constants present in TGA files.



#include "tif_msrc.h"

Custom data source for libtiff. Assumes all data is in memory at start.



#include "windefs.h"

Windows Bitmap Struct Definitions

Contains the definitions for the data structures used in windows bitmap files. For windows apps, they are already defined - but not with these names.

The WINRGBQUAD, WINBITMAPFILEHEADER, WINBITMAPINFOHEADER, and WINBITMAPINFO structs are defined as RGBQUAD etc. in the windows header files. See the windows documentation for details.