src/video/SDL_blit_N.c
changeset 2267 c785543d1843
parent 2262 bee005ace1bf
child 2698 e1da92da346c
equal deleted inserted replaced
2266:e61ad15a205f 2267:c785543d1843
   158 static void
   158 static void
   159 Blit_RGB888_RGB565Altivec(SDL_BlitInfo * info)
   159 Blit_RGB888_RGB565Altivec(SDL_BlitInfo * info)
   160 {
   160 {
   161     int height = info->dst_h;
   161     int height = info->dst_h;
   162     Uint8 *src = (Uint8 *) info->src;
   162     Uint8 *src = (Uint8 *) info->src;
   163     int srcskip = info->s_skip;
   163     int srcskip = info->src_skip;
   164     Uint8 *dst = (Uint8 *) info->dst;
   164     Uint8 *dst = (Uint8 *) info->dst;
   165     int dstskip = info->dst_pitch;
   165     int dstskip = info->dst_skip;
   166     SDL_PixelFormat *srcfmt = info->src;
   166     SDL_PixelFormat *srcfmt = info->src;
   167     vector unsigned char valpha = vec_splat_u8(0);
   167     vector unsigned char valpha = vec_splat_u8(0);
   168     vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
   168     vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
   169     vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
   169     vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
   170                                                     0x00, 0x0a, 0x00, 0x0e,
   170                                                     0x00, 0x0a, 0x00, 0x0e,
   262 static void
   262 static void
   263 Blit_RGB565_32Altivec(SDL_BlitInfo * info)
   263 Blit_RGB565_32Altivec(SDL_BlitInfo * info)
   264 {
   264 {
   265     int height = info->dst_h;
   265     int height = info->dst_h;
   266     Uint8 *src = (Uint8 *) info->src;
   266     Uint8 *src = (Uint8 *) info->src;
   267     int srcskip = info->s_skip;
   267     int srcskip = info->src_skip;
   268     Uint8 *dst = (Uint8 *) info->dst;
   268     Uint8 *dst = (Uint8 *) info->dst;
   269     int dstskip = info->dst_pitch;
   269     int dstskip = info->dst_skip;
   270     SDL_PixelFormat *srcfmt = info->src;
   270     SDL_PixelFormat *srcfmt = info->src;
   271     SDL_PixelFormat *dstfmt = info->dst;
   271     SDL_PixelFormat *dstfmt = info->dst;
   272     unsigned alpha;
   272     unsigned alpha;
   273     vector unsigned char valpha;
   273     vector unsigned char valpha;
   274     vector unsigned char vpermute;
   274     vector unsigned char vpermute;
   320     assert(dstfmt->BytesPerPixel == 4);
   320     assert(dstfmt->BytesPerPixel == 4);
   321 
   321 
   322     vf800 = (vector unsigned short) vec_splat_u8(-7);
   322     vf800 = (vector unsigned short) vec_splat_u8(-7);
   323     vf800 = vec_sl(vf800, vec_splat_u16(8));
   323     vf800 = vec_sl(vf800, vec_splat_u16(8));
   324 
   324 
   325     if (dstfmt->Amask && (info->cmod >> 24)) {
   325     if (dstfmt->Amask && info->a) {
   326         ((unsigned char *) &valpha)[0] = alpha = (info->cmod >> 24);
   326         ((unsigned char *) &valpha)[0] = alpha = info->a;
   327         valpha = vec_splat(valpha, 0);
   327         valpha = vec_splat(valpha, 0);
   328     } else {
   328     } else {
   329         alpha = 0;
   329         alpha = 0;
   330         valpha = vec_splat_u8(0);
   330         valpha = vec_splat_u8(0);
   331     }
   331     }
   410 static void
   410 static void
   411 Blit_RGB555_32Altivec(SDL_BlitInfo * info)
   411 Blit_RGB555_32Altivec(SDL_BlitInfo * info)
   412 {
   412 {
   413     int height = info->dst_h;
   413     int height = info->dst_h;
   414     Uint8 *src = (Uint8 *) info->src;
   414     Uint8 *src = (Uint8 *) info->src;
   415     int srcskip = info->s_skip;
   415     int srcskip = info->src_skip;
   416     Uint8 *dst = (Uint8 *) info->dst;
   416     Uint8 *dst = (Uint8 *) info->dst;
   417     int dstskip = info->dst_pitch;
   417     int dstskip = info->dst_skip;
   418     SDL_PixelFormat *srcfmt = info->src;
   418     SDL_PixelFormat *srcfmt = info->src;
   419     SDL_PixelFormat *dstfmt = info->dst;
   419     SDL_PixelFormat *dstfmt = info->dst;
   420     unsigned alpha;
   420     unsigned alpha;
   421     vector unsigned char valpha;
   421     vector unsigned char valpha;
   422     vector unsigned char vpermute;
   422     vector unsigned char vpermute;
   468     assert(dstfmt->BytesPerPixel == 4);
   468     assert(dstfmt->BytesPerPixel == 4);
   469 
   469 
   470     vf800 = (vector unsigned short) vec_splat_u8(-7);
   470     vf800 = (vector unsigned short) vec_splat_u8(-7);
   471     vf800 = vec_sl(vf800, vec_splat_u16(8));
   471     vf800 = vec_sl(vf800, vec_splat_u16(8));
   472 
   472 
   473     if (dstfmt->Amask && (info->cmod >> 24)) {
   473     if (dstfmt->Amask && info->a) {
   474         ((unsigned char *) &valpha)[0] = alpha = (info->cmod >> 24);
   474         ((unsigned char *) &valpha)[0] = alpha = info->a;
   475         valpha = vec_splat(valpha, 0);
   475         valpha = vec_splat(valpha, 0);
   476     } else {
   476     } else {
   477         alpha = 0;
   477         alpha = 0;
   478         valpha = vec_splat_u8(0);
   478         valpha = vec_splat_u8(0);
   479     }
   479     }
   559 static void
   559 static void
   560 Blit32to32KeyAltivec(SDL_BlitInfo * info)
   560 Blit32to32KeyAltivec(SDL_BlitInfo * info)
   561 {
   561 {
   562     int height = info->dst_h;
   562     int height = info->dst_h;
   563     Uint32 *srcp = (Uint32 *) info->src;
   563     Uint32 *srcp = (Uint32 *) info->src;
   564     int srcskip = info->s_skip;
   564     int srcskip = info->src_skip;
   565     Uint32 *dstp = (Uint32 *) info->dst;
   565     Uint32 *dstp = (Uint32 *) info->dst;
   566     int dstskip = info->dst_pitch;
   566     int dstskip = info->dst_skip;
   567     SDL_PixelFormat *srcfmt = info->src;
   567     SDL_PixelFormat *srcfmt = info->src;
   568     int srcbpp = srcfmt->BytesPerPixel;
   568     int srcbpp = srcfmt->BytesPerPixel;
   569     SDL_PixelFormat *dstfmt = info->dst;
   569     SDL_PixelFormat *dstfmt = info->dst;
   570     int dstbpp = dstfmt->BytesPerPixel;
   570     int dstbpp = dstfmt->BytesPerPixel;
   571     int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
   571     int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
   572     unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0;
   572     unsigned alpha = dstfmt->Amask ? info->a : 0;
   573     Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
   573     Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
   574     Uint32 ckey = info->ckey;
   574     Uint32 ckey = info->colorkey;
   575     vector unsigned int valpha;
   575     vector unsigned int valpha;
   576     vector unsigned char vpermute;
   576     vector unsigned char vpermute;
   577     vector unsigned char vzero;
   577     vector unsigned char vzero;
   578     vector unsigned int vckey;
   578     vector unsigned int vckey;
   579     vector unsigned int vrgbmask;
   579     vector unsigned int vrgbmask;
   677 static void
   677 static void
   678 ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info)
   678 ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info)
   679 {
   679 {
   680     int height = info->dst_h;
   680     int height = info->dst_h;
   681     Uint32 *src = (Uint32 *) info->src;
   681     Uint32 *src = (Uint32 *) info->src;
   682     int srcskip = info->s_skip;
   682     int srcskip = info->src_skip;
   683     Uint32 *dst = (Uint32 *) info->dst;
   683     Uint32 *dst = (Uint32 *) info->dst;
   684     int dstskip = info->dst_pitch;
   684     int dstskip = info->dst_skip;
   685     SDL_PixelFormat *srcfmt = info->src;
   685     SDL_PixelFormat *srcfmt = info->src;
   686     SDL_PixelFormat *dstfmt = info->dst;
   686     SDL_PixelFormat *dstfmt = info->dst;
   687     vector unsigned int vzero = vec_splat_u32(0);
   687     vector unsigned int vzero = vec_splat_u32(0);
   688     vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
   688     vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
   689     if (dstfmt->Amask && !srcfmt->Amask) {
   689     if (dstfmt->Amask && !srcfmt->Amask) {
   690         if ((info->cmod >> 24)) {
   690         if (info->a) {
   691             vector unsigned char valpha;
   691             vector unsigned char valpha;
   692             ((unsigned char *) &valpha)[0] = (info->cmod >> 24);
   692             ((unsigned char *) &valpha)[0] = info->a;
   693             vzero = (vector unsigned int) vec_splat(valpha, 0);
   693             vzero = (vector unsigned int) vec_splat(valpha, 0);
   694         }
   694         }
   695     }
   695     }
   696 
   696 
   697     assert(srcfmt->BytesPerPixel == 4);
   697     assert(srcfmt->BytesPerPixel == 4);
   756     const int scalar_dst_lead = sizeof(Uint32) * 4;
   756     const int scalar_dst_lead = sizeof(Uint32) * 4;
   757     const int vector_dst_lead = sizeof(Uint32) * 16;
   757     const int vector_dst_lead = sizeof(Uint32) * 16;
   758 
   758 
   759     int height = info->dst_h;
   759     int height = info->dst_h;
   760     Uint32 *src = (Uint32 *) info->src;
   760     Uint32 *src = (Uint32 *) info->src;
   761     int srcskip = info->s_skip;
   761     int srcskip = info->src_skip;
   762     Uint32 *dst = (Uint32 *) info->dst;
   762     Uint32 *dst = (Uint32 *) info->dst;
   763     int dstskip = info->dst_pitch;
   763     int dstskip = info->dst_skip;
   764     SDL_PixelFormat *srcfmt = info->src;
   764     SDL_PixelFormat *srcfmt = info->src;
   765     SDL_PixelFormat *dstfmt = info->dst;
   765     SDL_PixelFormat *dstfmt = info->dst;
   766     vector unsigned int vzero = vec_splat_u32(0);
   766     vector unsigned int vzero = vec_splat_u32(0);
   767     vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
   767     vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
   768     if (dstfmt->Amask && !srcfmt->Amask) {
   768     if (dstfmt->Amask && !srcfmt->Amask) {
   769         if ((info->cmod >> 24)) {
   769         if (info->a) {
   770             vector unsigned char valpha;
   770             vector unsigned char valpha;
   771             ((unsigned char *) &valpha)[0] = (info->cmod >> 24);
   771             ((unsigned char *) &valpha)[0] = info->a;
   772             vzero = (vector unsigned int) vec_splat(valpha, 0);
   772             vzero = (vector unsigned int) vec_splat(valpha, 0);
   773         }
   773         }
   774     }
   774     }
   775 
   775 
   776     assert(srcfmt->BytesPerPixel == 4);
   776     assert(srcfmt->BytesPerPixel == 4);
   899 
   899 
   900     /* Set up some basic variables */
   900     /* Set up some basic variables */
   901     width = info->dst_w;
   901     width = info->dst_w;
   902     height = info->dst_h;
   902     height = info->dst_h;
   903     src = (Uint32 *) info->src;
   903     src = (Uint32 *) info->src;
   904     srcskip = info->s_skip / 4;
   904     srcskip = info->src_skip / 4;
   905     dst = info->dst;
   905     dst = info->dst;
   906     dstskip = info->dst_pitch;
   906     dstskip = info->dst_skip;
   907     map = info->table;
   907     map = info->table;
   908 
   908 
   909     if (map == NULL) {
   909     if (map == NULL) {
   910         while (height--) {
   910         while (height--) {
   911 #ifdef USE_DUFFS_LOOP
   911 #ifdef USE_DUFFS_LOOP
  1016 
  1016 
  1017     /* Set up some basic variables */
  1017     /* Set up some basic variables */
  1018     width = info->dst_w;
  1018     width = info->dst_w;
  1019     height = info->dst_h;
  1019     height = info->dst_h;
  1020     src = (Uint32 *) info->src;
  1020     src = (Uint32 *) info->src;
  1021     srcskip = info->s_skip / 4;
  1021     srcskip = info->src_skip / 4;
  1022     dst = (Uint16 *) info->dst;
  1022     dst = (Uint16 *) info->dst;
  1023     dstskip = info->dst_pitch / 2;
  1023     dstskip = info->dst_skip / 2;
  1024 
  1024 
  1025 #ifdef USE_DUFFS_LOOP
  1025 #ifdef USE_DUFFS_LOOP
  1026     while (height--) {
  1026     while (height--) {
  1027 		/* *INDENT-OFF* */
  1027 		/* *INDENT-OFF* */
  1028 		DUFFS_LOOP(
  1028 		DUFFS_LOOP(
  1140 
  1140 
  1141     /* Set up some basic variables */
  1141     /* Set up some basic variables */
  1142     width = info->dst_w;
  1142     width = info->dst_w;
  1143     height = info->dst_h;
  1143     height = info->dst_h;
  1144     src = (Uint32 *) info->src;
  1144     src = (Uint32 *) info->src;
  1145     srcskip = info->s_skip / 4;
  1145     srcskip = info->src_skip / 4;
  1146     dst = (Uint16 *) info->dst;
  1146     dst = (Uint16 *) info->dst;
  1147     dstskip = info->dst_pitch / 2;
  1147     dstskip = info->dst_skip / 2;
  1148 
  1148 
  1149 #ifdef USE_DUFFS_LOOP
  1149 #ifdef USE_DUFFS_LOOP
  1150     while (height--) {
  1150     while (height--) {
  1151 		/* *INDENT-OFF* */
  1151 		/* *INDENT-OFF* */
  1152 		DUFFS_LOOP(
  1152 		DUFFS_LOOP(
  1253 
  1253 
  1254     /* Set up some basic variables */
  1254     /* Set up some basic variables */
  1255     width = info->dst_w;
  1255     width = info->dst_w;
  1256     height = info->dst_h;
  1256     height = info->dst_h;
  1257     src = (Uint8 *) info->src;
  1257     src = (Uint8 *) info->src;
  1258     srcskip = info->s_skip;
  1258     srcskip = info->src_skip;
  1259     dst = (Uint32 *) info->dst;
  1259     dst = (Uint32 *) info->dst;
  1260     dstskip = info->dst_pitch / 4;
  1260     dstskip = info->dst_skip / 4;
  1261 
  1261 
  1262 #ifdef USE_DUFFS_LOOP
  1262 #ifdef USE_DUFFS_LOOP
  1263     while (height--) {
  1263     while (height--) {
  1264 		/* *INDENT-OFF* */
  1264 		/* *INDENT-OFF* */
  1265 		DUFFS_LOOP(
  1265 		DUFFS_LOOP(
  1875 
  1875 
  1876     /* Set up some basic variables */
  1876     /* Set up some basic variables */
  1877     width = info->dst_w;
  1877     width = info->dst_w;
  1878     height = info->dst_h;
  1878     height = info->dst_h;
  1879     src = (Uint32 *) info->src;
  1879     src = (Uint32 *) info->src;
  1880     srcskip = info->s_skip / 4;
  1880     srcskip = info->src_skip / 4;
  1881     dst = info->dst;
  1881     dst = info->dst;
  1882     dstskip = info->dst_pitch;
  1882     dstskip = info->dst_skip;
  1883     map = info->table;
  1883     map = info->table;
  1884 
  1884 
  1885 #ifdef USE_DUFFS_LOOP
  1885 #ifdef USE_DUFFS_LOOP
  1886     while (height--) {
  1886     while (height--) {
  1887 		/* *INDENT-OFF* */
  1887 		/* *INDENT-OFF* */
  1948 
  1948 
  1949     /* Set up some basic variables */
  1949     /* Set up some basic variables */
  1950     width = info->dst_w;
  1950     width = info->dst_w;
  1951     height = info->dst_h;
  1951     height = info->dst_h;
  1952     src = info->src;
  1952     src = info->src;
  1953     srcskip = info->s_skip;
  1953     srcskip = info->src_skip;
  1954     dst = info->dst;
  1954     dst = info->dst;
  1955     dstskip = info->dst_pitch;
  1955     dstskip = info->dst_skip;
  1956     map = info->table;
  1956     map = info->table;
  1957     srcfmt = info->src;
  1957     srcfmt = info->src_fmt;
  1958     srcbpp = srcfmt->BytesPerPixel;
  1958     srcbpp = srcfmt->BytesPerPixel;
  1959 
  1959 
  1960     if (map == NULL) {
  1960     if (map == NULL) {
  1961         while (height--) {
  1961         while (height--) {
  1962 #ifdef USE_DUFFS_LOOP
  1962 #ifdef USE_DUFFS_LOOP
  2029 Blit4to4MaskAlpha(SDL_BlitInfo * info)
  2029 Blit4to4MaskAlpha(SDL_BlitInfo * info)
  2030 {
  2030 {
  2031     int width = info->dst_w;
  2031     int width = info->dst_w;
  2032     int height = info->dst_h;
  2032     int height = info->dst_h;
  2033     Uint32 *src = (Uint32 *) info->src;
  2033     Uint32 *src = (Uint32 *) info->src;
  2034     int srcskip = info->s_skip;
  2034     int srcskip = info->src_skip;
  2035     Uint32 *dst = (Uint32 *) info->dst;
  2035     Uint32 *dst = (Uint32 *) info->dst;
  2036     int dstskip = info->dst_pitch;
  2036     int dstskip = info->dst_skip;
  2037     SDL_PixelFormat *srcfmt = info->src;
  2037     SDL_PixelFormat *srcfmt = info->src_fmt;
  2038     SDL_PixelFormat *dstfmt = info->dst;
  2038     SDL_PixelFormat *dstfmt = info->dst_fmt;
  2039 
  2039 
  2040     if (dstfmt->Amask) {
  2040     if (dstfmt->Amask) {
  2041         /* RGB->RGBA, SET_ALPHA */
  2041         /* RGB->RGBA, SET_ALPHA */
  2042         Uint32 mask = ((info->cmod >> 24) >> dstfmt->Aloss) << dstfmt->Ashift;
  2042         Uint32 mask = (info->a >> dstfmt->Aloss) << dstfmt->Ashift;
  2043 
  2043 
  2044         while (height--) {
  2044         while (height--) {
  2045 			/* *INDENT-OFF* */
  2045 			/* *INDENT-OFF* */
  2046 			DUFFS_LOOP(
  2046 			DUFFS_LOOP(
  2047 			{
  2047 			{
  2078 BlitNtoN(SDL_BlitInfo * info)
  2078 BlitNtoN(SDL_BlitInfo * info)
  2079 {
  2079 {
  2080     int width = info->dst_w;
  2080     int width = info->dst_w;
  2081     int height = info->dst_h;
  2081     int height = info->dst_h;
  2082     Uint8 *src = info->src;
  2082     Uint8 *src = info->src;
  2083     int srcskip = info->s_skip;
  2083     int srcskip = info->src_skip;
  2084     Uint8 *dst = info->dst;
  2084     Uint8 *dst = info->dst;
  2085     int dstskip = info->dst_pitch;
  2085     int dstskip = info->dst_skip;
  2086     SDL_PixelFormat *srcfmt = info->src;
  2086     SDL_PixelFormat *srcfmt = info->src_fmt;
  2087     int srcbpp = srcfmt->BytesPerPixel;
  2087     int srcbpp = srcfmt->BytesPerPixel;
  2088     SDL_PixelFormat *dstfmt = info->dst;
  2088     SDL_PixelFormat *dstfmt = info->dst_fmt;
  2089     int dstbpp = dstfmt->BytesPerPixel;
  2089     int dstbpp = dstfmt->BytesPerPixel;
  2090     unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0;
  2090     unsigned alpha = dstfmt->Amask ? info->a : 0;
  2091 
  2091 
  2092     while (height--) {
  2092     while (height--) {
  2093 		/* *INDENT-OFF* */
  2093 		/* *INDENT-OFF* */
  2094 		DUFFS_LOOP(
  2094 		DUFFS_LOOP(
  2095 		{
  2095 		{
  2113 BlitNtoNCopyAlpha(SDL_BlitInfo * info)
  2113 BlitNtoNCopyAlpha(SDL_BlitInfo * info)
  2114 {
  2114 {
  2115     int width = info->dst_w;
  2115     int width = info->dst_w;
  2116     int height = info->dst_h;
  2116     int height = info->dst_h;
  2117     Uint8 *src = info->src;
  2117     Uint8 *src = info->src;
  2118     int srcskip = info->s_skip;
  2118     int srcskip = info->src_skip;
  2119     Uint8 *dst = info->dst;
  2119     Uint8 *dst = info->dst;
  2120     int dstskip = info->dst_pitch;
  2120     int dstskip = info->dst_skip;
  2121     SDL_PixelFormat *srcfmt = info->src;
  2121     SDL_PixelFormat *srcfmt = info->src_fmt;
  2122     int srcbpp = srcfmt->BytesPerPixel;
  2122     int srcbpp = srcfmt->BytesPerPixel;
  2123     SDL_PixelFormat *dstfmt = info->dst;
  2123     SDL_PixelFormat *dstfmt = info->dst_fmt;
  2124     int dstbpp = dstfmt->BytesPerPixel;
  2124     int dstbpp = dstfmt->BytesPerPixel;
  2125     int c;
  2125     int c;
  2126 
  2126 
  2127     /* FIXME: should map alpha to [0..255] correctly! */
  2127     /* FIXME: should map alpha to [0..255] correctly! */
  2128     while (height--) {
  2128     while (height--) {
  2143 BlitNto1Key(SDL_BlitInfo * info)
  2143 BlitNto1Key(SDL_BlitInfo * info)
  2144 {
  2144 {
  2145     int width = info->dst_w;
  2145     int width = info->dst_w;
  2146     int height = info->dst_h;
  2146     int height = info->dst_h;
  2147     Uint8 *src = info->src;
  2147     Uint8 *src = info->src;
  2148     int srcskip = info->s_skip;
  2148     int srcskip = info->src_skip;
  2149     Uint8 *dst = info->dst;
  2149     Uint8 *dst = info->dst;
  2150     int dstskip = info->dst_pitch;
  2150     int dstskip = info->dst_skip;
  2151     SDL_PixelFormat *srcfmt = info->src;
  2151     SDL_PixelFormat *srcfmt = info->src_fmt;
  2152     const Uint8 *palmap = info->table;
  2152     const Uint8 *palmap = info->table;
  2153     Uint32 ckey = info->ckey;
  2153     Uint32 ckey = info->colorkey;
  2154     Uint32 rgbmask = ~srcfmt->Amask;
  2154     Uint32 rgbmask = ~srcfmt->Amask;
  2155     int srcbpp;
  2155     int srcbpp;
  2156     Uint32 Pixel;
  2156     Uint32 Pixel;
  2157     unsigned sR, sG, sB;
  2157     unsigned sR, sG, sB;
  2158 
  2158 
  2209 Blit2to2Key(SDL_BlitInfo * info)
  2209 Blit2to2Key(SDL_BlitInfo * info)
  2210 {
  2210 {
  2211     int width = info->dst_w;
  2211     int width = info->dst_w;
  2212     int height = info->dst_h;
  2212     int height = info->dst_h;
  2213     Uint16 *srcp = (Uint16 *) info->src;
  2213     Uint16 *srcp = (Uint16 *) info->src;
  2214     int srcskip = info->s_skip;
  2214     int srcskip = info->src_skip;
  2215     Uint16 *dstp = (Uint16 *) info->dst;
  2215     Uint16 *dstp = (Uint16 *) info->dst;
  2216     int dstskip = info->dst_pitch;
  2216     int dstskip = info->dst_skip;
  2217     Uint32 ckey = info->ckey;
  2217     Uint32 ckey = info->colorkey;
  2218     Uint32 rgbmask = ~info->src->Amask;
  2218     Uint32 rgbmask = ~info->src_fmt->Amask;
  2219 
  2219 
  2220     /* Set up some basic variables */
  2220     /* Set up some basic variables */
  2221     srcskip /= 2;
  2221     srcskip /= 2;
  2222     dstskip /= 2;
  2222     dstskip /= 2;
  2223     ckey &= rgbmask;
  2223     ckey &= rgbmask;
  2243 BlitNtoNKey(SDL_BlitInfo * info)
  2243 BlitNtoNKey(SDL_BlitInfo * info)
  2244 {
  2244 {
  2245     int width = info->dst_w;
  2245     int width = info->dst_w;
  2246     int height = info->dst_h;
  2246     int height = info->dst_h;
  2247     Uint8 *src = info->src;
  2247     Uint8 *src = info->src;
  2248     int srcskip = info->s_skip;
  2248     int srcskip = info->src_skip;
  2249     Uint8 *dst = info->dst;
  2249     Uint8 *dst = info->dst;
  2250     int dstskip = info->dst_pitch;
  2250     int dstskip = info->dst_skip;
  2251     Uint32 ckey = info->ckey;
  2251     Uint32 ckey = info->colorkey;
  2252     SDL_PixelFormat *srcfmt = info->src;
  2252     SDL_PixelFormat *srcfmt = info->src_fmt;
  2253     SDL_PixelFormat *dstfmt = info->dst;
  2253     SDL_PixelFormat *dstfmt = info->dst_fmt;
  2254     int srcbpp = srcfmt->BytesPerPixel;
  2254     int srcbpp = srcfmt->BytesPerPixel;
  2255     int dstbpp = dstfmt->BytesPerPixel;
  2255     int dstbpp = dstfmt->BytesPerPixel;
  2256     unsigned alpha = dstfmt->Amask ? (info->cmod >> 24) : 0;
  2256     unsigned alpha = dstfmt->Amask ? info->a : 0;
  2257     Uint32 rgbmask = ~srcfmt->Amask;
  2257     Uint32 rgbmask = ~srcfmt->Amask;
  2258 
  2258 
  2259     /* Set up some basic variables */
  2259     /* Set up some basic variables */
  2260     ckey &= rgbmask;
  2260     ckey &= rgbmask;
  2261 
  2261 
  2286 BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info)
  2286 BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info)
  2287 {
  2287 {
  2288     int width = info->dst_w;
  2288     int width = info->dst_w;
  2289     int height = info->dst_h;
  2289     int height = info->dst_h;
  2290     Uint8 *src = info->src;
  2290     Uint8 *src = info->src;
  2291     int srcskip = info->s_skip;
  2291     int srcskip = info->src_skip;
  2292     Uint8 *dst = info->dst;
  2292     Uint8 *dst = info->dst;
  2293     int dstskip = info->dst_pitch;
  2293     int dstskip = info->dst_skip;
  2294     Uint32 ckey = info->ckey;
  2294     Uint32 ckey = info->colorkey;
  2295     SDL_PixelFormat *srcfmt = info->src;
  2295     SDL_PixelFormat *srcfmt = info->src_fmt;
  2296     SDL_PixelFormat *dstfmt = info->dst;
  2296     SDL_PixelFormat *dstfmt = info->dst_fmt;
  2297     Uint32 rgbmask = ~srcfmt->Amask;
  2297     Uint32 rgbmask = ~srcfmt->Amask;
  2298 
  2298 
  2299     Uint8 srcbpp;
  2299     Uint8 srcbpp;
  2300     Uint8 dstbpp;
  2300     Uint8 dstbpp;
  2301     Uint32 Pixel;
  2301     Uint32 Pixel;
  2330 {
  2330 {
  2331     Uint32 srcR, srcG, srcB;
  2331     Uint32 srcR, srcG, srcB;
  2332     int dstbpp;
  2332     int dstbpp;
  2333     Uint32 dstR, dstG, dstB;
  2333     Uint32 dstR, dstG, dstB;
  2334     Uint32 blit_features;
  2334     Uint32 blit_features;
  2335     SDL_loblit blitfunc;
  2335     SDL_BlitFunc blitfunc;
  2336     enum
  2336     enum
  2337     { NO_ALPHA = 1, SET_ALPHA = 2, COPY_ALPHA = 4 } alpha;
  2337     { NO_ALPHA = 1, SET_ALPHA = 2, COPY_ALPHA = 4 } alpha;
  2338 };
  2338 };
  2339 static const struct blit_table normal_blit_1[] = {
  2339 static const struct blit_table normal_blit_1[] = {
  2340     /* Default for 8-bit RGB source, an invalid combination */
  2340     /* Default for 8-bit RGB source, an invalid combination */
  2401 };
  2401 };
  2402 
  2402 
  2403 /* Mask matches table, or table entry is zero */
  2403 /* Mask matches table, or table entry is zero */
  2404 #define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000))
  2404 #define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000))
  2405 
  2405 
  2406 SDL_loblit
  2406 SDL_BlitFunc
  2407 SDL_CalculateBlitN(SDL_Surface * surface, int blit_index)
  2407 SDL_CalculateBlitN(SDL_Surface * surface)
  2408 {
  2408 {
  2409     SDL_PixelFormat *srcfmt;
  2409     SDL_PixelFormat *srcfmt;
  2410     SDL_PixelFormat *dstfmt;
  2410     SDL_PixelFormat *dstfmt;
  2411     const struct blit_table *table;
  2411     const struct blit_table *table;
  2412     int which;
  2412     int which;
  2413     SDL_loblit blitfun;
  2413     SDL_BlitFunc blitfun;
  2414 
  2414 
  2415     /* Set up data for choosing the blit */
  2415     /* Set up data for choosing the blit */
  2416     srcfmt = surface->format;
  2416     srcfmt = surface->format;
  2417     dstfmt = surface->map->dst->format;
  2417     dstfmt = surface->map->dst->format;
  2418 
  2418 
  2419     if (blit_index & 2) {
       
  2420         /* alpha or alpha+colorkey */
       
  2421         return SDL_CalculateAlphaBlit(surface, blit_index);
       
  2422     }
       
  2423 
       
  2424     /* We don't support destinations less than 8-bits */
  2419     /* We don't support destinations less than 8-bits */
  2425     if (dstfmt->BitsPerPixel < 8) {
  2420     if (dstfmt->BitsPerPixel < 8) {
  2426         return (NULL);
  2421         return (NULL);
  2427     }
  2422     }
  2428 
  2423 
  2429     if (blit_index == 1) {
  2424     switch (surface->map->info.flags) {
       
  2425     case 0:
       
  2426         blitfun = NULL;
       
  2427         if (dstfmt->BitsPerPixel == 8) {
       
  2428             /* We assume 8-bit destinations are palettized */
       
  2429             if ((srcfmt->BytesPerPixel == 4) &&
       
  2430                 (srcfmt->Rmask == 0x00FF0000) &&
       
  2431                 (srcfmt->Gmask == 0x0000FF00) &&
       
  2432                 (srcfmt->Bmask == 0x000000FF)) {
       
  2433                 if (surface->map->info.table) {
       
  2434                     blitfun = Blit_RGB888_index8_map;
       
  2435                 } else {
       
  2436                     blitfun = Blit_RGB888_index8;
       
  2437                 }
       
  2438             } else {
       
  2439                 blitfun = BlitNto1;
       
  2440             }
       
  2441         } else {
       
  2442             /* Now the meat, choose the blitter we want */
       
  2443             int a_need = NO_ALPHA;
       
  2444             if (dstfmt->Amask)
       
  2445                 a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA;
       
  2446             table = normal_blit[srcfmt->BytesPerPixel - 1];
       
  2447             for (which = 0; table[which].dstbpp; ++which) {
       
  2448                 if (MASKOK(srcfmt->Rmask, table[which].srcR) &&
       
  2449                     MASKOK(srcfmt->Gmask, table[which].srcG) &&
       
  2450                     MASKOK(srcfmt->Bmask, table[which].srcB) &&
       
  2451                     MASKOK(dstfmt->Rmask, table[which].dstR) &&
       
  2452                     MASKOK(dstfmt->Gmask, table[which].dstG) &&
       
  2453                     MASKOK(dstfmt->Bmask, table[which].dstB) &&
       
  2454                     dstfmt->BytesPerPixel == table[which].dstbpp &&
       
  2455                     (a_need & table[which].alpha) == a_need &&
       
  2456                     ((table[which].blit_features & GetBlitFeatures()) ==
       
  2457                      table[which].blit_features))
       
  2458                     break;
       
  2459             }
       
  2460             blitfun = table[which].blitfunc;
       
  2461 
       
  2462             if (blitfun == BlitNtoN) {  /* default C fallback catch-all. Slow! */
       
  2463                 /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
       
  2464                 if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4
       
  2465                     && srcfmt->Rmask == dstfmt->Rmask
       
  2466                     && srcfmt->Gmask == dstfmt->Gmask
       
  2467                     && srcfmt->Bmask == dstfmt->Bmask) {
       
  2468                     blitfun = Blit4to4MaskAlpha;
       
  2469                 } else if (a_need == COPY_ALPHA) {
       
  2470                     blitfun = BlitNtoNCopyAlpha;
       
  2471                 }
       
  2472             }
       
  2473         }
       
  2474         return (blitfun);
       
  2475 
       
  2476     case SDL_COPY_COLORKEY:
  2430         /* colorkey blit: Here we don't have too many options, mostly
  2477         /* colorkey blit: Here we don't have too many options, mostly
  2431            because RLE is the preferred fast way to deal with this.
  2478            because RLE is the preferred fast way to deal with this.
  2432            If a particular case turns out to be useful we'll add it. */
  2479            If a particular case turns out to be useful we'll add it. */
  2433 
  2480 
  2434         if (srcfmt->BytesPerPixel == 2 && surface->map->identity)
  2481         if (srcfmt->BytesPerPixel == 2 && surface->map->identity)
  2440             if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4)
  2487             if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4)
  2441                 && SDL_HasAltiVec()) {
  2488                 && SDL_HasAltiVec()) {
  2442                 return Blit32to32KeyAltivec;
  2489                 return Blit32to32KeyAltivec;
  2443             } else
  2490             } else
  2444 #endif
  2491 #endif
  2445 
  2492             if (srcfmt->Amask && dstfmt->Amask) {
  2446             if (srcfmt->Amask && dstfmt->Amask)
       
  2447                 return BlitNtoNKeyCopyAlpha;
  2493                 return BlitNtoNKeyCopyAlpha;
  2448             else
  2494             } else {
  2449                 return BlitNtoNKey;
  2495                 return BlitNtoNKey;
  2450         }
       
  2451     }
       
  2452 
       
  2453     blitfun = NULL;
       
  2454     if (dstfmt->BitsPerPixel == 8) {
       
  2455         /* We assume 8-bit destinations are palettized */
       
  2456         if ((srcfmt->BytesPerPixel == 4) &&
       
  2457             (srcfmt->Rmask == 0x00FF0000) &&
       
  2458             (srcfmt->Gmask == 0x0000FF00) && (srcfmt->Bmask == 0x000000FF)) {
       
  2459             if (surface->map->table) {
       
  2460                 blitfun = Blit_RGB888_index8_map;
       
  2461             } else {
       
  2462                 blitfun = Blit_RGB888_index8;
       
  2463             }
  2496             }
  2464         } else {
  2497         }
  2465             blitfun = BlitNto1;
  2498     }
  2466         }
  2499 
  2467     } else {
  2500     return NULL;
  2468         /* Now the meat, choose the blitter we want */
       
  2469         int a_need = NO_ALPHA;
       
  2470         if (dstfmt->Amask)
       
  2471             a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA;
       
  2472         table = normal_blit[srcfmt->BytesPerPixel - 1];
       
  2473         for (which = 0; table[which].dstbpp; ++which) {
       
  2474             if (MASKOK(srcfmt->Rmask, table[which].srcR) &&
       
  2475                 MASKOK(srcfmt->Gmask, table[which].srcG) &&
       
  2476                 MASKOK(srcfmt->Bmask, table[which].srcB) &&
       
  2477                 MASKOK(dstfmt->Rmask, table[which].dstR) &&
       
  2478                 MASKOK(dstfmt->Gmask, table[which].dstG) &&
       
  2479                 MASKOK(dstfmt->Bmask, table[which].dstB) &&
       
  2480                 dstfmt->BytesPerPixel == table[which].dstbpp &&
       
  2481                 (a_need & table[which].alpha) == a_need &&
       
  2482                 ((table[which].blit_features & GetBlitFeatures()) ==
       
  2483                  table[which].blit_features))
       
  2484                 break;
       
  2485         }
       
  2486         blitfun = table[which].blitfunc;
       
  2487 
       
  2488         if (blitfun == BlitNtoN) {      /* default C fallback catch-all. Slow! */
       
  2489             /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
       
  2490             if (srcfmt->BytesPerPixel == 4 && dstfmt->BytesPerPixel == 4 &&
       
  2491                 srcfmt->Rmask == dstfmt->Rmask &&
       
  2492                 srcfmt->Gmask == dstfmt->Gmask &&
       
  2493                 srcfmt->Bmask == dstfmt->Bmask) {
       
  2494                 blitfun = Blit4to4MaskAlpha;
       
  2495             } else if (a_need == COPY_ALPHA) {
       
  2496                 blitfun = BlitNtoNCopyAlpha;
       
  2497             }
       
  2498         }
       
  2499     }
       
  2500 
       
  2501 #ifdef DEBUG_ASM
       
  2502     if ((blitfun == BlitNtoN) || (blitfun == BlitNto1))
       
  2503         fprintf(stderr, "Using C blit\n");
       
  2504     else
       
  2505         fprintf(stderr, "Using optimized C blit\n");
       
  2506 #endif /* DEBUG_ASM */
       
  2507 
       
  2508     return (blitfun);
       
  2509 }
  2501 }
  2510 
  2502 
  2511 /* vi: set ts=4 sw=4 expandtab: */
  2503 /* vi: set ts=4 sw=4 expandtab: */