LibImage: name color to u32 function to to_argb from to_rgba
This is the actual format that it returns
This commit is contained in:
parent
8adc97980a
commit
d36b64e0c8
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
namespace LibImage
|
||||
|
@ -87,9 +86,9 @@ namespace LibImage
|
|||
constexpr Image::Color as_color() const
|
||||
{
|
||||
return Image::Color {
|
||||
.r = static_cast<uint8_t>(r < 0.0 ? 0.0 : r > 255.0 ? 255.0 : r),
|
||||
.g = static_cast<uint8_t>(g < 0.0 ? 0.0 : g > 255.0 ? 255.0 : g),
|
||||
.b = static_cast<uint8_t>(b < 0.0 ? 0.0 : b > 255.0 ? 255.0 : b),
|
||||
.g = static_cast<uint8_t>(g < 0.0 ? 0.0 : g > 255.0 ? 255.0 : g),
|
||||
.r = static_cast<uint8_t>(r < 0.0 ? 0.0 : r > 255.0 ? 255.0 : r),
|
||||
.a = static_cast<uint8_t>(a < 0.0 ? 0.0 : a > 255.0 ? 255.0 : a),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -560,52 +560,47 @@ namespace LibImage
|
|||
const auto extract_color =
|
||||
[&](auto& bit_buffer) -> Image::Color
|
||||
{
|
||||
uint8_t tmp;
|
||||
Image::Color color;
|
||||
switch (ihdr.colour_type)
|
||||
{
|
||||
case ColourType::Greyscale:
|
||||
tmp = extract_channel(bit_buffer);
|
||||
return Image::Color {
|
||||
.r = tmp,
|
||||
.g = tmp,
|
||||
.b = tmp,
|
||||
.a = 0xFF
|
||||
};
|
||||
color.r = extract_channel(bit_buffer);
|
||||
color.g = color.r;
|
||||
color.b = color.r;
|
||||
color.a = 0xFF;
|
||||
break;
|
||||
case ColourType::Truecolour:
|
||||
return Image::Color {
|
||||
.r = extract_channel(bit_buffer),
|
||||
.g = extract_channel(bit_buffer),
|
||||
.b = extract_channel(bit_buffer),
|
||||
.a = 0xFF
|
||||
};
|
||||
color.r = extract_channel(bit_buffer);
|
||||
color.g = extract_channel(bit_buffer);
|
||||
color.b = extract_channel(bit_buffer);
|
||||
color.a = 0xFF;
|
||||
break;
|
||||
case ColourType::IndexedColour:
|
||||
return palette[MUST(bit_buffer.get_bits(bits_per_channel))];
|
||||
color = palette[MUST(bit_buffer.get_bits(bits_per_channel))];
|
||||
break;
|
||||
case ColourType::GreyscaleAlpha:
|
||||
tmp = extract_channel(bit_buffer);
|
||||
return Image::Color {
|
||||
.r = tmp,
|
||||
.g = tmp,
|
||||
.b = tmp,
|
||||
.a = extract_channel(bit_buffer)
|
||||
};
|
||||
color.r = extract_channel(bit_buffer);
|
||||
color.g = color.r;
|
||||
color.b = color.r;
|
||||
color.a = extract_channel(bit_buffer);
|
||||
break;
|
||||
case ColourType::TruecolourAlpha:
|
||||
return Image::Color {
|
||||
.r = extract_channel(bit_buffer),
|
||||
.g = extract_channel(bit_buffer),
|
||||
.b = extract_channel(bit_buffer),
|
||||
.a = extract_channel(bit_buffer)
|
||||
};
|
||||
color.r = extract_channel(bit_buffer);
|
||||
color.g = extract_channel(bit_buffer);
|
||||
color.b = extract_channel(bit_buffer);
|
||||
color.a = extract_channel(bit_buffer);
|
||||
break;
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
return color;
|
||||
};
|
||||
|
||||
constexpr auto paeth_predictor =
|
||||
[](int16_t a, int16_t b, int16_t c) -> uint8_t
|
||||
{
|
||||
int16_t p = a + b - c;
|
||||
int16_t pa = BAN::Math::abs(p - a);
|
||||
int16_t pb = BAN::Math::abs(p - b);
|
||||
int16_t pc = BAN::Math::abs(p - c);
|
||||
const int16_t p = a + b - c;
|
||||
const int16_t pa = BAN::Math::abs(p - a);
|
||||
const int16_t pb = BAN::Math::abs(p - b);
|
||||
const int16_t pc = BAN::Math::abs(p - c);
|
||||
if (pa <= pb && pa <= pc)
|
||||
return a;
|
||||
if (pb <= pc)
|
||||
|
|
|
@ -13,9 +13,9 @@ namespace LibImage
|
|||
public:
|
||||
struct Color
|
||||
{
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t g;
|
||||
uint8_t r;
|
||||
uint8_t a;
|
||||
|
||||
// Calculate weighted average of colors
|
||||
|
@ -25,14 +25,14 @@ namespace LibImage
|
|||
const double b_mult = weight < 0.0 ? 0.0 : weight > 1.0 ? 1.0 : weight;
|
||||
const double a_mult = 1.0 - b_mult;
|
||||
return Color {
|
||||
.r = static_cast<uint8_t>(a.r * a_mult + b.r * b_mult),
|
||||
.g = static_cast<uint8_t>(a.g * a_mult + b.g * b_mult),
|
||||
.b = static_cast<uint8_t>(a.b * a_mult + b.b * b_mult),
|
||||
.g = static_cast<uint8_t>(a.g * a_mult + b.g * b_mult),
|
||||
.r = static_cast<uint8_t>(a.r * a_mult + b.r * b_mult),
|
||||
.a = static_cast<uint8_t>(a.a * a_mult + b.a * b_mult),
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t as_rgba() const
|
||||
uint32_t as_argb() const
|
||||
{
|
||||
return ((uint32_t)a << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||
}
|
||||
|
|
|
@ -330,7 +330,7 @@ void WindowServer::invalidate(Rectangle area)
|
|||
ASSERT(m_background_image->height() == (uint64_t)m_framebuffer.height);
|
||||
for (int32_t y = area.y; y < area.y + area.height; y++)
|
||||
for (int32_t x = area.x; x < area.x + area.width; x++)
|
||||
m_framebuffer.mmap[y * m_framebuffer.width + x] = m_background_image->get_color(x, y).as_rgba();
|
||||
m_framebuffer.mmap[y * m_framebuffer.width + x] = m_background_image->get_color(x, y).as_argb();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue