Programmer Reference : Common Graphics : Device-independent images
Device-independent images
Conceptually, an image is a two-dimensional array of colors. For storage efficiency, colors in an image are usually encoded as discrete pixel values with a fixed number of bits for each pixel value. There are two common ways in which colors are encoded as pixel values. In the first kind of encoding, the image is restricted to a small set of colors (256 or less). This set is ordered and the pixel values are treated as indices into the list of colors. This encoding requires 8 bits or fewer per pixel. In the second kind of encoding, colors are encoded directly in the pixel values. For example, the red, green, and blue intensities of a color can be encoded as values in the range 0 to 255, requiring 8 bits for each primary and therefore 24 bits for the whole pixel value. For both encodings a palette is required to define the pixel-value-to-color mapping.
Common Graphics provides a class, CgDeviceIndependentImage, that defines a device-independent representation of uncompressed bitmap images with 1, 4, 8, or 24 bits per pixel. The image data format is made public, allowing it to be efficiently manipulated by applications. The same data format is used on all platforms. The data format is as follows:
Scanlines are ordered from top (scanline 0) to bottom (scanline height-1).
The number of bytes representing a scanline is rounded up to an integral multiple specified on image creation (usually 1, 2, or 4 bytes).
In images of depth 1 or 4, the pixels are ordered in each byte from left to right starting at the most significant bit of the byte.
In images of depth greater than 8, the bytes comprising the pixel value are ordered with the most significant byte first.
Device-independent images are created in one of two ways:
Created by the application using application-defined data
Loaded from a file
The following section describes how to create an image using application-defined data. Image file formats are described in a later section.
Last modified date: 01/29/2015