src/video/SDL_blit_slow.c
changeset 2824 4dba7aa7ea77
parent 2256 e893d24ad8db
child 2859 99210400e8b9
     1.1 --- a/src/video/SDL_blit_slow.c	Tue Dec 02 17:10:05 2008 +0000
     1.2 +++ b/src/video/SDL_blit_slow.c	Tue Dec 02 17:14:04 2008 +0000
     1.3 @@ -27,5 +27,144 @@
     1.4  /* The ONE TRUE BLITTER
     1.5   * This puppy has to handle all the unoptimized cases - yes, it's slow.
     1.6   */
     1.7 +void
     1.8 +SDL_Blit_Slow(SDL_BlitInfo * info)
     1.9 +{
    1.10 +    const int flags = info->flags;
    1.11 +    const Uint32 modulateR = info->r;
    1.12 +    const Uint32 modulateG = info->g;
    1.13 +    const Uint32 modulateB = info->b;
    1.14 +    const Uint32 modulateA = info->a;
    1.15 +    Uint32 srcpixel;
    1.16 +    Uint32 srcR, srcG, srcB, srcA;
    1.17 +    Uint32 dstpixel;
    1.18 +    Uint32 dstR, dstG, dstB, dstA;
    1.19 +    int srcy, srcx;
    1.20 +    int posy, posx;
    1.21 +    int incy, incx;
    1.22 +    SDL_PixelFormat *src_fmt = info->src_fmt;
    1.23 +    SDL_PixelFormat *dst_fmt = info->dst_fmt;
    1.24 +    int srcbpp = src_fmt->BytesPerPixel;
    1.25 +    int dstbpp = dst_fmt->BytesPerPixel;
    1.26 +
    1.27 +    srcy = 0;
    1.28 +    posy = 0;
    1.29 +    incy = (info->src_h << 16) / info->dst_h;
    1.30 +    incx = (info->src_w << 16) / info->dst_w;
    1.31 +
    1.32 +    while (info->dst_h--) {
    1.33 +        Uint8 *src;
    1.34 +        Uint8 *dst = (Uint8 *) info->dst;
    1.35 +        int n = info->dst_w;
    1.36 +        srcx = -1;
    1.37 +        posx = 0x10000L;
    1.38 +        while (posy >= 0x10000L) {
    1.39 +            ++srcy;
    1.40 +            posy -= 0x10000L;
    1.41 +        }
    1.42 +        while (n--) {
    1.43 +            if (posx >= 0x10000L) {
    1.44 +                while (posx >= 0x10000L) {
    1.45 +                    ++srcx;
    1.46 +                    posx -= 0x10000L;
    1.47 +                }
    1.48 +                src =
    1.49 +                    (info->src + (srcy * info->src_pitch) + (srcx * srcbpp));
    1.50 +            }
    1.51 +            if (src_fmt->Amask) {
    1.52 +                DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG,
    1.53 +                              srcB, srcA);
    1.54 +            } else {
    1.55 +                DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG,
    1.56 +                             srcB);
    1.57 +                srcA = 0xFF;
    1.58 +            }
    1.59 +            if (flags & SDL_COPY_COLORKEY) {
    1.60 +                /* srcpixel isn't set for 24 bpp */
    1.61 +                if (srcbpp == 24) {
    1.62 +                    srcpixel = (srcR << src_fmt->Rshift) |
    1.63 +                        (srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
    1.64 +                }
    1.65 +                if (srcpixel == info->colorkey) {
    1.66 +                    posx += incx;
    1.67 +                    dst += dstbpp;
    1.68 +                    continue;
    1.69 +                }
    1.70 +            }
    1.71 +            if (dst_fmt->Amask) {
    1.72 +                DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG,
    1.73 +                              dstB, dstA);
    1.74 +            } else {
    1.75 +                DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG,
    1.76 +                             dstB);
    1.77 +                dstA = 0xFF;
    1.78 +            }
    1.79 +
    1.80 +            if (flags & SDL_COPY_MODULATE_COLOR) {
    1.81 +                srcR = (srcR * modulateR) / 255;
    1.82 +                srcG = (srcG * modulateG) / 255;
    1.83 +                srcB = (srcB * modulateB) / 255;
    1.84 +            }
    1.85 +            if (flags & SDL_COPY_MODULATE_ALPHA) {
    1.86 +                srcA = (srcA * modulateA) / 255;
    1.87 +            }
    1.88 +            if (flags & (SDL_COPY_BLEND | SDL_COPY_ADD)) {
    1.89 +                /* This goes away if we ever use premultiplied alpha */
    1.90 +                if (srcA < 255) {
    1.91 +                    srcR = (srcR * srcA) / 255;
    1.92 +                    srcG = (srcG * srcA) / 255;
    1.93 +                    srcB = (srcB * srcA) / 255;
    1.94 +                }
    1.95 +            }
    1.96 +            switch (flags &
    1.97 +                    (SDL_COPY_MASK | SDL_COPY_BLEND | SDL_COPY_ADD |
    1.98 +                     SDL_COPY_MOD)) {
    1.99 +            case 0:
   1.100 +                dstR = srcR;
   1.101 +                dstG = srcG;
   1.102 +                dstB = srcB;
   1.103 +                dstA = srcA;
   1.104 +                break;
   1.105 +            case SDL_COPY_MASK:
   1.106 +                if (srcA) {
   1.107 +                    dstR = srcR;
   1.108 +                    dstG = srcG;
   1.109 +                    dstB = srcB;
   1.110 +                }
   1.111 +                break;
   1.112 +            case SDL_COPY_BLEND:
   1.113 +                dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.114 +                dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.115 +                dstB = srcB + ((255 - srcA) * dstB) / 255;
   1.116 +                break;
   1.117 +            case SDL_COPY_ADD:
   1.118 +                dstR = srcR + dstR;
   1.119 +                if (dstR > 255)
   1.120 +                    dstR = 255;
   1.121 +                dstG = srcG + dstG;
   1.122 +                if (dstG > 255)
   1.123 +                    dstG = 255;
   1.124 +                dstB = srcB + dstB;
   1.125 +                if (dstB > 255)
   1.126 +                    dstB = 255;
   1.127 +                break;
   1.128 +            case SDL_COPY_MOD:
   1.129 +                dstR = (srcR * dstR) / 255;
   1.130 +                dstG = (srcG * dstG) / 255;
   1.131 +                dstB = (srcB * dstB) / 255;
   1.132 +                break;
   1.133 +            }
   1.134 +            if (dst_fmt->Amask) {
   1.135 +                ASSEMBLE_RGBA(dst, dstbpp, dst_fmt, dstR, dstG, dstB, dstA);
   1.136 +            } else {
   1.137 +                ASSEMBLE_RGB(dst, dstbpp, dst_fmt, dstR, dstG, dstB);
   1.138 +            }
   1.139 +            posx += incx;
   1.140 +            dst += dstbpp;
   1.141 +        }
   1.142 +        posy += incy;
   1.143 +        info->dst += info->dst_pitch;
   1.144 +    }
   1.145 +}
   1.146  
   1.147  /* vi: set ts=4 sw=4 expandtab: */