18 os <<
'(' << il.
x <<
',' << il.
y <<
')';
23 os <<
'[' <<
id.w <<
',' <<
id.h <<
']';
29 img(bufferBlockSize(id.w, id.h)), dim(id),
30 blkPerLine(bufferBlocksPerLine(id.w))
35 mv.dim.w = mv.dim.h = 0;
46 dim.
w = data[0] | (data[1] << 8);
47 dim.
h = data[2] | (data[3] << 8);
53 for (
int y = 0; y <
dim.
h; ++y) {
56 for (
int x = 0; x <
dim.
w; ++
data, ++dest, x += 8) {
64 const std::vector<char> &
data 67 if (data.size() < 5) {
71 dim.
w = data[0] | (data[1] << 8);
72 dim.
h = data[2] | (data[3] << 8);
74 if (data.size() < ((
dim.
w / 8 + ((
dim.
w % 8) ? 1 : 0)) *
dim.
h + 4)) {
83 std::vector<char>::const_iterator citer = data.cbegin() + 4;
85 for (
int y = 0; y <
dim.
h; ++y) {
88 for (
int x = 0; x <
dim.
w; ++citer, ++dest, x += 8) {
100 mv.dim.w = mv.dim.h = 0;
124 if ((newdim.
w < 0) || (newdim.
h < 0)) {
129 if (newdim.
empty()) {
131 }
else if (newdim !=
dim) {
159 for (
int y = 0; y <
dim.
h; ++y, ++spot, ++otherspot) {
161 for (
int x = 0; x < (
blocksPerLine() - 1); ++x, ++spot, ++otherspot) {
162 if (*spot != *otherspot) {
167 if ((*spot & mask) != (*otherspot & mask)) {
176 if ((py >
dim.
h) || (py < 0)) {
226 return Pixel(
this, il, dir);
303 return (*a & m) != 0;
310 *a = (*a & ~m) | (s ? m : 0);
317 return ((*a = (*a & ~m) ^ m) & m) != 0;
386 *dest = (*dest & ~mask) | (src & mask);
394 *dest = (*dest & ~mask) | (~src & mask);
402 *dest = (*dest & ~mask) | ((src & *dest) & mask);
418 *dest = (*dest & ~mask) | ((src ^ *dest) & mask);
457 for (; siter !=
EndPixel(); ++diter, ++siter) {
469 bool swapped =
false;
511 std::int16_t stop = ul.
x +
id.w;
522 for (++ul.
x; modmask && (ul.
x < stop); ++ul.
x) {
528 for (
int loop = 0; loop <
id.h; offset +=
blocksPerLine(), ++loop
533 while (ul.
x < stop) {
548 for (
int loop = 0; loop <
id.h; offset +=
blocksPerLine(), ++loop) {
559 ) : pos(-1, -1), blk(nullptr),
576 if ((il.
x != -1) && (il.
y != -1)) {
765 (cp.
pos.
x == -1) && (cp.
pos.
y == -1)
std::uintptr_t PixelBlock
The type used to hold pixel values, one bit per pixel.
constexpr ImageDimensions clip(const ImageDimensions &dim, const ImageLocation &loc=ImageLocation(0, 0)) const
Returns a region clipped to fit within this object's dimensions.
const ImageDimensions & dimensions() const
Returns the dimensions of the image.
The total number of supported operations.
boost::error_info< struct Info_ImageDimensions, ImageDimensions > ImageErrorDimensions
Image dimensions relevant to the error.
ImageDimensions dim
The dimensions of the image to iterate over; can be used to limit the portion visited by the iterator...
bool empty() const
Returns true if there is no image data.
The base class for errors related to the use of images.
Stores a location within an image.
void invertLines(int start, int height)
Toggles the state of all pixels of the given contiguous horizontal lines.
std::int16_t y
Vertical coordinate.
PixelBlock mask
The mask used to isolate the referenced pixel.
Pixel pixel(const ImageLocation &il, Direction dir=HorizInc)
Returns a Pixel (iterator) to iterate across the image starting from the given location.
std::int16_t x
Horizontal coordinate.
ImageLocation startPosition(Direction dir=HorizInc) const
Returns the starting location needed to iterate over the entire image in the given direction...
const PixelBlock * bufferLine(int py) const
Returns a pointer to the start of the given line.
constexpr bool empty() const
True if the dimensions indicate zero area.
void(* OpFunction)(PixelBlock *dest, const PixelBlock &src, const PixelBlock &mask)
static bool oporbit(bool dest, bool src)
ImageLocation pos
The location of the referenced pixel on the source image.
void swap(NddArray< T > &one, NddArray< T > &two)
Makes NddAray meet the requirements of Swappable to assist in using std::swap().
const std::vector< PixelBlock > & data() const
Provides access to the internal vector storing the image data.
bool state() const
Returns the state of the referenced pixel.
A forward and output iterator that visits each location of the image.
static constexpr int bufferBlocksPerLine(int width)
Returns the number of PixelBlock objects that will be used for each horizontal line of an image of th...
constexpr ImageDimensions maxExtent(const ImageDimensions &dim) const
Returns new dimensions that are minimally large enough to fit this dimension and the given dimension...
BppImage & operator=(BppImage &&mv)
Move assignment.
constexpr ConstPixel()
Construct a ConstPixel to nowhere.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
void invert()
Toggles the state of all pixels.
std::ostream & operator<<(std::ostream &os, const ImageLocation &il)
Writes an ImageLocation object to a stream in human readable form.
Direction dir
The direction to move when incremented.
const ImageLocation & location() const
Returns the coordinates of the referenced pixel relative to this object's origin. ...
static const OpFunction OpFunctions[OpTotal]
Functions implementing the operations listed in Operation one PixelBlock at a time.
Data with an image to parse was too short to hold the image.
PixelBlock * blk
The PixelBlock containing the referenced pixel.
static void opxor(BppImage::PixelBlock *dest, const BppImage::PixelBlock &src, const BppImage::PixelBlock &mask)
bool invertPixel(const ImageLocation &il)
Toggles the state of a pixel.
Stores the dimensions of an image.
Pixel begin()
Returns a Pixel (iterator) to the upper left of the image.
The Y coordinate will be incremented.
void patternLines(int start, int height, PixelBlock val)
Writes a pattern of pixles to a set of contiguous horizontal lines.
ConstPixel cbegin() const
Returns a ConstPixel (iterator) to the upper left of the image.
void blankImage(bool state)
Changes the state of every pixel in the image to the given state.
std::vector< PixelBlock > img
The image data.
Performs a bitwise exclusive-or operation with the destination and source data, and places the result...
static bool opsetbit(bool dest, bool src)
void write(const BppImage *const src, const ImageLocation &destLoc, const ImageLocation &srcLoc, const ImageDimensions &srcSize, Direction srcDir=HorizInc, Operation op=OpSet)
Writes the specified portion of the source into this image.
The Y coordinate will be decremented.
void origdimloc(const ImageLocation &o, const ImageDimensions &d, const ImageLocation &p)
Changes the origin, dimensions, and relative position of this object.
static bool opxorbit(bool dest, bool src)
The Pixel or ConstPixel iterator object was dereferenced when in at the end.
A problem with image bounds, such as the use of a location beyond the image's dimensions.
ImageDimensions dim
The dimensions of the image.
bool operator==(const BppImage &other) const
Returns true if the contents of the two images are identical.
static constexpr std::size_t bufferBlockSize(int w, int h)
Returns the size of an image buffer as the number of PixelBlock PixelBlocks needed to store an image ...
ConstPixel & operator++()
Pre-increment operator.
static void opset(BppImage::PixelBlock *dest, const BppImage::PixelBlock &src, const BppImage::PixelBlock &mask)
Can be used as an end iterator to avoid making a whole iterator.
void drawBox(ImageLocation ul, ImageDimensions id, Operation op=OpSet)
Draws a box into this image.
int size() const
Returns the number of pixels that make up the image.
The X coordinate will be decremented until reaching zero.
Pixel end()
Returns a Pixel end iterator.
int blkPerLine
Number of PixelBlocks used for each horizontal line.
void swapAxes()
Swaps the dimensions's axes.
The X coordinate will be incremented until reaching the width limit.
ImageLocation orig
Upper left corner of the image to limit the iteration to a portion of the whole image.
const ImageLocation & origin() const
Returns this object's origin used to limit the area of the source image that will be visited...
bool state(const ImageLocation &il) const
Returns the state of the image pixel of the requested location.
ConstPixel & operator=(const ConstPixel &)=default
Obvious assignment operator.
Direction
Controls the direction ConstPixel and Pixel objects will move across the image when the object is inc...
void resize(const duds::ui::graphics::ImageDimensions &newdim)
Changes the size of the image.
ImageDimensions MaxExtent(const BppImage *i0, const BppImage *i1)
Returns the maximum extent of the dimensions of two bit-per-pixel images.
bool toggle()
Toggles the state of the pixel.
static bool opandbit(bool dest, bool src)
void clear()
Removes all image data.
Operation
Tells how to modify the destination pixel with the source pixel data.
Indicates the image has zero size when an operation requires some image data.
BppImage()
Make an empty image with zero size.
static bool opnotbit(bool dest, bool src)
bool(* OpBitFunction)(bool dest, bool src)
static void opand(BppImage::PixelBlock *dest, const BppImage::PixelBlock &src, const BppImage::PixelBlock &mask)
A forward iterator like class that visits each location of the image or a subset of the image...
void swap(BppImage &other)
Swap two images.
void bufferSpot(PixelBlock *(&addr), PixelBlock &mask, const ImageLocation &il)
Provides the location of the specified pixel inside the image data.
constexpr ImageDimensions swappedAxes() const
Returns new dimensions with swapped axes.
bool state() const
Returns the state of the referenced pixel.
General graphics related code.
constexpr bool withinBounds(const ImageLocation &loc) const
Returns true if the given location is within the bounds specified by this object. ...
ConstPixel cpixel(const ImageLocation &il, Direction dir=HorizInc) const
Returns a ConstPixel (iterator) to iterate across the image starting from the given location...
boost::error_info< struct Info_ImageLocation, ImageLocation > ImageErrorLocation
An image location relevant to the error.
static void opor(BppImage::PixelBlock *dest, const BppImage::PixelBlock &src, const BppImage::PixelBlock &mask)
const PixelBlock * buffer() const
Retuns a pointer to the start of image data.
BppImage * src
The image to operate upon.
Assigns the pixels in the destination the same value as the pixels in the source. ...
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
An image that uses a single bit to represent the state of each pixel; a black or white picture...
const ImageDimensions & dimensions() const
Returns this object's dimensions used to limit the area of the source image that will be visited...
int blocksPerLine() const
Returns the number of PixelBlock objects per row in the image data.
std::int16_t height() const
Returns the height of the image.
static const OpBitFunction OpBitFunctions[OpTotal]
Functions implementing the operations listed in Operation one bit at a time.
bool operator==(const ConstPixel &cp) const
Less than obvious equality operator.
static void opnot(BppImage::PixelBlock *dest, const BppImage::PixelBlock &src, const BppImage::PixelBlock &mask)