darktable-org / darktable-org/darktable

sRGB export wrong without linear scaling calculation

Open
#13,335 23 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug: pending priority: high scope: image processing
Dominant language
C
Stars
13.1k
Forks
1.4k
Avg merge
22h 14m
Merged PRs (30d)
198

Description

The export of photos from DT 4.2 with downscaling or upscaling is calculating WRONG with nonlinear instead of linear RGB values.
This does decrease brightness and does change colors between pixels and all fine details in photos are affected. The effect is well known as "Gamma Error in Picture Scaling". See www.ericbrasseur.org/gamma.html

You can reproduce this error directly with a checkerboard file. See my PNG test file in another post https://github.com/darktable-org/darktable/issues/12310#issuecomment-1374626148 about the same issue of DR color picker, DT darkroom scaling and DT photo preview. Here are additional explanations: discuss.pixls.us/t/wrong-color-picker-calculation/34204/19

The export has to result in the same perceived color as the 100 % checkerboard file with 1x1 pixel.
This is a light yellow color (188,128,128) and NOT light red (188,188,128)
for the 1x1 pixel checkerboard with light green (188,255,128) and magenta (188,0,128).
This because the "average" of the green values 0 and 255 is not 128 but 188!

The image processing and viewing tools including all browsers who do result in light red or moiree colors are calculating wrong. The correct calculation would be to convert nonlinear RGB values to linear, then performing any manipulations (like calculation of average values) and finally calculating back to nonlinear RGB values. The formulas for this are well defined in IEC 61966-2-1 since 1999 and defined in chapter "Transformation" of en.wikipedia.org/wiki/SRGB

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the export with the referenced checkerboard PNG, using downscaling or upscaling and comparing it with the 1x1 reference result. Trace the export image-processing path to find where RGB values are averaged, then verify that the output preserves the expected perceived color rather than the reported light-red result.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.