Mercurial > mplayer.hg
comparison libswscale/swscale.c @ 29278:fdf257026cf0
Move colorspace conversion functions implemented in pure C from template
into swscale.c
author | kostya |
---|---|
date | Mon, 25 May 2009 16:42:54 +0000 |
parents | 9f1499cf3a68 |
children | 24954ec81529 |
comparison
equal
deleted
inserted
replaced
29277:ad3e27e1c279 | 29278:fdf257026cf0 |
---|---|
1120 memset(ptr, val, width); | 1120 memset(ptr, val, width); |
1121 ptr += stride; | 1121 ptr += stride; |
1122 } | 1122 } |
1123 } | 1123 } |
1124 | 1124 |
1125 #define BGR2Y(type, name, shr, shg, shb, maskr, maskg, maskb, RY, GY, BY, S)\ | |
1126 static inline void name(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)\ | |
1127 {\ | |
1128 int i;\ | |
1129 for (i=0; i<width; i++)\ | |
1130 {\ | |
1131 int b= (((const type*)src)[i]>>shb)&maskb;\ | |
1132 int g= (((const type*)src)[i]>>shg)&maskg;\ | |
1133 int r= (((const type*)src)[i]>>shr)&maskr;\ | |
1134 \ | |
1135 dst[i]= (((RY)*r + (GY)*g + (BY)*b + (33<<((S)-1)))>>(S));\ | |
1136 }\ | |
1137 } | |
1138 | |
1139 BGR2Y(uint32_t, bgr32ToY,16, 0, 0, 0x00FF, 0xFF00, 0x00FF, RY<< 8, GY , BY<< 8, RGB2YUV_SHIFT+8) | |
1140 BGR2Y(uint32_t, rgb32ToY, 0, 0,16, 0x00FF, 0xFF00, 0x00FF, RY<< 8, GY , BY<< 8, RGB2YUV_SHIFT+8) | |
1141 BGR2Y(uint16_t, bgr16ToY, 0, 0, 0, 0x001F, 0x07E0, 0xF800, RY<<11, GY<<5, BY , RGB2YUV_SHIFT+8) | |
1142 BGR2Y(uint16_t, bgr15ToY, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RY<<10, GY<<5, BY , RGB2YUV_SHIFT+7) | |
1143 BGR2Y(uint16_t, rgb16ToY, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RY , GY<<5, BY<<11, RGB2YUV_SHIFT+8) | |
1144 BGR2Y(uint16_t, rgb15ToY, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RY , GY<<5, BY<<10, RGB2YUV_SHIFT+7) | |
1145 | |
1146 static inline void abgrToA(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused){ | |
1147 int i; | |
1148 for (i=0; i<width; i++){ | |
1149 dst[i]= src[4*i]; | |
1150 } | |
1151 } | |
1152 | |
1153 #define BGR2UV(type, name, shr, shg, shb, maska, maskr, maskg, maskb, RU, GU, BU, RV, GV, BV, S)\ | |
1154 static inline void name(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\ | |
1155 {\ | |
1156 int i;\ | |
1157 for (i=0; i<width; i++)\ | |
1158 {\ | |
1159 int b= (((const type*)src)[i]&maskb)>>shb;\ | |
1160 int g= (((const type*)src)[i]&maskg)>>shg;\ | |
1161 int r= (((const type*)src)[i]&maskr)>>shr;\ | |
1162 \ | |
1163 dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<((S)-1)))>>(S);\ | |
1164 dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (257<<((S)-1)))>>(S);\ | |
1165 }\ | |
1166 }\ | |
1167 static inline void name ## _half(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\ | |
1168 {\ | |
1169 int i;\ | |
1170 for (i=0; i<width; i++)\ | |
1171 {\ | |
1172 int pix0= ((const type*)src)[2*i+0];\ | |
1173 int pix1= ((const type*)src)[2*i+1];\ | |
1174 int g= (pix0&~(maskr|maskb))+(pix1&~(maskr|maskb));\ | |
1175 int b= ((pix0+pix1-g)&(maskb|(2*maskb)))>>shb;\ | |
1176 int r= ((pix0+pix1-g)&(maskr|(2*maskr)))>>shr;\ | |
1177 g&= maskg|(2*maskg);\ | |
1178 \ | |
1179 g>>=shg;\ | |
1180 \ | |
1181 dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<(S)))>>((S)+1);\ | |
1182 dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (257<<(S)))>>((S)+1);\ | |
1183 }\ | |
1184 } | |
1185 | |
1186 BGR2UV(uint32_t, bgr32ToUV,16, 0, 0, 0xFF000000, 0xFF0000, 0xFF00, 0x00FF, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8) | |
1187 BGR2UV(uint32_t, rgb32ToUV, 0, 0,16, 0xFF000000, 0x00FF, 0xFF00, 0xFF0000, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8) | |
1188 BGR2UV(uint16_t, bgr16ToUV, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, RU<<11, GU<<5, BU , RV<<11, GV<<5, BV , RGB2YUV_SHIFT+8) | |
1189 BGR2UV(uint16_t, bgr15ToUV, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RU<<10, GU<<5, BU , RV<<10, GV<<5, BV , RGB2YUV_SHIFT+7) | |
1190 BGR2UV(uint16_t, rgb16ToUV, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RU , GU<<5, BU<<11, RV , GV<<5, BV<<11, RGB2YUV_SHIFT+8) | |
1191 BGR2UV(uint16_t, rgb15ToUV, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RU , GU<<5, BU<<10, RV , GV<<5, BV<<10, RGB2YUV_SHIFT+7) | |
1192 | |
1193 static inline void palToY(uint8_t *dst, const uint8_t *src, long width, uint32_t *pal) | |
1194 { | |
1195 int i; | |
1196 for (i=0; i<width; i++) | |
1197 { | |
1198 int d= src[i]; | |
1199 | |
1200 dst[i]= pal[d] & 0xFF; | |
1201 } | |
1202 } | |
1203 | |
1204 static inline void palToUV(uint8_t *dstU, uint8_t *dstV, | |
1205 const uint8_t *src1, const uint8_t *src2, | |
1206 long width, uint32_t *pal) | |
1207 { | |
1208 int i; | |
1209 assert(src1 == src2); | |
1210 for (i=0; i<width; i++) | |
1211 { | |
1212 int p= pal[src1[i]]; | |
1213 | |
1214 dstU[i]= p>>8; | |
1215 dstV[i]= p>>16; | |
1216 } | |
1217 } | |
1218 | |
1219 static inline void monowhite2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) | |
1220 { | |
1221 int i, j; | |
1222 for (i=0; i<width/8; i++){ | |
1223 int d= ~src[i]; | |
1224 for(j=0; j<8; j++) | |
1225 dst[8*i+j]= ((d>>(7-j))&1)*255; | |
1226 } | |
1227 } | |
1228 | |
1229 static inline void monoblack2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) | |
1230 { | |
1231 int i, j; | |
1232 for (i=0; i<width/8; i++){ | |
1233 int d= src[i]; | |
1234 for(j=0; j<8; j++) | |
1235 dst[8*i+j]= ((d>>(7-j))&1)*255; | |
1236 } | |
1237 } | |
1238 | |
1239 | |
1125 //Note: we have C, MMX, MMX2, 3DNOW versions, there is no 3DNOW+MMX2 one | 1240 //Note: we have C, MMX, MMX2, 3DNOW versions, there is no 3DNOW+MMX2 one |
1126 //Plain C versions | 1241 //Plain C versions |
1127 #if !HAVE_MMX || CONFIG_RUNTIME_CPUDETECT || !CONFIG_GPL | 1242 #if !HAVE_MMX || CONFIG_RUNTIME_CPUDETECT || !CONFIG_GPL |
1128 #define COMPILE_C | 1243 #define COMPILE_C |
1129 #endif | 1244 #endif |