mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 22:05:07 +00:00
LibGfx: Consolidate some types in the PNG decoder
This commit is contained in:
parent
6c89303e7e
commit
19587934f3
1 changed files with 19 additions and 33 deletions
|
@ -68,38 +68,28 @@ struct [[gnu::packed]] PaletteEntry
|
||||||
//u8 a;
|
//u8 a;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
struct [[gnu::packed]] Tuple
|
struct [[gnu::packed]] Tuple
|
||||||
{
|
{
|
||||||
u8 gray;
|
T gray;
|
||||||
u8 a;
|
T a;
|
||||||
};
|
|
||||||
|
|
||||||
struct [[gnu::packed]] Tuple16
|
|
||||||
{
|
|
||||||
u16 gray;
|
|
||||||
u16 a;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
struct [[gnu::packed]] Triplet
|
struct [[gnu::packed]] Triplet
|
||||||
{
|
{
|
||||||
u8 r;
|
T r;
|
||||||
u8 g;
|
T g;
|
||||||
u8 b;
|
T b;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct [[gnu::packed]] Triplet16
|
template<typename T>
|
||||||
|
struct [[gnu::packed]] Quad
|
||||||
{
|
{
|
||||||
u16 r;
|
T r;
|
||||||
u16 g;
|
T g;
|
||||||
u16 b;
|
T b;
|
||||||
};
|
T a;
|
||||||
|
|
||||||
struct [[gnu::packed]] Quad16
|
|
||||||
{
|
|
||||||
u16 r;
|
|
||||||
u16 g;
|
|
||||||
u16 b;
|
|
||||||
u16 a;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PNGLoadingContext {
|
struct PNGLoadingContext {
|
||||||
|
@ -136,9 +126,7 @@ struct PNGLoadingContext {
|
||||||
class Streamer {
|
class Streamer {
|
||||||
public:
|
public:
|
||||||
Streamer(const u8* data, int size)
|
Streamer(const u8* data, int size)
|
||||||
: m_original_data(data)
|
: m_data_ptr(data)
|
||||||
, m_original_size(size)
|
|
||||||
, m_data_ptr(data)
|
|
||||||
, m_size_remaining(size)
|
, m_size_remaining(size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -177,8 +165,6 @@ public:
|
||||||
bool at_end() const { return !m_size_remaining; }
|
bool at_end() const { return !m_size_remaining; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const u8* m_original_data;
|
|
||||||
int m_original_size;
|
|
||||||
const u8* m_data_ptr;
|
const u8* m_data_ptr;
|
||||||
int m_size_remaining;
|
int m_size_remaining;
|
||||||
};
|
};
|
||||||
|
@ -362,7 +348,7 @@ NEVER_INLINE FLATTEN static void unfilter(PNGLoadingContext& context)
|
||||||
case 4:
|
case 4:
|
||||||
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) {
|
||||||
auto* tuples = (Tuple*)context.scanlines[y].data.data();
|
auto* tuples = (Tuple<u8>*)context.scanlines[y].data.data();
|
||||||
for (int i = 0; i < context.width; ++i) {
|
for (int i = 0; i < context.width; ++i) {
|
||||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||||
pixel.r = tuples[i].gray;
|
pixel.r = tuples[i].gray;
|
||||||
|
@ -373,7 +359,7 @@ NEVER_INLINE FLATTEN static void unfilter(PNGLoadingContext& context)
|
||||||
}
|
}
|
||||||
} else if (context.bit_depth == 16) {
|
} else if (context.bit_depth == 16) {
|
||||||
for (int y = 0; y < context.height; ++y) {
|
for (int y = 0; y < context.height; ++y) {
|
||||||
auto* tuples = (Tuple16*)context.scanlines[y].data.data();
|
auto* tuples = (Tuple<u16>*)context.scanlines[y].data.data();
|
||||||
for (int i = 0; i < context.width; ++i) {
|
for (int i = 0; i < context.width; ++i) {
|
||||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||||
pixel.r = tuples[i].gray & 0xFF;
|
pixel.r = tuples[i].gray & 0xFF;
|
||||||
|
@ -389,7 +375,7 @@ NEVER_INLINE FLATTEN static void unfilter(PNGLoadingContext& context)
|
||||||
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) {
|
||||||
auto* triplets = (Triplet*)context.scanlines[y].data.data();
|
auto* triplets = (Triplet<u8>*)context.scanlines[y].data.data();
|
||||||
for (int i = 0; i < context.width; ++i) {
|
for (int i = 0; i < context.width; ++i) {
|
||||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||||
pixel.r = triplets[i].r;
|
pixel.r = triplets[i].r;
|
||||||
|
@ -400,7 +386,7 @@ NEVER_INLINE FLATTEN static void unfilter(PNGLoadingContext& context)
|
||||||
}
|
}
|
||||||
} else if (context.bit_depth == 16) {
|
} else if (context.bit_depth == 16) {
|
||||||
for (int y = 0; y < context.height; ++y) {
|
for (int y = 0; y < context.height; ++y) {
|
||||||
auto* triplets = (Triplet16*)context.scanlines[y].data.data();
|
auto* triplets = (Triplet<u16>*)context.scanlines[y].data.data();
|
||||||
for (int i = 0; i < context.width; ++i) {
|
for (int i = 0; i < context.width; ++i) {
|
||||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||||
pixel.r = triplets[i].r & 0xFF;
|
pixel.r = triplets[i].r & 0xFF;
|
||||||
|
@ -420,7 +406,7 @@ NEVER_INLINE FLATTEN static void unfilter(PNGLoadingContext& context)
|
||||||
}
|
}
|
||||||
} else if (context.bit_depth == 16) {
|
} else if (context.bit_depth == 16) {
|
||||||
for (int y = 0; y < context.height; ++y) {
|
for (int y = 0; y < context.height; ++y) {
|
||||||
auto* triplets = (Quad16*)context.scanlines[y].data.data();
|
auto* triplets = (Quad<u16>*)context.scanlines[y].data.data();
|
||||||
for (int i = 0; i < context.width; ++i) {
|
for (int i = 0; i < context.width; ++i) {
|
||||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||||
pixel.r = triplets[i].r & 0xFF;
|
pixel.r = triplets[i].r & 0xFF;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue