1 <?xml version=
"1.0" encoding=
"utf-8"?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5 <!-- The babl webpage is partially autogenerated
9 <title>Unified Alpha - babl
</title>
10 <meta http-equiv=
"content-type" content=
"text/html;charset=utf-8" />
11 <link rel=
"icon" href=
"graphics/babl-16x16.png" type=
"image/png" />
12 <link rel=
"shortcut icon" href=
"graphics/babl-16x16.png" type=
"image/png" />
13 <style type='text/css'
>
14 @import url(babl.css);
20 <div class='print_title'
>
29 <h2>Symmetric transformations for floating point alpha
</h2>
32 <p> babl clamps the alpha used when going from separate alpha to associated
33 alpha or from associated alpha to separate alpha to BABL_ALPHA_FLOOR. This
34 replaces asymptotic behavior and direct precision loss of color precision when
35 multiplying or dividing by alphas near
0.0 with a consistent symmetric
38 <p>Original intent of data as well as non-asymptotic precision loss is thus
39 maintained when the processing chain might temporarily use the other alpha
43 #define BABL_ALPHA_FLOOR (
1.0/
65536.0)
44 #define BABL_ALPHA_FLOOR_F (
1.0f/
65536.0f)
47 <p>The deviation from not clamping near
0.0 is within the quantization margin
48 of
16bit integer alpha, thus no adaptations for any SIMD or and similar
8bit
49 and
16bit extensions of pixel format conversions are needed.
52 <p>This is the clamping function in use:
</p>
55 babl_epsilon_for_zero_float (float value)
57 if (value
<= BABL_ALPHA_FLOOR_F
&&
58 value
>= -BABL_ALPHA_FLOOR_F)
59 return BABL_ALPHA_FLOOR_F;
64 <p>And an example use of this clamping function that is consistent with babls behavior:
</p>
67 associated_to_separate_rgba (const float *associated_rgba,
70 float alpha = associated_rgba[
3];
71 float reciprocal_alpha =
1.0f / babl_epsilon_for_zero_float (alpha);
73 separate_rgba[
0] = associated_rgba[
0] * reciprocal_alpha;
74 separate_rgba[
1] = associated_rgba[
1] * reciprocal_alpha;
75 separate_rgba[
2] = associated_rgba[
2] * reciprocal_alpha;
76 separate_rgba[
3] = alpha;
81 separate_to_associated_rgba (const float *separate_rgba,
82 float *associated_rgba)
84 float alpha = associated_rgba[
3];
85 float limited_alpha = babl_epsilon_for_zero_float (alpha);
87 associated_rgba[
0] = separate_rgba[
0] * limited_alpha;
88 associated_rgba[
1] = separate_rgba[
1] * limited_alpha;
89 associated_rgba[
2] = separate_rgba[
2] * limited_alpha;
90 associated_rgba[
3] = alpha;
95 <p>For more detils see
<a href='https://gitlab.gnome.org/GNOME/babl/commit/a4d607843d3cab18745d547fc8a46dec51dcea5e'
>the commit message of the most recent refinement
</a> as well as
<a href='https://www.patreon.com/posts/premultiplied-in-
21014115'
>blog post with further background
</a>.
</p>
99 <a href='graphics/index.html'
><img class='BablFish' alt='/babl' title='babl' src='graphics/babl-
48x48.png'
/></a>
103 <div class='graphic'
>
105 <img src='graphics/babl-a4poster.png' alt=' '
/>