4 def gamma_table(start
=0, stop
=256, gamma
=0.45):
7 for point
in range(spread
):
8 p1
= float(point
) / spread
10 out
= int(p1
* spread
) + start
16 lut
[0:0] = [lut
[0]] * start
18 lut
.extend([lut
[-1]] * (256 - stop
))
23 def srgb_to_linear_table():
26 for point
in range(256):
31 p
= ((p
+ a
) / (1 + a
)) ** 2.4
32 lut
.append(int(p
* 255))
35 def linear_to_srgb_table():
38 for point
in range(256):
43 p
= (1 + a
) * (p
** (1 / 2.4)) - a
44 lut
.append(int(p
* 255))
48 def cformat(table
, name
="SOME_TABLE", wrap
=75, unused
=True):
54 outs
.extend(("static guint8 %s [%s] = {" % (name
, len(table
)),
57 if len(outs
[-1]) >= wrap
:
59 outs
.append(' %s' % v
)
61 outs
[-1] += ', %s' % v
67 print "/* Gamma corrected lookup tables for inverting video */"
68 print "/* generated by '%s'. DO NOT EDIT */" % __file__
69 print '#include "gstsparrow.h"'
70 cformat(reversed(gamma_table(gamma
=2.0)), "sparrow_rgb_gamma_full_range_REVERSE")
71 cformat(reversed(gamma_table(16, 236)), "sparrow_rgb_gamma_headroom_REVERSE")