comparison imgconvert.c @ 2137:ef47c0b1ff28 libavcodec

UYVY support patch by ("Todd.Kirby" <doubleshot at pacbell dot net>)
author michael
date Sun, 25 Jul 2004 10:01:36 +0000
parents 5495691106c3
children 34eaf41657d5
comparison
equal deleted inserted replaced
2136:fd1665b9093c 2137:ef47c0b1ff28
89 .depth = 8, 89 .depth = 8,
90 .x_chroma_shift = 0, .y_chroma_shift = 0, 90 .x_chroma_shift = 0, .y_chroma_shift = 0,
91 }, 91 },
92 [PIX_FMT_YUV422] = { 92 [PIX_FMT_YUV422] = {
93 .name = "yuv422", 93 .name = "yuv422",
94 .nb_channels = 1,
95 .color_type = FF_COLOR_YUV,
96 .pixel_type = FF_PIXEL_PACKED,
97 .depth = 8,
98 .x_chroma_shift = 1, .y_chroma_shift = 0,
99 },
100 [PIX_FMT_UYVY422] = {
101 .name = "uyvy422",
94 .nb_channels = 1, 102 .nb_channels = 1,
95 .color_type = FF_COLOR_YUV, 103 .color_type = FF_COLOR_YUV,
96 .pixel_type = FF_PIXEL_PACKED, 104 .pixel_type = FF_PIXEL_PACKED,
97 .depth = 8, 105 .depth = 8,
98 .x_chroma_shift = 1, .y_chroma_shift = 0, 106 .x_chroma_shift = 1, .y_chroma_shift = 0,
286 picture->data[0] = ptr; 294 picture->data[0] = ptr;
287 picture->data[1] = NULL; 295 picture->data[1] = NULL;
288 picture->data[2] = NULL; 296 picture->data[2] = NULL;
289 picture->linesize[0] = width * 2; 297 picture->linesize[0] = width * 2;
290 return size * 2; 298 return size * 2;
299 case PIX_FMT_UYVY422:
300 picture->data[0] = ptr;
301 picture->data[1] = NULL;
302 picture->data[2] = NULL;
303 picture->linesize[0] = width * 2;
304 return size * 2;
291 case PIX_FMT_GRAY8: 305 case PIX_FMT_GRAY8:
292 picture->data[0] = ptr; 306 picture->data[0] = ptr;
293 picture->data[1] = NULL; 307 picture->data[1] = NULL;
294 picture->data[2] = NULL; 308 picture->data[2] = NULL;
295 picture->linesize[0] = width; 309 picture->linesize[0] = width;
328 342
329 if (size > dest_size) 343 if (size > dest_size)
330 return -1; 344 return -1;
331 345
332 if (pf->pixel_type == FF_PIXEL_PACKED || pf->pixel_type == FF_PIXEL_PALETTE) { 346 if (pf->pixel_type == FF_PIXEL_PACKED || pf->pixel_type == FF_PIXEL_PALETTE) {
333 if (pix_fmt == PIX_FMT_YUV422 || pix_fmt == PIX_FMT_RGB565 || 347 if (pix_fmt == PIX_FMT_YUV422 ||
334 pix_fmt == PIX_FMT_RGB555) 348 pix_fmt == PIX_FMT_UYVY422 ||
335 w = width * 2; 349 pix_fmt == PIX_FMT_RGB565 ||
350 pix_fmt == PIX_FMT_RGB555)
351 w = width * 2;
336 else if (pix_fmt == PIX_FMT_PAL8) 352 else if (pix_fmt == PIX_FMT_PAL8)
337 w = width; 353 w = width;
338 else 354 else
339 w = width * (pf->depth * pf->nb_channels / 8); 355 w = width * (pf->depth * pf->nb_channels / 8);
340 356
437 pf = &pix_fmt_info[pix_fmt]; 453 pf = &pix_fmt_info[pix_fmt];
438 switch(pf->pixel_type) { 454 switch(pf->pixel_type) {
439 case FF_PIXEL_PACKED: 455 case FF_PIXEL_PACKED:
440 switch(pix_fmt) { 456 switch(pix_fmt) {
441 case PIX_FMT_YUV422: 457 case PIX_FMT_YUV422:
458 case PIX_FMT_UYVY422:
442 case PIX_FMT_RGB565: 459 case PIX_FMT_RGB565:
443 case PIX_FMT_RGB555: 460 case PIX_FMT_RGB555:
444 bits = 16; 461 bits = 16;
445 break; 462 break;
446 default: 463 default:
549 pf = &pix_fmt_info[pix_fmt]; 566 pf = &pix_fmt_info[pix_fmt];
550 switch(pf->pixel_type) { 567 switch(pf->pixel_type) {
551 case FF_PIXEL_PACKED: 568 case FF_PIXEL_PACKED:
552 switch(pix_fmt) { 569 switch(pix_fmt) {
553 case PIX_FMT_YUV422: 570 case PIX_FMT_YUV422:
571 case PIX_FMT_UYVY422:
554 case PIX_FMT_RGB565: 572 case PIX_FMT_RGB565:
555 case PIX_FMT_RGB555: 573 case PIX_FMT_RGB555:
556 bits = 16; 574 bits = 16;
557 break; 575 break;
558 default: 576 default:
647 cb1 += dst->linesize[1]; 665 cb1 += dst->linesize[1];
648 cr1 += dst->linesize[2]; 666 cr1 += dst->linesize[2];
649 } 667 }
650 } 668 }
651 669
670 static void uyvy422_to_yuv420p(AVPicture *dst, const AVPicture *src,
671 int width, int height)
672 {
673 const uint8_t *p, *p1;
674 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
675 int w;
676
677 p1 = src->data[0];
678
679 lum1 = dst->data[0];
680 cb1 = dst->data[1];
681 cr1 = dst->data[2];
682
683 for(;height >= 1; height -= 2) {
684 p = p1;
685 lum = lum1;
686 cb = cb1;
687 cr = cr1;
688 for(w = width; w >= 2; w -= 2) {
689 lum[0] = p[1];
690 cb[0] = p[0];
691 lum[1] = p[3];
692 cr[0] = p[2];
693 p += 4;
694 lum += 2;
695 cb++;
696 cr++;
697 }
698 if (w) {
699 lum[0] = p[1];
700 cb[0] = p[0];
701 cr[0] = p[2];
702 cb++;
703 cr++;
704 }
705 p1 += src->linesize[0];
706 lum1 += dst->linesize[0];
707 if (height>1) {
708 p = p1;
709 lum = lum1;
710 for(w = width; w >= 2; w -= 2) {
711 lum[0] = p[1];
712 lum[1] = p[3];
713 p += 4;
714 lum += 2;
715 }
716 if (w) {
717 lum[0] = p[1];
718 }
719 p1 += src->linesize[0];
720 lum1 += dst->linesize[0];
721 }
722 cb1 += dst->linesize[1];
723 cr1 += dst->linesize[2];
724 }
725 }
726
727
728 static void uyvy422_to_yuv422p(AVPicture *dst, const AVPicture *src,
729 int width, int height)
730 {
731 const uint8_t *p, *p1;
732 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
733 int w;
734
735 p1 = src->data[0];
736 lum1 = dst->data[0];
737 cb1 = dst->data[1];
738 cr1 = dst->data[2];
739 for(;height > 0; height--) {
740 p = p1;
741 lum = lum1;
742 cb = cb1;
743 cr = cr1;
744 for(w = width; w >= 2; w -= 2) {
745 lum[0] = p[1];
746 cb[0] = p[0];
747 lum[1] = p[3];
748 cr[0] = p[2];
749 p += 4;
750 lum += 2;
751 cb++;
752 cr++;
753 }
754 p1 += src->linesize[0];
755 lum1 += dst->linesize[0];
756 cb1 += dst->linesize[1];
757 cr1 += dst->linesize[2];
758 }
759 }
760
761
652 static void yuv422_to_yuv422p(AVPicture *dst, const AVPicture *src, 762 static void yuv422_to_yuv422p(AVPicture *dst, const AVPicture *src,
653 int width, int height) 763 int width, int height)
654 { 764 {
655 const uint8_t *p, *p1; 765 const uint8_t *p, *p1;
656 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1; 766 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
713 cb1 += src->linesize[1]; 823 cb1 += src->linesize[1];
714 cr1 += src->linesize[2]; 824 cr1 += src->linesize[2];
715 } 825 }
716 } 826 }
717 827
828 static void yuv422p_to_uyvy422(AVPicture *dst, const AVPicture *src,
829 int width, int height)
830 {
831 uint8_t *p, *p1;
832 const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
833 int w;
834
835 p1 = dst->data[0];
836 lum1 = src->data[0];
837 cb1 = src->data[1];
838 cr1 = src->data[2];
839 for(;height > 0; height--) {
840 p = p1;
841 lum = lum1;
842 cb = cb1;
843 cr = cr1;
844 for(w = width; w >= 2; w -= 2) {
845 p[1] = lum[0];
846 p[0] = cb[0];
847 p[3] = lum[1];
848 p[2] = cr[0];
849 p += 4;
850 lum += 2;
851 cb++;
852 cr++;
853 }
854 p1 += dst->linesize[0];
855 lum1 += src->linesize[0];
856 cb1 += src->linesize[1];
857 cr1 += src->linesize[2];
858 }
859 }
860
861
862
718 #define SCALEBITS 10 863 #define SCALEBITS 10
719 #define ONE_HALF (1 << (SCALEBITS - 1)) 864 #define ONE_HALF (1 << (SCALEBITS - 1))
720 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5)) 865 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
721 866
722 #define YUV_TO_RGB1_CCIR(cb1, cr1)\ 867 #define YUV_TO_RGB1_CCIR(cb1, cr1)\
1442 }, 1587 },
1443 [PIX_FMT_YUV422P] = { 1588 [PIX_FMT_YUV422P] = {
1444 [PIX_FMT_YUV422] = { 1589 [PIX_FMT_YUV422] = {
1445 .convert = yuv422p_to_yuv422, 1590 .convert = yuv422p_to_yuv422,
1446 }, 1591 },
1592 [PIX_FMT_UYVY422] = {
1593 .convert = yuv422p_to_uyvy422,
1594 },
1447 }, 1595 },
1448 [PIX_FMT_YUV444P] = { 1596 [PIX_FMT_YUV444P] = {
1449 [PIX_FMT_RGB24] = { 1597 [PIX_FMT_RGB24] = {
1450 .convert = yuv444p_to_rgb24 1598 .convert = yuv444p_to_rgb24
1451 }, 1599 },
1478 }, 1626 },
1479 [PIX_FMT_YUV422P] = { 1627 [PIX_FMT_YUV422P] = {
1480 .convert = yuv422_to_yuv422p, 1628 .convert = yuv422_to_yuv422p,
1481 }, 1629 },
1482 }, 1630 },
1483 1631 [PIX_FMT_UYVY422] = {
1632 [PIX_FMT_YUV420P] = {
1633 .convert = uyvy422_to_yuv420p,
1634 },
1635 [PIX_FMT_YUV422P] = {
1636 .convert = uyvy422_to_yuv422p,
1637 },
1638 },
1484 [PIX_FMT_RGB24] = { 1639 [PIX_FMT_RGB24] = {
1485 [PIX_FMT_YUV420P] = { 1640 [PIX_FMT_YUV420P] = {
1486 .convert = rgb24_to_yuv420p 1641 .convert = rgb24_to_yuv420p
1487 }, 1642 },
1488 [PIX_FMT_RGB565] = { 1643 [PIX_FMT_RGB565] = {
1681 return 0; 1836 return 0;
1682 } 1837 }
1683 1838
1684 ce = &convert_table[src_pix_fmt][dst_pix_fmt]; 1839 ce = &convert_table[src_pix_fmt][dst_pix_fmt];
1685 if (ce->convert) { 1840 if (ce->convert) {
1686 /* specific convertion routine */ 1841 /* specific conversion routine */
1687 ce->convert(dst, src, dst_width, dst_height); 1842 ce->convert(dst, src, dst_width, dst_height);
1688 return 0; 1843 return 0;
1689 } 1844 }
1690 1845
1691 /* gray to YUV */ 1846 /* gray to YUV */
1836 /* try to use an intermediate format */ 1991 /* try to use an intermediate format */
1837 if (src_pix_fmt == PIX_FMT_YUV422 || 1992 if (src_pix_fmt == PIX_FMT_YUV422 ||
1838 dst_pix_fmt == PIX_FMT_YUV422) { 1993 dst_pix_fmt == PIX_FMT_YUV422) {
1839 /* specific case: convert to YUV422P first */ 1994 /* specific case: convert to YUV422P first */
1840 int_pix_fmt = PIX_FMT_YUV422P; 1995 int_pix_fmt = PIX_FMT_YUV422P;
1996 } else if (src_pix_fmt == PIX_FMT_UYVY422 ||
1997 dst_pix_fmt == PIX_FMT_UYVY422) {
1998 /* specific case: convert to YUV422P first */
1999 int_pix_fmt = PIX_FMT_YUV422P;
1841 } else if ((src_pix->color_type == FF_COLOR_GRAY && 2000 } else if ((src_pix->color_type == FF_COLOR_GRAY &&
1842 src_pix_fmt != PIX_FMT_GRAY8) || 2001 src_pix_fmt != PIX_FMT_GRAY8) ||
1843 (dst_pix->color_type == FF_COLOR_GRAY && 2002 (dst_pix->color_type == FF_COLOR_GRAY &&
1844 dst_pix_fmt != PIX_FMT_GRAY8)) { 2003 dst_pix_fmt != PIX_FMT_GRAY8)) {
1845 /* gray8 is the normalized format */ 2004 /* gray8 is the normalized format */