Skip to content

Commit

Permalink
Fix pixel probe
Browse files Browse the repository at this point in the history
Signed-off-by: Rémi Achard <[email protected]>
  • Loading branch information
remia committed Oct 6, 2023
1 parent e053e9c commit b9eba42
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/apps/ocioview/ocioview/viewer/image_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(self, parent: Optional[QtWidgets.QWidget] = None):
self._mouse_last_pos = QtCore.QPointF()

# Image texture
self._image_buf = None
self._image_array = None
self._image_tex = None
self._image_pos = np.array([0.0, 0.0])
self._image_size = np.array([1.0, 1.0])
Expand Down Expand Up @@ -348,14 +348,14 @@ def paintGL(self) -> None:
GL.glBindVertexArray(0)

def load_oiio(self, image_path: Path) -> np.ndarray:
self._image_buf = oiio.ImageBuf(image_path.as_posix())
spec = self._image_buf.spec()
image_buf = oiio.ImageBuf(image_path.as_posix())
spec = image_buf.spec()

# Convert to RGBA, filling missing color channels with 0.0, and a
# missing alpha with 1.0.
if spec.nchannels < 4:
self._image_buf = oiio.ImageBufAlgo.channels(
self._image_buf,
image_buf = oiio.ImageBufAlgo.channels(
image_buf,
tuple(
list(range(spec.nchannels))
+ ([0.0] * (4 - spec.nchannels - 1))
Expand All @@ -364,12 +364,12 @@ def load_oiio(self, image_path: Path) -> np.ndarray:
newchannelnames=("R", "G", "B", "A"),
)
elif spec.nchannels > 4:
self._image_buf = oiio.ImageBufAlgo.channels(
self._image_buf, (0, 1, 2, 3), newchannelnames=("R", "G", "B", "A")
image_buf = oiio.ImageBufAlgo.channels(
image_buf, (0, 1, 2, 3), newchannelnames=("R", "G", "B", "A")
)

# Get pixels as 32-bit float NumPy array
return self._image_buf.get_pixels(oiio.FLOAT)
return image_buf.get_pixels(oiio.FLOAT)

def load_iio(self, image_path: Path) -> np.ndarray:
data = iio.imread(image_path.as_posix())
Expand Down Expand Up @@ -417,12 +417,12 @@ def load_image(self, image_path: Path) -> None:
self._ocio_input_color_space = color_space_name

if "OpenImageIO" in sys.modules:
data = self.load_oiio(image_path)
self._image_array = self.load_oiio(image_path)
else:
data = self.load_iio(image_path)
self._image_array = self.load_iio(image_path)

width = data.shape[1]
height = data.shape[0]
width = self._image_array.shape[1]
height = self._image_array.shape[0]

# Stash image size for pan/zoom calculations

Expand All @@ -442,7 +442,7 @@ def load_image(self, image_path: Path) -> None:
0,
GL.GL_RGBA,
GL.GL_FLOAT,
data.ravel(),
self._image_array.ravel(),
)

self.image_loaded.emit(
Expand Down Expand Up @@ -707,13 +707,13 @@ def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None:

# Broadcast sample position
if (
self._image_buf is not None
and 0 <= pixel_pos[0] <= self._image_size[0]
and 0 <= pixel_pos[1] <= self._image_size[1]
self._image_array is not None
and 0 <= pixel_pos[0] < self._image_size[0]
and 0 <= pixel_pos[1] < self._image_size[1]
):
pixel_x = math.floor(pixel_pos[0])
pixel_y = math.floor(pixel_pos[1])
pixel_input = list(self._image_buf.getpixel(pixel_x, pixel_y))
pixel_input = list(self._image_array[pixel_y, pixel_x])
if len(pixel_input) < 3:
pixel_input += [0.0] * (3 - len(pixel_input))
elif len(pixel_input) > 3:
Expand Down Expand Up @@ -812,7 +812,7 @@ def zoom(

self.pan(offset, update=update)

if self._image_buf is not None:
if self._image_array is not None:
self.scale_changed.emit(self._image_scale)

def fit(self, update: bool = True) -> None:
Expand Down

0 comments on commit b9eba42

Please sign in to comment.