![](https://csdnimg.cn/release/download_crawler_static/4097856/bg5.jpg)
Quantizing levels: the Quantum type and the MaxRGB constant
Each member of the PixelPacket structure is an unsigned integer number, and depending on how
the library was compiled it may be implemented on 8 bits or 16 bits (i.e. the total size of a
PixelPacket is 4*8=32 bits or 4*16=64 bits); thus, the number of quantizing levels for each of the
PixelPacket components can be 2^8=256 or 2^16=65536.
In any case, Magick++ provides the applications with the 'MaxRGB' constant which always
specifies the number of quantizing levels - 1 as available on the particular version of the library
that is being used (e.g. for a library version compiled with 8 bits per PixelPacket component the
MaxRGB constant is 255).
In order to accommodate the implementation-specific values of quantizing levels, Magick++
provides the 'Quantum' data type. This type is an unsigned integer value that may be
implemented as unsigned char, unsigned short int, etc, but it is always guaranteed to be able of
holding all the quantizing levels as available on the particular version of the library that is being
used (i.e. it can always hold the 'MaxRGB' value).
The PixelPacket structure members are of type Quantum, and are in range [0, MaxRGB]:
struct PixelPacket {
Quantum red;
Quantum green;
Quantum blue;
Quantum opacity;
};
The Color class
The Magick++ library provides a class 'Color' that can be assigned to, and from, PixelPacket data
structures, thus facilitating an object-oriented approach for handling PixelPacket data structures.
The 'Color' class is also used as argument type by a number of Magick++ methods that set the
color attributes of various graphical operations.
The following table lists the most important Color methods:
// constructors
Color::Color();
Color::Color(const string& color); // the string 'color' is one of a set of "inbuilt"
// colors: "red", “blue”, "magenta", etc
Color::Color(Quantum red, // parameters in range 0 to MaxRGB
Quantum green,
Quantum blue,
Quantum alpha); // alpha is transparency: 0=opaque, MaxRGB=fully transparent
Color::Color(const PixelPacket& pixel);
// getter functions
Quantum Color::redQuantum();
Quantum Color::greenQuantum();
Quantum Color::blueQuantum();
Quantum Color::alphaQuantum();
// setter functions
void Color::redQuantum(Quantum red);
void Color::greenQuantum(Quantum green);
void Color::blueQuantum(Quantum blue);
void Color::alphaQuantum(Quantum alpha);
// conversion functions to and from PixelPacket
Color::operator PixelPacket() const;
const Color& Color::operator=(const PixelPacket& pixel);