1204
|
1 /*
|
|
2 * Templates for image convertion routines
|
|
3 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
|
|
4 *
|
|
5 * This library is free software; you can redistribute it and/or
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
7 * License as published by the Free Software Foundation; either
|
|
8 * version 2 of the License, or (at your option) any later version.
|
|
9 *
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 * Lesser General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
16 * License along with this library; if not, write to the Free Software
|
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 */
|
|
19
|
|
20 #ifndef RGB_OUT
|
|
21 #define RGB_OUT(d, r, g, b) RGBA_OUT(d, r, g, b, 0xff)
|
|
22 #endif
|
|
23
|
|
24 static void glue(yuv420p_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
|
|
25 int width, int height)
|
|
26 {
|
|
27 uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2;
|
|
28 int w, y, cb, cr, r_add, g_add, b_add, width2;
|
|
29 uint8_t *cm = cropTbl + MAX_NEG_CROP;
|
|
30 unsigned int r, g, b;
|
|
31
|
|
32 d = dst->data[0];
|
|
33 y1_ptr = src->data[0];
|
|
34 cb_ptr = src->data[1];
|
|
35 cr_ptr = src->data[2];
|
|
36 width2 = (width + 1) >> 1;
|
|
37 for(;height >= 2; height -= 2) {
|
|
38 d1 = d;
|
|
39 d2 = d + dst->linesize[0];
|
|
40 y2_ptr = y1_ptr + src->linesize[0];
|
|
41 for(w = width; w >= 2; w -= 2) {
|
|
42 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
|
|
43 /* output 4 pixels */
|
|
44 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
|
|
45 RGB_OUT(d1, r, g, b);
|
|
46
|
|
47 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
|
|
48 RGB_OUT(d1 + BPP, r, g, b);
|
|
49
|
|
50 YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
|
|
51 RGB_OUT(d2, r, g, b);
|
|
52
|
|
53 YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[1]);
|
|
54 RGB_OUT(d2 + BPP, r, g, b);
|
|
55
|
|
56 d1 += 2 * BPP;
|
|
57 d2 += 2 * BPP;
|
|
58
|
|
59 y1_ptr += 2;
|
|
60 y2_ptr += 2;
|
|
61 cb_ptr++;
|
|
62 cr_ptr++;
|
|
63 }
|
|
64 /* handle odd width */
|
|
65 if (w) {
|
|
66 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
|
|
67 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
|
|
68 RGB_OUT(d1, r, g, b);
|
|
69
|
|
70 YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
|
|
71 RGB_OUT(d2, r, g, b);
|
|
72 d1 += BPP;
|
|
73 d2 += BPP;
|
|
74 y1_ptr++;
|
|
75 y2_ptr++;
|
|
76 cb_ptr++;
|
|
77 cr_ptr++;
|
|
78 }
|
|
79 d += 2 * dst->linesize[0];
|
|
80 y1_ptr += 2 * src->linesize[0] - width;
|
|
81 cb_ptr += src->linesize[1] - width2;
|
|
82 cr_ptr += src->linesize[2] - width2;
|
|
83 }
|
|
84 /* handle odd height */
|
|
85 if (height) {
|
|
86 d1 = d;
|
|
87 for(w = width; w >= 2; w -= 2) {
|
|
88 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
|
|
89 /* output 2 pixels */
|
|
90 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
|
|
91 RGB_OUT(d1, r, g, b);
|
|
92
|
|
93 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
|
|
94 RGB_OUT(d1 + BPP, r, g, b);
|
|
95
|
|
96 d1 += 2 * BPP;
|
|
97
|
|
98 y1_ptr += 2;
|
|
99 cb_ptr++;
|
|
100 cr_ptr++;
|
|
101 }
|
|
102 /* handle width */
|
|
103 if (w) {
|
|
104 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
|
|
105 /* output 2 pixels */
|
|
106 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
|
|
107 RGB_OUT(d1, r, g, b);
|
|
108 d1 += BPP;
|
|
109
|
|
110 y1_ptr++;
|
|
111 cb_ptr++;
|
|
112 cr_ptr++;
|
|
113 }
|
|
114 }
|
|
115 }
|
|
116
|
|
117 static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
|
|
118 int width, int height)
|
|
119 {
|
|
120 uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2;
|
|
121 int w, y, cb, cr, r_add, g_add, b_add, width2;
|
|
122 uint8_t *cm = cropTbl + MAX_NEG_CROP;
|
|
123 unsigned int r, g, b;
|
|
124
|
|
125 d = dst->data[0];
|
|
126 y1_ptr = src->data[0];
|
|
127 cb_ptr = src->data[1];
|
|
128 cr_ptr = src->data[2];
|
|
129 width2 = (width + 1) >> 1;
|
|
130 for(;height >= 2; height -= 2) {
|
|
131 d1 = d;
|
|
132 d2 = d + dst->linesize[0];
|
|
133 y2_ptr = y1_ptr + src->linesize[0];
|
|
134 for(w = width; w >= 2; w -= 2) {
|
|
135 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
|
|
136 /* output 4 pixels */
|
|
137 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
|
|
138 RGB_OUT(d1, r, g, b);
|
|
139
|
|
140 YUV_TO_RGB2(r, g, b, y1_ptr[1]);
|
|
141 RGB_OUT(d1 + BPP, r, g, b);
|
|
142
|
|
143 YUV_TO_RGB2(r, g, b, y2_ptr[0]);
|
|
144 RGB_OUT(d2, r, g, b);
|
|
145
|
|
146 YUV_TO_RGB2(r, g, b, y2_ptr[1]);
|
|
147 RGB_OUT(d2 + BPP, r, g, b);
|
|
148
|
|
149 d1 += 2 * BPP;
|
|
150 d2 += 2 * BPP;
|
|
151
|
|
152 y1_ptr += 2;
|
|
153 y2_ptr += 2;
|
|
154 cb_ptr++;
|
|
155 cr_ptr++;
|
|
156 }
|
|
157 /* handle odd width */
|
|
158 if (w) {
|
|
159 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
|
|
160 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
|
|
161 RGB_OUT(d1, r, g, b);
|
|
162
|
|
163 YUV_TO_RGB2(r, g, b, y2_ptr[0]);
|
|
164 RGB_OUT(d2, r, g, b);
|
|
165 d1 += BPP;
|
|
166 d2 += BPP;
|
|
167 y1_ptr++;
|
|
168 y2_ptr++;
|
|
169 cb_ptr++;
|
|
170 cr_ptr++;
|
|
171 }
|
|
172 d += 2 * dst->linesize[0];
|
|
173 y1_ptr += 2 * src->linesize[0] - width;
|
|
174 cb_ptr += src->linesize[1] - width2;
|
|
175 cr_ptr += src->linesize[2] - width2;
|
|
176 }
|
|
177 /* handle odd height */
|
|
178 if (height) {
|
|
179 d1 = d;
|
|
180 for(w = width; w >= 2; w -= 2) {
|
|
181 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
|
|
182 /* output 2 pixels */
|
|
183 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
|
|
184 RGB_OUT(d1, r, g, b);
|
|
185
|
|
186 YUV_TO_RGB2(r, g, b, y1_ptr[1]);
|
|
187 RGB_OUT(d1 + BPP, r, g, b);
|
|
188
|
|
189 d1 += 2 * BPP;
|
|
190
|
|
191 y1_ptr += 2;
|
|
192 cb_ptr++;
|
|
193 cr_ptr++;
|
|
194 }
|
|
195 /* handle width */
|
|
196 if (w) {
|
|
197 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
|
|
198 /* output 2 pixels */
|
|
199 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
|
|
200 RGB_OUT(d1, r, g, b);
|
|
201 d1 += BPP;
|
|
202
|
|
203 y1_ptr++;
|
|
204 cb_ptr++;
|
|
205 cr_ptr++;
|
|
206 }
|
|
207 }
|
|
208 }
|
|
209
|
|
210 static void glue(RGB_NAME, _to_yuv420p)(AVPicture *dst, AVPicture *src,
|
|
211 int width, int height)
|
|
212 {
|
|
213 int wrap, wrap3, width2;
|
|
214 int r, g, b, r1, g1, b1, w;
|
|
215 uint8_t *lum, *cb, *cr;
|
|
216 const uint8_t *p;
|
|
217
|
|
218 lum = dst->data[0];
|
|
219 cb = dst->data[1];
|
|
220 cr = dst->data[2];
|
|
221
|
|
222 width2 = (width + 1) >> 1;
|
|
223 wrap = dst->linesize[0];
|
|
224 wrap3 = src->linesize[0];
|
|
225 p = src->data[0];
|
|
226 for(;height>=2;height -= 2) {
|
|
227 for(w = width; w >= 2; w -= 2) {
|
|
228 RGB_IN(r, g, b, p);
|
|
229 r1 = r;
|
|
230 g1 = g;
|
|
231 b1 = b;
|
|
232 lum[0] = RGB_TO_Y_CCIR(r, g, b);
|
|
233
|
|
234 RGB_IN(r, g, b, p + BPP);
|
|
235 r1 += r;
|
|
236 g1 += g;
|
|
237 b1 += b;
|
|
238 lum[1] = RGB_TO_Y_CCIR(r, g, b);
|
|
239 p += wrap3;
|
|
240 lum += wrap;
|
|
241
|
|
242 RGB_IN(r, g, b, p);
|
|
243 r1 += r;
|
|
244 g1 += g;
|
|
245 b1 += b;
|
|
246 lum[0] = RGB_TO_Y_CCIR(r, g, b);
|
|
247
|
|
248 RGB_IN(r, g, b, p + BPP);
|
|
249 r1 += r;
|
|
250 g1 += g;
|
|
251 b1 += b;
|
|
252 lum[1] = RGB_TO_Y_CCIR(r, g, b);
|
|
253
|
|
254 cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 2);
|
|
255 cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 2);
|
|
256
|
|
257 cb++;
|
|
258 cr++;
|
|
259 p += -wrap3 + 2 * BPP;
|
|
260 lum += -wrap + 2;
|
|
261 }
|
|
262 if (w) {
|
|
263 RGB_IN(r, g, b, p);
|
|
264 r1 = r;
|
|
265 g1 = g;
|
|
266 b1 = b;
|
|
267 lum[0] = RGB_TO_Y_CCIR(r, g, b);
|
|
268 p += wrap3;
|
|
269 lum += wrap;
|
|
270 RGB_IN(r, g, b, p);
|
|
271 r1 += r;
|
|
272 g1 += g;
|
|
273 b1 += b;
|
|
274 lum[0] = RGB_TO_Y_CCIR(r, g, b);
|
|
275 cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
|
|
276 cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
|
|
277 cb++;
|
|
278 cr++;
|
|
279 p += -wrap3 + BPP;
|
|
280 lum += -wrap + 1;
|
|
281 }
|
|
282 p += wrap3 + (wrap3 - width * BPP);
|
|
283 lum += wrap + (wrap - width);
|
|
284 cb += dst->linesize[1] - width2;
|
|
285 cr += dst->linesize[2] - width2;
|
|
286 }
|
|
287 /* handle odd height */
|
|
288 if (height) {
|
|
289 for(w = width; w >= 2; w -= 2) {
|
|
290 RGB_IN(r, g, b, p);
|
|
291 r1 = r;
|
|
292 g1 = g;
|
|
293 b1 = b;
|
|
294 lum[0] = RGB_TO_Y_CCIR(r, g, b);
|
|
295
|
|
296 RGB_IN(r, g, b, p + BPP);
|
|
297 r1 += r;
|
|
298 g1 += g;
|
|
299 b1 += b;
|
|
300 lum[1] = RGB_TO_Y_CCIR(r, g, b);
|
|
301 cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
|
|
302 cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
|
|
303 cb++;
|
|
304 cr++;
|
|
305 p += 2 * BPP;
|
|
306 lum += 2;
|
|
307 }
|
|
308 if (w) {
|
|
309 RGB_IN(r, g, b, p);
|
|
310 lum[0] = RGB_TO_Y_CCIR(r, g, b);
|
|
311 cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
|
|
312 cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
|
|
313 }
|
|
314 }
|
|
315 }
|
|
316
|
|
317 static void glue(RGB_NAME, _to_gray)(AVPicture *dst, AVPicture *src,
|
|
318 int width, int height)
|
|
319 {
|
|
320 const unsigned char *p;
|
|
321 unsigned char *q;
|
|
322 int r, g, b, dst_wrap, src_wrap;
|
|
323 int x, y;
|
|
324
|
|
325 p = src->data[0];
|
|
326 src_wrap = src->linesize[0] - BPP * width;
|
|
327
|
|
328 q = dst->data[0];
|
|
329 dst_wrap = dst->linesize[0] - width;
|
|
330
|
|
331 for(y=0;y<height;y++) {
|
|
332 for(x=0;x<width;x++) {
|
|
333 RGB_IN(r, g, b, p);
|
|
334 q[0] = RGB_TO_Y(r, g, b);
|
|
335 q++;
|
|
336 p += BPP;
|
|
337 }
|
|
338 p += src_wrap;
|
|
339 q += dst_wrap;
|
|
340 }
|
|
341 }
|
|
342
|
|
343 static void glue(gray_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
|
|
344 int width, int height)
|
|
345 {
|
|
346 const unsigned char *p;
|
|
347 unsigned char *q;
|
|
348 int r, dst_wrap, src_wrap;
|
|
349 int x, y;
|
|
350
|
|
351 p = src->data[0];
|
|
352 src_wrap = src->linesize[0] - width;
|
|
353
|
|
354 q = dst->data[0];
|
|
355 dst_wrap = dst->linesize[0] - BPP * width;
|
|
356
|
|
357 for(y=0;y<height;y++) {
|
|
358 for(x=0;x<width;x++) {
|
|
359 r = p[0];
|
|
360 RGB_OUT(q, r, r, r);
|
|
361 q += BPP;
|
|
362 p ++;
|
|
363 }
|
|
364 p += src_wrap;
|
|
365 q += dst_wrap;
|
|
366 }
|
|
367 }
|
|
368
|
|
369 static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
|
|
370 int width, int height)
|
|
371 {
|
|
372 const unsigned char *p;
|
|
373 unsigned char *q;
|
|
374 int r, g, b, dst_wrap, src_wrap;
|
|
375 int x, y;
|
|
376 uint32_t v;
|
|
377 const uint32_t *palette;
|
|
378
|
|
379 p = src->data[0];
|
|
380 src_wrap = src->linesize[0] - width;
|
|
381 palette = (uint32_t *)src->data[1];
|
|
382
|
|
383 q = dst->data[0];
|
|
384 dst_wrap = dst->linesize[0] - BPP * width;
|
|
385
|
|
386 for(y=0;y<height;y++) {
|
|
387 for(x=0;x<width;x++) {
|
|
388 v = palette[p[0]];
|
|
389 r = (v >> 16) & 0xff;
|
|
390 g = (v >> 8) & 0xff;
|
|
391 b = (v) & 0xff;
|
|
392 #ifdef RGBA_OUT
|
|
393 {
|
|
394 int a;
|
|
395 a = (v >> 24) & 0xff;
|
|
396 RGBA_OUT(q, r, g, b, a);
|
|
397 }
|
|
398 #else
|
|
399 RGB_OUT(q, r, g, b);
|
|
400 #endif
|
|
401 q += BPP;
|
|
402 p ++;
|
|
403 }
|
|
404 p += src_wrap;
|
|
405 q += dst_wrap;
|
|
406 }
|
|
407 }
|
|
408
|
|
409 #if !defined(FMT_RGBA32) && defined(RGBA_OUT)
|
|
410 /* alpha support */
|
|
411
|
|
412 static void glue(rgba32_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
|
|
413 int width, int height)
|
|
414 {
|
|
415 const uint8_t *s;
|
|
416 uint8_t *d;
|
|
417 int src_wrap, dst_wrap, j, y;
|
|
418 unsigned int v, r, g, b, a;
|
|
419
|
|
420 s = src->data[0];
|
|
421 src_wrap = src->linesize[0] - width * 4;
|
|
422
|
|
423 d = dst->data[0];
|
|
424 dst_wrap = dst->linesize[0] - width * BPP;
|
|
425
|
|
426 for(y=0;y<height;y++) {
|
|
427 for(j = 0;j < width; j++) {
|
|
428 v = ((const uint32_t *)(s))[0];
|
|
429 a = (v >> 24) & 0xff;
|
|
430 r = (v >> 16) & 0xff;
|
|
431 g = (v >> 8) & 0xff;
|
|
432 b = v & 0xff;
|
|
433 RGBA_OUT(d, r, g, b, a);
|
|
434 s += 4;
|
|
435 d += BPP;
|
|
436 }
|
|
437 s += src_wrap;
|
|
438 d += dst_wrap;
|
|
439 }
|
|
440 }
|
|
441
|
|
442 static void glue(RGB_NAME, _to_rgba32)(AVPicture *dst, AVPicture *src,
|
|
443 int width, int height)
|
|
444 {
|
|
445 const uint8_t *s;
|
|
446 uint8_t *d;
|
|
447 int src_wrap, dst_wrap, j, y;
|
|
448 unsigned int r, g, b, a;
|
|
449
|
|
450 s = src->data[0];
|
|
451 src_wrap = src->linesize[0] - width * BPP;
|
|
452
|
|
453 d = dst->data[0];
|
|
454 dst_wrap = dst->linesize[0] - width * 4;
|
|
455
|
|
456 for(y=0;y<height;y++) {
|
|
457 for(j = 0;j < width; j++) {
|
|
458 RGBA_IN(r, g, b, a, s);
|
|
459 ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;
|
|
460 d += 4;
|
|
461 s += BPP;
|
|
462 }
|
|
463 s += src_wrap;
|
|
464 d += dst_wrap;
|
|
465 }
|
|
466 }
|
|
467
|
|
468 #endif /* !defined(FMT_RGBA32) && defined(RGBA_IN) */
|
|
469
|
|
470 #ifndef FMT_RGB24
|
|
471
|
|
472 static void glue(rgb24_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
|
|
473 int width, int height)
|
|
474 {
|
|
475 const uint8_t *s;
|
|
476 uint8_t *d;
|
|
477 int src_wrap, dst_wrap, j, y;
|
|
478 unsigned int r, g, b;
|
|
479
|
|
480 s = src->data[0];
|
|
481 src_wrap = src->linesize[0] - width * 3;
|
|
482
|
|
483 d = dst->data[0];
|
|
484 dst_wrap = dst->linesize[0] - width * BPP;
|
|
485
|
|
486 for(y=0;y<height;y++) {
|
|
487 for(j = 0;j < width; j++) {
|
|
488 r = s[0];
|
|
489 g = s[1];
|
|
490 b = s[2];
|
|
491 RGB_OUT(d, r, g, b);
|
|
492 s += 3;
|
|
493 d += BPP;
|
|
494 }
|
|
495 s += src_wrap;
|
|
496 d += dst_wrap;
|
|
497 }
|
|
498 }
|
|
499
|
|
500 static void glue(RGB_NAME, _to_rgb24)(AVPicture *dst, AVPicture *src,
|
|
501 int width, int height)
|
|
502 {
|
|
503 const uint8_t *s;
|
|
504 uint8_t *d;
|
|
505 int src_wrap, dst_wrap, j, y;
|
|
506 unsigned int r, g , b;
|
|
507
|
|
508 s = src->data[0];
|
|
509 src_wrap = src->linesize[0] - width * BPP;
|
|
510
|
|
511 d = dst->data[0];
|
|
512 dst_wrap = dst->linesize[0] - width * 3;
|
|
513
|
|
514 for(y=0;y<height;y++) {
|
|
515 for(j = 0;j < width; j++) {
|
|
516 RGB_IN(r, g, b, s)
|
|
517 d[0] = r;
|
|
518 d[1] = g;
|
|
519 d[2] = b;
|
|
520 d += 3;
|
|
521 s += BPP;
|
|
522 }
|
|
523 s += src_wrap;
|
|
524 d += dst_wrap;
|
|
525 }
|
|
526 }
|
|
527
|
|
528 #endif /* !FMT_RGB24 */
|
|
529
|
|
530 #ifdef FMT_RGB24
|
|
531
|
|
532 static void yuv444p_to_rgb24(AVPicture *dst, AVPicture *src,
|
|
533 int width, int height)
|
|
534 {
|
|
535 uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1;
|
|
536 int w, y, cb, cr, r_add, g_add, b_add;
|
|
537 uint8_t *cm = cropTbl + MAX_NEG_CROP;
|
|
538 unsigned int r, g, b;
|
|
539
|
|
540 d = dst->data[0];
|
|
541 y1_ptr = src->data[0];
|
|
542 cb_ptr = src->data[1];
|
|
543 cr_ptr = src->data[2];
|
|
544 for(;height > 0; height --) {
|
|
545 d1 = d;
|
|
546 for(w = width; w > 0; w--) {
|
|
547 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
|
|
548
|
|
549 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
|
|
550 RGB_OUT(d1, r, g, b);
|
|
551 d1 += BPP;
|
|
552
|
|
553 y1_ptr++;
|
|
554 cb_ptr++;
|
|
555 cr_ptr++;
|
|
556 }
|
|
557 d += dst->linesize[0];
|
|
558 y1_ptr += src->linesize[0] - width;
|
|
559 cb_ptr += src->linesize[1] - width;
|
|
560 cr_ptr += src->linesize[2] - width;
|
|
561 }
|
|
562 }
|
|
563
|
|
564 static void yuvj444p_to_rgb24(AVPicture *dst, AVPicture *src,
|
|
565 int width, int height)
|
|
566 {
|
|
567 uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1;
|
|
568 int w, y, cb, cr, r_add, g_add, b_add;
|
|
569 uint8_t *cm = cropTbl + MAX_NEG_CROP;
|
|
570 unsigned int r, g, b;
|
|
571
|
|
572 d = dst->data[0];
|
|
573 y1_ptr = src->data[0];
|
|
574 cb_ptr = src->data[1];
|
|
575 cr_ptr = src->data[2];
|
|
576 for(;height > 0; height --) {
|
|
577 d1 = d;
|
|
578 for(w = width; w > 0; w--) {
|
|
579 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
|
|
580
|
|
581 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
|
|
582 RGB_OUT(d1, r, g, b);
|
|
583 d1 += BPP;
|
|
584
|
|
585 y1_ptr++;
|
|
586 cb_ptr++;
|
|
587 cr_ptr++;
|
|
588 }
|
|
589 d += dst->linesize[0];
|
|
590 y1_ptr += src->linesize[0] - width;
|
|
591 cb_ptr += src->linesize[1] - width;
|
|
592 cr_ptr += src->linesize[2] - width;
|
|
593 }
|
|
594 }
|
|
595
|
|
596 static void rgb24_to_yuv444p(AVPicture *dst, AVPicture *src,
|
|
597 int width, int height)
|
|
598 {
|
|
599 int src_wrap, x, y;
|
|
600 int r, g, b;
|
|
601 uint8_t *lum, *cb, *cr;
|
|
602 const uint8_t *p;
|
|
603
|
|
604 lum = dst->data[0];
|
|
605 cb = dst->data[1];
|
|
606 cr = dst->data[2];
|
|
607
|
|
608 src_wrap = src->linesize[0] - width * BPP;
|
|
609 p = src->data[0];
|
|
610 for(y=0;y<height;y++) {
|
|
611 for(x=0;x<width;x++) {
|
|
612 RGB_IN(r, g, b, p);
|
|
613 lum[0] = RGB_TO_Y_CCIR(r, g, b);
|
|
614 cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
|
|
615 cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
|
|
616 p += BPP;
|
|
617 cb++;
|
|
618 cr++;
|
|
619 lum++;
|
|
620 }
|
|
621 p += src_wrap;
|
|
622 lum += dst->linesize[0] - width;
|
|
623 cb += dst->linesize[1] - width;
|
|
624 cr += dst->linesize[2] - width;
|
|
625 }
|
|
626 }
|
|
627
|
|
628 static void rgb24_to_yuvj420p(AVPicture *dst, AVPicture *src,
|
|
629 int width, int height)
|
|
630 {
|
|
631 int wrap, wrap3, width2;
|
|
632 int r, g, b, r1, g1, b1, w;
|
|
633 uint8_t *lum, *cb, *cr;
|
|
634 const uint8_t *p;
|
|
635
|
|
636 lum = dst->data[0];
|
|
637 cb = dst->data[1];
|
|
638 cr = dst->data[2];
|
|
639
|
|
640 width2 = (width + 1) >> 1;
|
|
641 wrap = dst->linesize[0];
|
|
642 wrap3 = src->linesize[0];
|
|
643 p = src->data[0];
|
|
644 for(;height>=2;height -= 2) {
|
|
645 for(w = width; w >= 2; w -= 2) {
|
|
646 RGB_IN(r, g, b, p);
|
|
647 r1 = r;
|
|
648 g1 = g;
|
|
649 b1 = b;
|
|
650 lum[0] = RGB_TO_Y(r, g, b);
|
|
651
|
|
652 RGB_IN(r, g, b, p + BPP);
|
|
653 r1 += r;
|
|
654 g1 += g;
|
|
655 b1 += b;
|
|
656 lum[1] = RGB_TO_Y(r, g, b);
|
|
657 p += wrap3;
|
|
658 lum += wrap;
|
|
659
|
|
660 RGB_IN(r, g, b, p);
|
|
661 r1 += r;
|
|
662 g1 += g;
|
|
663 b1 += b;
|
|
664 lum[0] = RGB_TO_Y(r, g, b);
|
|
665
|
|
666 RGB_IN(r, g, b, p + BPP);
|
|
667 r1 += r;
|
|
668 g1 += g;
|
|
669 b1 += b;
|
|
670 lum[1] = RGB_TO_Y(r, g, b);
|
|
671
|
|
672 cb[0] = RGB_TO_U(r1, g1, b1, 2);
|
|
673 cr[0] = RGB_TO_V(r1, g1, b1, 2);
|
|
674
|
|
675 cb++;
|
|
676 cr++;
|
|
677 p += -wrap3 + 2 * BPP;
|
|
678 lum += -wrap + 2;
|
|
679 }
|
|
680 if (w) {
|
|
681 RGB_IN(r, g, b, p);
|
|
682 r1 = r;
|
|
683 g1 = g;
|
|
684 b1 = b;
|
|
685 lum[0] = RGB_TO_Y(r, g, b);
|
|
686 p += wrap3;
|
|
687 lum += wrap;
|
|
688 RGB_IN(r, g, b, p);
|
|
689 r1 += r;
|
|
690 g1 += g;
|
|
691 b1 += b;
|
|
692 lum[0] = RGB_TO_Y(r, g, b);
|
|
693 cb[0] = RGB_TO_U(r1, g1, b1, 1);
|
|
694 cr[0] = RGB_TO_V(r1, g1, b1, 1);
|
|
695 cb++;
|
|
696 cr++;
|
|
697 p += -wrap3 + BPP;
|
|
698 lum += -wrap + 1;
|
|
699 }
|
|
700 p += wrap3 + (wrap3 - width * BPP);
|
|
701 lum += wrap + (wrap - width);
|
|
702 cb += dst->linesize[1] - width2;
|
|
703 cr += dst->linesize[2] - width2;
|
|
704 }
|
|
705 /* handle odd height */
|
|
706 if (height) {
|
|
707 for(w = width; w >= 2; w -= 2) {
|
|
708 RGB_IN(r, g, b, p);
|
|
709 r1 = r;
|
|
710 g1 = g;
|
|
711 b1 = b;
|
|
712 lum[0] = RGB_TO_Y(r, g, b);
|
|
713
|
|
714 RGB_IN(r, g, b, p + BPP);
|
|
715 r1 += r;
|
|
716 g1 += g;
|
|
717 b1 += b;
|
|
718 lum[1] = RGB_TO_Y(r, g, b);
|
|
719 cb[0] = RGB_TO_U(r1, g1, b1, 1);
|
|
720 cr[0] = RGB_TO_V(r1, g1, b1, 1);
|
|
721 cb++;
|
|
722 cr++;
|
|
723 p += 2 * BPP;
|
|
724 lum += 2;
|
|
725 }
|
|
726 if (w) {
|
|
727 RGB_IN(r, g, b, p);
|
|
728 lum[0] = RGB_TO_Y(r, g, b);
|
|
729 cb[0] = RGB_TO_U(r, g, b, 0);
|
|
730 cr[0] = RGB_TO_V(r, g, b, 0);
|
|
731 }
|
|
732 }
|
|
733 }
|
|
734
|
|
735 static void rgb24_to_yuvj444p(AVPicture *dst, AVPicture *src,
|
|
736 int width, int height)
|
|
737 {
|
|
738 int src_wrap, x, y;
|
|
739 int r, g, b;
|
|
740 uint8_t *lum, *cb, *cr;
|
|
741 const uint8_t *p;
|
|
742
|
|
743 lum = dst->data[0];
|
|
744 cb = dst->data[1];
|
|
745 cr = dst->data[2];
|
|
746
|
|
747 src_wrap = src->linesize[0] - width * BPP;
|
|
748 p = src->data[0];
|
|
749 for(y=0;y<height;y++) {
|
|
750 for(x=0;x<width;x++) {
|
|
751 RGB_IN(r, g, b, p);
|
|
752 lum[0] = RGB_TO_Y(r, g, b);
|
|
753 cb[0] = RGB_TO_U(r, g, b, 0);
|
|
754 cr[0] = RGB_TO_V(r, g, b, 0);
|
|
755 p += BPP;
|
|
756 cb++;
|
|
757 cr++;
|
|
758 lum++;
|
|
759 }
|
|
760 p += src_wrap;
|
|
761 lum += dst->linesize[0] - width;
|
|
762 cb += dst->linesize[1] - width;
|
|
763 cr += dst->linesize[2] - width;
|
|
764 }
|
|
765 }
|
|
766
|
|
767 #endif /* FMT_RGB24 */
|
|
768
|
|
769 #if defined(FMT_RGB24) || defined(FMT_RGBA32)
|
|
770
|
|
771 static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, AVPicture *src,
|
|
772 int width, int height)
|
|
773 {
|
|
774 const unsigned char *p;
|
|
775 unsigned char *q;
|
|
776 int dst_wrap, src_wrap;
|
|
777 int x, y, has_alpha;
|
|
778 unsigned int r, g, b;
|
|
779
|
|
780 p = src->data[0];
|
|
781 src_wrap = src->linesize[0] - BPP * width;
|
|
782
|
|
783 q = dst->data[0];
|
|
784 dst_wrap = dst->linesize[0] - width;
|
|
785 has_alpha = 0;
|
|
786
|
|
787 for(y=0;y<height;y++) {
|
|
788 for(x=0;x<width;x++) {
|
|
789 #ifdef RGBA_IN
|
|
790 {
|
|
791 unsigned int a;
|
|
792 RGBA_IN(r, g, b, a, p);
|
|
793 /* crude approximation for alpha ! */
|
|
794 if (a < 0x80) {
|
|
795 has_alpha = 1;
|
|
796 q[0] = TRANSP_INDEX;
|
|
797 } else {
|
|
798 q[0] = gif_clut_index(r, g, b);
|
|
799 }
|
|
800 }
|
|
801 #else
|
|
802 RGB_IN(r, g, b, p);
|
|
803 q[0] = gif_clut_index(r, g, b);
|
|
804 #endif
|
|
805 q++;
|
|
806 p += BPP;
|
|
807 }
|
|
808 p += src_wrap;
|
|
809 q += dst_wrap;
|
|
810 }
|
|
811
|
|
812 build_rgb_palette(dst->data[1], has_alpha);
|
|
813 }
|
|
814
|
|
815 #endif /* defined(FMT_RGB24) || defined(FMT_RGBA32) */
|
|
816
|
1208
|
817 #ifdef RGBA_IN
|
|
818
|
|
819 static int glue(get_alpha_info_, RGB_NAME)(AVPicture *src, int width, int height)
|
|
820 {
|
|
821 const unsigned char *p;
|
|
822 int src_wrap, ret, x, y;
|
|
823 unsigned int r, g, b, a;
|
|
824
|
|
825 p = src->data[0];
|
|
826 src_wrap = src->linesize[0] - BPP * width;
|
|
827 ret = 0;
|
|
828 for(y=0;y<height;y++) {
|
|
829 for(x=0;x<width;x++) {
|
|
830 RGBA_IN(r, g, b, a, p);
|
|
831 if (a == 0x00) {
|
|
832 ret |= FF_ALPHA_TRANSP;
|
|
833 } else if (a != 0xff) {
|
|
834 ret |= FF_ALPHA_SEMI_TRANSP;
|
|
835 }
|
|
836 p += BPP;
|
|
837 }
|
|
838 p += src_wrap;
|
|
839 }
|
|
840 return ret;
|
|
841 }
|
|
842
|
|
843 #endif /* RGBA_IN */
|
|
844
|
1204
|
845 #undef RGB_IN
|
|
846 #undef RGBA_IN
|
|
847 #undef RGB_OUT
|
|
848 #undef RGBA_OUT
|
|
849 #undef BPP
|
|
850 #undef RGB_NAME
|
|
851 #undef FMT_RGB24
|
|
852 #undef FMT_RGBA32
|