File: UnifiedAlpha-static.html

package info (click to toggle)
babl 1%3A0.1.118-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,432 kB
  • sloc: ansic: 47,361; python: 180; ruby: 90; sh: 55; makefile: 24
file content (110 lines) | stat: -rw-r--r-- 3,483 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<!-- The babl webpage is partially autogenerated
-->
<html>
  <head>
    <title>Unified Alpha - babl</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <link rel="icon" href="graphics/babl-16x16.png" type="image/png" />
    <link rel="shortcut icon" href="graphics/babl-16x16.png" type="image/png" />
    <style type='text/css'>
       @import url(babl.css);
    </style>
  </head>
  <body>

    <div class='print'>
      <div class='print_title'>
        <h1>Babl</h1>
      </div>
    </div>
<!--TOC-->

    <div class='paper'>
  <div class='content'>

  <h2>Symmetric transformations for floating point alpha</h2>


  <p> 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
replaces asymptotic behavior and direct precision loss of color precision when
multiplying or dividing by alphas near 0.0 with a consistent symmetric
transformation.</p>

<p>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.</p>

<pre>
    #define BABL_ALPHA_FLOOR    (1.0/65536.0)
    #define BABL_ALPHA_FLOOR_F  (1.0f/65536.0f)
</pre>

<p>The deviation from not clamping near 0.0 is within the quantization margin
of 16bit integer alpha, thus no adaptations for any SIMD or and similar 8bit
and 16bit extensions of pixel format conversions are needed.
  </p>

   <p>This is the clamping function in use:</p>
<pre>
static inline float
babl_epsilon_for_zero_float (float value)
{
 if (value &lt;= BABL_ALPHA_FLOOR_F &amp;&amp;
     value &gt;= -BABL_ALPHA_FLOOR_F)
   return BABL_ALPHA_FLOOR_F;
 else
   return value;
}
</pre>
<p>And an example use of this clamping function that is consistent with babls behavior:</p>
<pre>
static inline void
associated_to_separate_rgba (const float *associated_rgba,
                                   float *separate_rgba)
{
  float alpha = associated_rgba[3];
  float reciprocal_alpha = 1.0f / babl_epsilon_for_zero_float (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;
}


static inline void
separate_to_associated_rgba (const float *separate_rgba,
                                   float *associated_rgba)
{
  float alpha = associated_rgba[3];
  float limited_alpha = babl_epsilon_for_zero_float (alpha);

  associated_rgba[0] = separate_rgba[0] * limited_alpha;
  associated_rgba[1] = separate_rgba[1] * limited_alpha;
  associated_rgba[2] = separate_rgba[2] * limited_alpha;
  associated_rgba[3] = alpha;
}
</pre>


<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>



  <a href='graphics/index.html'><img class='BablFish' alt='/babl' title='babl' src='graphics/babl-48x48.png'/></a>
  </div>
  </div>

    <div class='graphic'>
      <div class='print'>
        <img src='graphics/babl-a4poster.png' alt=' '/>
      </div>
    </div>

  </body>
</html>