mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibGfx: PNGLoader support for grayscale images with alpha.
This commit is contained in:
parent
d009df074f
commit
e5a598414f
Notes:
sideshowbarker
2024-07-19 07:16:31 +09:00
Author: https://github.com/LepkoQQ Commit: https://github.com/SerenityOS/serenity/commit/e5a598414fb Pull-request: https://github.com/SerenityOS/serenity/pull/1974
1 changed files with 41 additions and 3 deletions
|
@ -67,6 +67,18 @@ struct [[gnu::packed]] PaletteEntry
|
|||
//u8 a;
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] Tuple
|
||||
{
|
||||
u8 gray;
|
||||
u8 a;
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] Tuple16
|
||||
{
|
||||
u16 gray;
|
||||
u16 a;
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] Triplet
|
||||
{
|
||||
u8 r;
|
||||
|
@ -331,6 +343,33 @@ template<bool has_alpha, u8 filter_type>
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (context.bit_depth == 8) {
|
||||
for (int y = 0; y < context.height; ++y) {
|
||||
auto* tuples = (Tuple*)context.scanlines[y].data.data();
|
||||
for (int i = 0; i < context.width; ++i) {
|
||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||
pixel.r = tuples[i].gray;
|
||||
pixel.g = tuples[i].gray;
|
||||
pixel.b = tuples[i].gray;
|
||||
pixel.a = tuples[i].a;
|
||||
}
|
||||
}
|
||||
} else if (context.bit_depth == 16) {
|
||||
for (int y = 0; y < context.height; ++y) {
|
||||
auto* tuples = (Tuple16*)context.scanlines[y].data.data();
|
||||
for (int i = 0; i < context.width; ++i) {
|
||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||
pixel.r = tuples[i].gray & 0xFF;
|
||||
pixel.g = tuples[i].gray & 0xFF;
|
||||
pixel.b = tuples[i].gray & 0xFF;
|
||||
pixel.a = tuples[i].a & 0xFF;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (context.bit_depth == 8) {
|
||||
for (int y = 0; y < context.height; ++y) {
|
||||
|
@ -617,9 +656,8 @@ static bool process_IHDR(const ByteBuffer& data, PNGLoadingContext& context, boo
|
|||
context.bytes_per_pixel = ihdr.bit_depth / 8;
|
||||
break;
|
||||
case 4: // Each pixel is a grayscale sample, followed by an alpha sample.
|
||||
// FIXME: Implement grayscale PNG support.
|
||||
dbgprintf("PNGLoader::process_IHDR: Unsupported grayscale format.\n");
|
||||
return false;
|
||||
context.bytes_per_pixel = 2 * ihdr.bit_depth / 8;
|
||||
break;
|
||||
case 2:
|
||||
context.bytes_per_pixel = 3 * (ihdr.bit_depth / 8);
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue