aboutsummaryrefslogtreecommitdiff
path: root/src/PNGImage.h
diff options
context:
space:
mode:
authorDylan <boss@tehbox.org>2026-05-06 13:39:47 +1200
committerDylan <boss@tehbox.org>2026-05-06 13:39:47 +1200
commitd60976a70e68e1cd312b0e56fe6fbe6c7428cbaa (patch)
tree00bc987a6d935ca26e4d4c2d61ad70d7aa3c2f4c /src/PNGImage.h
parenta75bdd0e167140eeb4afb091c9dedd84474c8531 (diff)
downloadtehimage-d60976a70e68e1cd312b0e56fe6fbe6c7428cbaa.tar.gz
tehimage-d60976a70e68e1cd312b0e56fe6fbe6c7428cbaa.zip
feat: Started on PNG writing implementation
Currently writes IHDR and IEND chunks correctly CRC implementation is borrowed from the specification Writer class now also has a buffer for the CRC calculation
Diffstat (limited to 'src/PNGImage.h')
-rw-r--r--src/PNGImage.h35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/PNGImage.h b/src/PNGImage.h
index 1ed1be5..4bbb4ff 100644
--- a/src/PNGImage.h
+++ b/src/PNGImage.h
@@ -10,16 +10,28 @@
#include <string>
#include <vector>
-#define CHUNK_READER(X) void X(uint32_t chunkSize)
-#define REGISTER_CHUNK_READER(X) chunkReaders.insert({#X, &PNGImage::X})
-#define DEFINE_CHUNK_READER(X) void PNGImage::X(uint32_t chunkSize)
+#define CHUNK_READER(X) void read##X(uint32_t chunkSize)
+#define REGISTER_CHUNK_READER(X) chunkReaders.insert({#X, &PNGImage::read##X})
+#define DEFINE_CHUNK_READER(X) void PNGImage::read##X(uint32_t chunkSize)
+
+#define CHUNK_WRITER(X) void write##X()
+#define DEFINE_CHUNK_WRITER(X) void PNGImage::write##X()
+
+
namespace TehImage
{
-
class PNGImage : public Image
{
public:
+ typedef enum
+ {
+ GRAYSCALE = 0,
+ TRUECOLOR = 2,
+ INDEXED = 3,
+ ALPHA = 4
+ } ColorTypes;
+
PNGImage();
~PNGImage();
@@ -44,8 +56,6 @@ namespace TehImage
uint8_t hour;
uint8_t minute;
uint8_t second;
-
- bool readNextChunk();
private:
std::map<std::string, void(PNGImage::*)(uint32_t chunkSize)> chunkReaders;
@@ -60,6 +70,18 @@ namespace TehImage
CHUNK_READER(IDAT);
CHUNK_READER(IEND);
+ CHUNK_WRITER(IHDR);
+ CHUNK_WRITER(IDAT);
+ CHUNK_WRITER(IEND);
+
+
+
+ bool readNextChunk();
+
+ uint32_t calculateCRC(uint8_t *buffer, std::size_t bufflen);
+
+ const uint64_t PNG_CRC = 0x104C11DB7;
+
ZLib zlib;
uint8_t* idatData;
unsigned long idatDataSize;
@@ -67,6 +89,7 @@ namespace TehImage
bool end = false;
Reader *reader;
+ Writer *writer;
};
}