diff options
| author | BossCode45 <boss@tehbox.org> | 2025-07-24 12:46:39 +1200 |
|---|---|---|
| committer | BossCode45 <boss@tehbox.org> | 2025-07-24 12:48:21 +1200 |
| commit | 5823a8dff5c6c565c9b253b122d2baeb767b72e2 (patch) | |
| tree | 9a1f96321a1c82ba1ef992d2fc22808b5101bc91 | |
| parent | 767cdb89554689134ecaad0549b8beaee7b685d9 (diff) | |
| download | tehimage-5823a8dff5c6c565c9b253b122d2baeb767b72e2.tar.gz tehimage-5823a8dff5c6c565c9b253b122d2baeb767b72e2.zip | |
feat: Added filter method 3
the average filter method
| -rw-r--r-- | src/PNGImage.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
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 <bitset> #include <cctype> +#include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> @@ -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"); } } } |
