comparison imgconvert.c @ 5354:dfa6e7fa2bac libavcodec

create colorspace.h and use it where appropriate patch by Ian Caulfield: /ian caulfield gmail com/
author benoit
date Tue, 17 Jul 2007 12:33:14 +0000
parents 9930b7031cb2
children 45d083bbbbe7
comparison
equal deleted inserted replaced
5353:7e4703e16bbd 5354:dfa6e7fa2bac
30 * - integrate deinterlacing, postprocessing and scaling in the conversion process 30 * - integrate deinterlacing, postprocessing and scaling in the conversion process
31 */ 31 */
32 32
33 #include "avcodec.h" 33 #include "avcodec.h"
34 #include "dsputil.h" 34 #include "dsputil.h"
35 #include "colorspace.h"
35 36
36 #ifdef HAVE_MMX 37 #ifdef HAVE_MMX
37 #include "i386/mmx.h" 38 #include "i386/mmx.h"
38 #endif 39 #endif
39 40
1156 cb2 += src->linesize[1]; 1157 cb2 += src->linesize[1];
1157 cr2 += src->linesize[2]; 1158 cr2 += src->linesize[2];
1158 } 1159 }
1159 } 1160 }
1160 1161
1161 #define SCALEBITS 10
1162 #define ONE_HALF (1 << (SCALEBITS - 1))
1163 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
1164
1165 #define YUV_TO_RGB1_CCIR(cb1, cr1)\
1166 {\
1167 cb = (cb1) - 128;\
1168 cr = (cr1) - 128;\
1169 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
1170 g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
1171 ONE_HALF;\
1172 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
1173 }
1174
1175 #define YUV_TO_RGB2_CCIR(r, g, b, y1)\
1176 {\
1177 y = ((y1) - 16) * FIX(255.0/219.0);\
1178 r = cm[(y + r_add) >> SCALEBITS];\
1179 g = cm[(y + g_add) >> SCALEBITS];\
1180 b = cm[(y + b_add) >> SCALEBITS];\
1181 }
1182
1183 #define YUV_TO_RGB1(cb1, cr1)\
1184 {\
1185 cb = (cb1) - 128;\
1186 cr = (cr1) - 128;\
1187 r_add = FIX(1.40200) * cr + ONE_HALF;\
1188 g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
1189 b_add = FIX(1.77200) * cb + ONE_HALF;\
1190 }
1191
1192 #define YUV_TO_RGB2(r, g, b, y1)\
1193 {\
1194 y = (y1) << SCALEBITS;\
1195 r = cm[(y + r_add) >> SCALEBITS];\
1196 g = cm[(y + g_add) >> SCALEBITS];\
1197 b = cm[(y + b_add) >> SCALEBITS];\
1198 }
1199
1200 #define Y_CCIR_TO_JPEG(y)\
1201 cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS]
1202
1203 #define Y_JPEG_TO_CCIR(y)\
1204 (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
1205
1206 #define C_CCIR_TO_JPEG(y)\
1207 cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS]
1208
1209 /* NOTE: the clamp is really necessary! */
1210 static inline int C_JPEG_TO_CCIR(int y) {
1211 y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS);
1212 if (y < 16)
1213 y = 16;
1214 return y;
1215 }
1216
1217
1218 #define RGB_TO_Y(r, g, b) \
1219 ((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
1220 FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
1221
1222 #define RGB_TO_U(r1, g1, b1, shift)\
1223 (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
1224 FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1225
1226 #define RGB_TO_V(r1, g1, b1, shift)\
1227 (((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
1228 FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1229
1230 #define RGB_TO_Y_CCIR(r, g, b) \
1231 ((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
1232 FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
1233
1234 #define RGB_TO_U_CCIR(r1, g1, b1, shift)\
1235 (((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
1236 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1237
1238 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\
1239 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
1240 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1241
1242 static uint8_t y_ccir_to_jpeg[256]; 1162 static uint8_t y_ccir_to_jpeg[256];
1243 static uint8_t y_jpeg_to_ccir[256]; 1163 static uint8_t y_jpeg_to_ccir[256];
1244 static uint8_t c_ccir_to_jpeg[256]; 1164 static uint8_t c_ccir_to_jpeg[256];
1245 static uint8_t c_jpeg_to_ccir[256]; 1165 static uint8_t c_jpeg_to_ccir[256];
1246 1166
2868 emms(); 2788 emms();
2869 #endif 2789 #endif
2870 return 0; 2790 return 0;
2871 } 2791 }
2872 2792
2873 #undef FIX