1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:47:35 +00:00

LibGfx: Move PNG header and paeth_predictor function to a shared header

This commit is contained in:
Karol Kosek 2022-07-10 00:14:19 +02:00 committed by Andreas Kling
parent ebc20f7ac3
commit 98a90d79de
3 changed files with 28 additions and 27 deletions

View file

@ -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;
}
};