From 3e4cad0bfd36536ffc870d16a6e26aac5049dd0b Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 28 Jun 2025 00:44:40 +1200 Subject: fixup: Updated some stuff Mainly just cleaning up code --- src/PNGImage.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/PNGImage.cpp') diff --git a/src/PNGImage.cpp b/src/PNGImage.cpp index 50df7c6..b70f5ed 100644 --- a/src/PNGImage.cpp +++ b/src/PNGImage.cpp @@ -1,15 +1,15 @@ #include "PNGImage.h" #include "zlib.h" -#include "puff.h" +#include "debug.h" + #include #include #include #include #include #include -#include #include -#include +#include #include using std::cout, std::endl; @@ -130,7 +130,7 @@ DEFINE_CHUNK_READER(IHDR) cout << "Assigning " << imageDataSize << " bytes for image" << endl; - imageData = new uint8_t[imageDataSize]; + imageData = std::make_unique(imageDataSize); /* Scanline>* lines = new Scanline> [height]; @@ -144,7 +144,6 @@ DEFINE_CHUNK_READER(IHDR) DEFINE_CHUNK_READER(iCCP) { - cout << "!!! iCCP chunk reader not finished !!!" << endl; std::string profileName; char c = reader->readByte(); chunkSize--; @@ -167,11 +166,18 @@ DEFINE_CHUNK_READER(iCCP) bool FDICT = FLG & 0b00100000; uint8_t FLEVEL = FLG & 0b11000000; chunkSize--; - cout << std::bitset<4>(CM) << ", " << std::bitset<4>(CINFO) << ", " << (check?"Valid":"Failed checksum") << ", " << (FDICT?"Dict is present":"No dict present") << ", " << std::bitset<2>(FLEVEL) << endl; + if(CM != 8) + cout << "Invalid CM: " << 0+CM << endl; + cout << 0+CM << ", " << 0+CINFO << ", " << (check?"Valid":"Failed checksum") << ", " << (FDICT?"Dict is present":"No dict present") << ", " << 0+FLEVEL << endl; char compressedData[chunkSize - 4]; reader->readBytes(compressedData, chunkSize - 4); - const int compressedSize = chunkSize - 4; + char outData[1024]; + + ZLibInflator inflator; + inflator.decodeData((uint8_t*)compressedData, chunkSize - 4, (uint8_t*)outData, 1024); + + cout << "iCCP not supported" << endl; uint32_t checkValue = reader->readData(); @@ -263,15 +269,17 @@ DEFINE_CHUNK_READER(IDAT) if(idatDataSize == 0) { uint8_t CMF = reader->readByte(); - uint8_t CM = (CMF & 0b11110000) >> 4; - uint8_t CINFO = CMF & 0b00001111; + uint8_t CM = CMF & 0b00001111; + uint8_t CINFO = (CMF & 0b11110000) >> 4; chunkSize--; uint8_t FLG = reader->readByte(); bool check = (CMF * 256 + FLG)%31 == 0; bool FDICT = FLG & 0b00000100; uint8_t FLEVEL = FLG & 0b00000011; chunkSize--; - cout << std::bitset<4>(CM) << ", " << std::bitset<4>(CINFO) << ", " << (check?"Valid":"Failed checksum") << ", " << (FDICT?"Dict is present":"No dict present") << ", " << std::bitset<2>(FLEVEL) << endl; + if(CM != 8) + cout << "Invalid CM: " << 0+CM << endl; + cout << 0+CM << ", " << 0+CINFO << ", " << (check?"Valid":"Failed checksum") << ", " << (FDICT?"Dict is present":"No dict present") << ", " << 0+FLEVEL << endl; idatData = (uint8_t*)malloc(0); } -- cgit v1.2.3