2 * Misc image conversion 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
22 * Misc image conversion routines.
26 * - write 'ffimg' program to test all the image related stuff
27 * - move all api to slice based system
28 * - integrate deinterlacing, postprocessing and scaling in the conversion process
33 #include "gstffmpegcodecmap.h"
38 GST_DEBUG_CATEGORY_EXTERN (ffmpegcolorspace_performance);
40 #define xglue(x, y) x ## y
41 #define glue(x, y) xglue(x, y)
43 /* this table gives more information about formats */
44 /* FIXME, this table is also in ffmpegcodecmap */
45 static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
47 /* [PIX_FMT_YUV420P] = */ {
48 /* .format = */ PIX_FMT_YUV420P,
49 /* .name = */ "yuv420p",
50 /* .nb_channels = */ 3,
51 /* .color_type = */ FF_COLOR_YUV,
52 /* .pixel_type = */ FF_PIXEL_PLANAR,
54 /* .x_chroma_shift = */ 1,
55 /* .y_chroma_shift = */ 1,
58 /* [PIX_FMT_YVU420P] = */ {
59 /* .format = */ PIX_FMT_YVU420P,
60 /* .name = */ "yvu420p",
61 /* .nb_channels = */ 3,
62 /* .color_type = */ FF_COLOR_YUV,
63 /* .pixel_type = */ FF_PIXEL_PLANAR,
65 /* .x_chroma_shift = */ 1,
66 /* .y_chroma_shift = */ 1,
69 /* [PIX_FMT_NV12] = */ {
70 /* .format = */ PIX_FMT_NV12,
72 /* .nb_channels = */ 2,
73 /* .color_type = */ FF_COLOR_YUV,
74 /* .pixel_type = */ FF_PIXEL_PACKED,
76 /* .x_chroma_shift = */ 1,
77 /* .y_chroma_shift = */ 1,
80 /* [PIX_FMT_NV21] = */ {
81 /* .format = */ PIX_FMT_NV21,
83 /* .nb_channels = */ 2,
84 /* .color_type = */ FF_COLOR_YUV,
85 /* .pixel_type = */ FF_PIXEL_PACKED,
87 /* .x_chroma_shift = */ 1,
88 /* .y_chroma_shift = */ 1,
91 /* [PIX_FMT_YUV422P] = */ {
92 /* .format = */ PIX_FMT_YUV422P,
93 /* .name = */ "yuv422p",
94 /* .nb_channels = */ 3,
95 /* .color_type = */ FF_COLOR_YUV,
96 /* .pixel_type = */ FF_PIXEL_PLANAR,
98 /* .x_chroma_shift = */ 1,
99 /* .y_chroma_shift = */ 0,
102 /* [PIX_FMT_YUV444P] = */ {
103 /* .format = */ PIX_FMT_YUV444P,
104 /* .name = */ "yuv444p",
105 /* .nb_channels = */ 3,
106 /* .color_type = */ FF_COLOR_YUV,
107 /* .pixel_type = */ FF_PIXEL_PLANAR,
109 /* .x_chroma_shift = */ 0,
110 /* .y_chroma_shift = */ 0,
113 /* [PIX_FMT_YUV422] = */ {
114 /* .format = */ PIX_FMT_YUV422,
115 /* .name = */ "yuv422",
116 /* .nb_channels = */ 1,
117 /* .color_type = */ FF_COLOR_YUV,
118 /* .pixel_type = */ FF_PIXEL_PACKED,
120 /* .x_chroma_shift = */ 1,
121 /* .y_chroma_shift = */ 0,
124 /* [PIX_FMT_UYVY422] = */ {
125 /* .format = */ PIX_FMT_UYVY422,
126 /* .name = */ "uyvy422",
127 /* .nb_channels = */ 1,
128 /* .color_type = */ FF_COLOR_YUV,
129 /* .pixel_type = */ FF_PIXEL_PACKED,
131 /* .x_chroma_shift = */ 1,
132 /* .y_chroma_shift = */ 0,
135 /* [PIX_FMT_YVYU422] = */ {
136 /* .format = */ PIX_FMT_YVYU422,
137 /* .name = */ "yvyu422",
138 /* .nb_channels = */ 1,
139 /* .color_type = */ FF_COLOR_YUV,
140 /* .pixel_type = */ FF_PIXEL_PACKED,
142 /* .x_chroma_shift = */ 1,
143 /* .y_chroma_shift = */ 0,
146 /* [PIX_FMT_V308] = */ {
147 /* .format = */ PIX_FMT_V308,
148 /* .name = */ "v308",
149 /* .nb_channels = */ 1,
150 /* .color_type = */ FF_COLOR_YUV,
151 /* .pixel_type = */ FF_PIXEL_PACKED,
153 /* .x_chroma_shift = */ 0,
154 /* .y_chroma_shift = */ 0,
157 /* [PIX_FMT_YUV410P] = */ {
158 /* .format = */ PIX_FMT_YUV410P,
159 /* .name = */ "yuv410p",
160 /* .nb_channels = */ 3,
161 /* .color_type = */ FF_COLOR_YUV,
162 /* .pixel_type = */ FF_PIXEL_PLANAR,
164 /* .x_chroma_shift = */ 2,
165 /* .y_chroma_shift = */ 2,
168 /* [PIX_FMT_YVU410P] = */ {
169 /* .format = */ PIX_FMT_YVU410P,
170 /* .name = */ "yvu410p",
171 /* .nb_channels = */ 3,
172 /* .color_type = */ FF_COLOR_YUV,
173 /* .pixel_type = */ FF_PIXEL_PLANAR,
175 /* .x_chroma_shift = */ 2,
176 /* .y_chroma_shift = */ 2,
179 /* [PIX_FMT_YUV411P] = */ {
180 /* .format = */ PIX_FMT_YUV411P,
181 /* .name = */ "yuv411p",
182 /* .nb_channels = */ 3,
183 /* .color_type = */ FF_COLOR_YUV,
184 /* .pixel_type = */ FF_PIXEL_PLANAR,
186 /* .x_chroma_shift = */ 2,
187 /* .y_chroma_shift = */ 0,
190 /* [PIX_FMT_Y800] = */ {
191 /* .format = */ PIX_FMT_Y800,
192 /* .name = */ "y800",
193 /* .nb_channels = */ 1,
194 /* .color_type = */ FF_COLOR_YUV,
195 /* .pixel_type = */ FF_PIXEL_PLANAR,
197 /* .x_chroma_shift = */ 0,
198 /* .y_chroma_shift = */ 0,
201 /* [PIX_FMT_Y16] = */ {
202 /* .format = */ PIX_FMT_Y16,
204 /* .nb_channels = */ 1,
205 /* .color_type = */ FF_COLOR_YUV,
206 /* .pixel_type = */ FF_PIXEL_PLANAR,
208 /* .x_chroma_shift = */ 0,
209 /* .y_chroma_shift = */ 0,
214 /* [PIX_FMT_YUVJ420P] = */ {
215 /* .format = */ PIX_FMT_YUVJ420P,
216 /* .name = */ "yuvj420p",
217 /* .nb_channels = */ 3,
218 /* .color_type = */ FF_COLOR_YUV_JPEG,
219 /* .pixel_type = */ FF_PIXEL_PLANAR,
221 /* .x_chroma_shift = */ 1,
222 /* .y_chroma_shift = */ 1,
225 /* [PIX_FMT_YUVJ422P] = */ {
226 /* .format = */ PIX_FMT_YUVJ422P,
227 /* .name = */ "yuvj422p",
228 /* .nb_channels = */ 3,
229 /* .color_type = */ FF_COLOR_YUV_JPEG,
230 /* .pixel_type = */ FF_PIXEL_PLANAR,
232 /* .x_chroma_shift = */ 1,
233 /* .y_chroma_shift = */ 0,
236 /* [PIX_FMT_YUVJ444P] = */ {
237 /* .format = */ PIX_FMT_YUVJ444P,
238 /* .name = */ "yuvj444p",
239 /* .nb_channels = */ 3,
240 /* .color_type = */ FF_COLOR_YUV_JPEG,
241 /* .pixel_type = */ FF_PIXEL_PLANAR,
243 /* .x_chroma_shift = */ 0,
244 /* .y_chroma_shift = */ 0,
249 /* [PIX_FMT_RGB24] = */ {
250 /* .format = */ PIX_FMT_RGB24,
251 /* .name = */ "rgb24",
252 /* .nb_channels = */ 3,
253 /* .color_type = */ FF_COLOR_RGB,
254 /* .pixel_type = */ FF_PIXEL_PACKED,
256 /* .x_chroma_shift = */ 0,
257 /* .y_chroma_shift = */ 0,
260 /* [PIX_FMT_BGR24] = */ {
261 /* .format = */ PIX_FMT_BGR24,
262 /* .name = */ "bgr24",
263 /* .nb_channels = */ 3,
264 /* .color_type = */ FF_COLOR_RGB,
265 /* .pixel_type = */ FF_PIXEL_PACKED,
267 /* .x_chroma_shift = */ 0,
268 /* .y_chroma_shift = */ 0,
271 /* [PIX_FMT_RGB32] = */ {
272 /* .format = */ PIX_FMT_RGB32,
273 /* .name = */ "rgb32",
274 /* .nb_channels = */ 4,
275 /* .color_type = */ FF_COLOR_RGB,
276 /* .pixel_type = */ FF_PIXEL_PACKED,
278 /* .x_chroma_shift = */ 0,
279 /* .y_chroma_shift = */ 0,
282 /* [PIX_FMT_BGR32] = */ {
283 /* .format = */ PIX_FMT_BGR32,
284 /* .name = */ "bgr32",
285 /* .nb_channels = */ 4,
286 /* .color_type = */ FF_COLOR_RGB,
287 /* .pixel_type = */ FF_PIXEL_PACKED,
289 /* .x_chroma_shift = */ 0,
290 /* .y_chroma_shift = */ 0,
293 /* [PIX_FMT_RGB32] = */ {
294 /* .format = */ PIX_FMT_xRGB32,
295 /* .name = */ "xrgb32",
296 /* .nb_channels = */ 4,
297 /* .color_type = */ FF_COLOR_RGB,
298 /* .pixel_type = */ FF_PIXEL_PACKED,
300 /* .x_chroma_shift = */ 0,
301 /* .y_chroma_shift = */ 0,
304 /* [PIX_FMT_BGR32] = */ {
305 /* .format = */ PIX_FMT_BGRx32,
306 /* .name = */ "bgrx32",
307 /* .nb_channels = */ 4,
308 /* .color_type = */ FF_COLOR_RGB,
309 /* .pixel_type = */ FF_PIXEL_PACKED,
311 /* .x_chroma_shift = */ 0,
312 /* .y_chroma_shift = */ 0,
315 /* [PIX_FMT_RGBA32] = */ {
316 /* .format = */ PIX_FMT_RGBA32,
317 /* .name = */ "rgba32",
318 /* .nb_channels = */ 4,
319 /* .color_type = */ FF_COLOR_RGB,
320 /* .pixel_type = */ FF_PIXEL_PACKED,
322 /* .x_chroma_shift = */ 0,
323 /* .y_chroma_shift = */ 0,
326 /* [PIX_FMT_BGRA32] = */ {
327 /* .format = */ PIX_FMT_BGRA32,
328 /* .name = */ "bgra32",
329 /* .nb_channels = */ 4,
330 /* .color_type = */ FF_COLOR_RGB,
331 /* .pixel_type = */ FF_PIXEL_PACKED,
333 /* .x_chroma_shift = */ 0,
334 /* .y_chroma_shift = */ 0,
337 /* [PIX_FMT_ARGB32] = */ {
338 /* .format = */ PIX_FMT_ARGB32,
339 /* .name = */ "argb32",
340 /* .nb_channels = */ 4,
341 /* .color_type = */ FF_COLOR_RGB,
342 /* .pixel_type = */ FF_PIXEL_PACKED,
344 /* .x_chroma_shift = */ 0,
345 /* .y_chroma_shift = */ 0,
348 /* [PIX_FMT_ABGR32] = */ {
349 /* .format = */ PIX_FMT_ABGR32,
350 /* .name = */ "abgr32",
351 /* .nb_channels = */ 4,
352 /* .color_type = */ FF_COLOR_RGB,
353 /* .pixel_type = */ FF_PIXEL_PACKED,
355 /* .x_chroma_shift = */ 0,
356 /* .y_chroma_shift = */ 0,
359 /* [PIX_FMT_RGB565] = */ {
360 /* .format = */ PIX_FMT_RGB565,
361 /* .name = */ "rgb565",
362 /* .nb_channels = */ 3,
363 /* .color_type = */ FF_COLOR_RGB,
364 /* .pixel_type = */ FF_PIXEL_PACKED,
366 /* .x_chroma_shift = */ 0,
367 /* .y_chroma_shift = */ 0,
370 /* [PIX_FMT_RGB555] = */ {
371 /* .format = */ PIX_FMT_RGB555,
372 /* .name = */ "rgb555",
373 /* .nb_channels = */ 4,
374 /* .color_type = */ FF_COLOR_RGB,
375 /* .pixel_type = */ FF_PIXEL_PACKED,
377 /* .x_chroma_shift = */ 0,
378 /* .y_chroma_shift = */ 0,
382 /* gray / mono formats */
383 /* [PIX_FMT_GRAY8] = */ {
384 /* .format = */ PIX_FMT_GRAY8,
385 /* .name = */ "gray",
386 /* .nb_channels = */ 1,
387 /* .color_type = */ FF_COLOR_GRAY,
388 /* .pixel_type = */ FF_PIXEL_PLANAR,
390 /* .x_chroma_shift = */ 0,
391 /* .y_chroma_shift = */ 0,
394 /* [PIX_FMT_GRAY16_L] = */ {
395 /* .format = */ PIX_FMT_GRAY16_L,
396 /* .name = */ "gray",
397 /* .nb_channels = */ 1,
398 /* .color_type = */ FF_COLOR_GRAY,
399 /* .pixel_type = */ FF_PIXEL_PLANAR,
401 /* .x_chroma_shift = */ 0,
402 /* .y_chroma_shift = */ 0,
405 /* [PIX_FMT_GRAY16_B] = */ {
406 /* .format = */ PIX_FMT_GRAY16_B,
407 /* .name = */ "gray",
408 /* .nb_channels = */ 1,
409 /* .color_type = */ FF_COLOR_GRAY,
410 /* .pixel_type = */ FF_PIXEL_PLANAR,
412 /* .x_chroma_shift = */ 0,
413 /* .y_chroma_shift = */ 0,
416 /* [PIX_FMT_MONOWHITE] = */ {
417 /* .format = */ PIX_FMT_MONOWHITE,
418 /* .name = */ "monow",
419 /* .nb_channels = */ 1,
420 /* .color_type = */ FF_COLOR_GRAY,
421 /* .pixel_type = */ FF_PIXEL_PLANAR,
423 /* .x_chroma_shift = */ 0,
424 /* .y_chroma_shift = */ 0,
427 /* [PIX_FMT_MONOBLACK] = */ {
428 /* .format = */ PIX_FMT_MONOBLACK,
429 /* .name = */ "monob",
430 /* .nb_channels = */ 1,
431 /* .color_type = */ FF_COLOR_GRAY,
432 /* .pixel_type = */ FF_PIXEL_PLANAR,
434 /* .x_chroma_shift = */ 0,
435 /* .y_chroma_shift = */ 0,
439 /* paletted formats */
440 /* [PIX_FMT_PAL8] = */ {
441 /* .format = */ PIX_FMT_PAL8,
442 /* .name = */ "pal8",
443 /* .nb_channels = */ 4,
444 /* .color_type = */ FF_COLOR_RGB,
445 /* .pixel_type = */ FF_PIXEL_PALETTE,
447 /* .x_chroma_shift = */ 0,
448 /* .y_chroma_shift = */ 0,
451 /* [PIX_FMT_XVMC_MPEG2_MC] = */ {
452 /* .format = */ PIX_FMT_XVMC_MPEG2_MC,
453 /* .name = */ "xvmcmc",
455 /* [PIX_FMT_XVMC_MPEG2_IDCT] = */ {
456 /* .format = */ PIX_FMT_XVMC_MPEG2_IDCT,
457 /* .name = */ "xvmcidct",
459 /* [PIX_FMT_UYVY411] = */ {
460 /* .format = */ PIX_FMT_UYVY411,
461 /* .name = */ "uyvy411",
462 /* .nb_channels = */ 1,
463 /* .color_type = */ FF_COLOR_YUV,
464 /* .pixel_type = */ FF_PIXEL_PACKED,
466 /* .x_chroma_shift = */ 2,
467 /* .y_chroma_shift = */ 0,
470 /* [PIX_FMT_AYUV4444] = */ {
471 /* .format = */ PIX_FMT_AYUV4444,
472 /* .name = */ "ayuv4444",
473 /* .nb_channels = */ 1,
474 /* .color_type = */ FF_COLOR_YUV,
475 /* .pixel_type = */ FF_PIXEL_PACKED,
477 /* .x_chroma_shift = */ 0,
478 /* .y_chroma_shift = */ 0,
481 /* [PIX_FMT_YUVA420P] = */ {
482 /* .format = */ PIX_FMT_YUVA420P,
483 /* .name = */ "yuva420p",
484 /* .nb_channels = */ 4,
485 /* .color_type = */ FF_COLOR_YUV,
486 /* .pixel_type = */ FF_PIXEL_PLANAR,
488 /* .x_chroma_shift = */ 1,
489 /* .y_chroma_shift = */ 1,
494 /* returns NULL if not found */
495 /* undid static since this is also used in gstffmpegcodecmap.c */
497 get_pix_fmt_info (enum PixelFormat format)
501 for (i = 0; i < sizeof (pix_fmt_info) / sizeof (pix_fmt_info[0]); i++) {
502 if (pix_fmt_info[i].format == format) {
503 return pix_fmt_info + i;
507 /* since this doesn't get checked *anywhere*, we might as well warn
508 here if we return NULL so you have *some* idea what's going on */
510 ("Could not find info for pixel format %d out of %d known pixel formats. One segfault coming up",
516 avcodec_get_chroma_sub_sample (int pix_fmt, int *h_shift, int *v_shift)
518 *h_shift = get_pix_fmt_info (pix_fmt)->x_chroma_shift;
519 *v_shift = get_pix_fmt_info (pix_fmt)->y_chroma_shift;
523 avcodec_get_pix_fmt_name (int pix_fmt)
525 if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
528 return get_pix_fmt_info (pix_fmt)->name;
532 avcodec_get_pix_fmt (const char *name)
536 for (i = 0; i < PIX_FMT_NB; i++)
537 if (!strcmp (pix_fmt_info[i].name, name))
539 return pix_fmt_info[i].format;
544 avpicture_layout (const AVPicture * src, int pix_fmt, int width, int height,
545 unsigned char *dest, int dest_size)
547 PixFmtInfo *pf = get_pix_fmt_info (pix_fmt);
548 int i, j, w, h, data_planes;
549 const unsigned char *s;
550 int size = avpicture_get_size (pix_fmt, width, height);
552 if (size > dest_size)
555 if (pf->pixel_type == FF_PIXEL_PACKED || pf->pixel_type == FF_PIXEL_PALETTE) {
556 if (pix_fmt == PIX_FMT_YUV422 ||
557 pix_fmt == PIX_FMT_UYVY422 ||
558 pix_fmt == PIX_FMT_RGB565 || pix_fmt == PIX_FMT_RGB555)
560 else if (pix_fmt == PIX_FMT_UYVY411)
561 w = width + width / 2;
562 else if (pix_fmt == PIX_FMT_PAL8)
565 w = width * (pf->depth * pf->nb_channels / 8);
570 data_planes = pf->nb_channels;
571 w = (width * pf->depth + 7) / 8;
575 for (i = 0; i < data_planes; i++) {
577 w = width >> pf->x_chroma_shift;
578 h = height >> pf->y_chroma_shift;
581 for (j = 0; j < h; j++) {
584 s += src->linesize[i];
588 if (pf->pixel_type == FF_PIXEL_PALETTE)
589 memcpy ((unsigned char *) (((size_t) dest + 3) & ~3), src->data[1],
597 avpicture_get_size (int pix_fmt, int width, int height)
599 AVPicture dummy_pict;
601 return gst_ffmpegcsp_avpicture_fill (&dummy_pict, NULL, pix_fmt, width,
606 * compute the loss when converting from a pixel format to another
609 avcodec_get_pix_fmt_loss (int dst_pix_fmt, int src_pix_fmt, int has_alpha)
611 const PixFmtInfo *pf, *ps;
614 ps = get_pix_fmt_info (src_pix_fmt);
615 pf = get_pix_fmt_info (dst_pix_fmt);
619 if (pf->depth < ps->depth ||
620 (dst_pix_fmt == PIX_FMT_RGB555 && src_pix_fmt == PIX_FMT_RGB565))
621 loss |= FF_LOSS_DEPTH;
622 if (pf->x_chroma_shift > ps->x_chroma_shift ||
623 pf->y_chroma_shift > ps->y_chroma_shift)
624 loss |= FF_LOSS_RESOLUTION;
625 switch (pf->color_type) {
627 if (ps->color_type != FF_COLOR_RGB && ps->color_type != FF_COLOR_GRAY)
628 loss |= FF_LOSS_COLORSPACE;
631 if (ps->color_type != FF_COLOR_GRAY)
632 loss |= FF_LOSS_COLORSPACE;
635 if (ps->color_type != FF_COLOR_YUV)
636 loss |= FF_LOSS_COLORSPACE;
638 case FF_COLOR_YUV_JPEG:
639 if (ps->color_type != FF_COLOR_YUV_JPEG &&
640 ps->color_type != FF_COLOR_YUV && ps->color_type != FF_COLOR_GRAY)
641 loss |= FF_LOSS_COLORSPACE;
645 if (ps->color_type != pf->color_type)
646 loss |= FF_LOSS_COLORSPACE;
649 if (pf->color_type == FF_COLOR_GRAY && ps->color_type != FF_COLOR_GRAY)
650 loss |= FF_LOSS_CHROMA;
651 if (!pf->is_alpha && (ps->is_alpha && has_alpha))
652 loss |= FF_LOSS_ALPHA;
653 if (pf->pixel_type == FF_PIXEL_PALETTE &&
654 (ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY))
655 loss |= FF_LOSS_COLORQUANT;
660 avg_bits_per_pixel (int pix_fmt)
663 const PixFmtInfo *pf;
665 pf = get_pix_fmt_info (pix_fmt);
666 switch (pf->pixel_type) {
667 case FF_PIXEL_PACKED:
670 case PIX_FMT_UYVY422:
671 case PIX_FMT_YVYU422:
676 case PIX_FMT_UYVY411:
680 bits = pf->depth * pf->nb_channels;
684 case FF_PIXEL_PLANAR:
685 if (pf->x_chroma_shift == 0 && pf->y_chroma_shift == 0) {
686 bits = pf->depth * pf->nb_channels;
688 bits = pf->depth + ((2 * pf->depth) >>
689 (pf->x_chroma_shift + pf->y_chroma_shift));
692 case FF_PIXEL_PALETTE:
703 avcodec_find_best_pix_fmt1 (int pix_fmt_mask,
704 int src_pix_fmt, int has_alpha, int loss_mask)
706 int dist, i, loss, min_dist, dst_pix_fmt;
708 /* find exact color match with smallest size */
710 min_dist = 0x7fffffff;
711 for (i = 0; i < PIX_FMT_NB; i++) {
712 if (pix_fmt_mask & (1 << i)) {
713 loss = avcodec_get_pix_fmt_loss (i, src_pix_fmt, has_alpha) & loss_mask;
715 dist = avg_bits_per_pixel (i);
716 if (dist < min_dist) {
727 * find best pixel format to convert to. Return -1 if none found
730 avcodec_find_best_pix_fmt (int pix_fmt_mask, int src_pix_fmt,
731 int has_alpha, int *loss_ptr)
733 int dst_pix_fmt, loss_mask, i;
734 static const int loss_mask_order[] = {
735 ~0, /* no loss first */
738 ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION),
744 /* try with successive loss */
747 loss_mask = loss_mask_order[i++];
748 dst_pix_fmt = avcodec_find_best_pix_fmt1 (pix_fmt_mask, src_pix_fmt,
749 has_alpha, loss_mask);
750 if (dst_pix_fmt >= 0)
758 *loss_ptr = avcodec_get_pix_fmt_loss (dst_pix_fmt, src_pix_fmt, has_alpha);
763 img_copy_plane (uint8_t * dst, int dst_wrap,
764 const uint8_t * src, int src_wrap, int width, int height)
766 for (; height > 0; height--) {
767 memcpy (dst, src, width);
774 * Copy image 'src' to 'dst'.
777 img_copy (AVPicture * dst, const AVPicture * src,
778 int pix_fmt, int width, int height)
781 const PixFmtInfo *pf;
783 pf = get_pix_fmt_info (pix_fmt);
784 switch (pf->pixel_type) {
785 case FF_PIXEL_PACKED:
788 case PIX_FMT_UYVY422:
789 case PIX_FMT_YVYU422:
794 case PIX_FMT_UYVY411:
798 bits = pf->depth * pf->nb_channels;
801 bwidth = (width * bits + 7) >> 3;
802 img_copy_plane (dst->data[0], dst->linesize[0],
803 src->data[0], src->linesize[0], bwidth, height);
805 case FF_PIXEL_PLANAR:
806 for (i = 0; i < pf->nb_channels; i++) {
811 if (i == 1 || i == 2) {
812 w >>= pf->x_chroma_shift;
813 h >>= pf->y_chroma_shift;
815 bwidth = (w * pf->depth + 7) >> 3;
816 img_copy_plane (dst->data[i], dst->linesize[i],
817 src->data[i], src->linesize[i], bwidth, h);
820 case FF_PIXEL_PALETTE:
821 img_copy_plane (dst->data[0], dst->linesize[0],
822 src->data[0], src->linesize[0], width, height);
823 /* copy the palette */
824 img_copy_plane (dst->data[1], dst->linesize[1],
825 src->data[1], src->linesize[1], 4, 256);
830 /* XXX: totally non optimized */
833 yuv422_to_yuv420p (AVPicture * dst, const AVPicture * src,
834 int width, int height)
836 const uint8_t *p, *p1;
837 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
845 for (; height >= 1; height -= 2) {
850 for (w = width; w >= 2; w -= 2) {
865 p1 += src->linesize[0];
866 lum1 += dst->linesize[0];
870 for (w = width; w >= 2; w -= 2) {
879 p1 += src->linesize[0];
880 lum1 += dst->linesize[0];
882 cb1 += dst->linesize[1];
883 cr1 += dst->linesize[2];
888 uyvy422_to_gray (AVPicture * dst, const AVPicture * src, int width, int height)
890 const uint8_t *p, *p1;
896 for (; height > 0; height--) {
900 for (w = width; w >= 2; w -= 2) {
910 p1 += src->linesize[0];
911 lum1 += dst->linesize[0];
917 uyvy422_to_yuv420p (AVPicture * dst, const AVPicture * src,
918 int width, int height)
920 const uint8_t *p, *p1;
921 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
930 for (; height >= 1; height -= 2) {
935 for (w = width; w >= 2; w -= 2) {
950 p1 += src->linesize[0];
951 lum1 += dst->linesize[0];
955 for (w = width; w >= 2; w -= 2) {
964 p1 += src->linesize[0];
965 lum1 += dst->linesize[0];
967 cb1 += dst->linesize[1];
968 cr1 += dst->linesize[2];
974 uyvy422_to_yuv422p (AVPicture * dst, const AVPicture * src,
975 int width, int height)
977 const uint8_t *p, *p1;
978 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
985 for (; height > 0; height--) {
990 for (w = width; w >= 2; w -= 2) {
1005 p1 += src->linesize[0];
1006 lum1 += dst->linesize[0];
1007 cb1 += dst->linesize[1];
1008 cr1 += dst->linesize[2];
1013 yvyu422_to_gray (AVPicture * dst, const AVPicture * src, int width, int height)
1015 const uint8_t *p, *p1;
1016 uint8_t *lum, *lum1;
1020 lum1 = dst->data[0];
1021 for (; height > 0; height--) {
1025 for (w = width; w >= 2; w -= 2) {
1035 p1 += src->linesize[0];
1036 lum1 += dst->linesize[0];
1041 yvyu422_to_yuv420p (AVPicture * dst, const AVPicture * src,
1042 int width, int height)
1044 const uint8_t *p, *p1;
1045 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
1050 lum1 = dst->data[0];
1054 for (; height >= 1; height -= 2) {
1059 for (w = width; w >= 2; w -= 2) {
1074 p1 += src->linesize[0];
1075 lum1 += dst->linesize[0];
1079 for (w = width; w >= 2; w -= 2) {
1088 p1 += src->linesize[0];
1089 lum1 += dst->linesize[0];
1091 cb1 += dst->linesize[1];
1092 cr1 += dst->linesize[2];
1097 yvyu422_to_yuv422p (AVPicture * dst, const AVPicture * src,
1098 int width, int height)
1100 const uint8_t *p, *p1;
1101 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
1105 lum1 = dst->data[0];
1108 for (; height > 0; height--) {
1113 for (w = width; w >= 2; w -= 2) {
1128 p1 += src->linesize[0];
1129 lum1 += dst->linesize[0];
1130 cb1 += dst->linesize[1];
1131 cr1 += dst->linesize[2];
1136 yuv422_to_yuv422p (AVPicture * dst, const AVPicture * src,
1137 int width, int height)
1139 const uint8_t *p, *p1;
1140 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
1144 lum1 = dst->data[0];
1147 for (; height > 0; height--) {
1152 for (w = width; w >= 2; w -= 2) {
1167 p1 += src->linesize[0];
1168 lum1 += dst->linesize[0];
1169 cb1 += dst->linesize[1];
1170 cr1 += dst->linesize[2];
1175 yuv422p_to_yuv422 (AVPicture * dst, const AVPicture * src,
1176 int width, int height)
1179 const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
1183 lum1 = src->data[0];
1186 for (; height > 0; height--) {
1191 for (w = width; w >= 2; w -= 2) {
1206 p1 += dst->linesize[0];
1207 lum1 += src->linesize[0];
1208 cb1 += src->linesize[1];
1209 cr1 += src->linesize[2];
1214 yuv422p_to_uyvy422 (AVPicture * dst, const AVPicture * src,
1215 int width, int height)
1218 const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
1222 lum1 = src->data[0];
1225 for (; height > 0; height--) {
1230 for (w = width; w >= 2; w -= 2) {
1245 p1 += dst->linesize[0];
1246 lum1 += src->linesize[0];
1247 cb1 += src->linesize[1];
1248 cr1 += src->linesize[2];
1253 yuv422p_to_yvyu422 (AVPicture * dst, const AVPicture * src,
1254 int width, int height)
1257 const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
1261 lum1 = src->data[0];
1264 for (; height > 0; height--) {
1269 for (w = width; w >= 2; w -= 2) {
1284 p1 += dst->linesize[0];
1285 lum1 += src->linesize[0];
1286 cb1 += src->linesize[1];
1287 cr1 += src->linesize[2];
1292 uyvy411_to_yuv411p (AVPicture * dst, const AVPicture * src,
1293 int width, int height)
1295 const uint8_t *p, *p1;
1296 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
1300 lum1 = dst->data[0];
1303 for (; height > 0; height--) {
1308 for (w = width; w >= 4; w -= 4) {
1320 p1 += src->linesize[0];
1321 lum1 += dst->linesize[0];
1322 cb1 += dst->linesize[1];
1323 cr1 += dst->linesize[2];
1328 yuv411p_to_uyvy411 (AVPicture * dst, const AVPicture * src,
1329 int width, int height)
1332 const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
1336 lum1 = src->data[0];
1339 for (; height > 0; height--) {
1344 for (w = width; w >= 4; w -= 4) {
1356 p1 += dst->linesize[0];
1357 lum1 += src->linesize[0];
1358 cb1 += src->linesize[1];
1359 cr1 += src->linesize[2];
1364 yuv420p_to_yuv422 (AVPicture * dst, const AVPicture * src,
1365 int width, int height)
1368 uint8_t *line1, *line2, *linesrc = dst->data[0];
1369 uint8_t *lum1, *lum2, *lumsrc = src->data[0];
1370 uint8_t *cb1, *cb2 = src->data[1];
1371 uint8_t *cr1, *cr2 = src->data[2];
1373 for (h = height / 2; h--;) {
1375 line2 = linesrc + dst->linesize[0];
1378 lum2 = lumsrc + src->linesize[0];
1383 for (w = width / 2; w--;) {
1386 *line1++ = *line2++ = *cb1++;
1389 *line1++ = *line2++ = *cr1++;
1392 if (width % 2 != 0) {
1395 *line1++ = *line2++ = *cb1++;
1398 linesrc += dst->linesize[0] * 2;
1399 lumsrc += src->linesize[0] * 2;
1400 cb2 += src->linesize[1];
1401 cr2 += src->linesize[2];
1404 if (height % 2 != 0) {
1410 for (w = width / 2; w--;) {
1417 if (width % 2 != 0) {
1425 nv12_to_nv21 (AVPicture * dst, const AVPicture * src, int width, int height)
1427 const uint8_t *s_c_ptr;
1431 memcpy (dst->data[0], src->data[0], src->linesize[0] * height);
1433 s_c_ptr = src->data[1];
1434 d_c_ptr = dst->data[1];
1435 c_wrap = src->linesize[1] - ((width + 1) & ~0x01);
1437 for (; height >= 2; height -= 2) {
1438 for (w = width; w >= 2; w -= 2) {
1439 d_c_ptr[0] = s_c_ptr[1];
1440 d_c_ptr[1] = s_c_ptr[0];
1445 /* handle odd width */
1447 d_c_ptr[0] = s_c_ptr[1];
1448 d_c_ptr[1] = s_c_ptr[0];
1456 /* handle odd height */
1458 for (w = width; w >= 2; w -= 2) {
1459 d_c_ptr[0] = s_c_ptr[1];
1460 d_c_ptr[1] = s_c_ptr[0];
1465 /* handle odd width */
1467 d_c_ptr[0] = s_c_ptr[1];
1468 d_c_ptr[1] = s_c_ptr[0];
1476 nv12_to_yuv444p (AVPicture * dst, const AVPicture * src, int width, int height)
1479 uint8_t *dst_lum1, *dst_lum2, *dst_line = dst->data[0];
1480 uint8_t *dst_cb1, *dst_cb2, *dst_cb_line = dst->data[1];
1481 uint8_t *dst_cr1, *dst_cr2, *dst_cr_line = dst->data[2];
1482 uint8_t *lum1, *lum2, *src_lum_line = src->data[0];
1483 uint8_t *src_c1, *src_c_line = src->data[1];
1486 for (h = height / 2; h--;) {
1487 dst_lum1 = dst_line;
1488 dst_lum2 = dst_line + dst->linesize[0];
1490 dst_cb1 = dst_cb_line;
1491 dst_cb2 = dst_cb_line + dst->linesize[1];
1492 dst_cr1 = dst_cr_line;
1493 dst_cr2 = dst_cr_line + dst->linesize[2];
1495 lum1 = src_lum_line;
1496 lum2 = src_lum_line + src->linesize[0];
1498 src_c1 = src_c_line;
1500 for (w = width / 2; w--;) {
1503 *dst_lum1++ = *lum1++;
1504 *dst_lum2++ = *lum2++;
1505 *dst_cb1++ = *dst_cb2++ = cb;
1506 *dst_cr1++ = *dst_cr2++ = cr;
1507 *dst_lum1++ = *lum1++;
1508 *dst_lum2++ = *lum2++;
1509 *dst_cb1++ = *dst_cb2++ = cb;
1510 *dst_cr1++ = *dst_cr2++ = cr;
1513 if (width % 2 != 0) {
1516 *dst_lum1++ = *lum1++;
1517 *dst_lum2++ = *lum2++;
1518 *dst_cb1++ = *dst_cb2++ = *src_c1++;
1519 *dst_cr1++ = *dst_cr2++ = *src_c1++;
1522 dst_line += dst->linesize[0] * 2;
1523 dst_cb_line += dst->linesize[1] * 2;
1524 dst_cr_line += dst->linesize[2] * 2;
1525 src_lum_line += src->linesize[0] * 2;
1526 src_c_line += src->linesize[1];
1530 if (height % 2 != 0) {
1531 dst_lum1 = dst_line;
1532 lum1 = src_lum_line;
1533 src_c1 = src_c_line;
1534 dst_cb1 = dst_cb_line;
1535 dst_cr1 = dst_cr_line;
1537 for (w = width / 2; w--;) {
1540 *dst_lum1++ = *lum1++;
1543 *dst_lum1++ = *lum1++;
1548 if (width % 2 != 0) {
1551 *dst_lum1++ = *lum1++;
1558 #define nv21_to_nv12 nv12_to_nv21
1561 nv21_to_yuv444p (AVPicture * dst, const AVPicture * src, int width, int height)
1564 uint8_t *dst_lum1, *dst_lum2, *dst_line = dst->data[0];
1565 uint8_t *dst_cb1, *dst_cb2, *dst_cb_line = dst->data[1];
1566 uint8_t *dst_cr1, *dst_cr2, *dst_cr_line = dst->data[2];
1567 uint8_t *lum1, *lum2, *src_lum_line = src->data[0];
1568 uint8_t *src_c1, *src_c_line = src->data[1];
1571 for (h = height / 2; h--;) {
1572 dst_lum1 = dst_line;
1573 dst_lum2 = dst_line + dst->linesize[0];
1575 dst_cb1 = dst_cb_line;
1576 dst_cb2 = dst_cb_line + dst->linesize[1];
1577 dst_cr1 = dst_cr_line;
1578 dst_cr2 = dst_cr_line + dst->linesize[2];
1580 lum1 = src_lum_line;
1581 lum2 = src_lum_line + src->linesize[0];
1583 src_c1 = src_c_line;
1585 for (w = width / 2; w--;) {
1588 *dst_lum1++ = *lum1++;
1589 *dst_lum2++ = *lum2++;
1590 *dst_cb1++ = *dst_cb2++ = cb;
1591 *dst_cr1++ = *dst_cr2++ = cr;
1592 *dst_lum1++ = *lum1++;
1593 *dst_lum2++ = *lum2++;
1594 *dst_cb1++ = *dst_cb2++ = cb;
1595 *dst_cr1++ = *dst_cr2++ = cr;
1598 if (width % 2 != 0) {
1601 *dst_lum1++ = *lum1++;
1602 *dst_lum2++ = *lum2++;
1603 *dst_cb1++ = *dst_cb2++ = *src_c1++;
1604 *dst_cr1++ = *dst_cr2++ = *src_c1++;
1607 dst_line += dst->linesize[0] * 2;
1608 dst_cb_line += dst->linesize[1] * 2;
1609 dst_cr_line += dst->linesize[2] * 2;
1610 src_lum_line += src->linesize[0] * 2;
1611 src_c_line += src->linesize[1];
1615 if (height % 2 != 0) {
1616 dst_lum1 = dst_line;
1617 lum1 = src_lum_line;
1618 src_c1 = src_c_line;
1620 dst_cb1 = dst_cb_line;
1621 dst_cr1 = dst_cr_line;
1623 for (w = width / 2; w--;) {
1626 *dst_lum1++ = *lum1++;
1629 *dst_lum1++ = *lum1++;
1634 if (width % 2 != 0) {
1637 *dst_lum1++ = *lum1++;
1645 yuva420p_to_yuv420p (AVPicture * dst, const AVPicture * src, int width,
1648 memcpy (dst->data[0], src->data[0], dst->linesize[0] * height);
1649 memcpy (dst->data[1], src->data[1], dst->linesize[1] * ((height + 1) / 2));
1650 memcpy (dst->data[2], src->data[2], dst->linesize[2] * ((height + 1) / 2));
1654 yuva420p_to_yuv422 (AVPicture * dst, const AVPicture * src,
1655 int width, int height)
1658 uint8_t *line1, *line2, *linesrc = dst->data[0];
1659 uint8_t *lum1, *lum2, *lumsrc = src->data[0];
1660 uint8_t *cb1, *cb2 = src->data[1];
1661 uint8_t *cr1, *cr2 = src->data[2];
1663 for (h = height / 2; h--;) {
1665 line2 = linesrc + dst->linesize[0];
1668 lum2 = lumsrc + src->linesize[0];
1673 for (w = width / 2; w--;) {
1676 *line1++ = *line2++ = *cb1++;
1679 *line1++ = *line2++ = *cr1++;
1682 if (width % 2 != 0) {
1685 *line1++ = *line2++ = *cb1++;
1688 linesrc += dst->linesize[0] * 2;
1689 lumsrc += src->linesize[0] * 2;
1690 cb2 += src->linesize[1];
1691 cr2 += src->linesize[2];
1694 if (height % 2 != 0) {
1700 for (w = width / 2; w--;) {
1707 if (width % 2 != 0) {
1714 #define SCALEBITS 10
1715 #define ONE_HALF (1 << (SCALEBITS - 1))
1716 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
1718 #define YUV_TO_RGB1_CCIR(cb1, cr1)\
1722 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
1723 g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
1725 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
1728 #define YUV_TO_RGB2_CCIR(r, g, b, y1)\
1730 y = ((y1) - 16) * FIX(255.0/219.0);\
1731 r = cm[(y + r_add) >> SCALEBITS];\
1732 g = cm[(y + g_add) >> SCALEBITS];\
1733 b = cm[(y + b_add) >> SCALEBITS];\
1736 #define YUV_TO_RGB1(cb1, cr1)\
1740 r_add = FIX(1.40200) * cr + ONE_HALF;\
1741 g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
1742 b_add = FIX(1.77200) * cb + ONE_HALF;\
1745 #define YUV_TO_RGB2(r, g, b, y1)\
1747 y = (y1) << SCALEBITS;\
1748 r = cm[(y + r_add) >> SCALEBITS];\
1749 g = cm[(y + g_add) >> SCALEBITS];\
1750 b = cm[(y + b_add) >> SCALEBITS];\
1753 #define Y_CCIR_TO_JPEG(y)\
1754 cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS]
1756 #define Y_JPEG_TO_CCIR(y)\
1757 (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
1759 #define C_CCIR_TO_JPEG(y)\
1760 cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS]
1762 /* NOTE: the clamp is really necessary! */
1764 C_JPEG_TO_CCIR (int y)
1766 y = (((y - 128) * FIX (112.0 / 127.0) + (ONE_HALF +
1767 (128 << SCALEBITS))) >> SCALEBITS);
1774 #define RGB_TO_Y(r, g, b) \
1775 ((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
1776 FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
1778 #define RGB_TO_U(r1, g1, b1, shift)\
1779 (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
1780 FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1782 #define RGB_TO_V(r1, g1, b1, shift)\
1783 (((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
1784 FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1786 #define RGB_TO_Y_CCIR(r, g, b) \
1787 ((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
1788 FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
1790 #define RGB_TO_U_CCIR(r1, g1, b1, shift)\
1791 (((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
1792 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1794 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\
1795 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
1796 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1798 static uint8_t y_ccir_to_jpeg[256];
1799 static uint8_t y_jpeg_to_ccir[256];
1800 static uint8_t c_ccir_to_jpeg[256];
1801 static uint8_t c_jpeg_to_ccir[256];
1803 /* init various conversion tables */
1805 img_convert_init (void)
1808 uint8_t *cm = cropTbl + MAX_NEG_CROP;
1810 for (i = 0; i < 256; i++) {
1811 y_ccir_to_jpeg[i] = Y_CCIR_TO_JPEG (i);
1812 y_jpeg_to_ccir[i] = Y_JPEG_TO_CCIR (i);
1813 c_ccir_to_jpeg[i] = C_CCIR_TO_JPEG (i);
1814 c_jpeg_to_ccir[i] = C_JPEG_TO_CCIR (i);
1818 /* apply to each pixel the given table */
1820 img_apply_table (uint8_t * dst, int dst_wrap,
1821 const uint8_t * src, int src_wrap,
1822 int width, int height, const uint8_t * table1)
1827 const uint8_t *table;
1830 for (; height > 0; height--) {
1854 /* XXX: use generic filter ? */
1855 /* XXX: in most cases, the sampling position is incorrect */
1858 img_copy_plane_resize (uint8_t * dst, int dst_wrap, int dst_width,
1859 int dst_height, const uint8_t * src, int src_wrap, int src_width,
1862 img_copy_plane (dst, dst_wrap, src, src_wrap, dst_width, dst_height);
1867 shrink41 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
1868 const uint8_t * src, int src_wrap, int src_width, int src_height)
1874 for (; dst_height > 0; dst_height--) {
1877 for (s_w = src_width, w = dst_width; w > 0 && s_w > 3; w--, s_w -= 4) {
1878 d[0] = (s[0] + s[1] + s[2] + s[3] + 2) >> 2;
1885 d[0] = (s[0] + s[1] + s[2]) / 3;
1887 d[0] = (s[0] + s[1]) / 2;
1899 shrink21 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
1900 const uint8_t * src, int src_wrap, int src_width, int src_height)
1906 for (; dst_height > 0; dst_height--) {
1909 for (s_w = src_width, w = dst_width; w > 0 && s_w > 1; w--, s_w -= 2) {
1910 d[0] = (s[0] + s[1]) >> 1;
1915 if (w) /* s_w == 1 */
1925 shrink12 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
1926 const uint8_t * src, int src_wrap, int src_width, int src_height)
1930 const uint8_t *s1, *s2;
1932 for (; dst_height > 0; dst_height--, src_height -= 2) {
1934 s2 = s1 + (src_height > 1 ? src_wrap : 0);
1936 for (w = dst_width; w >= 4; w -= 4) {
1937 d[0] = (s1[0] + s2[0]) >> 1;
1938 d[1] = (s1[1] + s2[1]) >> 1;
1939 d[2] = (s1[2] + s2[2]) >> 1;
1940 d[3] = (s1[3] + s2[3]) >> 1;
1945 for (; w > 0; w--) {
1946 d[0] = (s1[0] + s2[0]) >> 1;
1951 src += 2 * src_wrap;
1958 shrink22 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
1959 const uint8_t * src, int src_wrap, int src_width, int src_height)
1962 const uint8_t *s1, *s2;
1965 for (; dst_height > 0; dst_height--, src_height -= 2) {
1967 s2 = s1 + (src_height > 1 ? src_wrap : 0);
1969 for (s_w = src_width, w = dst_width; w >= 4; w -= 4, s_w -= 8) {
1970 d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
1971 d[1] = (s1[2] + s1[3] + s2[2] + s2[3] + 2) >> 2;
1972 d[2] = (s1[4] + s1[5] + s2[4] + s2[5] + 2) >> 2;
1973 d[3] = (s1[6] + s1[7] + s2[6] + s2[7] + 2) >> 2;
1978 for (; w > 0 && s_w > 1; w--, s_w -= 2) {
1979 d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
1986 d[0] = (s1[0] + s2[0] + 1) >> 1;
1988 src += 2 * src_wrap;
1995 shrink44 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
1996 const uint8_t * src, int src_wrap, int src_width, int src_height)
1999 const uint8_t *s1, *s2, *s3, *s4;
2002 for (; dst_height > 0; dst_height--, src_height -= 4) {
2004 s2 = s1 + (src_height > 1 ? src_wrap : 0);
2005 s3 = s2 + (src_height > 2 ? src_wrap : 0);
2006 s4 = s3 + (src_height > 3 ? src_wrap : 0);
2008 for (s_w = src_width, w = dst_width; s_w > 3 && w > 0; w--, s_w -= 4) {
2009 d[0] = (s1[0] + s1[1] + s1[2] + s1[3] +
2010 s2[0] + s2[1] + s2[2] + s2[3] +
2011 s3[0] + s3[1] + s3[2] + s3[3] +
2012 s4[0] + s4[1] + s4[2] + s4[3] + 8) >> 4;
2022 d[0] = (s1[0] + s1[1] + s1[2] +
2023 s2[0] + s2[1] + s2[2] +
2024 s3[0] + s3[1] + s3[2] + s4[0] + s4[1] + s4[2]) / 12;
2026 d[0] = (s1[0] + s1[1] +
2027 s2[0] + s2[1] + s3[0] + s3[1] + s4[0] + s4[1]) / 8;
2029 d[0] = (s1[0] + s2[0] + s3[0] + s4[0]) / 4;
2032 src += 4 * src_wrap;
2038 grow21_line (uint8_t * dst, const uint8_t * src, int width)
2046 for (w = width; w >= 4; w -= 4) {
2047 d[1] = d[0] = s1[0];
2048 d[3] = d[2] = s1[1];
2052 for (; w >= 2; w -= 2) {
2053 d[1] = d[0] = s1[0];
2057 /* only needed if width is not a multiple of two */
2064 grow41_line (uint8_t * dst, const uint8_t * src, int width)
2072 for (w = width; w >= 4; w -= 4) {
2081 for (; w > 0; w--) {
2089 grow21 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
2090 const uint8_t * src, int src_wrap, int src_width, int src_height)
2092 for (; dst_height > 0; dst_height--) {
2093 grow21_line (dst, src, dst_width);
2101 grow22 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
2102 const uint8_t * src, int src_wrap, int src_width, int src_height)
2104 for (; dst_height > 0; dst_height--) {
2105 grow21_line (dst, src, dst_width);
2114 grow41 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
2115 const uint8_t * src, int src_wrap, int src_width, int src_height)
2117 for (; dst_height > 0; dst_height--) {
2118 grow41_line (dst, src, dst_width);
2126 grow44 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
2127 const uint8_t * src, int src_wrap, int src_width, int src_height)
2129 for (; dst_height > 0; dst_height--) {
2130 grow41_line (dst, src, dst_width);
2131 if ((dst_height & 3) == 1)
2139 conv411 (uint8_t * dst, int dst_wrap, int dst_width, int dst_height,
2140 const uint8_t * src, int src_wrap, int src_width, int src_height)
2143 const uint8_t *s1, *s2;
2146 for (; dst_height > 0; dst_height--, src_height -= 2) {
2148 s2 = src + (src_height > 1 ? src_wrap : 0);
2150 for (w = dst_width; w > 1; w -= 2) {
2151 c = (s1[0] + s2[0]) >> 1;
2160 d[0] = (s1[0] + s2[0]) >> 1;
2163 src += src_wrap * 2;
2168 /* XXX: add jpeg quantize code */
2170 #define TRANSP_INDEX (6*6*6)
2172 /* this is maybe slow, but allows for extensions */
2173 static inline unsigned char
2174 gif_clut_index (uint8_t r, uint8_t g, uint8_t b)
2176 return ((((r) / 47) % 6) * 6 * 6 + (((g) / 47) % 6) * 6 + (((b) / 47) % 6));
2180 build_rgb_palette (uint8_t * palette, int has_alpha)
2183 static const uint8_t pal_value[6] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
2186 pal = (uint32_t *) palette;
2188 for (r = 0; r < 6; r++) {
2189 for (g = 0; g < 6; g++) {
2190 for (b = 0; b < 6; b++) {
2191 pal[i++] = (0xffU << 24) | (pal_value[r] << 16) |
2192 (pal_value[g] << 8) | pal_value[b];
2199 pal[i++] = 0xff000000;
2202 /* copy bit n to bits 0 ... n - 1 */
2203 static inline unsigned int
2204 bitcopy_n (unsigned int a, int n)
2208 mask = (1 << n) - 1;
2209 return (a & (0xff & ~mask)) | ((-((a >> n) & 1)) & mask);
2212 /* rgb555 handling */
2214 #define RGB_NAME rgb555
2216 #define RGB_IN(r, g, b, s)\
2218 unsigned int v = ((const uint16_t *)(s))[0];\
2219 r = bitcopy_n(v >> (10 - 3), 3);\
2220 g = bitcopy_n(v >> (5 - 3), 3);\
2221 b = bitcopy_n(v << 3, 3);\
2224 #define RGBA_IN(r, g, b, a, s)\
2226 unsigned int v = ((const uint16_t *)(s))[0];\
2227 r = bitcopy_n(v >> (10 - 3), 3);\
2228 g = bitcopy_n(v >> (5 - 3), 3);\
2229 b = bitcopy_n(v << 3, 3);\
2230 a = (-(v >> 15)) & 0xff;\
2233 #define RGBA_OUT(d, r, g, b, a)\
2235 ((uint16_t *)(d))[0] = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) | \
2236 ((a << 8) & 0x8000);\
2241 #include "imgconvert_template.h"
2243 /* rgb565 handling */
2245 #define RGB_NAME rgb565
2247 #define RGB_IN(r, g, b, s)\
2249 unsigned int v = ((const uint16_t *)(s))[0];\
2250 r = bitcopy_n(v >> (11 - 3), 3);\
2251 g = bitcopy_n(v >> (5 - 2), 2);\
2252 b = bitcopy_n(v << 3, 3);\
2255 #define RGB_OUT(d, r, g, b)\
2257 ((uint16_t *)(d))[0] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);\
2262 #include "imgconvert_template.h"
2264 /* bgr24 handling */
2266 #define RGB_NAME bgr24
2268 #define RGB_IN(r, g, b, s)\
2275 #define RGB_OUT(d, r, g, b)\
2284 #include "imgconvert_template.h"
2290 /* rgb24 handling */
2292 #define RGB_NAME rgb24
2295 #define RGB_IN(r, g, b, s)\
2302 #define RGB_OUT(d, r, g, b)\
2311 #include "imgconvert_template.h"
2313 /* rgb32 handling */
2315 #define RGB_NAME rgb32
2318 #define RGB_IN(r, g, b, s)\
2320 unsigned int v = ((const uint32_t *)(s))[0];\
2321 r = (v >> 16) & 0xff;\
2322 g = (v >> 8) & 0xff;\
2326 #define RGBA_IN(r, g, b, a, s)\
2328 unsigned int v = ((const uint32_t *)(s))[0];\
2330 r = (v >> 16) & 0xff;\
2331 g = (v >> 8) & 0xff;\
2335 #define RGBA_OUT(d, r, g, b, a)\
2337 ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;\
2342 #include "imgconvert_template.h"
2344 /* bgr32 handling */
2346 #define RGB_NAME bgr32
2348 #define RGB_IN(r, g, b, s)\
2350 unsigned int v = ((const uint32_t *)(s))[0];\
2351 r = (v >> 8) & 0xff;\
2352 g = (v >> 16) & 0xff;\
2353 b = (v >> 24) & 0xff;\
2356 #define RGBA_IN(r, g, b, a, s)\
2358 unsigned int v = ((const uint32_t *)(s))[0];\
2360 r = (v >> 8) & 0xff;\
2361 g = (v >> 16) & 0xff;\
2362 b = (v >> 24) & 0xff;\
2365 #define RGBA_OUT(d, r, g, b, a)\
2367 ((uint32_t *)(d))[0] = a | (r << 8) | (g << 16) | (b << 24);\
2372 #include "imgconvert_template.h"
2374 /* xrgb32 handling */
2376 #define RGB_NAME xrgb32
2379 #define RGB_IN(r, g, b, s)\
2381 unsigned int v = ((const uint32_t *)(s))[0];\
2382 r = (v >> 24) & 0xff;\
2383 g = (v >> 16) & 0xff;\
2384 b = (v >> 8) & 0xff;\
2387 #define RGBA_IN(r, g, b, a, s)\
2389 unsigned int v = ((const uint32_t *)(s))[0];\
2391 r = (v >> 24) & 0xff;\
2392 g = (v >> 16) & 0xff;\
2393 b = (v >> 8) & 0xff;\
2396 #define RGBA_OUT(d, r, g, b, a)\
2398 ((uint32_t *)(d))[0] = (r << 24) | (g << 16) | (b << 8) | a;\
2403 #include "imgconvert_template.h"
2405 /* bgrx32 handling */
2407 #define RGB_NAME bgrx32
2409 #define RGB_IN(r, g, b, s)\
2411 unsigned int v = ((const uint32_t *)(s))[0];\
2413 g = (v >> 8) & 0xff;\
2414 b = (v >> 16) & 0xff;\
2417 #define RGBA_IN(r, g, b, a, s)\
2419 unsigned int v = ((const uint32_t *)(s))[0];\
2422 g = (v >> 8) & 0xff;\
2423 b = (v >> 16) & 0xff;\
2426 #define RGBA_OUT(d, r, g, b, a)\
2428 ((uint32_t *)(d))[0] = r | (g << 8) | (b << 16) | (a << 24);\
2433 #include "imgconvert_template.h"
2435 /* rgba32 handling */
2437 #define RGB_NAME rgba32
2440 #define RGB_IN(r, g, b, s)\
2442 unsigned int v = ((const uint32_t *)(s))[0];\
2443 r = (v >> 16) & 0xff;\
2444 g = (v >> 8) & 0xff;\
2448 #define RGBA_IN(r, g, b, a, s)\
2450 unsigned int v = ((const uint32_t *)(s))[0];\
2451 a = (v >> 24) & 0xff;\
2452 r = (v >> 16) & 0xff;\
2453 g = (v >> 8) & 0xff;\
2457 #define RGBA_OUT(d, r, g, b, a)\
2459 ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;\
2464 #include "imgconvert_template.h"
2466 /* bgra32 handling */
2468 #define RGB_NAME bgra32
2471 #define RGB_IN(r, g, b, s)\
2473 unsigned int v = ((const uint32_t *)(s))[0];\
2474 r = (v >> 8) & 0xff;\
2475 g = (v >> 16) & 0xff;\
2476 b = (v >> 24) & 0xff;\
2479 #define RGBA_IN(r, g, b, a, s)\
2481 unsigned int v = ((const uint32_t *)(s))[0];\
2483 r = (v >> 8) & 0xff;\
2484 g = (v >> 16) & 0xff;\
2485 b = (v >> 24) & 0xff;\
2488 #define RGBA_OUT(d, r, g, b, a)\
2490 ((uint32_t *)(d))[0] = a | (r << 8) | (g << 16) | (b << 24 );\
2495 #include "imgconvert_template.h"
2497 /* argb32 handling */
2499 #define RGB_NAME argb32
2502 #define RGB_IN(r, g, b, s)\
2504 unsigned int v = ((const uint32_t *)(s))[0];\
2505 r = (v >> 24) & 0xff;\
2506 g = (v >> 16) & 0xff;\
2507 b = (v >> 8) & 0xff;\
2510 #define RGBA_IN(r, g, b, a, s)\
2512 unsigned int v = ((const uint32_t *)(s))[0];\
2513 r = (v >> 24) & 0xff;\
2514 g = (v >> 16) & 0xff;\
2515 b = (v >> 8) & 0xff;\
2519 #define RGBA_OUT(d, r, g, b, a)\
2521 ((uint32_t *)(d))[0] = (r << 24) | (g << 16) | (b << 8) | a;\
2526 #include "imgconvert_template.h"
2528 /* abgr32 handling */
2530 #define RGB_NAME abgr32
2533 #define RGB_IN(r, g, b, s)\
2535 unsigned int v = ((const uint32_t *)(s))[0];\
2537 g = (v >> 8) & 0xff;\
2538 b = (v >> 16) & 0xff;\
2541 #define RGBA_IN(r, g, b, a, s)\
2543 unsigned int v = ((const uint32_t *)(s))[0];\
2545 g = (v >> 8) & 0xff;\
2546 b = (v >> 16) & 0xff;\
2547 a = (v >> 24) & 0xff;\
2550 #define RGBA_OUT(d, r, g, b, a)\
2552 ((uint32_t *)(d))[0] = r | (g << 8) | (b << 16) | (a << 24 );\
2557 #include "imgconvert_template.h"
2560 gray_to_gray16_l (AVPicture * dst, const AVPicture * src, int width, int height)
2562 const unsigned char *p;
2564 int dst_wrap, src_wrap;
2568 src_wrap = src->linesize[0] - width;
2571 dst_wrap = dst->linesize[0] - 2 * width;
2573 for (y = 0; y < height; y++) {
2574 for (x = 0; x < width; x++) {
2575 GST_WRITE_UINT16_LE (q, (*p << 8));
2585 gray_to_gray16_b (AVPicture * dst, const AVPicture * src, int width, int height)
2587 const unsigned char *p;
2589 int dst_wrap, src_wrap;
2593 src_wrap = src->linesize[0] - width;
2596 dst_wrap = dst->linesize[0] - 2 * width;
2598 for (y = 0; y < height; y++) {
2599 for (x = 0; x < width; x++) {
2600 GST_WRITE_UINT16_BE (q, (*p << 8));
2610 gray16_l_to_gray (AVPicture * dst, const AVPicture * src, int width, int height)
2612 const unsigned char *p;
2614 int dst_wrap, src_wrap;
2618 src_wrap = src->linesize[0] - 2 * width;
2621 dst_wrap = dst->linesize[0] - width;
2623 for (y = 0; y < height; y++) {
2624 for (x = 0; x < width; x++) {
2625 q[0] = GST_READ_UINT16_LE (p) >> 8;
2635 gray16_b_to_gray (AVPicture * dst, const AVPicture * src, int width, int height)
2637 const unsigned char *p;
2639 int dst_wrap, src_wrap;
2643 src_wrap = src->linesize[0] - 2 * width;
2646 dst_wrap = dst->linesize[0] - width;
2648 for (y = 0; y < height; y++) {
2649 for (x = 0; x < width; x++) {
2650 q[0] = GST_READ_UINT16_BE (p) >> 8;
2660 gray16_b_to_gray16_l (AVPicture * dst, const AVPicture * src,
2661 int width, int height)
2663 const unsigned char *p;
2665 int dst_wrap, src_wrap;
2669 src_wrap = src->linesize[0] - 2 * width;
2672 dst_wrap = dst->linesize[0] - 2 * width;
2674 for (y = 0; y < height; y++) {
2675 for (x = 0; x < width; x++) {
2687 mono_to_gray (AVPicture * dst, const AVPicture * src,
2688 int width, int height, int xor_mask)
2690 const unsigned char *p;
2692 int v, dst_wrap, src_wrap;
2696 src_wrap = src->linesize[0] - ((width + 7) >> 3);
2699 dst_wrap = dst->linesize[0] - width;
2700 for (y = 0; y < height; y++) {
2703 v = *p++ ^ xor_mask;
2705 q[1] = -((v >> 6) & 1);
2706 q[2] = -((v >> 5) & 1);
2707 q[3] = -((v >> 4) & 1);
2708 q[4] = -((v >> 3) & 1);
2709 q[5] = -((v >> 2) & 1);
2710 q[6] = -((v >> 1) & 1);
2711 q[7] = -((v >> 0) & 1);
2716 v = *p++ ^ xor_mask;
2718 q[0] = -((v >> 7) & 1);
2729 monowhite_to_gray (AVPicture * dst, const AVPicture * src,
2730 int width, int height)
2732 mono_to_gray (dst, src, width, height, 0xff);
2736 monoblack_to_gray (AVPicture * dst, const AVPicture * src,
2737 int width, int height)
2739 mono_to_gray (dst, src, width, height, 0x00);
2743 gray_to_mono (AVPicture * dst, const AVPicture * src,
2744 int width, int height, int xor_mask)
2749 int j, b, v, n1, src_wrap, dst_wrap, y;
2752 src_wrap = src->linesize[0] - width;
2755 dst_wrap = dst->linesize[0] - ((width + 7) >> 3);
2757 for (y = 0; y < height; y++) {
2761 for (j = 0; j < 8; j++) {
2764 v = (v << 1) | (b >> 7);
2766 d[0] = v ^ xor_mask;
2776 v = (v << 1) | (b >> 7);
2779 d[0] = (v << (8 - (n1 & 7))) ^ xor_mask;
2788 gray_to_monowhite (AVPicture * dst, const AVPicture * src,
2789 int width, int height)
2791 gray_to_mono (dst, src, width, height, 0xff);
2795 gray_to_monoblack (AVPicture * dst, const AVPicture * src,
2796 int width, int height)
2798 gray_to_mono (dst, src, width, height, 0x00);
2802 y800_to_y16 (AVPicture * dst, const AVPicture * src, int width, int height)
2804 const unsigned char *p;
2806 int dst_wrap, src_wrap;
2810 src_wrap = src->linesize[0] - width;
2813 dst_wrap = dst->linesize[0] - 2 * width;
2815 for (y = 0; y < height; y++) {
2816 for (x = 0; x < width; x++) {
2817 GST_WRITE_UINT16_LE (q, (*p << 8));
2827 y16_to_y800 (AVPicture * dst, const AVPicture * src, int width, int height)
2829 const unsigned char *p;
2831 int dst_wrap, src_wrap;
2835 src_wrap = src->linesize[0] - 2 * width;
2838 dst_wrap = dst->linesize[0] - width;
2840 for (y = 0; y < height; y++) {
2841 for (x = 0; x < width; x++) {
2842 q[0] = GST_READ_UINT16_LE (p) >> 8;
2852 yuva420p_to_ayuv4444 (AVPicture * dst, const AVPicture * src,
2853 int width, int height)
2855 const uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *a1_ptr, *a2_ptr;
2856 uint8_t *d, *d1, *d2;
2860 y1_ptr = src->data[0];
2861 cb_ptr = src->data[1];
2862 cr_ptr = src->data[2];
2863 a1_ptr = src->data[3];
2864 width2 = (width + 1) >> 1;
2865 for (; height >= 2; height -= 2) {
2867 d2 = d + dst->linesize[0];
2868 y2_ptr = y1_ptr + src->linesize[0];
2869 a2_ptr = a1_ptr + src->linesize[3];
2870 for (w = width; w >= 2; w -= 2) {
2876 d1[4 + 0] = a1_ptr[1];
2877 d1[4 + 1] = y1_ptr[1];
2878 d1[4 + 2] = cb_ptr[0];
2879 d1[4 + 3] = cr_ptr[0];
2886 d2[4 + 0] = a2_ptr[1];
2887 d2[4 + 1] = y2_ptr[1];
2888 d2[4 + 2] = cb_ptr[0];
2889 d2[4 + 3] = cr_ptr[0];
2901 /* handle odd width */
2922 d += 2 * dst->linesize[0];
2923 y1_ptr += 2 * src->linesize[0] - width;
2924 cb_ptr += src->linesize[1] - width2;
2925 cr_ptr += src->linesize[2] - width2;
2926 a1_ptr += 2 * src->linesize[3] - width;
2928 /* handle odd height */
2931 for (w = width; w >= 2; w -= 2) {
2937 d1[4 + 0] = a1_ptr[1];
2938 d1[4 + 1] = y1_ptr[1];
2939 d1[4 + 2] = cb_ptr[0];
2940 d1[4 + 3] = cr_ptr[0];
2966 ayuv4444_to_yuva420p (AVPicture * dst,
2967 const AVPicture * src, int width, int height)
2969 int wrap, wrap3, width2;
2971 uint8_t *lum, *cb, *cr, *a;
2979 width2 = (width + 1) >> 1;
2980 wrap = dst->linesize[0];
2981 wrap3 = src->linesize[0];
2983 for (; height >= 2; height -= 2) {
2984 for (w = width; w >= 2; w -= 2) {
3013 p += -wrap3 + 2 * 4;
3039 p += wrap3 + (wrap3 - width * 4);
3040 lum += wrap + (wrap - width);
3041 a += wrap + (wrap - width);
3042 cb += dst->linesize[1] - width2;
3043 cr += dst->linesize[2] - width2;
3045 /* handle odd height */
3047 for (w = width; w >= 2; w -= 2) {
3074 typedef struct ConvertEntry
3076 enum PixelFormat src;
3077 enum PixelFormat dest;
3078 void (*convert) (AVPicture * dst,
3079 const AVPicture * src, int width, int height);
3082 /* Add each new conversion function in this table. In order to be able
3083 to convert from any format to any format, the following constraints
3086 - all FF_COLOR_RGB formats must convert to and from PIX_FMT_RGB24
3088 - all FF_COLOR_GRAY formats must convert to and from PIX_FMT_GRAY8
3090 - all FF_COLOR_RGB formats with alpha must convert to and from PIX_FMT_RGBA32
3092 - PIX_FMT_YUV444P and PIX_FMT_YUVJ444P must convert to and from
3095 - PIX_FMT_422 must convert to and from PIX_FMT_422P.
3097 The other conversion functions are just optimisations for common cases.
3099 static ConvertEntry convert_table[] = {
3100 {PIX_FMT_YUV420P, PIX_FMT_YUV422, yuv420p_to_yuv422},
3101 {PIX_FMT_YUV420P, PIX_FMT_RGB555, yuv420p_to_rgb555},
3102 {PIX_FMT_YUV420P, PIX_FMT_RGB565, yuv420p_to_rgb565},
3103 {PIX_FMT_YUV420P, PIX_FMT_BGR24, yuv420p_to_bgr24},
3104 {PIX_FMT_YUV420P, PIX_FMT_RGB24, yuv420p_to_rgb24},
3105 {PIX_FMT_YUV420P, PIX_FMT_RGB32, yuv420p_to_rgb32},
3106 {PIX_FMT_YUV420P, PIX_FMT_BGR32, yuv420p_to_bgr32},
3107 {PIX_FMT_YUV420P, PIX_FMT_xRGB32, yuv420p_to_xrgb32},
3108 {PIX_FMT_YUV420P, PIX_FMT_BGRx32, yuv420p_to_bgrx32},
3109 {PIX_FMT_YUV420P, PIX_FMT_RGBA32, yuv420p_to_rgba32},
3110 {PIX_FMT_YUV420P, PIX_FMT_BGRA32, yuv420p_to_bgra32},
3111 {PIX_FMT_YUV420P, PIX_FMT_ARGB32, yuv420p_to_argb32},
3112 {PIX_FMT_YUV420P, PIX_FMT_ABGR32, yuv420p_to_abgr32},
3114 {PIX_FMT_NV12, PIX_FMT_RGB555, nv12_to_rgb555},
3115 {PIX_FMT_NV12, PIX_FMT_RGB565, nv12_to_rgb565},
3116 {PIX_FMT_NV12, PIX_FMT_BGR24, nv12_to_bgr24},
3117 {PIX_FMT_NV12, PIX_FMT_RGB24, nv12_to_rgb24},
3118 {PIX_FMT_NV12, PIX_FMT_RGB32, nv12_to_rgb32},
3119 {PIX_FMT_NV12, PIX_FMT_BGR32, nv12_to_bgr32},
3120 {PIX_FMT_NV12, PIX_FMT_xRGB32, nv12_to_xrgb32},
3121 {PIX_FMT_NV12, PIX_FMT_BGRx32, nv12_to_bgrx32},
3122 {PIX_FMT_NV12, PIX_FMT_RGBA32, nv12_to_rgba32},
3123 {PIX_FMT_NV12, PIX_FMT_BGRA32, nv12_to_bgra32},
3124 {PIX_FMT_NV12, PIX_FMT_ARGB32, nv12_to_argb32},
3125 {PIX_FMT_NV12, PIX_FMT_ABGR32, nv12_to_abgr32},
3126 {PIX_FMT_NV12, PIX_FMT_NV21, nv12_to_nv21},
3127 {PIX_FMT_NV12, PIX_FMT_YUV444P, nv12_to_yuv444p},
3129 {PIX_FMT_NV21, PIX_FMT_RGB555, nv21_to_rgb555},
3130 {PIX_FMT_NV21, PIX_FMT_RGB565, nv21_to_rgb565},
3131 {PIX_FMT_NV21, PIX_FMT_BGR24, nv21_to_bgr24},
3132 {PIX_FMT_NV21, PIX_FMT_RGB24, nv21_to_rgb24},
3133 {PIX_FMT_NV21, PIX_FMT_RGB32, nv21_to_rgb32},
3134 {PIX_FMT_NV21, PIX_FMT_BGR32, nv21_to_bgr32},
3135 {PIX_FMT_NV21, PIX_FMT_xRGB32, nv21_to_xrgb32},
3136 {PIX_FMT_NV21, PIX_FMT_BGRx32, nv21_to_bgrx32},
3137 {PIX_FMT_NV21, PIX_FMT_RGBA32, nv21_to_rgba32},
3138 {PIX_FMT_NV21, PIX_FMT_BGRA32, nv21_to_bgra32},
3139 {PIX_FMT_NV21, PIX_FMT_ARGB32, nv21_to_argb32},
3140 {PIX_FMT_NV21, PIX_FMT_ABGR32, nv21_to_abgr32},
3141 {PIX_FMT_NV21, PIX_FMT_YUV444P, nv21_to_yuv444p},
3142 {PIX_FMT_NV21, PIX_FMT_NV12, nv21_to_nv12},
3144 {PIX_FMT_YUV422P, PIX_FMT_YUV422, yuv422p_to_yuv422},
3145 {PIX_FMT_YUV422P, PIX_FMT_UYVY422, yuv422p_to_uyvy422},
3146 {PIX_FMT_YUV422P, PIX_FMT_YVYU422, yuv422p_to_yvyu422},
3148 {PIX_FMT_YUV444P, PIX_FMT_RGB24, yuv444p_to_rgb24},
3150 {PIX_FMT_YUVJ420P, PIX_FMT_RGB555, yuvj420p_to_rgb555},
3151 {PIX_FMT_YUVJ420P, PIX_FMT_RGB565, yuvj420p_to_rgb565},
3152 {PIX_FMT_YUVJ420P, PIX_FMT_BGR24, yuvj420p_to_bgr24},
3153 {PIX_FMT_YUVJ420P, PIX_FMT_RGB24, yuvj420p_to_rgb24},
3154 {PIX_FMT_YUVJ420P, PIX_FMT_RGB32, yuvj420p_to_rgb32},
3155 {PIX_FMT_YUVJ420P, PIX_FMT_BGR32, yuvj420p_to_bgr32},
3156 {PIX_FMT_YUVJ420P, PIX_FMT_RGB32, yuvj420p_to_xrgb32},
3157 {PIX_FMT_YUVJ420P, PIX_FMT_BGR32, yuvj420p_to_bgrx32},
3158 {PIX_FMT_YUVJ420P, PIX_FMT_RGBA32, yuvj420p_to_rgba32},
3159 {PIX_FMT_YUVJ420P, PIX_FMT_BGRA32, yuvj420p_to_bgra32},
3160 {PIX_FMT_YUVJ420P, PIX_FMT_ARGB32, yuvj420p_to_argb32},
3161 {PIX_FMT_YUVJ420P, PIX_FMT_ABGR32, yuvj420p_to_abgr32},
3163 {PIX_FMT_YUVJ444P, PIX_FMT_RGB24, yuvj444p_to_rgb24},
3165 {PIX_FMT_YUV422, PIX_FMT_YUV420P, yuv422_to_yuv420p},
3166 {PIX_FMT_YUV422, PIX_FMT_YUV422P, yuv422_to_yuv422p},
3167 {PIX_FMT_YUV422, PIX_FMT_GRAY8, yvyu422_to_gray},
3168 {PIX_FMT_YUV422, PIX_FMT_RGB555, yuv422_to_rgb555},
3169 {PIX_FMT_YUV422, PIX_FMT_RGB565, yuv422_to_rgb565},
3170 {PIX_FMT_YUV422, PIX_FMT_BGR24, yuv422_to_bgr24},
3171 {PIX_FMT_YUV422, PIX_FMT_RGB24, yuv422_to_rgb24},
3172 {PIX_FMT_YUV422, PIX_FMT_BGR32, yuv422_to_bgr32},
3173 {PIX_FMT_YUV422, PIX_FMT_RGB32, yuv422_to_rgb32},
3174 {PIX_FMT_YUV422, PIX_FMT_xRGB32, yuv422_to_xrgb32},
3175 {PIX_FMT_YUV422, PIX_FMT_BGRx32, yuv422_to_bgrx32},
3176 {PIX_FMT_YUV422, PIX_FMT_BGRA32, yuv422_to_bgra32},
3177 {PIX_FMT_YUV422, PIX_FMT_RGBA32, yuv422_to_rgba32},
3178 {PIX_FMT_YUV422, PIX_FMT_ABGR32, yuv422_to_abgr32},
3179 {PIX_FMT_YUV422, PIX_FMT_ARGB32, yuv422_to_argb32},
3181 {PIX_FMT_UYVY422, PIX_FMT_YUV420P, uyvy422_to_yuv420p},
3182 {PIX_FMT_UYVY422, PIX_FMT_YUV422P, uyvy422_to_yuv422p},
3183 {PIX_FMT_UYVY422, PIX_FMT_GRAY8, uyvy422_to_gray},
3184 {PIX_FMT_UYVY422, PIX_FMT_RGB555, uyvy422_to_rgb555},
3185 {PIX_FMT_UYVY422, PIX_FMT_RGB565, uyvy422_to_rgb565},
3186 {PIX_FMT_UYVY422, PIX_FMT_BGR24, uyvy422_to_bgr24},
3187 {PIX_FMT_UYVY422, PIX_FMT_RGB24, uyvy422_to_rgb24},
3188 {PIX_FMT_UYVY422, PIX_FMT_RGB32, uyvy422_to_rgb32},
3189 {PIX_FMT_UYVY422, PIX_FMT_BGR32, uyvy422_to_bgr32},
3190 {PIX_FMT_UYVY422, PIX_FMT_xRGB32, uyvy422_to_xrgb32},
3191 {PIX_FMT_UYVY422, PIX_FMT_BGRx32, uyvy422_to_bgrx32},
3192 {PIX_FMT_UYVY422, PIX_FMT_RGBA32, uyvy422_to_rgba32},
3193 {PIX_FMT_UYVY422, PIX_FMT_BGRA32, uyvy422_to_bgra32},
3194 {PIX_FMT_UYVY422, PIX_FMT_ARGB32, uyvy422_to_argb32},
3195 {PIX_FMT_UYVY422, PIX_FMT_ABGR32, uyvy422_to_abgr32},
3197 {PIX_FMT_YVYU422, PIX_FMT_YUV420P, yvyu422_to_yuv420p},
3198 {PIX_FMT_YVYU422, PIX_FMT_YUV422P, yvyu422_to_yuv422p},
3199 {PIX_FMT_YVYU422, PIX_FMT_GRAY8, yvyu422_to_gray},
3200 {PIX_FMT_YVYU422, PIX_FMT_RGB555, yvyu422_to_rgb555},
3201 {PIX_FMT_YVYU422, PIX_FMT_RGB565, yvyu422_to_rgb565},
3202 {PIX_FMT_YVYU422, PIX_FMT_BGR24, yvyu422_to_bgr24},
3203 {PIX_FMT_YVYU422, PIX_FMT_RGB24, yvyu422_to_rgb24},
3204 {PIX_FMT_YVYU422, PIX_FMT_BGR32, yvyu422_to_bgr32},
3205 {PIX_FMT_YVYU422, PIX_FMT_RGB32, yvyu422_to_rgb32},
3206 {PIX_FMT_YVYU422, PIX_FMT_xRGB32, yvyu422_to_xrgb32},
3207 {PIX_FMT_YVYU422, PIX_FMT_BGRx32, yvyu422_to_bgrx32},
3208 {PIX_FMT_YVYU422, PIX_FMT_BGRA32, yvyu422_to_bgra32},
3209 {PIX_FMT_YVYU422, PIX_FMT_RGBA32, yvyu422_to_rgba32},
3210 {PIX_FMT_YVYU422, PIX_FMT_ABGR32, yvyu422_to_abgr32},
3211 {PIX_FMT_YVYU422, PIX_FMT_ARGB32, yvyu422_to_argb32},
3213 {PIX_FMT_RGB24, PIX_FMT_YUV420P, rgb24_to_yuv420p},
3214 {PIX_FMT_RGB24, PIX_FMT_YUVA420P, rgb24_to_yuva420p},
3215 {PIX_FMT_RGB24, PIX_FMT_NV12, rgb24_to_nv12},
3216 {PIX_FMT_RGB24, PIX_FMT_NV21, rgb24_to_nv21},
3217 {PIX_FMT_RGB24, PIX_FMT_RGB565, rgb24_to_rgb565},
3218 {PIX_FMT_RGB24, PIX_FMT_RGB555, rgb24_to_rgb555},
3219 {PIX_FMT_RGB24, PIX_FMT_RGB32, rgb24_to_rgb32},
3220 {PIX_FMT_RGB24, PIX_FMT_BGR32, rgb24_to_bgr32},
3221 {PIX_FMT_RGB24, PIX_FMT_xRGB32, rgb24_to_xrgb32},
3222 {PIX_FMT_RGB24, PIX_FMT_BGRx32, rgb24_to_bgrx32},
3223 {PIX_FMT_RGB24, PIX_FMT_RGBA32, rgb24_to_rgba32},
3224 {PIX_FMT_RGB24, PIX_FMT_BGR24, rgb24_to_bgr24},
3225 {PIX_FMT_RGB24, PIX_FMT_BGRA32, rgb24_to_bgra32},
3226 {PIX_FMT_RGB24, PIX_FMT_ARGB32, rgb24_to_argb32},
3227 {PIX_FMT_RGB24, PIX_FMT_ABGR32, rgb24_to_abgr32},
3228 {PIX_FMT_RGB24, PIX_FMT_Y800, rgb24_to_y800},
3229 {PIX_FMT_RGB24, PIX_FMT_Y16, rgb24_to_y16},
3230 {PIX_FMT_RGB24, PIX_FMT_GRAY8, rgb24_to_gray},
3231 {PIX_FMT_RGB24, PIX_FMT_GRAY16_L, rgb24_to_gray16_l},
3232 {PIX_FMT_RGB24, PIX_FMT_GRAY16_B, rgb24_to_gray16_b},
3233 {PIX_FMT_RGB24, PIX_FMT_PAL8, rgb24_to_pal8},
3234 {PIX_FMT_RGB24, PIX_FMT_YUV444P, rgb24_to_yuv444p},
3235 {PIX_FMT_RGB24, PIX_FMT_YUVJ420P, rgb24_to_yuvj420p},
3236 {PIX_FMT_RGB24, PIX_FMT_YUVJ444P, rgb24_to_yuvj444p},
3237 {PIX_FMT_RGB24, PIX_FMT_AYUV4444, rgb24_to_ayuv4444},
3238 {PIX_FMT_RGB24, PIX_FMT_V308, rgb24_to_v308},
3240 {PIX_FMT_RGB32, PIX_FMT_RGB24, rgb32_to_rgb24},
3241 {PIX_FMT_RGB32, PIX_FMT_RGB555, rgba32_to_rgb555},
3242 {PIX_FMT_RGB32, PIX_FMT_PAL8, rgb32_to_pal8},
3243 {PIX_FMT_RGB32, PIX_FMT_YUV420P, rgb32_to_yuv420p},
3244 {PIX_FMT_RGB32, PIX_FMT_YUVA420P, rgb32_to_yuva420p},
3245 {PIX_FMT_RGB32, PIX_FMT_NV12, rgb32_to_nv12},
3246 {PIX_FMT_RGB32, PIX_FMT_NV21, rgb32_to_nv21},
3247 {PIX_FMT_RGB32, PIX_FMT_Y800, rgb32_to_y800},
3248 {PIX_FMT_RGB32, PIX_FMT_Y16, rgb32_to_y16},
3249 {PIX_FMT_RGB32, PIX_FMT_GRAY8, rgb32_to_gray},
3250 {PIX_FMT_RGB32, PIX_FMT_GRAY16_L, rgb32_to_gray16_l},
3251 {PIX_FMT_RGB32, PIX_FMT_GRAY16_B, rgb32_to_gray16_b},
3253 {PIX_FMT_xRGB32, PIX_FMT_RGB24, xrgb32_to_rgb24},
3254 {PIX_FMT_xRGB32, PIX_FMT_PAL8, xrgb32_to_pal8},
3255 {PIX_FMT_xRGB32, PIX_FMT_YUV420P, xrgb32_to_yuv420p},
3256 {PIX_FMT_xRGB32, PIX_FMT_YUVA420P, xrgb32_to_yuva420p},
3257 {PIX_FMT_xRGB32, PIX_FMT_NV12, xrgb32_to_nv12},
3258 {PIX_FMT_xRGB32, PIX_FMT_NV21, xrgb32_to_nv21},
3259 {PIX_FMT_xRGB32, PIX_FMT_Y800, xrgb32_to_y800},
3260 {PIX_FMT_xRGB32, PIX_FMT_Y16, xrgb32_to_y16},
3261 {PIX_FMT_xRGB32, PIX_FMT_GRAY8, xrgb32_to_gray},
3262 {PIX_FMT_xRGB32, PIX_FMT_GRAY16_L, xrgb32_to_gray16_l},
3263 {PIX_FMT_xRGB32, PIX_FMT_GRAY16_B, xrgb32_to_gray16_b},
3265 {PIX_FMT_RGBA32, PIX_FMT_BGRA32, rgba32_to_bgra32},
3266 {PIX_FMT_RGBA32, PIX_FMT_ABGR32, rgba32_to_abgr32},
3267 {PIX_FMT_RGBA32, PIX_FMT_ARGB32, rgba32_to_argb32},
3268 {PIX_FMT_RGBA32, PIX_FMT_BGR32, rgba32_to_bgr32},
3269 {PIX_FMT_RGBA32, PIX_FMT_BGRx32, rgba32_to_bgrx32},
3270 {PIX_FMT_RGBA32, PIX_FMT_ABGR32, rgba32_to_abgr32},
3271 {PIX_FMT_RGBA32, PIX_FMT_RGB24, rgba32_to_rgb24},
3272 {PIX_FMT_RGBA32, PIX_FMT_RGB555, rgba32_to_rgb555},
3273 {PIX_FMT_RGBA32, PIX_FMT_PAL8, rgba32_to_pal8},
3274 {PIX_FMT_RGBA32, PIX_FMT_YUV420P, rgba32_to_yuv420p},
3275 {PIX_FMT_RGBA32, PIX_FMT_YUVA420P, rgba32_to_yuva420p},
3276 {PIX_FMT_RGBA32, PIX_FMT_NV12, rgba32_to_nv12},
3277 {PIX_FMT_RGBA32, PIX_FMT_NV21, rgba32_to_nv21},
3278 {PIX_FMT_RGBA32, PIX_FMT_Y800, rgba32_to_y800},
3279 {PIX_FMT_RGBA32, PIX_FMT_Y16, rgba32_to_y16},
3280 {PIX_FMT_RGBA32, PIX_FMT_GRAY8, rgba32_to_gray},
3281 {PIX_FMT_RGBA32, PIX_FMT_GRAY16_L, rgba32_to_gray16_l},
3282 {PIX_FMT_RGBA32, PIX_FMT_GRAY16_B, rgba32_to_gray16_b},
3283 {PIX_FMT_RGBA32, PIX_FMT_AYUV4444, rgba32_to_ayuv4444},
3285 {PIX_FMT_BGR24, PIX_FMT_RGB24, bgr24_to_rgb24},
3286 {PIX_FMT_BGR24, PIX_FMT_YUV420P, bgr24_to_yuv420p},
3287 {PIX_FMT_BGR24, PIX_FMT_YUVA420P, bgr24_to_yuva420p},
3288 {PIX_FMT_BGR24, PIX_FMT_NV12, bgr24_to_nv12},
3289 {PIX_FMT_BGR24, PIX_FMT_NV21, bgr24_to_nv21},
3290 {PIX_FMT_BGR24, PIX_FMT_Y800, bgr24_to_y800},
3291 {PIX_FMT_BGR24, PIX_FMT_Y16, bgr24_to_y16},
3292 {PIX_FMT_BGR24, PIX_FMT_GRAY8, bgr24_to_gray},
3293 {PIX_FMT_BGR24, PIX_FMT_GRAY16_L, bgr24_to_gray16_l},
3294 {PIX_FMT_BGR24, PIX_FMT_GRAY16_B, bgr24_to_gray16_b},
3296 {PIX_FMT_BGR32, PIX_FMT_RGB24, bgr32_to_rgb24},
3297 {PIX_FMT_BGR32, PIX_FMT_RGBA32, bgr32_to_rgba32},
3298 {PIX_FMT_BGR32, PIX_FMT_YUV420P, bgr32_to_yuv420p},
3299 {PIX_FMT_BGR32, PIX_FMT_YUVA420P, bgr32_to_yuva420p},
3300 {PIX_FMT_BGR32, PIX_FMT_NV12, bgr32_to_nv12},
3301 {PIX_FMT_BGR32, PIX_FMT_NV21, bgr32_to_nv21},
3302 {PIX_FMT_BGR32, PIX_FMT_Y800, bgr32_to_y800},
3303 {PIX_FMT_BGR32, PIX_FMT_Y16, bgr32_to_y16},
3304 {PIX_FMT_BGR32, PIX_FMT_GRAY8, bgr32_to_gray},
3305 {PIX_FMT_BGR32, PIX_FMT_GRAY16_L, bgr32_to_gray16_l},
3306 {PIX_FMT_BGR32, PIX_FMT_GRAY16_B, bgr32_to_gray16_b},
3308 {PIX_FMT_BGRx32, PIX_FMT_RGB24, bgrx32_to_rgb24},
3309 {PIX_FMT_BGRx32, PIX_FMT_RGBA32, bgrx32_to_rgba32},
3310 {PIX_FMT_BGRx32, PIX_FMT_YUV420P, bgrx32_to_yuv420p},
3311 {PIX_FMT_BGRx32, PIX_FMT_YUVA420P, bgrx32_to_yuva420p},
3312 {PIX_FMT_BGRx32, PIX_FMT_NV12, bgrx32_to_nv12},
3313 {PIX_FMT_BGRx32, PIX_FMT_NV21, bgrx32_to_nv21},
3314 {PIX_FMT_BGRx32, PIX_FMT_Y800, bgrx32_to_y800},
3315 {PIX_FMT_BGRx32, PIX_FMT_Y16, bgrx32_to_y16},
3316 {PIX_FMT_BGRx32, PIX_FMT_GRAY8, bgrx32_to_gray},
3317 {PIX_FMT_BGRx32, PIX_FMT_GRAY16_L, bgrx32_to_gray16_l},
3318 {PIX_FMT_BGRx32, PIX_FMT_GRAY16_B, bgrx32_to_gray16_b},
3320 {PIX_FMT_BGRA32, PIX_FMT_RGB24, bgra32_to_rgb24},
3321 {PIX_FMT_BGRA32, PIX_FMT_RGBA32, bgra32_to_rgba32},
3322 {PIX_FMT_BGRA32, PIX_FMT_YUV420P, bgra32_to_yuv420p},
3323 {PIX_FMT_BGRA32, PIX_FMT_YUVA420P, bgra32_to_yuva420p},
3324 {PIX_FMT_BGRA32, PIX_FMT_NV12, bgra32_to_nv12},
3325 {PIX_FMT_BGRA32, PIX_FMT_NV21, bgra32_to_nv21},
3326 {PIX_FMT_BGRA32, PIX_FMT_Y800, bgra32_to_y800},
3327 {PIX_FMT_BGRA32, PIX_FMT_Y16, bgra32_to_y16},
3328 {PIX_FMT_BGRA32, PIX_FMT_GRAY8, bgra32_to_gray},
3329 {PIX_FMT_BGRA32, PIX_FMT_GRAY16_L, bgra32_to_gray16_l},
3330 {PIX_FMT_BGRA32, PIX_FMT_GRAY16_B, bgra32_to_gray16_b},
3331 {PIX_FMT_BGRA32, PIX_FMT_AYUV4444, bgra32_to_ayuv4444},
3333 {PIX_FMT_ABGR32, PIX_FMT_RGB24, abgr32_to_rgb24},
3334 {PIX_FMT_ABGR32, PIX_FMT_RGBA32, abgr32_to_rgba32},
3335 {PIX_FMT_ABGR32, PIX_FMT_YUV420P, abgr32_to_yuv420p},
3336 {PIX_FMT_ABGR32, PIX_FMT_YUVA420P, abgr32_to_yuva420p},
3337 {PIX_FMT_ABGR32, PIX_FMT_NV12, abgr32_to_nv12},
3338 {PIX_FMT_ABGR32, PIX_FMT_NV21, abgr32_to_nv21},
3339 {PIX_FMT_ABGR32, PIX_FMT_Y800, abgr32_to_y800},
3340 {PIX_FMT_ABGR32, PIX_FMT_Y16, abgr32_to_y16},
3341 {PIX_FMT_ABGR32, PIX_FMT_GRAY8, abgr32_to_gray},
3342 {PIX_FMT_ABGR32, PIX_FMT_GRAY16_L, abgr32_to_gray16_l},
3343 {PIX_FMT_ABGR32, PIX_FMT_GRAY16_B, abgr32_to_gray16_b},
3344 {PIX_FMT_ABGR32, PIX_FMT_AYUV4444, abgr32_to_ayuv4444},
3346 {PIX_FMT_ARGB32, PIX_FMT_RGB24, argb32_to_rgb24},
3347 {PIX_FMT_ARGB32, PIX_FMT_RGBA32, argb32_to_rgba32},
3348 {PIX_FMT_ARGB32, PIX_FMT_YUV420P, argb32_to_yuv420p},
3349 {PIX_FMT_ARGB32, PIX_FMT_YUVA420P, argb32_to_yuva420p},
3350 {PIX_FMT_ARGB32, PIX_FMT_NV12, argb32_to_nv12},
3351 {PIX_FMT_ARGB32, PIX_FMT_NV21, argb32_to_nv21},
3352 {PIX_FMT_ARGB32, PIX_FMT_Y800, argb32_to_y800},
3353 {PIX_FMT_ARGB32, PIX_FMT_Y16, argb32_to_y16},
3354 {PIX_FMT_ARGB32, PIX_FMT_GRAY8, argb32_to_gray},
3355 {PIX_FMT_ARGB32, PIX_FMT_GRAY16_L, argb32_to_gray16_l},
3356 {PIX_FMT_ARGB32, PIX_FMT_GRAY16_B, argb32_to_gray16_b},
3357 {PIX_FMT_ARGB32, PIX_FMT_AYUV4444, argb32_to_ayuv4444},
3359 {PIX_FMT_RGB555, PIX_FMT_RGB24, rgb555_to_rgb24},
3360 {PIX_FMT_RGB555, PIX_FMT_RGB32, rgb555_to_rgba32},
3361 {PIX_FMT_RGB555, PIX_FMT_RGBA32, rgb555_to_rgba32},
3362 {PIX_FMT_RGB555, PIX_FMT_YUV420P, rgb555_to_yuv420p},
3363 {PIX_FMT_RGB555, PIX_FMT_YUVA420P, rgb555_to_yuva420p},
3364 {PIX_FMT_RGB555, PIX_FMT_NV12, rgb555_to_nv12},
3365 {PIX_FMT_RGB555, PIX_FMT_NV21, rgb555_to_nv21},
3366 {PIX_FMT_RGB555, PIX_FMT_Y800, rgb555_to_y800},
3367 {PIX_FMT_RGB555, PIX_FMT_Y16, rgb555_to_y16},
3368 {PIX_FMT_RGB555, PIX_FMT_GRAY8, rgb555_to_gray},
3369 {PIX_FMT_RGB555, PIX_FMT_GRAY16_L, rgb555_to_gray16_l},
3370 {PIX_FMT_RGB555, PIX_FMT_GRAY16_B, rgb555_to_gray16_b},
3372 {PIX_FMT_RGB565, PIX_FMT_RGB24, rgb565_to_rgb24},
3373 {PIX_FMT_RGB565, PIX_FMT_YUV420P, rgb565_to_yuv420p},
3374 {PIX_FMT_RGB565, PIX_FMT_YUVA420P, rgb565_to_yuva420p},
3375 {PIX_FMT_RGB565, PIX_FMT_NV12, rgb565_to_nv12},
3376 {PIX_FMT_RGB565, PIX_FMT_NV21, rgb565_to_nv21},
3377 {PIX_FMT_RGB565, PIX_FMT_Y800, rgb565_to_y800},
3378 {PIX_FMT_RGB565, PIX_FMT_Y16, rgb565_to_y16},
3379 {PIX_FMT_RGB565, PIX_FMT_GRAY8, rgb565_to_gray},
3380 {PIX_FMT_RGB565, PIX_FMT_GRAY16_L, rgb565_to_gray16_l},
3381 {PIX_FMT_RGB565, PIX_FMT_GRAY16_B, rgb565_to_gray16_b},
3383 {PIX_FMT_Y800, PIX_FMT_RGB555, y800_to_rgb555},
3384 {PIX_FMT_Y800, PIX_FMT_RGB565, y800_to_rgb565},
3385 {PIX_FMT_Y800, PIX_FMT_BGR24, y800_to_bgr24},
3386 {PIX_FMT_Y800, PIX_FMT_RGB24, y800_to_rgb24},
3387 {PIX_FMT_Y800, PIX_FMT_RGB32, y800_to_rgb32},
3388 {PIX_FMT_Y800, PIX_FMT_BGR32, y800_to_bgr32},
3389 {PIX_FMT_Y800, PIX_FMT_RGB32, y800_to_xrgb32},
3390 {PIX_FMT_Y800, PIX_FMT_BGR32, y800_to_bgrx32},
3391 {PIX_FMT_Y800, PIX_FMT_RGBA32, y800_to_rgba32},
3392 {PIX_FMT_Y800, PIX_FMT_BGRA32, y800_to_bgra32},
3393 {PIX_FMT_Y800, PIX_FMT_ARGB32, y800_to_argb32},
3394 {PIX_FMT_Y800, PIX_FMT_ABGR32, y800_to_abgr32},
3395 {PIX_FMT_Y800, PIX_FMT_Y16, y800_to_y16},
3397 {PIX_FMT_Y16, PIX_FMT_RGB555, y16_to_rgb555},
3398 {PIX_FMT_Y16, PIX_FMT_RGB565, y16_to_rgb565},
3399 {PIX_FMT_Y16, PIX_FMT_BGR24, y16_to_bgr24},
3400 {PIX_FMT_Y16, PIX_FMT_RGB24, y16_to_rgb24},
3401 {PIX_FMT_Y16, PIX_FMT_RGB32, y16_to_rgb32},
3402 {PIX_FMT_Y16, PIX_FMT_BGR32, y16_to_bgr32},
3403 {PIX_FMT_Y16, PIX_FMT_RGB32, y16_to_xrgb32},
3404 {PIX_FMT_Y16, PIX_FMT_BGR32, y16_to_bgrx32},
3405 {PIX_FMT_Y16, PIX_FMT_RGBA32, y16_to_rgba32},
3406 {PIX_FMT_Y16, PIX_FMT_BGRA32, y16_to_bgra32},
3407 {PIX_FMT_Y16, PIX_FMT_ARGB32, y16_to_argb32},
3408 {PIX_FMT_Y16, PIX_FMT_ABGR32, y16_to_abgr32},
3409 {PIX_FMT_Y16, PIX_FMT_Y800, y16_to_y800},
3411 {PIX_FMT_GRAY8, PIX_FMT_RGB555, gray_to_rgb555},
3412 {PIX_FMT_GRAY8, PIX_FMT_RGB565, gray_to_rgb565},
3413 {PIX_FMT_GRAY8, PIX_FMT_RGB24, gray_to_rgb24},
3414 {PIX_FMT_GRAY8, PIX_FMT_BGR24, gray_to_bgr24},
3415 {PIX_FMT_GRAY8, PIX_FMT_RGB32, gray_to_rgb32},
3416 {PIX_FMT_GRAY8, PIX_FMT_BGR32, gray_to_bgr32},
3417 {PIX_FMT_GRAY8, PIX_FMT_xRGB32, gray_to_xrgb32},
3418 {PIX_FMT_GRAY8, PIX_FMT_BGRx32, gray_to_bgrx32},
3419 {PIX_FMT_GRAY8, PIX_FMT_RGBA32, gray_to_rgba32},
3420 {PIX_FMT_GRAY8, PIX_FMT_BGRA32, gray_to_bgra32},
3421 {PIX_FMT_GRAY8, PIX_FMT_ARGB32, gray_to_argb32},
3422 {PIX_FMT_GRAY8, PIX_FMT_ABGR32, gray_to_abgr32},
3423 {PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, gray_to_monowhite},
3424 {PIX_FMT_GRAY8, PIX_FMT_MONOBLACK, gray_to_monoblack},
3425 {PIX_FMT_GRAY8, PIX_FMT_GRAY16_L, gray_to_gray16_l},
3426 {PIX_FMT_GRAY8, PIX_FMT_GRAY16_B, gray_to_gray16_b},
3428 {PIX_FMT_MONOWHITE, PIX_FMT_GRAY8, monowhite_to_gray},
3430 {PIX_FMT_MONOBLACK, PIX_FMT_GRAY8, monoblack_to_gray},
3432 {PIX_FMT_GRAY16_L, PIX_FMT_GRAY8, gray16_l_to_gray},
3433 {PIX_FMT_GRAY16_L, PIX_FMT_RGB555, gray16_l_to_rgb555},
3434 {PIX_FMT_GRAY16_L, PIX_FMT_RGB565, gray16_l_to_rgb565},
3435 {PIX_FMT_GRAY16_L, PIX_FMT_BGR24, gray16_l_to_bgr24},
3436 {PIX_FMT_GRAY16_L, PIX_FMT_RGB24, gray16_l_to_rgb24},
3437 {PIX_FMT_GRAY16_L, PIX_FMT_BGR32, gray16_l_to_bgr32},
3438 {PIX_FMT_GRAY16_L, PIX_FMT_RGB32, gray16_l_to_rgb32},
3439 {PIX_FMT_GRAY16_L, PIX_FMT_xRGB32, gray16_l_to_xrgb32},
3440 {PIX_FMT_GRAY16_L, PIX_FMT_BGRx32, gray16_l_to_bgrx32},
3441 {PIX_FMT_GRAY16_L, PIX_FMT_ABGR32, gray16_l_to_abgr32},
3442 {PIX_FMT_GRAY16_L, PIX_FMT_ARGB32, gray16_l_to_argb32},
3443 {PIX_FMT_GRAY16_L, PIX_FMT_BGRA32, gray16_l_to_bgra32},
3444 {PIX_FMT_GRAY16_L, PIX_FMT_RGBA32, gray16_l_to_rgba32},
3445 {PIX_FMT_GRAY16_L, PIX_FMT_GRAY16_B, gray16_b_to_gray16_l},
3447 {PIX_FMT_GRAY16_B, PIX_FMT_GRAY8, gray16_b_to_gray},
3448 {PIX_FMT_GRAY16_B, PIX_FMT_RGB555, gray16_b_to_rgb555},
3449 {PIX_FMT_GRAY16_B, PIX_FMT_RGB565, gray16_b_to_rgb565},
3450 {PIX_FMT_GRAY16_B, PIX_FMT_BGR24, gray16_b_to_bgr24},
3451 {PIX_FMT_GRAY16_B, PIX_FMT_RGB24, gray16_b_to_rgb24},
3452 {PIX_FMT_GRAY16_B, PIX_FMT_BGR32, gray16_b_to_bgr32},
3453 {PIX_FMT_GRAY16_B, PIX_FMT_RGB32, gray16_b_to_rgb32},
3454 {PIX_FMT_GRAY16_B, PIX_FMT_xRGB32, gray16_b_to_xrgb32},
3455 {PIX_FMT_GRAY16_B, PIX_FMT_BGRx32, gray16_b_to_bgrx32},
3456 {PIX_FMT_GRAY16_B, PIX_FMT_ABGR32, gray16_b_to_abgr32},
3457 {PIX_FMT_GRAY16_B, PIX_FMT_ARGB32, gray16_b_to_argb32},
3458 {PIX_FMT_GRAY16_B, PIX_FMT_BGRA32, gray16_b_to_bgra32},
3459 {PIX_FMT_GRAY16_B, PIX_FMT_RGBA32, gray16_b_to_rgba32},
3460 {PIX_FMT_GRAY16_B, PIX_FMT_GRAY16_L, gray16_b_to_gray16_l},
3462 {PIX_FMT_PAL8, PIX_FMT_RGB555, pal8_to_rgb555},
3463 {PIX_FMT_PAL8, PIX_FMT_RGB565, pal8_to_rgb565},
3464 {PIX_FMT_PAL8, PIX_FMT_BGR24, pal8_to_bgr24},
3465 {PIX_FMT_PAL8, PIX_FMT_RGB24, pal8_to_rgb24},
3466 {PIX_FMT_PAL8, PIX_FMT_RGB32, pal8_to_rgb32},
3467 {PIX_FMT_PAL8, PIX_FMT_BGR32, pal8_to_bgr32},
3468 {PIX_FMT_PAL8, PIX_FMT_xRGB32, pal8_to_xrgb32},
3469 {PIX_FMT_PAL8, PIX_FMT_BGRx32, pal8_to_bgrx32},
3470 {PIX_FMT_PAL8, PIX_FMT_RGBA32, pal8_to_rgba32},
3471 {PIX_FMT_PAL8, PIX_FMT_BGRA32, pal8_to_bgra32},
3472 {PIX_FMT_PAL8, PIX_FMT_ARGB32, pal8_to_argb32},
3473 {PIX_FMT_PAL8, PIX_FMT_ABGR32, pal8_to_abgr32},
3475 {PIX_FMT_UYVY411, PIX_FMT_YUV411P, uyvy411_to_yuv411p},
3476 {PIX_FMT_YUV411P, PIX_FMT_UYVY411, yuv411p_to_uyvy411},
3478 {PIX_FMT_V308, PIX_FMT_RGB24, v308_to_rgb24},
3480 {PIX_FMT_AYUV4444, PIX_FMT_RGBA32, ayuv4444_to_rgba32},
3481 {PIX_FMT_AYUV4444, PIX_FMT_ARGB32, ayuv4444_to_argb32},
3482 {PIX_FMT_AYUV4444, PIX_FMT_BGRA32, ayuv4444_to_bgra32},
3483 {PIX_FMT_AYUV4444, PIX_FMT_ABGR32, ayuv4444_to_abgr32},
3484 {PIX_FMT_AYUV4444, PIX_FMT_RGB24, ayuv4444_to_rgb24},
3485 {PIX_FMT_AYUV4444, PIX_FMT_YUVA420P, ayuv4444_to_yuva420p},
3487 {PIX_FMT_YUVA420P, PIX_FMT_YUV420P, yuva420p_to_yuv420p},
3488 {PIX_FMT_YUVA420P, PIX_FMT_YUV422, yuva420p_to_yuv422},
3489 {PIX_FMT_YUVA420P, PIX_FMT_AYUV4444, yuva420p_to_ayuv4444},
3490 {PIX_FMT_YUVA420P, PIX_FMT_RGB555, yuva420p_to_rgb555},
3491 {PIX_FMT_YUVA420P, PIX_FMT_RGB565, yuva420p_to_rgb565},
3492 {PIX_FMT_YUVA420P, PIX_FMT_BGR24, yuva420p_to_bgr24},
3493 {PIX_FMT_YUVA420P, PIX_FMT_RGB24, yuva420p_to_rgb24},
3494 {PIX_FMT_YUVA420P, PIX_FMT_RGB32, yuva420p_to_rgb32},
3495 {PIX_FMT_YUVA420P, PIX_FMT_BGR32, yuva420p_to_bgr32},
3496 {PIX_FMT_YUVA420P, PIX_FMT_xRGB32, yuva420p_to_xrgb32},
3497 {PIX_FMT_YUVA420P, PIX_FMT_BGRx32, yuva420p_to_bgrx32},
3498 {PIX_FMT_YUVA420P, PIX_FMT_RGBA32, yuva420p_to_rgba32},
3499 {PIX_FMT_YUVA420P, PIX_FMT_BGRA32, yuva420p_to_bgra32},
3500 {PIX_FMT_YUVA420P, PIX_FMT_ARGB32, yuva420p_to_argb32},
3501 {PIX_FMT_YUVA420P, PIX_FMT_ABGR32, yuva420p_to_abgr32},
3504 static ConvertEntry *
3505 get_convert_table_entry (int src_pix_fmt, int dst_pix_fmt)
3509 for (i = 0; i < sizeof (convert_table) / sizeof (convert_table[0]); i++) {
3510 if (convert_table[i].src == src_pix_fmt &&
3511 convert_table[i].dest == dst_pix_fmt) {
3512 return convert_table + i;
3520 avpicture_alloc (AVPicture * picture, int pix_fmt, int width, int height,
3526 size = avpicture_get_size (pix_fmt, width, height);
3527 ptr = av_malloc (size);
3530 gst_ffmpegcsp_avpicture_fill (picture, ptr, pix_fmt, width, height,
3534 memset (picture, 0, sizeof (AVPicture));
3539 avpicture_free (AVPicture * picture)
3541 av_free (picture->data[0]);
3544 /* return true if yuv planar */
3546 is_yuv_planar (PixFmtInfo * ps)
3548 return (ps->color_type == FF_COLOR_YUV ||
3549 ps->color_type == FF_COLOR_YUV_JPEG) && ps->pixel_type == FF_PIXEL_PLANAR;
3552 /* XXX: always use linesize. Return -1 if not supported */
3554 img_convert (AVPicture * dst, int dst_pix_fmt,
3555 const AVPicture * src, int src_pix_fmt, int src_width, int src_height)
3558 int i, ret, dst_width, dst_height, int_pix_fmt;
3559 PixFmtInfo *src_pix, *dst_pix;
3561 AVPicture tmp1, *tmp = &tmp1;
3563 if (G_UNLIKELY (src_width <= 0 || src_height <= 0))
3566 if (G_UNLIKELY (!inited)) {
3568 img_convert_init ();
3571 dst_width = src_width;
3572 dst_height = src_height;
3574 dst_pix = get_pix_fmt_info (dst_pix_fmt);
3575 src_pix = get_pix_fmt_info (src_pix_fmt);
3576 if (G_UNLIKELY (src_pix_fmt == dst_pix_fmt)) {
3577 /* no conversion needed: just copy */
3578 img_copy (dst, src, dst_pix_fmt, dst_width, dst_height);
3582 ce = get_convert_table_entry (src_pix_fmt, dst_pix_fmt);
3583 if (ce && ce->convert) {
3584 /* specific conversion routine */
3585 ce->convert (dst, src, dst_width, dst_height);
3590 if (is_yuv_planar (dst_pix) && dst_pix_fmt != PIX_FMT_Y16
3591 && src_pix_fmt == PIX_FMT_GRAY8) {
3595 if (dst_pix->color_type == FF_COLOR_YUV_JPEG) {
3596 img_copy_plane (dst->data[0], dst->linesize[0],
3597 src->data[0], src->linesize[0], dst_width, dst_height);
3599 img_apply_table (dst->data[0], dst->linesize[0],
3600 src->data[0], src->linesize[0],
3601 dst_width, dst_height, y_jpeg_to_ccir);
3603 /* fill U and V with 128 */
3606 w >>= dst_pix->x_chroma_shift;
3607 h >>= dst_pix->y_chroma_shift;
3608 for (i = 1; i <= 2; i++) {
3612 for (y = 0; y < h; y++) {
3614 d += dst->linesize[i];
3621 if (is_yuv_planar (src_pix) && src_pix_fmt != PIX_FMT_Y16
3622 && dst_pix_fmt == PIX_FMT_GRAY8) {
3623 if (src_pix->color_type == FF_COLOR_YUV_JPEG) {
3624 img_copy_plane (dst->data[0], dst->linesize[0],
3625 src->data[0], src->linesize[0], dst_width, dst_height);
3627 img_apply_table (dst->data[0], dst->linesize[0],
3628 src->data[0], src->linesize[0],
3629 dst_width, dst_height, y_ccir_to_jpeg);
3634 /* YUV to YUV planar */
3635 if (is_yuv_planar (dst_pix) && is_yuv_planar (src_pix) &&
3636 dst_pix->depth == src_pix->depth) {
3637 int x_shift, y_shift, xy_shift;
3638 void (*resize_func) (uint8_t * dst, int dst_wrap, int dst_width,
3639 int dst_height, const uint8_t * src, int src_wrap, int src_width,
3642 x_shift = (dst_pix->x_chroma_shift - src_pix->x_chroma_shift);
3643 y_shift = (dst_pix->y_chroma_shift - src_pix->y_chroma_shift);
3644 xy_shift = ((x_shift & 0xf) << 4) | (y_shift & 0xf);
3646 /* there must be filters for conversion at least from and to
3650 resize_func = img_copy_plane_resize;
3653 resize_func = shrink21;
3656 resize_func = shrink41;
3659 resize_func = shrink12;
3662 resize_func = shrink22;
3665 resize_func = shrink44;
3668 resize_func = grow21;
3671 resize_func = grow41;
3674 resize_func = grow22;
3677 resize_func = grow44;
3680 resize_func = conv411;
3683 /* currently not handled */
3684 goto no_chroma_filter;
3687 img_copy_plane (dst->data[0], dst->linesize[0],
3688 src->data[0], src->linesize[0], dst_width, dst_height);
3690 #define GEN_MASK(x) ((1<<(x))-1)
3691 #define DIV_ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) >> (x))
3693 for (i = 1; i <= 2; i++) {
3697 w = DIV_ROUND_UP_X (dst_width, dst_pix->x_chroma_shift);
3698 h = DIV_ROUND_UP_X (dst_height, dst_pix->y_chroma_shift);
3700 s_w = DIV_ROUND_UP_X (src_width, src_pix->x_chroma_shift);
3701 s_h = DIV_ROUND_UP_X (src_height, src_pix->y_chroma_shift);
3703 if (src->data[i] != NULL && dst->data[i] != NULL) {
3704 resize_func (dst->data[i], dst->linesize[i], w, h,
3705 src->data[i], src->linesize[i], s_w, s_h);
3706 } else if (dst->data[i] != NULL) {
3707 memset (dst->data[i], 128, dst->linesize[i] * h);
3710 /* if yuv color space conversion is needed, we do it here on
3711 the destination image */
3712 if (dst_pix->color_type != src_pix->color_type) {
3713 const uint8_t *y_table, *c_table;
3715 if (dst_pix->color_type == FF_COLOR_YUV) {
3716 y_table = y_jpeg_to_ccir;
3717 c_table = c_jpeg_to_ccir;
3719 y_table = y_ccir_to_jpeg;
3720 c_table = c_ccir_to_jpeg;
3722 img_apply_table (dst->data[0], dst->linesize[0],
3723 dst->data[0], dst->linesize[0], dst_width, dst_height, y_table);
3725 for (i = 1; i <= 2; i++)
3726 img_apply_table (dst->data[i], dst->linesize[i],
3727 dst->data[i], dst->linesize[i],
3728 dst_width >> dst_pix->x_chroma_shift,
3729 dst_height >> dst_pix->y_chroma_shift, c_table);
3734 GST_CAT_INFO (ffmpegcolorspace_performance,
3735 "no direct path to convert colorspace from %s -> %s", src_pix->name,
3738 /* try to use an intermediate format */
3739 if (src_pix_fmt == PIX_FMT_YUV422 || dst_pix_fmt == PIX_FMT_YUV422) {
3740 /* specific case: convert to YUV422P first */
3741 int_pix_fmt = PIX_FMT_YUV422P;
3742 } else if (src_pix_fmt == PIX_FMT_UYVY422 || dst_pix_fmt == PIX_FMT_UYVY422 ||
3743 src_pix_fmt == PIX_FMT_YVYU422 || dst_pix_fmt == PIX_FMT_YVYU422) {
3744 /* specific case: convert to YUV422P first */
3745 int_pix_fmt = PIX_FMT_YUV422P;
3746 } else if (src_pix_fmt == PIX_FMT_UYVY411 || dst_pix_fmt == PIX_FMT_UYVY411) {
3747 /* specific case: convert to YUV411P first */
3748 int_pix_fmt = PIX_FMT_YUV411P;
3749 } else if ((src_pix->color_type == FF_COLOR_GRAY &&
3750 src_pix_fmt != PIX_FMT_GRAY8) ||
3751 (dst_pix->color_type == FF_COLOR_GRAY && dst_pix_fmt != PIX_FMT_GRAY8)) {
3752 /* gray8 is the normalized format */
3753 int_pix_fmt = PIX_FMT_GRAY8;
3754 } else if (src_pix_fmt == PIX_FMT_Y16 || dst_pix_fmt == PIX_FMT_Y16) {
3755 /* y800 is the normalized format */
3756 int_pix_fmt = PIX_FMT_Y800;
3757 } else if ((is_yuv_planar (src_pix) &&
3758 src_pix_fmt != PIX_FMT_YUV444P && src_pix_fmt != PIX_FMT_YUVJ444P)) {
3759 /* yuv444 is the normalized format */
3760 if (src_pix->color_type == FF_COLOR_YUV_JPEG)
3761 int_pix_fmt = PIX_FMT_YUVJ444P;
3763 int_pix_fmt = PIX_FMT_YUV444P;
3764 } else if ((is_yuv_planar (dst_pix) &&
3765 dst_pix_fmt != PIX_FMT_YUV444P && dst_pix_fmt != PIX_FMT_YUVJ444P)) {
3766 /* yuv444 is the normalized format */
3767 if (dst_pix->color_type == FF_COLOR_YUV_JPEG)
3768 int_pix_fmt = PIX_FMT_YUVJ444P;
3770 int_pix_fmt = PIX_FMT_YUV444P;
3772 /* the two formats are rgb or gray8 or yuv[j]444p */
3773 if (src_pix->is_alpha && dst_pix->is_alpha)
3774 int_pix_fmt = PIX_FMT_RGBA32;
3776 int_pix_fmt = PIX_FMT_RGB24;
3778 if (avpicture_alloc (tmp, int_pix_fmt, dst_width, dst_height,
3779 dst->interlaced) < 0)
3782 if (img_convert (tmp, int_pix_fmt,
3783 src, src_pix_fmt, src_width, src_height) < 0)
3786 if (img_convert (dst, dst_pix_fmt,
3787 tmp, int_pix_fmt, dst_width, dst_height) < 0)
3791 avpicture_free (tmp);
3795 /* NOTE: we scan all the pixels to have an exact information */
3797 get_alpha_info_pal8 (const AVPicture * src, int width, int height)
3799 const unsigned char *p;
3800 int src_wrap, ret, x, y;
3802 uint32_t *palette = (uint32_t *) src->data[1];
3805 src_wrap = src->linesize[0] - width;
3807 for (y = 0; y < height; y++) {
3808 for (x = 0; x < width; x++) {
3809 a = palette[p[0]] >> 24;
3811 ret |= FF_ALPHA_TRANSP;
3812 } else if (a != 0xff) {
3813 ret |= FF_ALPHA_SEMI_TRANSP;
3823 * Tell if an image really has transparent alpha values.
3824 * @return ored mask of FF_ALPHA_xxx constants
3827 img_get_alpha_info (const AVPicture * src, int pix_fmt, int width, int height)
3829 const PixFmtInfo *pf;
3832 pf = get_pix_fmt_info (pix_fmt);
3833 /* no alpha can be represented in format */
3838 ret = get_alpha_info_rgb32 (src, width, height);
3841 ret = get_alpha_info_bgr32 (src, width, height);
3843 case PIX_FMT_xRGB32:
3844 ret = get_alpha_info_xrgb32 (src, width, height);
3846 case PIX_FMT_BGRx32:
3847 ret = get_alpha_info_bgrx32 (src, width, height);
3849 case PIX_FMT_RGBA32:
3850 ret = get_alpha_info_rgba32 (src, width, height);
3852 case PIX_FMT_BGRA32:
3853 ret = get_alpha_info_bgra32 (src, width, height);
3855 case PIX_FMT_ARGB32:
3856 ret = get_alpha_info_argb32 (src, width, height);
3858 case PIX_FMT_ABGR32:
3859 ret = get_alpha_info_abgr32 (src, width, height);
3861 case PIX_FMT_RGB555:
3862 ret = get_alpha_info_rgb555 (src, width, height);
3865 ret = get_alpha_info_pal8 (src, width, height);
3868 /* we do not know, so everything is indicated */
3869 ret = FF_ALPHA_TRANSP | FF_ALPHA_SEMI_TRANSP;
3876 #define DEINT_INPLACE_LINE_LUM \
3877 movd_m2r(lum_m4[0],mm0);\
3878 movd_m2r(lum_m3[0],mm1);\
3879 movd_m2r(lum_m2[0],mm2);\
3880 movd_m2r(lum_m1[0],mm3);\
3881 movd_m2r(lum[0],mm4);\
3882 punpcklbw_r2r(mm7,mm0);\
3883 movd_r2m(mm2,lum_m4[0]);\
3884 punpcklbw_r2r(mm7,mm1);\
3885 punpcklbw_r2r(mm7,mm2);\
3886 punpcklbw_r2r(mm7,mm3);\
3887 punpcklbw_r2r(mm7,mm4);\
3888 paddw_r2r(mm3,mm1);\
3890 paddw_r2r(mm4,mm0);\
3892 paddw_r2r(mm6,mm2);\
3893 paddw_r2r(mm2,mm1);\
3894 psubusw_r2r(mm0,mm1);\
3896 packuswb_r2r(mm7,mm1);\
3897 movd_r2m(mm1,lum_m2[0]);
3899 #define DEINT_LINE_LUM \
3900 movd_m2r(lum_m4[0],mm0);\
3901 movd_m2r(lum_m3[0],mm1);\
3902 movd_m2r(lum_m2[0],mm2);\
3903 movd_m2r(lum_m1[0],mm3);\
3904 movd_m2r(lum[0],mm4);\
3905 punpcklbw_r2r(mm7,mm0);\
3906 punpcklbw_r2r(mm7,mm1);\
3907 punpcklbw_r2r(mm7,mm2);\
3908 punpcklbw_r2r(mm7,mm3);\
3909 punpcklbw_r2r(mm7,mm4);\
3910 paddw_r2r(mm3,mm1);\
3912 paddw_r2r(mm4,mm0);\
3914 paddw_r2r(mm6,mm2);\
3915 paddw_r2r(mm2,mm1);\
3916 psubusw_r2r(mm0,mm1);\
3918 packuswb_r2r(mm7,mm1);\
3919 movd_r2m(mm1,dst[0]);
3922 /* filter parameters: [-1 4 2 4 -1] // 8 */
3925 deinterlace_line (uint8_t * dst,
3926 const uint8_t * lum_m4, const uint8_t * lum_m3,
3927 const uint8_t * lum_m2, const uint8_t * lum_m1,
3928 const uint8_t * lum, int size)
3931 uint8_t *cm = cropTbl + MAX_NEG_CROP;
3934 for (; size > 0; size--) {
3936 sum += lum_m3[0] << 2;
3937 sum += lum_m2[0] << 1;
3938 sum += lum_m1[0] << 2;
3940 dst[0] = cm[(sum + 4) >> 3];
3957 pxor_r2r (mm7, mm7);
3958 movq_m2r (rounder, mm6);
3960 for (; size > 3; size -= 4) {
3961 DEINT_LINE_LUM lum_m4 += 4;
3973 deinterlace_line_inplace (uint8_t * lum_m4, uint8_t * lum_m3, uint8_t * lum_m2,
3974 uint8_t * lum_m1, uint8_t * lum, int size)
3977 uint8_t *cm = cropTbl + MAX_NEG_CROP;
3980 for (; size > 0; size--) {
3982 sum += lum_m3[0] << 2;
3983 sum += lum_m2[0] << 1;
3984 lum_m4[0] = lum_m2[0];
3985 sum += lum_m1[0] << 2;
3987 lum_m2[0] = cm[(sum + 4) >> 3];
4003 pxor_r2r (mm7, mm7);
4004 movq_m2r (rounder, mm6);
4006 for (; size > 3; size -= 4) {
4007 DEINT_INPLACE_LINE_LUM lum_m4 += 4;
4018 /* deinterlacing : 2 temporal taps, 3 spatial taps linear filter. The
4019 top field is copied as is, but the bottom field is deinterlaced
4020 against the top field. */
4023 deinterlace_bottom_field (uint8_t * dst, int dst_wrap,
4024 const uint8_t * src1, int src_wrap, int width, int height)
4026 const uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2;
4031 src_0 = &src_m1[src_wrap];
4032 src_p1 = &src_0[src_wrap];
4033 src_p2 = &src_p1[src_wrap];
4034 for (y = 0; y < (height - 2); y += 2) {
4035 memcpy (dst, src_m1, width);
4037 deinterlace_line (dst, src_m2, src_m1, src_0, src_p1, src_p2, width);
4041 src_p1 += 2 * src_wrap;
4042 src_p2 += 2 * src_wrap;
4045 memcpy (dst, src_m1, width);
4048 deinterlace_line (dst, src_m2, src_m1, src_0, src_0, src_0, width);
4052 deinterlace_bottom_field_inplace (uint8_t * src1, int src_wrap,
4053 int width, int height)
4055 uint8_t *src_m1, *src_0, *src_p1, *src_p2;
4059 buf = (uint8_t *) av_malloc (width);
4062 memcpy (buf, src_m1, width);
4063 src_0 = &src_m1[src_wrap];
4064 src_p1 = &src_0[src_wrap];
4065 src_p2 = &src_p1[src_wrap];
4066 for (y = 0; y < (height - 2); y += 2) {
4067 deinterlace_line_inplace (buf, src_m1, src_0, src_p1, src_p2, width);
4070 src_p1 += 2 * src_wrap;
4071 src_p2 += 2 * src_wrap;
4074 deinterlace_line_inplace (buf, src_m1, src_0, src_0, src_0, width);
4079 /* deinterlace - if not supported return -1 */
4082 avpicture_deinterlace (AVPicture * dst, const AVPicture * src,
4083 int pix_fmt, int width, int height)
4087 if (pix_fmt != PIX_FMT_YUV420P &&
4088 pix_fmt != PIX_FMT_YUV422P &&
4089 pix_fmt != PIX_FMT_YUV444P && pix_fmt != PIX_FMT_YUV411P)
4091 if ((width & 3) != 0 || (height & 3) != 0)
4094 for (i = 0; i < 3; i++) {
4097 case PIX_FMT_YUV420P:
4101 case PIX_FMT_YUV422P:
4104 case PIX_FMT_YUV411P:
4112 deinterlace_bottom_field_inplace (dst->data[i], dst->linesize[i],
4115 deinterlace_bottom_field (dst->data[i], dst->linesize[i],
4116 src->data[i], src->linesize[i], width, height);