forked from AcademySoftwareFoundation/OpenColorIO
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement initial chromaticity inspector.
- Loading branch information
Showing
7 changed files
with
325 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright Contributors to the OpenColorIO Project. | ||
|
||
from .chromaticities_inspector import ChromaticitiesInspector | ||
from .code_inspector import CodeInspector | ||
from .curve_inspector import CurveInspector | ||
from .log_inspector import LogInspector |
119 changes: 119 additions & 0 deletions
119
src/apps/ocioview/ocioview/inspect/chromaticities_inspector.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright Contributors to the OpenColorIO Project. | ||
|
||
import numpy as np | ||
import pygfx as gfx | ||
import PyOpenColorIO as ocio | ||
from colour_visuals import * | ||
from PySide6 import QtCore, QtGui, QtWidgets | ||
from typing import Optional | ||
|
||
from ..viewer import WgpuCanvasOffScreenViewer | ||
from ..message_router import MessageRouter | ||
from ..processor_context import ProcessorContext | ||
from ..utils import get_glyph_icon, subsampling_factor | ||
|
||
|
||
class ChromaticitiesInspector(QtWidgets.QWidget): | ||
@classmethod | ||
def label(cls) -> str: | ||
return "Chromaticities" | ||
|
||
@classmethod | ||
def icon(cls) -> QtGui.QIcon: | ||
return get_glyph_icon("mdi6.grain") | ||
|
||
def __init__(self, parent: Optional[QtCore.QObject] = None): | ||
super().__init__(parent=parent) | ||
|
||
self._cpu_proc = None | ||
self._image_array = None | ||
|
||
self._wgpu_viewer = WgpuCanvasOffScreenViewer() | ||
self._root = None | ||
self._visuals = {} | ||
self._setup_scene() | ||
|
||
# Layout | ||
layout = QtWidgets.QHBoxLayout() | ||
self.setLayout(layout) | ||
layout.addWidget(self._wgpu_viewer) | ||
|
||
msg_router = MessageRouter.get_instance() | ||
msg_router.processor_ready.connect(self._on_processor_ready) | ||
msg_router.image_ready.connect(self._on_image_ready) | ||
|
||
@property | ||
def wgpu_viewer(self): | ||
return self._wgpu_viewer | ||
|
||
def _setup_scene(self): | ||
self._wgpu_viewer.wgpu_scene.add( | ||
gfx.Background( | ||
None, gfx.BackgroundMaterial(np.array([0.18, 0.18, 0.18])) | ||
) | ||
) | ||
self._visuals = { | ||
"grid": VisualGrid(size=2), | ||
"chromaticity_diagram": VisualChromaticityDiagramCIE1931( | ||
kwargs_visual_chromaticity_diagram={"opacity": 0.25} | ||
), | ||
"rgb_scatter_3d": VisualRGBScatter3D(np.zeros(3), "ACES2065-1", | ||
size=4), | ||
} | ||
|
||
self._root = gfx.Group() | ||
for visual in self._visuals.values(): | ||
self._root.add(visual) | ||
self._wgpu_viewer.wgpu_scene.add(self._root) | ||
|
||
def reset(self) -> None: | ||
pass | ||
|
||
def showEvent(self, event: QtGui.QShowEvent) -> None: | ||
"""Start listening for processor updates, if visible.""" | ||
super().showEvent(event) | ||
|
||
msg_router = MessageRouter.get_instance() | ||
msg_router.processor_updates_allowed = True | ||
msg_router.image_updates_allowed = True | ||
|
||
def hideEvent(self, event: QtGui.QHideEvent) -> None: | ||
"""Stop listening for processor updates, if not visible.""" | ||
super().hideEvent(event) | ||
|
||
msg_router = MessageRouter.get_instance() | ||
msg_router.processor_updates_allowed = False | ||
msg_router.image_updates_allowed = False | ||
|
||
@QtCore.Slot(ocio.CPUProcessor) | ||
def _on_processor_ready(self, proc_context: ProcessorContext, | ||
cpu_proc: ocio.CPUProcessor) -> None: | ||
print("ChromaticitiesInspector._on_processor_ready") | ||
|
||
self._cpu_proc = cpu_proc | ||
|
||
@QtCore.Slot(np.ndarray) | ||
def _on_image_ready(self, image_array: np.ndarray) -> None: | ||
print("ChromaticitiesInspector._on_image_ready") | ||
|
||
if self._cpu_proc is not None: | ||
sub_sampling_factor = int( | ||
np.sqrt(subsampling_factor(image_array, 1e6))) | ||
self._image_array = image_array[ | ||
::sub_sampling_factor, ::sub_sampling_factor, | ||
... | ||
] | ||
self._cpu_proc.applyRGB(image_array) | ||
self._visuals["rgb_scatter_3d"].RGB = image_array | ||
|
||
self._wgpu_viewer.render() | ||
|
||
|
||
if __name__ == "__main__": | ||
application = QtWidgets.QApplication([]) | ||
chromaticity_inspector = ChromaticitiesInspector() | ||
chromaticity_inspector.resize(800, 600) | ||
chromaticity_inspector.show() | ||
|
||
application.exec() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.