diff options
author | Karol Kosek <krkk@serenityos.org> | 2022-07-10 00:14:19 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-10 15:01:07 +0200 |
commit | 98a90d79de57fa7690ed68cee5af32c22bfa3fbe (patch) | |
tree | 9335ad57d421e962b037dc4cc22a7f44e0d135f0 /Userland/Libraries/LibGfx/PNGShared.h | |
parent | ebc20f7ac3090654823746d587b49ffab1e66bed (diff) | |
download | serenity-98a90d79de57fa7690ed68cee5af32c22bfa3fbe.zip |
LibGfx: Move PNG header and paeth_predictor function to a shared header
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; +} + }; |