![]() |
The ZX Ecosystem v5.1.0;_GUI_v3.1.0
|
Definitions of RGB colors, palettes and images.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Classes | |
class | RGBColor |
A RGB color with 8 bits per component. More... | |
class | RGBPalette |
A palette defining a number of RGB colors. More... | |
class | RasterCursor< CELLW, CELLH > |
A cursor to access RasterImage pixels bi-linearly with certain tesselation. More... | |
class | RasterImage< PixelType > |
A 2D matrix of certain type that has contiguous storage. More... | |
class | PalettizedImage< ColorIndex > |
An image that stores pixel colors contiguously as palette indexes. More... | |
Typedefs | |
using | ImageCoordDim = unsigned |
Type for coordinates and dimensions of images. More... | |
using | ThreeBytes = uint8_t[3] |
Auxiliary type needed for RGBImage. More... | |
using | RGBImage = RasterImage< ThreeBytes > |
An image that stores pixel colors contiguously in R-G-B format, 1 byteperpix. More... | |
class RGBColor |
A RGB color with 8 bits per component.
Definition at line 46 of file ColorImages.h.
Public Types | |
using | CompLevel = uint8_t |
A component level, from 0 to 255. More... | |
Static Public Attributes | |
static constexpr double | kMaxRGBDist2 = 255.0 * 255.0 * 3.0 |
Maximum squared Euclidean distance between 2 rgb colors. More... | |
Public Member Functions | |
RGBColor (CompLevel r=0, CompLevel g=0, CompLevel b=0) | |
Default constructor. More... | |
RGBColor (const CompLevel *rgb) | |
Constructor from an array of 3 components in R-G-B order. More... | |
RGBColor (const RGBColor &)=default | |
Moves are just copies. | |
RGBColor (RGBColor &&)=default | |
RGBColor & | operator= (const RGBColor &)=default |
RGBColor & | operator= (RGBColor &&)=default |
CompLevel | r (void) const noexcept |
Return the red component. More... | |
CompLevel | g (void) const noexcept |
Return the green component. More... | |
CompLevel | b (void) const noexcept |
Return the blue component. More... | |
const CompLevel * | rgb (void) const noexcept |
Return the three components in R-G-B order. More... | |
void | rgbRead (CompLevel *rgb) const noexcept |
Fill the three components into RGB. More... | |
void | setR (CompLevel r) noexcept |
Change the red component. More... | |
void | setG (CompLevel g) noexcept |
Change the green component. More... | |
void | setB (CompLevel b) noexcept |
Change the red component. More... | |
void | set (CompLevel r, CompLevel g, CompLevel b) noexcept |
Change all components. More... | |
void | set (const CompLevel *rgb) noexcept |
Change all components in R-G-B order. More... | |
void | vector (const RGBColor &oth, double *rgbv) const noexcept |
Fill RGBV with the three components of a vector going from THIS to OTH. More... | |
double | rgbDistance2 (const RGBColor &oth) const |
Return the squared Euclidean distance between THIS and OTH. | |
void | setFromHTMLString (const std::string &c) |
C must be in '#......' HTML format. Otherwise, throw. | |
std::string | getHTMLString (void) const |
In '#......' HTML format. | |
bool | operator== (const RGBColor &oth) const noexcept |
bool | operator!= (const RGBColor &oth) const noexcept |
std::string | to_string (void) const |
Return a text describing the color. | |
using RGBColor::CompLevel = uint8_t |
A component level, from 0 to 255.
Definition at line 51 of file ColorImages.h.
Default constructor.
Definition at line 58 of file ColorImages.h.
|
inline |
Constructor from an array of 3 components in R-G-B order.
Definition at line 61 of file ColorImages.h.
|
inlinenoexcept |
Return the red component.
Definition at line 73 of file ColorImages.h.
|
inlinenoexcept |
Return the green component.
Definition at line 76 of file ColorImages.h.
|
inlinenoexcept |
Return the blue component.
Definition at line 79 of file ColorImages.h.
|
inlinenoexcept |
Return the three components in R-G-B order.
Definition at line 82 of file ColorImages.h.
|
inlinenoexcept |
Fill the three components into RGB.
Definition at line 85 of file ColorImages.h.
|
inlinenoexcept |
Change the red component.
Definition at line 88 of file ColorImages.h.
|
inlinenoexcept |
Change the green component.
Definition at line 91 of file ColorImages.h.
|
inlinenoexcept |
Change the red component.
Definition at line 94 of file ColorImages.h.
Change all components.
Definition at line 97 of file ColorImages.h.
|
inlinenoexcept |
Change all components in R-G-B order.
Definition at line 101 of file ColorImages.h.
|
noexcept |
Fill RGBV with the three components of a vector going from THIS to OTH.
The components are filled in R-G-B order and measure the distance from THIS to OTH (i.e., it is not normalized). RGBV must have room for 3 doubles.
|
inlinenoexcept |
Definition at line 120 of file ColorImages.h.
|
inlinenoexcept |
Definition at line 125 of file ColorImages.h.
|
staticconstexpr |
Maximum squared Euclidean distance between 2 rgb colors.
Definition at line 54 of file ColorImages.h.
class RGBPalette |
A palette defining a number of RGB colors.
Definition at line 146 of file ColorImages.h.
Public Types | |
using | Size = uint32_t |
Size of a palette. More... | |
using | Index = Size |
Index of a color in a palette. More... | |
Public Member Functions | |
RGBPalette (Size s) | |
Constructor: S colors, all (0,0,0). If S is 0, throws. | |
RGBPalette (const RGBColor::CompLevel *rgbs, Size s) | |
Constructor: from an array of R-G-B bytes for S colors. More... | |
RGBPalette (const RGBPalette &)=delete | |
No copies; only moves. | |
RGBPalette & | operator= (const RGBPalette &)=delete |
RGBPalette (RGBPalette &&oth)=default | |
RGBPalette & | operator= (RGBPalette &&)=default |
Size | numColors (void) const noexcept |
Return the number of colors in the palette. More... | |
const RGBColor & | operator[] (Index ind) const |
Read one of the colors. Throw if out of range index. | |
RGBColor & | operator[] (Index ind) |
Read/write one of the colors. Throw if out of range index. | |
Index | closestColor (const RGBColor &col) const noexcept |
Find the closest color in the palette to COL. More... | |
std::string | to_string (void) const |
Return a multi-line description of the palette. | |
using RGBPalette::Size = uint32_t |
Size of a palette.
Definition at line 151 of file ColorImages.h.
using RGBPalette::Index = Size |
Index of a color in a palette.
Definition at line 154 of file ColorImages.h.
RGBPalette::RGBPalette | ( | const RGBColor::CompLevel * | rgbs, |
Size | s | ||
) |
Constructor: from an array of R-G-B bytes for S colors.
If S is 0, throws.
|
inlinenoexcept |
Return the number of colors in the palette.
Definition at line 173 of file ColorImages.h.
class RasterCursor |
A cursor to access RasterImage pixels bi-linearly with certain tesselation.
This class is defined to do optimal movements left to right / top to bottom and optimal accesses to the currently pointed pixel. The tessellation is defined with CELLW and CELLH; the cursor will move following the top-left pixel of each cell defined by these lengths. The tessellation does not need to fit the image size exactly.
Definition at line 226 of file ColorImages.h.
Public Member Functions | |
RasterCursor (ImageCoordDim wimage, ImageCoordDim himage) | |
Default constructor / position constructor for a given sized image. More... | |
RasterCursor (const RasterCursor &)=default | |
RasterCursor (RasterCursor &&)=default | |
RasterCursor & | operator= (const RasterCursor &)=default |
RasterCursor & | operator= (RasterCursor &&)=default |
constexpr ImageCoordDim | cellW (void) const noexcept |
To get the tesselation in X from any RasterCursor object. More... | |
constexpr ImageCoordDim | cellH (void) const noexcept |
To get the tesselation in Y from any RasterCursor object. More... | |
void | setRegion (ImageCoordDim xmin, ImageCoordDim xlength, ImageCoordDim ymin, ImageCoordDim ylength) |
Change the region of the image reachable by the cursor. More... | |
void | resetRegion (void) |
Change area of the image reachable by the cursor to the whole image. More... | |
bool | inside (void) const noexcept |
Return TRUE if the cursor is inside the current region of the image. More... | |
RasterCursor< 1, 1 > | subCursor (void) const |
Return a cursor limited to the cell where this cursor is. More... | |
void | set (ImageCoordDim xc, ImageCoordDim yc) noexcept |
Set the cursor to the given cell coords. Do not throw if outside. More... | |
void | reset (void) noexcept |
Set the cursor to the top-left cell coords of the current region. More... | |
ImageCoordDim | x (void) const noexcept |
Return the X-cell coordinate within current region. More... | |
ImageCoordDim | y (void) const noexcept |
Return the Y-cell coordinate within current region. More... | |
ImageCoordDim | xPixel (void) const noexcept |
Return the X-pixel coordinate within current region. More... | |
ImageCoordDim | yPixel (void) const noexcept |
Return the Y-pixel coordinate within current region. More... | |
size_t | globalOffset (void) const |
Return the linear offset within the image corresponding to cursor. More... | |
bool | right (void) noexcept |
Move the cursor one cell to the right (no row change). More... | |
bool | forward (void) noexcept |
Move the cursor one cell forward. More... | |
bool | lastChangedRow (void) const noexcept |
Return TRUE if the last movement caused a change of row. More... | |
std::string | to_string (bool summary=true) const |
Return a text describing the cursor. More... | |
|
inline |
Default constructor / position constructor for a given sized image.
The image size must be in pixels. After creation, the cursor is at the top-left pixel of the image and it is allowed to reach any part of the image (see setRegion()).
Definition at line 234 of file ColorImages.h.
|
inlineconstexprnoexcept |
To get the tesselation in X from any RasterCursor object.
Definition at line 248 of file ColorImages.h.
|
inlineconstexprnoexcept |
To get the tesselation in Y from any RasterCursor object.
Definition at line 251 of file ColorImages.h.
|
inline |
Change the region of the image reachable by the cursor.
The limits are given in one-pixel coordinates, not in cells. They can correspond to a region smaller than a cell. If the region goes beyond the image size, it is readjusted to cover only existing image. Also reset cursor position to the top-left pixel of that region, which get cell coords (0,0) from now on.
Definition at line 259 of file ColorImages.h.
|
inline |
Change area of the image reachable by the cursor to the whole image.
Definition at line 287 of file ColorImages.h.
|
inlinenoexcept |
Return TRUE if the cursor is inside the current region of the image.
Definition at line 290 of file ColorImages.h.
|
inline |
Return a cursor limited to the cell where this cursor is.
The tesselation of the returned cursor is of 1 pixel. It is placed at the top-left corner of the current cell, i.e., at the same position as the current cursor.
Definition at line 298 of file ColorImages.h.
|
inlinenoexcept |
Set the cursor to the given cell coords. Do not throw if outside.
The pixel pointed by the cursor will be the top-left one of that cell. The changed-row indicator is set to false (see lastChangedRow()). XC and YC must be specified within the current region.
Definition at line 308 of file ColorImages.h.
|
inlinenoexcept |
Set the cursor to the top-left cell coords of the current region.
Definition at line 312 of file ColorImages.h.
|
inlinenoexcept |
Return the X-cell coordinate within current region.
Unpredictable value if not inside (see inside()).
Definition at line 316 of file ColorImages.h.
|
inlinenoexcept |
Return the Y-cell coordinate within current region.
Unpredictable value if not inside (see inside()).
Definition at line 321 of file ColorImages.h.
|
inlinenoexcept |
Return the X-pixel coordinate within current region.
Unpredictable value if not inside (see inside()).
Definition at line 326 of file ColorImages.h.
|
inlinenoexcept |
Return the Y-pixel coordinate within current region.
Unpredictable value if not inside (see inside()).
Definition at line 330 of file ColorImages.h.
|
inline |
Return the linear offset within the image corresponding to cursor.
This ignores region: the offset is in the whole image dimensions provided when the cursor was created.
Definition at line 335 of file ColorImages.h.
|
inlinenoexcept |
Move the cursor one cell to the right (no row change).
If it was at the last cell of the row or outside the current region, do not do anything and return FALSE.
Definition at line 340 of file ColorImages.h.
|
inlinenoexcept |
Move the cursor one cell forward.
Change cell row and do carrier return if goes out of the row. Return FALSE if gone out of the current region in the image.
Definition at line 347 of file ColorImages.h.
|
inlinenoexcept |
Return TRUE if the last movement caused a change of row.
Initially or after any set/reset, it is false.
Definition at line 360 of file ColorImages.h.
|
inline |
Return a text describing the cursor.
Definition at line 364 of file ColorImages.h.
class RasterImage |
A 2D matrix of certain type that has contiguous storage.
A RasterImage stores contiguously a number of pixel values of certain type PixelType and can be accessed both linearly and bi-linearly through the RasterCursor class. It can be in undefined (empty) state.
Definition at line 433 of file ColorImages.h.
Public Member Functions | |
RasterImage (void)=default | |
Default constructor: undefined content. | |
RasterImage (ImageCoordDim w, ImageCoordDim h) | |
Constructor: image of certain size; content not set, just stored. More... | |
RasterImage (const RasterImage &)=delete | |
Copies forbidden; moves leave the original without content. | |
RasterImage (RasterImage &&oth) | |
RasterImage & | operator= (const RasterImage &)=delete |
RasterImage & | operator= (RasterImage &&oth) |
bool | empty (void) const noexcept |
ImageCoordDim | width (void) const noexcept |
ImageCoordDim | height (void) const noexcept |
size_t | numPixels (void) const noexcept |
template<ImageCoordDim CELLW = 1, ImageCoordDim CELLH = 1> | |
RasterCursor< CELLW, CELLH > | makeCursor (void) const |
template<ImageCoordDim CELLW = 1, ImageCoordDim CELLH = 1> | |
PixelType & | pixel (const RasterCursor< CELLW, CELLH > &cursor) |
template<ImageCoordDim CELLW = 1, ImageCoordDim CELLH = 1> | |
const PixelType & | pixel (const RasterCursor< CELLW, CELLH > &cursor) const |
PixelType * | contigContent (void) noexcept |
const PixelType * | contigContent (void) const noexcept |
|
inline |
Constructor: image of certain size; content not set, just stored.
Throw if the size does not match exactly the tesselation.
Definition at line 442 of file ColorImages.h.
|
inline |
Definition at line 449 of file ColorImages.h.
|
inline |
Definition at line 451 of file ColorImages.h.
|
inlinenoexcept |
Definition at line 457 of file ColorImages.h.
|
inlinenoexcept |
Definition at line 458 of file ColorImages.h.
|
inlinenoexcept |
Definition at line 459 of file ColorImages.h.
|
inlinenoexcept |
Definition at line 460 of file ColorImages.h.
|
inline |
Definition at line 463 of file ColorImages.h.
|
inline |
Definition at line 467 of file ColorImages.h.
|
inline |
Definition at line 471 of file ColorImages.h.
|
inlinenoexcept |
Definition at line 474 of file ColorImages.h.
|
inlinenoexcept |
Definition at line 476 of file ColorImages.h.
class PalettizedImage |
An image that stores pixel colors contiguously as palette indexes.
Those indexes must be enough to store any palette color, but do not have to coincide with the RGBPalette::Index type, which is intended for managing palettes, not to store images efficiently. A PalettizedImage can be created empty and becomes empty if moved to another one; empty palettized images throw in operations.
Definition at line 529 of file ColorImages.h.
Public Types | |
using | Base = RasterImage< ColorIndex > |
Public Member Functions | |
PalettizedImage (void)=default | |
Default constructor: emptied palettized image. | |
PalettizedImage (const RGBPalette &pal, unsigned w, unsigned h) | |
Create storage for an image with the given palette and dimensions. More... | |
PalettizedImage (const RGBPalette &pal, const RGBImage &img) | |
Build a palettized version of RGBIMG. More... | |
PalettizedImage (const PalettizedImage &)=delete | |
Copies forbidden; moves leave the original without content. | |
PalettizedImage (PalettizedImage &&oth) | |
PalettizedImage & | operator= (const PalettizedImage &)=delete |
PalettizedImage & | operator= (PalettizedImage &&oth) |
const RGBPalette & | palette (void) const noexcept |
RGBImage | toRGBImg (void) const |
Create and return a new RGBImage with the content of this image. More... | |
![]() | |
RasterImage (void)=default | |
Default constructor: undefined content. | |
RasterImage (ImageCoordDim w, ImageCoordDim h) | |
Constructor: image of certain size; content not set, just stored. More... | |
RasterImage (const RasterImage &)=delete | |
Copies forbidden; moves leave the original without content. | |
RasterImage (RasterImage &&oth) | |
RasterImage & | operator= (const RasterImage &)=delete |
RasterImage & | operator= (RasterImage &&oth) |
bool | empty (void) const noexcept |
ImageCoordDim | width (void) const noexcept |
ImageCoordDim | height (void) const noexcept |
size_t | numPixels (void) const noexcept |
RasterCursor< CELLW, CELLH > | makeCursor (void) const |
ColorIndex & | pixel (const RasterCursor< CELLW, CELLH > &cursor) |
const ColorIndex & | pixel (const RasterCursor< CELLW, CELLH > &cursor) const |
ColorIndex * | contigContent (void) noexcept |
const ColorIndex * | contigContent (void) const noexcept |
using PalettizedImage< ColorIndex >::Base = RasterImage<ColorIndex> |
Definition at line 533 of file ColorImages.h.
|
inline |
Create storage for an image with the given palette and dimensions.
Throw if PAL is not compatible with ColorIndex. PAL must outlive this object since a pointer is internally kept.
Definition at line 541 of file ColorImages.h.
|
inline |
Build a palettized version of RGBIMG.
Definition at line 549 of file ColorImages.h.
|
inline |
Definition at line 564 of file ColorImages.h.
|
inline |
Definition at line 566 of file ColorImages.h.
|
inlinenoexcept |
Definition at line 572 of file ColorImages.h.
|
inline |
Create and return a new RGBImage with the content of this image.
Definition at line 576 of file ColorImages.h.
using ImageCoordDim = unsigned |
#include <ColorImages.h>
Type for coordinates and dimensions of images.
Definition at line 210 of file ColorImages.h.
using ThreeBytes = uint8_t[3] |
#include <ColorImages.h>
Auxiliary type needed for RGBImage.
[0] -> red, [1] -> green, [2] -> blue
Definition at line 505 of file ColorImages.h.
using RGBImage = RasterImage<ThreeBytes> |
#include <ColorImages.h>
An image that stores pixel colors contiguously in R-G-B format, 1 byteperpix.
Accessing each r-g-b pixel is done as: auto * pix = rgimg.contigContent(); pix[<pixel offset>][0] = 2; pix[<pixel offset>][1] = 3; pix[<pixel offset>][2] = 4;
Definition at line 513 of file ColorImages.h.