Skip to content
Snippets Groups Projects

shaders/icc: set icc transfer to closest value

Closed Kacper Michajłow requested to merge kasper93/libplacebo:icc_trc into master
2 unresolved threads

Merge request reports

Pipeline #443428 passed

Pipeline passed for c34d72d8 on kasper93:icc_trc

Test coverage 80.12% (0.00%) from 1 job
Approval is optional

Closed by Kacper MichajłowKacper Michajłow 1 year ago (Mar 14, 2024 7:49pm UTC)

Merge details

  • The changes were not merged into master.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
264 264 pl_unreachable();
265 265 }
266 266
267 float pl_color_transfer_approx_gamma(enum pl_color_transfer trc)
  • I would prefer not exposing this publicly - it's very specific to ICC, both in its ignorance of how to handle this for HDR, and its general low usability outside the very specific context of needing to measure/estimate the gamma of a look-up table. It also invites using inaccurate approximations.

    Edited by Niklas Haas
  • Please register or sign in to reply
  • Niklas Haas
    Niklas Haas @haasn started a thread on commit c34d72d8
  • 407 407 best = pl_raw_primaries_get(icc->containing_primaries);
    408 408 }
    409 409
    410 icc->csp.transfer = PL_COLOR_TRC_GAMMA18;
    411 for (enum pl_color_transfer trc = PL_COLOR_TRC_GAMMA18; trc <= PL_COLOR_TRC_GAMMA28; trc++) {
    412 if (fabsf(icc->gamma - pl_color_transfer_approx_gamma(icc->csp.transfer)) >
    413 fabsf(icc->gamma - pl_color_transfer_approx_gamma(trc)))
    414 {
    415 icc->csp.transfer = trc;
    • Wouldn't it be better to measure the MSE of the target curve against the measured curve directly, rather than basing this off the approximation gamma?

    • Author Contributor

      You mean to implement all PL_COLOR_TRC in C and compare them with the response from ICC profile? Seems like much code for this silly feature.

    • True, but it's the price you pay for this feature actually being useful. 9 times out of 10, the most interesting thing about a profile is whether it's BT.1886, gamma 2.2 or sRGB. This methodology cannot even resolve that distinction because both are hard-coded to 2.2, so it'll use the numerically first one. Not good design IMO.

      I think I'll just go ahead and make a C implementation of the TRCs, it's useful anyway

    • Author Contributor

      That's good point, I was thinking about it, but out of laziness just left it as is.

      I think I'll just go ahead and make a C implementation of the TRCs, it's useful anyway

      I can help, but give me pointer how would you like the API to look like for those?

    • Well, if we want it to be able to apply the HLG OOTF, it needs to handle all three channels at the same time:

      void pl_color_linearize(const struct pl_color_space *csp, float color[3]);
      void pl_color_delinearize(const struct pl_color_space *csp, float color[3]);

      That way it can be the natural mirror of pl_shader_(de)linearize, with no unexpected surprises.

    • Maybe having the *csp be the last parameter will allow this more useful construction:

      float color[3] = { 0.5, 0.5, 0.5 };
      pl_color_linearize(color, pl_color_space(
          .primaries = FOO,
          .transfer  = BAR,
      ));
    • Please register or sign in to reply
  • As a side note, you may be interested in this:

    https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/libavcodec/fflcms2.c#l302

    It might actually be easier to re-use the Little-CMS implementation of these transfer functions for our purposes as well. But I feel like a generic C function would be more interesting/useful long-term.

    Edited by Niklas Haas
  • Niklas Haas mentioned in commit 2617a3c1

    mentioned in commit 2617a3c1

  • Please register or sign in to reply
    Loading