src/video/SDL_blit_N.c
changeset 12582 57b136cff952
parent 12503 806492103856
child 12583 338b02acfdfc
equal deleted inserted replaced
12581:62f26ad46749 12582:57b136cff952
  2513         src += srcskip;
  2513         src += srcskip;
  2514         dst += dstskip;
  2514         dst += dstskip;
  2515     }
  2515     }
  2516 }
  2516 }
  2517 
  2517 
       
  2518 /* Blit_3or4_to_3or4__same_rgb: 3 or 4 bpp, same RGB triplet */
       
  2519 static void
       
  2520 Blit_3or4_to_3or4__same_rgb(SDL_BlitInfo * info)
       
  2521 {
       
  2522     int width = info->dst_w;
       
  2523     int height = info->dst_h;
       
  2524     Uint8 *src = info->src;
       
  2525     int srcskip = info->src_skip;
       
  2526     Uint8 *dst = info->dst;
       
  2527     int dstskip = info->dst_skip;
       
  2528     SDL_PixelFormat *srcfmt = info->src_fmt;
       
  2529     int srcbpp = srcfmt->BytesPerPixel;
       
  2530     SDL_PixelFormat *dstfmt = info->dst_fmt;
       
  2531     int dstbpp = dstfmt->BytesPerPixel;
       
  2532 
       
  2533     if (dstfmt->Amask) {
       
  2534         /* SET_ALPHA */
       
  2535         unsigned alpha = info->a;
       
  2536         int alphashift = alpha << 24;
       
  2537         while (height--) {
       
  2538             /* *INDENT-OFF* */
       
  2539             DUFFS_LOOP(
       
  2540             {
       
  2541                 Uint32  *dst32 = (Uint32*)dst;
       
  2542                 unsigned s0 = src[0];
       
  2543                 unsigned s1 = src[1];
       
  2544                 unsigned s2 = src[2];
       
  2545                 *dst32 = (s0) | (s1 << 8) | (s2 << 16) | alphashift;
       
  2546                 dst += dstbpp;
       
  2547                 src += srcbpp;
       
  2548             }, width);
       
  2549             /* *INDENT-ON* */
       
  2550             src += srcskip;
       
  2551             dst += dstskip;
       
  2552         }
       
  2553     } else {
       
  2554         /* NO_ALPHA */
       
  2555         while (height--) {
       
  2556             /* *INDENT-OFF* */
       
  2557             DUFFS_LOOP(
       
  2558             {
       
  2559                 Uint32  *dst32 = (Uint32*)dst;
       
  2560                 unsigned s0 = src[0];
       
  2561                 unsigned s1 = src[1];
       
  2562                 unsigned s2 = src[2];
       
  2563                 *dst32 = (s0) | (s1 << 8) | (s2 << 16);
       
  2564                 dst += dstbpp;
       
  2565                 src += srcbpp;
       
  2566             }, width);
       
  2567             /* *INDENT-ON* */
       
  2568             src += srcskip;
       
  2569             dst += dstskip;
       
  2570         }
       
  2571     }
       
  2572     return;
       
  2573 }
       
  2574 
       
  2575 /* Blit_3or4_to_3or4__inversed_rgb: 3 or 4 bpp, inversed RGB triplet */
       
  2576 static void
       
  2577 Blit_3or4_to_3or4__inversed_rgb(SDL_BlitInfo * info)
       
  2578 {
       
  2579     int width = info->dst_w;
       
  2580     int height = info->dst_h;
       
  2581     Uint8 *src = info->src;
       
  2582     int srcskip = info->src_skip;
       
  2583     Uint8 *dst = info->dst;
       
  2584     int dstskip = info->dst_skip;
       
  2585     SDL_PixelFormat *srcfmt = info->src_fmt;
       
  2586     int srcbpp = srcfmt->BytesPerPixel;
       
  2587     SDL_PixelFormat *dstfmt = info->dst_fmt;
       
  2588     int dstbpp = dstfmt->BytesPerPixel;
       
  2589 
       
  2590     if (dstfmt->Amask) {
       
  2591 
       
  2592         if (srcfmt->Amask) {
       
  2593             /* COPY_ALPHA */
       
  2594             /* Only to switch ABGR8888 <-> ARGB8888 */
       
  2595             while (height--) {
       
  2596                 /* *INDENT-OFF* */
       
  2597                 DUFFS_LOOP(
       
  2598                 {
       
  2599                     Uint32  *dst32 = (Uint32*)dst;
       
  2600                     unsigned s0 = src[0];
       
  2601                     unsigned s1 = src[1];
       
  2602                     unsigned s2 = src[2];
       
  2603                     unsigned alphashift = src[3] << 24;
       
  2604                     /* inversed, compared to Blit_3or4_to_3or4__same_rgb */
       
  2605                     *dst32 = (s0 << 16) | (s1 << 8) | (s2) | alphashift;
       
  2606                     dst += dstbpp;
       
  2607                     src += srcbpp;
       
  2608                 }, width);
       
  2609                 /* *INDENT-ON* */
       
  2610                 src += srcskip;
       
  2611                 dst += dstskip;
       
  2612             }
       
  2613         } else {
       
  2614             /* SET_ALPHA */
       
  2615             unsigned alpha = info->a;
       
  2616             int alphashift = alpha << 24;
       
  2617             while (height--) {
       
  2618                 /* *INDENT-OFF* */
       
  2619                 DUFFS_LOOP(
       
  2620                 {
       
  2621                     Uint32  *dst32 = (Uint32*)dst;
       
  2622                     unsigned s0 = src[0];
       
  2623                     unsigned s1 = src[1];
       
  2624                     unsigned s2 = src[2];
       
  2625                     /* inversed, compared to Blit_3or4_to_3or4__same_rgb */
       
  2626                     *dst32 = (s0 << 16) | (s1 << 8) | (s2) | alphashift;
       
  2627                     dst += dstbpp;
       
  2628                     src += srcbpp;
       
  2629                 }, width);
       
  2630                 /* *INDENT-ON* */
       
  2631                 src += srcskip;
       
  2632                 dst += dstskip;
       
  2633             }
       
  2634         }
       
  2635     } else {
       
  2636         /* NO_ALPHA */
       
  2637         while (height--) {
       
  2638             /* *INDENT-OFF* */
       
  2639             DUFFS_LOOP(
       
  2640             {
       
  2641                 Uint32  *dst32 = (Uint32*)dst;
       
  2642                 unsigned s0 = src[0];
       
  2643                 unsigned s1 = src[1];
       
  2644                 unsigned s2 = src[2];
       
  2645                 /* inversed, compared to Blit_3or4_to_3or4__same_rgb */
       
  2646                 *dst32 = (s0 << 16) | (s1 << 8) | (s2);
       
  2647                 dst += dstbpp;
       
  2648                 src += srcbpp;
       
  2649             }, width);
       
  2650             /* *INDENT-ON* */
       
  2651             src += srcskip;
       
  2652             dst += dstskip;
       
  2653         }
       
  2654     }
       
  2655     return;
       
  2656 }
       
  2657 
  2518 /* Normal N to N optimized blitters */
  2658 /* Normal N to N optimized blitters */
  2519 #define NO_ALPHA   1
  2659 #define NO_ALPHA   1
  2520 #define SET_ALPHA  2
  2660 #define SET_ALPHA  2
  2521 #define COPY_ALPHA 4
  2661 #define COPY_ALPHA 4
  2522 struct blit_table
  2662 struct blit_table
  2553     /* Default for 16-bit RGB source, used if no other blitter matches */
  2693     /* Default for 16-bit RGB source, used if no other blitter matches */
  2554     {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
  2694     {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
  2555 };
  2695 };
  2556 
  2696 
  2557 static const struct blit_table normal_blit_3[] = {
  2697 static const struct blit_table normal_blit_3[] = {
       
  2698 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
       
  2699     /* 3->4 with same rgb triplet */
       
  2700     {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
       
  2701      0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
       
  2702     {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
       
  2703      0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
       
  2704     /* 3->4 with inversed rgb triplet */
       
  2705     {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
       
  2706      0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
       
  2707     {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
       
  2708      0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
       
  2709     /* 3->3 to switch RGB 24 <-> BGR 24 */
       
  2710     {0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
       
  2711      0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA },
       
  2712     {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
       
  2713      0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA },
       
  2714 #endif
  2558     /* Default for 24-bit RGB source, never optimized */
  2715     /* Default for 24-bit RGB source, never optimized */
  2559     {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
  2716     {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
  2560 };
  2717 };
  2561 
  2718 
  2562 static const struct blit_table normal_blit_4[] = {
  2719 static const struct blit_table normal_blit_4[] = {
  2569      2, ConvertAltivec32to32_prefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
  2726      2, ConvertAltivec32to32_prefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA},
  2570     /* has-altivec */
  2727     /* has-altivec */
  2571     {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, 0x0000001F,
  2728     {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, 0x0000001F,
  2572      2, Blit_RGB888_RGB565Altivec, NO_ALPHA},
  2729      2, Blit_RGB888_RGB565Altivec, NO_ALPHA},
  2573 #endif
  2730 #endif
       
  2731 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
       
  2732     /* 4->3 with same rgb triplet */
       
  2733     {0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
       
  2734      0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
       
  2735     {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
       
  2736      0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
       
  2737     /* 4->3 with inversed rgb triplet */
       
  2738     {0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
       
  2739      0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
       
  2740     {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
       
  2741      0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
       
  2742 #endif
       
  2743     /* 4->4 with inversed rgb triplet, and COPY_ALPHA to switch ABGR8888 <-> ARGB8888 */
       
  2744     {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
       
  2745      0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA | COPY_ALPHA},
       
  2746     {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
       
  2747      0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA | COPY_ALPHA},
       
  2748     /* RBG 888 and RGB 565 */
  2574     {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, 0x0000001F,
  2749     {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, 0x0000001F,
  2575      0, Blit_RGB888_RGB565, NO_ALPHA},
  2750      0, Blit_RGB888_RGB565, NO_ALPHA},
  2576     {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, 0x0000001F,
  2751     {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, 0x0000001F,
  2577      0, Blit_RGB888_RGB555, NO_ALPHA},
  2752      0, Blit_RGB888_RGB555, NO_ALPHA},
  2578     /* Default for 32-bit RGB source, used if no other blitter matches */
  2753     /* Default for 32-bit RGB source, used if no other blitter matches */
  2621             } else {
  2796             } else {
  2622                 blitfun = BlitNto1;
  2797                 blitfun = BlitNto1;
  2623             }
  2798             }
  2624         } else {
  2799         } else {
  2625             /* Now the meat, choose the blitter we want */
  2800             /* Now the meat, choose the blitter we want */
  2626             int a_need = NO_ALPHA;
  2801             Uint32 a_need = NO_ALPHA;
  2627             if (dstfmt->Amask)
  2802             if (dstfmt->Amask)
  2628                 a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA;
  2803                 a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA;
  2629             table = normal_blit[srcfmt->BytesPerPixel - 1];
  2804             table = normal_blit[srcfmt->BytesPerPixel - 1];
  2630             for (which = 0; table[which].dstbpp; ++which) {
  2805             for (which = 0; table[which].dstbpp; ++which) {
  2631                 if (MASKOK(srcfmt->Rmask, table[which].srcR) &&
  2806                 if (MASKOK(srcfmt->Rmask, table[which].srcR) &&