15
return 1.055 * $c ** (1.0/2.4) - 0.055;
29
return (($c + 0.055) / 1.055) ** 2.4
34
for my $linear (0 .. 4095)
36
my $srgb = int(linear_to_srgb($linear / 4095.0) * 255.0 + 0.5);
37
push @linear_to_srgb, $srgb;
41
for my $srgb (0 .. 255)
43
my $linear = int(srgb_to_linear($srgb / 255.0) * 65535.0 + 0.5);
44
push @srgb_to_linear, $linear;
47
# Ensure that we have a lossless sRGB and back conversion loop.
48
# some of the darkest shades need a little bias -- maximum is just
49
# 5 increments out of 16. This gives us useful property with
50
# least amount of error in the sRGB-to-linear table, and keeps the actual
51
# table lookup in the other direction as simple as possible.
52
for my $srgb (0 .. $#srgb_to_linear)
57
my $linear = $srgb_to_linear[$srgb];
58
my $srgb_lossy = $linear_to_srgb[$linear >> 4];
59
last if $srgb == $srgb_lossy;
61
# Add slight bias to this component until it rounds correctly
62
$srgb_to_linear[$srgb] ++;
65
die "Too many adds at $srgb" if $add > 5;
69
/* WARNING: This file is generated by $0.
70
* Please edit that file instead of this one.
79
#include "pixman-private.h"
83
print "const uint8_t linear_to_srgb[" . @linear_to_srgb . "] =\n";
85
for my $linear (0 .. $#linear_to_srgb)
87
if (($linear % 10) == 0)
91
print sprintf("%d, ", $linear_to_srgb[$linear]);
92
if (($linear % 10) == 9)
100
print "const uint16_t srgb_to_linear[" . @srgb_to_linear . "] =\n";
102
for my $srgb (0 .. $#srgb_to_linear)
104
if (($srgb % 10) == 0)
108
print sprintf("%d, ", $srgb_to_linear[$srgb]);
109
if (($srgb % 10) == 9)