Skip to content

Image Reader

renderkit.io.image_reader.ImageReader

Bases: ABC

Abstract base class for image readers.

Source code in src/renderkit/io/image_reader.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
class ImageReader(ABC):
    """Abstract base class for image readers."""

    @abstractmethod
    def read_imagebuf(
        self,
        path: Path,
        layer: Optional[str] = None,
        layer_map: Optional[dict[str, "LayerMapEntry"]] = None,
    ) -> Any:
        """Read an image file and return as an OIIO ImageBuf."""
        pass

    @abstractmethod
    def get_file_info(self, path: Path) -> FileInfo:
        """Get consolidated file information in a single read operation."""
        pass

    @abstractmethod
    def get_layers(self, path: Path) -> list[str]:
        """Get available layers from the image file."""
        pass

    @abstractmethod
    def get_channels(self, path: Path) -> int:
        """Get the number of channels."""
        pass

    @abstractmethod
    def get_resolution(self, path: Path) -> tuple[int, int]:
        """Get the resolution (width, height)."""
        pass

    @abstractmethod
    def get_metadata_fps(self, path: Path) -> Optional[float]:
        """Get FPS from metadata."""
        pass

    @abstractmethod
    def get_metadata_color_space(self, path: Path) -> Optional[str]:
        """Get color space from metadata."""
        pass

get_channels(path) abstractmethod

Get the number of channels.

Source code in src/renderkit/io/image_reader.py
106
107
108
109
@abstractmethod
def get_channels(self, path: Path) -> int:
    """Get the number of channels."""
    pass

get_file_info(path) abstractmethod

Get consolidated file information in a single read operation.

Source code in src/renderkit/io/image_reader.py
96
97
98
99
@abstractmethod
def get_file_info(self, path: Path) -> FileInfo:
    """Get consolidated file information in a single read operation."""
    pass

get_layers(path) abstractmethod

Get available layers from the image file.

Source code in src/renderkit/io/image_reader.py
101
102
103
104
@abstractmethod
def get_layers(self, path: Path) -> list[str]:
    """Get available layers from the image file."""
    pass

get_metadata_color_space(path) abstractmethod

Get color space from metadata.

Source code in src/renderkit/io/image_reader.py
121
122
123
124
@abstractmethod
def get_metadata_color_space(self, path: Path) -> Optional[str]:
    """Get color space from metadata."""
    pass

get_metadata_fps(path) abstractmethod

Get FPS from metadata.

Source code in src/renderkit/io/image_reader.py
116
117
118
119
@abstractmethod
def get_metadata_fps(self, path: Path) -> Optional[float]:
    """Get FPS from metadata."""
    pass

get_resolution(path) abstractmethod

Get the resolution (width, height).

Source code in src/renderkit/io/image_reader.py
111
112
113
114
@abstractmethod
def get_resolution(self, path: Path) -> tuple[int, int]:
    """Get the resolution (width, height)."""
    pass

read_imagebuf(path, layer=None, layer_map=None) abstractmethod

Read an image file and return as an OIIO ImageBuf.

Source code in src/renderkit/io/image_reader.py
86
87
88
89
90
91
92
93
94
@abstractmethod
def read_imagebuf(
    self,
    path: Path,
    layer: Optional[str] = None,
    layer_map: Optional[dict[str, "LayerMapEntry"]] = None,
) -> Any:
    """Read an image file and return as an OIIO ImageBuf."""
    pass

renderkit.io.image_reader.ImageReaderFactory

Factory for creating appropriate image readers (Now standardized to OIIO).

Source code in src/renderkit/io/image_reader.py
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
class ImageReaderFactory:
    """Factory for creating appropriate image readers (Now standardized to OIIO)."""

    _readers: dict[str, type[ImageReader]] = {
        "exr": OIIOReader,
        "png": OIIOReader,
        "jpg": OIIOReader,
        "jpeg": OIIOReader,
        "tiff": OIIOReader,
        "tif": OIIOReader,
        "dpx": OIIOReader,
    }

    @classmethod
    def create_reader(cls, path: Path, image_cache: Optional[Any] = None) -> ImageReader:
        """Create an OIIO reader for the given file."""
        extension = FileUtils.get_file_extension(path)
        reader_class = cls._readers.get(extension, OIIOReader)
        try:
            return reader_class(image_cache=image_cache)
        except TypeError:
            return reader_class()

    @classmethod
    def register_reader(cls, extension: str, reader_class: type[ImageReader]) -> None:
        """Register a custom image reader."""
        cls._readers[extension.lower()] = reader_class

create_reader(path, image_cache=None) classmethod

Create an OIIO reader for the given file.

Source code in src/renderkit/io/image_reader.py
618
619
620
621
622
623
624
625
626
@classmethod
def create_reader(cls, path: Path, image_cache: Optional[Any] = None) -> ImageReader:
    """Create an OIIO reader for the given file."""
    extension = FileUtils.get_file_extension(path)
    reader_class = cls._readers.get(extension, OIIOReader)
    try:
        return reader_class(image_cache=image_cache)
    except TypeError:
        return reader_class()

register_reader(extension, reader_class) classmethod

Register a custom image reader.

Source code in src/renderkit/io/image_reader.py
628
629
630
631
@classmethod
def register_reader(cls, extension: str, reader_class: type[ImageReader]) -> None:
    """Register a custom image reader."""
    cls._readers[extension.lower()] = reader_class