AcademySoftwareFoundation / OpenImageIO

Reading, writing, and processing images in a wide variety of file formats, using a format-agnostic API, aimed at VFX applications.
https://openimageio.readthedocs.org
Apache License 2.0
1.95k stars 582 forks source link

Feature request: improve sRGB parsing #4165

Closed BrianHanke closed 6 months ago

BrianHanke commented 6 months ago

Howdy all, a new beta version of Gaffer is out and it uses a newer version of OIIO. A number of us ran into a problem when the Gaffer launcher couldn't find an sRGB color space.

In my case I traced the problem to using a custom OCIO config and OIIO being unable to find the keywords it's looking for. My config's sRGB texture section originally read as follows:

name: sRGB texture
aliases: [srgb_tx, Utility - sRGB texture, srgb_texture, Input - Generic - sRGB texture]

OIIO couldn't parse this. I was able to fix the problem by either changing the name to sRGB - Texture or adding a new srgb alias. I should note that my config is based on the official ASWF CG config which also does not have an srgb alias.

It seems like one solution might be to add some more aliases from the ASWF config to OIIO's search: maybe srgb_tx and srgb_texture. Thank you!

johnhaddon commented 6 months ago

I think the relevant details on the Gaffer side are :

I had hoped that setting OIIO_DISABLE_OCIO would get us back to using OIIO's built-in sRGB->linear transform, but that doesn't seem to help.

lgritz commented 6 months ago

Sounds like something is broken.

Do you have a way to trigger a symptomatic behavior using just OIIO? Like, given a particular OCIO config, is there a straight-up oiiotool command or short python script that will do something clearly wrong that I can use to track this down?

johnhaddon commented 6 months ago

Yep, over on the Gaffer issue there's a config that shows the problem when used with this : OCIO=bhgc_v2.ocio oiiotool test.png --colorconvert sRGB linear -o test.exr. I don't think you need anything special in test.png- any old file will do I think.

Unless the problem is on the Gaffer side after all, I'd expect that to fail with OIIO 2.5.8.0 and OCIO 2.2.1.

BrianHanke commented 6 months ago

I already patched that config to work with Gaffer 1.4. Here's the old one that showcases the issue:

ocio_profile_version: 2.1

environment:
  {}
search_path: ""
strictparsing: true
luma: [0.2126, 0.7152, 0.0722]
name: bhgc_v2
description: |
  Version 2024.2.2, February 26, 2024. 

  Simplified OCIO config for CG by Brian Hanke (brianrhanke@outlook.com). Based on the new ASWF CG config.  

  To use, copy this file to a location of your choice and point your OCIO environment variable to it. 

  This work is licensed under CC BY 4.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.

roles:  
  aces_interchange: ACES2065-1
  cie_xyz_d65_interchange: CIE-XYZ-D65

  color_picking: sRGB texture
  texture_paint: sRGB texture

  color_timing: ACEScct
  compositing_log: ACEScct
  matte_paint: ACEScct

  data: Raw

  rendering: ACEScg
  scene_linear: ACEScg

file_rules:
  - !<Rule> {name: Default, colorspace: ACES2065-1}

displays:
  ACES:
    - !<View> {name: sRGB, view_transform: ACES 1.0 - SDR Video, display_colorspace: sRGB - Display}
    - !<View> {name: Rec.709, view_transform: ACES 1.0 - SDR Video, display_colorspace: Rec.1886 Rec.709 - Display}
    - !<View> {name: Raw, display_colorspace: Raw}

inactive_colorspaces: [CIE-XYZ-D65, sRGB - Display, Rec.1886 Rec.709 - Display]

view_transforms:
  - !<ViewTransform>
    name: ACES 1.0 - SDR Video
    description: |
      Component of ACES Output Transforms for SDR D65 video

      ACEStransformID: urn:ampas:aces:transformId:v1.5:ODT.Academy.RGBmonitor_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:ODT.Academy.Rec709_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:ODT.Academy.Rec2020_100nits_dim.a1.0.3

      AMF Components
      --------------
      ACEStransformID: urn:ampas:aces:transformId:v1.5:InvODT.Academy.RGBmonitor_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:InvODT.Academy.Rec709_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:InvODT.Academy.Rec2020_100nits_dim.a1.0.3
    from_scene_reference: !<BuiltinTransform> {style: ACES-OUTPUT - ACES2065-1_to_CIE-XYZ-D65 - SDR-VIDEO_1.0}

display_colorspaces:
  - !<ColorSpace>
    name: CIE-XYZ-D65
    aliases: [cie_xyz_d65]
    family: ""
    equalitygroup: ""
    bitdepth: 32f
    description: The CIE XYZ (D65) display connection colorspace
    isdata: false
    allocation: uniform

  - !<ColorSpace>
    name: sRGB - Display
    aliases: [srgb_display]
    family: Display
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Convert CIE XYZ (D65 white) to sRGB (piecewise EOTF)

      AMF Components
      --------------
      ACEStransformID: urn:ampas:aces:transformId:v1.5:ODT.Academy.RGBmonitor_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:InvODT.Academy.RGBmonitor_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:ODT.Academy.RGBmonitor_D60sim_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:InvODT.Academy.RGBmonitor_D60sim_100nits_dim.a1.0.3
    isdata: false
    categories: [file-io]
    encoding: sdr-video
    allocation: uniform
    from_display_reference: !<BuiltinTransform> {style: DISPLAY - CIE-XYZ-D65_to_sRGB}

  - !<ColorSpace>
    name: Rec.1886 Rec.709 - Display
    aliases: [rec1886_rec709_display]
    family: Display
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Convert CIE XYZ (D65 white) to Rec.1886/Rec.709 (HD video)

      AMF Components
      --------------
      ACEStransformID: urn:ampas:aces:transformId:v1.5:ODT.Academy.Rec709_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:InvODT.Academy.Rec709_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:ODT.Academy.Rec709_D60sim_100nits_dim.a1.0.3
      ACEStransformID: urn:ampas:aces:transformId:v1.5:InvODT.Academy.Rec709_D60sim_100nits_dim.a1.0.3
    isdata: false
    categories: [file-io]
    encoding: sdr-video
    allocation: uniform
    from_display_reference: !<BuiltinTransform> {style: DISPLAY - CIE-XYZ-D65_to_REC.1886-REC.709}

colorspaces:
  - !<ColorSpace>
    name: ACES2065-1
    aliases: [aces2065_1, ACES - ACES2065-1, lin_ap0]
    family: ACES
    equalitygroup: ""
    bitdepth: 32f
    description: The "Academy Color Encoding System" reference colorspace.
    isdata: false
    categories: [file-io]
    encoding: scene-linear
    allocation: uniform

  - !<ColorSpace>
    name: ACEScc
    aliases: [ACES - ACEScc, acescc_ap1]
    family: ACES
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Convert ACEScc to ACES2065-1

      ACEStransformID: urn:ampas:aces:transformId:v1.5:ACEScsc.Academy.ACEScc_to_ACES.a1.0.3
    isdata: false
    categories: [file-io]
    encoding: log
    allocation: uniform
    to_scene_reference: !<BuiltinTransform> {style: ACEScc_to_ACES2065-1}

  - !<ColorSpace>
    name: ACEScct
    aliases: [ACES - ACEScct, acescct_ap1]
    family: ACES
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Convert ACEScct to ACES2065-1

      ACEStransformID: urn:ampas:aces:transformId:v1.5:ACEScsc.Academy.ACEScct_to_ACES.a1.0.3
    isdata: false
    categories: [file-io, working-space]
    encoding: log
    allocation: uniform
    to_scene_reference: !<BuiltinTransform> {style: ACEScct_to_ACES2065-1}

  - !<ColorSpace>
    name: ACEScg
    aliases: [ACES - ACEScg, lin_ap1]
    family: ACES
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Convert ACEScg to ACES2065-1

      ACEStransformID: urn:ampas:aces:transformId:v1.5:ACEScsc.Academy.ACEScg_to_ACES.a1.0.3
    isdata: false
    categories: [file-io, working-space]
    encoding: scene-linear
    allocation: uniform
    to_scene_reference: !<BuiltinTransform> {style: ACEScg_to_ACES2065-1}

  - !<ColorSpace>
    name: sRGB linear
    aliases: [lin_rec709_srgb, Utility - Linear - Rec.709, lin_rec709, lin_srgb, Utility - Linear - sRGB]
    family: Utility
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Convert ACES2065-1 to linear Rec.709 primaries, D65 white point

      CLFtransformID: urn:aswf:ocio:transformId:1.0:OCIO:Utility:AP0_to_Linear_Rec709:1.0
    isdata: false
    categories: [file-io, working-space]
    encoding: scene-linear
    allocation: uniform
    from_scene_reference: !<GroupTransform>
      name: AP0 to Linear Rec.709 (sRGB)
      children:
        - !<MatrixTransform> {matrix: [2.52168618674388, -1.13413098823972, -0.387555198504164, 0, -0.276479914229922, 1.37271908766826, -0.096239173438334, 0, -0.0153780649660342, -0.152975335867399, 1.16835340083343, 0, 0, 0, 0, 1]}

  - !<ColorSpace>
    name: sRGB texture
    aliases: [srgb_tx, Utility - sRGB texture, srgb_texture, Input - Generic - sRGB texture]
    family: Utility
    equalitygroup: ""
    bitdepth: 32f
    description: |
      Convert ACES2065-1 to sRGB

      CLFtransformID: urn:aswf:ocio:transformId:1.0:OCIO:Utility:AP0_to_sRGB-Texture:1.0
    isdata: false
    categories: [file-io]
    allocation: uniform
    from_scene_reference: !<GroupTransform>
      name: AP0 to sRGB Rec.709
      children:
        - !<MatrixTransform> {matrix: [2.52168618674388, -1.13413098823972, -0.387555198504164, 0, -0.276479914229922, 1.37271908766826, -0.096239173438334, 0, -0.0153780649660342, -0.152975335867399, 1.16835340083343, 0, 0, 0, 0, 1]}
        - !<ExponentWithLinearTransform> {gamma: 2.4, offset: 0.055, direction: inverse}

  - !<ColorSpace>
    name: Raw
    aliases: [Utility - Raw]
    family: Utility
    equalitygroup: ""
    bitdepth: 32f
    description: The utility "Raw" colorspace.
    isdata: true
    categories: [file-io]
    allocation: uniform

  - !<ColorSpace>
    name: sRGB neutral
    family: Utility
    equalitygroup: ""
    bitdepth: 32f
    description: For neutral input and output of images on sRGB - Display ACES 1.0 - SDR Video displays
    isdata: false
    categories: [file-io]
    encoding: sdr-video
    allocation: uniform
    from_reference: !<GroupTransform>
      children:
        - !<DisplayViewTransform> {src: ACES2065-1, display: ACES, view: sRGB}
        - !<RangeTransform> {min_in_value: 0., min_out_value: 0., max_in_value: 1., max_out_value: 1.}

  - !<ColorSpace>
    name: Rec.709 neutral
    aliases: [Gamma2.2]
    family: Utility
    equalitygroup: ""
    bitdepth: 32f
    description: For neutral input and output of images on Rec.1886 Rec.709 - Display ACES 1.0 - SDR Video displays
    isdata: false
    categories: [file-io]
    encoding: sdr-video
    allocation: uniform
    from_reference: !<GroupTransform>
      children:
        - !<DisplayViewTransform> {src: ACES2065-1, display: ACES, view: Rec.709}
        - !<RangeTransform> {min_in_value: 0., min_out_value: 0., max_in_value: 1., max_out_value: 1.}
lgritz commented 6 months ago

I can repro. Working toward a fix.

johnhaddon commented 6 months ago

Thanks Larry! That's great news!

lgritz commented 6 months ago

Proposed fix here: #4166