From: Øyvind Kolås Date: Wed, 19 Jun 2019 11:20:43 +0000 (+0200) Subject: docs: update X-Git-Tag: archive/raspbian/1%0.1.106-3+rpi1^2~15^2~11^2~101 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8c0d1a942a4010b136f41b05cda45421b73d80da;p=babl.git docs: update --- diff --git a/TODO b/TODO index 2dbb27a..b83bb34 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,12 @@

TODO

+

These are among desired or expected changes to babl, that are missing.

+ diff --git a/docs/index-static.html.in b/docs/index-static.html.in index 9f9a08f..207a620 100644 --- a/docs/index-static.html.in +++ b/docs/index-static.html.in @@ -71,6 +71,9 @@

GEGL through

When performing further extensions to the vocabulary of babl, the internal consistency is governed by reference conversions that operate - on double (64 bit floating point values). The only color model - created during BablCore bootstrap is RGBA (linear light RGB, - 0.0 - 1.0, with a linear 0.0 - 1.0 opacity channel) backed by the - double datatype. Defined similarily to double (64 bit floating point values). Color Spaces can + be created from chromaticity coordinates or ICC profiles. The reference + color space - to maintain fast and bit-accurate conversions on with + sRGB is similar to scRGB using 64bit floating point.

-

If babls conversion isn't fast enough, you can provide - your own conversion shortcut between two formats. The registered - shortcut might also be used by babl as an intermediate conversion when - constructing BablFishes for other conversions. +

To speed up operations, ffast path conversions are used. + The registered shortcut might also be used by babl as an intermediate +conversion when constructing BablFishes for other conversions.

Babl extensions are shared objects. If you have already developed @@ -276,7 +281,68 @@ spaces, as they are defined with constants on their wikipedia pages or similar u a babl format can also be queried with babl_format_get_space.

- + +

Symmetric transformations for floating point alpha

+ + +

+ babl clamps the alpha used when going from separate alpha to associated alpha +or from associated alpha to separate alpha to BABL_ALPHA_FLOOR. This avoids +asymptotic behavior and direct precision loss of color precision when multiplying or dividing by alphas near 0.0.

+ +

Original intent of data as well as non-asymptotic precision loss is thus +maintained when the processing chain might temporarily use the other alpha +representation.

+ +
+    #define BABL_ALPHA_FLOOR    (1.0/65536.0)
+    #define BABL_ALPHA_FLOOR_F  (1.0f/65536.0f)
+
+ +

The deviation from not clamping near 0.0 is within the quantization margin +of 16bit integer alpha, thus no adaptations of are introduced for the 8bit and 16bit versions of pixel format conversions were needed. +

+ +

This is the clamping function:

+
+
+    static inline float
+    babl_epsilon_for_zero_float (float value)
+    {
+     if (value <= BABL_ALPHA_FLOOR_F)
+     {
+       /* for performance one could directly retun BABL_ALPHA_FLOOR_F here
+          and dropping handling negative values consistently. */
+       if (value >= 0.0f)
+         return BABL_ALPHA_FLOOR_F;
+       else if (value >= -BABL_ALPHA_FLOOR_F)
+         return -BABL_ALPHA_FLOOR_F;
+     }
+     return value;  /* most common case, return input value */
+    }
+
+

And an example use of this clamping function that is consistent with babls behavior:

+
+    static inline void
+    associated_to_separate_rgba (const float *associated_rgba,
+                                       float *separate_rgba)
+    {
+      float alpha = associated_rgba[3];
+      float clamped_alpha = babl_epsilon_for_zero_float (alpha);
+      float reciprocal_alpha = 1.0f / clamped_alpha;
+
+      separate_rgba[0] = associated_rgba[0] * reciprocal_alpha;
+      separate_rgba[1] = associated_rgba[1] * reciprocal_alpha;
+      separate_rgba[2] = associated_rgba[2] * reciprocal_alpha;
+      separate_rgba[3] = alpha;
+    }
+
+ + +

For more detils see the commit message of the most recent refinement as well as blog post with further background.

+ + +

CMYK

CMYK handling is done using babl-spaces created with ICC profiles @@ -370,25 +436,6 @@ and float:

--> - -

Pre-multiplied alpha

- -

babl stores color information in transparent pre-multiplied or associated -alpha pixels in floating point formats. With floating point pixel formats -standard way of handling alpha maintains color information very near fully -transparent pixels - by introducing a limit: BABL_ALPHA_FLOOR which is -1/65536.0, and treating all alphas beteen zero and this value as this value we -maintain color information while the discrepancy in behavior gets concealed by -quantization in 16bit and 8bit formats. -

-

For images that already are in a premultiplied format on import, this change -has no impact on its use for pre-multiplied arithmetic, meaning that -superluminous colors are still supported, it also opens up to GEGL more widely -expect premultiplied data in more operations which will become a speedup when -more filters want to integrate in the layer processing pipeline.

- -

There is a post on patreon with further details about the implementation.

- diff --git a/tests/transparent_symmetry.c b/tests/transparent_symmetry.c index 90a0974..a42709a 100644 --- a/tests/transparent_symmetry.c +++ b/tests/transparent_symmetry.c @@ -20,20 +20,22 @@ #include #include "babl-internal.h" -#define TOLERANCE 0.000001 -#define PIXELS 10 +#define TOLERANCE 0.001 +#define PIXELS 12 float source_buf [PIXELS * 4] = -{ 10.0, 1.0, 0.1, 1.0, - 10.0, 1.0, 0.1, 0.5, - 10.0, 1.0, 0.1, 0.1, - 10.0, 1.0, 0.1, 0.01, - 10.0, 1.0, 0.1, -0.01, - 10.0, 1.0, 0.1, 1.5, - 10.0, 1.0, 0.0001, 0.000001, - 10.0, 1.0, 0.1, -0.00001, - 10.0, 1.0, 0.1, 0.0, - 10.0, 1.0, 0.1, -0.5, +{ 10.0, 1.0, 0.1, 1.0, + 10.0, 1.0, 0.1, 0.5, + 10.0, 1.0, 0.1, 0.1, + 10.0, 1.0, 0.1, 0.01, + 10.0, 1.0, 0.1, -0.01, + 10.0, 1.0, 0.1, 1.5, + 10.0, 1.0, 0.0001, 0.000001, + 10.0, 1.0, 0.1 , -0.00001, + 10.0, 1.0, 0.1, 0.0, + 10.0, 1.0, 0.1, -0.5, + 1000.0,10000.0, 100000.0, 0.001, + 5000.0,50000.0, 500000.0, 0.01, }; float bounce_buf [PIXELS * 4];