summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-31 13:04:34 +1100
committerTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-31 13:04:34 +1100
commit7c56468903540fefc8029f67395665436f5d26b3 (patch)
treef288373e87429ea0a91ded82de20f2d10663ef8b /src
parent40dbca72e7cfbb01e716d747262c4f28b6cdc638 (diff)
fix(png): Implement Paeth predictor in ff_png_data_handler for scanline filtering
Diffstat (limited to 'src')
-rw-r--r--src/format/image/png.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/format/image/png.c b/src/format/image/png.c
index 1d4109d..162d5ee 100644
--- a/src/format/image/png.c
+++ b/src/format/image/png.c
@@ -218,7 +218,19 @@ ff_result ff_png_data_handler(uint8_t *buf, size_t len, ff_png_ctx *ctx)
reconstructed_buf[x] = raw[x] + ((left + above) / 2);
break;
case 4: // Paeth Predictor
- // TODO: Get a Paeth predictor function
+ {
+ int p = left + above - diagonal;
+ int pa = abs(p - left);
+ int pb = abs(p - above);
+ int pc = abs(p - diagonal);
+
+ if (pa <= pb && pa <= pc)
+ reconstructed_buf[x] = raw[x] + left;
+ else if (pb <= pc)
+ reconstructed_buf[x] = raw[x] + above;
+ else
+ reconstructed_buf[x] = raw[x] + diagonal;
+ }
break;
default: // Unknown
ff_dprintf("png: unsupported scanline filter method '%d'", filter_type);