Depending on the capabilities of the operating system, and the relationship of the window to the image, the pixel cache may be a copy of the pixels in the selected window, or it may be the actual image pixels. In any case calling sync() insures that the base image is updated with the contents of the modified pixel cache. The method decode() supports copying foreign pixel data formats into the pixel cache according to the QuantumTypes. The method encode() supports copying the pixels in the cache to a foreign pixel representation according to the format specified by QuantumTypes.
Setting a view using the Pixels class does not cause the number of references to the underlying image to be reduced to one. Therefore, in order to ensure that only the current generation of the image is modified, the Image's modifyImage() method should be invoked to reduce the reference count on the underlying image to one. If this is not done, then it is possible for a previous generation of the image to be modified due to the use of reference counting when copying or constructing an Image.
The pixel view is a small image in which the pixels may be accessed,
addressed, and updated, as shown in the following example, which produces
an image similar to the one on the right (minus lines and text):
// Create base image
Image image(Geometry(254,218), "white");
// Set image pixels to DirectClass representation
//
Ensure that there is only one reference to underlying image
// Allocate pixel view
// Set all pixels in region anchored at 38x36,
with size 160x230 to green.
// Set all pixels in region anchored at 86x72,
with size 108x67 to yellow.
// Set pixel at position 108,94 to red
|
Pixels supports the following methods:
|
|
|
|
|
PixelPacket* | int x_, int y_, unsigned int columns_, unsigned int rows_ | Transfers pixels from the image to the pixel cache as defined by the specified rectangular region. Modified pixels may be subsequently transferred back to the image via sync. |
|
PixelPacket* | int x_, int y_, unsigned int columns_, unsigned int rows_ | Allocates a pixel cache region to store image pixels as defined by the region rectangle. This area is subsequently transferred from the pixel cache to the image via sync. |
|
void | void | Transfers the image cache pixels to the image. |
|
IndexPacket* | void | Returns the PsuedoColor pixel indexes. Only valid for PseudoColor images. The pixel indexes (typically an array of type unsigned short) provide the colormap index (see colorMap) for each pixel in the image. |
|
unsigned int | void | Left ordinate of view |
|
unsigned int | void | Top ordinate of view |
|
unsigned int | void | Width of view |
|
unsigned int | void | Height of view |