Mercurial > libavcodec.hg
comparison imgconvert.c @ 1022:d651df667898 libavcodec
added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
author | bellard |
---|---|
date | Mon, 20 Jan 2003 22:26:19 +0000 |
parents | 617e3531d3fb |
children | e61be5796027 |
comparison
equal
deleted
inserted
replaced
1021:2d7c9f5738de | 1022:d651df667898 |
---|---|
518 lum = dst->data[0]; \ | 518 lum = dst->data[0]; \ |
519 cb = dst->data[1]; \ | 519 cb = dst->data[1]; \ |
520 cr = dst->data[2]; \ | 520 cr = dst->data[2]; \ |
521 \ | 521 \ |
522 wrap = width; \ | 522 wrap = width; \ |
523 wrap3 = width * 3; \ | 523 wrap3 = width * BPP; \ |
524 p = src->data[0]; \ | 524 p = src->data[0]; \ |
525 for(y=0;y<height;y+=2) { \ | 525 for(y=0;y<height;y+=2) { \ |
526 for(x=0;x<width;x+=2) { \ | 526 for(x=0;x<width;x+=2) { \ |
527 RGB_IN(r, g, b, p); \ | 527 RGB_IN(r, g, b, p); \ |
528 r1 = r; \ | 528 r1 = r; \ |
560 FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> \ | 560 FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> \ |
561 (SCALEBITS + 2)) + 128; \ | 561 (SCALEBITS + 2)) + 128; \ |
562 \ | 562 \ |
563 cb++; \ | 563 cb++; \ |
564 cr++; \ | 564 cr++; \ |
565 p += -wrap3 + 2 * 3; \ | 565 p += -wrap3 + 2 * BPP; \ |
566 lum += -wrap + 2; \ | 566 lum += -wrap + 2; \ |
567 } \ | 567 } \ |
568 p += wrap3; \ | 568 p += wrap3; \ |
569 lum += wrap; \ | 569 lum += wrap; \ |
570 } \ | |
571 } \ | |
572 \ | |
573 static void rgb_name ## _to_gray(AVPicture *dst, AVPicture *src, \ | |
574 int width, int height) \ | |
575 { \ | |
576 const unsigned char *p; \ | |
577 unsigned char *q; \ | |
578 int r, g, b, dst_wrap, src_wrap; \ | |
579 int x, y; \ | |
580 \ | |
581 p = src->data[0]; \ | |
582 src_wrap = src->linesize[0] - BPP * width; \ | |
583 \ | |
584 q = dst->data[0]; \ | |
585 dst_wrap = dst->linesize[0] - width; \ | |
586 \ | |
587 for(y=0;y<height;y++) { \ | |
588 for(x=0;x<width;x++) { \ | |
589 RGB_IN(r, g, b, p); \ | |
590 q[0] = (FIX(0.29900) * r + FIX(0.58700) * g + \ | |
591 FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; \ | |
592 q++; \ | |
593 p += BPP; \ | |
594 } \ | |
595 p += src_wrap; \ | |
596 q += dst_wrap; \ | |
597 } \ | |
598 } \ | |
599 \ | |
600 static void gray_to_ ## rgb_name(AVPicture *dst, AVPicture *src, \ | |
601 int width, int height) \ | |
602 { \ | |
603 const unsigned char *p; \ | |
604 unsigned char *q; \ | |
605 int r, dst_wrap, src_wrap; \ | |
606 int x, y; \ | |
607 \ | |
608 p = src->data[0]; \ | |
609 src_wrap = src->linesize[0] - width; \ | |
610 \ | |
611 q = dst->data[0]; \ | |
612 dst_wrap = dst->linesize[0] - BPP * width; \ | |
613 \ | |
614 for(y=0;y<height;y++) { \ | |
615 for(x=0;x<width;x++) { \ | |
616 r = p[0]; \ | |
617 RGB_OUT(q, r, r, r); \ | |
618 q += BPP; \ | |
619 p ++; \ | |
620 } \ | |
621 p += src_wrap; \ | |
622 q += dst_wrap; \ | |
570 } \ | 623 } \ |
571 } | 624 } |
572 | 625 |
573 /* copy bit n to bits 0 ... n - 1 */ | 626 /* copy bit n to bits 0 ... n - 1 */ |
574 static inline unsigned int bitcopy_n(unsigned int a, int n) | 627 static inline unsigned int bitcopy_n(unsigned int a, int n) |
749 | 802 |
750 ((unsigned short *)q)[0] = | 803 ((unsigned short *)q)[0] = |
751 ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) | 0x8000; | 804 ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) | 0x8000; |
752 q += 2; | 805 q += 2; |
753 p += 3; | 806 p += 3; |
754 } | |
755 p += src_wrap; | |
756 q += dst_wrap; | |
757 } | |
758 } | |
759 | |
760 static void rgb24_to_gray(AVPicture *dst, AVPicture *src, | |
761 int width, int height) | |
762 { | |
763 const unsigned char *p; | |
764 unsigned char *q; | |
765 int r, g, b, dst_wrap, src_wrap; | |
766 int x, y; | |
767 | |
768 p = src->data[0]; | |
769 src_wrap = src->linesize[0] - 3 * width; | |
770 | |
771 q = dst->data[0]; | |
772 dst_wrap = dst->linesize[0] - width; | |
773 | |
774 for(y=0;y<height;y++) { | |
775 for(x=0;x<width;x++) { | |
776 r = p[0]; | |
777 g = p[1]; | |
778 b = p[2]; | |
779 | |
780 q[0] = (FIX(0.29900) * r + FIX(0.58700) * g + | |
781 FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; | |
782 q++; | |
783 p += 3; | |
784 } | |
785 p += src_wrap; | |
786 q += dst_wrap; | |
787 } | |
788 } | |
789 | |
790 static void gray_to_rgb24(AVPicture *dst, AVPicture *src, | |
791 int width, int height) | |
792 { | |
793 const unsigned char *p; | |
794 unsigned char *q; | |
795 int r, dst_wrap, src_wrap; | |
796 int x, y; | |
797 | |
798 p = src->data[0]; | |
799 src_wrap = src->linesize[0] - width; | |
800 | |
801 q = dst->data[0]; | |
802 dst_wrap = dst->linesize[0] - 3 * width; | |
803 | |
804 for(y=0;y<height;y++) { | |
805 for(x=0;x<width;x++) { | |
806 r = p[0]; | |
807 | |
808 q[0] = r; | |
809 q[1] = r; | |
810 q[2] = r; | |
811 | |
812 q += 3; | |
813 p ++; | |
814 } | 807 } |
815 p += src_wrap; | 808 p += src_wrap; |
816 q += dst_wrap; | 809 q += dst_wrap; |
817 } | 810 } |
818 } | 811 } |
992 }, | 985 }, |
993 [PIX_FMT_RGBA32] = { | 986 [PIX_FMT_RGBA32] = { |
994 [PIX_FMT_YUV420P] = { | 987 [PIX_FMT_YUV420P] = { |
995 .convert = rgba32_to_yuv420p | 988 .convert = rgba32_to_yuv420p |
996 }, | 989 }, |
990 [PIX_FMT_GRAY8] = { | |
991 .convert = rgba32_to_gray | |
992 }, | |
997 }, | 993 }, |
998 [PIX_FMT_BGR24] = { | 994 [PIX_FMT_BGR24] = { |
999 [PIX_FMT_YUV420P] = { | 995 [PIX_FMT_YUV420P] = { |
1000 .convert = bgr24_to_yuv420p | 996 .convert = bgr24_to_yuv420p |
1001 }, | 997 }, |
998 [PIX_FMT_GRAY8] = { | |
999 .convert = bgr24_to_gray | |
1000 }, | |
1002 }, | 1001 }, |
1003 [PIX_FMT_RGB555] = { | 1002 [PIX_FMT_RGB555] = { |
1004 [PIX_FMT_YUV420P] = { | 1003 [PIX_FMT_YUV420P] = { |
1005 .convert = rgb555_to_yuv420p | 1004 .convert = rgb555_to_yuv420p |
1006 }, | 1005 }, |
1006 [PIX_FMT_GRAY8] = { | |
1007 .convert = rgb555_to_gray | |
1008 }, | |
1007 }, | 1009 }, |
1008 [PIX_FMT_RGB565] = { | 1010 [PIX_FMT_RGB565] = { |
1009 [PIX_FMT_YUV420P] = { | 1011 [PIX_FMT_YUV420P] = { |
1010 .convert = rgb565_to_yuv420p | 1012 .convert = rgb565_to_yuv420p |
1011 }, | 1013 }, |
1014 [PIX_FMT_GRAY8] = { | |
1015 .convert = rgb565_to_gray | |
1016 }, | |
1012 }, | 1017 }, |
1013 [PIX_FMT_GRAY8] = { | 1018 [PIX_FMT_GRAY8] = { |
1019 [PIX_FMT_RGB555] = { | |
1020 .convert = gray_to_rgb555 | |
1021 }, | |
1022 [PIX_FMT_RGB565] = { | |
1023 .convert = gray_to_rgb565 | |
1024 }, | |
1014 [PIX_FMT_RGB24] = { | 1025 [PIX_FMT_RGB24] = { |
1015 .convert = gray_to_rgb24 | 1026 .convert = gray_to_rgb24 |
1027 }, | |
1028 [PIX_FMT_BGR24] = { | |
1029 .convert = gray_to_bgr24 | |
1030 }, | |
1031 [PIX_FMT_RGBA32] = { | |
1032 .convert = gray_to_rgba32 | |
1016 }, | 1033 }, |
1017 [PIX_FMT_MONOWHITE] = { | 1034 [PIX_FMT_MONOWHITE] = { |
1018 .convert = gray_to_monowhite | 1035 .convert = gray_to_monowhite |
1019 }, | 1036 }, |
1020 [PIX_FMT_MONOBLACK] = { | 1037 [PIX_FMT_MONOBLACK] = { |
1070 if (src_pix_fmt < 0 || src_pix_fmt >= PIX_FMT_NB || | 1087 if (src_pix_fmt < 0 || src_pix_fmt >= PIX_FMT_NB || |
1071 dst_pix_fmt < 0 || dst_pix_fmt >= PIX_FMT_NB) | 1088 dst_pix_fmt < 0 || dst_pix_fmt >= PIX_FMT_NB) |
1072 return -1; | 1089 return -1; |
1073 if (src_width <= 0 || src_height <= 0) | 1090 if (src_width <= 0 || src_height <= 0) |
1074 return 0; | 1091 return 0; |
1075 | 1092 |
1076 dst_width = src_width; | 1093 dst_width = src_width; |
1077 dst_height = src_height; | 1094 dst_height = src_height; |
1078 | 1095 |
1079 dst_pix = &pix_fmt_info[dst_pix_fmt]; | 1096 dst_pix = &pix_fmt_info[dst_pix_fmt]; |
1080 src_pix = &pix_fmt_info[src_pix_fmt]; | 1097 src_pix = &pix_fmt_info[src_pix_fmt]; |
1081 if (src_pix_fmt == dst_pix_fmt) { | 1098 if (src_pix_fmt == dst_pix_fmt) { |
1082 /* XXX: incorrect */ | 1099 /* XXX: incorrect */ |
1083 /* same format: just copy */ | 1100 /* same format: just copy */ |