summaryrefslogtreecommitdiff
path: root/include/tinyff
diff options
context:
space:
mode:
authorTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-26 20:47:57 +1100
committerTazyFoundSoup <gardendistrict0x0@outlook.com>2026-01-26 20:47:57 +1100
commit4702ca610c84818a90cf0d6aa73a6711285b8a5b (patch)
treef83de40d543837de737d6f0f8be06bd3793a0245 /include/tinyff
parent245c07842e49da00c254b2ffb411763e71deaa67 (diff)
feat(png): Add small BpP helper function for ff_png_ctx
Diffstat (limited to 'include/tinyff')
-rw-r--r--include/tinyff/image/png.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/include/tinyff/image/png.h b/include/tinyff/image/png.h
index c195951..c2c7db2 100644
--- a/include/tinyff/image/png.h
+++ b/include/tinyff/image/png.h
@@ -55,6 +55,27 @@ typedef struct {
} ff_png_ctx;
+// Small BpP helper function
+
+static inline uint16_t ff_png_bpp(ff_png_ctx *ctx)
+{
+ int16_t byte_depth = ctx->bit_depth / 8;
+ switch (ctx->color_type) {
+ case 0: // Grayscale
+ return byte_depth * 1; // Gray
+ case 2: // Truecolor
+ return byte_depth * 3; // R, G, B
+ case 3: // Indexed-color
+ return byte_depth * 1; // Index
+ case 4: // Grayscale with alpha
+ return byte_depth * 2; // Gray w/ alpha
+ case 6: // Truecolor with alpha
+ return byte_depth * 4; // R, G, B w/ alpha
+ default:
+ return 0; // damn, you corrupt
+ }
+}
+
// Chunk handling