color_management.md (2882B)
1 # Color Management 2 3 [TOC] 4 5 <!--* 6 # Document freshness: For more information, see go/fresh-source. 7 freshness: { owner: 'sboukortt' reviewed: '2022-09-27' } 8 *--> 9 10 ## Why 11 12 The vast majority of web images are still sRGB. However, wide-gamut material is 13 increasingly being produced (photography, cinema, 4K). Screens covering most of 14 the Adobe RGB gamut are readily available and some also cover most of DCI P3 15 (iPhone, Pixel2) or even BT.2020. 16 17 Currently, after a camera records a very saturated red pixel, most raw 18 processors would clip it to the rather small sRGB gamut before saving as JPEG. 19 In keeping with our high-quality goal, we prevent such loss by allowing wider 20 input color spaces. 21 22 ## Which color space 23 24 Even wide gamuts could be expressed relative to the sRGB primaries, but the 25 resulting coordinates may be outside the valid 0..1 range. Surprisingly, such 26 'unbounded' coordinates can be passed through color transforms provided the 27 transfer functions are expressed as parametric functions (not lookup tables). 28 However, most image file formats (including PNG and PNM) lack min/max metadata 29 and thus do not support unbounded coordinates. 30 31 Instead, we need a larger working gamut to ensure most pixel coordinates are 32 within bounds and thus not clipped. However, larger gamuts result in lower 33 precision/resolution when using <= 16 bit encodings (as opposed to 32-bit float 34 in PFM). BT.2100 or P3 DCI appear to be good compromises. 35 36 ## CMS library 37 38 Transforms with unbounded pixels are desirable because they reduce round-trip 39 error in tests. This requires parametric curves, which are only supported for 40 the common sRGB case in ICC v4 profiles. ArgyllCMS does not support v4. The 41 other popular open-source CMS is LittleCMS. It is also used by color-managed 42 editors (Krita/darktable), which increases the chances of interoperability. 43 However, LCMS has race conditions and overflow issues that prevent fuzzing. We 44 will later switch to the newer skcms. Note that this library does not intend to 45 support multiProcessElements, so HDR transfer functions cannot be represented 46 accurately. Thus in the long term, we will probably migrate away from ICC 47 profiles entirely. 48 49 ## Which viewer 50 51 On Linux, Krita and darktable support loading our PNG output images and their 52 ICC profile. 53 54 ## How to compress/decompress 55 56 ### Embedded ICC profile 57 58 - Create an 8-bit or 16-bit PNG with an iCCP chunk, e.g. using darktable. 59 - Pass it to `cjxl`, then `djxl` with no special arguments. The decoded output 60 will have the same bit depth (can override with `--output_bit_depth`) and 61 color space. 62 63 ### Images without metadata (e.g. HDR) 64 65 - Create a PGM/PPM/PFM file in a known color space. 66 - Invoke `cjxl` with `-x color_space=RGB_D65_202_Rel_Lin` (linear 2020). For 67 details/possible values, see color_encoding.cc `Description`. 68 - Invoke `djxl` as above with no special arguments.