Skip to content

Image Scaler

renderkit.processing.scaler.ImageScaler

Utility class for image scaling using OpenImageIO.

Source code in src/renderkit/processing/scaler.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class ImageScaler:
    """Utility class for image scaling using OpenImageIO."""

    @staticmethod
    def scale_buf(
        buf,
        width: int,
        height: int,
        filter_name: str = "lanczos3",
    ):
        """Scale an OIIO ImageBuf without converting to NumPy."""
        oiio = require_oiio()

        spec = buf.spec()
        src_buf = ensure_float_imagebuf(oiio, buf)

        dst_buf = oiio.ImageBuf(oiio.ImageSpec(width, height, spec.nchannels, oiio.FLOAT))
        if not oiio.ImageBufAlgo.resize(dst_buf, src_buf, filtername=filter_name):
            raise RuntimeError(f"OIIO resize failed: {oiio.geterror()}")

        return dst_buf

scale_buf(buf, width, height, filter_name='lanczos3') staticmethod

Scale an OIIO ImageBuf without converting to NumPy.

Source code in src/renderkit/processing/scaler.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@staticmethod
def scale_buf(
    buf,
    width: int,
    height: int,
    filter_name: str = "lanczos3",
):
    """Scale an OIIO ImageBuf without converting to NumPy."""
    oiio = require_oiio()

    spec = buf.spec()
    src_buf = ensure_float_imagebuf(oiio, buf)

    dst_buf = oiio.ImageBuf(oiio.ImageSpec(width, height, spec.nchannels, oiio.FLOAT))
    if not oiio.ImageBufAlgo.resize(dst_buf, src_buf, filtername=filter_name):
        raise RuntimeError(f"OIIO resize failed: {oiio.geterror()}")

    return dst_buf