From 441ad19f6b870cb876e2295e9f64a719884dcbba Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 21 Mar 2022 16:55:52 -0400 Subject: [PATCH] Fetch the real colorspace for the drawable when creating scratch bitmaps. --- xlib/Drawables.cpp | 13 +++++++++++++ xlib/Drawables.h | 5 +++++ xlib/Drawing.cpp | 3 +-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/xlib/Drawables.cpp b/xlib/Drawables.cpp index 263716a..f3b9e15 100644 --- a/xlib/Drawables.cpp +++ b/xlib/Drawables.cpp @@ -6,6 +6,7 @@ #include "Drawables.h" #include +#include #include #include @@ -400,6 +401,12 @@ XWindow::border_pixel(long border_color) UnlockLooper(); } +color_space +XWindow::colorspace() +{ + return BScreen(Window()).ColorSpace(); +} + bool XWindow::resize(BSize newSize) { @@ -827,6 +834,12 @@ XPixmap::~XPixmap() delete _offscreen; } +color_space +XPixmap::colorspace() +{ + return _offscreen->ColorSpace(); +} + bool XPixmap::resize(BSize newSize) { diff --git a/xlib/Drawables.h b/xlib/Drawables.h index b03e158..5a4a3e9 100644 --- a/xlib/Drawables.h +++ b/xlib/Drawables.h @@ -72,6 +72,7 @@ class XDrawable : XLIBE_DRAWABLES_PROTECTED BView { virtual ~XDrawable() override; BView* view() { return this; } + virtual color_space colorspace() = 0; Display* display() const { return _display; } Drawable id() const { return _id; } @@ -112,6 +113,8 @@ class XWindow : public XDrawable { void create_bwindow(); + virtual color_space colorspace() override; + virtual bool resize(BSize newSize) override; int border_width() { return _border_width; } @@ -164,6 +167,8 @@ class XPixmap : public XDrawable { XPixmap(Display* dpy, BRect frame, unsigned int depth); virtual ~XPixmap() override; + virtual color_space colorspace() override; + int depth() { return _depth; } BBitmap* offscreen() { return _offscreen; } diff --git a/xlib/Drawing.cpp b/xlib/Drawing.cpp index 5f24b5c..cdd7f59 100644 --- a/xlib/Drawing.cpp +++ b/xlib/Drawing.cpp @@ -372,8 +372,7 @@ XPutImage(Display *display, Drawable d, GC gc, XImage* image, size.height = scratchBounds.Height(); delete drawable->scratch_bitmap; - drawable->scratch_bitmap = new BBitmap(BRect(BPoint(0, 0), size), 0, B_RGB32); - // TODO: or FIXME: get the actual color space? + drawable->scratch_bitmap = new BBitmap(BRect(BPoint(0, 0), size), 0, drawable->colorspace()); } // TODO: Optimization: Import only the bits we are about to draw!