DUDS
Distributed Update of Data from Something
BppImage.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2018 Jeff Jackowski
9  */
10 #ifndef BPPIMAGE_HPP
11 #define BPPIMAGE_HPP
12 
13 #include <vector>
14 #include <cstdint>
15 #include <type_traits>
16 #include <boost/exception/info.hpp>
17 
18 namespace duds { namespace ui {
19 
25 namespace graphics {
26 
27 struct ImageDimensions;
28 
33 struct ImageLocation {
37  std::int16_t x;
41  std::int16_t y;
45  ImageLocation() = default;
54  template <
55  typename Int0,
56  typename Int1,
57  std::enable_if_t<std::is_integral<Int0>::value, bool> = true,
58  std::enable_if_t<std::is_integral<Int1>::value, bool> = true
59  >
60  constexpr ImageLocation(Int0 px, Int1 py) :
61  x((std::int16_t)px), y((std::int16_t)py) { }
65  constexpr bool operator == (const ImageLocation &il) const {
66  return (x == il.x) && (y == il.y);
67  }
71  constexpr bool operator != (const ImageLocation &il) const {
72  return (x != il.x) || (y != il.y);
73  }
77  constexpr ImageLocation operator + (const ImageLocation &il) const {
78  return ImageLocation(x + il.x, y + il.y);
79  }
83  constexpr ImageLocation operator - (const ImageLocation &il) const {
84  return ImageLocation(x - il.x, y - il.y);
85  }
89  constexpr ImageLocation operator + (const ImageDimensions &id) const;
93  constexpr ImageLocation operator - (const ImageDimensions &id) const;
97  void swapAxes() {
98  std::swap(x, y);
99  }
103  constexpr ImageLocation swappedAxes() const {
104  return ImageLocation(y, x);
105  }
106 };
107 
111 std::ostream &operator << (std::ostream &os, const ImageLocation &il);
112 
116 inline void swap(ImageLocation &l0, ImageLocation &l1) {
117  std::swap(l0.x, l1.x);
118  std::swap(l0.y, l1.y);
119 }
120 
129  std::int16_t w;
133  std::int16_t h;
137  ImageDimensions() = default;
146  template <
147  typename Int0,
148  typename Int1,
149  std::enable_if_t<std::is_integral<Int0>::value, bool> = true,
150  std::enable_if_t<std::is_integral<Int1>::value, bool> = true
151  >
152  constexpr ImageDimensions(Int0 dw, Int1 dh) :
153  w((std::int16_t)dw), h((std::int16_t)dh) { }
157  constexpr bool operator == (const ImageDimensions &id) const {
158  return (w == id.w) && (h == id.h);
159  }
163  constexpr bool operator != (const ImageDimensions &id) const {
164  return (w != id.w) || (h != id.h);
165  }
169  constexpr bool empty() const {
170  return !w || !h;
171  }
175  void clear() {
176  w = h = 0;
177  }
182  constexpr bool withinBounds(const ImageLocation &loc) const {
183  return (loc.x >= 0) && (loc.x < w) && (loc.y >= 0) && (loc.y < h);
184  }
189  constexpr bool fits(const ImageDimensions &id) const {
190  return (id.w <= w) && (id.h <= h);
191  }
196  constexpr bool fits(const ImageLocation &loc, const ImageDimensions &id) const {
197  return ((loc.x + id.w) <= w) && ((loc.y + id.h) <= h);
198  }
202  void swapAxes() {
203  std::swap(w, h);
204  }
208  constexpr ImageDimensions swappedAxes() const {
209  return ImageDimensions(h, w);
210  }
215  constexpr ImageDimensions minExtent(const ImageDimensions &dim) const {
216  return ImageDimensions(std::min(w, dim.w), std::min(h, dim.h));
217  }
222  constexpr ImageDimensions maxExtent(const ImageDimensions &dim) const {
223  return ImageDimensions(std::max(w, dim.w), std::max(h, dim.h));
224  }
235  const ImageDimensions &dim,
236  const ImageLocation &loc = ImageLocation(0, 0)
237  ) const {
238  return ImageDimensions(
239  std::max(
240  std::min(dim.w - ((loc.x < 0) ? loc.x : 0), w - std::abs(loc.x)),
241  0 // don't be negative
242  ),
243  std::max(
244  std::min(dim.h - ((loc.y < 0) ? loc.y : 0), h - std::abs(loc.y)),
245  0
246  )
247  );
248  }
249 };
250 
254 std::ostream &operator << (std::ostream &os, const ImageDimensions &id);
255 
259 inline void swap(ImageDimensions &d0, ImageDimensions &d1) {
260  std::swap(d0.w, d1.w);
261  std::swap(d0.h, d1.h);
262 }
263 
269  const ImageDimensions &id
270 ) const {
271  return ImageLocation(x + id.w, y + id.h);
272 }
273 
279  const ImageDimensions &id
280 ) const {
281  return ImageLocation(x - id.w, y - id.h);
282 }
283 
287 typedef boost::error_info<struct Info_ImageLocation, ImageLocation>
292 typedef boost::error_info<struct Info_ImageDimensions, ImageDimensions>
297 typedef boost::error_info<struct Info_ImageDimensions, ImageDimensions>
302 typedef boost::error_info<struct Info_FrameDimensions, ImageDimensions>
304 
305 
321 class BppImage {
322 public:
326  typedef std::uintptr_t PixelBlock;
327 private:
331  std::vector<PixelBlock> img;
341 public:
347  static constexpr std::size_t bufferBlockSize(int w, int h) {
348  return (w / (sizeof(PixelBlock) * 8) +
349  ((w % (sizeof(PixelBlock) * 8)) ? 1 : 0)) * h;
350  }
355  static constexpr std::size_t bufferByteSize(int w, int h) {
356  return bufferBlockSize(w, h) * sizeof(PixelBlock);
357  }
363  static constexpr int bufferBlocksPerLine(int width) {
364  return width / (sizeof(PixelBlock) * 8) +
365  ((width % (sizeof(PixelBlock) * 8)) ? 1 : 0);
366  }
372  static constexpr int bufferBlocksPerLine(ImageDimensions dim) {
373  return dim.w / (sizeof(PixelBlock) * 8) +
374  ((dim.w % (sizeof(PixelBlock) * 8)) ? 1 : 0);
375  }
386  enum Direction {
419  Rotate0DCCW = HorizInc,
425  Rotate90DCCW = VertInc,
432  Rotate180DCCW = HorizDec,
438  Rotate270DCCW = VertDec,
439  };
445  struct EndPixel { };
446  class Pixel;
456  class ConstPixel {
457  public:
458  struct End { };
459  protected:
466  // allow for quick referencing of data; recalc of img array index and
467  // bit position is not always required
471  PixelBlock *blk;
475  PixelBlock mask;
494  public:
498  constexpr ConstPixel() :
499  src(nullptr),
500  blk(nullptr),
501  mask(0),
502  pos(-1, -1),
503  orig(0, 0),
504  dim(0, 0),
505  dir(HorizInc)
506  { }
510  constexpr ConstPixel(const EndPixel) : ConstPixel() { }
514  ConstPixel(const ConstPixel &) = default;
518  ConstPixel(const BppImage *img, const End e);
524  ConstPixel(
525  const BppImage *img,
526  const ImageLocation &il = ImageLocation(0, 0),
527  Direction d = HorizInc
528  );
535  const BppImage *img,
536  int x,
537  int y,
538  Direction d = HorizInc
539  ) : ConstPixel(img, ImageLocation(x, y), d) { }
564  ConstPixel(
565  const BppImage *img,
566  const ImageLocation &o,
567  const ImageDimensions &s,
568  const ImageLocation &p = ImageLocation(0, 0),
569  Direction d = HorizInc
570  );
574  ConstPixel &operator = (const ConstPixel &) = default;
579  ConstPixel &operator = (const Pixel &p);
583  ConstPixel &operator = (const EndPixel) {
584  pos.x = pos.y = -1;
585  blk = nullptr;
586  return *this;
587  }
592  return dir;
593  }
598  dir = d;
599  }
604  bool state() const;
605  /* *
606  * Works like adding a number to increment the ConstPixel and calling
607  * state() on the result, but without making a new ConstPixel object.
608  * @todo This requires an implementation similar to operator+(int).
609  */
610  //bool stateAtOffset(int inc) const;
617  bool operator == (const ConstPixel &cp) const;
621  bool operator == (const EndPixel) const {
622  return (pos.x == -1) && (pos.y == -1);
623  }
627  bool operator != (const ConstPixel &cp) const {
628  return (src != cp.src) || (pos != cp.pos);
629  }
633  bool operator != (const EndPixel) const {
634  return (pos.x != -1) || (pos.y != -1);
635  }
639  ConstPixel &operator ++();
643  ConstPixel operator ++(int) {
644  ConstPixel cp(*this);
645  operator++();
646  return cp;
647  }
648  //operator +(int);
649  //operator +=(int); ?
654  int x() const {
655  return pos.x;
656  }
661  int y() const {
662  return pos.y;
663  }
668  const ImageLocation &location() const {
669  return pos;
670  }
676  void location(const ImageLocation &il);
682  void location(int x, int y) {
683  location(ImageLocation(x, y));
684  }
688  int absX() const {
689  return orig.x + pos.x;
690  }
694  int absY() const {
695  return orig.y + pos.y;
696  }
701  return orig + pos;
702  }
707  int originX() const {
708  return orig.x;
709  }
714  int originY() const {
715  return orig.y;
716  }
721  const ImageLocation &origin() const {
722  return orig;
723  }
730  void origin(const ImageLocation &il);
735  int width() const {
736  return dim.w;
737  }
742  int height() const {
743  return dim.h;
744  }
749  const ImageDimensions &dimensions() const {
750  return dim;
751  }
757  void dimensions(const ImageDimensions &d);
775  void origdimloc(
776  const ImageLocation &o,
777  const ImageDimensions &d,
778  const ImageLocation &p
779  );
780  /* *
781  * Changes the coordinate perpendicular to the set direction as if by
782  * incrementing this pixel by an amount equal to @a l multiplied by
783  * the width, for HorizInc and HorizDec, or the height, for VertInc
784  * and VertDec. This means that with direction HorizInc starting at
785  * position (x,y), line(l) will change the position to (x,y+l) if y+l
786  * is within the height bound.
787  */
788  //void line(int l);
789 
795  const ConstPixel *cp;
796  public:
797  ConstBoolProxy(const ConstPixel *p) : cp(p) { }
802  operator bool () const {
803  return cp->state();
804  }
805  };
810  return ConstBoolProxy(this);
811  }
812 
813  // incomplete attempt at fulfilling all standard iterator requirements
814  //typedef std::forward_iterator_tag iterator_category;
815  typedef bool value_type;
816  //typedef ? difference_type;
817  //typedef ConstBoolProxy pointer; // doesn't seem quite right
818  //typedef ? reference;
819  };
823  class Pixel : public ConstPixel {
824  public:
831  BppImage *img,
832  const ImageLocation &il = { 0, 0 },
833  Direction d = HorizInc
834  ) : ConstPixel(img, il, d) { }
841  BppImage *img,
842  int x,
843  int y,
844  Direction d = HorizInc
845  ) : ConstPixel(img, ImageLocation(x, y), d) { }
871  BppImage *img,
872  const ImageLocation &o,
873  const ImageDimensions &s,
874  const ImageLocation &p = { 0, 0 },
875  Direction d = HorizInc
876  ) : ConstPixel(img, o, s, p, d) { }
880  Pixel &operator = (const Pixel &p) = default;
884  Pixel &operator = (const EndPixel) {
885  pos.x = pos.y = -1;
886  blk = nullptr;
887  return *this;
888  }
892  void state(bool s);
897  bool state() const {
898  return ConstPixel::state();
899  }
905  Pixel &operator = (bool s) {
906  state(s);
907  return *this;
908  }
913  void clear() {
914  state(false);
915  }
920  void set() {
921  state(true);
922  }
929  bool toggle();
930 
935  class BoolProxy {
937  public:
938  BoolProxy(Pixel *p) : pix(p) { }
943  operator bool () {
944  return pix->state();
945  }
950  bool operator = (bool b) {
951  pix->state(b);
952  return b;
953  }
954  };
959  return BoolProxy(this);
960  }
961  };
965  BppImage() : dim(0, 0), blkPerLine(0) { };
969  BppImage(const ImageDimensions &id);
973  BppImage(int width, int height) : BppImage(ImageDimensions(width, height)) { }
977  BppImage(BppImage &&mv);
981  BppImage(const BppImage &src);
997  BppImage(const char *data);
1013  BppImage(const std::vector<char> &data);
1018  static std::shared_ptr<BppImage> make(const ImageDimensions &id) {
1019  return std::make_shared<BppImage>(id);
1020  }
1025  static std::shared_ptr<BppImage> make(int width, int height) {
1026  return std::make_shared<BppImage>(width, height);
1027  }
1032  static std::shared_ptr<BppImage> make(const char *data) {
1033  return std::make_shared<BppImage>(data);
1034  }
1039  static std::shared_ptr<BppImage> make(const std::vector<char> &data) {
1040  return std::make_shared<BppImage>(data);
1041  }
1045  BppImage &operator = (BppImage &&mv);
1049  BppImage &operator = (const BppImage &src);
1053  void swap(BppImage &other);
1059  void clear();
1066  void resize(const duds::ui::graphics::ImageDimensions &newdim);
1074  void resize(int width, int height) {
1075  resize(duds::ui::graphics::ImageDimensions(width, height));
1076  }
1080  bool empty() const {
1081  return img.empty();
1082  }
1088  std::size_t bufferSize() const {
1089  return img.size();
1090  }
1094  int size() const {
1095  return dim.w * dim.h;
1096  }
1100  std::int16_t width() const {
1101  return dim.w;
1102  }
1106  std::int16_t height() const {
1107  return dim.h;
1108  }
1112  const ImageDimensions &dimensions() const {
1113  return dim;
1114  }
1119  const PixelBlock *buffer() const;
1124  PixelBlock *buffer() {
1125  // re-use the const implementation
1126  return const_cast<BppImage::PixelBlock*>
1127  (((const BppImage*)this)->buffer());
1128  }
1132  // C++ containers are going with data() for underlying container
1133  const std::vector<PixelBlock> &data() const {
1134  return img;
1135  }
1139  bool operator == (const BppImage &other) const;
1149  const PixelBlock *bufferLine(int py) const;
1159  PixelBlock *bufferLine(int py) {
1160  // re-use the const implementation
1161  return const_cast<BppImage::PixelBlock*>
1162  (((const BppImage*)this)->bufferLine(py));
1163  }
1167  int blocksPerLine() const {
1168  return blkPerLine;
1169  }
1182  void bufferSpot(
1183  PixelBlock *(&addr),
1184  PixelBlock &mask,
1185  const ImageLocation &il
1186  );
1200  void bufferSpot(PixelBlock *(&addr), PixelBlock &mask, int x, int y) {
1201  bufferSpot(addr, mask, ImageLocation(x, y));
1202  }
1216  const PixelBlock *(&addr),
1217  PixelBlock &mask,
1218  const ImageLocation &il
1219  ) const {
1220  // the implementation is the same, save for a couple of const
1221  const_cast<BppImage*>(this)->bufferSpot(
1222  const_cast<PixelBlock*&>(addr),
1223  mask,
1224  il
1225  );
1226  }
1233  ImageLocation startPosition(Direction dir = HorizInc) const;
1242  static ImageLocation startPosition(
1243  const ImageLocation &origin,
1244  const ImageDimensions &size,
1245  Direction dir = HorizInc
1246  );
1254  Pixel pixel(const ImageLocation &il, Direction dir = HorizInc);
1263  Pixel pixel(int x, int y, Direction dir = HorizInc) {
1264  return pixel(ImageLocation(x, y), dir);
1265  }
1273  ConstPixel cpixel(const ImageLocation &il, Direction dir = HorizInc) const;
1282  ConstPixel cpixel(int x, int y, Direction dir = HorizInc) const {
1283  return cpixel(ImageLocation(x, y), dir);
1284  }
1292  ConstPixel operator () (int x, int y) const {
1293  return cpixel(x, y);
1294  }
1298  Pixel begin();
1304  Pixel begin(Direction dir);
1321  Pixel begin(
1322  const ImageLocation &origin,
1323  const ImageDimensions &size,
1324  Direction dir = HorizInc
1325  );
1329  ConstPixel cbegin() const;
1335  ConstPixel cbegin(Direction dir) const;
1352  ConstPixel cbegin(
1353  const ImageLocation &origin,
1354  const ImageDimensions &size,
1355  Direction dir = HorizInc
1356  ) const;
1360  ConstPixel begin() const {
1361  return cbegin();
1362  }
1368  static EndPixel endPixel() {
1369  return EndPixel();
1370  }
1375  Pixel end();
1382  static constexpr ConstPixel cend() {
1383  return ConstPixel();
1384  }
1391  ConstPixel end() const {
1392  return cend();
1393  }
1398  bool state(const ImageLocation &il) const;
1404  bool state(int x, int y) const {
1405  return state(ImageLocation(x, y));
1406  }
1412  void state(const ImageLocation &il, bool s);
1419  void state(int x, int y, bool s) {
1420  state(ImageLocation(x, y), s);
1421  }
1426  void clearPixel(const ImageLocation &il) {
1427  state(il, false);
1428  }
1434  void clearPixel(int x, int y) {
1435  state(x, y, false);
1436  }
1441  void setPixel(const ImageLocation &il) {
1442  state(il, true);
1443  }
1449  void setPixel(int x, int y) {
1450  state(x, y, true);
1451  }
1456  bool invertPixel(const ImageLocation &il);
1462  bool invertPixel(int x, int y) {
1463  return invertPixel(ImageLocation(x, y));
1464  }
1468  void invert();
1474  void invertLines(int start, int height);
1482  void patternLines(int start, int height, PixelBlock val);
1488  void setLines(int start, int height) {
1489  patternLines(start, height, -1);
1490  }
1496  void clearLines(int start, int height) {
1497  patternLines(start, height, 0);
1498  }
1505  void blankImage(bool state);
1509  void clearImage() {
1510  blankImage(false);
1511  }
1515  void setImage() {
1516  blankImage(true);
1517  }
1521  enum Operation {
1550  OpTotal
1551  };
1552 private:
1553  typedef bool (*OpBitFunction)(bool dest, bool src);
1559  static const OpBitFunction OpBitFunctions[OpTotal];
1560  typedef void (*OpFunction)(PixelBlock *dest, const PixelBlock &src, const PixelBlock &mask);
1566  static const OpFunction OpFunctions[OpTotal];
1567 public:
1581  void write(
1582  const BppImage * const src,
1583  const ImageLocation &destLoc,
1584  const ImageLocation &srcLoc,
1585  const ImageDimensions &srcSize,
1586  Direction srcDir = HorizInc,
1587  Operation op = OpSet
1588  );
1601  void write(
1602  const BppImage * const src,
1603  const ImageLocation &destLoc,
1604  const ImageDimensions &srcSize,
1605  Direction srcDir = HorizInc,
1606  Operation op = OpSet
1607  ) {
1608  write(src, destLoc, ImageLocation(0, 0), srcSize, srcDir, op);
1609  }
1623  void write(
1624  const std::shared_ptr<const BppImage> &src,
1625  const ImageLocation &destLoc,
1626  const ImageLocation &srcLoc,
1627  const ImageDimensions &srcSize,
1628  Direction srcDir = HorizInc,
1629  Operation op = OpSet
1630  ) {
1631  write(src.get(), destLoc, srcLoc, srcSize, srcDir, op);
1632  }
1645  void write(
1646  const std::shared_ptr<const BppImage> src,
1647  const ImageLocation &destLoc,
1648  const ImageDimensions &srcSize,
1649  Direction srcDir = HorizInc,
1650  Operation op = OpSet
1651  ) {
1652  write(src.get(), destLoc, ImageLocation(0, 0), srcSize, srcDir, op);
1653  }
1664  void write(
1665  const BppImage * const src,
1666  const ImageLocation &dest,
1667  Direction srcDir = HorizInc,
1668  Operation op = OpSet
1669  );
1680  void write(
1681  const std::shared_ptr<const BppImage> &src,
1682  const ImageLocation &dest,
1683  Direction srcDir = HorizInc,
1684  Operation op = OpSet
1685  ) {
1686  write(src.get(), dest, srcDir, op);
1687  }
1705  void drawBox(
1706  ImageLocation ul,
1707  ImageDimensions id,
1708  Operation op = OpSet
1709  );
1718  void drawBox(
1719  ImageLocation ul,
1720  ImageDimensions id,
1721  bool state
1722  ) {
1723  drawBox(ul, id, state ? OpSet : OpNot);
1724  }
1739  void drawBox(
1740  int x,
1741  int y,
1742  int w,
1743  int h = 1,
1744  Operation op = OpSet
1745  ) {
1746  drawBox(ImageLocation(x, y), ImageDimensions(w, h), op);
1747  }
1758  void drawBox(
1759  int x,
1760  int y,
1761  int w,
1762  int h,
1763  bool state
1764  ) {
1765  drawBox(ImageLocation(x, y), ImageDimensions(w, h), state ? OpSet : OpNot);
1766  }
1767  // https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
1768 };
1769 
1773 inline void swap(BppImage &bi0, BppImage &bi1) {
1774  bi0.swap(bi1);
1775 }
1776 
1777 typedef std::shared_ptr<BppImage> BppImageSptr;
1778 typedef std::shared_ptr<const BppImage> ConstBppImageSptr;
1779 typedef std::weak_ptr<BppImage> BppImageWptr;
1780 typedef std::weak_ptr<const BppImage> ConstBppImageWptr;
1781 
1791 ImageDimensions MaxExtent(const BppImage *i0, const BppImage *i1);
1792 
1799  const BppImage &i0,
1800  const BppImage &i1
1801 ) {
1802  return MaxExtent(&i0, &i1);
1803 }
1804 
1813  const ConstBppImageSptr &i0,
1814  const ConstBppImageSptr &i1
1815 ) {
1816  return MaxExtent(i0.get(), i1.get());
1817 }
1818 
1819 } } }
1820 
1821 #endif // #ifndef BPPIMAGE_HPP
constexpr ImageLocation(Int0 px, Int1 py)
Construct with the given location.
Definition: BppImage.hpp:60
std::uintptr_t PixelBlock
The type used to hold pixel values, one bit per pixel.
Definition: BppImage.hpp:326
constexpr ImageDimensions clip(const ImageDimensions &dim, const ImageLocation &loc=ImageLocation(0, 0)) const
Returns a region clipped to fit within this object&#39;s dimensions.
Definition: BppImage.hpp:234
const ImageDimensions & dimensions() const
Returns the dimensions of the image.
Definition: BppImage.hpp:1112
void clearPixel(const ImageLocation &il)
Changes the state of a pixel to clear (false).
Definition: BppImage.hpp:1426
int y() const
Returns the vertical coordinate of the referenced pixel relative to this object&#39;s origin...
Definition: BppImage.hpp:661
boost::error_info< struct Info_ImageDimensions, ImageDimensions > ImageErrorDimensions
Image dimensions relevant to the error.
Definition: BppImage.hpp:293
void bufferSpot(const PixelBlock *(&addr), PixelBlock &mask, const ImageLocation &il) const
Provides the location of the specified pixel inside the image data.
Definition: BppImage.hpp:1215
void resize(int width, int height)
Changes the size of the image.
Definition: BppImage.hpp:1074
PixelBlock * bufferLine(int py)
Returns a pointer to the start of the given line.
Definition: BppImage.hpp:1159
ImageDimensions dim
The dimensions of the image to iterate over; can be used to limit the portion visited by the iterator...
Definition: BppImage.hpp:489
bool empty() const
Returns true if there is no image data.
Definition: BppImage.hpp:1080
constexpr ImageLocation operator+(const ImageLocation &il) const
Add locations together.
Definition: BppImage.hpp:77
void write(const std::shared_ptr< const BppImage > &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.
Definition: BppImage.hpp:1623
static std::shared_ptr< BppImage > make(const char *data)
Convenience function to make a shared pointer to an image using the BppImage(const char *) constructo...
Definition: BppImage.hpp:1032
Stores a location within an image.
Definition: BppImage.hpp:33
void write(const std::shared_ptr< const BppImage > &src, const ImageLocation &dest, Direction srcDir=HorizInc, Operation op=OpSet)
Writes as much of the given source image as will fit into this image.
Definition: BppImage.hpp:1680
std::int16_t y
Vertical coordinate.
Definition: BppImage.hpp:41
PixelBlock mask
The mask used to isolate the referenced pixel.
Definition: BppImage.hpp:475
std::int16_t x
Horizontal coordinate.
Definition: BppImage.hpp:37
constexpr bool operator==(const ImageLocation &il) const
Obvious equality operator.
Definition: BppImage.hpp:65
Retreives a pixel&#39;s state; used to allow ConstPixel to be dereferenced like any other iterator to get...
Definition: BppImage.hpp:794
constexpr bool empty() const
True if the dimensions indicate zero area.
Definition: BppImage.hpp:169
int originX() const
Returns the X coordinate of this object&#39;s origin used to limit the area of the source image that will...
Definition: BppImage.hpp:707
ImageLocation pos
The location of the referenced pixel on the source image.
Definition: BppImage.hpp:479
int originY() const
Returns the Y coordinate of this object&#39;s origin used to limit the area of the source image that will...
Definition: BppImage.hpp:714
std::shared_ptr< const BppImage > ConstBppImageSptr
Definition: BppImage.hpp:1778
static std::shared_ptr< BppImage > make(int width, int height)
Convenience function to make a shared pointer to an image using the BppImage(int, int) constructor...
Definition: BppImage.hpp:1025
const std::vector< PixelBlock > & data() const
Provides access to the internal vector storing the image data.
Definition: BppImage.hpp:1133
bool state() const
Returns the state of the referenced pixel.
Definition: BppImage.cpp:773
void setPixel(const ImageLocation &il)
Changes the state of a pixel to set (true).
Definition: BppImage.hpp:1441
ConstPixel begin() const
Returns a ConstPixel (iterator) to the upper left of the image.
Definition: BppImage.hpp:1360
constexpr ImageDimensions(Int0 dw, Int1 dh)
Construct with the given dimensions.
Definition: BppImage.hpp:152
A forward and output iterator that visits each location of the image.
Definition: BppImage.hpp:823
constexpr ImageDimensions minExtent(const ImageDimensions &dim) const
Returns new dimensions that only cover the union of this dimension and the given dimension.
Definition: BppImage.hpp:215
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...
Definition: BppImage.hpp:363
STL namespace.
constexpr ImageDimensions maxExtent(const ImageDimensions &dim) const
Returns new dimensions that are minimally large enough to fit this dimension and the given dimension...
Definition: BppImage.hpp:222
constexpr ConstPixel()
Construct a ConstPixel to nowhere.
Definition: BppImage.hpp:498
void state(bool s)
Sets the state of the pixel.
Definition: BppImage.cpp:781
void drawBox(int x, int y, int w, int h=1, Operation op=OpSet)
Draws a box into this image.
Definition: BppImage.hpp:1739
void state(int x, int y, bool s)
Changes the state of a pixel.
Definition: BppImage.hpp:1419
Pixel pixel(int x, int y, Direction dir=HorizInc)
Returns a Pixel (iterator) to iterate across the image starting from the given location.
Definition: BppImage.hpp:1263
std::ostream & operator<<(std::ostream &os, const ImageLocation &il)
Writes an ImageLocation object to a stream in human readable form.
Definition: BppImage.cpp:17
Direction dir
The direction to move when incremented.
Definition: BppImage.hpp:493
std::int16_t width() const
Returns the width of the image.
Definition: BppImage.hpp:1100
const ImageLocation & location() const
Returns the coordinates of the referenced pixel relative to this object&#39;s origin. ...
Definition: BppImage.hpp:668
PixelBlock * blk
The PixelBlock containing the referenced pixel.
Definition: BppImage.hpp:471
Stores the dimensions of an image.
Definition: BppImage.hpp:125
static constexpr std::size_t bufferByteSize(int w, int h)
Returns the size of an image buffer in bytes needed for the specified image size. ...
Definition: BppImage.hpp:355
The Y coordinate will be incremented.
Definition: BppImage.hpp:399
static constexpr ConstPixel cend()
Returns a ConstPixel end iterator.
Definition: BppImage.hpp:1382
void location(int x, int y)
Changes the location referenced by this ConstPixel relative to its origin.
Definition: BppImage.hpp:682
int absY() const
Returns the absolute vertical coordinate of the referenced pixel.
Definition: BppImage.hpp:694
std::vector< PixelBlock > img
The image data.
Definition: BppImage.hpp:331
void setPixel(int x, int y)
Changes the state of a pixel to set (true).
Definition: BppImage.hpp:1449
std::shared_ptr< BppImage > BppImageSptr
Definition: BppImage.hpp:1777
Performs a bitwise exclusive-or operation with the destination and source data, and places the result...
Definition: BppImage.hpp:1546
int height() const
Returns the height of this object&#39;s dimensions used to limit the area of the source image that will b...
Definition: BppImage.hpp:742
boost::error_info< struct Info_ImageDimensions, ImageDimensions > ImageErrorSourceDimensions
Image dimensions for a source image relevant to the error.
Definition: BppImage.hpp:298
BoolProxy operator*()
Dereferences the Pixel; provides the state of the pixel.
Definition: BppImage.hpp:958
void write(const BppImage *const src, const ImageLocation &destLoc, const ImageDimensions &srcSize, Direction srcDir=HorizInc, Operation op=OpSet)
Writes a portion of the source image, starting from (0, 0), into this image.
Definition: BppImage.hpp:1601
ConstPixel end() const
Returns a ConstPixel end iterator.
Definition: BppImage.hpp:1391
std::size_t bufferSize() const
Returns the number of PixelBlocks, not bytes, that make up the image buffer.
Definition: BppImage.hpp:1088
void clear()
Clears (make false) the referenced pixel.
Definition: BppImage.hpp:913
The Y coordinate will be decremented.
Definition: BppImage.hpp:412
static EndPixel endPixel()
Convenience function that returns EndPixel, which can be used as an end iterator with any ConstPixel ...
Definition: BppImage.hpp:1368
void drawBox(ImageLocation ul, ImageDimensions id, bool state)
Draws a box into this image.
Definition: BppImage.hpp:1718
void clearLines(int start, int height)
Clears all the pixles of the given contiguous horizontal lines.
Definition: BppImage.hpp:1496
void swap(ImageLocation &l0, ImageLocation &l1)
Swaps the values of two ImageLocation objects.
Definition: BppImage.hpp:116
int width() const
Returns the width of this object&#39;s dimensions used to limit the area of the source image that will be...
Definition: BppImage.hpp:735
static std::shared_ptr< BppImage > make(const std::vector< char > &data)
Convenience function to make a shared pointer to an image using the BppImage(const std::vector<char> ...
Definition: BppImage.hpp:1039
PixelBlock * buffer()
Retuns a pointer to the start of image data.
Definition: BppImage.hpp:1124
ConstBoolProxy operator*() const
Dereferences the ConstPixel; provides the state of the pixel.
Definition: BppImage.hpp:809
ImageLocation absLocation() const
Returns the absolute coordinates of the referenced pixel.
Definition: BppImage.hpp:700
static constexpr int bufferBlocksPerLine(ImageDimensions dim)
Returns the number of PixelBlock objects that will be used for each horizontal line of an image of th...
Definition: BppImage.hpp:372
constexpr ImageLocation swappedAxes() const
Returns a new location with swapped axes.
Definition: BppImage.hpp:103
ImageDimensions dim
The dimensions of the image.
Definition: BppImage.hpp:335
std::basic_ostream< Char, Traits > & clear(std::basic_ostream< Char, Traits > &os)
Display stream manipulator that clears all text from the display and places the cursor in the upper l...
Pixel(BppImage *img, const ImageLocation &il={ 0, 0 }, Direction d=HorizInc)
Construct a Pixel to reference the requested location of the image.
Definition: BppImage.hpp:830
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 ...
Definition: BppImage.hpp:347
constexpr ConstPixel(const EndPixel)
Construct a ConstPixel to nowhere.
Definition: BppImage.hpp:510
void direction(Direction d)
Changes the direction used for incrementing.
Definition: BppImage.hpp:597
Can be used as an end iterator to avoid making a whole iterator.
Definition: BppImage.hpp:445
int size() const
Returns the number of pixels that make up the image.
Definition: BppImage.hpp:1094
int absX() const
Returns the absolute horizontal coordinate of the referenced pixel.
Definition: BppImage.hpp:688
The X coordinate will be decremented until reaching zero.
Definition: BppImage.hpp:406
void bufferSpot(PixelBlock *(&addr), PixelBlock &mask, int x, int y)
Provides the location of the specified pixel inside the image data.
Definition: BppImage.hpp:1200
int blkPerLine
Number of PixelBlocks used for each horizontal line.
Definition: BppImage.hpp:340
void swapAxes()
Swaps the dimensions&#39;s axes.
Definition: BppImage.hpp:202
The X coordinate will be incremented until reaching the width limit.
Definition: BppImage.hpp:393
ImageLocation orig
Upper left corner of the image to limit the iteration to a portion of the whole image.
Definition: BppImage.hpp:484
const ImageLocation & origin() const
Returns this object&#39;s origin used to limit the area of the source image that will be visited...
Definition: BppImage.hpp:721
constexpr bool fits(const ImageLocation &loc, const ImageDimensions &id) const
Returns true if the given dimensions at the given location relative to this object can fit within thi...
Definition: BppImage.hpp:196
Direction
Controls the direction ConstPixel and Pixel objects will move across the image when the object is inc...
Definition: BppImage.hpp:386
Assigns the pixels in the destination the opposing value of the pixels in the source.
Definition: BppImage.hpp:1531
ImageDimensions MaxExtent(const BppImage *i0, const BppImage *i1)
Returns the maximum extent of the dimensions of two bit-per-pixel images.
Definition: BppImage.cpp:797
Performs a bitwise or operation with the destination and source data, and places the result in the de...
Definition: BppImage.hpp:1541
Operation
Tells how to modify the destination pixel with the source pixel data.
Definition: BppImage.hpp:1521
Direction direction() const
Returns the direction used for incrementing.
Definition: BppImage.hpp:591
BppImage()
Make an empty image with zero size.
Definition: BppImage.hpp:965
void swap(BppImage &bi0, BppImage &bi1)
Support swap operations with the C++ standard library and BppImage objects.
Definition: BppImage.hpp:1773
A forward iterator like class that visits each location of the image or a subset of the image...
Definition: BppImage.hpp:456
void swap(BppImage &other)
Swap two images.
Definition: BppImage.cpp:111
void write(const std::shared_ptr< const BppImage > src, const ImageLocation &destLoc, const ImageDimensions &srcSize, Direction srcDir=HorizInc, Operation op=OpSet)
Writes a portion of the source image, starting from (0, 0), into this image.
Definition: BppImage.hpp:1645
void clearPixel(int x, int y)
Changes the state of a pixel to clear (false).
Definition: BppImage.hpp:1434
std::weak_ptr< BppImage > BppImageWptr
Definition: BppImage.hpp:1779
static std::shared_ptr< BppImage > make(const ImageDimensions &id)
Convenience function to make a shared pointer to an image using the BppImage(const ImageDimensions &)...
Definition: BppImage.hpp:1018
constexpr ImageDimensions swappedAxes() const
Returns new dimensions with swapped axes.
Definition: BppImage.hpp:208
bool state() const
Returns the state of the referenced pixel.
Definition: BppImage.hpp:897
void clearImage()
Clears every pixel (change to false) in the image.
Definition: BppImage.hpp:1509
General graphics related code.
Definition: HD44780.hpp:15
void setLines(int start, int height)
Sets all the pixles of the given contiguous horizontal lines.
Definition: BppImage.hpp:1488
constexpr bool withinBounds(const ImageLocation &loc) const
Returns true if the given location is within the bounds specified by this object. ...
Definition: BppImage.hpp:182
bool invertPixel(int x, int y)
Toggles the state of a pixel.
Definition: BppImage.hpp:1462
bool state(int x, int y) const
Returns the state of the image pixel of the requested location.
Definition: BppImage.hpp:1404
std::weak_ptr< const BppImage > ConstBppImageWptr
Definition: BppImage.hpp:1780
boost::error_info< struct Info_ImageLocation, ImageLocation > ImageErrorLocation
An image location relevant to the error.
Definition: BppImage.hpp:288
ConstPixel cpixel(int x, int y, Direction dir=HorizInc) const
Returns a ConstPixel (iterator) to iterate across the image starting from the given location...
Definition: BppImage.hpp:1282
int x() const
Returns the horizontal coordinate of the referenced pixel relative to this object&#39;s origin...
Definition: BppImage.hpp:654
Retreives a pixel&#39;s state; used to allow Pixel to be dereferenced like any other iterator to get a bo...
Definition: BppImage.hpp:935
Pixel(BppImage *img, const ImageLocation &o, const ImageDimensions &s, const ImageLocation &p={ 0, 0 }, Direction d=HorizInc)
Construct a Pixel to iterate over a subset of the image, and start at a given spot.
Definition: BppImage.hpp:870
constexpr ImageLocation operator-(const ImageLocation &il) const
Subtract locations.
Definition: BppImage.hpp:83
BppImage * src
The image to operate upon.
Definition: BppImage.hpp:465
void clear()
Set the dimensions to zero area.
Definition: BppImage.hpp:175
ConstPixel(const BppImage *img, int x, int y, Direction d=HorizInc)
Construct a ConstPixel to reference the requested location of the image.
Definition: BppImage.hpp:534
constexpr bool operator!=(const ImageLocation &il) const
Obvious inequality operator.
Definition: BppImage.hpp:71
Pixel(BppImage *img, int x, int y, Direction d=HorizInc)
Construct a Pixel to reference the requested location of the image.
Definition: BppImage.hpp:840
Assigns the pixels in the destination the same value as the pixels in the source. ...
Definition: BppImage.hpp:1526
ImageLocation()=default
Construct uninitialized.
An image that uses a single bit to represent the state of each pixel; a black or white picture...
Definition: BppImage.hpp:321
void drawBox(int x, int y, int w, int h, bool state)
Draws a box into this image.
Definition: BppImage.hpp:1758
const ImageDimensions & dimensions() const
Returns this object&#39;s dimensions used to limit the area of the source image that will be visited...
Definition: BppImage.hpp:749
int blocksPerLine() const
Returns the number of PixelBlock objects per row in the image data.
Definition: BppImage.hpp:1167
boost::error_info< struct Info_FrameDimensions, ImageDimensions > ImageErrorTargetDimensions
Image dimensions for a target image relevant to the error.
Definition: BppImage.hpp:303
constexpr bool fits(const ImageDimensions &id) const
Returns true if the given dimensions are not larger than this object&#39;s dimensions.
Definition: BppImage.hpp:189
void swapAxes()
Swaps the location&#39;s axes.
Definition: BppImage.hpp:97
void setImage()
Sets every pixel (set to true) in the image.
Definition: BppImage.hpp:1515
std::int16_t height() const
Returns the height of the image.
Definition: BppImage.hpp:1106
BppImage(int width, int height)
Makes an image of the requested size with uninitialized image data.
Definition: BppImage.hpp:973
Performs a bitwise and operation with the destination and source data, and places the result in the d...
Definition: BppImage.hpp:1536