From 5823a8dff5c6c565c9b253b122d2baeb767b72e2 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Thu, 24 Jul 2025 12:46:39 +1200 Subject: feat: Added filter method 3 the average filter method --- src/PNGImage.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PNGImage.cpp b/src/PNGImage.cpp index b70f5ed..b6002ca 100644 --- a/src/PNGImage.cpp +++ b/src/PNGImage.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -346,6 +347,14 @@ DEFINE_CHUNK_READER(IEND) uint8_t prior = (y>=1)?imageDataIndex(x, (y-1)):0; imageDataIndex(x, y) = up + prior; } + else if(filterByte(y) == 3) + { + uint8_t avg = pngImageDataIndex(x, y); + uint8_t a = (x>=bpp)?imageDataIndex((x-bpp), y):0; + uint8_t b = (y>=1)?imageDataIndex(x, (y-1)):0; + imageDataIndex(x, y) = avg + std::floor((a + b)/2); + + } else if(filterByte(y) == 4) { uint8_t a = (x>=bpp)?imageDataIndex((x-bpp), y):0; @@ -358,7 +367,7 @@ DEFINE_CHUNK_READER(IEND) else { cout << "No method for filter type: " << (int)filterByte(y) << ", row: " << y << endl; - throw "uh oh"; + throw std::invalid_argument("Filter type not implemented"); } } } -- cgit v1.2.3