Mercurial > libavcodec.hg
comparison imgconvert.c @ 1055:6261fdd1f69d libavcodec
added paletted 8 bit format support
author | bellard |
---|---|
date | Sun, 09 Feb 2003 16:20:25 +0000 |
parents | f529b09e64b7 |
children | bb5de8a59da8 |
comparison
equal
deleted
inserted
replaced
1054:f874e2122d45 | 1055:6261fdd1f69d |
---|---|
105 .nb_components = 1, .is_packed = 1, .is_gray = 1, | 105 .nb_components = 1, .is_packed = 1, .is_gray = 1, |
106 }, | 106 }, |
107 [PIX_FMT_MONOBLACK] = { | 107 [PIX_FMT_MONOBLACK] = { |
108 .name = "monob", | 108 .name = "monob", |
109 .nb_components = 1, .is_packed = 1, .is_gray = 1, | 109 .nb_components = 1, .is_packed = 1, .is_gray = 1, |
110 }, | |
111 | |
112 /* paletted formats */ | |
113 [PIX_FMT_PAL8] = { | |
114 .name = "pal8", | |
115 .nb_components = 1, .is_packed = 1, .is_paletted = 1, | |
110 }, | 116 }, |
111 }; | 117 }; |
112 | 118 |
113 void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift) | 119 void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift) |
114 { | 120 { |
186 picture->data[0] = ptr; | 192 picture->data[0] = ptr; |
187 picture->data[1] = NULL; | 193 picture->data[1] = NULL; |
188 picture->data[2] = NULL; | 194 picture->data[2] = NULL; |
189 picture->linesize[0] = (width + 7) >> 3; | 195 picture->linesize[0] = (width + 7) >> 3; |
190 return picture->linesize[0] * height; | 196 return picture->linesize[0] * height; |
197 case PIX_FMT_PAL8: | |
198 size2 = (size + 3) & ~3; | |
199 picture->data[0] = ptr; | |
200 picture->data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */ | |
201 picture->data[2] = NULL; | |
202 picture->linesize[0] = width; | |
203 picture->linesize[1] = 4; | |
204 return size2 + 256 * 4; | |
191 default: | 205 default: |
192 picture->data[0] = NULL; | 206 picture->data[0] = NULL; |
193 picture->data[1] = NULL; | 207 picture->data[1] = NULL; |
194 picture->data[2] = NULL; | 208 picture->data[2] = NULL; |
209 picture->data[3] = NULL; | |
195 return -1; | 210 return -1; |
196 } | 211 } |
197 } | 212 } |
198 | 213 |
199 int avpicture_get_size(int pix_fmt, int width, int height) | 214 int avpicture_get_size(int pix_fmt, int width, int height) |
676 p ++; \ | 691 p ++; \ |
677 } \ | 692 } \ |
678 p += src_wrap; \ | 693 p += src_wrap; \ |
679 q += dst_wrap; \ | 694 q += dst_wrap; \ |
680 } \ | 695 } \ |
696 } \ | |
697 \ | |
698 static void pal8_to_ ## rgb_name(AVPicture *dst, AVPicture *src, \ | |
699 int width, int height) \ | |
700 { \ | |
701 const unsigned char *p; \ | |
702 unsigned char *q; \ | |
703 int r, g, b, dst_wrap, src_wrap; \ | |
704 int x, y; \ | |
705 uint32_t v;\ | |
706 const uint32_t *palette;\ | |
707 \ | |
708 p = src->data[0]; \ | |
709 src_wrap = src->linesize[0] - width; \ | |
710 palette = (uint32_t *)src->data[1];\ | |
711 \ | |
712 q = dst->data[0]; \ | |
713 dst_wrap = dst->linesize[0] - BPP * width; \ | |
714 \ | |
715 for(y=0;y<height;y++) { \ | |
716 for(x=0;x<width;x++) { \ | |
717 v = palette[p[0]];\ | |
718 r = (v >> 16) & 0xff;\ | |
719 g = (v >> 8) & 0xff;\ | |
720 b = (v) & 0xff;\ | |
721 RGB_OUT(q, r, g, b); \ | |
722 q += BPP; \ | |
723 p ++; \ | |
724 } \ | |
725 p += src_wrap; \ | |
726 q += dst_wrap; \ | |
727 } \ | |
681 } | 728 } |
682 | 729 |
683 /* copy bit n to bits 0 ... n - 1 */ | 730 /* copy bit n to bits 0 ... n - 1 */ |
684 static inline unsigned int bitcopy_n(unsigned int a, int n) | 731 static inline unsigned int bitcopy_n(unsigned int a, int n) |
685 { | 732 { |
975 int width, int height) | 1022 int width, int height) |
976 { | 1023 { |
977 gray_to_mono(dst, src, width, height, 0x00); | 1024 gray_to_mono(dst, src, width, height, 0x00); |
978 } | 1025 } |
979 | 1026 |
1027 /* this is maybe slow, but allows for extensions */ | |
1028 static inline unsigned char gif_clut_index(UINT8 r, UINT8 g, UINT8 b) | |
1029 { | |
1030 return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6)); | |
1031 } | |
1032 | |
1033 /* XXX: put jpeg quantize code instead */ | |
1034 static void rgb24_to_pal8(AVPicture *dst, AVPicture *src, | |
1035 int width, int height) | |
1036 { | |
1037 const unsigned char *p; | |
1038 unsigned char *q; | |
1039 int r, g, b, dst_wrap, src_wrap; | |
1040 int x, y, i; | |
1041 static const uint8_t pal_value[6] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff }; | |
1042 uint32_t *pal; | |
1043 | |
1044 p = src->data[0]; | |
1045 src_wrap = src->linesize[0] - 3 * width; | |
1046 | |
1047 q = dst->data[0]; | |
1048 dst_wrap = dst->linesize[0] - width; | |
1049 | |
1050 for(y=0;y<height;y++) { | |
1051 for(x=0;x<width;x++) { | |
1052 r = p[0]; | |
1053 g = p[1]; | |
1054 b = p[2]; | |
1055 | |
1056 q[0] = gif_clut_index(r, g, b); | |
1057 q++; | |
1058 p += 3; | |
1059 } | |
1060 p += src_wrap; | |
1061 q += dst_wrap; | |
1062 } | |
1063 | |
1064 /* build palette */ | |
1065 pal = (uint32_t *)dst->data[1]; | |
1066 i = 0; | |
1067 for(r = 0; r < 6; r++) { | |
1068 for(g = 0; g < 6; g++) { | |
1069 for(b = 0; b < 6; b++) { | |
1070 pal[i++] = (0xff << 24) | (pal_value[r] << 16) | | |
1071 (pal_value[g] << 8) | pal_value[b]; | |
1072 } | |
1073 } | |
1074 } | |
1075 while (i < 256) | |
1076 pal[i++] = 0; | |
1077 } | |
1078 | |
980 typedef struct ConvertEntry { | 1079 typedef struct ConvertEntry { |
981 void (*convert)(AVPicture *dst, AVPicture *src, int width, int height); | 1080 void (*convert)(AVPicture *dst, AVPicture *src, int width, int height); |
982 } ConvertEntry; | 1081 } ConvertEntry; |
983 | 1082 |
984 /* add each new convertion function in this table */ | 1083 /* add each new convertion function in this table */ |
1037 .convert = rgb24_to_rgb555 | 1136 .convert = rgb24_to_rgb555 |
1038 }, | 1137 }, |
1039 [PIX_FMT_GRAY8] = { | 1138 [PIX_FMT_GRAY8] = { |
1040 .convert = rgb24_to_gray | 1139 .convert = rgb24_to_gray |
1041 }, | 1140 }, |
1141 [PIX_FMT_PAL8] = { | |
1142 .convert = rgb24_to_pal8 | |
1143 }, | |
1042 }, | 1144 }, |
1043 [PIX_FMT_RGBA32] = { | 1145 [PIX_FMT_RGBA32] = { |
1044 [PIX_FMT_YUV420P] = { | 1146 [PIX_FMT_YUV420P] = { |
1045 .convert = rgba32_to_yuv420p | 1147 .convert = rgba32_to_yuv420p |
1046 }, | 1148 }, |
1101 }, | 1203 }, |
1102 }, | 1204 }, |
1103 [PIX_FMT_MONOBLACK] = { | 1205 [PIX_FMT_MONOBLACK] = { |
1104 [PIX_FMT_GRAY8] = { | 1206 [PIX_FMT_GRAY8] = { |
1105 .convert = monoblack_to_gray | 1207 .convert = monoblack_to_gray |
1208 }, | |
1209 }, | |
1210 [PIX_FMT_PAL8] = { | |
1211 [PIX_FMT_RGB555] = { | |
1212 .convert = pal8_to_rgb555 | |
1213 }, | |
1214 [PIX_FMT_RGB565] = { | |
1215 .convert = pal8_to_rgb565 | |
1216 }, | |
1217 [PIX_FMT_BGR24] = { | |
1218 .convert = pal8_to_bgr24 | |
1219 }, | |
1220 [PIX_FMT_RGB24] = { | |
1221 .convert = pal8_to_rgb24 | |
1222 }, | |
1223 [PIX_FMT_RGBA32] = { | |
1224 .convert = pal8_to_rgba32 | |
1106 }, | 1225 }, |
1107 }, | 1226 }, |
1108 }; | 1227 }; |
1109 | 1228 |
1110 static int avpicture_alloc(AVPicture *picture, | 1229 static int avpicture_alloc(AVPicture *picture, |