src/video/SDL_RLEaccel.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 19 Jun 2015 23:12:13 -0700
changeset 9761 fd7fe355f173
parent 9619 b94b6d0bff0f
child 10000 acd714e378f4
permissions -rw-r--r--
Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer Adam M. Okay, here is the problem, I think. During the first blit, RLEAlphaSurface is called to do RLE conversion of the RGBA source into a format allowing it "to be quickly alpha-blittable onto dest". Since the destination is the screen, it has no alpha channel. RLEAlphaSurface calls copy_opaque(dst, src + runstart, len, sf, df) (where copy_opaque is copy_32), which has this code: SDL_RLEaccel.c:984: RGBA_FROM_8888(*src, sfmt, r, g, b, a); PIXEL_FROM_RGBA(*d, dfmt, r, g, b, a); On the first line, it reads the source pixel 0xFFFFFFFF. The second line drops the alpha value (because dfmt for the screen has no alpha channel) and writes 0x00FFFFFF. Later, when the RLE conversion is being undone, uncopy_32 is called, which has the following code: SDL_RLEaccel.c:1001: Uint32 pixel = *s++; RGB_FROM_PIXEL(pixel, sfmt, r, g, b); a = pixel >> 24; PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a); However, the the alpha channel has already been dropped by copy_opaque (= copy_32), so pixel = 0x00FFFFFF and 'a' becomes 0. Thus, all opaque pixels lose their alpha channel when being unRLE'd. (I don't know what happens to pixels with alpha from 1-254, but they should be checked too.) So, that seems to be the problem, but I'm not sure what the solution should be. Since opaque pixels have alpha == 255, I'm thinking to create another uncopy function for opaque pixels that simply uses 255 for alpha. However, there may be other problems here. For translucent pixels, uncopy_32 assumes the alpha channel is stored in the upper 8 bits, but copy_32 doesn't store it there. Instead, it stores it in whatever location is appropriate for the destination surface. Isn't one of their behaviors incorrect, given the other? I'm not sure which to change, however. For translucent pixels, it seems that the blit function uses do_blend, which is the BLIT_TRANSL_888 macro, which also assumes alpha is in top 8 bits. It has the comment "we have made sure the alpha is stored in the top 8 bits...", but it seems that's not true (copy_32 doesn't make sure the alpha goes there). Perhaps the correct fix is to make copy_32 put the alpha there, but then that seems to require that RLE conversion be limited to destination surfaces that don't use the upper 8 bits. However, looking further, it seems that has already been done: if (masksum != 0x00ffffff) return -1; /* requires unused high byte */
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     2
  Simple DirectMedia Layer
9619
b94b6d0bff0f Updated the copyright year to 2015
Sam Lantinga <slouken@libsdl.org>
parents: 8924
diff changeset
     3
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     7
  arising from the use of this software.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    11
  freely, subject to the following restrictions:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5439
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    20
*/
8093
b43765095a6f Make internal SDL sources include SDL_internal.h instead of SDL_config.h
Ryan C. Gordon <icculus@icculus.org>
parents: 7719
diff changeset
    21
#include "../SDL_internal.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
 * RLE encoding for software colorkey and alpha-channel acceleration
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
 * Original version by Sam Lantinga
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
 * Mattias Engdegård (Yorick): Rewrite. New encoding format, encoder and
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
 * decoder. Added per-surface alpha blitter. Added per-pixel alpha
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
 * format, encoder and blitter.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
 * Many thanks to Xark and johns for hints, benchmarks and useful comments
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    33
 * leading to this code.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    34
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    35
 * Welcome to Macro Mayhem.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    36
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    37
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    38
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    39
 * The encoding translates the image data to a stream of segments of the form
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    40
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    41
 * <skip> <run> <data>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    42
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    43
 * where <skip> is the number of transparent pixels to skip,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    44
 *       <run>  is the number of opaque pixels to blit,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    45
 * and   <data> are the pixels themselves.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    46
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    47
 * This basic structure is used both for colorkeyed surfaces, used for simple
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    48
 * binary transparency and for per-surface alpha blending, and for surfaces
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    49
 * with per-pixel alpha. The details differ, however:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    50
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    51
 * Encoding of colorkeyed surfaces:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    52
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    53
 *   Encoded pixels always have the same format as the target surface.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    54
 *   <skip> and <run> are unsigned 8 bit integers, except for 32 bit depth
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    55
 *   where they are 16 bit. This makes the pixel data aligned at all times.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    56
 *   Segments never wrap around from one scan line to the next.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    57
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    58
 *   The end of the sequence is marked by a zero <skip>,<run> pair at the *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    59
 *   beginning of a line.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    60
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    61
 * Encoding of surfaces with per-pixel alpha:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    62
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    63
 *   The sequence begins with a struct RLEDestFormat describing the target
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    64
 *   pixel format, to provide reliable un-encoding.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    65
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    66
 *   Each scan line is encoded twice: First all completely opaque pixels,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    67
 *   encoded in the target format as described above, and then all
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    68
 *   partially transparent (translucent) pixels (where 1 <= alpha <= 254),
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    69
 *   in the following 32-bit format:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    70
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    71
 *   For 32-bit targets, each pixel has the target RGB format but with
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    72
 *   the alpha value occupying the highest 8 bits. The <skip> and <run>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    73
 *   counts are 16 bit.
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
    74
 *
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    75
 *   For 16-bit targets, each pixel has the target RGB format, but with
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    76
 *   the middle component (usually green) shifted 16 steps to the left,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    77
 *   and the hole filled with the 5 most significant bits of the alpha value.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    78
 *   i.e. if the target has the format         rrrrrggggggbbbbb,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    79
 *   the encoded pixel will be 00000gggggg00000rrrrr0aaaaabbbbb.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    80
 *   The <skip> and <run> counts are 8 bit for the opaque lines, 16 bit
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    81
 *   for the translucent lines. Two padding bytes may be inserted
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    82
 *   before each translucent line to keep them 32-bit aligned.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    83
 *
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    84
 *   The end of the sequence is marked by a zero <skip>,<run> pair at the
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    85
 *   beginning of an opaque line.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    86
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    87
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    88
#include "SDL_video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    89
#include "SDL_sysvideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    90
#include "SDL_blit.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    91
#include "SDL_RLEaccel_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    92
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    93
#ifndef MAX
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    94
#define MAX(a, b) ((a) > (b) ? (a) : (b))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    95
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    96
#ifndef MIN
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    97
#define MIN(a, b) ((a) < (b) ? (a) : (b))
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    98
#endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    99
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   100
#define PIXEL_COPY(to, from, len, bpp)          \
7351
668a3dc28361 Removed the inline functions from SDL_stdinc.h
Sam Lantinga <slouken@libsdl.org>
parents: 7191
diff changeset
   101
    SDL_memcpy(to, from, (size_t)(len) * (bpp))
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   102
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   103
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   104
 * Various colorkey blit methods, for opaque and per-surface alpha
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   105
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   106
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   107
#define OPAQUE_BLIT(to, from, length, bpp, alpha)   \
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
   108
    PIXEL_COPY(to, from, length, bpp)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   109
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   110
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   111
 * For 32bpp pixels on the form 0x00rrggbb:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   112
 * If we treat the middle component separately, we can process the two
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   113
 * remaining in parallel. This is safe to do because of the gap to the left
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   114
 * of each component, so the bits from the multiplication don't collide.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   115
 * This can be used for any RGB permutation of course.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   116
 */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   117
#define ALPHA_BLIT32_888(to, from, length, bpp, alpha)      \
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   118
    do {                                                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   119
        int i;                                              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   120
        Uint32 *src = (Uint32 *)(from);                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   121
        Uint32 *dst = (Uint32 *)(to);                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   122
        for (i = 0; i < (int)(length); i++) {               \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   123
            Uint32 s = *src++;                              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   124
            Uint32 d = *dst;                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   125
            Uint32 s1 = s & 0xff00ff;                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   126
            Uint32 d1 = d & 0xff00ff;                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   127
            d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   128
            s &= 0xff00;                                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   129
            d &= 0xff00;                                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   130
            d = (d + ((s - d) * alpha >> 8)) & 0xff00;      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   131
            *dst++ = d1 | d;                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   132
        }                                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   133
    } while (0)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   134
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   135
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   136
 * For 16bpp pixels we can go a step further: put the middle component
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   137
 * in the high 16 bits of a 32 bit word, and process all three RGB
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   138
 * components at the same time. Since the smallest gap is here just
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   139
 * 5 bits, we have to scale alpha down to 5 bits as well.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   140
 */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   141
#define ALPHA_BLIT16_565(to, from, length, bpp, alpha)  \
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   142
    do {                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   143
        int i;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   144
        Uint16 *src = (Uint16 *)(from);                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   145
        Uint16 *dst = (Uint16 *)(to);                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   146
        Uint32 ALPHA = alpha >> 3;                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   147
        for(i = 0; i < (int)(length); i++) {            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   148
            Uint32 s = *src++;                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   149
            Uint32 d = *dst;                            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   150
            s = (s | s << 16) & 0x07e0f81f;             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   151
            d = (d | d << 16) & 0x07e0f81f;             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   152
            d += (s - d) * ALPHA >> 5;                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   153
            d &= 0x07e0f81f;                            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   154
            *dst++ = (Uint16)(d | d >> 16);             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   155
        }                                               \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   156
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   158
#define ALPHA_BLIT16_555(to, from, length, bpp, alpha)  \
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   159
    do {                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   160
        int i;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   161
        Uint16 *src = (Uint16 *)(from);                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   162
        Uint16 *dst = (Uint16 *)(to);                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   163
        Uint32 ALPHA = alpha >> 3;                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   164
        for(i = 0; i < (int)(length); i++) {            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   165
            Uint32 s = *src++;                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   166
            Uint32 d = *dst;                            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   167
            s = (s | s << 16) & 0x03e07c1f;             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   168
            d = (d | d << 16) & 0x03e07c1f;             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   169
            d += (s - d) * ALPHA >> 5;                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   170
            d &= 0x03e07c1f;                            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   171
            *dst++ = (Uint16)(d | d >> 16);             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   172
        }                                               \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   173
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   174
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   175
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   176
 * The general slow catch-all function, for remaining depths and formats
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   177
 */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   178
#define ALPHA_BLIT_ANY(to, from, length, bpp, alpha)            \
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   179
    do {                                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   180
        int i;                                                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   181
        Uint8 *src = from;                                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   182
        Uint8 *dst = to;                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   183
        for (i = 0; i < (int)(length); i++) {                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   184
            Uint32 s, d;                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   185
            unsigned rs, gs, bs, rd, gd, bd;                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   186
            switch (bpp) {                                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   187
            case 2:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   188
                s = *(Uint16 *)src;                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   189
                d = *(Uint16 *)dst;                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   190
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   191
            case 3:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   192
                if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   193
                    s = (src[0] << 16) | (src[1] << 8) | src[2]; \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   194
                    d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   195
                } else {                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   196
                    s = (src[2] << 16) | (src[1] << 8) | src[0]; \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   197
                    d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   198
                }                                               \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   199
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   200
            case 4:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   201
                s = *(Uint32 *)src;                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   202
                d = *(Uint32 *)dst;                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   203
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   204
            }                                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   205
            RGB_FROM_PIXEL(s, fmt, rs, gs, bs);                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   206
            RGB_FROM_PIXEL(d, fmt, rd, gd, bd);                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   207
            rd += (rs - rd) * alpha >> 8;                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   208
            gd += (gs - gd) * alpha >> 8;                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   209
            bd += (bs - bd) * alpha >> 8;                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   210
            PIXEL_FROM_RGB(d, fmt, rd, gd, bd);                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   211
            switch (bpp) {                                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   212
            case 2:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   213
                *(Uint16 *)dst = (Uint16)d;                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   214
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   215
            case 3:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   216
                if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   217
                    dst[0] = (Uint8)(d >> 16);                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   218
                    dst[1] = (Uint8)(d >> 8);                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   219
                    dst[2] = (Uint8)(d);                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   220
                } else {                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   221
                    dst[0] = (Uint8)d;                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   222
                    dst[1] = (Uint8)(d >> 8);                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   223
                    dst[2] = (Uint8)(d >> 16);                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   224
                }                                               \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   225
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   226
            case 4:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   227
                *(Uint32 *)dst = d;                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   228
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   229
            }                                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   230
            src += bpp;                                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   231
            dst += bpp;                                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   232
        }                                                       \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   233
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   234
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   235
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   236
 * Special case: 50% alpha (alpha=128)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   237
 * This is treated specially because it can be optimized very well, and
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   238
 * since it is good for many cases of semi-translucency.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   239
 * The theory is to do all three components at the same time:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   240
 * First zero the lowest bit of each component, which gives us room to
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   241
 * add them. Then shift right and add the sum of the lowest bits.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   242
 */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   243
#define ALPHA_BLIT32_888_50(to, from, length, bpp, alpha)       \
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   244
    do {                                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   245
        int i;                                                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   246
        Uint32 *src = (Uint32 *)(from);                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   247
        Uint32 *dst = (Uint32 *)(to);                           \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   248
        for(i = 0; i < (int)(length); i++) {                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   249
            Uint32 s = *src++;                                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   250
            Uint32 d = *dst;                                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   251
            *dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   252
                 + (s & d & 0x00010101);                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   253
        }                                                       \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   254
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   255
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   256
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   257
 * For 16bpp, we can actually blend two pixels in parallel, if we take
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   258
 * care to shift before we add, not after.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   259
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   260
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   261
/* helper: blend a single 16 bit pixel at 50% */
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   262
#define BLEND16_50(dst, src, mask)                              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   263
    do {                                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   264
        Uint32 s = *src++;                                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   265
        Uint32 d = *dst;                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   266
        *dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) +    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   267
                          (s & d & (~mask & 0xffff)));          \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   268
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   269
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   270
/* basic 16bpp blender. mask is the pixels to keep when adding. */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   271
#define ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask)     \
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   272
    do {                                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   273
        unsigned n = (length);                                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   274
        Uint16 *src = (Uint16 *)(from);                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   275
        Uint16 *dst = (Uint16 *)(to);                           \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   276
        if (((uintptr_t)src ^ (uintptr_t)dst) & 3) {            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   277
            /* source and destination not in phase, blit one by one */ \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   278
            while (n--)                                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   279
                BLEND16_50(dst, src, mask);                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   280
        } else {                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   281
            if ((uintptr_t)src & 3) {                           \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   282
                /* first odd pixel */                           \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   283
                BLEND16_50(dst, src, mask);                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   284
                n--;                                            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   285
            }                                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   286
            for (; n > 1; n -= 2) {                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   287
                Uint32 s = *(Uint32 *)src;                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   288
                Uint32 d = *(Uint32 *)dst;                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   289
                *(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   290
                    + ((d & (mask | mask << 16)) >> 1)          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   291
                    + (s & d & (~(mask | mask << 16)));         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   292
                src += 2;                                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   293
                dst += 2;                                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   294
            }                                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   295
            if (n)                                              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   296
                BLEND16_50(dst, src, mask); /* last odd pixel */ \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   297
        }                                                       \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   298
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   299
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   300
#define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha)       \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   301
    ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7de)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   302
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   303
#define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha)       \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   304
    ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   305
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   306
#define CHOOSE_BLIT(blitter, alpha, fmt)                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   307
    do {                                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   308
        if (alpha == 255) {                                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   309
            switch (fmt->BytesPerPixel) {                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   310
            case 1: blitter(1, Uint8, OPAQUE_BLIT); break;      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   311
            case 2: blitter(2, Uint8, OPAQUE_BLIT); break;      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   312
            case 3: blitter(3, Uint8, OPAQUE_BLIT); break;      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   313
            case 4: blitter(4, Uint16, OPAQUE_BLIT); break;     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   314
            }                                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   315
        } else {                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   316
            switch (fmt->BytesPerPixel) {                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   317
            case 1:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   318
                /* No 8bpp alpha blitting */                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   319
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   320
                                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   321
            case 2:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   322
                switch (fmt->Rmask | fmt->Gmask | fmt->Bmask) { \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   323
                case 0xffff:                                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   324
                    if (fmt->Gmask == 0x07e0                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   325
                        || fmt->Rmask == 0x07e0                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   326
                        || fmt->Bmask == 0x07e0) {              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   327
                        if (alpha == 128) {                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   328
                            blitter(2, Uint8, ALPHA_BLIT16_565_50); \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   329
                        } else {                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   330
                            blitter(2, Uint8, ALPHA_BLIT16_565); \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   331
                        }                                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   332
                    } else                                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   333
                        goto general16;                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   334
                    break;                                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   335
                                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   336
                case 0x7fff:                                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   337
                    if (fmt->Gmask == 0x03e0                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   338
                        || fmt->Rmask == 0x03e0                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   339
                        || fmt->Bmask == 0x03e0) {              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   340
                        if (alpha == 128) {                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   341
                            blitter(2, Uint8, ALPHA_BLIT16_555_50); \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   342
                        } else {                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   343
                            blitter(2, Uint8, ALPHA_BLIT16_555); \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   344
                        }                                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   345
                        break;                                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   346
                    } else                                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   347
                        goto general16;                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   348
                    break;                                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   349
                                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   350
                default:                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   351
    general16:                                                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   352
                    blitter(2, Uint8, ALPHA_BLIT_ANY);          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   353
                }                                               \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   354
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   355
                                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   356
            case 3:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   357
                blitter(3, Uint8, ALPHA_BLIT_ANY);              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   358
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   359
                                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   360
            case 4:                                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   361
                if ((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   362
                    && (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   363
                    || fmt->Bmask == 0xff00)) {                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   364
                    if (alpha == 128) {                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   365
                        blitter(4, Uint16, ALPHA_BLIT32_888_50); \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   366
                    } else {                                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   367
                        blitter(4, Uint16, ALPHA_BLIT32_888);   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   368
                    }                                           \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   369
                } else                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   370
                    blitter(4, Uint16, ALPHA_BLIT_ANY);         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   371
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   372
            }                                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   373
        }                                                       \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   374
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   375
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   376
/*
9761
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   377
 * Set a pixel value using the given format, except that the alpha value is
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   378
 * placed in the top byte. This is the format used for RLE with alpha.
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   379
 */
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   380
#define RLEPIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a)                      \
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   381
{                                                                       \
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   382
    Pixel = ((r>>fmt->Rloss)<<fmt->Rshift)|                             \
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   383
        ((g>>fmt->Gloss)<<fmt->Gshift)|                                 \
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   384
        ((b>>fmt->Bloss)<<fmt->Bshift)|                                 \
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   385
        (a<<24);                                                        \
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   386
}
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   387
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   388
/*
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   389
 * This takes care of the case when the surface is clipped on the left and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   390
 * right. Top clipping has already been taken care of.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   391
 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   392
static void
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   393
RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   394
            Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   395
{
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   396
    SDL_PixelFormat *fmt = surf_dst->format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   397
8924
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   398
#define RLECLIPBLIT(bpp, Type, do_blit)                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   399
    do {                                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   400
        int linecount = srcrect->h;                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   401
        int ofs = 0;                                            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   402
        int left = srcrect->x;                                  \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   403
        int right = left + srcrect->w;                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   404
        dstbuf -= left * bpp;                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   405
        for (;;) {                                              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   406
            int run;                                            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   407
            ofs += *(Type *)srcbuf;                             \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   408
            run = ((Type *)srcbuf)[1];                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   409
            srcbuf += 2 * sizeof(Type);                         \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   410
            if (run) {                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   411
                /* clip to left and right borders */            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   412
                if (ofs < right) {                              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   413
                    int start = 0;                              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   414
                    int len = run;                              \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   415
                    int startcol;                               \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   416
                    if (left - ofs > 0) {                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   417
                        start = left - ofs;                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   418
                        len -= start;                           \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   419
                        if (len <= 0)                           \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   420
                            goto nocopy ## bpp ## do_blit;      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   421
                    }                                           \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   422
                    startcol = ofs + start;                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   423
                    if (len > right - startcol)                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   424
                        len = right - startcol;                 \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   425
                    do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   426
                        len, bpp, alpha);                       \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   427
                }                                               \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   428
    nocopy ## bpp ## do_blit:                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   429
                srcbuf += run * bpp;                            \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   430
                ofs += run;                                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   431
            } else if (!ofs)                                    \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   432
                break;                                          \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   433
                                                                \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   434
            if (ofs == w) {                                     \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   435
                ofs = 0;                                        \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   436
                dstbuf += surf_dst->pitch;                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   437
                if (!--linecount)                               \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   438
                    break;                                      \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   439
            }                                                   \
b80cdf666e91 Made the RLE code (semi) readable again
Sam Lantinga <slouken@libsdl.org>
parents: 8922
diff changeset
   440
        }                                                       \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   441
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   442
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   443
    CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   444
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   445
#undef RLECLIPBLIT
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   446
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   447
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   448
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   449
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   450
/* blit a colorkeyed RLE surface */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   451
int
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   452
SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   453
            SDL_Surface * surf_dst, SDL_Rect * dstrect)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   454
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   455
    Uint8 *dstbuf;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   456
    Uint8 *srcbuf;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   457
    int x, y;
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   458
    int w = surf_src->w;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   459
    unsigned alpha;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   460
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   461
    /* Lock the destination if necessary */
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   462
    if (SDL_MUSTLOCK(surf_dst)) {
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   463
        if (SDL_LockSurface(surf_dst) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   464
            return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   465
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   466
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   467
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   468
    /* Set up the source and destination pointers */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   469
    x = dstrect->x;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   470
    y = dstrect->y;
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   471
    dstbuf = (Uint8 *) surf_dst->pixels
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   472
        + y * surf_dst->pitch + x * surf_src->format->BytesPerPixel;
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   473
    srcbuf = (Uint8 *) surf_src->map->data;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   474
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   475
    {
7128
e10c5a9cc858 Corrected spelling in C source file.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7037
diff changeset
   476
        /* skip lines at the top if necessary */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   477
        int vskip = srcrect->y;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   478
        int ofs = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   479
        if (vskip) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   480
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   481
#define RLESKIP(bpp, Type)          \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   482
        for(;;) {           \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   483
            int run;            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   484
            ofs += *(Type *)srcbuf; \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   485
            run = ((Type *)srcbuf)[1];  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   486
            srcbuf += sizeof(Type) * 2; \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   487
            if(run) {           \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   488
            srcbuf += run * bpp;    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   489
            ofs += run;     \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   490
            } else if(!ofs)     \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   491
            goto done;      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   492
            if(ofs == w) {      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   493
            ofs = 0;        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   494
            if(!--vskip)        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   495
                break;      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   496
            }               \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   497
        }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   498
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   499
            switch (surf_src->format->BytesPerPixel) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   500
            case 1:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   501
                RLESKIP(1, Uint8);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   502
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   503
            case 2:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   504
                RLESKIP(2, Uint8);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   505
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   506
            case 3:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   507
                RLESKIP(3, Uint8);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   508
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   509
            case 4:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   510
                RLESKIP(4, Uint16);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   511
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   512
            }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   513
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   514
#undef RLESKIP
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   515
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   516
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   517
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   518
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   519
    alpha = surf_src->map->info.a;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   520
    /* if left or right edge clipping needed, call clip blit */
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   521
    if (srcrect->x || srcrect->w != surf_src->w) {
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   522
        RLEClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect, alpha);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   523
    } else {
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   524
        SDL_PixelFormat *fmt = surf_src->format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   525
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   526
#define RLEBLIT(bpp, Type, do_blit)                       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   527
        do {                                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   528
        int linecount = srcrect->h;                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   529
        int ofs = 0;                              \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   530
        for(;;) {                             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   531
            unsigned run;                         \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   532
            ofs += *(Type *)srcbuf;                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   533
            run = ((Type *)srcbuf)[1];                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   534
            srcbuf += 2 * sizeof(Type);                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   535
            if(run) {                             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   536
            do_blit(dstbuf + ofs * bpp, srcbuf, run, bpp, alpha); \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   537
            srcbuf += run * bpp;                      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   538
            ofs += run;                       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   539
            } else if(!ofs)                       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   540
            break;                            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   541
            if(ofs == w) {                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   542
            ofs = 0;                          \
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   543
            dstbuf += surf_dst->pitch;                     \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   544
            if(!--linecount)                      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   545
                break;                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   546
            }                                 \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   547
        }                                 \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   548
        } while(0)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   549
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   550
        CHOOSE_BLIT(RLEBLIT, alpha, fmt);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   551
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   552
#undef RLEBLIT
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   553
    }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   554
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   555
  done:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   556
    /* Unlock the destination if necessary */
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   557
    if (SDL_MUSTLOCK(surf_dst)) {
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   558
        SDL_UnlockSurface(surf_dst);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   559
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   560
    return (0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   561
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   562
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   563
#undef OPAQUE_BLIT
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   564
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   565
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   566
 * Per-pixel blitting macros for translucent pixels:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   567
 * These use the same techniques as the per-surface blitting macros
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   568
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   569
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   570
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   571
 * For 32bpp pixels, we have made sure the alpha is stored in the top
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   572
 * 8 bits, so proceed as usual
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   573
 */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   574
#define BLIT_TRANSL_888(src, dst)               \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   575
    do {                            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   576
        Uint32 s = src;                     \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   577
    Uint32 d = dst;                     \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   578
    unsigned alpha = s >> 24;               \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   579
    Uint32 s1 = s & 0xff00ff;               \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   580
    Uint32 d1 = d & 0xff00ff;               \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   581
    d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff;    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   582
    s &= 0xff00;                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   583
    d &= 0xff00;                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   584
    d = (d + ((s - d) * alpha >> 8)) & 0xff00;      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   585
    dst = d1 | d | 0xff000000;              \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   586
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   587
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   588
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   589
 * For 16bpp pixels, we have stored the 5 most significant alpha bits in
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   590
 * bits 5-10. As before, we can process all 3 RGB components at the same time.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   591
 */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   592
#define BLIT_TRANSL_565(src, dst)       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   593
    do {                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   594
    Uint32 s = src;             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   595
    Uint32 d = dst;             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   596
    unsigned alpha = (s & 0x3e0) >> 5;  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   597
    s &= 0x07e0f81f;            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   598
    d = (d | d << 16) & 0x07e0f81f;     \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   599
    d += (s - d) * alpha >> 5;      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   600
    d &= 0x07e0f81f;            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   601
    dst = (Uint16)(d | d >> 16);            \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   602
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   603
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   604
#define BLIT_TRANSL_555(src, dst)       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   605
    do {                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   606
    Uint32 s = src;             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   607
    Uint32 d = dst;             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   608
    unsigned alpha = (s & 0x3e0) >> 5;  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   609
    s &= 0x03e07c1f;            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   610
    d = (d | d << 16) & 0x03e07c1f;     \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   611
    d += (s - d) * alpha >> 5;      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   612
    d &= 0x03e07c1f;            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   613
    dst = (Uint16)(d | d >> 16);            \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   614
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   615
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   616
/* used to save the destination format in the encoding. Designed to be
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   617
   macro-compatible with SDL_PixelFormat but without the unneeded fields */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   618
typedef struct
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   619
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   620
    Uint8 BytesPerPixel;
5435
3de226f0cc06 Fixed up structure to match header, added missing Aloss
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
   621
    Uint8 padding[3];
3de226f0cc06 Fixed up structure to match header, added missing Aloss
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
   622
    Uint32 Rmask;
3de226f0cc06 Fixed up structure to match header, added missing Aloss
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
   623
    Uint32 Gmask;
3de226f0cc06 Fixed up structure to match header, added missing Aloss
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
   624
    Uint32 Bmask;
3de226f0cc06 Fixed up structure to match header, added missing Aloss
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
   625
    Uint32 Amask;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   626
    Uint8 Rloss;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   627
    Uint8 Gloss;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   628
    Uint8 Bloss;
5435
3de226f0cc06 Fixed up structure to match header, added missing Aloss
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
   629
    Uint8 Aloss;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   630
    Uint8 Rshift;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   631
    Uint8 Gshift;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   632
    Uint8 Bshift;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   633
    Uint8 Ashift;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   634
} RLEDestFormat;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   635
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   636
/* blit a pixel-alpha RLE surface clipped at the right and/or left edges */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   637
static void
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   638
RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   639
                 Uint8 * dstbuf, SDL_Rect * srcrect)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   640
{
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   641
    SDL_PixelFormat *df = surf_dst->format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   642
    /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   643
     * clipped blitter: Ptype is the destination pixel type,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   644
     * Ctype the translucent count type, and do_blend the macro
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   645
     * to blend one pixel.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   646
     */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   647
#define RLEALPHACLIPBLIT(Ptype, Ctype, do_blend)              \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   648
    do {                                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   649
    int linecount = srcrect->h;                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   650
    int left = srcrect->x;                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   651
    int right = left + srcrect->w;                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   652
    dstbuf -= left * sizeof(Ptype);                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   653
    do {                                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   654
        int ofs = 0;                          \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   655
        /* blit opaque pixels on one line */              \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   656
        do {                              \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   657
        unsigned run;                         \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   658
        ofs += ((Ctype *)srcbuf)[0];                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   659
        run = ((Ctype *)srcbuf)[1];               \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   660
        srcbuf += 2 * sizeof(Ctype);                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   661
        if(run) {                         \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   662
            /* clip to left and right borders */          \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   663
            int cofs = ofs;                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   664
            int crun = run;                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   665
            if(left - cofs > 0) {                 \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   666
            crun -= left - cofs;                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   667
            cofs = left;                      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   668
            }                             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   669
            if(crun > right - cofs)               \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   670
            crun = right - cofs;                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   671
            if(crun > 0)                      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   672
            PIXEL_COPY(dstbuf + cofs * sizeof(Ptype),     \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   673
                   srcbuf + (cofs - ofs) * sizeof(Ptype), \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   674
                   (unsigned)crun, sizeof(Ptype));    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   675
            srcbuf += run * sizeof(Ptype);            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   676
            ofs += run;                       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   677
        } else if(!ofs)                       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   678
            return;                       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   679
        } while(ofs < w);                         \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   680
        /* skip padding if necessary */               \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   681
        if(sizeof(Ptype) == 2)                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   682
        srcbuf += (uintptr_t)srcbuf & 2;              \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   683
        /* blit translucent pixels on the same line */        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   684
        ofs = 0;                              \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   685
        do {                              \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   686
        unsigned run;                         \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   687
        ofs += ((Uint16 *)srcbuf)[0];                 \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   688
        run = ((Uint16 *)srcbuf)[1];                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   689
        srcbuf += 4;                          \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   690
        if(run) {                         \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   691
            /* clip to left and right borders */          \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   692
            int cofs = ofs;                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   693
            int crun = run;                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   694
            if(left - cofs > 0) {                 \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   695
            crun -= left - cofs;                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   696
            cofs = left;                      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   697
            }                             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   698
            if(crun > right - cofs)               \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   699
            crun = right - cofs;                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   700
            if(crun > 0) {                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   701
            Ptype *dst = (Ptype *)dstbuf + cofs;          \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   702
            Uint32 *src = (Uint32 *)srcbuf + (cofs - ofs);    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   703
            int i;                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   704
            for(i = 0; i < crun; i++)             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   705
                do_blend(src[i], dst[i]);             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   706
            }                             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   707
            srcbuf += run * 4;                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   708
            ofs += run;                       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   709
        }                             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   710
        } while(ofs < w);                         \
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   711
        dstbuf += surf_dst->pitch;                     \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   712
    } while(--linecount);                         \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   713
    } while(0)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   714
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   715
    switch (df->BytesPerPixel) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   716
    case 2:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   717
        if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   718
            RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   719
        else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   720
            RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   721
        break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   722
    case 4:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   723
        RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   724
        break;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   725
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   726
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   727
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   728
/* blit a pixel-alpha RLE surface */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   729
int
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   730
SDL_RLEAlphaBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   731
                 SDL_Surface * surf_dst, SDL_Rect * dstrect)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   732
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   733
    int x, y;
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   734
    int w = surf_src->w;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   735
    Uint8 *srcbuf, *dstbuf;
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   736
    SDL_PixelFormat *df = surf_dst->format;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   737
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   738
    /* Lock the destination if necessary */
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   739
    if (SDL_MUSTLOCK(surf_dst)) {
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   740
        if (SDL_LockSurface(surf_dst) < 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   741
            return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   742
        }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   743
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   744
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   745
    x = dstrect->x;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   746
    y = dstrect->y;
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   747
    dstbuf = (Uint8 *) surf_dst->pixels + y * surf_dst->pitch + x * df->BytesPerPixel;
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   748
    srcbuf = (Uint8 *) surf_src->map->data + sizeof(RLEDestFormat);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   749
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   750
    {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   751
        /* skip lines at the top if necessary */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   752
        int vskip = srcrect->y;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   753
        if (vskip) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   754
            int ofs;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   755
            if (df->BytesPerPixel == 2) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   756
                /* the 16/32 interleaved format */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   757
                do {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   758
                    /* skip opaque line */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   759
                    ofs = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   760
                    do {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   761
                        int run;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   762
                        ofs += srcbuf[0];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   763
                        run = srcbuf[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   764
                        srcbuf += 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   765
                        if (run) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   766
                            srcbuf += 2 * run;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   767
                            ofs += run;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   768
                        } else if (!ofs)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   769
                            goto done;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
   770
                    } while (ofs < w);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   771
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   772
                    /* skip padding */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   773
                    srcbuf += (uintptr_t) srcbuf & 2;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   774
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   775
                    /* skip translucent line */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   776
                    ofs = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   777
                    do {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   778
                        int run;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   779
                        ofs += ((Uint16 *) srcbuf)[0];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   780
                        run = ((Uint16 *) srcbuf)[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   781
                        srcbuf += 4 * (run + 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   782
                        ofs += run;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
   783
                    } while (ofs < w);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
   784
                } while (--vskip);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   785
            } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   786
                /* the 32/32 interleaved format */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   787
                vskip <<= 1;    /* opaque and translucent have same format */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   788
                do {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   789
                    ofs = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   790
                    do {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   791
                        int run;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   792
                        ofs += ((Uint16 *) srcbuf)[0];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   793
                        run = ((Uint16 *) srcbuf)[1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   794
                        srcbuf += 4;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   795
                        if (run) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   796
                            srcbuf += 4 * run;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   797
                            ofs += run;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   798
                        } else if (!ofs)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   799
                            goto done;
2735
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
   800
                    } while (ofs < w);
204be4fc2726 Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
   801
                } while (--vskip);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   802
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   803
        }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   804
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   805
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   806
    /* if left or right edge clipping needed, call clip blit */
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   807
    if (srcrect->x || srcrect->w != surf_src->w) {
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   808
        RLEAlphaClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   809
    } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   810
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   811
        /*
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   812
         * non-clipped blitter. Ptype is the destination pixel type,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   813
         * Ctype the translucent count type, and do_blend the
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   814
         * macro to blend one pixel.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   815
         */
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   816
#define RLEALPHABLIT(Ptype, Ctype, do_blend)                 \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   817
    do {                                 \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   818
        int linecount = srcrect->h;                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   819
        do {                             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   820
        int ofs = 0;                         \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   821
        /* blit opaque pixels on one line */             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   822
        do {                             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   823
            unsigned run;                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   824
            ofs += ((Ctype *)srcbuf)[0];             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   825
            run = ((Ctype *)srcbuf)[1];              \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   826
            srcbuf += 2 * sizeof(Ctype);             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   827
            if(run) {                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   828
            PIXEL_COPY(dstbuf + ofs * sizeof(Ptype), srcbuf, \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   829
                   run, sizeof(Ptype));          \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   830
            srcbuf += run * sizeof(Ptype);           \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   831
            ofs += run;                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   832
            } else if(!ofs)                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   833
            goto done;                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   834
        } while(ofs < w);                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   835
        /* skip padding if necessary */              \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   836
        if(sizeof(Ptype) == 2)                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   837
            srcbuf += (uintptr_t)srcbuf & 2;             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   838
        /* blit translucent pixels on the same line */       \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   839
        ofs = 0;                         \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   840
        do {                             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   841
            unsigned run;                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   842
            ofs += ((Uint16 *)srcbuf)[0];            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   843
            run = ((Uint16 *)srcbuf)[1];             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   844
            srcbuf += 4;                     \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   845
            if(run) {                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   846
            Ptype *dst = (Ptype *)dstbuf + ofs;      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   847
            unsigned i;                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   848
            for(i = 0; i < run; i++) {           \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   849
                Uint32 src = *(Uint32 *)srcbuf;      \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   850
                do_blend(src, *dst);             \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   851
                srcbuf += 4;                 \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   852
                dst++;                   \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   853
            }                        \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   854
            ofs += run;                  \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   855
            }                            \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   856
        } while(ofs < w);                    \
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   857
        dstbuf += surf_dst->pitch;                    \
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   858
        } while(--linecount);                    \
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
   859
    } while(0)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   860
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   861
        switch (df->BytesPerPixel) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   862
        case 2:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   863
            if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   864
                || df->Bmask == 0x07e0)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   865
                RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   866
            else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   867
                RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   868
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   869
        case 4:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   870
            RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   871
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   872
        }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   873
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   874
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   875
  done:
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   876
    /* Unlock the destination if necessary */
8922
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   877
    if (SDL_MUSTLOCK(surf_dst)) {
dfb6f8611ebe Fixed bug 2556 - add compilation flag -Wshadow
Sam Lantinga <slouken@libsdl.org>
parents: 8149
diff changeset
   878
        SDL_UnlockSurface(surf_dst);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   879
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   880
    return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   881
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   882
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   883
/*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   884
 * Auxiliary functions:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   885
 * The encoding functions take 32bpp rgb + a, and
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   886
 * return the number of bytes copied to the destination.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   887
 * The decoding functions copy to 32bpp rgb + a, and
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   888
 * return the number of bytes copied from the source.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   889
 * These are only used in the encoder and un-RLE code and are therefore not
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   890
 * highly optimised.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   891
 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   892
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   893
/* encode 32bpp rgb + a into 16bpp rgb, losing alpha */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   894
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   895
copy_opaque_16(void *dst, Uint32 * src, int n,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   896
               SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   897
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   898
    int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   899
    Uint16 *d = dst;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   900
    for (i = 0; i < n; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   901
        unsigned r, g, b;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   902
        RGB_FROM_PIXEL(*src, sfmt, r, g, b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   903
        PIXEL_FROM_RGB(*d, dfmt, r, g, b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   904
        src++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   905
        d++;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   906
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   907
    return n * 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   908
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   909
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   910
/* decode opaque pixels from 16bpp to 32bpp rgb + a */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   911
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   912
uncopy_opaque_16(Uint32 * dst, void *src, int n,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   913
                 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   914
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   915
    int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   916
    Uint16 *s = src;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   917
    unsigned alpha = dfmt->Amask ? 255 : 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   918
    for (i = 0; i < n; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   919
        unsigned r, g, b;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   920
        RGB_FROM_PIXEL(*s, sfmt, r, g, b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   921
        PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   922
        s++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   923
        dst++;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   924
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   925
    return n * 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   926
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   927
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   928
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   929
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   930
/* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   931
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   932
copy_transl_565(void *dst, Uint32 * src, int n,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   933
                SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   934
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   935
    int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   936
    Uint32 *d = dst;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   937
    for (i = 0; i < n; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   938
        unsigned r, g, b, a;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   939
        Uint16 pix;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   940
        RGBA_FROM_8888(*src, sfmt, r, g, b, a);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   941
        PIXEL_FROM_RGB(pix, dfmt, r, g, b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   942
        *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   943
        src++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   944
        d++;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   945
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   946
    return n * 4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   947
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   948
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   949
/* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   950
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   951
copy_transl_555(void *dst, Uint32 * src, int n,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   952
                SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   953
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   954
    int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   955
    Uint32 *d = dst;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   956
    for (i = 0; i < n; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   957
        unsigned r, g, b, a;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   958
        Uint16 pix;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   959
        RGBA_FROM_8888(*src, sfmt, r, g, b, a);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   960
        PIXEL_FROM_RGB(pix, dfmt, r, g, b);
5439
3a778c6c0269 Removed the NDS hack for ARGB1555 surfaces, since it's a general problem; added full color expansion for 16 bpp packed pixels.
Sam Lantinga <slouken@libsdl.org>
parents: 5435
diff changeset
   961
        *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   962
        src++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   963
        d++;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   964
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   965
    return n * 4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   966
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   967
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   968
/* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   969
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   970
uncopy_transl_16(Uint32 * dst, void *src, int n,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   971
                 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   972
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   973
    int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   974
    Uint32 *s = src;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   975
    for (i = 0; i < n; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   976
        unsigned r, g, b, a;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   977
        Uint32 pix = *s++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   978
        a = (pix & 0x3e0) >> 2;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   979
        pix = (pix & ~0x3e0) | pix >> 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   980
        RGB_FROM_PIXEL(pix, sfmt, r, g, b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   981
        PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   982
        dst++;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   983
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   984
    return n * 4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   985
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   986
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   987
/* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   988
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   989
copy_32(void *dst, Uint32 * src, int n,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   990
        SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   991
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   992
    int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   993
    Uint32 *d = dst;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   994
    for (i = 0; i < n; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   995
        unsigned r, g, b, a;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   996
        RGBA_FROM_8888(*src, sfmt, r, g, b, a);
9761
fd7fe355f173 Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Sam Lantinga <slouken@libsdl.org>
parents: 9619
diff changeset
   997
        RLEPIXEL_FROM_RGBA(*d, dfmt, r, g, b, a);
5631
3e1cbc6d7cad RLE: Don't trash alpha channel in copy_32().
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
   998
        d++;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
   999
        src++;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1000
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1001
    return n * 4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1002
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1003
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1004
/* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1005
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1006
uncopy_32(Uint32 * dst, void *src, int n,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1007
          RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1008
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1009
    int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1010
    Uint32 *s = src;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1011
    for (i = 0; i < n; i++) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1012
        unsigned r, g, b, a;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1013
        Uint32 pixel = *s++;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1014
        RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1015
        a = pixel >> 24;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1016
        PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1017
        dst++;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1018
    }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1019
    return n * 4;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1020
}
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1021
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1022
#define ISOPAQUE(pixel, fmt) ((((pixel) & fmt->Amask) >> fmt->Ashift) == 255)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1023
7191
75360622e65f File style cleanup for the SDL 2.0 release
Sam Lantinga <slouken@libsdl.org>
parents: 7128
diff changeset
  1024
#define ISTRANSL(pixel, fmt)    \
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1025
    ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1026
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1027
/* convert surface to be quickly alpha-blittable onto dest, if possible */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1028
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1029
RLEAlphaSurface(SDL_Surface * surface)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1030
{
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1031
    SDL_Surface *dest;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1032
    SDL_PixelFormat *df;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1033
    int maxsize = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1034
    int max_opaque_run;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1035
    int max_transl_run = 65535;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1036
    unsigned masksum;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1037
    Uint8 *rlebuf, *dst;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1038
    int (*copy_opaque) (void *, Uint32 *, int,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1039
                        SDL_PixelFormat *, SDL_PixelFormat *);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1040
    int (*copy_transl) (void *, Uint32 *, int,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1041
                        SDL_PixelFormat *, SDL_PixelFormat *);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1042
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1043
    dest = surface->map->dst;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1044
    if (!dest)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1045
        return -1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1046
    df = dest->format;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1047
    if (surface->format->BitsPerPixel != 32)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1048
        return -1;              /* only 32bpp source supported */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1049
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1050
    /* find out whether the destination is one we support,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1051
       and determine the max size of the encoded result */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1052
    masksum = df->Rmask | df->Gmask | df->Bmask;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1053
    switch (df->BytesPerPixel) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1054
    case 2:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1055
        /* 16bpp: only support 565 and 555 formats */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1056
        switch (masksum) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1057
        case 0xffff:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1058
            if (df->Gmask == 0x07e0
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1059
                || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1060
                copy_opaque = copy_opaque_16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1061
                copy_transl = copy_transl_565;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1062
            } else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1063
                return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1064
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1065
        case 0x7fff:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1066
            if (df->Gmask == 0x03e0
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1067
                || df->Rmask == 0x03e0 || df->Bmask == 0x03e0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1068
                copy_opaque = copy_opaque_16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1069
                copy_transl = copy_transl_555;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1070
            } else
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1071
                return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1072
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1073
        default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1074
            return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1075
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1076
        max_opaque_run = 255;   /* runs stored as bytes */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
  1077
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1078
        /* worst case is alternating opaque and translucent pixels,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1079
           with room for alignment padding between lines */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1456
diff changeset
  1080
        maxsize = surface->h * (2 + (4 + 2) * (surface->w + 1)) + 2;