Skip to content

Commit 9146a7d

Browse files
committed
Import format converters from _mplcairo, not from _util.
1 parent 3d9151d commit 9146a7d

File tree

7 files changed

+16
-20
lines changed

7 files changed

+16
-20
lines changed

lib/mplcairo/_util.py

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
import matplotlib as mpl
77

88
from . import _backports
9-
from ._mplcairo import (
10-
cairo_to_premultiplied_argb32,
11-
cairo_to_premultiplied_rgba8888,
12-
cairo_to_straight_rgba8888,
13-
)
149

1510

1611
@functools.lru_cache(1)

lib/mplcairo/base.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath="TeX!", mtext=None):
158158
mb.draw(self, x, y, angle)
159159

160160
def stop_filter(self, filter_func):
161-
img = _util.cairo_to_straight_rgba8888(self._stop_filter_get_buffer())
161+
img = _mplcairo.cairo_to_straight_rgba8888(
162+
self._stop_filter_get_buffer())
162163
img, (l, b, w, h) = _get_drawn_subarray_and_bounds(img)
163164
if not (w and h):
164165
return
@@ -176,14 +177,14 @@ def stop_filter(self, filter_func):
176177
lock = _LOCK # For webagg_core; matplotlib#10708 (<3.0).
177178

178179
def buffer_rgba(self): # For tkagg, webagg_core.
179-
return _util.cairo_to_straight_rgba8888(self._get_buffer())
180+
return _mplcairo.cairo_to_straight_rgba8888(self._get_buffer())
180181

181182
_renderer = property(buffer_rgba) # For tkagg; matplotlib#18993 (<3.4).
182183

183184
# For MixedModeRenderer; matplotlib#17788 (<3.4).
184185
def tostring_rgba_minimized(self):
185186
img, bounds = _get_drawn_subarray_and_bounds(
186-
_util.cairo_to_straight_rgba8888(self._get_buffer()))
187+
_mplcairo.cairo_to_straight_rgba8888(self._get_buffer()))
187188
return img.tobytes(), bounds
188189

189190

@@ -345,7 +346,7 @@ def _get_fresh_straight_rgba8888(self):
345346
renderer.clear()
346347
with _LOCK:
347348
self.figure.draw(renderer)
348-
return _util.cairo_to_straight_rgba8888(renderer._get_buffer())
349+
return _mplcairo.cairo_to_straight_rgba8888(renderer._get_buffer())
349350

350351
def print_rgba(self, path_or_stream, *,
351352
dryrun=False, metadata=None, **kwargs):

lib/mplcairo/macosx.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from matplotlib.backends.backend_macosx import _BackendMac, FigureCanvasMac
22

3-
from . import _util
3+
from . import _mplcairo
44
from .base import FigureCanvasCairo
55

66

@@ -11,7 +11,7 @@ def _draw(self):
1111
renderer.clear()
1212
self.figure.draw(renderer)
1313
# A bit hackish, but that's what _macosx.FigureCanvas wants...
14-
self._renderer = _util.cairo_to_straight_rgba8888(
14+
self._renderer = _mplcairo.cairo_to_straight_rgba8888(
1515
renderer._get_buffer())
1616
return self
1717

lib/mplcairo/qt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
_BackendQT5 as _BackendQT, FigureCanvasQT)
99
from matplotlib.backends.qt_compat import QtCore, QtGui
1010

11-
from . import _util
11+
from . import _mplcairo
1212
from .base import FigureCanvasCairo
1313

1414

@@ -19,7 +19,7 @@ def paintEvent(self, event):
1919
# We always repaint the full canvas (doing otherwise would require an
2020
# additional copy of the buffer into a contiguous block, so it's not
2121
# clear it would be faster).
22-
buf = _util.cairo_to_premultiplied_argb32(
22+
buf = _mplcairo.cairo_to_premultiplied_argb32(
2323
self.get_renderer()._get_buffer())
2424
height, width, _ = buf.shape
2525
# The image buffer is not necessarily contiguous, but the padding

lib/mplcairo/tk.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from matplotlib.backends._backend_tk import _BackendTk, FigureCanvasTk
44

5-
from . import _util
5+
from . import _mplcairo
66
from .base import FigureCanvasCairo
77

88
try:
@@ -19,7 +19,7 @@ def draw(self):
1919
self.blit()
2020

2121
def blit(self, bbox=None):
22-
buf = _util.cairo_to_straight_rgba8888(
22+
buf = _mplcairo.cairo_to_straight_rgba8888(
2323
self.get_renderer()._get_buffer())
2424
_tk_blit(self._tkphoto, buf, bbox=bbox)
2525

lib/mplcairo/wx.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
_BackendWx, _FigureCanvasWxBase, FigureFrameWx)
33
import wx
44

5-
from . import _util
5+
from . import _mplcairo, _util
66
from .base import FigureCanvasCairo
77

88

@@ -24,7 +24,7 @@ def draw(self, drawDC=None):
2424
# The source of wx.lib.wxcairo.BitmapFromImageSurface seems to suggest
2525
# that one can directly pass premultiplied RGBA to wx.Bitmap, but this
2626
# is incorrect (likely a bug?).
27-
buf = _util.cairo_to_straight_rgba8888(
27+
buf = _mplcairo.cairo_to_straight_rgba8888(
2828
self.get_renderer()._get_buffer())
2929
height, width, _ = buf.shape
3030
self.bitmap = wx.Bitmap.FromBufferRGBA(width, height, buf)

tests/test_speed.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from matplotlib.backends.backend_agg import FigureCanvasAgg
1111
import mplcairo
12-
from mplcairo import _util, antialias_t
12+
from mplcairo import _mplcairo, antialias_t
1313
from mplcairo.base import FigureCanvasCairo
1414

1515
# Import an autouse fixture.
@@ -37,8 +37,8 @@ def test_cairo_to_straight_rgba8888(benchmark, buf_name):
3737
s = 41774594
3838
else:
3939
assert False
40-
benchmark(_util.cairo_to_straight_rgba8888, buf)
41-
assert _util.cairo_to_straight_rgba8888(buf).sum() == s
40+
benchmark(_mplcairo.cairo_to_straight_rgba8888, buf)
41+
assert _mplcairo.cairo_to_straight_rgba8888(buf).sum() == s
4242

4343

4444
@pytest.fixture

0 commit comments

Comments
 (0)