Skip to content

Commit 60dc544

Browse files
committed
Fixed XYImageFilterItem regression bug
1 parent 3632e9c commit 60dc544

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

plotpy/items/image/filter.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import sys
6+
from collections.abc import Callable
67
from typing import TYPE_CHECKING
78

89
import numpy as np
@@ -38,12 +39,12 @@
3839
if TYPE_CHECKING: # pragma: no cover
3940
import qwt.color_map
4041
import qwt.scale_map
41-
from qtpy import QtGui as QG
4242
from qtpy.QtCore import QPointF, QRectF
4343
from qtpy.QtGui import QPainter
4444

4545
from plotpy.interfaces import IItemType
46-
from plotpy.styles.base import ItemParameters
46+
from plotpy.items import RawImageItem, XYImageItem
47+
from plotpy.styles import ImageFilterParam, ItemParameters
4748

4849

4950
# ==============================================================================
@@ -74,10 +75,15 @@ class ImageFilterItem(BaseImageItem):
7475
_can_resize = True
7576
_can_move = True
7677

77-
def __init__(self, image, filter, param):
78+
def __init__(
79+
self, image: RawImageItem | None, filter: Callable, param: ImageFilterParam
80+
) -> None:
7881
self.use_source_cmap = None
79-
self.image = None # BaseImageItem constructor will try to set this
80-
# item's color map using the method 'set_color_map'
82+
83+
# BaseImageItem constructor will try to set this item's color map
84+
# using the method 'set_color_map'
85+
self.image: RawImageItem | None = None
86+
8187
super().__init__(param=param)
8288
self.border_rect.set_style("plot", "shape/imagefilter")
8389
self.image = image
@@ -88,15 +94,15 @@ def __init__(self, image, filter, param):
8894
self.setIcon(get_icon("funct.png"))
8995

9096
# ---- Public API -----------------------------------------------------------
91-
def set_image(self, image):
97+
def set_image(self, image: RawImageItem | None) -> None:
9298
"""
9399
Set the image item on which the filter will be applied
94100
95101
* image: :py:class:`.RawImageItem` instance
96102
"""
97103
self.image = image
98104

99-
def set_filter(self, filter):
105+
def set_filter(self, filter: Callable) -> None:
100106
"""
101107
Set the filter function
102108
@@ -195,11 +201,8 @@ def set_color_map(
195201
else:
196202
BaseImageItem.set_color_map(self, name_or_table)
197203

198-
def get_color_map(self):
199-
"""
200-
201-
:return:
202-
"""
204+
def get_color_map(self) -> qwt.color_map.QwtLinearColorMap:
205+
"""Get colormap"""
203206
if self.use_source_cmap:
204207
return self.image.get_color_map()
205208
else:
@@ -267,8 +270,11 @@ class XYImageFilterItem(ImageFilterItem):
267270
(:py:class:`.ImageFilterParam` instance)
268271
"""
269272

270-
def __init__(self, image, filter, param):
271-
ImageFilterItem.__init__(self, image, filter, param)
273+
def __init__(
274+
self, image: XYImageItem, filter: Callable, param: ImageFilterParam
275+
) -> None:
276+
self.image: XYImageItem | None = None
277+
super().__init__(image, filter, param)
272278

273279
def set_image(self, image):
274280
"""
@@ -321,21 +327,10 @@ def draw_image(
321327
if W <= 1 or H <= 1:
322328
return
323329

324-
x0, y0, x1, y1 = src_rect
325-
cx = canvasRect.left()
326-
cy = canvasRect.top()
327-
sx = (x1 - x0) / (W - 1)
328-
sy = (y1 - y0) / (H - 1)
329-
# tr1 = tr(x0,y0)@scale(sx,sy)@tr(-cx,-cy)
330-
tr = np.array([[sx, 0, x0 - cx * sx], [0, sy, y0 - cy * sy], [0, 0, 1]], float)
331-
mat = self.image.tr @ tr
332-
333-
xytr = x - self.image.x[0], y - self.image.y[0], src_rect
334-
330+
# x, y = x - self.image.x[0], y - self.image.y[0]
335331
dest = _scale_xy(
336332
new_data,
337-
xytr,
338-
mat,
333+
(x, y, src_rect),
339334
self._offscreen,
340335
dstRect.getCoords(),
341336
lut,

0 commit comments

Comments
 (0)