diff options
Diffstat (limited to 'Userland/Libraries/LibGfx/PNGShared.h')
-rw-r--r-- | Userland/Libraries/LibGfx/PNGShared.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/PNGShared.h b/Userland/Libraries/LibGfx/PNGShared.h index 3486456f86..6f60d848ae 100644 --- a/Userland/Libraries/LibGfx/PNGShared.h +++ b/Userland/Libraries/LibGfx/PNGShared.h @@ -8,6 +8,9 @@ namespace Gfx::PNG { +// https://www.w3.org/TR/PNG/#5PNG-file-signature +static constexpr Array<u8, 8> header = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; + // https://www.w3.org/TR/PNG/#6Colour-values enum class ColorType : u8 { Greyscale = 0, @@ -26,4 +29,18 @@ enum class FilterType : u8 { Paeth, }; +// https://www.w3.org/TR/PNG/#9Filter-type-4-Paeth +ALWAYS_INLINE u8 paeth_predictor(u8 a, u8 b, u8 c) +{ + int p = a + b - c; + int pa = abs(p - a); + int pb = abs(p - b); + int pc = abs(p - c); + if (pa <= pb && pa <= pc) + return a; + if (pb <= pc) + return b; + return c; +} + }; |