mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibGfx: PNGLoader support for grayscale images with alpha.
This commit is contained in:
parent
d009df074f
commit
e5a598414f
1 changed files with 41 additions and 3 deletions
|
@ -67,6 +67,18 @@ struct [[gnu::packed]] PaletteEntry
|
||||||
//u8 a;
|
//u8 a;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct [[gnu::packed]] Tuple
|
||||||
|
{
|
||||||
|
u8 gray;
|
||||||
|
u8 a;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct [[gnu::packed]] Tuple16
|
||||||
|
{
|
||||||
|
u16 gray;
|
||||||
|
u16 a;
|
||||||
|
};
|
||||||
|
|
||||||
struct [[gnu::packed]] Triplet
|
struct [[gnu::packed]] Triplet
|
||||||
{
|
{
|
||||||
u8 r;
|
u8 r;
|
||||||
|
@ -331,6 +343,33 @@ template<bool has_alpha, u8 filter_type>
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case 2:
|
||||||
if (context.bit_depth == 8) {
|
if (context.bit_depth == 8) {
|
||||||
for (int y = 0; y < context.height; ++y) {
|
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;
|
context.bytes_per_pixel = ihdr.bit_depth / 8;
|
||||||
break;
|
break;
|
||||||
case 4: // Each pixel is a grayscale sample, followed by an alpha sample.
|
case 4: // Each pixel is a grayscale sample, followed by an alpha sample.
|
||||||
// FIXME: Implement grayscale PNG support.
|
context.bytes_per_pixel = 2 * ihdr.bit_depth / 8;
|
||||||
dbgprintf("PNGLoader::process_IHDR: Unsupported grayscale format.\n");
|
break;
|
||||||
return false;
|
|
||||||
case 2:
|
case 2:
|
||||||
context.bytes_per_pixel = 3 * (ihdr.bit_depth / 8);
|
context.bytes_per_pixel = 3 * (ihdr.bit_depth / 8);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue