From 2fb992e34ae0d6bf73b9450139419063c61801ce Mon Sep 17 00:00:00 2001 From: John Wiggins Date: Thu, 18 Mar 2021 17:58:48 +0100 Subject: [PATCH] Use BGRA32 for celiagg's default pixel format --- enable/qt4/celiagg.py | 4 ++-- kiva/celiagg.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/enable/qt4/celiagg.py b/enable/qt4/celiagg.py index 1b3fea2c1..73fc90575 100644 --- a/enable/qt4/celiagg.py +++ b/enable/qt4/celiagg.py @@ -21,7 +21,7 @@ class Window(BaseWindow): # Keep a buffer around for converting RGBA -> BGRA _shuffle_buffer = Array(shape=(None, None, 4), dtype=np.uint8) - def _create_gc(self, size, pix_format="rgba32"): + def _create_gc(self, size, pix_format="bgra32"): gc = GraphicsContext( (size[0] + 1, size[1] + 1), pix_format=pix_format, @@ -58,7 +58,7 @@ def _shuffle_copy(self): Qt's Format_RGB32 is actually BGR. So, Yeah... """ - src = self._gc.gc.array + src = self._gc.bmp_array dst = self._shuffle_buffer src_fmt = self._gc.pix_format diff --git a/kiva/celiagg.py b/kiva/celiagg.py index 9b3b25223..05aee2947 100644 --- a/kiva/celiagg.py +++ b/kiva/celiagg.py @@ -87,7 +87,7 @@ def __init__(self, size, *args, **kwargs): super(GraphicsContext, self).__init__() self._width = size[0] self._height = size[1] - self.pix_format = kwargs.get('pix_format', 'rgba32') + self.pix_format = kwargs.get('pix_format', 'bgra32') shape = (self._height, self._width, 4) buffer = np.zeros(shape, dtype=np.uint8) @@ -113,6 +113,9 @@ def __init__(self, size, *args, **kwargs): self.base_scale = kwargs.pop('base_pixel_scale', 1) self.transform.scale(self.base_scale, self.base_scale) + # Make this look like a kiva.agg GC + self.bmp_array = buffer + # ---------------------------------------------------------------- # Size info # ---------------------------------------------------------------- @@ -584,16 +587,16 @@ def normalize_image(img): elif isinstance(img, Image.Image): img, img_format = normalize_image(img) img_array = np.array(img) + elif isinstance(img, GraphicsContext): + img_array = img.gc.array + img_format = pix_formats[img.pix_format] elif hasattr(img, 'bmp_array'): - # An offscreen kiva context + # An offscreen kiva.agg context # XXX: Use a copy to kill the read-only flag which plays havoc # with the Cython memoryviews used by celiagg img = Image.fromarray(img.bmp_array) img, img_format = normalize_image(img) img_array = np.array(img) - elif isinstance(img, GraphicsContext): - img_array = img.gc.array - img_format = pix_formats[img.pix_format] else: msg = "Cannot render image of type '{}' into celiagg context." warnings.warn(msg.format(type(img)))