classPiiColorBase
#include <PiiColor.h>
A structure that represents a three-channel color.
Inherited by PiiColor< T >, PiiColor4< T >
Description
The data type of the color channels is a template parameter with a
default value of unsigned char. This
should work for most cases because color spaces with more than four
channels or more than eight bits per channel are seldom used.
The generic way of accessing color channels is via the
channel array. In PiiColor, the array can be accessed
with indices from 0 to 2. In PiiColor4, 3 can also be used. (The
array is defined to have space for three elements only, but the
arrangement of classes in memory makes it possible to utilize array
overflow in a constructive fashion.)
In your code, you can utilized the #channel(int) function or color space specific names:
PiiColor<> clr(255, 127, 0); QCOMPARE(clr.channel(1), clr.rgbG); QCOMPARE(clr.rgbG, static_cast<unsigned char>(127)); QCOMPARE(clr.channel(2), clr.hsvV); QCOMPARE(clr.c2, clr.rgbaB);
The syntax is <space><Channel>, where <space> is any of the following: rgb, hsv, hsi, yuv, yiq, xyz, lab, luv, cmyk, rgba. <Channel> is the name of the color channel as a capital letter, e.g. R, G, B, or Y. The R channel of the RGB color space is denoted by rgbR. Furthermore, the channels are aliased with generic names c0, c1 and c2. If possible, the color channel names should be preferred over the channel array for code readability.
NOTE! The order of color channels in the channel array is
opposite to what you probably expect. For example, rgbR corresponds
to channel[2], and rgbB to channel[0]. This allows one to use
PiiColor4<unsigned char> and int interchangeably
on little-endian hardware (such as the PC). It also makes it
possible to use the colors with QRgb. You can, however, use the
channel(int) function to access the channels in the "natural"
order.
See also
Public types
|
typedef PiiColorBaseTraits<
T >::Type
|
The content type. |
Constructors and destructor
|
(
Create a new color with the same value on each color channel. |
|
|
(
Create a new color with the given values for each color channel. |
Public member functions
|
PiiColorBaseTraits<
T >::ConstIterator
|
( )
An stl-style const iterator to the first color channel. |
|
PiiColorBaseTraits<
T >::Iterator
|
( )
An stl-style iterator to the first color channel. |
|
T
|
(
Return the value of the channel denoted by
|
|
( )
Return the average of all color channels as a |
|
|
( )
Return the average of all color channels as a |
|
|
( )
Return the average of all color channels as a |
|
|
( )
Return the average of all color channels as an |
|
|
( )
Return the average of all color channels as a |
|
|
Return the average of all color channels as an
|
|
|
Return the average of all color channels as an
|
|
|
Return the average of all color channels as an
|
|
|
void
|
(
Set the value of a color channel. |
Function details
-
PiiColorBase
(- T value = 0
[inline]Create a new color with the same value on each color channel.
-
PiiColorBase
(- T channel0
- T channel1
- T channel2
[inline]Create a new color with the given values for each color channel.
Note that the order of channels in the channel array is reversed. When you initialize a PiiColor with RGB values, B will be the first channel.
// Parameters: R, G, B PiiColorBase<> pureRed(255, 0, 0); QVERIFY(pureRed.rgbR == 255); QVERIFY(pureRed.c0 == 255); QVERIFY(pureRed.channels[0] == 0); // !
-
An stl-style const iterator to the first color channel.
Note that the first color channel in the RGB space is B.
-
An stl-style iterator to the first color channel.
Note that the first color channel in the RGB space is B.
-
T channel
(- int channelIndex
[inline]Return the value of the channel denoted by
channelIndex.This is a convenience function that returns the channels in "traditional" order (
channel(0)returns the R channel etc.) -
operator char
()[inline]Return the average of all color channels as a
char. -
operator double
()[inline]Return the average of all color channels as a
double. -
operator float
()[inline]Return the average of all color channels as a
float. -
operator int
()[inline]Return the average of all color channels as an
int. -
operator short
()[inline]Return the average of all color channels as a
short. -
operator unsigned char
()[inline]Return the average of all color channels as an
unsignedchar. -
operator unsigned int
()[inline]Return the average of all color channels as an
unsignedint. -
operator unsigned short
()[inline]Return the average of all color channels as an
unsignedshort. -
void setChannel
(- int channelIndex
- T value
[inline]Set the value of a color channel.
This is a convenience function that allows one to index the channels in "traditional" order.
Add a note
Not a single note added yet. Be the first, add yours.