From e0f32626bcae634528327e43bcfa59c810c5a3ef Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 16 Mar 2021 11:48:42 +0100 Subject: [PATCH] LibGfx: Rename 32-bit BitmapFormats to BGRA8888 and BGRx888x The previous names (RGBA32 and RGB32) were misleading since that's not the actual byte order in memory. The new names reflect exactly how the color values get laid out in bitmap data. --- .../DisplaySettings/MonitorWidget.cpp | 2 +- Userland/Applications/PixelPaint/Image.cpp | 4 ++-- Userland/Applications/PixelPaint/Layer.cpp | 2 +- Userland/Demos/Cube/Cube.cpp | 2 +- Userland/Demos/LibGfxDemo/main.cpp | 2 +- Userland/Demos/LibGfxScaleDemo/main.cpp | 6 ++--- Userland/Demos/Screensaver/Screensaver.cpp | 2 +- .../DevTools/Profiler/DisassemblyModel.cpp | 2 +- Userland/Games/Solitaire/Card.cpp | 4 ++-- Userland/Libraries/LibGUI/Clipboard.cpp | 2 +- Userland/Libraries/LibGUI/ColorPicker.cpp | 4 ++-- Userland/Libraries/LibGUI/FileSystemModel.cpp | 2 +- Userland/Libraries/LibGUI/Window.cpp | 4 ++-- Userland/Libraries/LibGfx/BMPLoader.cpp | 8 +++---- Userland/Libraries/LibGfx/Bitmap.cpp | 4 ++-- Userland/Libraries/LibGfx/Bitmap.h | 18 +++++++-------- Userland/Libraries/LibGfx/GIFLoader.cpp | 4 ++-- Userland/Libraries/LibGfx/ICOLoader.cpp | 2 +- Userland/Libraries/LibGfx/JPGLoader.cpp | 2 +- Userland/Libraries/LibGfx/PNGLoader.cpp | 4 ++-- Userland/Libraries/LibGfx/Painter.cpp | 22 +++++++++---------- .../LibGfx/PortableImageLoaderCommon.h | 2 +- Userland/Libraries/LibTTF/Glyf.cpp | 2 +- .../LibWeb/HTML/HTMLCanvasElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/ImageData.cpp | 2 +- .../Libraries/LibWeb/OutOfProcessWebView.cpp | 4 ++-- .../ClipboardHistoryModel.cpp | 4 ++-- .../WindowServer/ClientConnection.cpp | 2 +- Userland/Services/WindowServer/Compositor.cpp | 10 ++++----- Userland/Services/WindowServer/Window.cpp | 2 +- .../Services/WindowServer/WindowFrame.cpp | 8 +++---- 31 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Userland/Applications/DisplaySettings/MonitorWidget.cpp b/Userland/Applications/DisplaySettings/MonitorWidget.cpp index db60aa3233..2f04c19426 100644 --- a/Userland/Applications/DisplaySettings/MonitorWidget.cpp +++ b/Userland/Applications/DisplaySettings/MonitorWidget.cpp @@ -116,7 +116,7 @@ void MonitorWidget::paint_event(GUI::PaintEvent& event) // Render text label scaled with scale factor to hint at its effect. // FIXME: Once bitmaps have intrinsic scale factors, we could create a bitmap with an intrinsic scale factor of m_desktop_scale_factor // and that should give us the same effect with less code. - auto text_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, Gfx::IntSize { painter.font().width(displayed_resolution_string) + 1, painter.font().glyph_height() + 1 }); + auto text_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, Gfx::IntSize { painter.font().width(displayed_resolution_string) + 1, painter.font().glyph_height() + 1 }); GUI::Painter text_painter(*text_bitmap); text_painter.set_font(painter.font()); diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index 248ccc1bb0..4638b83bad 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -141,7 +141,7 @@ void Image::save(const String& file_path) const void Image::export_bmp(const String& file_path) { - auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, m_size); + auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, m_size); GUI::Painter painter(*bitmap); paint_into(painter, { 0, 0, m_size.width(), m_size.height() }); @@ -154,7 +154,7 @@ void Image::export_bmp(const String& file_path) void Image::export_png(const String& file_path) { - auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, m_size); + auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, m_size); GUI::Painter painter(*bitmap); paint_into(painter, { 0, 0, m_size.width(), m_size.height() }); diff --git a/Userland/Applications/PixelPaint/Layer.cpp b/Userland/Applications/PixelPaint/Layer.cpp index e607113c32..8a0627d765 100644 --- a/Userland/Applications/PixelPaint/Layer.cpp +++ b/Userland/Applications/PixelPaint/Layer.cpp @@ -66,7 +66,7 @@ Layer::Layer(Image& image, const Gfx::IntSize& size, const String& name) : m_image(image) , m_name(name) { - m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, size); + m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size); } Layer::Layer(Image& image, const Gfx::Bitmap& bitmap, const String& name) diff --git a/Userland/Demos/Cube/Cube.cpp b/Userland/Demos/Cube/Cube.cpp index 30088c9607..9c97fa8990 100644 --- a/Userland/Demos/Cube/Cube.cpp +++ b/Userland/Demos/Cube/Cube.cpp @@ -80,7 +80,7 @@ private: Cube::Cube() { - m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT }); + m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }); m_accumulated_time = 0; m_cycles = 0; diff --git a/Userland/Demos/LibGfxDemo/main.cpp b/Userland/Demos/LibGfxDemo/main.cpp index 2122d40a1a..c068f089ed 100644 --- a/Userland/Demos/LibGfxDemo/main.cpp +++ b/Userland/Demos/LibGfxDemo/main.cpp @@ -53,7 +53,7 @@ private: Canvas::Canvas() { - m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT }); + m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }); draw(); } diff --git a/Userland/Demos/LibGfxScaleDemo/main.cpp b/Userland/Demos/LibGfxScaleDemo/main.cpp index e7763b3e65..4c2185d126 100644 --- a/Userland/Demos/LibGfxScaleDemo/main.cpp +++ b/Userland/Demos/LibGfxScaleDemo/main.cpp @@ -58,15 +58,15 @@ private: Canvas::Canvas() { - m_bitmap_1x = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT }, 1); - m_bitmap_2x = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { WIDTH, HEIGHT }, 2); + m_bitmap_1x = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 1); + m_bitmap_2x = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { WIDTH, HEIGHT }, 2); // m_bitmap_1x and m_bitmap_2x have the same logical size, so LibGfx will try to draw them at the same physical size: // When drawing on a 2x backing store it'd scale m_bitmap_1x up 2x and paint m_bitmap_2x at its physical size. // When drawing on a 1x backing store it'd draw m_bitmap_1x at its physical size, and it would have to scale down m_bitmap_2x to 0.5x its size. // But the system can't current scale down, and we want to draw the 2x bitmap at twice the size of the 1x bitmap in this particular application, // so make a 1x alias of the 2x bitmap to make LibGfx paint it without any scaling at paint time, mapping once pixel to one pixel. - m_bitmap_2x_as_1x = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGB32, m_bitmap_2x->physical_size(), 1, m_bitmap_2x->pitch(), m_bitmap_2x->scanline(0)); + m_bitmap_2x_as_1x = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::BGRx8888, m_bitmap_2x->physical_size(), 1, m_bitmap_2x->pitch(), m_bitmap_2x->scanline(0)); Gfx::Painter painter_1x(*m_bitmap_1x); draw(painter_1x); diff --git a/Userland/Demos/Screensaver/Screensaver.cpp b/Userland/Demos/Screensaver/Screensaver.cpp index bf6166a154..2fb8940631 100644 --- a/Userland/Demos/Screensaver/Screensaver.cpp +++ b/Userland/Demos/Screensaver/Screensaver.cpp @@ -54,7 +54,7 @@ private: Screensaver::Screensaver(int width, int height, int interval) { - m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { width, height }); + m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { width, height }); srand(time(nullptr)); stop_timer(); start_timer(interval); diff --git a/Userland/DevTools/Profiler/DisassemblyModel.cpp b/Userland/DevTools/Profiler/DisassemblyModel.cpp index 10d29b8cf1..02309cbdf2 100644 --- a/Userland/DevTools/Profiler/DisassemblyModel.cpp +++ b/Userland/DevTools/Profiler/DisassemblyModel.cpp @@ -38,7 +38,7 @@ static const Gfx::Bitmap& heat_gradient() { static RefPtr bitmap; if (!bitmap) { - bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { 101, 1 }); + bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { 101, 1 }); GUI::Painter painter(*bitmap); painter.fill_rect_with_gradient(Orientation::Horizontal, bitmap->rect(), Color::from_rgb(0xffc080), Color::from_rgb(0xff3000)); } diff --git a/Userland/Games/Solitaire/Card.cpp b/Userland/Games/Solitaire/Card.cpp index 1887393bb0..11fb81c412 100644 --- a/Userland/Games/Solitaire/Card.cpp +++ b/Userland/Games/Solitaire/Card.cpp @@ -81,7 +81,7 @@ static RefPtr s_background; Card::Card(Type type, uint8_t value) : m_rect(Gfx::IntRect({}, { width, height })) - , m_front(*Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { width, height })) + , m_front(*Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { width, height })) , m_type(type) , m_value(value) { @@ -89,7 +89,7 @@ Card::Card(Type type, uint8_t value) Gfx::IntRect paint_rect({ 0, 0 }, { width, height }); if (s_background.is_null()) { - s_background = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { width, height }); + s_background = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { width, height }); Gfx::Painter bg_painter(*s_background); s_background->fill(Color::White); diff --git a/Userland/Libraries/LibGUI/Clipboard.cpp b/Userland/Libraries/LibGUI/Clipboard.cpp index f484005ae0..32cc1eaad9 100644 --- a/Userland/Libraries/LibGUI/Clipboard.cpp +++ b/Userland/Libraries/LibGUI/Clipboard.cpp @@ -133,7 +133,7 @@ RefPtr Clipboard::bitmap() const return nullptr; auto clipping_bitmap = Gfx::Bitmap::create_wrapper((Gfx::BitmapFormat)format.value(), { (int)width.value(), (int)height.value() }, scale.value(), pitch.value(), clipping.data.data()); - auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, { (int)width.value(), (int)height.value() }, scale.value()); + auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { (int)width.value(), (int)height.value() }, scale.value()); for (int y = 0; y < clipping_bitmap->physical_height(); ++y) { for (int x = 0; x < clipping_bitmap->physical_width(); ++x) { diff --git a/Userland/Libraries/LibGUI/ColorPicker.cpp b/Userland/Libraries/LibGUI/ColorPicker.cpp index cfa7287afb..b9ebc70110 100644 --- a/Userland/Libraries/LibGUI/ColorPicker.cpp +++ b/Userland/Libraries/LibGUI/ColorPicker.cpp @@ -479,7 +479,7 @@ ColorField::ColorField(Color color) void ColorField::create_color_bitmap() { - m_color_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { 256, 256 }); + m_color_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { 256, 256 }); auto painter = Gfx::Painter(*m_color_bitmap); Gfx::HSV hsv; @@ -605,7 +605,7 @@ void ColorField::resize_event(ResizeEvent&) ColorSlider::ColorSlider(double value) : m_value(value) { - m_color_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { 32, 360 }); + m_color_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { 32, 360 }); auto painter = Gfx::Painter(*m_color_bitmap); for (int h = 0; h < 360; h++) { diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index b504ae09e2..b04c4cb70d 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -497,7 +497,7 @@ static RefPtr render_thumbnail(const StringView& path) double scale = min(32 / (double)png_bitmap->width(), 32 / (double)png_bitmap->height()); - auto thumbnail = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, { 32, 32 }); + auto thumbnail = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { 32, 32 }); Gfx::IntRect destination = Gfx::IntRect(0, 0, (int)(png_bitmap->width() * scale), (int)(png_bitmap->height() * scale)); destination.center_within(thumbnail->rect()); diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 89d10c3ec7..90810cd8ed 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -757,7 +757,7 @@ void Window::flip(const Vector& dirty_rects) OwnPtr Window::create_backing_store(const Gfx::IntSize& size) { - auto format = m_has_alpha_channel ? Gfx::BitmapFormat::RGBA32 : Gfx::BitmapFormat::RGB32; + auto format = m_has_alpha_channel ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888; VERIFY(!size.is_empty()); size_t pitch = Gfx::Bitmap::minimum_pitch(size.width(), format); @@ -793,7 +793,7 @@ void Window::set_icon(const Gfx::Bitmap* icon) Gfx::IntSize icon_size = icon ? icon->size() : Gfx::IntSize(16, 16); - m_icon = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, icon_size); + m_icon = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, icon_size); VERIFY(m_icon); if (icon) { Painter painter(*m_icon); diff --git a/Userland/Libraries/LibGfx/BMPLoader.cpp b/Userland/Libraries/LibGfx/BMPLoader.cpp index 65e7da62f4..f009b36e5d 100644 --- a/Userland/Libraries/LibGfx/BMPLoader.cpp +++ b/Userland/Libraries/LibGfx/BMPLoader.cpp @@ -1186,12 +1186,12 @@ static bool decode_bmp_pixel_data(BMPLoadingContext& context) return BitmapFormat::Indexed8; case 16: if (context.dib.info.masks.size() == 4) - return BitmapFormat::RGBA32; - return BitmapFormat::RGB32; + return BitmapFormat::BGRA8888; + return BitmapFormat::BGRx8888; case 24: - return BitmapFormat::RGB32; + return BitmapFormat::BGRx8888; case 32: - return BitmapFormat::RGBA32; + return BitmapFormat::BGRA8888; default: return BitmapFormat::Invalid; } diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index 2046fdcf74..09e1505de5 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -248,7 +248,7 @@ RefPtr Bitmap::create_with_anon_fd(BitmapFormat format, int anon_fd, con /// - scale_factor /// - format /// - palette count -/// - palette data (= palette count * RGBA32) +/// - palette data (= palette count * BGRA8888) /// - image data (= actual size * u8) RefPtr Bitmap::create_from_serialized_byte_buffer(ByteBuffer&& buffer) { @@ -270,7 +270,7 @@ RefPtr Bitmap::create_from_serialized_byte_buffer(ByteBuffer&& buffer) if (!read(actual_size) || !read(width) || !read(height) || !read(scale_factor) || !read(format) || !read(palette_size)) return nullptr; - if (format > BitmapFormat::RGBA32 || format < BitmapFormat::Indexed1) + if (format > BitmapFormat::BGRA8888 || format < BitmapFormat::Indexed1) return nullptr; if (!check_size({ width, height }, scale_factor, format, actual_size)) diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index bcfb89fa96..69204b405e 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -52,8 +52,8 @@ enum class BitmapFormat { Indexed2, Indexed4, Indexed8, - RGB32, - RGBA32, + BGRx8888, + BGRA8888, }; inline bool is_valid_bitmap_format(unsigned format) @@ -64,8 +64,8 @@ inline bool is_valid_bitmap_format(unsigned format) case (unsigned)BitmapFormat::Indexed2: case (unsigned)BitmapFormat::Indexed4: case (unsigned)BitmapFormat::Indexed8: - case (unsigned)BitmapFormat::RGB32: - case (unsigned)BitmapFormat::RGBA32: + case (unsigned)BitmapFormat::BGRx8888: + case (unsigned)BitmapFormat::BGRA8888: return true; } return false; @@ -80,9 +80,9 @@ enum class StorageFormat { static StorageFormat determine_storage_format(BitmapFormat format) { switch (format) { - case BitmapFormat::RGB32: + case BitmapFormat::BGRx8888: return StorageFormat::RGB32; - case BitmapFormat::RGBA32: + case BitmapFormat::BGRA8888: return StorageFormat::RGBA32; case BitmapFormat::Indexed1: case BitmapFormat::Indexed2: @@ -194,8 +194,8 @@ public: return 4; case BitmapFormat::Indexed8: return 8; - case BitmapFormat::RGB32: - case BitmapFormat::RGBA32: + case BitmapFormat::BGRx8888: + case BitmapFormat::BGRA8888: return 32; default: VERIFY_NOT_REACHED(); @@ -213,7 +213,7 @@ public: void fill(Color); - bool has_alpha_channel() const { return m_format == BitmapFormat::RGBA32; } + bool has_alpha_channel() const { return m_format == BitmapFormat::BGRA8888; } BitmapFormat format() const { return m_format; } void set_mmap_name(const StringView&); diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index fb7b9eb26b..db69df4e11 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -318,10 +318,10 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index) size_t start_frame = context.current_frame + 1; if (context.state < GIFLoadingContext::State::FrameComplete) { start_frame = 0; - context.frame_buffer = Bitmap::create_purgeable(BitmapFormat::RGBA32, { context.logical_screen.width, context.logical_screen.height }); + context.frame_buffer = Bitmap::create_purgeable(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); if (!context.frame_buffer) return false; - context.prev_frame_buffer = Bitmap::create_purgeable(BitmapFormat::RGBA32, { context.logical_screen.width, context.logical_screen.height }); + context.prev_frame_buffer = Bitmap::create_purgeable(BitmapFormat::BGRA8888, { context.logical_screen.width, context.logical_screen.height }); if (!context.prev_frame_buffer) return false; } else if (frame_index < context.current_frame) { diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp index 51a2107e4b..e27920e182 100644 --- a/Userland/Libraries/LibGfx/ICOLoader.cpp +++ b/Userland/Libraries/LibGfx/ICOLoader.cpp @@ -288,7 +288,7 @@ static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc) return false; } - desc.bitmap = Bitmap::create_purgeable(BitmapFormat::RGBA32, { desc.width, desc.height }); + desc.bitmap = Bitmap::create_purgeable(BitmapFormat::BGRA8888, { desc.width, desc.height }); if (!desc.bitmap) return false; Bitmap& bitmap = *desc.bitmap; diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp index 0ec40055db..2597c7cdf8 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPGLoader.cpp @@ -1083,7 +1083,7 @@ static void ycbcr_to_rgb(const JPGLoadingContext& context, Vector& m static bool compose_bitmap(JPGLoadingContext& context, const Vector& macroblocks) { - context.bitmap = Bitmap::create_purgeable(BitmapFormat::RGB32, { context.frame.width, context.frame.height }); + context.bitmap = Bitmap::create_purgeable(BitmapFormat::BGRx8888, { context.frame.width, context.frame.height }); if (!context.bitmap) return false; diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp index 6dc47cc4f6..94d57c0bde 100644 --- a/Userland/Libraries/LibGfx/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/PNGLoader.cpp @@ -630,7 +630,7 @@ static bool decode_png_bitmap_simple(PNGLoadingContext& context) } } - context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? BitmapFormat::RGBA32 : BitmapFormat::RGB32, { context.width, context.height }); + context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); if (!context.bitmap) { context.state = PNGLoadingContext::State::Error; @@ -750,7 +750,7 @@ static bool decode_adam7_pass(PNGLoadingContext& context, Streamer& streamer, in static bool decode_png_adam7(PNGLoadingContext& context) { Streamer streamer(context.decompression_buffer.data(), context.decompression_buffer.size()); - context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? BitmapFormat::RGBA32 : BitmapFormat::RGB32, { context.width, context.height }); + context.bitmap = Bitmap::create_purgeable(context.has_alpha() ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888, { context.width, context.height }); if (!context.bitmap) return false; diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 9d0e37d5b0..e83c9386cf 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -62,9 +62,9 @@ ALWAYS_INLINE Color get_pixel(const Gfx::Bitmap& bitmap, int x, int y) return bitmap.palette_color(bitmap.scanline_u8(y)[x]); if constexpr (format == BitmapFormat::Indexed1) return bitmap.palette_color(bitmap.scanline_u8(y)[x]); - if constexpr (format == BitmapFormat::RGB32) + if constexpr (format == BitmapFormat::BGRx8888) return Color::from_rgb(bitmap.scanline(y)[x]); - if constexpr (format == BitmapFormat::RGBA32) + if constexpr (format == BitmapFormat::BGRA8888) return Color::from_rgba(bitmap.scanline(y)[x]); return bitmap.get_pixel(x, y); } @@ -73,7 +73,7 @@ Painter::Painter(Gfx::Bitmap& bitmap) : m_target(bitmap) { int scale = bitmap.scale(); - VERIFY(bitmap.format() == Gfx::BitmapFormat::RGB32 || bitmap.format() == Gfx::BitmapFormat::RGBA32); + VERIFY(bitmap.format() == Gfx::BitmapFormat::BGRx8888 || bitmap.format() == Gfx::BitmapFormat::BGRA8888); VERIFY(bitmap.physical_width() % scale == 0); VERIFY(bitmap.physical_height() % scale == 0); m_state_stack.append(State()); @@ -687,7 +687,7 @@ void Painter::draw_tiled_bitmap(const IntRect& a_dst_rect, const Gfx::Bitmap& so RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - if (source.format() == BitmapFormat::RGB32 || source.format() == BitmapFormat::RGBA32) { + if (source.format() == BitmapFormat::BGRx8888 || source.format() == BitmapFormat::BGRA8888) { int s = scale / source.scale(); if (s == 1) { int x_start = first_column + a_dst_rect.left() * scale; @@ -759,7 +759,7 @@ void Painter::blit(const IntPoint& position, const Gfx::Bitmap& source, const In RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - if (source.format() == BitmapFormat::RGB32 || source.format() == BitmapFormat::RGBA32) { + if (source.format() == BitmapFormat::BGRx8888 || source.format() == BitmapFormat::BGRA8888) { const RGBA32* src = source.scanline(src_rect.top() + first_row) + src_rect.left() + first_column; const size_t src_skip = source.pitch() / sizeof(RGBA32); for (int row = first_row; row <= last_row; ++row) { @@ -866,11 +866,11 @@ void Painter::draw_scaled_bitmap(const IntRect& a_dst_rect, const Gfx::Bitmap& s if (source.has_alpha_channel() || opacity != 1.0f) { switch (source.format()) { - case BitmapFormat::RGB32: - do_draw_scaled_bitmap(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity); + case BitmapFormat::BGRx8888: + do_draw_scaled_bitmap(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity); break; - case BitmapFormat::RGBA32: - do_draw_scaled_bitmap(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity); + case BitmapFormat::BGRA8888: + do_draw_scaled_bitmap(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity); break; case BitmapFormat::Indexed8: do_draw_scaled_bitmap(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity); @@ -890,8 +890,8 @@ void Painter::draw_scaled_bitmap(const IntRect& a_dst_rect, const Gfx::Bitmap& s } } else { switch (source.format()) { - case BitmapFormat::RGB32: - do_draw_scaled_bitmap(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity); + case BitmapFormat::BGRx8888: + do_draw_scaled_bitmap(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity); break; case BitmapFormat::Indexed8: do_draw_scaled_bitmap(*m_target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity); diff --git a/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h b/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h index 67afa508c8..2005e3e087 100644 --- a/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h +++ b/Userland/Libraries/LibGfx/PortableImageLoaderCommon.h @@ -198,7 +198,7 @@ static bool read_max_val(TContext& context, Streamer& streamer) template static bool create_bitmap(TContext& context) { - context.bitmap = Bitmap::create_purgeable(BitmapFormat::RGB32, { context.width, context.height }); + context.bitmap = Bitmap::create_purgeable(BitmapFormat::BGRx8888, { context.width, context.height }); if (!context.bitmap) { context.state = TContext::State::Error; return false; diff --git a/Userland/Libraries/LibTTF/Glyf.cpp b/Userland/Libraries/LibTTF/Glyf.cpp index 76dd9bcfbd..de1b5a292c 100644 --- a/Userland/Libraries/LibTTF/Glyf.cpp +++ b/Userland/Libraries/LibTTF/Glyf.cpp @@ -227,7 +227,7 @@ void Rasterizer::draw_path(Gfx::Path& path) RefPtr Rasterizer::accumulate() { - auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, m_size); + auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, m_size); Color base_color = Color::from_rgb(0xffffff); for (int y = 0; y < m_size.height(); y++) { float accumulator = 0.0; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 259f88083d..fed960276e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -98,7 +98,7 @@ bool HTMLCanvasElement::create_bitmap() return false; } if (!m_bitmap || m_bitmap->size() != size) - m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, size); + m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size); return m_bitmap; } diff --git a/Userland/Libraries/LibWeb/HTML/ImageData.cpp b/Userland/Libraries/LibWeb/HTML/ImageData.cpp index 81a76594ed..fd39fbf43d 100644 --- a/Userland/Libraries/LibWeb/HTML/ImageData.cpp +++ b/Userland/Libraries/LibWeb/HTML/ImageData.cpp @@ -46,7 +46,7 @@ RefPtr ImageData::create_with_size(JS::GlobalObject& global_object, i auto data_handle = JS::make_handle(data); - auto bitmap = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGBA32, Gfx::IntSize(width, height), 1, width * sizeof(u32), (u32*)data->data()); + auto bitmap = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::BGRA8888, Gfx::IntSize(width, height), 1, width * sizeof(u32), (u32*)data->data()); if (!bitmap) return nullptr; return adopt(*new ImageData(bitmap.release_nonnull(), move(data_handle))); diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index ad736e70f3..b247777741 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -160,13 +160,13 @@ void OutOfProcessWebView::handle_resize() if (available_size().is_empty()) return; - if (auto new_bitmap = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::RGB32, available_size())) { + if (auto new_bitmap = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) { m_client_state.front_bitmap = move(new_bitmap); m_client_state.front_bitmap_id = m_client_state.next_bitmap_id++; client().post_message(Messages::WebContentServer::AddBackingStore(m_client_state.front_bitmap_id, m_client_state.front_bitmap->to_shareable_bitmap())); } - if (auto new_bitmap = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::RGB32, available_size())) { + if (auto new_bitmap = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) { m_client_state.back_bitmap = move(new_bitmap); m_client_state.back_bitmap_id = m_client_state.next_bitmap_id++; client().post_message(Messages::WebContentServer::AddBackingStore(m_client_state.back_bitmap_id, m_client_state.back_bitmap->to_shareable_bitmap())); diff --git a/Userland/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp b/Userland/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp index 2afbeca41a..3df29df700 100644 --- a/Userland/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp +++ b/Userland/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp @@ -64,8 +64,8 @@ static const char* bpp_for_format_resilient(String format) return "4"; case Gfx::BitmapFormat::Indexed8: return "8"; - case Gfx::BitmapFormat::RGB32: - case Gfx::BitmapFormat::RGBA32: + case Gfx::BitmapFormat::BGRx8888: + case Gfx::BitmapFormat::BGRA8888: return "32"; case Gfx::BitmapFormat::Invalid: /* fall-through */ diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index 9536e1346c..243b2a1056 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -623,7 +623,7 @@ OwnPtr ClientConnection:: } else { // FIXME: Plumb scale factor here eventually. auto backing_store = Gfx::Bitmap::create_with_anon_fd( - message.has_alpha_channel() ? Gfx::BitmapFormat::RGBA32 : Gfx::BitmapFormat::RGB32, + message.has_alpha_channel() ? Gfx::BitmapFormat::BGRA8888 : Gfx::BitmapFormat::BGRx8888, message.anon_file().take_fd(), message.size(), 1, diff --git a/Userland/Services/WindowServer/Compositor.cpp b/Userland/Services/WindowServer/Compositor.cpp index c7125ccaf4..c9b5471863 100644 --- a/Userland/Services/WindowServer/Compositor.cpp +++ b/Userland/Services/WindowServer/Compositor.cpp @@ -92,16 +92,16 @@ void Compositor::init_bitmaps() auto& screen = Screen::the(); auto size = screen.size(); - m_front_bitmap = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGB32, size, screen.scale_factor(), screen.pitch(), screen.scanline(0)); + m_front_bitmap = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::BGRx8888, size, screen.scale_factor(), screen.pitch(), screen.scanline(0)); m_front_painter = make(*m_front_bitmap); if (m_screen_can_set_buffer) - m_back_bitmap = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::RGB32, size, screen.scale_factor(), screen.pitch(), screen.scanline(screen.physical_height())); + m_back_bitmap = Gfx::Bitmap::create_wrapper(Gfx::BitmapFormat::BGRx8888, size, screen.scale_factor(), screen.pitch(), screen.scanline(screen.physical_height())); else - m_back_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, size, screen.scale_factor()); + m_back_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, size, screen.scale_factor()); m_back_painter = make(*m_back_bitmap); - m_temp_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, size, screen.scale_factor()); + m_temp_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, size, screen.scale_factor()); m_temp_painter = make(*m_temp_bitmap); m_buffers_are_flipped = false; @@ -803,7 +803,7 @@ void Compositor::draw_cursor(const Gfx::IntRect& cursor_rect) auto& wm = WindowManager::the(); if (!m_cursor_back_bitmap || m_cursor_back_bitmap->size() != cursor_rect.size() || m_cursor_back_bitmap->scale() != Screen::the().scale_factor()) { - m_cursor_back_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, cursor_rect.size(), Screen::the().scale_factor()); + m_cursor_back_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, cursor_rect.size(), Screen::the().scale_factor()); m_cursor_back_painter = make(*m_cursor_back_bitmap); } diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index 12102bd81f..51ccd784a5 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -159,7 +159,7 @@ void Window::set_rect(const Gfx::IntRect& rect) auto old_rect = m_rect; m_rect = rect; if (!m_client && (!m_backing_store || old_rect.size() != rect.size())) { - m_backing_store = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, m_rect.size()); + m_backing_store = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, m_rect.size()); } invalidate(true, old_rect.size() != rect.size()); diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index fc1e9d56ba..8ada69986b 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -227,7 +227,7 @@ bool WindowFrame::frame_has_alpha() const { if (m_has_alpha_channel) return true; - if (auto* shadow_bitmap = window_shadow(); shadow_bitmap && shadow_bitmap->format() == Gfx::BitmapFormat::RGBA32) + if (auto* shadow_bitmap = window_shadow(); shadow_bitmap && shadow_bitmap->format() == Gfx::BitmapFormat::BGRA8888) return true; return false; } @@ -388,7 +388,7 @@ void WindowFrame::render_to_cache() if (!s_tmp_bitmap || !s_tmp_bitmap->size().contains(total_frame_rect.size()) || s_tmp_bitmap->scale() != scale) { if (s_tmp_bitmap) s_tmp_bitmap->unref(); - s_tmp_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, total_frame_rect.size(), scale).leak_ref(); + s_tmp_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, total_frame_rect.size(), scale).leak_ref(); } auto top_bottom_height = total_frame_rect.height() - window_rect.height(); @@ -396,14 +396,14 @@ void WindowFrame::render_to_cache() if (!m_top_bottom || m_top_bottom->width() != total_frame_rect.width() || m_top_bottom->height() != top_bottom_height || m_top_bottom->scale() != scale) { if (top_bottom_height > 0) - m_top_bottom = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, { total_frame_rect.width(), top_bottom_height }, scale); + m_top_bottom = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { total_frame_rect.width(), top_bottom_height }, scale); else m_top_bottom = nullptr; m_shadow_dirty = true; } if (!m_left_right || m_left_right->height() != total_frame_rect.height() || m_left_right->width() != left_right_width || m_left_right->scale() != scale) { if (left_right_width > 0) - m_left_right = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, { left_right_width, total_frame_rect.height() }, scale); + m_left_right = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { left_right_width, total_frame_rect.height() }, scale); else m_left_right = nullptr; m_shadow_dirty = true;