Libav
|
00001 /* 00002 * yuv2rgb_mmx.c, software YUV to RGB converter with Intel MMX "technology" 00003 * 00004 * Copyright (C) 2000, Silicon Integrated System Corp 00005 * 00006 * Author: Olie Lho <ollie@sis.com.tw> 00007 * 00008 * 15,24 bpp and dithering from Michael Niedermayer (michaelni@gmx.at) 00009 * MMX/MMX2 Template stuff from Michael Niedermayer (needed for fast movntq support) 00010 * context / deglobalize stuff by Michael Niedermayer 00011 * 00012 * This file is part of mpeg2dec, a free MPEG-2 video decoder 00013 * 00014 * mpeg2dec is free software; you can redistribute it and/or modify 00015 * it under the terms of the GNU General Public License as published by 00016 * the Free Software Foundation; either version 2, or (at your option) 00017 * any later version. 00018 * 00019 * mpeg2dec is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU General Public License 00025 * along with mpeg2dec; if not, write to the Free Software 00026 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00027 */ 00028 00029 #undef MOVNTQ 00030 #undef EMMS 00031 #undef SFENCE 00032 00033 #if HAVE_AMD3DNOW 00034 /* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */ 00035 #define EMMS "femms" 00036 #else 00037 #define EMMS "emms" 00038 #endif 00039 00040 #if HAVE_MMX2 00041 #define MOVNTQ "movntq" 00042 #define SFENCE "sfence" 00043 #else 00044 #define MOVNTQ "movq" 00045 #define SFENCE " # nop" 00046 #endif 00047 00048 #define YUV2RGB \ 00049 /* Do the multiply part of the conversion for even and odd pixels, 00050 register usage: 00051 mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, 00052 mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, 00053 mm6 -> Y even, mm7 -> Y odd */\ 00054 /* convert the chroma part */\ 00055 "punpcklbw %%mm4, %%mm0;" /* scatter 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ 00056 "punpcklbw %%mm4, %%mm1;" /* scatter 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ 00057 \ 00058 "psllw $3, %%mm0;" /* Promote precision */ \ 00059 "psllw $3, %%mm1;" /* Promote precision */ \ 00060 \ 00061 "psubsw "U_OFFSET"(%4), %%mm0;" /* Cb -= 128 */ \ 00062 "psubsw "V_OFFSET"(%4), %%mm1;" /* Cr -= 128 */ \ 00063 \ 00064 "movq %%mm0, %%mm2;" /* Copy 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ 00065 "movq %%mm1, %%mm3;" /* Copy 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ 00066 \ 00067 "pmulhw "UG_COEFF"(%4), %%mm2;" /* Mul Cb with green coeff -> Cb green */ \ 00068 "pmulhw "VG_COEFF"(%4), %%mm3;" /* Mul Cr with green coeff -> Cr green */ \ 00069 \ 00070 "pmulhw "UB_COEFF"(%4), %%mm0;" /* Mul Cb -> Cblue 00 b3 00 b2 00 b1 00 b0 */\ 00071 "pmulhw "VR_COEFF"(%4), %%mm1;" /* Mul Cr -> Cred 00 r3 00 r2 00 r1 00 r0 */\ 00072 \ 00073 "paddsw %%mm3, %%mm2;" /* Cb green + Cr green -> Cgreen */\ 00074 \ 00075 /* convert the luma part */\ 00076 "movq %%mm6, %%mm7;" /* Copy 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\ 00077 "pand "MANGLE(mmx_00ffw)", %%mm6;" /* get Y even 00 Y6 00 Y4 00 Y2 00 Y0 */\ 00078 \ 00079 "psrlw $8, %%mm7;" /* get Y odd 00 Y7 00 Y5 00 Y3 00 Y1 */\ 00080 \ 00081 "psllw $3, %%mm6;" /* Promote precision */\ 00082 "psllw $3, %%mm7;" /* Promote precision */\ 00083 \ 00084 "psubw "Y_OFFSET"(%4), %%mm6;" /* Y -= 16 */\ 00085 "psubw "Y_OFFSET"(%4), %%mm7;" /* Y -= 16 */\ 00086 \ 00087 "pmulhw "Y_COEFF"(%4), %%mm6;" /* Mul 4 Y even 00 y6 00 y4 00 y2 00 y0 */\ 00088 "pmulhw "Y_COEFF"(%4), %%mm7;" /* Mul 4 Y odd 00 y7 00 y5 00 y3 00 y1 */\ 00089 \ 00090 /* Do the addition part of the conversion for even and odd pixels, 00091 register usage: 00092 mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, 00093 mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, 00094 mm6 -> Y even, mm7 -> Y odd */\ 00095 "movq %%mm0, %%mm3;" /* Copy Cblue */\ 00096 "movq %%mm1, %%mm4;" /* Copy Cred */\ 00097 "movq %%mm2, %%mm5;" /* Copy Cgreen */\ 00098 \ 00099 "paddsw %%mm6, %%mm0;" /* Y even + Cblue 00 B6 00 B4 00 B2 00 B0 */\ 00100 "paddsw %%mm7, %%mm3;" /* Y odd + Cblue 00 B7 00 B5 00 B3 00 B1 */\ 00101 \ 00102 "paddsw %%mm6, %%mm1;" /* Y even + Cred 00 R6 00 R4 00 R2 00 R0 */\ 00103 "paddsw %%mm7, %%mm4;" /* Y odd + Cred 00 R7 00 R5 00 R3 00 R1 */\ 00104 \ 00105 "paddsw %%mm6, %%mm2;" /* Y even + Cgreen 00 G6 00 G4 00 G2 00 G0 */\ 00106 "paddsw %%mm7, %%mm5;" /* Y odd + Cgreen 00 G7 00 G5 00 G3 00 G1 */\ 00107 \ 00108 /* Limit RGB even to 0..255 */\ 00109 "packuswb %%mm0, %%mm0;" /* B6 B4 B2 B0 B6 B4 B2 B0 */\ 00110 "packuswb %%mm1, %%mm1;" /* R6 R4 R2 R0 R6 R4 R2 R0 */\ 00111 "packuswb %%mm2, %%mm2;" /* G6 G4 G2 G0 G6 G4 G2 G0 */\ 00112 \ 00113 /* Limit RGB odd to 0..255 */\ 00114 "packuswb %%mm3, %%mm3;" /* B7 B5 B3 B1 B7 B5 B3 B1 */\ 00115 "packuswb %%mm4, %%mm4;" /* R7 R5 R3 R1 R7 R5 R3 R1 */\ 00116 "packuswb %%mm5, %%mm5;" /* G7 G5 G3 G1 G7 G5 G3 G1 */\ 00117 \ 00118 /* Interleave RGB even and odd */\ 00119 "punpcklbw %%mm3, %%mm0;" /* B7 B6 B5 B4 B3 B2 B1 B0 */\ 00120 "punpcklbw %%mm4, %%mm1;" /* R7 R6 R5 R4 R3 R2 R1 R0 */\ 00121 "punpcklbw %%mm5, %%mm2;" /* G7 G6 G5 G4 G3 G2 G1 G0 */\ 00122 00123 00124 #define YUV422_UNSHIFT \ 00125 if(c->srcFormat == PIX_FMT_YUV422P) {\ 00126 srcStride[1] *= 2; \ 00127 srcStride[2] *= 2; \ 00128 } \ 00129 00130 #define YUV2RGB_LOOP(depth) \ 00131 h_size= (c->dstW+7)&~7; \ 00132 if(h_size*depth > FFABS(dstStride[0])) h_size-=8; \ 00133 \ 00134 __asm__ volatile ("pxor %mm4, %mm4;" /* zero mm4 */ ); \ 00135 for (y= 0; y<srcSliceH; y++ ) { \ 00136 uint8_t *image = dst[0] + (y+srcSliceY)*dstStride[0]; \ 00137 const uint8_t *py = src[0] + y*srcStride[0]; \ 00138 const uint8_t *pu = src[1] + (y>>1)*srcStride[1]; \ 00139 const uint8_t *pv = src[2] + (y>>1)*srcStride[2]; \ 00140 x86_reg index= -h_size/2; \ 00141 00142 #define YUV2RGB_INIT \ 00143 /* This MMX assembly code deals with a SINGLE scan line at a time, \ 00144 * it converts 8 pixels in each iteration. */ \ 00145 __asm__ volatile ( \ 00146 /* load data for start of next scan line */ \ 00147 "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ \ 00148 "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ \ 00149 "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ \ 00150 /* \ 00151 ".balign 16 \n\t" \ 00152 */ \ 00153 "1: \n\t" \ 00154 /* No speed difference on my p3@500 with prefetch, \ 00155 * if it is faster for anyone with -benchmark then tell me. \ 00156 PREFETCH" 64(%0) \n\t" \ 00157 PREFETCH" 64(%1) \n\t" \ 00158 PREFETCH" 64(%2) \n\t" \ 00159 */ \ 00160 00161 #define YUV2RGB_ENDLOOP(depth) \ 00162 "add $"AV_STRINGIFY(depth*8)", %1 \n\t" \ 00163 "add $4, %0 \n\t" \ 00164 " js 1b \n\t" \ 00165 00166 #define YUV2RGB_OPERANDS \ 00167 : "+r" (index), "+r" (image) \ 00168 : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), "r" (py - 2*index) \ 00169 ); \ 00170 } \ 00171 __asm__ volatile (SFENCE"\n\t"EMMS); \ 00172 return srcSliceH; \ 00173 00174 #define YUV2RGB_OPERANDS_ALPHA \ 00175 : "+r" (index), "+r" (image) \ 00176 : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), "r" (py - 2*index), "r" (pa - 2*index) \ 00177 ); \ 00178 } \ 00179 __asm__ volatile (SFENCE"\n\t"EMMS); \ 00180 return srcSliceH; \ 00181 00182 static inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, 00183 int srcSliceH, uint8_t* dst[], int dstStride[]) 00184 { 00185 int y, h_size; 00186 00187 YUV422_UNSHIFT 00188 YUV2RGB_LOOP(2) 00189 00190 c->blueDither= ff_dither8[y&1]; 00191 c->greenDither= ff_dither4[y&1]; 00192 c->redDither= ff_dither8[(y+1)&1]; 00193 00194 YUV2RGB_INIT 00195 YUV2RGB 00196 00197 #ifdef DITHER1XBPP 00198 "paddusb "BLUE_DITHER"(%4), %%mm0;" 00199 "paddusb "GREEN_DITHER"(%4), %%mm2;" 00200 "paddusb "RED_DITHER"(%4), %%mm1;" 00201 #endif 00202 /* mask unneeded bits off */ 00203 "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ 00204 "pand "MANGLE(mmx_grnmask)", %%mm2;" /* g7g6g5g4 g3g2_0_0 g7g6g5g4 g3g2_0_0 */ 00205 "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ 00206 00207 "psrlw $3, %%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ 00208 "pxor %%mm4, %%mm4;" /* zero mm4 */ 00209 00210 "movq %%mm0, %%mm5;" /* Copy B7-B0 */ 00211 "movq %%mm2, %%mm7;" /* Copy G7-G0 */ 00212 00213 /* convert RGB24 plane to RGB16 pack for pixel 0-3 */ 00214 "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ 00215 "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ 00216 00217 "psllw $3, %%mm2;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ 00218 "por %%mm2, %%mm0;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ 00219 00220 "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ 00221 MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */ 00222 00223 /* convert RGB24 plane to RGB16 pack for pixel 0-3 */ 00224 "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ 00225 "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ 00226 00227 "psllw $3, %%mm7;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ 00228 "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ 00229 00230 "por %%mm7, %%mm5;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ 00231 "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ 00232 00233 MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */ 00234 00235 YUV2RGB_ENDLOOP(2) 00236 YUV2RGB_OPERANDS 00237 } 00238 00239 static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, 00240 int srcSliceH, uint8_t* dst[], int dstStride[]) 00241 { 00242 int y, h_size; 00243 00244 YUV422_UNSHIFT 00245 YUV2RGB_LOOP(2) 00246 00247 c->blueDither= ff_dither8[y&1]; 00248 c->greenDither= ff_dither8[y&1]; 00249 c->redDither= ff_dither8[(y+1)&1]; 00250 00251 YUV2RGB_INIT 00252 YUV2RGB 00253 00254 #ifdef DITHER1XBPP 00255 "paddusb "BLUE_DITHER"(%4), %%mm0 \n\t" 00256 "paddusb "GREEN_DITHER"(%4), %%mm2 \n\t" 00257 "paddusb "RED_DITHER"(%4), %%mm1 \n\t" 00258 #endif 00259 00260 /* mask unneeded bits off */ 00261 "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ 00262 "pand "MANGLE(mmx_redmask)", %%mm2;" /* g7g6g5g4 g3_0_0_0 g7g6g5g4 g3_0_0_0 */ 00263 "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ 00264 00265 "psrlw $3, %%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ 00266 "psrlw $1, %%mm1;" /* 0_r7r6r5 r4r3_0_0 0_r7r6r5 r4r3_0_0 */ 00267 "pxor %%mm4, %%mm4;" /* zero mm4 */ 00268 00269 "movq %%mm0, %%mm5;" /* Copy B7-B0 */ 00270 "movq %%mm2, %%mm7;" /* Copy G7-G0 */ 00271 00272 /* convert RGB24 plane to RGB16 pack for pixel 0-3 */ 00273 "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3_0_0_0 */ 00274 "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ 00275 00276 "psllw $2, %%mm2;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ 00277 "por %%mm2, %%mm0;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ 00278 00279 "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ 00280 MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */ 00281 00282 /* convert RGB24 plane to RGB16 pack for pixel 0-3 */ 00283 "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 0_g7g6g5 g4g3_0_0 */ 00284 "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ 00285 00286 "psllw $2, %%mm7;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ 00287 "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ 00288 00289 "por %%mm7, %%mm5;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ 00290 "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ 00291 00292 MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */ 00293 00294 YUV2RGB_ENDLOOP(2) 00295 YUV2RGB_OPERANDS 00296 } 00297 00298 #undef RGB_PLANAR2PACKED24 00299 #if HAVE_MMX2 00300 #define RGB_PLANAR2PACKED24(red, blue)\ 00301 "movq "MANGLE(ff_M24A)", %%mm4 \n\t"\ 00302 "movq "MANGLE(ff_M24C)", %%mm7 \n\t"\ 00303 "pshufw $0x50, %%mm"blue", %%mm5 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\ 00304 "pshufw $0x50, %%mm2, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\ 00305 "pshufw $0x00, %%mm"red", %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\ 00306 \ 00307 "pand %%mm4, %%mm5 \n\t" /* B2 B1 B0 */\ 00308 "pand %%mm4, %%mm3 \n\t" /* G2 G1 G0 */\ 00309 "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\ 00310 \ 00311 "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\ 00312 "por %%mm5, %%mm6 \n\t"\ 00313 "por %%mm3, %%mm6 \n\t"\ 00314 MOVNTQ" %%mm6, (%1) \n\t"\ 00315 \ 00316 "psrlq $8, %%mm2 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\ 00317 "pshufw $0xA5, %%mm"blue", %%mm5\n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\ 00318 "pshufw $0x55, %%mm2, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\ 00319 "pshufw $0xA5, %%mm"red", %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\ 00320 \ 00321 "pand "MANGLE(ff_M24B)", %%mm5 \n\t" /* B5 B4 B3 */\ 00322 "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\ 00323 "pand %%mm4, %%mm6 \n\t" /* R4 R3 R2 */\ 00324 \ 00325 "por %%mm5, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\ 00326 "por %%mm3, %%mm6 \n\t"\ 00327 MOVNTQ" %%mm6, 8(%1) \n\t"\ 00328 \ 00329 "pshufw $0xFF, %%mm"blue", %%mm5\n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\ 00330 "pshufw $0xFA, %%mm2, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\ 00331 "pshufw $0xFA, %%mm"red", %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\ 00332 "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */\ 00333 \ 00334 "pand %%mm7, %%mm5 \n\t" /* B7 B6 */\ 00335 "pand %%mm4, %%mm3 \n\t" /* G7 G6 G5 */\ 00336 "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7 R6 R5 */\ 00337 "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */\ 00338 \ 00339 "por %%mm5, %%mm3 \n\t"\ 00340 "por %%mm3, %%mm6 \n\t"\ 00341 MOVNTQ" %%mm6, 16(%1) \n\t"\ 00342 "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\ 00343 "pxor %%mm4, %%mm4 \n\t" 00344 #else 00345 #define RGB_PLANAR2PACKED24(red, blue)\ 00346 "pxor %%mm4, %%mm4 \n\t"\ 00347 "movq %%mm"blue", %%mm5\n\t" /* B */\ 00348 "movq %%mm"red", %%mm6 \n\t" /* R */\ 00349 "punpcklbw %%mm2, %%mm"blue"\n\t" /* GBGBGBGB 0 */\ 00350 "punpcklbw %%mm4, %%mm"red" \n\t" /* 0R0R0R0R 0 */\ 00351 "punpckhbw %%mm2, %%mm5 \n\t" /* GBGBGBGB 2 */\ 00352 "punpckhbw %%mm4, %%mm6 \n\t" /* 0R0R0R0R 2 */\ 00353 "movq %%mm"blue", %%mm7\n\t" /* GBGBGBGB 0 */\ 00354 "movq %%mm5, %%mm3 \n\t" /* GBGBGBGB 2 */\ 00355 "punpcklwd %%mm"red", %%mm7 \n\t" /* 0RGB0RGB 0 */\ 00356 "punpckhwd %%mm"red", %%mm"blue"\n\t" /* 0RGB0RGB 1 */\ 00357 "punpcklwd %%mm6, %%mm5 \n\t" /* 0RGB0RGB 2 */\ 00358 "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ 00359 \ 00360 "movq %%mm7, %%mm2 \n\t" /* 0RGB0RGB 0 */\ 00361 "movq %%mm"blue", %%mm6\n\t" /* 0RGB0RGB 1 */\ 00362 "movq %%mm5, %%mm"red" \n\t" /* 0RGB0RGB 2 */\ 00363 "movq %%mm3, %%mm4 \n\t" /* 0RGB0RGB 3 */\ 00364 \ 00365 "psllq $40, %%mm7 \n\t" /* RGB00000 0 */\ 00366 "psllq $40, %%mm"blue"\n\t" /* RGB00000 1 */\ 00367 "psllq $40, %%mm5 \n\t" /* RGB00000 2 */\ 00368 "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\ 00369 \ 00370 "punpckhdq %%mm2, %%mm7 \n\t" /* 0RGBRGB0 0 */\ 00371 "punpckhdq %%mm6, %%mm"blue"\n\t" /* 0RGBRGB0 1 */\ 00372 "punpckhdq %%mm"red", %%mm5 \n\t" /* 0RGBRGB0 2 */\ 00373 "punpckhdq %%mm4, %%mm3 \n\t" /* 0RGBRGB0 3 */\ 00374 \ 00375 "psrlq $8, %%mm7 \n\t" /* 00RGBRGB 0 */\ 00376 "movq %%mm"blue", %%mm6\n\t" /* 0RGBRGB0 1 */\ 00377 "psllq $40, %%mm"blue"\n\t" /* GB000000 1 */\ 00378 "por %%mm"blue", %%mm7\n\t" /* GBRGBRGB 0 */\ 00379 MOVNTQ" %%mm7, (%1) \n\t"\ 00380 \ 00381 "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\ 00382 "movq %%mm5, %%mm"red" \n\t" /* 0RGBRGB0 2 */\ 00383 "psllq $24, %%mm5 \n\t" /* BRGB0000 2 */\ 00384 "por %%mm5, %%mm6 \n\t" /* BRGBRGBR 1 */\ 00385 MOVNTQ" %%mm6, 8(%1) \n\t"\ 00386 \ 00387 "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\ 00388 \ 00389 "psrlq $40, %%mm"red" \n\t" /* 000000RG 2 */\ 00390 "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\ 00391 "por %%mm3, %%mm"red" \n\t" /* RGBRGBRG 2 */\ 00392 MOVNTQ" %%mm"red", 16(%1)\n\t"\ 00393 \ 00394 "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */\ 00395 "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */\ 00396 "pxor %%mm4, %%mm4 \n\t" 00397 #endif 00398 00399 static inline int RENAME(yuv420_rgb24)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, 00400 int srcSliceH, uint8_t* dst[], int dstStride[]) 00401 { 00402 int y, h_size; 00403 00404 YUV422_UNSHIFT 00405 YUV2RGB_LOOP(3) 00406 00407 YUV2RGB_INIT 00408 YUV2RGB 00409 /* mm0=B, %%mm2=G, %%mm1=R */ 00410 RGB_PLANAR2PACKED24("0", "1") 00411 00412 YUV2RGB_ENDLOOP(3) 00413 YUV2RGB_OPERANDS 00414 } 00415 00416 static inline int RENAME(yuv420_bgr24)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, 00417 int srcSliceH, uint8_t* dst[], int dstStride[]) 00418 { 00419 int y, h_size; 00420 00421 YUV422_UNSHIFT 00422 YUV2RGB_LOOP(3) 00423 00424 YUV2RGB_INIT 00425 YUV2RGB 00426 /* mm0=B, %%mm2=G, %%mm1=R */ 00427 RGB_PLANAR2PACKED24("1", "0") 00428 00429 YUV2RGB_ENDLOOP(3) 00430 YUV2RGB_OPERANDS 00431 } 00432 00433 /* 00434 00435 RGB_PLANAR2PACKED32(red,green,blue,alpha) 00436 00437 convert RGB plane to RGB packed format 00438 00439 macro parameters specify the output color channel order: 00440 00441 RGB_PLANAR2PACKED32(REG_RED, REG_GREEN, REG_BLUE, REG_ALPHA) for RGBA output, 00442 RGB_PLANAR2PACKED32(REG_BLUE, REG_GREEN, REG_RED, REG_ALPHA) for BGRA output, 00443 RGB_PLANAR2PACKED32(REG_ALPHA,REG_BLUE, REG_GREEN,REG_RED) for ABGR output, 00444 00445 etc. 00446 */ 00447 00448 #define REG_BLUE "0" 00449 #define REG_RED "1" 00450 #define REG_GREEN "2" 00451 #define REG_ALPHA "3" 00452 00453 #define RGB_PLANAR2PACKED32(red,green,blue,alpha) \ 00454 /* convert RGB plane to RGB packed format, \ 00455 mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> A, \ 00456 mm4 -> GB, mm5 -> AR pixel 4-7, \ 00457 mm6 -> GB, mm7 -> AR pixel 0-3 */ \ 00458 "movq %%mm" blue ", %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ \ 00459 "movq %%mm" red ", %%mm7;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ \ 00460 \ 00461 "movq %%mm" blue ", %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ \ 00462 "movq %%mm" red ", %%mm5;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ \ 00463 \ 00464 "punpcklbw %%mm" green ", %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ \ 00465 "punpcklbw %%mm" alpha ", %%mm7;" /* A3 R3 A2 R2 A1 R1 A0 R0 */ \ 00466 \ 00467 "punpcklwd %%mm7, %%mm6;" /* A1 R1 B1 G1 A0 R0 B0 G0 */ \ 00468 MOVNTQ " %%mm6, (%1);" /* Store ARGB1 ARGB0 */ \ 00469 \ 00470 "movq %%mm" blue ", %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ \ 00471 "punpcklbw %%mm" green ", %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ \ 00472 \ 00473 "punpckhwd %%mm7, %%mm6;" /* A3 R3 G3 B3 A2 R2 B3 G2 */ \ 00474 MOVNTQ " %%mm6, 8 (%1);" /* Store ARGB3 ARGB2 */ \ 00475 \ 00476 "punpckhbw %%mm" green ", %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ \ 00477 "punpckhbw %%mm" alpha ", %%mm5;" /* A7 R7 A6 R6 A5 R5 A4 R4 */ \ 00478 \ 00479 "punpcklwd %%mm5, %%mm4;" /* A5 R5 B5 G5 A4 R4 B4 G4 */ \ 00480 MOVNTQ " %%mm4, 16 (%1);" /* Store ARGB5 ARGB4 */ \ 00481 \ 00482 "movq %%mm" blue ", %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ \ 00483 "punpckhbw %%mm" green ", %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ \ 00484 \ 00485 "punpckhwd %%mm5, %%mm4;" /* A7 R7 G7 B7 A6 R6 B6 G6 */ \ 00486 MOVNTQ " %%mm4, 24 (%1);" /* Store ARGB7 ARGB6 */ \ 00487 \ 00488 "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ \ 00489 "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ \ 00490 \ 00491 "pxor %%mm4, %%mm4;" /* zero mm4 */ \ 00492 "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ \ 00493 00494 static inline int RENAME(yuv420_rgb32)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, 00495 int srcSliceH, uint8_t* dst[], int dstStride[]) 00496 { 00497 int y, h_size; 00498 00499 YUV422_UNSHIFT 00500 YUV2RGB_LOOP(4) 00501 00502 YUV2RGB_INIT 00503 YUV2RGB 00504 "pcmpeqd %%mm3, %%mm3;" /* fill mm3 */ 00505 RGB_PLANAR2PACKED32(REG_RED,REG_GREEN,REG_BLUE,REG_ALPHA) 00506 00507 YUV2RGB_ENDLOOP(4) 00508 YUV2RGB_OPERANDS 00509 } 00510 00511 static inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, 00512 int srcSliceH, uint8_t* dst[], int dstStride[]) 00513 { 00514 #if HAVE_7REGS 00515 int y, h_size; 00516 00517 YUV2RGB_LOOP(4) 00518 00519 const uint8_t *pa = src[3] + y*srcStride[3]; 00520 YUV2RGB_INIT 00521 YUV2RGB 00522 "movq (%6, %0, 2), %%mm3;" /* Load 8 A A7 A6 A5 A4 A3 A2 A1 A0 */ 00523 RGB_PLANAR2PACKED32(REG_RED,REG_GREEN,REG_BLUE,REG_ALPHA) 00524 00525 YUV2RGB_ENDLOOP(4) 00526 YUV2RGB_OPERANDS_ALPHA 00527 #endif 00528 } 00529 00530 static inline int RENAME(yuv420_bgr32)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, 00531 int srcSliceH, uint8_t* dst[], int dstStride[]) 00532 { 00533 int y, h_size; 00534 00535 YUV422_UNSHIFT 00536 YUV2RGB_LOOP(4) 00537 00538 YUV2RGB_INIT 00539 YUV2RGB 00540 "pcmpeqd %%mm3, %%mm3;" /* fill mm3 */ 00541 RGB_PLANAR2PACKED32(REG_BLUE,REG_GREEN,REG_RED,REG_ALPHA) 00542 00543 YUV2RGB_ENDLOOP(4) 00544 YUV2RGB_OPERANDS 00545 } 00546 00547 static inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, 00548 int srcSliceH, uint8_t* dst[], int dstStride[]) 00549 { 00550 #if HAVE_7REGS 00551 int y, h_size; 00552 00553 YUV2RGB_LOOP(4) 00554 00555 const uint8_t *pa = src[3] + y*srcStride[3]; 00556 YUV2RGB_INIT 00557 YUV2RGB 00558 "movq (%6, %0, 2), %%mm3;" /* Load 8 A A7 A6 A5 A4 A3 A2 A1 A0 */ 00559 RGB_PLANAR2PACKED32(REG_BLUE,REG_GREEN,REG_RED,REG_ALPHA) 00560 00561 YUV2RGB_ENDLOOP(4) 00562 YUV2RGB_OPERANDS_ALPHA 00563 #endif 00564 }