1#ifndef __FACADE_PNG_HPP
2#define __FACADE_PNG_HPP
108 std::uint8_t _tag[4];
111 ChunkTag() { std::memset(this->_tag, 0,
sizeof(std::uint8_t) * 4); }
112 ChunkTag(
const std::uint8_t *tag, std::size_t size) { this->set_tag(tag, size); }
113 ChunkTag(
const char *tag) { this->set_tag(std::string(tag)); }
114 ChunkTag(
const std::string tag) { this->set_tag(tag); }
117 bool operator==(
const ChunkTag &other)
const;
126 void set_tag(
const std::string tag);
136 void set_tag(
const std::uint8_t *tag, std::size_t size);
144 const std::uint8_t *tag()
const;
148 std::string to_string()
const;
163 std::vector<std::uint8_t> _data;
169 _data(&reinterpret_cast<const std::uint8_t *>(ptr)[0],
170 &reinterpret_cast<const std::uint8_t *>(ptr)[size]) {}
171 ChunkVec(
const ChunkTag tag,
const std::vector<std::uint8_t> &data) : _tag(tag), _data(data) {}
174 bool operator==(
const ChunkVec &other)
const;
178 std::size_t length()
const;
189 std::vector<std::uint8_t> &data();
192 const std::vector<std::uint8_t> &data()
const;
196 void set_data(std::vector<std::uint8_t> &data);
200 std::uint32_t crc()
const;
206 std::pair<std::vector<std::uint8_t>,
ChunkPtr> to_chunk_ptr()
const;
210 template <
typename T>
212 static_assert(std::is_base_of<ChunkVec, T>::value,
213 "Upcast type must derive ChunkVec");
215 return *
static_cast<T*
>(
this);
220 template <
typename T>
222 static_assert(std::is_base_of<ChunkVec, T>::value,
223 "Upcast type must derive ChunkVec");
225 return *
static_cast<const T*
>(
this);
238 const ChunkVec &as_chunk_vec()
const;
251 const std::uint32_t *_length;
253 const std::uint8_t *_data;
254 const std::uint32_t *_crc;
256 ChunkPtr(
const std::uint32_t *length,
const ChunkTag *tag,
const std::uint8_t *data,
const std::uint32_t *crc)
263 ChunkPtr() : _length(nullptr), _tag(nullptr), _data(nullptr), _crc(nullptr) {}
265 : _length(other._length),
279 static ChunkPtr parse(
const void *ptr, std::size_t size, std::size_t offset);
286 static ChunkPtr parse(
const std::vector<std::uint8_t> &vec, std::size_t offset);
290 std::size_t length()
const;
296 std::vector<std::uint8_t> data()
const;
301 std::uint32_t crc()
const;
305 bool validate()
const;
311 std::size_t chunk_size()
const;
316 std::vector<std::uint8_t> chunk_data()
const;
357 template <
typename _Base=std::u
int8_t, std::
size_t _Bits=sizeof(_Base)*8>
363 static_assert(_Bits == 1 || _Bits == 2 || _Bits == 4 || _Bits == 8 || _Bits == 16,
364 "Bits must be 1, 2, 4, 8 or 16.");
365 static_assert(std::is_same<_Base,std::uint8_t>::value || std::is_same<_Base,std::uint16_t>::value,
366 "Base must be uint8_t or uint16_t.");
367 static_assert((std::is_same<_Base,std::uint16_t>::value && _Bits == 16) ||
368 (std::is_same<_Base,std::uint8_t>::value && _Bits <= 8),
369 "Bit size does not match the base type.");
377 const static std::size_t Bits = _Bits;
379 const static std::size_t Max = (1 << Bits) - 1;
397 if constexpr (Bits == 16) {
return endian_swap_16(this->_value); }
398 else {
return this->_value & this->Max; }
411 if constexpr (Bits == 1 || Bits == 2 || Bits == 4)
413 this->_value = value & this->Max;
415 else if constexpr (Bits == 16) { this->_value =
endian_swap_16(value); }
416 else { this->_value = value; }
437 template <typename _Base=std::uint8_t, std::
size_t _Bits=sizeof(_Base)*8>
464 template <
typename _Sample=Sample8Bit>
470 static_assert(std::is_same<_Sample,Sample8Bit>::value || std::is_same<_Sample,Sample16Bit>::value,
471 "Sample type must be Sample8Bit or Sample16Bit.");
473 _Sample _red, _green, _blue;
492 _green(other._green),
493 _blue(other._blue) {}
530 template <std::
size_t _Bits=sizeof(std::uint8_t)*8>
533 static_assert(_Bits == 1 || _Bits == 2 || _Bits == 4 || _Bits == 8,
534 "Bits can only be 1, 2, 4, or 8.");
558 template <
typename _Base=std::u
int8_t>
564 static_assert(std::is_same<_Base,std::uint8_t>::value || std::is_same<_Base,std::uint16_t>::value,
565 "Base must be uint8_t or uint16_t.");
611 const static std::size_t Bits=_Sample::Bits*4;
618 : _alpha(other._alpha),
623 _Sample &
alpha() {
return this->_alpha; }
627 const _Sample &
alpha()
const {
return this->_alpha; }
677#define ASSERT_PIXEL(pixel) static_assert(std::is_same<pixel, GrayscalePixel1Bit>::value || \
678 std::is_same<pixel, GrayscalePixel2Bit>::value || \
679 std::is_same<pixel, GrayscalePixel4Bit>::value || \
680 std::is_same<pixel, GrayscalePixel8Bit>::value || \
681 std::is_same<pixel, GrayscalePixel16Bit>::value || \
682 std::is_same<pixel, TrueColorPixel8Bit>::value || \
683 std::is_same<pixel, TrueColorPixel16Bit>::value || \
684 std::is_same<pixel, PalettePixel1Bit>::value || \
685 std::is_same<pixel, PalettePixel2Bit>::value || \
686 std::is_same<pixel, PalettePixel4Bit>::value || \
687 std::is_same<pixel, PalettePixel8Bit>::value || \
688 std::is_same<pixel, AlphaGrayscalePixel8Bit>::value || \
689 std::is_same<pixel, AlphaGrayscalePixel16Bit>::value || \
690 std::is_same<pixel, AlphaTrueColorPixel8Bit>::value || \
691 std::is_same<pixel, AlphaTrueColorPixel16Bit>::value, \
692 #pixel " is not a base pixel-type.")
703 template <
typename PixelType>
712 std::uint8_t bytes[PixelType::Bits/8];
723 const static std::size_t Samples = (8 / PixelType::Bits) +
static_cast<int>(PixelType::Bits > 8);
733 const std::uint8_t *
data()
const {
734 auto u8_ptr =
reinterpret_cast<const std::uint8_t *
>(&this->_data);
740 std::size_t
data_size()
const {
return sizeof(PixelType); }
750 if constexpr (PixelType::Bits < 8) {
751 auto bits = this->_data.bits;
752 bits >>= (this->Samples - 1 - index) * PixelType::Bits;
753 bits &= PixelType::Max;
755 return PixelType(bits);
757 else {
return *
reinterpret_cast<const PixelType *
>(&this->_data.bytes[0]); }
768 void set(
const Pixel &pixel, std::size_t index=0) {
772 if constexpr (PixelType::Bits < 8)
774 auto bits = this->_data.bits;
775 auto shift = (this->Samples - 1 - index) * PixelType::Bits;
776 auto mask = (PixelType::Max << shift) ^ 0xFF;
778 auto value = std::get<PixelType>(pixel).value();
779 this->_data.bits = (bits & mask) | (value << shift);
782 std::memcpy(&this->_data.bytes[0], &pixel, PixelType::Bits/8);
789 template <
typename PixelType>
790 using PixelRow = std::vector<PixelSpan<PixelType>>;
796 template <
typename PixelType>
799 std::vector<std::uint8_t> result;
801 for (
auto &span : pixels)
803 auto data = span.data();
804 result.insert(result.end(), &data[0], &data[span.data_size()]);
819 Header(
const void *ptr, std::size_t size) :
ChunkVec(std::string(
"IHDR"), ptr, size) {}
820 Header(
const std::vector<std::uint8_t> &vec) :
ChunkVec(std::string(
"IHDR"), vec) {}
821 Header(std::uint32_t width, std::uint32_t height, std::uint8_t bit_depth,
822 std::uint8_t color_type, std::uint8_t compression_method=0,
823 std::uint8_t filter_method=0, std::uint8_t interlace_method=0)
824 :
ChunkVec(std::string(
"IHDR"), std::vector<std::uint8_t>(13))
846 void set(std::uint32_t width, std::uint32_t height, std::uint8_t bit_depth,
847 std::uint8_t color_type, std::uint8_t compression_method=0,
848 std::uint8_t filter_method=0, std::uint8_t interlace_method=0);
852 std::uint32_t width()
const;
855 void set_width(std::uint32_t width);
858 std::uint32_t height()
const;
860 void set_height(std::uint32_t height);
863 std::uint8_t bit_depth()
const;
865 void set_bit_depth(std::uint8_t bit_depth);
868 std::uint8_t color_type()
const;
870 void set_color_type(std::uint8_t color_type);
873 std::uint8_t compression_method()
const;
875 void set_compression_method(std::uint8_t compression_method);
878 std::uint8_t filter_method()
const;
880 void set_filter_method(std::uint8_t filter_method);
883 std::uint8_t interlace_method()
const;
885 void set_interlace_method(std::uint8_t interlace_method);
896 std::size_t pixel_size()
const;
899 std::size_t buffer_size()
const;
909 Text(std::string keyword, std::string text) :
ChunkVec(std::string(
"tEXt")) {
910 this->set_keyword(keyword);
911 this->set_text(text);
919 std::optional<std::size_t> null_terminator()
const;
923 std::size_t text_offset()
const;
929 bool has_keyword()
const;
934 std::string keyword()
const;
940 void set_keyword(std::string keyword,
bool validate=
true);
945 bool has_text()
const;
948 std::string text()
const;
951 void set_text(std::string text);
961 ZText(std::string keyword, std::string text) :
ChunkVec(std::string(
"zTXt")) {
962 this->set_keyword(keyword);
963 this->set_compression_method(0);
964 this->set_text(text);
972 std::optional<std::size_t> null_terminator()
const;
976 std::size_t text_offset()
const;
982 bool has_keyword()
const;
987 std::string keyword()
const;
993 void set_keyword(std::string keyword,
bool validate=
true);
996 std::uint8_t compression_method()
const;
1001 void set_compression_method(std::uint8_t compression_method);
1006 bool has_text()
const;
1009 std::string text()
const;
1012 void set_text(std::string text);
1039 template <
typename PixelType>
1051 std::uint8_t _filter_type;
1052 std::vector<Span> _pixel_data;
1057 : _filter_type(filter_type),
1058 _pixel_data(width /
Span::Samples + static_cast<int>(width %
Span::Samples != 0)) {}
1059 ScanlineBase(std::uint8_t filter_type, std::vector<Span> pixel_data) : _filter_type(filter_type), _pixel_data(pixel_data) {}
1069 static ScanlineBase read_line(
const std::vector<std::uint8_t> &raw_data, std::size_t offset, std::size_t width);
1078 static std::vector<ScanlineBase> from_raw(
const Header &header,
const std::vector<std::uint8_t> &raw_data);
1083 Pixel operator[](std::size_t index)
const;
1087 std::uint8_t filter_type()
const;
1090 void set_filter_type(std::uint8_t filter_type);
1092#if !defined(LIBFACADE_WIN32)
1097 const std::vector<Span> &pixel_data()
const;
1125 const Span &get_span(std::size_t index)
const;
1134 void set_span(
const Span &span, std::size_t index);
1142 Pixel get_pixel(std::size_t index)
const;
1149 void set_pixel(
const Pixel &pixel, std::size_t index);
1153 std::vector<std::uint8_t> to_raw()
const;
1165 ScanlineBase reconstruct(std::optional<ScanlineBase> previous)
const;
1262 Pixel operator[](std::size_t index)
const;
1267 std::uint8_t filter_type()
const;
1271 void set_filter_type(std::uint8_t filter_type);
1276 std::size_t pixel_span()
const;
1280 std::size_t pixel_width()
const;
1285 Pixel get_pixel(std::size_t index)
const;
1289 void set_pixel(
const Pixel &pixel, std::size_t index);
1294 std::vector<std::uint8_t> to_raw()
const;
1308 static const std::uint8_t Signature[8];
1320 Image(
const void *ptr, std::size_t size,
bool validate=
true) { this->parse(ptr, size, validate); }
1321 Image(
const std::vector<std::uint8_t> &data,
bool validate=
true) { this->parse(data, validate); }
1322 Image(
const std::string &filename,
bool validate=
true) { this->parse(filename, validate); }
1323 Image(
const Image &other) : chunk_map(other.chunk_map), trailing_data(other.trailing_data), image_data(other.image_data) {}
1331 Scanline &operator[](std::size_t index);
1335 const Scanline &operator[](std::size_t index)
const;
1340 bool has_chunk(
const std::string &tag)
const;
1345 std::vector<ChunkVec> get_chunks(
const std::string &tag)
const;
1348 void add_chunk(
const ChunkVec &chunk);
1352 bool has_trailing_data()
const;
1357 std::vector<std::uint8_t> &get_trailing_data();
1362 const std::vector<std::uint8_t> &get_trailing_data()
const;
1365 void set_trailing_data(
const std::vector<std::uint8_t> &data);
1368 void clear_trailing_data();
1378 void parse(
const void *ptr, std::size_t size,
bool validate=
true);
1382 void parse(
const std::vector<std::uint8_t> &data,
bool validate=
true);
1388 void parse(
const std::string &filename,
bool validate=
true);
1404 Scanline &scanline(std::size_t index);
1410 const Scanline &scanline(std::size_t index)
const;
1414 bool has_header()
const;
1424 const Header &header()
const;
1432 std::size_t width()
const;
1436 std::size_t height()
const;
1440 bool has_image_data()
const;
1445 bool is_loaded()
const;
1461 void compress(std::optional<std::size_t> chunk_size=8192,
int level=-1);
1480 std::vector<std::uint8_t> to_file()
const;
1485 void save(
const std::string &filename)
const;
1489 bool has_text()
const;
1496 Text &add_text(
const std::string &keyword,
const std::string &text);
1500 void remove_text(
const Text &text);
1504 void remove_text(
const std::string &keyword,
const std::string &text);
1508 std::vector<Text> get_text(
const std::string &keyword)
const;
1512 bool has_ztext()
const;
1519 ZText &add_ztext(
const std::string &keyword,
const std::string &text);
1523 void remove_ztext(
const ZText &ztext);
1527 void remove_ztext(
const std::string &keyword,
const std::string &text);
1531 std::vector<ZText> get_ztext(
const std::string &keyword)
const;
An exception thrown when a given integer overflows.
Definition: exception.hpp:264
An exception thrown when the operation goes out of bounds.
Definition: exception.hpp:48
An exception thrown when pixel types do not match up.
Definition: exception.hpp:184
A grayscale pixel with alpha channel.
Definition: png.hpp:563
Sample< _Base > & alpha()
The alpha channel of this pixel.
Definition: png.hpp:584
AlphaGrayscalePixel(Sample< _Base > value, Sample< _Base > alpha)
Definition: png.hpp:579
AlphaGrayscalePixel(const AlphaGrayscalePixel &other)
Definition: png.hpp:580
AlphaGrayscalePixel()
Definition: png.hpp:578
_Base Base
The type base of the samples in this pixel.
Definition: png.hpp:570
const Sample< _Base > & alpha() const
The const alpha channel of this pixel.
Definition: png.hpp:588
An RGB pixel with alpha channel.
Definition: png.hpp:607
_Sample & alpha()
The alpha channel of this pixel.
Definition: png.hpp:623
const _Sample & alpha() const
The const alpha channel of this pixel.
Definition: png.hpp:627
AlphaTrueColorPixel(_Sample red, _Sample green, _Sample blue, _Sample alpha)
Definition: png.hpp:614
AlphaTrueColorPixel(const AlphaTrueColorPixel &other)
Definition: png.hpp:617
AlphaTrueColorPixel()
Definition: png.hpp:613
The chunk class responsible for parsing the raw data of a PNG file.
Definition: png.hpp:250
ChunkPtr()
Definition: png.hpp:263
ChunkPtr(const ChunkPtr &other)
Definition: png.hpp:264
The string tag identifying a given facade::png::ChunkVec or facade::png::ChunkPtr.
Definition: png.hpp:107
ChunkTag()
Definition: png.hpp:111
ChunkTag(const char *tag)
Definition: png.hpp:113
ChunkTag(const std::uint8_t *tag, std::size_t size)
Definition: png.hpp:112
ChunkTag(const std::string tag)
Definition: png.hpp:114
ChunkTag(const ChunkTag &other)
Definition: png.hpp:115
A vector-based version of a given PNG chunk.
Definition: png.hpp:161
T & upcast()
Create a reference to a higher-level ChunkVec object, such as facade::png::Header.
Definition: png.hpp:211
ChunkVec(const ChunkTag tag, const void *ptr, std::size_t size)
Definition: png.hpp:167
ChunkVec(const ChunkVec &other)
Definition: png.hpp:172
ChunkVec(const ChunkTag tag)
Definition: png.hpp:166
const T & upcast() const
Create a const reference to a higher-level ChunkVec object, such as facade::png::Header.
Definition: png.hpp:221
ChunkVec(const ChunkTag tag, const std::vector< std::uint8_t > &data)
Definition: png.hpp:171
The end chunk for a given PNG file.
Definition: png.hpp:1019
End()
Definition: png.hpp:1021
End(const End &other)
Definition: png.hpp:1022
A grayscale pixel object, based on the facade::png::Sample class.
Definition: png.hpp:439
GrayscalePixel()
Definition: png.hpp:441
GrayscalePixel(_Base value)
Definition: png.hpp:442
GrayscalePixel(const GrayscalePixel &other)
Definition: png.hpp:443
A class for loading and manipulating PNG images.
Definition: png.hpp:1305
Image(const Image &other)
Definition: png.hpp:1323
Image(const std::string &filename, bool validate=true)
Definition: png.hpp:1322
Image(const std::vector< std::uint8_t > &data, bool validate=true)
Definition: png.hpp:1321
std::optional< std::vector< std::uint8_t > > trailing_data
A container for trailing data, if present when parsing or when writing afterward.
Definition: png.hpp:1314
Image()
Definition: png.hpp:1319
Image(const void *ptr, std::size_t size, bool validate=true)
Definition: png.hpp:1320
std::map< std::string, std::vector< ChunkVec > > chunk_map
A map of chunk tags to their corresponding facade::png::ChunkVec types.
Definition: png.hpp:1312
std::optional< std::vector< Scanline > > image_data
The loaded image data from the compressed IDAT chunks.
Definition: png.hpp:1316
A paletted pixel object.
Definition: png.hpp:532
PalettePixel(const PalettePixel &other)
Definition: png.hpp:539
PalettePixel()
Definition: png.hpp:537
PalettePixel(std::uint8_t value)
Definition: png.hpp:538
A span of data representing the underlying bits or bytes of a pixel.
Definition: png.hpp:707
Pixel get(std::size_t index=0) const
Retrieve a facade::png::Pixel variant of the underlying pixel type at the given index.
Definition: png.hpp:747
PixelSpan(const PixelSpan &other)
Definition: png.hpp:717
std::uint8_t bits
Definition: png.hpp:711
void set(const Pixel &pixel, std::size_t index=0)
Set a given facade::png::Pixel variant at the given offset.
Definition: png.hpp:768
const std::uint8_t * data() const
Return the underlying raw byte data representing this pixel span.
Definition: png.hpp:733
std::size_t data_size() const
Return the size of this pixel span.
Definition: png.hpp:740
Pixel operator[](std::size_t index) const
Syntactic sugar to get a facade::png::Pixel variant out of this span.
Definition: png.hpp:729
PixelSpan()
Definition: png.hpp:716
A sample of data for a given pixel.
Definition: png.hpp:362
Sample(const Sample &other)
Definition: png.hpp:383
Base value() const
Get the value retained by this sample.
Definition: png.hpp:396
Base operator*() const
Syntactic sugar to get the value of this sample.
Definition: png.hpp:388
Sample(Base value)
Definition: png.hpp:382
static const std::size_t Bits
The size, in bits, of this sample.
Definition: png.hpp:377
void set_value(Base value)
Assign the given value to this sample.
Definition: png.hpp:408
Sample()
Definition: png.hpp:381
static const std::size_t Max
The maximum value that can be used with this sample.
Definition: png.hpp:379
Sample & operator=(Base value)
Syntactic sugar to assign the value of this sample.
Definition: png.hpp:392
_Base Base
The base type used by this sample.
Definition: png.hpp:375
The base scanline class containing a row of facade::png::PixelSpan of the given pixel type.
Definition: png.hpp:1043
ScanlineBase(const ScanlineBase &other)
Definition: png.hpp:1060
std::size_t pixel_width() const
Return the size, in samples, of the given scanline.
__attribute__((used)) const std std::size_t pixel_span() const
Return a const reference to the underlying pixel data array.
ScanlineBase filter(std::optional< ScanlineBase > previous) const
Calculate all filters and determine the best compressed filter among them.
ScanlineBase(std::uint8_t filter_type, std::vector< Span > pixel_data)
Definition: png.hpp:1059
ScanlineBase(std::uint8_t filter_type, std::size_t width)
Definition: png.hpp:1056
ScanlineBase filter(FilterType filter_type, std::optional< ScanlineBase > previous) const
Calculate the given filter type on this scanline.
ScanlineBase()
Definition: png.hpp:1055
Span & get_span(std::size_t index)
Get the facade::png::PixelSpan reference at the given index.
A wrapper object for ScanlineVariant.
Definition: png.hpp:1239
Scanline(const GrayscaleScanline4Bit &scanline)
Definition: png.hpp:1244
Scanline(const GrayscaleScanline16Bit &scanline)
Definition: png.hpp:1246
Scanline(const AlphaTrueColorScanline8Bit &scanline)
Definition: png.hpp:1255
Scanline(const Scanline &other)
Definition: png.hpp:1257
Scanline(const AlphaTrueColorScanline16Bit &scanline)
Definition: png.hpp:1256
Scanline(const TrueColorScanline16Bit &scanline)
Definition: png.hpp:1248
Scanline()
Definition: png.hpp:1241
Scanline(const TrueColorScanline8Bit &scanline)
Definition: png.hpp:1247
Scanline(const GrayscaleScanline2Bit &scanline)
Definition: png.hpp:1243
Scanline(const PaletteScanline2Bit &scanline)
Definition: png.hpp:1250
Scanline(const PaletteScanline4Bit &scanline)
Definition: png.hpp:1251
Scanline(const AlphaGrayscaleScanline8Bit &scanline)
Definition: png.hpp:1253
Scanline(const PaletteScanline1Bit &scanline)
Definition: png.hpp:1249
Scanline(const GrayscaleScanline8Bit &scanline)
Definition: png.hpp:1245
Scanline(const PaletteScanline8Bit &scanline)
Definition: png.hpp:1252
Scanline(const GrayscaleScanline1Bit &scanline)
Definition: png.hpp:1242
Scanline(const AlphaGrayscaleScanline16Bit &scanline)
Definition: png.hpp:1254
A tEXt chunk object.
Definition: png.hpp:906
Text(std::string keyword, std::string text)
Definition: png.hpp:909
Text()
Definition: png.hpp:908
Text(const Text &other)
Definition: png.hpp:913
An RGB pixel object.
Definition: png.hpp:469
_Sample Sample
The sample class that was used in creating this class.
Definition: png.hpp:477
Sample & blue()
Retrieve a reference to the blue channel.
Definition: png.hpp:511
const Sample & blue() const
Retrieve a const reference to the blue channel.
Definition: png.hpp:514
TrueColorPixel(const TrueColorPixel &other)
Definition: png.hpp:490
typename Sample::Base Base
The base type of the sample class used in creating this class.
Definition: png.hpp:479
Sample & red()
Retrieve a reference to the red channel.
Definition: png.hpp:497
const Sample & green() const
Retrieve a const reference to the green channel.
Definition: png.hpp:507
TrueColorPixel(Sample red, Sample green, Sample blue)
Definition: png.hpp:486
Sample & green()
Retrieve a reference to the green channel.
Definition: png.hpp:504
TrueColorPixel()
Definition: png.hpp:485
const Sample & red() const
Retrieve a const reference to the red channel.
Definition: png.hpp:500
A compressed text chunk.
Definition: png.hpp:958
ZText()
Definition: png.hpp:960
ZText(std::string keyword, std::string text)
Definition: png.hpp:961
ZText(const Text &other)
Definition: png.hpp:966
A collection of exceptions thrown by the library.
TrueColorPixel< Sample16Bit > TrueColorPixel16Bit
A facade::png::TrueColorPixel with a 16-bit facade::png::Sample value.
Definition: png.hpp:521
GrayscalePixel< std::uint8_t > GrayscalePixel8Bit
A facade::png::GrayscalePixel with an 8-bit facade::png::Sample value.
Definition: png.hpp:455
PalettePixel< 2 > PalettePixel2Bit
A facade::png::PalettePixel object with a 2-bit facade::png::Sample value.
Definition: png.hpp:547
std::variant< GrayscaleScanline1Bit, GrayscaleScanline2Bit, GrayscaleScanline4Bit, GrayscaleScanline8Bit, GrayscaleScanline16Bit, TrueColorScanline8Bit, TrueColorScanline16Bit, PaletteScanline1Bit, PaletteScanline2Bit, PaletteScanline4Bit, PaletteScanline8Bit, AlphaGrayscaleScanline8Bit, AlphaGrayscaleScanline16Bit, AlphaTrueColorScanline8Bit, AlphaTrueColorScanline16Bit > ScanlineVariant
A variant type containing all accepted scanline types.
Definition: png.hpp:1232
ColorType
The color type represented in the PNG file.
Definition: png.hpp:325
@ PALETTE
Definition: png.hpp:328
@ TRUE_COLOR
Definition: png.hpp:327
@ GRAYSCALE
Definition: png.hpp:326
@ ALPHA_GRAYSCALE
Definition: png.hpp:329
@ ALPHA_TRUE_COLOR
Definition: png.hpp:330
ScanlineBase< GrayscalePixel16Bit > GrayscaleScanline16Bit
A 16-bit grayscale scanline, using facade::png::GrayscalePixel16Bit as a pixel base.
Definition: png.hpp:1192
std::vector< PixelSpan< PixelType > > PixelRow
A vector of a facade::png::PixelSpan of the given pixel type.
Definition: png.hpp:790
AlphaGrayscalePixel< std::uint8_t > AlphaGrayscalePixel8Bit
An facade::png::AlphaGrayscalePixel with an 8-bit facade::png::Sample size.
Definition: png.hpp:593
AlphaGrayscalePixel< std::uint16_t > AlphaGrayscalePixel16Bit
An facade::png::AlphaGrayscalePixel with a 16-bit facade::png::Sample size.
Definition: png.hpp:595
ScanlineBase< PalettePixel1Bit > PaletteScanline1Bit
A 1-bit palette scanline, using facade::png::PalettePixel1Bit as a pixel base.
Definition: png.hpp:1198
ScanlineBase< AlphaTrueColorPixel8Bit > AlphaTrueColorScanline8Bit
An 8-bit RGB scanline with alpha channel, using facade::png::AlphaTrueColorPixel8Bit as a pixel base.
Definition: png.hpp:1210
ScanlineBase< PalettePixel2Bit > PaletteScanline2Bit
A 2-bit palette scanline, using facade::png::PalettePixel2Bit as a pixel base.
Definition: png.hpp:1200
ScanlineBase< TrueColorPixel8Bit > TrueColorScanline8Bit
An 8-bit RGB scanline, using facade::png::TrueColorPixel8Bit as a pixel base.
Definition: png.hpp:1194
GrayscalePixel< std::uint8_t, 1 > GrayscalePixel1Bit
A facade::png::GrayscalePixel with a 1-bit facade::png::Sample value.
Definition: png.hpp:449
GrayscalePixel< std::uint16_t > GrayscalePixel16Bit
A facade::png::GrayscalePixel with a 16-bit facade::png::Sample value.
Definition: png.hpp:457
PalettePixel< 1 > PalettePixel1Bit
A facade::png::PalettePixel object with a 1-bit facade::png::Sample value.
Definition: png.hpp:545
ScanlineBase< AlphaGrayscalePixel16Bit > AlphaGrayscaleScanline16Bit
A 16-bit grayscale scanline with alpha channel, using facade::png::AlphaGrayscalePixel16Bit as a pixe...
Definition: png.hpp:1208
TrueColorPixel< Sample8Bit > TrueColorPixel8Bit
A facade::png::TrueColorPixel with an 8-bit facade::png::Sample value.
Definition: png.hpp:519
AlphaTrueColorPixel< Sample8Bit > AlphaTrueColorPixel8Bit
An facade::png::AlphaTrueColorPixel with an 8-bit facade::png::Sample size.
Definition: png.hpp:632
ScanlineBase< PalettePixel8Bit > PaletteScanline8Bit
An 8-bit palette scanline, using facade::png::PalettePixel8Bit as a pixel base.
Definition: png.hpp:1204
ScanlineBase< AlphaGrayscalePixel8Bit > AlphaGrayscaleScanline8Bit
An 8-bit grayscale scanline with alpha channel, using facade::png::AlphaGrayscalePixel8Bit as a pixel...
Definition: png.hpp:1206
EXPORT std::vector< std::uint8_t > pixels_to_raw(const PixelRow< PixelType > &pixels)
Convert a row of facade::png::PixelSpan of the given pixel type into a vector of bytes.
Definition: png.hpp:797
std::variant< GrayscalePixel1Bit, GrayscalePixel2Bit, GrayscalePixel4Bit, GrayscalePixel8Bit, GrayscalePixel16Bit, TrueColorPixel8Bit, TrueColorPixel16Bit, PalettePixel1Bit, PalettePixel2Bit, PalettePixel4Bit, PalettePixel8Bit, AlphaGrayscalePixel8Bit, AlphaGrayscalePixel16Bit, AlphaTrueColorPixel8Bit, AlphaTrueColorPixel16Bit > Pixel
The variant type corresponding to all known pixel types for PNG images.
Definition: png.hpp:674
PalettePixel< 8 > PalettePixel8Bit
A facade::png::PalettePixel object with an 8-bit facade::png::Sample value.
Definition: png.hpp:551
ScanlineBase< PalettePixel4Bit > PaletteScanline4Bit
A 4-bit palette scanline, using facade::png::PalettePixel4Bit as a pixel base.
Definition: png.hpp:1202
ScanlineBase< GrayscalePixel1Bit > GrayscaleScanline1Bit
A 1-bit grayscale scanline, using facade::png::GrayscalePixel1Bit as a pixel base.
Definition: png.hpp:1184
ScanlineBase< GrayscalePixel2Bit > GrayscaleScanline2Bit
A 2-bit grayscale scanline, using facade::png::GrayscalePixel2Bit as a pixel base.
Definition: png.hpp:1186
FilterType
The filter type to use for a given scanline.
Definition: png.hpp:1028
@ AVERAGE
Definition: png.hpp:1032
@ PAETH
Definition: png.hpp:1033
@ SUB
Definition: png.hpp:1030
@ NONE
Definition: png.hpp:1029
@ UP
Definition: png.hpp:1031
ScanlineBase< TrueColorPixel16Bit > TrueColorScanline16Bit
A 16-bit RGB scanline, using facade::png::TrueColorPixel16Bit as a pixel base.
Definition: png.hpp:1196
GrayscalePixel< std::uint8_t, 4 > GrayscalePixel4Bit
A facade::png::GrayscalePixel with a 4-bit facade::png::Sample value.
Definition: png.hpp:453
GrayscalePixel< std::uint8_t, 2 > GrayscalePixel2Bit
A facade::png::GrayscalePixel with a 2-bit facade::png::Sample value.
Definition: png.hpp:451
PixelEnum
An enum representing all available pixel types.
Definition: png.hpp:640
@ PALETTE_PIXEL_1BIT
Definition: png.hpp:648
@ ALPHA_TRUE_COLOR_PIXEL_16BIT
Definition: png.hpp:655
@ ALPHA_GRAYSCALE_PIXEL_16BIT
Definition: png.hpp:653
@ GRAYSCALE_PIXEL_1BIT
Definition: png.hpp:641
@ GRAYSCALE_PIXEL_8BIT
Definition: png.hpp:644
@ PALETTE_PIXEL_8BIT
Definition: png.hpp:651
@ GRAYSCALE_PIXEL_16BIT
Definition: png.hpp:645
@ PALETTE_PIXEL_4BIT
Definition: png.hpp:650
@ TRUE_COLOR_PIXEL_16BIT
Definition: png.hpp:647
@ ALPHA_TRUE_COLOR_PIXEL_8BIT
Definition: png.hpp:654
@ TRUE_COLOR_PIXEL_8BIT
Definition: png.hpp:646
@ GRAYSCALE_PIXEL_2BIT
Definition: png.hpp:642
@ PALETTE_PIXEL_2BIT
Definition: png.hpp:649
@ ALPHA_GRAYSCALE_PIXEL_8BIT
Definition: png.hpp:652
@ GRAYSCALE_PIXEL_4BIT
Definition: png.hpp:643
PalettePixel< 4 > PalettePixel4Bit
A facade::png::PalettePixel object with a 4-bit facade::png::Sample value.
Definition: png.hpp:549
ScanlineBase< GrayscalePixel4Bit > GrayscaleScanline4Bit
A 4-bit grayscale scanline, using facade::png::GrayscalePixel4Bit as a pixel base.
Definition: png.hpp:1188
ScanlineBase< GrayscalePixel8Bit > GrayscaleScanline8Bit
An 8-bit grayscale scanline, using facade::png::GrayscalePixel8Bit as a pixel base.
Definition: png.hpp:1190
Definition: exception.hpp:14
EXPORT std::uint16_t endian_swap_16(std::uint16_t value)
Swap the endianness of a 16-bit value.
Definition: utility.cpp:5
EXPORT std::vector< std::uint8_t > compress(const void *ptr, std::size_t size, int level)
Compress the given data buffer with the given compression level.
Definition: utility.cpp:30
EXPORT std::vector< std::uint8_t > decompress(const void *ptr, std::size_t size)
Decompress the given data buffer with zlib's inflate algorithm.
Definition: utility.cpp:67
__attribute__((used)) const std
Definition: png.cpp:617
#define ASSERT_PIXEL(pixel)
Macro that creates a static_assert that the given argument class is a known base pixel type.
Definition: png.hpp:677
Functions relating to the needs of images in the program.