3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / media / plugins / ffmpeg / gen_lookup.cpp
blob4972db9567fe7d05bd1cdd05f58533250db6401e
1 /*
2 ** Copyright 2004, Marcus Overhagen. All rights reserved.
3 ** Distributed under the terms of the MIT license.
4 **
5 ** This file generates the lookup tables used by image
6 ** format conversion from planar YCbCr420 format to
7 ** linear RGB32 format in file gfx_conv_c_lookup.cpp
8 */
10 #include <strings.h>
11 #include <stdio.h>
13 double precision = 32768.0;
14 int shift = 15;
17 R = 1.164(Y ­ 16) + 1.596(Cr ­ 128)
18 G = 1.164(Y - 16) ­ 0.813(Cr ­ 128) ­ 0.392(Cb ­ 128)
19 B = 1.164(Y ­ 16) + 2.017(Cb ­ 128)
22 int main()
24 printf("const int32 Cb_Gtab[256] = {\n\t");
25 for (int i = 0; i < 256; i++) {
26 int Cr_R = (- 128 + i) * 1.596 * precision + 0.5;
27 int Cr_G = (- 128 + i) * -0.813 * precision + 0.5;
28 int Cb_G = (- 128 + i) * -0.392 * precision + 0.5;
29 int Cb_B = (- 128 + i) * 2.017 * precision + 0.5;
30 printf("%d, ", Cb_G);
31 if ((i % 10) == 9)
32 printf("\n\t");
34 printf("\n};\n\n");
36 printf("const int32 Cb_Btab[256] = {\n\t");
37 for (int i = 0; i < 256; i++) {
38 int Cr_R = (- 128 + i) * 1.596 * precision + 0.5;
39 int Cr_G = (- 128 + i) * -0.813 * precision + 0.5;
40 int Cb_G = (- 128 + i) * -0.392 * precision + 0.5;
41 int Cb_B = (- 128 + i) * 2.017 * precision + 0.5;
42 printf("%d, ", Cb_B);
43 if ((i % 10) == 9)
44 printf("\n\t");
46 printf("\n};\n\n");
48 printf("const int32 Cr_Rtab[256] = {\n\t");
49 for (int i = 0; i < 256; i++) {
50 int Cr_R = (- 128 + i) * 1.596 * precision + 0.5;
51 int Cr_G = (- 128 + i) * -0.813 * precision + 0.5;
52 int Cb_G = (- 128 + i) * -0.392 * precision + 0.5;
53 int Cb_B = (- 128 + i) * 2.017 * precision + 0.5;
54 printf("%d, ", Cr_R);
55 if ((i % 10) == 9)
56 printf("\n\t");
58 printf("\n};\n\n");
60 printf("const int32 Cr_Gtab[256] = {\n\t");
61 for (int i = 0; i < 256; i++) {
62 int Cr_R = (- 128 + i) * 1.596 * precision + 0.5;
63 int Cr_G = (- 128 + i) * -0.813 * precision + 0.5;
64 int Cb_G = (- 128 + i) * -0.392 * precision + 0.5;
65 int Cb_B = (- 128 + i) * 2.017 * precision + 0.5;
66 printf("%d, ", Cr_G);
67 if ((i % 10) == 9)
68 printf("\n\t");
70 printf("\n};\n\n");
72 printf("const int32 Ytab[256] = {\n\t");
73 for (int i = 0; i < 256; i++) {
74 int Y = (i - 16) * 1.164 * precision + 0.5;
75 printf("%d, ", Y);
76 if ((i % 10) == 9)
77 printf("\n\t");
79 printf("\n};\n\n");
81 int Ymin = (0 - 16) * 1.164 * precision + 0.5;
82 int Ymax = (255 - 16) * 1.164 * precision + 0.5;
84 int Cr_Rmin = (- 128 + 0) * 1.596 * precision + 0.5;
85 int Cr_Rmax = (- 128 + 255) * 1.596 * precision + 0.5;
86 int Cr_Gmin = (- 128 + 255) * -0.813 * precision + 0.5;
87 int Cr_Gmax = (- 128 + 0) * -0.813 * precision + 0.5;
88 int Cb_Gmin = (- 128 + 255) * -0.392 * precision + 0.5;
89 int Cb_Gmax = (- 128 + 0) * -0.392 * precision + 0.5;
90 int Cb_Bmin = (- 128 + 0) * 2.017 * precision + 0.5;
91 int Cb_Bmax = (- 128 + 255) * 2.017 * precision + 0.5;
93 printf("Cr_Rmin %d\n", Cr_Rmin);
94 printf("Cr_Rmax %d\n", Cr_Rmax);
95 printf("Cr_Gmin %d\n", Cr_Gmin);
96 printf("Cr_Gmax %d\n", Cr_Gmax);
97 printf("Cb_Gmin %d\n", Cb_Gmin);
98 printf("Cb_Gmax %d\n", Cb_Gmax);
99 printf("Cb_Bmin %d\n", Cb_Bmin);
100 printf("Cb_Bmax %d\n", Cb_Bmax);
102 int Rmax = (Ymax + Cr_Rmax) >> shift;
103 int Rmin = (Ymin + Cr_Rmin) >> shift;
104 int Gmax = (Ymax + Cr_Gmax + Cb_Gmax) >> shift;
105 int Gmin = (Ymin + Cr_Gmin + Cb_Gmin) >> shift;
106 int Bmax = (Ymax + Cb_Bmax) >> shift;
107 int Bmin = (Ymin + Cb_Bmin) >> shift;
109 printf("Rmax %d\n", Rmax);
110 printf("Rmin %d\n", Rmin);
111 printf("Gmax %d\n", Gmax);
112 printf("Gmin %d\n", Gmin);
113 printf("Bmax %d\n", Bmax);
114 printf("Bmin %d\n", Bmin);
116 int num_Rneg = (Rmin < 0) ? -Rmin : 0;
117 int num_Rpos = (Rmax > 255) ? Rmax - 255 : 0;
118 int num_Rent = num_Rneg + 256 + num_Rpos;
120 printf("num_Rneg %d\n", num_Rneg);
121 printf("num_Rpos %d\n", num_Rpos);
122 printf("num_Rent %d\n", num_Rent);
124 printf("const uint32 Rsat[%d] = {\n\t", num_Rent);
125 for (int i = 0; i < num_Rneg; i++) {
126 printf("0x000000, ");
127 if ((i % 10) == 9)
128 printf("\n\t");
130 printf("\n\t");
131 for (int i = 0; i < 256; i++) {
132 printf("0x%06x, ", i << 16);
133 if ((i % 10) == 9)
134 printf("\n\t");
136 printf("\n\t");
137 for (int i = 0; i < num_Rpos; i++) {
138 printf("0x%06x, ", 255 << 16);
139 if ((i % 10) == 9)
140 printf("\n\t");
142 printf("\n};\n");
143 printf("const uint32 *Rtab = &Rsat[%d];\n\n", num_Rneg);
147 int num_Gneg = (Gmin < 0) ? -Gmin : 0;
148 int num_Gpos = (Gmax > 255) ? Gmax - 255 : 0;
149 int num_Gent = num_Gneg + 256 + num_Gpos;
151 printf("num_Gneg %d\n", num_Gneg);
152 printf("num_Gpos %d\n", num_Gpos);
153 printf("num_Gent %d\n", num_Gent);
155 printf("const uint32 Gsat[%d] = {\n\t", num_Gent);
156 for (int i = 0; i < num_Gneg; i++) {
157 printf("0x000000, ");
158 if ((i % 10) == 9)
159 printf("\n\t");
161 printf("\n\t");
162 for (int i = 0; i < 256; i++) {
163 printf("0x%06x, ", i << 8);
164 if ((i % 10) == 9)
165 printf("\n\t");
167 printf("\n\t");
168 for (int i = 0; i < num_Gpos; i++) {
169 printf("0x%06x, ", 255 << 8);
170 if ((i % 10) == 9)
171 printf("\n\t");
173 printf("\n};\n");
174 printf("const uint32 *Gtab = &Gsat[%d];\n\n", num_Gneg);
177 int num_Bneg = (Bmin < 0) ? -Bmin : 0;
178 int num_Bpos = (Bmax > 255) ? Bmax - 255 : 0;
179 int num_Bent = num_Bneg + 256 + num_Bpos;
181 printf("num_Bneg %d\n", num_Bneg);
182 printf("num_Bpos %d\n", num_Bpos);
183 printf("num_Bent %d\n", num_Bent);
185 printf("const uint32 Bsat[%d] = {\n\t", num_Bent);
186 for (int i = 0; i < num_Bneg; i++) {
187 printf("0x000000, ");
188 if ((i % 10) == 9)
189 printf("\n\t");
191 printf("\n\t");
192 for (int i = 0; i < 256; i++) {
193 printf("0x%06x, ", i << 0);
194 if ((i % 10) == 9)
195 printf("\n\t");
197 printf("\n\t");
198 for (int i = 0; i < num_Bpos; i++) {
199 printf("0x%06x, ", 255 << 0);
200 if ((i % 10) == 9)
201 printf("\n\t");
203 printf("\n};\n");
204 printf("const uint32 *Btab = &Bsat[%d];\n\n", num_Bneg);
206 return 0;