... | ... |
@@ -7,6 +7,9 @@ $(AREF): avconv$(EXESUF) tests/data/asynth1.sw |
7 | 7 |
|
8 | 8 |
OBJDIRS += tests/data tests/vsynth1 tests/vsynth2 |
9 | 9 |
|
10 |
+# Required due to missing automatic dependency tracking for HOSTOBJS. |
|
11 |
+tests/rotozoom.o tests/videogen.o: tests/utils.c |
|
12 |
+ |
|
10 | 13 |
tests/vsynth1/00.pgm: tests/videogen$(HOSTEXESUF) | tests/vsynth1 |
11 | 14 |
$(M)./$< 'tests/vsynth1/' |
12 | 15 |
|
... | ... |
@@ -24,6 +24,8 @@ |
24 | 24 |
#include <stdio.h> |
25 | 25 |
#include <inttypes.h> |
26 | 26 |
|
27 |
+#include "utils.c" |
|
28 |
+ |
|
27 | 29 |
#define FIXP (1 << 16) |
28 | 30 |
#define MY_PI 205887 // (M_PI * FIX) |
29 | 31 |
|
... | ... |
@@ -53,130 +55,6 @@ static int64_t int_sin(int64_t a) |
53 | 53 |
return a - int_pow(a, 3) / 6 + int_pow(a, 5) / 120 - int_pow(a, 7) / 5040; |
54 | 54 |
} |
55 | 55 |
|
56 |
-#define SCALEBITS 8 |
|
57 |
-#define ONE_HALF (1 << (SCALEBITS - 1)) |
|
58 |
-#define FIX(x) ((int) ((x) * (1L << SCALEBITS) + 0.5)) |
|
59 |
- |
|
60 |
-static void rgb24_to_yuv420p(unsigned char *lum, unsigned char *cb, |
|
61 |
- unsigned char *cr, unsigned char *src, |
|
62 |
- int width, int height) |
|
63 |
-{ |
|
64 |
- int wrap, wrap3, x, y; |
|
65 |
- int r, g, b, r1, g1, b1; |
|
66 |
- unsigned char *p; |
|
67 |
- |
|
68 |
- wrap = width; |
|
69 |
- wrap3 = width * 3; |
|
70 |
- p = src; |
|
71 |
- for (y = 0; y < height; y += 2) { |
|
72 |
- for (x = 0; x < width; x += 2) { |
|
73 |
- r = p[0]; |
|
74 |
- g = p[1]; |
|
75 |
- b = p[2]; |
|
76 |
- r1 = r; |
|
77 |
- g1 = g; |
|
78 |
- b1 = b; |
|
79 |
- lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
80 |
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
81 |
- r = p[3]; |
|
82 |
- g = p[4]; |
|
83 |
- b = p[5]; |
|
84 |
- r1 += r; |
|
85 |
- g1 += g; |
|
86 |
- b1 += b; |
|
87 |
- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
88 |
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
89 |
- p += wrap3; |
|
90 |
- lum += wrap; |
|
91 |
- |
|
92 |
- r = p[0]; |
|
93 |
- g = p[1]; |
|
94 |
- b = p[2]; |
|
95 |
- r1 += r; |
|
96 |
- g1 += g; |
|
97 |
- b1 += b; |
|
98 |
- lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
99 |
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
100 |
- r = p[3]; |
|
101 |
- g = p[4]; |
|
102 |
- b = p[5]; |
|
103 |
- r1 += r; |
|
104 |
- g1 += g; |
|
105 |
- b1 += b; |
|
106 |
- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
107 |
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
108 |
- |
|
109 |
- cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + |
|
110 |
- FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; |
|
111 |
- cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - |
|
112 |
- FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; |
|
113 |
- |
|
114 |
- cb++; |
|
115 |
- cr++; |
|
116 |
- p += -wrap3 + 2 * 3; |
|
117 |
- lum += -wrap + 2; |
|
118 |
- } |
|
119 |
- p += wrap3; |
|
120 |
- lum += wrap; |
|
121 |
- } |
|
122 |
-} |
|
123 |
- |
|
124 |
-/* cif format */ |
|
125 |
-#define DEFAULT_WIDTH 352 |
|
126 |
-#define DEFAULT_HEIGHT 288 |
|
127 |
-#define DEFAULT_NB_PICT 50 |
|
128 |
- |
|
129 |
-static void pgmyuv_save(const char *filename, int w, int h, |
|
130 |
- unsigned char *rgb_tab) |
|
131 |
-{ |
|
132 |
- FILE *f; |
|
133 |
- int i, h2, w2; |
|
134 |
- unsigned char *cb, *cr; |
|
135 |
- unsigned char *lum_tab, *cb_tab, *cr_tab; |
|
136 |
- |
|
137 |
- lum_tab = malloc(w * h); |
|
138 |
- cb_tab = malloc(w * h / 4); |
|
139 |
- cr_tab = malloc(w * h / 4); |
|
140 |
- |
|
141 |
- rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h); |
|
142 |
- |
|
143 |
- f = fopen(filename, "wb"); |
|
144 |
- fprintf(f, "P5\n%d %d\n%d\n", w, h * 3 / 2, 255); |
|
145 |
- fwrite(lum_tab, 1, w * h, f); |
|
146 |
- h2 = h / 2; |
|
147 |
- w2 = w / 2; |
|
148 |
- cb = cb_tab; |
|
149 |
- cr = cr_tab; |
|
150 |
- for (i = 0; i < h2; i++) { |
|
151 |
- fwrite(cb, 1, w2, f); |
|
152 |
- fwrite(cr, 1, w2, f); |
|
153 |
- cb += w2; |
|
154 |
- cr += w2; |
|
155 |
- } |
|
156 |
- fclose(f); |
|
157 |
- |
|
158 |
- free(lum_tab); |
|
159 |
- free(cb_tab); |
|
160 |
- free(cr_tab); |
|
161 |
-} |
|
162 |
- |
|
163 |
-static unsigned char *rgb_tab; |
|
164 |
-static int width, height, wrap; |
|
165 |
- |
|
166 |
-static void put_pixel(int x, int y, int r, int g, int b) |
|
167 |
-{ |
|
168 |
- unsigned char *p; |
|
169 |
- |
|
170 |
- if (x < 0 || x >= width || |
|
171 |
- y < 0 || y >= height) |
|
172 |
- return; |
|
173 |
- |
|
174 |
- p = rgb_tab + y * wrap + x * 3; |
|
175 |
- p[0] = r; |
|
176 |
- p[1] = g; |
|
177 |
- p[2] = b; |
|
178 |
-} |
|
179 |
- |
|
180 | 56 |
static unsigned char tab_r[256 * 256]; |
181 | 57 |
static unsigned char tab_g[256 * 256]; |
182 | 58 |
static unsigned char tab_b[256 * 256]; |
183 | 59 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,144 @@ |
0 |
+/* |
|
1 |
+ * This file is part of Libav. |
|
2 |
+ * |
|
3 |
+ * Libav is free software; you can redistribute it and/or |
|
4 |
+ * modify it under the terms of the GNU Lesser General Public |
|
5 |
+ * License as published by the Free Software Foundation; either |
|
6 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
7 |
+ * |
|
8 |
+ * Libav is distributed in the hope that it will be useful, |
|
9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 |
+ * Lesser General Public License for more details. |
|
12 |
+ * |
|
13 |
+ * You should have received a copy of the GNU Lesser General Public |
|
14 |
+ * License along with Libav; if not, write to the Free Software |
|
15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 |
+ */ |
|
17 |
+ |
|
18 |
+#include <stdio.h> |
|
19 |
+#include <stdlib.h> |
|
20 |
+ |
|
21 |
+#define SCALEBITS 8 |
|
22 |
+#define ONE_HALF (1 << (SCALEBITS - 1)) |
|
23 |
+#define FIX(x) ((int) ((x) * (1L << SCALEBITS) + 0.5)) |
|
24 |
+ |
|
25 |
+static void rgb24_to_yuv420p(unsigned char *lum, unsigned char *cb, |
|
26 |
+ unsigned char *cr, unsigned char *src, |
|
27 |
+ int width, int height) |
|
28 |
+{ |
|
29 |
+ int wrap, wrap3, x, y; |
|
30 |
+ int r, g, b, r1, g1, b1; |
|
31 |
+ unsigned char *p; |
|
32 |
+ |
|
33 |
+ wrap = width; |
|
34 |
+ wrap3 = width * 3; |
|
35 |
+ p = src; |
|
36 |
+ for (y = 0; y < height; y += 2) { |
|
37 |
+ for (x = 0; x < width; x += 2) { |
|
38 |
+ r = p[0]; |
|
39 |
+ g = p[1]; |
|
40 |
+ b = p[2]; |
|
41 |
+ r1 = r; |
|
42 |
+ g1 = g; |
|
43 |
+ b1 = b; |
|
44 |
+ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
45 |
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
46 |
+ r = p[3]; |
|
47 |
+ g = p[4]; |
|
48 |
+ b = p[5]; |
|
49 |
+ r1 += r; |
|
50 |
+ g1 += g; |
|
51 |
+ b1 += b; |
|
52 |
+ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
53 |
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
54 |
+ p += wrap3; |
|
55 |
+ lum += wrap; |
|
56 |
+ |
|
57 |
+ r = p[0]; |
|
58 |
+ g = p[1]; |
|
59 |
+ b = p[2]; |
|
60 |
+ r1 += r; |
|
61 |
+ g1 += g; |
|
62 |
+ b1 += b; |
|
63 |
+ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
64 |
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
65 |
+ r = p[3]; |
|
66 |
+ g = p[4]; |
|
67 |
+ b = p[5]; |
|
68 |
+ r1 += r; |
|
69 |
+ g1 += g; |
|
70 |
+ b1 += b; |
|
71 |
+ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
72 |
+ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
73 |
+ |
|
74 |
+ cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + |
|
75 |
+ FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; |
|
76 |
+ cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - |
|
77 |
+ FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; |
|
78 |
+ |
|
79 |
+ cb++; |
|
80 |
+ cr++; |
|
81 |
+ p += -wrap3 + 2 * 3; |
|
82 |
+ lum += -wrap + 2; |
|
83 |
+ } |
|
84 |
+ p += wrap3; |
|
85 |
+ lum += wrap; |
|
86 |
+ } |
|
87 |
+} |
|
88 |
+ |
|
89 |
+/* cif format */ |
|
90 |
+#define DEFAULT_WIDTH 352 |
|
91 |
+#define DEFAULT_HEIGHT 288 |
|
92 |
+#define DEFAULT_NB_PICT 50 |
|
93 |
+ |
|
94 |
+static void pgmyuv_save(const char *filename, int w, int h, |
|
95 |
+ unsigned char *rgb_tab) |
|
96 |
+{ |
|
97 |
+ FILE *f; |
|
98 |
+ int i, h2, w2; |
|
99 |
+ unsigned char *cb, *cr; |
|
100 |
+ unsigned char *lum_tab, *cb_tab, *cr_tab; |
|
101 |
+ |
|
102 |
+ lum_tab = malloc(w * h); |
|
103 |
+ cb_tab = malloc(w * h / 4); |
|
104 |
+ cr_tab = malloc(w * h / 4); |
|
105 |
+ |
|
106 |
+ rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h); |
|
107 |
+ |
|
108 |
+ f = fopen(filename, "wb"); |
|
109 |
+ fprintf(f, "P5\n%d %d\n%d\n", w, h * 3 / 2, 255); |
|
110 |
+ fwrite(lum_tab, 1, w * h, f); |
|
111 |
+ h2 = h / 2; |
|
112 |
+ w2 = w / 2; |
|
113 |
+ cb = cb_tab; |
|
114 |
+ cr = cr_tab; |
|
115 |
+ for (i = 0; i < h2; i++) { |
|
116 |
+ fwrite(cb, 1, w2, f); |
|
117 |
+ fwrite(cr, 1, w2, f); |
|
118 |
+ cb += w2; |
|
119 |
+ cr += w2; |
|
120 |
+ } |
|
121 |
+ fclose(f); |
|
122 |
+ |
|
123 |
+ free(lum_tab); |
|
124 |
+ free(cb_tab); |
|
125 |
+ free(cr_tab); |
|
126 |
+} |
|
127 |
+ |
|
128 |
+static unsigned char *rgb_tab; |
|
129 |
+static int width, height, wrap; |
|
130 |
+ |
|
131 |
+static void put_pixel(int x, int y, int r, int g, int b) |
|
132 |
+{ |
|
133 |
+ unsigned char *p; |
|
134 |
+ |
|
135 |
+ if (x < 0 || x >= width || |
|
136 |
+ y < 0 || y >= height) |
|
137 |
+ return; |
|
138 |
+ |
|
139 |
+ p = rgb_tab + y * wrap + x * 3; |
|
140 |
+ p[0] = r; |
|
141 |
+ p[1] = g; |
|
142 |
+ p[2] = b; |
|
143 |
+} |
... | ... |
@@ -25,134 +25,7 @@ |
25 | 25 |
#include <stdint.h> |
26 | 26 |
#include <stdio.h> |
27 | 27 |
|
28 |
-#define SCALEBITS 8 |
|
29 |
-#define ONE_HALF (1 << (SCALEBITS - 1)) |
|
30 |
-#define FIX(x) ((int) ((x) * (1L << SCALEBITS) + 0.5)) |
|
31 |
- |
|
32 |
-static void rgb24_to_yuv420p(uint8_t *lum, uint8_t *cb, uint8_t *cr, |
|
33 |
- uint8_t *src, int width, int height) |
|
34 |
-{ |
|
35 |
- int wrap, wrap3, x, y; |
|
36 |
- int r, g, b, r1, g1, b1; |
|
37 |
- uint8_t *p; |
|
38 |
- |
|
39 |
- wrap = width; |
|
40 |
- wrap3 = width * 3; |
|
41 |
- p = src; |
|
42 |
- for (y = 0; y < height; y += 2) { |
|
43 |
- for (x = 0; x < width; x += 2) { |
|
44 |
- r = p[0]; |
|
45 |
- g = p[1]; |
|
46 |
- b = p[2]; |
|
47 |
- r1 = r; |
|
48 |
- g1 = g; |
|
49 |
- b1 = b; |
|
50 |
- lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
51 |
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
52 |
- r = p[3]; |
|
53 |
- g = p[4]; |
|
54 |
- b = p[5]; |
|
55 |
- r1 += r; |
|
56 |
- g1 += g; |
|
57 |
- b1 += b; |
|
58 |
- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
59 |
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
60 |
- p += wrap3; |
|
61 |
- lum += wrap; |
|
62 |
- |
|
63 |
- r = p[0]; |
|
64 |
- g = p[1]; |
|
65 |
- b = p[2]; |
|
66 |
- r1 += r; |
|
67 |
- g1 += g; |
|
68 |
- b1 += b; |
|
69 |
- lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
70 |
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
71 |
- r = p[3]; |
|
72 |
- g = p[4]; |
|
73 |
- b = p[5]; |
|
74 |
- r1 += r; |
|
75 |
- g1 += g; |
|
76 |
- b1 += b; |
|
77 |
- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + |
|
78 |
- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; |
|
79 |
- |
|
80 |
- cb[0] = 128 + ((- FIX(0.16874) * r1 - |
|
81 |
- FIX(0.33126) * g1 + |
|
82 |
- FIX(0.50000) * b1 + |
|
83 |
- 4 * ONE_HALF - 1) |
|
84 |
- >> (SCALEBITS + 2)); |
|
85 |
- cr[0] = 128 + ((FIX(0.50000) * r1 - |
|
86 |
- FIX(0.41869) * g1 - |
|
87 |
- FIX(0.08131) * b1 + |
|
88 |
- 4 * ONE_HALF - 1) |
|
89 |
- >> (SCALEBITS + 2)); |
|
90 |
- |
|
91 |
- cb++; |
|
92 |
- cr++; |
|
93 |
- p += -wrap3 + 2 * 3; |
|
94 |
- lum += -wrap + 2; |
|
95 |
- } |
|
96 |
- p += wrap3; |
|
97 |
- lum += wrap; |
|
98 |
- } |
|
99 |
-} |
|
100 |
- |
|
101 |
-/* cif format */ |
|
102 |
-#define DEFAULT_WIDTH 352 |
|
103 |
-#define DEFAULT_HEIGHT 288 |
|
104 |
-#define DEFAULT_NB_PICT 50 /* 2 seconds */ |
|
105 |
- |
|
106 |
-static void pgmyuv_save(const char *filename, int w, int h, |
|
107 |
- unsigned char *rgb_tab) |
|
108 |
-{ |
|
109 |
- FILE *f; |
|
110 |
- int i, h2, w2; |
|
111 |
- unsigned char *cb, *cr; |
|
112 |
- unsigned char *lum_tab, *cb_tab, *cr_tab; |
|
113 |
- |
|
114 |
- lum_tab = malloc(w * h); |
|
115 |
- cb_tab = malloc((w * h) / 4); |
|
116 |
- cr_tab = malloc((w * h) / 4); |
|
117 |
- |
|
118 |
- rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h); |
|
119 |
- |
|
120 |
- f = fopen(filename, "wb"); |
|
121 |
- fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255); |
|
122 |
- fwrite(lum_tab, 1, w * h, f); |
|
123 |
- h2 = h / 2; |
|
124 |
- w2 = w / 2; |
|
125 |
- cb = cb_tab; |
|
126 |
- cr = cr_tab; |
|
127 |
- for (i = 0; i < h2; i++) { |
|
128 |
- fwrite(cb, 1, w2, f); |
|
129 |
- fwrite(cr, 1, w2, f); |
|
130 |
- cb += w2; |
|
131 |
- cr += w2; |
|
132 |
- } |
|
133 |
- fclose(f); |
|
134 |
- |
|
135 |
- free(lum_tab); |
|
136 |
- free(cb_tab); |
|
137 |
- free(cr_tab); |
|
138 |
-} |
|
139 |
- |
|
140 |
-static unsigned char *rgb_tab; |
|
141 |
-static int width, height, wrap; |
|
142 |
- |
|
143 |
-static void put_pixel(int x, int y, int r, int g, int b) |
|
144 |
-{ |
|
145 |
- unsigned char *p; |
|
146 |
- |
|
147 |
- if (x < 0 || x >= width || |
|
148 |
- y < 0 || y >= height) |
|
149 |
- return; |
|
150 |
- |
|
151 |
- p = rgb_tab + y * wrap + x * 3; |
|
152 |
- p[0] = r; |
|
153 |
- p[1] = g; |
|
154 |
- p[2] = b; |
|
155 |
-} |
|
28 |
+#include "utils.c" |
|
156 | 29 |
|
157 | 30 |
static unsigned int myrnd(unsigned int *seed_ptr, int n) |
158 | 31 |
{ |