src/video/SDL_blit_N.c
changeset 12609 48e26b5d4f56
parent 12608 b3a02787a4dd
child 12610 587922004ea0
equal deleted inserted replaced
12608:b3a02787a4dd 12609:48e26b5d4f56
  2150 }
  2150 }
  2151 
  2151 
  2152 /* permutation for mapping srcfmt to dstfmt, overloading or not the alpha channel */
  2152 /* permutation for mapping srcfmt to dstfmt, overloading or not the alpha channel */
  2153 static void
  2153 static void
  2154 get_permutation(SDL_PixelFormat *srcfmt, SDL_PixelFormat *dstfmt,
  2154 get_permutation(SDL_PixelFormat *srcfmt, SDL_PixelFormat *dstfmt,
  2155         int *_r , int *_g, int *_b, int *_a, int *_missing)
  2155         int *_p0 , int *_p1, int *_p2, int *_p3, int *_alpha_channel)
  2156 {
  2156 {
  2157     int missing = 0, r, g, b, a = 0;
  2157     int alpha_channel = 0, p0, p1, p2, p3;
  2158     int Pixel = 0x04030201; /* identity permutation */
  2158     int Pixel = 0x04030201; /* identity permutation */
  2159 
  2159 
  2160     if (srcfmt->Amask) {
  2160     if (srcfmt->Amask) {
  2161         RGBA_FROM_PIXEL(Pixel, srcfmt, r, g, b, a);
  2161         RGBA_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2, p3);
  2162     } else {
  2162     } else {
  2163         RGB_FROM_PIXEL(Pixel, srcfmt, r, g, b);
  2163         RGB_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2);
       
  2164         p3 = 0;
  2164     }
  2165     }
  2165 
  2166 
  2166     if (dstfmt->Amask) {
  2167     if (dstfmt->Amask) {
  2167         if (srcfmt->Amask) {
  2168         if (srcfmt->Amask) {
  2168             PIXEL_FROM_RGBA(Pixel, dstfmt, r, g, b, a);
  2169             PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, p3);
  2169         } else {
  2170         } else {
  2170             PIXEL_FROM_RGBA(Pixel, dstfmt, r, g, b, 0);
  2171             PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, 0);
  2171         }
  2172         }
  2172     } else {
  2173     } else {
  2173         PIXEL_FROM_RGB(Pixel, dstfmt, r, g, b);
  2174         PIXEL_FROM_RGB(Pixel, dstfmt, p0, p1, p2);
  2174     }
  2175     }
  2175 
  2176 
  2176     r = Pixel & 0xFF;
  2177     p0 = Pixel & 0xFF;
  2177     g = (Pixel >> 8) & 0xFF;
  2178     p1 = (Pixel >> 8) & 0xFF;
  2178     b = (Pixel >> 16) & 0xFF;
  2179     p2 = (Pixel >> 16) & 0xFF;
  2179     a = (Pixel >> 24) & 0xFF;
  2180     p3 = (Pixel >> 24) & 0xFF;
  2180 
  2181 
  2181     if (r == 0) {
  2182     if (p0 == 0) {
  2182         r = 1;
  2183         p0 = 1;
  2183         missing = 0;
  2184         alpha_channel = 0;
  2184     } else if (g == 0) {
  2185     } else if (p1 == 0) {
  2185         g = 1;
  2186         p1 = 1;
  2186         missing = 1;
  2187         alpha_channel = 1;
  2187     } else if (b == 0) {
  2188     } else if (p2 == 0) {
  2188         b = 1;
  2189         p2 = 1;
  2189         missing = 2;
  2190         alpha_channel = 2;
  2190     } else if (a == 0) {
  2191     } else if (p3 == 0) {
  2191         a = 1;
  2192         p3 = 1;
  2192         missing = 3;
  2193         alpha_channel = 3;
  2193     }
  2194     }
  2194 
  2195 
  2195     *_r = r - 1;
  2196     *_p0 = p0 - 1;
  2196     *_g = g - 1;
  2197     *_p1 = p1 - 1;
  2197     *_b = b - 1;
  2198     *_p2 = p2 - 1;
  2198     *_a = a - 1;
  2199     *_p3 = p3 - 1;
  2199 
  2200 
  2200     if (_missing) {
  2201     if (_alpha_channel) {
  2201         *_missing = missing;
  2202         *_alpha_channel = alpha_channel;
  2202     }
  2203     }
  2203     return;
  2204     return;
  2204 }
  2205 }
  2205 
  2206 
  2206 
  2207 
  2226 
  2227 
  2227         Uint32 *src32 = (Uint32*)src;
  2228         Uint32 *src32 = (Uint32*)src;
  2228         Uint32 *dst32 = (Uint32*)dst;
  2229         Uint32 *dst32 = (Uint32*)dst;
  2229 
  2230 
  2230         /* Find the appropriate permutation */
  2231         /* Find the appropriate permutation */
  2231         int missing = 0, r, g, b, a;
  2232         int alpha_channel, p0, p1, p2, p3;
  2232         get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, &missing);
  2233         get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
  2233 
  2234 
  2234         while (height--) {
  2235         while (height--) {
  2235             /* *INDENT-OFF* */
  2236             /* *INDENT-OFF* */
  2236             DUFFS_LOOP(
  2237             DUFFS_LOOP(
  2237             {
  2238             {
  2238                 Uint8 *s8 = (Uint8 *)src32;
  2239                 Uint8 *s8 = (Uint8 *)src32;
  2239                 Uint8 *d8 = (Uint8 *)dst32;
  2240                 Uint8 *d8 = (Uint8 *)dst32;
  2240                 d8[0] = s8[r];
  2241                 d8[0] = s8[p0];
  2241                 d8[1] = s8[g];
  2242                 d8[1] = s8[p1];
  2242                 d8[2] = s8[b];
  2243                 d8[2] = s8[p2];
  2243                 d8[3] = s8[a];
  2244                 d8[3] = s8[p3];
  2244                 d8[missing] = alpha;
  2245                 d8[alpha_channel] = alpha;
  2245                 ++src32;
  2246                 ++src32;
  2246                 ++dst32;
  2247                 ++dst32;
  2247             }, width);
  2248             }, width);
  2248             /* *INDENT-ON* */
  2249             /* *INDENT-ON* */
  2249             src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
  2250             src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
  2257         srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2258         srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2258 
  2259 
  2259         Uint32 *src32 = (Uint32*)src;
  2260         Uint32 *src32 = (Uint32*)src;
  2260 
  2261 
  2261         /* Find the appropriate permutation */
  2262         /* Find the appropriate permutation */
  2262         int r, g, b, a;
  2263         int p0, p1, p2, p3;
  2263         get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, NULL);
  2264         get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
  2264 
  2265 
  2265         while (height--) {
  2266         while (height--) {
  2266             /* *INDENT-OFF* */
  2267             /* *INDENT-OFF* */
  2267             DUFFS_LOOP(
  2268             DUFFS_LOOP(
  2268             {
  2269             {
  2269                 Uint8 *s8 = (Uint8 *)src32;
  2270                 Uint8 *s8 = (Uint8 *)src32;
  2270                 dst[0] = s8[r];
  2271                 dst[0] = s8[p0];
  2271                 dst[1] = s8[g];
  2272                 dst[1] = s8[p1];
  2272                 dst[2] = s8[b];
  2273                 dst[2] = s8[p2];
  2273                 ++src32;
  2274                 ++src32;
  2274                 dst += 3;
  2275                 dst += 3;
  2275             }, width);
  2276             }, width);
  2276             /* *INDENT-ON* */
  2277             /* *INDENT-ON* */
  2277             src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
  2278             src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
  2285         dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2286         dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2286 
  2287 
  2287         Uint32 *dst32 = (Uint32*)dst;
  2288         Uint32 *dst32 = (Uint32*)dst;
  2288 
  2289 
  2289         /* Find the appropriate permutation */
  2290         /* Find the appropriate permutation */
  2290         int missing = 0, r, g, b, a;
  2291         int alpha_channel, p0, p1, p2, p3;
  2291         get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, &missing);
  2292         get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
  2292 
  2293 
  2293         while (height--) {
  2294         while (height--) {
  2294             /* *INDENT-OFF* */
  2295             /* *INDENT-OFF* */
  2295             DUFFS_LOOP(
  2296             DUFFS_LOOP(
  2296             {
  2297             {
  2297                 Uint8 *d8 = (Uint8 *)dst32;
  2298                 Uint8 *d8 = (Uint8 *)dst32;
  2298                 d8[0] = src[r];
  2299                 d8[0] = src[p0];
  2299                 d8[1] = src[g];
  2300                 d8[1] = src[p1];
  2300                 d8[2] = src[b];
  2301                 d8[2] = src[p2];
  2301                 d8[3] = src[a];
  2302                 d8[3] = src[p3];
  2302                 d8[missing] = alpha;
  2303                 d8[alpha_channel] = alpha;
  2303                 src += 3;
  2304                 src += 3;
  2304                 ++dst32;
  2305                 ++dst32;
  2305             }, width);
  2306             }, width);
  2306             /* *INDENT-ON* */
  2307             /* *INDENT-ON* */
  2307             src += srcskip;
  2308             src += srcskip;
  2352 
  2353 
  2353         Uint32 *src32 = (Uint32*)src;
  2354         Uint32 *src32 = (Uint32*)src;
  2354         Uint32 *dst32 = (Uint32*)dst;
  2355         Uint32 *dst32 = (Uint32*)dst;
  2355 
  2356 
  2356         /* Find the appropriate permutation */
  2357         /* Find the appropriate permutation */
  2357         int r, g, b, a;
  2358         int p0, p1, p2, p3;
  2358         get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, NULL);
  2359         get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
  2359 
  2360 
  2360         while (height--) {
  2361         while (height--) {
  2361             /* *INDENT-OFF* */
  2362             /* *INDENT-OFF* */
  2362             DUFFS_LOOP(
  2363             DUFFS_LOOP(
  2363             {
  2364             {
  2364                 Uint8 *s8 = (Uint8 *)src32;
  2365                 Uint8 *s8 = (Uint8 *)src32;
  2365                 Uint8 *d8 = (Uint8 *)dst32;
  2366                 Uint8 *d8 = (Uint8 *)dst32;
  2366                 d8[0] = s8[r];
  2367                 d8[0] = s8[p0];
  2367                 d8[1] = s8[g];
  2368                 d8[1] = s8[p1];
  2368                 d8[2] = s8[b];
  2369                 d8[2] = s8[p2];
  2369                 d8[3] = s8[a];
  2370                 d8[3] = s8[p3];
  2370                 ++src32;
  2371                 ++src32;
  2371                 ++dst32;
  2372                 ++dst32;
  2372             }, width);
  2373             }, width);
  2373             /* *INDENT-ON* */
  2374             /* *INDENT-ON* */
  2374             src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
  2375             src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
  2564 
  2565 
  2565         Uint32 *src32 = (Uint32*)src;
  2566         Uint32 *src32 = (Uint32*)src;
  2566         Uint32 *dst32 = (Uint32*)dst;
  2567         Uint32 *dst32 = (Uint32*)dst;
  2567 
  2568 
  2568         /* Find the appropriate permutation */
  2569         /* Find the appropriate permutation */
  2569         int missing = 0, r, g, b, a;
  2570         int alpha_channel, p0, p1, p2, p3;
  2570         get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, &missing);
  2571         get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
  2571 
  2572 
  2572         while (height--) {
  2573         while (height--) {
  2573             /* *INDENT-OFF* */
  2574             /* *INDENT-OFF* */
  2574             DUFFS_LOOP(
  2575             DUFFS_LOOP(
  2575             {
  2576             {
  2576                 if ((*src32 & rgbmask) != ckey) {
  2577                 if ((*src32 & rgbmask) != ckey) {
  2577                     Uint8 *s8 = (Uint8 *)src32;
  2578                     Uint8 *s8 = (Uint8 *)src32;
  2578                     Uint8 *d8 = (Uint8 *)dst32;
  2579                     Uint8 *d8 = (Uint8 *)dst32;
  2579                     d8[0] = s8[r];
  2580                     d8[0] = s8[p0];
  2580                     d8[1] = s8[g];
  2581                     d8[1] = s8[p1];
  2581                     d8[2] = s8[b];
  2582                     d8[2] = s8[p2];
  2582                     d8[3] = s8[a];
  2583                     d8[3] = s8[p3];
  2583                     d8[missing] = alpha;
  2584                     d8[alpha_channel] = alpha;
  2584                 }
  2585                 }
  2585                 ++src32;
  2586                 ++src32;
  2586                 ++dst32;
  2587                 ++dst32;
  2587             }, width);
  2588             }, width);
  2588             /* *INDENT-ON* */
  2589             /* *INDENT-ON* */
  2661         srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2662         srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2662 
  2663 
  2663         Uint32 *src32 = (Uint32*)src;
  2664         Uint32 *src32 = (Uint32*)src;
  2664 
  2665 
  2665         /* Find the appropriate permutation */
  2666         /* Find the appropriate permutation */
  2666         int r, g, b, a;
  2667         int p0, p1, p2, p3;
  2667         get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, NULL);
  2668         get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
  2668 
  2669 
  2669         while (height--) {
  2670         while (height--) {
  2670             /* *INDENT-OFF* */
  2671             /* *INDENT-OFF* */
  2671             DUFFS_LOOP(
  2672             DUFFS_LOOP(
  2672             {
  2673             {
  2673                 if ((*src32 & rgbmask) != ckey) {
  2674                 if ((*src32 & rgbmask) != ckey) {
  2674                     Uint8 *s8 = (Uint8 *)src32;
  2675                     Uint8 *s8 = (Uint8 *)src32;
  2675                     dst[0] = s8[r];
  2676                     dst[0] = s8[p0];
  2676                     dst[1] = s8[g];
  2677                     dst[1] = s8[p1];
  2677                     dst[2] = s8[b];
  2678                     dst[2] = s8[p2];
  2678                 }
  2679                 }
  2679                 ++src32;
  2680                 ++src32;
  2680                 dst += 3;
  2681                 dst += 3;
  2681             }, width);
  2682             }, width);
  2682             /* *INDENT-ON* */
  2683             /* *INDENT-ON* */
  2695         Uint8 k0 = ckey & 0xFF;
  2696         Uint8 k0 = ckey & 0xFF;
  2696         Uint8 k1 = (ckey >> 8)  & 0xFF;
  2697         Uint8 k1 = (ckey >> 8)  & 0xFF;
  2697         Uint8 k2 = (ckey >> 16) & 0xFF;
  2698         Uint8 k2 = (ckey >> 16) & 0xFF;
  2698 
  2699 
  2699         /* Find the appropriate permutation */
  2700         /* Find the appropriate permutation */
  2700         int missing = 0, r, g, b, a;
  2701         int alpha_channel, p0, p1, p2, p3;
  2701         get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, &missing);
  2702         get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
  2702 
  2703 
  2703         while (height--) {
  2704         while (height--) {
  2704             /* *INDENT-OFF* */
  2705             /* *INDENT-OFF* */
  2705             DUFFS_LOOP(
  2706             DUFFS_LOOP(
  2706             {
  2707             {
  2708                 Uint8 s1 = src[1];
  2709                 Uint8 s1 = src[1];
  2709                 Uint8 s2 = src[2];
  2710                 Uint8 s2 = src[2];
  2710 
  2711 
  2711                 if (k0 != s0 || k1 != s1 || k2 != s2) {
  2712                 if (k0 != s0 || k1 != s1 || k2 != s2) {
  2712                     Uint8 *d8 = (Uint8 *)dst32;
  2713                     Uint8 *d8 = (Uint8 *)dst32;
  2713                     d8[0] = src[r];
  2714                     d8[0] = src[p0];
  2714                     d8[1] = src[g];
  2715                     d8[1] = src[p1];
  2715                     d8[2] = src[b];
  2716                     d8[2] = src[p2];
  2716                     d8[3] = src[a];
  2717                     d8[3] = src[p3];
  2717                     d8[missing] = alpha;
  2718                     d8[alpha_channel] = alpha;
  2718                 }
  2719                 }
  2719                 src += 3;
  2720                 src += 3;
  2720                 ++dst32;
  2721                 ++dst32;
  2721             }, width);
  2722             }, width);
  2722             /* *INDENT-ON* */
  2723             /* *INDENT-ON* */
  2810 
  2811 
  2811         Uint32 *src32 = (Uint32*)src;
  2812         Uint32 *src32 = (Uint32*)src;
  2812         Uint32 *dst32 = (Uint32*)dst;
  2813         Uint32 *dst32 = (Uint32*)dst;
  2813 
  2814 
  2814         /* Find the appropriate permutation */
  2815         /* Find the appropriate permutation */
  2815         int r, g, b, a;
  2816         int p0, p1, p2, p3;
  2816         get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, NULL);
  2817         get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
  2817 
  2818 
  2818         while (height--) {
  2819         while (height--) {
  2819             /* *INDENT-OFF* */
  2820             /* *INDENT-OFF* */
  2820             DUFFS_LOOP(
  2821             DUFFS_LOOP(
  2821             {
  2822             {
  2822                 if ((*src32 & rgbmask) != ckey) {
  2823                 if ((*src32 & rgbmask) != ckey) {
  2823                     Uint8 *s8 = (Uint8 *)src32;
  2824                     Uint8 *s8 = (Uint8 *)src32;
  2824                     Uint8 *d8 = (Uint8 *)dst32;
  2825                     Uint8 *d8 = (Uint8 *)dst32;
  2825                     d8[0] = s8[r];
  2826                     d8[0] = s8[p0];
  2826                     d8[1] = s8[g];
  2827                     d8[1] = s8[p1];
  2827                     d8[2] = s8[b];
  2828                     d8[2] = s8[p2];
  2828                     d8[3] = s8[a];
  2829                     d8[3] = s8[p3];
  2829                 }
  2830                 }
  2830                 ++src32;
  2831                 ++src32;
  2831                 ++dst32;
  2832                 ++dst32;
  2832             }, width);
  2833             }, width);
  2833             /* *INDENT-ON* */
  2834             /* *INDENT-ON* */