src/video/SDL_blit_N.c
changeset 12582 57b136cff952
parent 12503 806492103856
child 12583 338b02acfdfc
     1.1 --- a/src/video/SDL_blit_N.c	Tue Jan 29 12:21:22 2019 +0000
     1.2 +++ b/src/video/SDL_blit_N.c	Wed Jan 30 15:23:33 2019 +0100
     1.3 @@ -2515,6 +2515,146 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +/* Blit_3or4_to_3or4__same_rgb: 3 or 4 bpp, same RGB triplet */
     1.8 +static void
     1.9 +Blit_3or4_to_3or4__same_rgb(SDL_BlitInfo * info)
    1.10 +{
    1.11 +    int width = info->dst_w;
    1.12 +    int height = info->dst_h;
    1.13 +    Uint8 *src = info->src;
    1.14 +    int srcskip = info->src_skip;
    1.15 +    Uint8 *dst = info->dst;
    1.16 +    int dstskip = info->dst_skip;
    1.17 +    SDL_PixelFormat *srcfmt = info->src_fmt;
    1.18 +    int srcbpp = srcfmt->BytesPerPixel;
    1.19 +    SDL_PixelFormat *dstfmt = info->dst_fmt;
    1.20 +    int dstbpp = dstfmt->BytesPerPixel;
    1.21 +
    1.22 +    if (dstfmt->Amask) {
    1.23 +        /* SET_ALPHA */
    1.24 +        unsigned alpha = info->a;
    1.25 +        int alphashift = alpha << 24;
    1.26 +        while (height--) {
    1.27 +            /* *INDENT-OFF* */
    1.28 +            DUFFS_LOOP(
    1.29 +            {
    1.30 +                Uint32  *dst32 = (Uint32*)dst;
    1.31 +                unsigned s0 = src[0];
    1.32 +                unsigned s1 = src[1];
    1.33 +                unsigned s2 = src[2];
    1.34 +                *dst32 = (s0) | (s1 << 8) | (s2 << 16) | alphashift;
    1.35 +                dst += dstbpp;
    1.36 +                src += srcbpp;
    1.37 +            }, width);
    1.38 +            /* *INDENT-ON* */
    1.39 +            src += srcskip;
    1.40 +            dst += dstskip;
    1.41 +        }
    1.42 +    } else {
    1.43 +        /* NO_ALPHA */
    1.44 +        while (height--) {
    1.45 +            /* *INDENT-OFF* */
    1.46 +            DUFFS_LOOP(
    1.47 +            {
    1.48 +                Uint32  *dst32 = (Uint32*)dst;
    1.49 +                unsigned s0 = src[0];
    1.50 +                unsigned s1 = src[1];
    1.51 +                unsigned s2 = src[2];
    1.52 +                *dst32 = (s0) | (s1 << 8) | (s2 << 16);
    1.53 +                dst += dstbpp;
    1.54 +                src += srcbpp;
    1.55 +            }, width);
    1.56 +            /* *INDENT-ON* */
    1.57 +            src += srcskip;
    1.58 +            dst += dstskip;
    1.59 +        }
    1.60 +    }
    1.61 +    return;
    1.62 +}
    1.63 +
    1.64 +/* Blit_3or4_to_3or4__inversed_rgb: 3 or 4 bpp, inversed RGB triplet */
    1.65 +static void
    1.66 +Blit_3or4_to_3or4__inversed_rgb(SDL_BlitInfo * info)
    1.67 +{
    1.68 +    int width = info->dst_w;
    1.69 +    int height = info->dst_h;
    1.70 +    Uint8 *src = info->src;
    1.71 +    int srcskip = info->src_skip;
    1.72 +    Uint8 *dst = info->dst;
    1.73 +    int dstskip = info->dst_skip;
    1.74 +    SDL_PixelFormat *srcfmt = info->src_fmt;
    1.75 +    int srcbpp = srcfmt->BytesPerPixel;
    1.76 +    SDL_PixelFormat *dstfmt = info->dst_fmt;
    1.77 +    int dstbpp = dstfmt->BytesPerPixel;
    1.78 +
    1.79 +    if (dstfmt->Amask) {
    1.80 +
    1.81 +        if (srcfmt->Amask) {
    1.82 +            /* COPY_ALPHA */
    1.83 +            /* Only to switch ABGR8888 <-> ARGB8888 */
    1.84 +            while (height--) {
    1.85 +                /* *INDENT-OFF* */
    1.86 +                DUFFS_LOOP(
    1.87 +                {
    1.88 +                    Uint32  *dst32 = (Uint32*)dst;
    1.89 +                    unsigned s0 = src[0];
    1.90 +                    unsigned s1 = src[1];
    1.91 +                    unsigned s2 = src[2];
    1.92 +                    unsigned alphashift = src[3] << 24;
    1.93 +                    /* inversed, compared to Blit_3or4_to_3or4__same_rgb */
    1.94 +                    *dst32 = (s0 << 16) | (s1 << 8) | (s2) | alphashift;
    1.95 +                    dst += dstbpp;
    1.96 +                    src += srcbpp;
    1.97 +                }, width);
    1.98 +                /* *INDENT-ON* */
    1.99 +                src += srcskip;
   1.100 +                dst += dstskip;
   1.101 +            }
   1.102 +        } else {
   1.103 +            /* SET_ALPHA */
   1.104 +            unsigned alpha = info->a;
   1.105 +            int alphashift = alpha << 24;
   1.106 +            while (height--) {
   1.107 +                /* *INDENT-OFF* */
   1.108 +                DUFFS_LOOP(
   1.109 +                {
   1.110 +                    Uint32  *dst32 = (Uint32*)dst;
   1.111 +                    unsigned s0 = src[0];
   1.112 +                    unsigned s1 = src[1];
   1.113 +                    unsigned s2 = src[2];
   1.114 +                    /* inversed, compared to Blit_3or4_to_3or4__same_rgb */
   1.115 +                    *dst32 = (s0 << 16) | (s1 << 8) | (s2) | alphashift;
   1.116 +                    dst += dstbpp;
   1.117 +                    src += srcbpp;
   1.118 +                }, width);
   1.119 +                /* *INDENT-ON* */
   1.120 +                src += srcskip;
   1.121 +                dst += dstskip;
   1.122 +            }
   1.123 +        }
   1.124 +    } else {
   1.125 +        /* NO_ALPHA */
   1.126 +        while (height--) {
   1.127 +            /* *INDENT-OFF* */
   1.128 +            DUFFS_LOOP(
   1.129 +            {
   1.130 +                Uint32  *dst32 = (Uint32*)dst;
   1.131 +                unsigned s0 = src[0];
   1.132 +                unsigned s1 = src[1];
   1.133 +                unsigned s2 = src[2];
   1.134 +                /* inversed, compared to Blit_3or4_to_3or4__same_rgb */
   1.135 +                *dst32 = (s0 << 16) | (s1 << 8) | (s2);
   1.136 +                dst += dstbpp;
   1.137 +                src += srcbpp;
   1.138 +            }, width);
   1.139 +            /* *INDENT-ON* */
   1.140 +            src += srcskip;
   1.141 +            dst += dstskip;
   1.142 +        }
   1.143 +    }
   1.144 +    return;
   1.145 +}
   1.146 +
   1.147  /* Normal N to N optimized blitters */
   1.148  #define NO_ALPHA   1
   1.149  #define SET_ALPHA  2
   1.150 @@ -2555,6 +2695,23 @@
   1.151  };
   1.152  
   1.153  static const struct blit_table normal_blit_3[] = {
   1.154 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.155 +    /* 3->4 with same rgb triplet */
   1.156 +    {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
   1.157 +     0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
   1.158 +    {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
   1.159 +     0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
   1.160 +    /* 3->4 with inversed rgb triplet */
   1.161 +    {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
   1.162 +     0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
   1.163 +    {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
   1.164 +     0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
   1.165 +    /* 3->3 to switch RGB 24 <-> BGR 24 */
   1.166 +    {0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
   1.167 +     0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA },
   1.168 +    {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
   1.169 +     0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA },
   1.170 +#endif
   1.171      /* Default for 24-bit RGB source, never optimized */
   1.172      {0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
   1.173  };
   1.174 @@ -2571,6 +2728,24 @@
   1.175      {0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, 0x0000001F,
   1.176       2, Blit_RGB888_RGB565Altivec, NO_ALPHA},
   1.177  #endif
   1.178 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   1.179 +    /* 4->3 with same rgb triplet */
   1.180 +    {0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
   1.181 +     0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
   1.182 +    {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
   1.183 +     0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA},
   1.184 +    /* 4->3 with inversed rgb triplet */
   1.185 +    {0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
   1.186 +     0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
   1.187 +    {0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
   1.188 +     0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA},
   1.189 +#endif
   1.190 +    /* 4->4 with inversed rgb triplet, and COPY_ALPHA to switch ABGR8888 <-> ARGB8888 */
   1.191 +    {0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
   1.192 +     0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA | COPY_ALPHA},
   1.193 +    {0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
   1.194 +     0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA | COPY_ALPHA},
   1.195 +    /* RBG 888 and RGB 565 */
   1.196      {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, 0x0000001F,
   1.197       0, Blit_RGB888_RGB565, NO_ALPHA},
   1.198      {0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, 0x0000001F,
   1.199 @@ -2623,7 +2798,7 @@
   1.200              }
   1.201          } else {
   1.202              /* Now the meat, choose the blitter we want */
   1.203 -            int a_need = NO_ALPHA;
   1.204 +            Uint32 a_need = NO_ALPHA;
   1.205              if (dstfmt->Amask)
   1.206                  a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA;
   1.207              table = normal_blit[srcfmt->BytesPerPixel - 1];