146 {
return(pc & (~7)); }
152 {
return(pc & (~7)); }
159 {
return(7 - (pc % 8)); }
216 {
return(
static_cast<PixelDist>(pc) * 8); }
225 {
return(
static_cast<CharDist>(toceil ?
226 (cc % 8 > 0 ? (cc / 8 + 1) : (cc / 8)) :
271 static constexpr const char *
name =
"CharC";
281 static constexpr const char *
name =
"PixC";
293 static constexpr const char *
name =
"CharD";
305 static constexpr const char *
name =
"PixD";
316 static constexpr const char *
name =
"IntD";
326 static constexpr const char *
name =
"BorderC";
338 static constexpr const char *
name =
"BorderD";
357template <
typename WRES,
typename HRES>
365 typename WidthType::type
x;
366 typename HeightType::type
y;
370 {
static const Cursor kz{0,0};
return(kz); }
374 {
return(
Cursor{(c0.x >= c1.x) && (c0.y >= c1.y) ? c0 : c1}); }
378 typename HeightType::type yc):
x{xc},
y{yc} {}
387 void newRow(
void)
noexcept { ++
y;
x = 0; }
390 void newCol(
void)
noexcept { ++
x; }
393 void incRow(
void)
noexcept { ++
y; }
396 bool zero(
void)
const noexcept {
return((
x == 0) && (
y == 0)); }
402 {
return((oth.y >
y) || ((oth.x >
x) && (oth.y ==
y))); }
407 {
return((
y >= oth.y) && (
x >= oth.x)); }
411 {
return(
static_cast<IntDist>(
x - oth.x)); }
415 {
return(
static_cast<IntDist>(
y - oth.y)); }
419 {
x =
static_cast<typename WidthType::type
>(
421 y =
static_cast<typename HeightType::type
>(
426 {
return((oth.x ==
x) && (oth.y ==
y)); }
430 {
return(!
operator==(oth)); }
434 {
return(
Cursor{
static_cast<typename WidthType::type
>(
x + oth.x),
435 static_cast<typename HeightType::type
>(
y + oth.y)}); }
439 { *
this = *
this + oth;
return(*
this); }
444 return(
Cursor{
static_cast<typename WidthType::type
>(
x - oth.
x),
445 static_cast<typename HeightType::type
>(
y - oth.
y)});
450 { *
this = *
this - oth;
return(*
this); }
452 std::string
to_string(
bool withtype =
true) const
455 return(std::string{
"Cursor<"} + WidthType::name +
"," +
457 ">(x: " + std::to_string(
x) +
", y: " +
458 std::to_string(
y) +
")");
459 return(std::string{
"(x: "} + std::to_string(
x) +
", y: " +
460 std::to_string(
y) +
")"); }
462static_assert(std::is_base_of<CoordT,WRES>::value &&
463 std::is_base_of<CoordT,HRES>::value,
464 "WRES and HRES types in Cursor<> must be derived from CoordT");
502template <
typename WRES,
typename HRES>
510 typename HRES::coord_typeT>;
516 {
static const Area kz{0,0};
return(kz); }
520 Area(
typename WidthType::type w,
521 typename HeightType::type h):
width{w},
height{h} {}
533 {
if (!c1.rightBelow(c0))
RUNTIMEEXCEP(
"Invalid corners for area");
534 width = c1.x - c0.x + 1;
height = c1.y - c0.y + 1; }
539 size_t area(
void)
const noexcept
541 {
return(
static_cast<size_t>(
width) *
static_cast<size_t>(
height)); }
545 {
return((
width <= oth.width) && (
height <= oth.height)); }
549 {
return(
Area{
static_cast<typename WidthType::type
>(
width + oth.width),
550 static_cast<typename HeightType::type
>(
height +oth.height)
555 {
width += oth.width;
height += oth.height;
return(*
this); }
559 {
if (!oth.containedInto(*
this))
561 return(
Area{
static_cast<typename WidthType::type
>(
width - oth.width),
562 static_cast<typename HeightType::type
>(
height -oth.height)
586 {
return(!
operator==(oth)); }
588 std::string
to_string(
bool withtype =
true) const
591 return(std::string{
"Area<"} + WidthType::name +
"," +
593 ">[w: " + std::to_string((
unsigned)
width) +
", h: " +
594 std::to_string((
unsigned)
height) +
"]");
595 return(std::string{
"[w: "} +
596 std::to_string((
unsigned)
width) +
", h: " +
597 std::to_string((
unsigned)
height) +
"]"); }
599static_assert(std::is_base_of<DistT,WRES>::value &&
600 std::is_base_of<DistT,HRES>::value,
601 "WRES and HRES types in Area<> must be derived from DistT");
642template <
typename WRES,
typename HRES>
646 typename HRES::coord_typeT>;
659 const area_type & a = area_type{0,0}):
corner{c},
area{a} {}
670 {
return(
cursor_type{
static_cast<typename WRES::coord_typeT::type
>(
672 static_cast<typename HRES::coord_typeT::type
>(
676 const Rect & oth)
noexcept;
703 char horalign,
char vertalign)
const;
718 {
return(!
operator==(oth)); }
723 return(std::string{
"Rect<"} + WRES::name +
"," + HRES::name +
729static_assert(std::is_base_of<DistT,WRES>::value &&
730 std::is_base_of<DistT,HRES>::value,
731 "WRES and HRES types in Rect<> must be derived from DistT");
791 std::string to_string(
void)
const
820 std::string to_string(
void)
const
855 template <LinearGraphic::GraphOp op>
856 static constexpr uint8_t
doGraphOp(uint8_t b0, uint8_t b1)
noexcept;
879 size_t chunksize,
size_t gap,
size_t numchunks);
900 bool external(
void)
const noexcept {
return(external_); }
903 bool owner(
void)
const noexcept {
return(owner_); }
908 size_t size(
void)
const noexcept {
return(s_); }
915 bool oneByte(
void)
const noexcept {
return(onebyte_); }
918 uint8_t
getByte(
size_t offset)
const;
927 void setByte(
size_t offset, uint8_t b);
1007template <
typename HEIGHTRESOL>
1057 {
if (
this != &oth) { LinearGraphic::clear(); moveFrom(std::move(oth));}
1104 typename HEIGHTRESOL::type
scrollUp(
typename HEIGHTRESOL::type howmany,
1105 typename HEIGHTRESOL::type upperrow,
1107 {
return(scrollUpRegion({{0,0},
dims},howmany,upperrow,fillb)); }
1115 static size_t sizeForDimensions(
const AreaType & a)
1116 {
return(
static_cast<size_t>(a.
width) *
static_cast<size_t>(a.
height));}
1121 LinearGraphic::moveFrom(std::move(og));
1125 typename HEIGHTRESOL::type scrollUpRegion(
const RectType & region,
1126 typename HEIGHTRESOL::type howmany,
1127 typename HEIGHTRESOL::type upperrow,
1130static_assert(std::is_base_of<DistT,HEIGHTRESOL>::value,
1131 "HEIGHTRESOL type in DimsGraphic<> must be derived from DistT");
1136template <
typename WIDTHRESOL,
typename HEIGHTRESOL>
1159 using BaseGr::BaseGr;
1169 Bitmap(uint8_t ascii, uint8_t * chartable =
nullptr);
1228 using BaseGr::BaseGr;
1315 attrmap{g.attrmap,region,copy} {}
1326 const PNGConversionParms & parms =
1333 DoubleGraphic(
const DoubleGraphic &) =
delete;
1334 DoubleGraphic & operator=(
const DoubleGraphic &) =
delete;
1335 DoubleGraphic(DoubleGraphic && oth):DoubleGraphic{
CharArea{0,0}}
1336 { moveFrom(std::move(oth)); }
1338 {
if (
this != &oth) moveFrom(std::move(oth));
return(*
this); }
1340 virtual ~DoubleGraphic(
void);
1351 attrmap.
merge(oth.attrmap,pos); }
1358 {
return(
"Bitmap: " + bitmap.
to_string() +
1364 using ColCountInCell = uint8_t;
1365 using ColFreq = std::pair<RGBPalette::Index,ColCountInCell>;
1366 using ZXColorDecisor = std::function<
1367 std::pair<BrightColor,BrightColor>(
const PNGConversionParms &,
1372 using ZXBitmapDecisor = std::function<
1373 bool(
const PNGConversionParms &,
1375 const RGBColor &,
const std::pair<BrightColor,BrightColor>) >;
1381 class DitheringSystem
1395 (kNumColorsButBright - 1) *
1396 kNumColorsButBright /
1399 kClusterSizeButBright * 2;
1406 friend DitheringSystem;
1409 {
return(palcolor_); }
1417 DitherLevel ditherLevel(
void)
const noexcept {
return(l_); }
1419 bool notDithered(
void)
const noexcept
1420 {
return((l_ == 0) || (l_ == dsys_->maxDithLevel())); }
1422 bool equalExtremesOrder(
const Color & oc)
const noexcept
1423 { checkSameLevs(oc);
return((oc.c0_ == c0_) && (oc.c1_ ==c1_));}
1425 bool equalExtremesNotOrder(
const Color & oc)
const noexcept
1426 { checkSameLevs(oc);
return((oc.c0_ == c1_) && (oc.c1_ ==c0_));}
1428 bool equalExtremes(
const Color & oc)
const noexcept
1429 { checkSameLevs(oc);
1430 return(equalExtremesOrder(oc) || equalExtremesNotOrder(oc)); }
1432 Color makeCompatibleWith(
const Color & oc)
const noexcept;
1434 std::string to_string(
void)
const;
1438 const DitheringSystem * dsys_;
1447 Color(
const RGBColor & rgb,
const DitheringSystem & dithsys);
1449 void checkSameLevs(
const Color & oth)
const;
1450 int closestLevel(
const Color &oc)
const;
1455 {
if ((nlvs < kMinDiths) || (nlvs > kMaxDiths))
1456 RUNTIMEEXCEP(
"Out of range number of dithering levels"); }
1457 DitheringSystem(
const DitheringSystem &) =
delete;
1458 DitheringSystem(DitheringSystem &&) =
delete;
1459 DitheringSystem & operator=(
const DitheringSystem &) =
delete;
1460 DitheringSystem & operator=(DitheringSystem &&) =
delete;
1463 {
return(numlvs_); }
1466 {
return(numlvs_ - 1); }
1468 constexpr DitherLevel inverseDithLevel(DitherLevel dl)
const noexcept
1469 {
return(maxDithLevel() - dl); }
1472 {
return(numlvs_ - 2); }
1475 {
return(kNumPureColors +
1476 kClusterSize * numClusters()); }
1478 double dithLevDegree(DitherLevel dl)
const;
1480 const RGBPalette & ditheredPalette(
void)
const noexcept;
1482 Color deployColor(
const RGBColor & rgb)
const
1483 {
return(Color{rgb,*
this}); }
1486 {
return(Color(palind,*
this)); }
1493 double ditherdegree);
1500 template <
typename ColorIndex>
1508 freqs[f] = std::make_pair(f,0);
1510 do ++(freqs[img.pixel(curpix)].second);
1511 while (curpix.forward());
1513 std::sort(freqs,freqs + img.palette().
numColors(),
1514 [](
const ColFreq & lhs,
const ColFreq & rhs) ->
bool
1515 { return(lhs.second > rhs.second); });
1518 static void reduceColors(
const RGBPalette & pal, ColFreq * freqs);
1520 static void fillGraphicFromZXNoClash(
1522 const PNGConversionParms & parms,
1523 const ZXColorDecisor & zxcoldec,
1524 const ZXBitmapDecisor & zxbmdec,
1525 Bitmap & bitmap, Attrmap & attrmap);
1527 void fillGraphicFromRGB_ToNearestPlain(
const RGBImage & rgbimg,
1528 const PNGConversionParms & parms,
1529 Bitmap & bitmap, Attrmap & attrmap);
1530 void fillGraphicFromRGB_Dither(
const RGBImage & rgbimg,
1531 const PNGConversionParms & parms,
1532 Bitmap & bitmap, Attrmap & attrmap);
1535 void moveFrom(DoubleGraphic && oth)
1536 { bitmap = std::move(oth.bitmap); attrmap = std::move(oth.attrmap); }
1556template <
typename WRES,
typename HRES>
1559 if (!cur.rightBelow(corner))
return(
false);
1560 return(
area_type{corner,cur}.containedInto(area));
1563template <
typename WRES,
typename HRES>
1565 const Rect & oth)
noexcept
1567 auto oldx = corner.
x;
1568 auto oldy = corner.
y;
1577 if (
static_cast<int>(corner.
x) +
static_cast<int>(xdiff) +
1578 static_cast<int>(area.
width) > oth.corner.x + oth.
area.width)
1581 if (
static_cast<int>(corner.
y) +
static_cast<int>(ydiff) +
1582 static_cast<int>(area.
height) > oth.corner.y + oth.
area.height)
1589 return((newx != oldx) || (newy != oldy));
1592template <
typename WRES,
typename HRES>
1595 using WCoordType =
typename WRES::coord_typeT::type;
1596 using HCoordType =
typename HRES::coord_typeT::type;
1597 using WDistType =
typename WRES::type;
1598 using HDistType =
typename HRES::type;
1601 if ((!empty()) && (!oth.
empty()))
1604 static_cast<WCoordType
>(
1605 corner.
x + area.
width - 1)};
1607 static_cast<HCoordType
>(
1610 static_cast<WCoordType
>(
1611 oth.corner.x + oth.
area.width -1)};
1613 static_cast<HCoordType
>(
1614 oth.corner.y + oth.
area.height-1)};
1615 auto intersx = myxint.intersect(othxint);
1616 auto intersy = myyint.intersect(othyint);
1617 if ((!intersx.empty()) && (!intersy.empty()))
1619 res.
corner = {intersx.minimum(), intersy.minimum()};
1620 res.
area = {
static_cast<WDistType
>(intersx.width() + 1),
1621 static_cast<HDistType
>(intersy.width() + 1)};
1627template <
typename WRES,
typename HRES>
1629 char horalign,
char vertalign)
const
1632 RUNTIMEEXCEP(
"Cannot align needed area: greater than available zone");
1666 return(
Rect{corner + cur,areaneeded});
1678constexpr uint8_t LinearGraphic::doGraphOp<LinearGraphic::GraphOp::COPY>(
1680 uint8_t b1)
noexcept
1684constexpr uint8_t LinearGraphic::doGraphOp<LinearGraphic::GraphOp::INV>(
1686 uint8_t b1)
noexcept
1690constexpr uint8_t LinearGraphic::doGraphOp<LinearGraphic::GraphOp::OR>(
1692 uint8_t b1)
noexcept
1693 {
return(b1 | b0); }
1696constexpr uint8_t LinearGraphic::doGraphOp<LinearGraphic::GraphOp::INVOR>(
1698 uint8_t b1)
noexcept
1699 {
return((~b1) | b0); }
1702constexpr uint8_t LinearGraphic::doGraphOp<LinearGraphic::GraphOp::AND>(
1704 uint8_t b1)
noexcept
1705 {
return(b1 & b0); }
1708constexpr uint8_t LinearGraphic::doGraphOp<LinearGraphic::GraphOp::INVAND>(
1710 uint8_t b1)
noexcept
1711 {
return((~b1) & b0); }
1714constexpr uint8_t LinearGraphic::doGraphOp<LinearGraphic::GraphOp::XOR>(
1716 uint8_t b1)
noexcept
1717 {
return(b1 ^ b0); }
1720constexpr uint8_t LinearGraphic::doGraphOp<LinearGraphic::GraphOp::INVXOR>(
1722 uint8_t b1)
noexcept
1723 {
return((~b1) ^ b0); }
1732template <
typename HEIGHTRESOL>
1733typename HEIGHTRESOL::type DimsGraphic<HEIGHTRESOL>::scrollUpRegion(
1734 const RectType & region,
1735 typename HEIGHTRESOL::type howmany,
1736 typename HEIGHTRESOL::type upperrow,
1740 if ((howmany == 0) || (howmany >= region.area.height) ||
1741 (upperrow >= region.area.height) || oneByte())
1744 if (upperrow < howmany)
1745 upperrow =
static_cast<typename HEIGHTRESOL::type
>(howmany);
1749 const typename HEIGHTRESOL::type firstoverwritten = upperrow - howmany;
1750 const typename HEIGHTRESOL::type rowstomove = region.area.height - upperrow;
1751 size_t offsetfirstrow =
1752 static_cast<size_t>(upperrow + region.corner.y) *
1753 static_cast<size_t>(dims.
width) +
1754 static_cast<size_t>(region.corner.x);
1755 size_t offsetfirstoverwritten =
1756 static_cast<size_t>(firstoverwritten + region.corner.y) *
1757 static_cast<size_t>(dims.
width) +
1758 static_cast<size_t>(region.corner.x);
1761 for (
typename HEIGHTRESOL::type f = 0; f < rowstomove; ++f)
1765 offsetfirstrow += dims.
width;
1766 offsetfirstoverwritten += dims.
width;
1770 offsetfirstrow =
static_cast<size_t>(region.area.height - 1 +
1772 static_cast<size_t>(dims.
width) +
1773 static_cast<size_t>(region.corner.x);
1774 const LinearGraphic blankline{region.area.width,fillb};
1775 for (
typename HEIGHTRESOL::type f = 0; f < howmany; ++f)
1779 offsetfirstrow -= dims.
width;
1785template <
typename HEIGHTRESOL>
1789 if ((g.dims.width == 0) || (g.dims.height == 0))
1790 RUNTIMEEXCEP(
"Cannot construct empty DimsGraphic from another "
1791 "DimsGraphic; g.width: " + std::to_string(g.dims.width) +
1792 ", g.height: " + std::to_string(g.dims.height) +
1793 "; g: " + g.to_string());
1795 if ((region.corner.x >= g.dims.width) ||
1796 (region.corner.y >= g.dims.height))
return;
1798 RectType reg = region;
1799 if (region.area.empty())
1801 reg.area.width = g.dims.width - region.corner.x;
1802 reg.area.height = g.dims.height - region.corner.y;
1805 auto w = std::min(reg.area.width,
1807 g.dims.width - reg.corner.x));
1808 auto h = std::min(reg.area.height,
1810 typename HEIGHTRESOL::coord_typeT::type
>(
1811 g.dims.height - reg.corner.y));
1816 size_t offseting = g.offset(reg.corner);
1817 size_t offsetinthis = 0;
1818 *
this = DimsGraphic{reg.area};
1819 for (
typename HEIGHTRESOL::type y = 0; y < h ; ++y)
1821 LinearGraphic::mergeUnsafe(offsetinthis, g, offseting, w);
1822 offsetinthis += dims.
width;
1823 offseting += g.dims.width;
1829 this->LinearGraphic::operator=(
1830 LinearGraphic{g,g.offset(reg.corner),w,
1831 static_cast<size_t>(g.dims.width - w),
1837template <
typename HEIGHTRESOL>
1842 " out of range in DimsGraphic " + to_string());
1843 return(
static_cast<size_t>(pos.
y) *
1844 static_cast<size_t>(dims.
width) +
1845 static_cast<size_t>(pos.
x));
1848template <
typename HEIGHTRESOL>
1852 if (offset >= s_)
RUNTIMEEXCEP(
"Offset out of range in DimsGraphic");
1853 return(
CursorType{
static_cast<typename HEIGHTRESOL::coord_typeT::type
>
1854 (offset % dims.
width),
1858template <
typename HEIGHTRESOL>
1864 RUNTIMEEXCEP(
"Cannot merge nothing on a one-byte DimsGraphic");
1869 size_t thisoffset =
static_cast<size_t>(pos.
y) *
1870 static_cast<size_t>(dims.
width) +
1871 static_cast<size_t>(pos.
x);
1873 const CharDist firstinvisiblebinthis =
1875 const typename HEIGHTRESOL::type firstinvisibleyg =
1876 std::min(oth.
dims.
height,
static_cast<typename HEIGHTRESOL::type
>(
1879 for (
typename HEIGHTRESOL::coord_typeT::type yg = 0;
1880 yg < firstinvisibleyg; ++yg)
1882 LinearGraphic::mergeUnsafe(thisoffset,
1884 firstinvisiblebinthis,
1886 thisoffset +=
static_cast<size_t>(dims.
width);
1890template <
typename HEIGHTRESOL>
1893 return(std::string{
"DimsGraphic<"} +
1894 AreaType::HeightType::name +
">{ width: " +
1895 std::to_string((
unsigned)dims.
width) +
", height: " +
1896 std::to_string((
unsigned)dims.
height) +
"; " +
1897 LinearGraphic::to_string() +
" }");
1909static_assert(std::is_integral<PixelCoord>::value &&
1910 std::is_unsigned<PixelCoord>::value,
1911 "PixelCoord type must be integral and unsigned");
1912static_assert(std::is_integral<CharCoord>::value &&
1913 std::is_unsigned<CharCoord>::value,
1914 "CharCoord type must be integral and unsigned");
1915static_assert(std::is_integral<PixelDist>::value &&
1916 std::is_unsigned<PixelDist>::value,
1917 "PixelDist type must be integral and unsigned");
1918static_assert(std::is_integral<CharDist>::value &&
1919 std::is_unsigned<CharDist>::value,
1920 "CharDist type must be integral and unsigned");
1921static_assert(std::is_integral<IntDist>::value &&
1922 std::is_signed<IntDist>::value,
1923 "IntDist type must be integral and signed");
uint32_t Size
Size of a palette.
Size numColors(void) const noexcept
Return the number of colors in the palette.
Size Index
Index of a color in a palette.
RasterCursor< 1, 1 > subCursor(void) const
Return a cursor limited to the cell where this cursor is.
An image that stores pixel colors contiguously as palette indexes.
A RGB color with 8 bits per component.
A palette defining a number of RGB colors.
A cursor to access RasterImage pixels bi-linearly with certain tesselation.
A 2D matrix of certain type that has contiguous storage.
Collect diverse traits for the fixed integer type T.
An interval, typically numeric, either closed, opened or semi-closed.
#define RUNTIMEEXCEP(txt)
Raise a runtime exception with the given std::string TXT + additional info.
Interface with the functionality that a desktop must provide.
static constexpr RGBPalette::Size NUMLINEARCOLORS
Number of linear colors. Black is counted twice, being equal w & w/o br.
DimsGraphic(const AreaType &a, uint8_t b)
Construct a graphic of the given dimensions filled with one byte (B).
static const Rect & theEmpty(void) noexcept
Return a reference to an inmutable empty rectangle of this type.
HRES HeightType
Type used for the height dimension.
cursor_type bottomRight(void) const noexcept
< Return the coordinates of the bottom-right extreme within the rectangle
LinearGraphic(uint8_t *bs, size_t s)
Construct a graphic that is held externally (NO OWNERSHIP to this).
Rect(const cursor_type &c=cursor_type{0, 0}, const area_type &a=area_type{0, 0})
Default constructor: empty rectangle.
HRES HeightType
Type used for the height dimension.
static constexpr uint8_t doGraphOp(uint8_t b0, uint8_t b1) noexcept
Return the result of doing operation OP on byte B0 with byte B1.
Area & operator*=(const Area &oth)
Intersect OTH to THIS and return THIS.
area_type area
Width and height.
std::string to_string(void) const
Return a text with the info of the graphic.
DimsGraphic & operator=(DimsGraphic &&oth)
Move assignment.
PixRect getPixRect(const CharRect &cc)
Convert a char rect to a pix rect representing the same region on screen.
CharArea chararea
Char resolution.
Cursor< typename WRES::coord_typeT, typename HRES::coord_typeT > CursorType
Cursor.
bool empty(void) const noexcept
Return TRUE if the area is empty.
LinearGraphic(size_t s)
Construct an empty graphic of the given size, yet to be filled.
void merge(const DimsGraphic &oth, const CursorType &pos, GraphOp mode=GraphOp::COPY)
Merge OTH at the given coordinates of this object with the given mode.
constexpr CharCoord kMaxCharCoord
Maximum value of a char coordinate.
type value
To hold values of that type.
CharDist type
Numerical type corresponding to this class.
bool oneByte(void) const noexcept
Return TRUE if the graphic content is compressed into one byte.
Bitmap(uint8_t ascii, uint8_t *chartable=nullptr)
Construct a bitmap for a ZX ascii char (including block-graphic ones).
constexpr CharDist SCREENCOLS
Number of columns in the screen of the original ZX.
bool empty(void) const noexcept
Return TRUE if the rectangle area is empty.
PixCursor getPixCursor(const CharCursor &cc)
Convert a char cursor to a pix cursor placed at the top-left of the former.
type value
To hold values of that type.
static const Cursor & theZero(void) noexcept
< Return a reference to an inmutable zero cursorof this type.
constexpr size_t DISPLAYLEN
Length in memory (bytes) of the original complete zx screen.
void swapPaperInk(void)
< Reuse all constructor from Gr<CharDistT>.
uint8_t getByte(size_t offset) const
Get the byte at the given offset, throwing if it is out of range.
static constexpr const char * name
Name of numeric type.
Area< CharDistT, CharDistT > CharArea
Shortcut for this kind of area.
CursorType coords(size_t offset) const
Get the coordinates of the given offset, if it is valid, or throws.
WRES WidthType
Type used for the width dimension.
type value
To hold values of that type.
PNGConversionMode mode
Mode for conversion.
constexpr BorderDist TOPBORDERH
Height in pixels of the original zx visible border in its top section.
constexpr PixelDist SCREENH
Height in pixels of the original zx screen.
void newRow(void) noexcept
Go down one row resetting x (y <- y + 1 & x <- 0).
PixelDist type
Numerical type corresponding to this class.
IntDist yDiff(const Cursor &oth) const noexcept
< Return the signed distance in Y from OTH to THIS.
DimsGraphic(DimsGraphic &&oth)
Move constructor.
constexpr BorderCoord kMaxBorderCoord
Maximum value of a border pixel coordinate.
void incRow(void) noexcept
Go down one row without resetting x.
bool containedInto(const Area &oth) const noexcept
< Return TRUE if this area can be contained into OTH or if they are equal
bool operator==(const Area &oth) const noexcept
< Equality.
size_t offset(const CursorType &pos) const
Get the offset corresponding to the given coordinates in the graphic.
type value
To hold values of that type.
HEIGHTRESOL::type scrollUp(typename HEIGHTRESOL::type howmany, typename HEIGHTRESOL::type upperrow, uint8_t fillb)
Scroll HOWMANY rows of the graphic up, beginning at y-coord UPPERROW.
type value
To hold values of that type.
void addDiff(IntDist xdiff, IntDist ydiff) noexcept
< Add the given signed distances to both coordinates.
size_t area(void) const noexcept
< Return the number of cells in the area.
Area & operator-=(const Area &oth)
Substract OTH from THIS and return THIS. Throw if error.
Cursor & operator+=(const Cursor &oth)
Make the sum and return the result.
static constexpr const char * name
Name of numeric type.
WidthType::type width
width of the area.
constexpr PixelDist SCREENW
Width in pixels of the original zx screen.
CharPixArea getCharPixArea(const CharArea &cc)
Convert a char area to a char-pix area covering the same region on screen.
constexpr CharDist SCREENROWS
Number of rows in the screen of the original ZX.
bool applyConstrainedDiffs(IntDist &xdiff, IntDist &ydiff, const Rect &oth) noexcept
Apply the given increments to the corner of THIS, keeping it within OTH.
uint8_t * getAllBytes(void)
Return a pointer to the data or throw if it is onebyte or external.
bool rightBelow(const Cursor &oth) const noexcept
< Return TRUE if THIS is placed to the right and below of OTH.
void mergeUnsafe(size_t destoffset, const LinearGraphic &oth, size_t origoffset, size_t howmany, GraphOp op=GraphOp::COPY)
Merge HOWMANY bytes from OTH (at ORIGOFFSET) into this (at DESTOFFSET).
static constexpr const char * name
Name of numeric type.
constexpr BorderDist BOTTOMBORDERH
Height in pixels of the original zx visible border in its bottom section.
constexpr PixelDist kMaxPixelDist
Maximum value of a pixel distance.
bool operator!=(const Cursor &oth) const noexcept
< Unequality.
void merge(const DoubleGraphic &oth, const CharCursor &pos, LinearGraphic::GraphOp mode=LinearGraphic::GraphOp::COPY)
Merge both bitmap and attrmap of OTH at the given coordinates in MODE.
Area operator*(const Area &oth) const
< Intersect OTH dimensions to THIS dims and return the result.
std::string to_string(void) const
Return a text with the info of the graphic.
type value
To hold values of that type.
constexpr PixelCoord pixelOfCharX(CharCoord cc) noexcept
Conversion from an x-CharCoord to PixelCoord.
void setByteUnsafe(size_t offset, uint8_t b) noexcept
Change the byte at the given offset without checking anything.
DimsGraphic(DimsGraphic &g, const RectType ®ion, bool copy=true)
Construct a graphic that refers to a region within another one.
struct zxeco::DoubleGraphic::PNGConversionParms::@2 tonearestplain
Parms for ToNearestPlain mode.
Area(typename WidthType::type w, typename HeightType::type h)
Default constructor, from the numerical dist types.
std::string to_string(void) const
Return a text with the info of the graphic.
constexpr PixelCoord firstPixelInCharX(PixelCoord pc) noexcept
Get the PixelCoord of 1st pixel in the character of this x-PixelCoord.
PNGConversionMode
Modes of conversion of PNG images into DoubleGraphic.
constexpr BorderDist RIGHTBORDERW
Height in pixels of the original zx visible border in its right section.
PNGConversionSubmode
Submode of conversion of PNG images into DoubleGraphic.
LinearGraphic(void)
Default constructor: empty graphic.
PixArea pixarea
Pixel resolution.
AreaType dims
Dimensions of the graphic.
constexpr PixelCoord pixelOfCharY(CharCoord cc) noexcept
Conversion from a y-CharCoord to PixelCoord.
constexpr PixelCoord kMaxPixelCoord
Maximum value of a pixel coordinate.
constexpr BorderDist kMaxBorderDist
Maximum value of a border pixel distance.
bool operator==(const Rect &oth) const noexcept
< Equality.
DoubleGraphic(const CharArea &dims)
Constructor for a given size in characters.
void setByte(const CursorType &pos, uint8_t b)
< Unhide the linear setByte() method hidden by the new setByte().
CharPixCursor getCharPixCursor(const CharCursor &cc)
Convert a char cursor to a char-pix cursor placed at the top of the former.
struct zxeco::DoubleGraphic::PNGConversionParms::@3 dither
Parms for Dither and its submodes.
GraphOp
Possible operations on Graphics.
Area operator-(const Area &oth) const
< Substract OTH dimensions from THIS dims and return the result, or throw
DimsGraphic(uint8_t *bs, const AreaType &a)
Construct a graphic that is held externally (NO OWNERSHIP to this).
bool contains(const cursor_type &cur) const noexcept
Return TRUE if CUR is inside the rectangle.
int compare(const LinearGraphic &oth, bool withinv=false) const noexcept
Compare this graphic to OTH and return 1 if both are equal.
constexpr CharDist kMaxCharDist
Maximum value of a char distance.
void setAllBytes(uint8_t b) noexcept
Set all bytes of the graphic to the given value.
CharPixRect getCharPixRect(const CharRect &cc)
Convert a char rect to a char-pix rect representing the same region.
PixRect pixrect
Pixel resolution.
uint8_t NumDithLevels
Type for storing number of dithering levels.
static constexpr const char * name
Name of numeric type.
void savePNG(DesktopInterface &desktop, const std::string &pngfile)
Save the double graphic into a PNG file.
constexpr IntDist kMinIntDist
Minimum value of an int distance.
Rect subRect(const cursor_type &reltopleft) const
< Return the absolute sub-rectangle that starts at RELTOPLEFT within this
void newCol(void) noexcept
Go right one column (x <- x + 1).
uint16_t PixelDist
A distance measured in screen pixels.
bool graphicDimensionsTooLarge(unsigned sx, unsigned sy) noexcept
< Return TRUE if SX,SY are too large to fit in WITHRESOL,HEIGHTRESOL.
type value
To hold values of that type.
void merge(size_t destoffset, const LinearGraphic &oth, size_t origoffset, size_t howmany, GraphOp op=GraphOp::COPY)
Merge HOWMANY bytes from OTH (at ORIGOFFSET) into this (at DESTOFFSET).
uint16_t CharCoord
Represent both x and y screen char coordinates.
constexpr CharDist pixelDistToCharDist(PixelDist cc, bool toceil=true) noexcept
Conversion from PixelDist to CharDist.
constexpr IntDist kMaxIntDist
Maximum value of an int distance.
size_t similarity(const LinearGraphic &oth) const noexcept
Return a measure of the bitmap similarity (bit by bit) between both.
BorderCoord type
Numerical type corresponding to this class.
HeightType::type height
height of the area.
IntDist type
Numerical type corresponding to this class.
std::string to_string(bool withtype=true) const
< Return a string with the textual information of the rectangle.
constexpr PixelDist charDistToPixelDist(CharDist pc) noexcept
Conversion from CharDist to PixelDist.
uint8_t getByte(const CursorType &pos) const
< Unhide the linear getByte() method hidden by the new getByte().
Rect intersect(const Rect &oth) const noexcept
Return the rectangle resulting from the intersection of this and OTH.
uint16_t PixelCoord
Represent both x and y screen pix coordinates.
constexpr PixelCoord firstPixelInCharY(PixelCoord pc) noexcept
Get the PixelCoord of 1st pixel in the character of this y-PixelCoord.
CharRect charrect
Char resolution.
bool operator==(const Cursor &oth) const noexcept
< Return TRUE if both cursors are placed at the same place.
WRES WidthType
Type used for the width dimension.
DimsGraphic(const AreaType &a)
Construct an undefined graphic of the given dimensions, to be filled.
void merge(const Bitmap &oth, const PixCursor &pos, GraphOp mode=GraphOp::COPY)
< Unhide the base merge() method hidden by the new merge().
cursor_type corner
Top-left corner.
Cursor operator-(const Cursor &oth) const
< Return the cursor THIS relative to OTH, or throw if result is negative.
static const Area & theEmpty(void) noexcept
Return a reference to an inmutable empty area of this type.
Cursor(typename WidthType::type xc, typename HeightType::type yc)
Constructor, from the numerical coord types.
Area operator+(const Area &oth) const noexcept
< Add width and height of OTH to THIS.
int16_t IntDist
Positive and negative distances on screen.
PNGConversionSubmode submode
Submode.
constexpr size_t BITMAPLEN
Length in memory (bytes) of the original zx screen bitmap.
size_t size(void) const noexcept
Size in memory, in bytes.
Cursor operator+(const Cursor &oth) const
< Return the sum of both cursors.
Bitmap(DesktopInterface &desktop, const std::string &pngfile)
< Reuse all constructor from Gr<PixelDistT>.
PixArea getPixArea(const CharArea &cc)
Convert a char area to a pix area covering the same region on screen.
LinearGraphic(size_t s, uint8_t b)
Construct a graphic of the given size filled with 1 byte (B).
Rect compose(const Rect &reloth) const
< Return the RELOTH region of THIS as a rectangle.
CharCoord type
Numerical type corresponding to this class.
bool operator!=(const Area &oth) const noexcept
< Unequality.
Cursor & operator-=(const Cursor &oth)
Make the substraction and return the result.
LinearGraphic(LinearGraphic &oth, size_t firstoff, size_t chunksize, size_t gap, size_t numchunks)
Construct a graphic referring to part of another one (no ownership).
bool operator!=(const Rect &oth) const noexcept
< Unequality.
void setByte(size_t offset, uint8_t b)
Change the byte at the given offset inside the data.
PixelCoord type
Numerical type corresponding to this class.
uint8_t getByteUnsafe(size_t offset) const noexcept
Get the byte at the given offset without checking out of range.
static Cursor max(const Cursor &c0, const Cursor &c1) noexcept
< Return a copy of the one of C0, C1 that is more to the right and below.
bool zero(void) const noexcept
Return TRUE if the cursor is placed at (0,0). */.
Rect align_area(const area_type &areaneeded, char horalign, char vertalign) const
Return the portion of this rectangle that contains AREANEEDED aligned.
constexpr CharDist SCREENCHARROWS
Number of char rows in the screen.
NumDithLevels numlevels
Number of dithering levels.
std::string to_string(bool withtype=true) const
< Return a string with the textual information of the area.
bool external(void) const noexcept
Whether the object refers to part of another linear graphic.
static constexpr const char * name
Name of numeric type.
std::string to_string(bool withtype=true) const
< Return a string with the textual information of the area.
constexpr CharCoord charOfPixelX(PixelCoord pc) noexcept
Conversion from an x-PixelCoord to CharCoord.
BorderDist type
Numerical type corresponding to this class.
bool before(const Cursor &oth) const noexcept
< Return TRUE if THIS is placed before OTH in the plane (linearly).
bool owner(void) const noexcept
Whether the object owns the graphical data.
WidthType::type x
Coordinate in width (horizontally).
int16_t BorderCoord
Represent both x and y pix coords in border.
constexpr CharDist SCREENCHARCOLS
Number of char columns in the screen.
std::string to_string(void) const
Return a text with the info of the graphic.
static constexpr const char * name
Name of numeric type.
static constexpr const char * name
Name of numeric type.
IntDist xDiff(const Cursor &oth) const noexcept
< Return the signed distance in X from OTH to THIS.
constexpr size_t ATTRMAPLEN
Length in memory (bytes) of the original zx screen attrmap.
Area & operator+=(const Area &oth) noexcept
< Add to THIS the width and height of OTH.
DimsGraphic(void)
Default constructor: empty graphic.
HeightType::type y
Coordinates in height (vertically).
uint16_t CharDist
A distance meadured in screen chars.
constexpr CharCoord charOfPixelY(PixelCoord pc) noexcept
Conversion from an y-PixelCoord to CharCoord.
constexpr unsigned char bitOfPixelX(PixelCoord pc) noexcept
Get the bit position of the pixel of this x-PixelCoord.
constexpr BorderDist LEFTBORDERW
Height in pixels of the original zx visible border in its left section.
std::string to_string(void) const
Return a text with the info of the graphic.
uint16_t BorderDist
A distance measured in pixels in the border.
@ OR
OR the graphic and the screen content.
@ INV
like COPY but with the graphic bits inverted first
@ AND
AND the graphic and the screen content.
@ INVAND
like AND but first inverts the graphic bits
@ INVXOR
like XOR but with the graphic bits inverted first
@ INVOR
like OR but first invert the graphic bits
@ XOR
XOR the graphic and the screen content.
@ COPY
put the graphic on the screen (substitution)
An area on the screen that uses the given distance resolutions.
A graphic that contains an attrmap, i.e., it has char resolution in height.
A graphic that contains a bitmap, i.e., it has pixel resolution in height.
A cursor on screen that uses the given coordinates resolution.
A graphic that has certain 2D dimensions and coordinates.
An area with both char and pixel resolutions, possibly synchronized.
A bitmap plus an attrmap, possibly synchronized.
A rectangle with both char and pixel resolutions, possibly synchronized.
A rectangular graphic block.
A class that makes BorderCoord a different, distinguishable type from others.
A class that makes BorderDist a different, distinguishable type from others.
A class that makes CharCoord a different, distinguishable type from others.
A class that makes CharDist a different, distinguishable type from others.
Base class for all coordinate trait classes.
Base class for all distance trait classes.
Parameters for the conversion of PNG images into DoubleGraphic.
A class that makes IntDist a different, distinguishable type from others.
A class that makes PixelCoord a different, distinguishable type from others.
A class that makes PixelDist a different, distinguishable type from others.
A rectangle placed on the screen that uses the given resolutions.
The main namespace of the library, that spans across all the zx modules.