r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / quicktime / ffmpeg / libavcodec / imgconvert_template.h
blobcd5a7313c3f59b7bd2191b8c95d325d232da9aad
1 /*
2 * Templates for image convertion routines
3 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
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.
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.
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
20 #ifndef RGB_OUT
21 #define RGB_OUT(d, r, g, b) RGBA_OUT(d, r, g, b, 0xff)
22 #endif
24 static void glue(yuv420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
25 int width, int height)
27 const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
28 uint8_t *d, *d1, *d2;
29 int w, y, cb, cr, r_add, g_add, b_add, width2;
30 uint8_t *cm = cropTbl + MAX_NEG_CROP;
31 unsigned int r, g, b;
33 d = dst->data[0];
34 y1_ptr = src->data[0];
35 cb_ptr = src->data[1];
36 cr_ptr = src->data[2];
37 width2 = (width + 1) >> 1;
38 for(;height >= 2; height -= 2) {
39 d1 = d;
40 d2 = d + dst->linesize[0];
41 y2_ptr = y1_ptr + src->linesize[0];
42 for(w = width; w >= 2; w -= 2) {
43 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
44 /* output 4 pixels */
45 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
46 RGB_OUT(d1, r, g, b);
48 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
49 RGB_OUT(d1 + BPP, r, g, b);
51 YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
52 RGB_OUT(d2, r, g, b);
54 YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[1]);
55 RGB_OUT(d2 + BPP, r, g, b);
57 d1 += 2 * BPP;
58 d2 += 2 * BPP;
60 y1_ptr += 2;
61 y2_ptr += 2;
62 cb_ptr++;
63 cr_ptr++;
65 /* handle odd width */
66 if (w) {
67 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
68 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
69 RGB_OUT(d1, r, g, b);
71 YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
72 RGB_OUT(d2, r, g, b);
73 d1 += BPP;
74 d2 += BPP;
75 y1_ptr++;
76 y2_ptr++;
77 cb_ptr++;
78 cr_ptr++;
80 d += 2 * dst->linesize[0];
81 y1_ptr += 2 * src->linesize[0] - width;
82 cb_ptr += src->linesize[1] - width2;
83 cr_ptr += src->linesize[2] - width2;
85 /* handle odd height */
86 if (height) {
87 d1 = d;
88 for(w = width; w >= 2; w -= 2) {
89 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
90 /* output 2 pixels */
91 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
92 RGB_OUT(d1, r, g, b);
94 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
95 RGB_OUT(d1 + BPP, r, g, b);
97 d1 += 2 * BPP;
99 y1_ptr += 2;
100 cb_ptr++;
101 cr_ptr++;
103 /* handle width */
104 if (w) {
105 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
106 /* output 2 pixels */
107 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
108 RGB_OUT(d1, r, g, b);
109 d1 += BPP;
111 y1_ptr++;
112 cb_ptr++;
113 cr_ptr++;
118 static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
119 int width, int height)
121 const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr;
122 uint8_t *d, *d1, *d2;
123 int w, y, cb, cr, r_add, g_add, b_add, width2;
124 uint8_t *cm = cropTbl + MAX_NEG_CROP;
125 unsigned int r, g, b;
127 d = dst->data[0];
128 y1_ptr = src->data[0];
129 cb_ptr = src->data[1];
130 cr_ptr = src->data[2];
131 width2 = (width + 1) >> 1;
132 for(;height >= 2; height -= 2) {
133 d1 = d;
134 d2 = d + dst->linesize[0];
135 y2_ptr = y1_ptr + src->linesize[0];
136 for(w = width; w >= 2; w -= 2) {
137 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
138 /* output 4 pixels */
139 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
140 RGB_OUT(d1, r, g, b);
142 YUV_TO_RGB2(r, g, b, y1_ptr[1]);
143 RGB_OUT(d1 + BPP, r, g, b);
145 YUV_TO_RGB2(r, g, b, y2_ptr[0]);
146 RGB_OUT(d2, r, g, b);
148 YUV_TO_RGB2(r, g, b, y2_ptr[1]);
149 RGB_OUT(d2 + BPP, r, g, b);
151 d1 += 2 * BPP;
152 d2 += 2 * BPP;
154 y1_ptr += 2;
155 y2_ptr += 2;
156 cb_ptr++;
157 cr_ptr++;
159 /* handle odd width */
160 if (w) {
161 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
162 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
163 RGB_OUT(d1, r, g, b);
165 YUV_TO_RGB2(r, g, b, y2_ptr[0]);
166 RGB_OUT(d2, r, g, b);
167 d1 += BPP;
168 d2 += BPP;
169 y1_ptr++;
170 y2_ptr++;
171 cb_ptr++;
172 cr_ptr++;
174 d += 2 * dst->linesize[0];
175 y1_ptr += 2 * src->linesize[0] - width;
176 cb_ptr += src->linesize[1] - width2;
177 cr_ptr += src->linesize[2] - width2;
179 /* handle odd height */
180 if (height) {
181 d1 = d;
182 for(w = width; w >= 2; w -= 2) {
183 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
184 /* output 2 pixels */
185 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
186 RGB_OUT(d1, r, g, b);
188 YUV_TO_RGB2(r, g, b, y1_ptr[1]);
189 RGB_OUT(d1 + BPP, r, g, b);
191 d1 += 2 * BPP;
193 y1_ptr += 2;
194 cb_ptr++;
195 cr_ptr++;
197 /* handle width */
198 if (w) {
199 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
200 /* output 2 pixels */
201 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
202 RGB_OUT(d1, r, g, b);
203 d1 += BPP;
205 y1_ptr++;
206 cb_ptr++;
207 cr_ptr++;
212 static void glue(RGB_NAME, _to_yuv420p)(AVPicture *dst, const AVPicture *src,
213 int width, int height)
215 int wrap, wrap3, width2;
216 int r, g, b, r1, g1, b1, w;
217 uint8_t *lum, *cb, *cr;
218 const uint8_t *p;
220 lum = dst->data[0];
221 cb = dst->data[1];
222 cr = dst->data[2];
224 width2 = (width + 1) >> 1;
225 wrap = dst->linesize[0];
226 wrap3 = src->linesize[0];
227 p = src->data[0];
228 for(;height>=2;height -= 2) {
229 for(w = width; w >= 2; w -= 2) {
230 RGB_IN(r, g, b, p);
231 r1 = r;
232 g1 = g;
233 b1 = b;
234 lum[0] = RGB_TO_Y_CCIR(r, g, b);
236 RGB_IN(r, g, b, p + BPP);
237 r1 += r;
238 g1 += g;
239 b1 += b;
240 lum[1] = RGB_TO_Y_CCIR(r, g, b);
241 p += wrap3;
242 lum += wrap;
244 RGB_IN(r, g, b, p);
245 r1 += r;
246 g1 += g;
247 b1 += b;
248 lum[0] = RGB_TO_Y_CCIR(r, g, b);
250 RGB_IN(r, g, b, p + BPP);
251 r1 += r;
252 g1 += g;
253 b1 += b;
254 lum[1] = RGB_TO_Y_CCIR(r, g, b);
256 cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 2);
257 cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 2);
259 cb++;
260 cr++;
261 p += -wrap3 + 2 * BPP;
262 lum += -wrap + 2;
264 if (w) {
265 RGB_IN(r, g, b, p);
266 r1 = r;
267 g1 = g;
268 b1 = b;
269 lum[0] = RGB_TO_Y_CCIR(r, g, b);
270 p += wrap3;
271 lum += wrap;
272 RGB_IN(r, g, b, p);
273 r1 += r;
274 g1 += g;
275 b1 += b;
276 lum[0] = RGB_TO_Y_CCIR(r, g, b);
277 cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
278 cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
279 cb++;
280 cr++;
281 p += -wrap3 + BPP;
282 lum += -wrap + 1;
284 p += wrap3 + (wrap3 - width * BPP);
285 lum += wrap + (wrap - width);
286 cb += dst->linesize[1] - width2;
287 cr += dst->linesize[2] - width2;
289 /* handle odd height */
290 if (height) {
291 for(w = width; w >= 2; w -= 2) {
292 RGB_IN(r, g, b, p);
293 r1 = r;
294 g1 = g;
295 b1 = b;
296 lum[0] = RGB_TO_Y_CCIR(r, g, b);
298 RGB_IN(r, g, b, p + BPP);
299 r1 += r;
300 g1 += g;
301 b1 += b;
302 lum[1] = RGB_TO_Y_CCIR(r, g, b);
303 cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
304 cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
305 cb++;
306 cr++;
307 p += 2 * BPP;
308 lum += 2;
310 if (w) {
311 RGB_IN(r, g, b, p);
312 lum[0] = RGB_TO_Y_CCIR(r, g, b);
313 cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
314 cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
319 static void glue(RGB_NAME, _to_gray)(AVPicture *dst, const AVPicture *src,
320 int width, int height)
322 const unsigned char *p;
323 unsigned char *q;
324 int r, g, b, dst_wrap, src_wrap;
325 int x, y;
327 p = src->data[0];
328 src_wrap = src->linesize[0] - BPP * width;
330 q = dst->data[0];
331 dst_wrap = dst->linesize[0] - width;
333 for(y=0;y<height;y++) {
334 for(x=0;x<width;x++) {
335 RGB_IN(r, g, b, p);
336 q[0] = RGB_TO_Y(r, g, b);
337 q++;
338 p += BPP;
340 p += src_wrap;
341 q += dst_wrap;
345 static void glue(gray_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
346 int width, int height)
348 const unsigned char *p;
349 unsigned char *q;
350 int r, dst_wrap, src_wrap;
351 int x, y;
353 p = src->data[0];
354 src_wrap = src->linesize[0] - width;
356 q = dst->data[0];
357 dst_wrap = dst->linesize[0] - BPP * width;
359 for(y=0;y<height;y++) {
360 for(x=0;x<width;x++) {
361 r = p[0];
362 RGB_OUT(q, r, r, r);
363 q += BPP;
364 p ++;
366 p += src_wrap;
367 q += dst_wrap;
371 static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
372 int width, int height)
374 const unsigned char *p;
375 unsigned char *q;
376 int r, g, b, dst_wrap, src_wrap;
377 int x, y;
378 uint32_t v;
379 const uint32_t *palette;
381 p = src->data[0];
382 src_wrap = src->linesize[0] - width;
383 palette = (uint32_t *)src->data[1];
385 q = dst->data[0];
386 dst_wrap = dst->linesize[0] - BPP * width;
388 for(y=0;y<height;y++) {
389 for(x=0;x<width;x++) {
390 v = palette[p[0]];
391 r = (v >> 16) & 0xff;
392 g = (v >> 8) & 0xff;
393 b = (v) & 0xff;
394 #ifdef RGBA_OUT
396 int a;
397 a = (v >> 24) & 0xff;
398 RGBA_OUT(q, r, g, b, a);
400 #else
401 RGB_OUT(q, r, g, b);
402 #endif
403 q += BPP;
404 p ++;
406 p += src_wrap;
407 q += dst_wrap;
411 #if !defined(FMT_RGBA32) && defined(RGBA_OUT)
412 /* alpha support */
414 static void glue(rgba32_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
415 int width, int height)
417 const uint8_t *s;
418 uint8_t *d;
419 int src_wrap, dst_wrap, j, y;
420 unsigned int v, r, g, b, a;
422 s = src->data[0];
423 src_wrap = src->linesize[0] - width * 4;
425 d = dst->data[0];
426 dst_wrap = dst->linesize[0] - width * BPP;
428 for(y=0;y<height;y++) {
429 for(j = 0;j < width; j++) {
430 v = ((const uint32_t *)(s))[0];
431 a = (v >> 24) & 0xff;
432 r = (v >> 16) & 0xff;
433 g = (v >> 8) & 0xff;
434 b = v & 0xff;
435 RGBA_OUT(d, r, g, b, a);
436 s += 4;
437 d += BPP;
439 s += src_wrap;
440 d += dst_wrap;
444 static void glue(RGB_NAME, _to_rgba32)(AVPicture *dst, const AVPicture *src,
445 int width, int height)
447 const uint8_t *s;
448 uint8_t *d;
449 int src_wrap, dst_wrap, j, y;
450 unsigned int r, g, b, a;
452 s = src->data[0];
453 src_wrap = src->linesize[0] - width * BPP;
455 d = dst->data[0];
456 dst_wrap = dst->linesize[0] - width * 4;
458 for(y=0;y<height;y++) {
459 for(j = 0;j < width; j++) {
460 RGBA_IN(r, g, b, a, s);
461 ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;
462 d += 4;
463 s += BPP;
465 s += src_wrap;
466 d += dst_wrap;
470 #endif /* !defined(FMT_RGBA32) && defined(RGBA_IN) */
472 #ifndef FMT_RGB24
474 static void glue(rgb24_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src,
475 int width, int height)
477 const uint8_t *s;
478 uint8_t *d;
479 int src_wrap, dst_wrap, j, y;
480 unsigned int r, g, b;
482 s = src->data[0];
483 src_wrap = src->linesize[0] - width * 3;
485 d = dst->data[0];
486 dst_wrap = dst->linesize[0] - width * BPP;
488 for(y=0;y<height;y++) {
489 for(j = 0;j < width; j++) {
490 r = s[0];
491 g = s[1];
492 b = s[2];
493 RGB_OUT(d, r, g, b);
494 s += 3;
495 d += BPP;
497 s += src_wrap;
498 d += dst_wrap;
502 static void glue(RGB_NAME, _to_rgb24)(AVPicture *dst, const AVPicture *src,
503 int width, int height)
505 const uint8_t *s;
506 uint8_t *d;
507 int src_wrap, dst_wrap, j, y;
508 unsigned int r, g , b;
510 s = src->data[0];
511 src_wrap = src->linesize[0] - width * BPP;
513 d = dst->data[0];
514 dst_wrap = dst->linesize[0] - width * 3;
516 for(y=0;y<height;y++) {
517 for(j = 0;j < width; j++) {
518 RGB_IN(r, g, b, s)
519 d[0] = r;
520 d[1] = g;
521 d[2] = b;
522 d += 3;
523 s += BPP;
525 s += src_wrap;
526 d += dst_wrap;
530 #endif /* !FMT_RGB24 */
532 #ifdef FMT_RGB24
534 static void yuv444p_to_rgb24(AVPicture *dst, const AVPicture *src,
535 int width, int height)
537 const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
538 uint8_t *d, *d1;
539 int w, y, cb, cr, r_add, g_add, b_add;
540 uint8_t *cm = cropTbl + MAX_NEG_CROP;
541 unsigned int r, g, b;
543 d = dst->data[0];
544 y1_ptr = src->data[0];
545 cb_ptr = src->data[1];
546 cr_ptr = src->data[2];
547 for(;height > 0; height --) {
548 d1 = d;
549 for(w = width; w > 0; w--) {
550 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
552 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
553 RGB_OUT(d1, r, g, b);
554 d1 += BPP;
556 y1_ptr++;
557 cb_ptr++;
558 cr_ptr++;
560 d += dst->linesize[0];
561 y1_ptr += src->linesize[0] - width;
562 cb_ptr += src->linesize[1] - width;
563 cr_ptr += src->linesize[2] - width;
567 static void yuvj444p_to_rgb24(AVPicture *dst, const AVPicture *src,
568 int width, int height)
570 const uint8_t *y1_ptr, *cb_ptr, *cr_ptr;
571 uint8_t *d, *d1;
572 int w, y, cb, cr, r_add, g_add, b_add;
573 uint8_t *cm = cropTbl + MAX_NEG_CROP;
574 unsigned int r, g, b;
576 d = dst->data[0];
577 y1_ptr = src->data[0];
578 cb_ptr = src->data[1];
579 cr_ptr = src->data[2];
580 for(;height > 0; height --) {
581 d1 = d;
582 for(w = width; w > 0; w--) {
583 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
585 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
586 RGB_OUT(d1, r, g, b);
587 d1 += BPP;
589 y1_ptr++;
590 cb_ptr++;
591 cr_ptr++;
593 d += dst->linesize[0];
594 y1_ptr += src->linesize[0] - width;
595 cb_ptr += src->linesize[1] - width;
596 cr_ptr += src->linesize[2] - width;
600 static void rgb24_to_yuv444p(AVPicture *dst, const AVPicture *src,
601 int width, int height)
603 int src_wrap, x, y;
604 int r, g, b;
605 uint8_t *lum, *cb, *cr;
606 const uint8_t *p;
608 lum = dst->data[0];
609 cb = dst->data[1];
610 cr = dst->data[2];
612 src_wrap = src->linesize[0] - width * BPP;
613 p = src->data[0];
614 for(y=0;y<height;y++) {
615 for(x=0;x<width;x++) {
616 RGB_IN(r, g, b, p);
617 lum[0] = RGB_TO_Y_CCIR(r, g, b);
618 cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
619 cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
620 p += BPP;
621 cb++;
622 cr++;
623 lum++;
625 p += src_wrap;
626 lum += dst->linesize[0] - width;
627 cb += dst->linesize[1] - width;
628 cr += dst->linesize[2] - width;
632 static void rgb24_to_yuvj420p(AVPicture *dst, const AVPicture *src,
633 int width, int height)
635 int wrap, wrap3, width2;
636 int r, g, b, r1, g1, b1, w;
637 uint8_t *lum, *cb, *cr;
638 const uint8_t *p;
640 lum = dst->data[0];
641 cb = dst->data[1];
642 cr = dst->data[2];
644 width2 = (width + 1) >> 1;
645 wrap = dst->linesize[0];
646 wrap3 = src->linesize[0];
647 p = src->data[0];
648 for(;height>=2;height -= 2) {
649 for(w = width; w >= 2; w -= 2) {
650 RGB_IN(r, g, b, p);
651 r1 = r;
652 g1 = g;
653 b1 = b;
654 lum[0] = RGB_TO_Y(r, g, b);
656 RGB_IN(r, g, b, p + BPP);
657 r1 += r;
658 g1 += g;
659 b1 += b;
660 lum[1] = RGB_TO_Y(r, g, b);
661 p += wrap3;
662 lum += wrap;
664 RGB_IN(r, g, b, p);
665 r1 += r;
666 g1 += g;
667 b1 += b;
668 lum[0] = RGB_TO_Y(r, g, b);
670 RGB_IN(r, g, b, p + BPP);
671 r1 += r;
672 g1 += g;
673 b1 += b;
674 lum[1] = RGB_TO_Y(r, g, b);
676 cb[0] = RGB_TO_U(r1, g1, b1, 2);
677 cr[0] = RGB_TO_V(r1, g1, b1, 2);
679 cb++;
680 cr++;
681 p += -wrap3 + 2 * BPP;
682 lum += -wrap + 2;
684 if (w) {
685 RGB_IN(r, g, b, p);
686 r1 = r;
687 g1 = g;
688 b1 = b;
689 lum[0] = RGB_TO_Y(r, g, b);
690 p += wrap3;
691 lum += wrap;
692 RGB_IN(r, g, b, p);
693 r1 += r;
694 g1 += g;
695 b1 += b;
696 lum[0] = RGB_TO_Y(r, g, b);
697 cb[0] = RGB_TO_U(r1, g1, b1, 1);
698 cr[0] = RGB_TO_V(r1, g1, b1, 1);
699 cb++;
700 cr++;
701 p += -wrap3 + BPP;
702 lum += -wrap + 1;
704 p += wrap3 + (wrap3 - width * BPP);
705 lum += wrap + (wrap - width);
706 cb += dst->linesize[1] - width2;
707 cr += dst->linesize[2] - width2;
709 /* handle odd height */
710 if (height) {
711 for(w = width; w >= 2; w -= 2) {
712 RGB_IN(r, g, b, p);
713 r1 = r;
714 g1 = g;
715 b1 = b;
716 lum[0] = RGB_TO_Y(r, g, b);
718 RGB_IN(r, g, b, p + BPP);
719 r1 += r;
720 g1 += g;
721 b1 += b;
722 lum[1] = RGB_TO_Y(r, g, b);
723 cb[0] = RGB_TO_U(r1, g1, b1, 1);
724 cr[0] = RGB_TO_V(r1, g1, b1, 1);
725 cb++;
726 cr++;
727 p += 2 * BPP;
728 lum += 2;
730 if (w) {
731 RGB_IN(r, g, b, p);
732 lum[0] = RGB_TO_Y(r, g, b);
733 cb[0] = RGB_TO_U(r, g, b, 0);
734 cr[0] = RGB_TO_V(r, g, b, 0);
739 static void rgb24_to_yuvj444p(AVPicture *dst, const AVPicture *src,
740 int width, int height)
742 int src_wrap, x, y;
743 int r, g, b;
744 uint8_t *lum, *cb, *cr;
745 const uint8_t *p;
747 lum = dst->data[0];
748 cb = dst->data[1];
749 cr = dst->data[2];
751 src_wrap = src->linesize[0] - width * BPP;
752 p = src->data[0];
753 for(y=0;y<height;y++) {
754 for(x=0;x<width;x++) {
755 RGB_IN(r, g, b, p);
756 lum[0] = RGB_TO_Y(r, g, b);
757 cb[0] = RGB_TO_U(r, g, b, 0);
758 cr[0] = RGB_TO_V(r, g, b, 0);
759 p += BPP;
760 cb++;
761 cr++;
762 lum++;
764 p += src_wrap;
765 lum += dst->linesize[0] - width;
766 cb += dst->linesize[1] - width;
767 cr += dst->linesize[2] - width;
771 #endif /* FMT_RGB24 */
773 #if defined(FMT_RGB24) || defined(FMT_RGBA32)
775 static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, const AVPicture *src,
776 int width, int height)
778 const unsigned char *p;
779 unsigned char *q;
780 int dst_wrap, src_wrap;
781 int x, y, has_alpha;
782 unsigned int r, g, b;
784 p = src->data[0];
785 src_wrap = src->linesize[0] - BPP * width;
787 q = dst->data[0];
788 dst_wrap = dst->linesize[0] - width;
789 has_alpha = 0;
791 for(y=0;y<height;y++) {
792 for(x=0;x<width;x++) {
793 #ifdef RGBA_IN
795 unsigned int a;
796 RGBA_IN(r, g, b, a, p);
797 /* crude approximation for alpha ! */
798 if (a < 0x80) {
799 has_alpha = 1;
800 q[0] = TRANSP_INDEX;
801 } else {
802 q[0] = gif_clut_index(r, g, b);
805 #else
806 RGB_IN(r, g, b, p);
807 q[0] = gif_clut_index(r, g, b);
808 #endif
809 q++;
810 p += BPP;
812 p += src_wrap;
813 q += dst_wrap;
816 build_rgb_palette(dst->data[1], has_alpha);
819 #endif /* defined(FMT_RGB24) || defined(FMT_RGBA32) */
821 #ifdef RGBA_IN
823 static int glue(get_alpha_info_, RGB_NAME)(const AVPicture *src,
824 int width, int height)
826 const unsigned char *p;
827 int src_wrap, ret, x, y;
828 unsigned int r, g, b, a;
830 p = src->data[0];
831 src_wrap = src->linesize[0] - BPP * width;
832 ret = 0;
833 for(y=0;y<height;y++) {
834 for(x=0;x<width;x++) {
835 RGBA_IN(r, g, b, a, p);
836 if (a == 0x00) {
837 ret |= FF_ALPHA_TRANSP;
838 } else if (a != 0xff) {
839 ret |= FF_ALPHA_SEMI_TRANSP;
841 p += BPP;
843 p += src_wrap;
845 return ret;
848 #endif /* RGBA_IN */
850 #undef RGB_IN
851 #undef RGBA_IN
852 #undef RGB_OUT
853 #undef RGBA_OUT
854 #undef BPP
855 #undef RGB_NAME
856 #undef FMT_RGB24
857 #undef FMT_RGBA32