Merge pull request #1377 from ixjlyons/issue-1353-imageitem-autodownsample
Consolidate and fix downsample factor computation in ImageItem
This commit is contained in:
commit
e2dc21e2ca
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
|
||||||
from ..Qt import QtGui, QtCore
|
from ..Qt import QtGui, QtCore
|
||||||
|
@ -370,22 +371,11 @@ class ImageItem(GraphicsObject):
|
||||||
lut = None
|
lut = None
|
||||||
|
|
||||||
if self.autoDownsample:
|
if self.autoDownsample:
|
||||||
# reduce dimensions of image based on screen resolution
|
xds, yds = self._computeDownsampleFactors()
|
||||||
o = self.mapToDevice(QtCore.QPointF(0,0))
|
if xds is None:
|
||||||
x = self.mapToDevice(QtCore.QPointF(1,0))
|
|
||||||
y = self.mapToDevice(QtCore.QPointF(0,1))
|
|
||||||
|
|
||||||
# Check if graphics view is too small to render anything
|
|
||||||
if o is None or x is None or y is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
w = Point(x-o).length()
|
|
||||||
h = Point(y-o).length()
|
|
||||||
if w == 0 or h == 0:
|
|
||||||
self.qimage = None
|
self.qimage = None
|
||||||
return
|
return
|
||||||
xds = max(1, int(1.0 / w))
|
|
||||||
yds = max(1, int(1.0 / h))
|
|
||||||
axes = [1, 0] if self.axisOrder == 'row-major' else [0, 1]
|
axes = [1, 0] if self.axisOrder == 'row-major' else [0, 1]
|
||||||
image = fn.downsample(self.image, xds, axis=axes[0])
|
image = fn.downsample(self.image, xds, axis=axes[0])
|
||||||
image = fn.downsample(image, yds, axis=axes[1])
|
image = fn.downsample(image, yds, axis=axes[1])
|
||||||
|
@ -552,20 +542,28 @@ class ImageItem(GraphicsObject):
|
||||||
|
|
||||||
def viewTransformChanged(self):
|
def viewTransformChanged(self):
|
||||||
if self.autoDownsample:
|
if self.autoDownsample:
|
||||||
o = self.mapToDevice(QtCore.QPointF(0,0))
|
xds, yds = self._computeDownsampleFactors()
|
||||||
x = self.mapToDevice(QtCore.QPointF(1,0))
|
if xds is None:
|
||||||
y = self.mapToDevice(QtCore.QPointF(0,1))
|
|
||||||
w = Point(x-o).length()
|
|
||||||
h = Point(y-o).length()
|
|
||||||
if w == 0 or h == 0:
|
|
||||||
self.qimage = None
|
self.qimage = None
|
||||||
return
|
return
|
||||||
xds = max(1, int(1.0 / w))
|
|
||||||
yds = max(1, int(1.0 / h))
|
|
||||||
if (xds, yds) != self._lastDownsample:
|
if (xds, yds) != self._lastDownsample:
|
||||||
self.qimage = None
|
self.qimage = None
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
def _computeDownsampleFactors(self):
|
||||||
|
# reduce dimensions of image based on screen resolution
|
||||||
|
o = self.mapToDevice(QtCore.QPointF(0, 0))
|
||||||
|
x = self.mapToDevice(QtCore.QPointF(1, 0))
|
||||||
|
y = self.mapToDevice(QtCore.QPointF(0, 1))
|
||||||
|
# scene may not be available yet
|
||||||
|
if o is None:
|
||||||
|
return None, None
|
||||||
|
w = Point(x - o).length()
|
||||||
|
h = Point(y - o).length()
|
||||||
|
if w == 0 or h == 0:
|
||||||
|
return None, None
|
||||||
|
return max(1, int(1.0 / w)), max(1, int(1.0 / h))
|
||||||
|
|
||||||
def mouseDragEvent(self, ev):
|
def mouseDragEvent(self, ev):
|
||||||
if ev.button() != QtCore.Qt.LeftButton:
|
if ev.button() != QtCore.Qt.LeftButton:
|
||||||
ev.ignore()
|
ev.ignore()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user