OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 from __future__ import print_function | 4 from __future__ import print_function |
5 from math import * | 5 from math import * |
6 | 6 |
7 | 7 |
8 COPYRIGHT = '''/* | 8 COPYRIGHT = '''/* |
9 * Copyright 2013 Google Inc. | 9 * Copyright 2013 Google Inc. |
10 * | 10 * |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 # From Daly 1993 | 54 # From Daly 1993 |
55 def visual_mask(contrast): | 55 def visual_mask(contrast): |
56 x = pow(392.498 * contrast, 0.7) | 56 x = pow(392.498 * contrast, 0.7) |
57 x = pow(0.0153 * x, 4.0) | 57 x = pow(0.0153 * x, 4.0) |
58 return pow(1.0 + x, 0.25) | 58 return pow(1.0 + x, 0.25) |
59 | 59 |
60 | 60 |
61 # float gCubeRootTable[] | 61 # float gCubeRootTable[] |
62 CUBE_ROOT_ACCESS_FUNCTION = ''' | 62 CUBE_ROOT_ACCESS_FUNCTION = ''' |
63 float get_cube_root(float value) { | 63 static float get_cube_root(float value) { |
64 SkASSERT(value >= 0.0f); | 64 SkASSERT(value >= 0.0f); |
65 SkASSERT(value * 1023.0f < 1024.0f); | 65 SkASSERT(value * 1023.0f < 1024.0f); |
66 return gCubeRootTable[(int)(value * 1023.0f)]; | 66 return gCubeRootTable[(int)(value * 1023.0f)]; |
67 } | 67 } |
68 ''' | 68 ''' |
69 def generate_cube_root_table(stream): | 69 def generate_cube_root_table(stream): |
70 print('static float gCubeRootTable[] = {', end='', file=stream) | 70 print('static float gCubeRootTable[] = {', end='', file=stream) |
71 for i in range(1024): | 71 for i in range(1024): |
72 if i % 6 == 0: | 72 if i % 6 == 0: |
73 print('\n ', end='', file=stream) | 73 print('\n ', end='', file=stream) |
74 print("%.10f" % pow(i / 1024.0, 1.0 / 3.0), end='f,', file=stream) | 74 print("%.10f" % pow(i / 1024.0, 1.0 / 3.0), end='f,', file=stream) |
75 print('\n};', end='', file=stream) | 75 print('\n};', end='', file=stream) |
76 print(CUBE_ROOT_ACCESS_FUNCTION, file=stream) | 76 print(CUBE_ROOT_ACCESS_FUNCTION, file=stream) |
77 | 77 |
78 | 78 |
79 # float gGammaTable[] | 79 # float gGammaTable[] |
80 GAMMA_ACCESS_FUNCTION = ''' | 80 GAMMA_ACCESS_FUNCTION = ''' |
81 float get_gamma(unsigned char value) { | 81 static float get_gamma(unsigned char value) { |
82 return gGammaTable[value]; | 82 return gGammaTable[value]; |
83 } | 83 } |
84 ''' | 84 ''' |
85 def generate_gamma_table(stream): | 85 def generate_gamma_table(stream): |
86 print('static float gGammaTable[] = {', end='', file=stream) | 86 print('static float gGammaTable[] = {', end='', file=stream) |
87 for i in range(256): | 87 for i in range(256): |
88 if i % 6 == 0: | 88 if i % 6 == 0: |
89 print('\n ', end='', file=stream) | 89 print('\n ', end='', file=stream) |
90 print("%.10f" % pow(i / 255.0, 2.2), end='f,', file=stream) | 90 print("%.10f" % pow(i / 255.0, 2.2), end='f,', file=stream) |
91 print('\n};', end='', file=stream) | 91 print('\n};', end='', file=stream) |
92 print(GAMMA_ACCESS_FUNCTION, file=stream) | 92 print(GAMMA_ACCESS_FUNCTION, file=stream) |
93 | 93 |
94 | 94 |
95 # float gTVITable[] | 95 # float gTVITable[] |
96 TVI_ACCESS_FUNCTION = ''' | 96 TVI_ACCESS_FUNCTION = ''' |
97 float get_threshold_vs_intensity(float value) { | 97 static float get_threshold_vs_intensity(float value) { |
98 SkASSERT(value >= 0.0f); | 98 SkASSERT(value >= 0.0f); |
99 SkASSERT(value < 100.0f); | 99 SkASSERT(value < 100.0f); |
100 return gTVITable[(int)(value * 100.0f)]; | 100 return gTVITable[(int)(value * 100.0f)]; |
101 } | 101 } |
102 ''' | 102 ''' |
103 def generate_tvi_table(stream): | 103 def generate_tvi_table(stream): |
104 print('static float gTVITable[] = {', end='', file=stream) | 104 print('static float gTVITable[] = {', end='', file=stream) |
105 for i in range(10000): | 105 for i in range(10000): |
106 if i % 6 == 0: | 106 if i % 6 == 0: |
107 print('\n ', end='', file=stream) | 107 print('\n ', end='', file=stream) |
108 print("%.10f" % threshold_vs_intensity(i / 100.0), end='f,', file=stream
) | 108 print("%.10f" % threshold_vs_intensity(i / 100.0), end='f,', file=stream
) |
109 print('\n};', end='', file=stream) | 109 print('\n};', end='', file=stream) |
110 print(TVI_ACCESS_FUNCTION, file=stream) | 110 print(TVI_ACCESS_FUNCTION, file=stream) |
111 | 111 |
112 | 112 |
113 # float gVisualMaskTable[] | 113 # float gVisualMaskTable[] |
114 VISUAL_MASK_DOMAIN = 4000 | 114 VISUAL_MASK_DOMAIN = 4000 |
115 VISUAL_MASK_ACCESS_FUNCTION = ''' | 115 VISUAL_MASK_ACCESS_FUNCTION = ''' |
116 float get_visual_mask(float value) {{ | 116 static float get_visual_mask(float value) {{ |
117 SkASSERT(value >= 0.0f); | 117 SkASSERT(value >= 0.0f); |
118 SkASSERT(value < {}.0f); | 118 SkASSERT(value < {}.0f); |
119 return gVisualMaskTable[(int)value]; | 119 return gVisualMaskTable[(int)value]; |
120 }}''' | 120 }}''' |
121 def generate_visual_mask_table(stream): | 121 def generate_visual_mask_table(stream): |
122 print('static float gVisualMaskTable[] = {', end='', file=stream) | 122 print('static float gVisualMaskTable[] = {', end='', file=stream) |
123 for i in range(VISUAL_MASK_DOMAIN): | 123 for i in range(VISUAL_MASK_DOMAIN): |
124 if i % 6 == 0: | 124 if i % 6 == 0: |
125 print('\n ', end='', file=stream) | 125 print('\n ', end='', file=stream) |
126 print("%.10f" % visual_mask(i), end='f,', file=stream) | 126 print("%.10f" % visual_mask(i), end='f,', file=stream) |
(...skipping 13 matching lines...) Expand all Loading... |
140 | 140 |
141 | 141 |
142 def main(): | 142 def main(): |
143 pmetric_util_out = open('SkPMetricUtil_generated.h', 'wb') | 143 pmetric_util_out = open('SkPMetricUtil_generated.h', 'wb') |
144 generate_lookup_tables(pmetric_util_out) | 144 generate_lookup_tables(pmetric_util_out) |
145 pmetric_util_out.close() | 145 pmetric_util_out.close() |
146 | 146 |
147 | 147 |
148 if __name__ == '__main__': | 148 if __name__ == '__main__': |
149 main() | 149 main() |
OLD | NEW |