src/video/sdlgenblit.pl
author Sam Lantinga <slouken@libsdl.org>
Mon, 28 Aug 2006 03:17:39 +0000
changeset 1985 8055185ae4ed
child 1989 5b5f5de5433f
permissions -rwxr-xr-x
Added source color and alpha modulation support.
Added perl script to generate optimized render copy functions.
slouken@1985
     1
#!/usr/bin/perl -w
slouken@1985
     2
#
slouken@1985
     3
# A script to generate optimized C blitters for Simple DirectMedia Layer
slouken@1985
     4
# http://www.libsdl.org/
slouken@1985
     5
slouken@1985
     6
use warnings;
slouken@1985
     7
use strict;
slouken@1985
     8
slouken@1985
     9
my %file;
slouken@1985
    10
slouken@1985
    11
# The formats potentially supported by this script:
slouken@1985
    12
# SDL_PIXELFORMAT_INDEX8
slouken@1985
    13
# SDL_PIXELFORMAT_RGB332
slouken@1985
    14
# SDL_PIXELFORMAT_RGB444
slouken@1985
    15
# SDL_PIXELFORMAT_RGB555
slouken@1985
    16
# SDL_PIXELFORMAT_ARGB4444
slouken@1985
    17
# SDL_PIXELFORMAT_ARGB1555
slouken@1985
    18
# SDL_PIXELFORMAT_RGB565
slouken@1985
    19
# SDL_PIXELFORMAT_RGB24
slouken@1985
    20
# SDL_PIXELFORMAT_BGR24
slouken@1985
    21
# SDL_PIXELFORMAT_RGB888
slouken@1985
    22
# SDL_PIXELFORMAT_BGR888
slouken@1985
    23
# SDL_PIXELFORMAT_ARGB8888
slouken@1985
    24
# SDL_PIXELFORMAT_RGBA8888
slouken@1985
    25
# SDL_PIXELFORMAT_ABGR8888
slouken@1985
    26
# SDL_PIXELFORMAT_BGRA8888
slouken@1985
    27
# SDL_PIXELFORMAT_ARGB2101010
slouken@1985
    28
slouken@1985
    29
# The formats we're actually creating blitters for:
slouken@1985
    30
my @src_formats = (
slouken@1985
    31
    "RGB888",
slouken@1985
    32
    "BGR888",
slouken@1985
    33
    "ARGB8888",
slouken@1985
    34
    "RGBA8888",
slouken@1985
    35
    "ABGR8888",
slouken@1985
    36
    "BGRA8888",
slouken@1985
    37
);
slouken@1985
    38
my @dst_formats = (
slouken@1985
    39
    "RGB888",
slouken@1985
    40
    "BGR888",
slouken@1985
    41
);
slouken@1985
    42
slouken@1985
    43
my %format_size = (
slouken@1985
    44
    "RGB888" => 4,
slouken@1985
    45
    "BGR888" => 4,
slouken@1985
    46
    "ARGB8888" => 4,
slouken@1985
    47
    "RGBA8888" => 4,
slouken@1985
    48
    "ABGR8888" => 4,
slouken@1985
    49
    "BGRA8888" => 4,
slouken@1985
    50
);
slouken@1985
    51
slouken@1985
    52
my %format_type = (
slouken@1985
    53
    "RGB888" => "Uint32",
slouken@1985
    54
    "BGR888" => "Uint32",
slouken@1985
    55
    "ARGB8888" => "Uint32",
slouken@1985
    56
    "RGBA8888" => "Uint32",
slouken@1985
    57
    "ABGR8888" => "Uint32",
slouken@1985
    58
    "BGRA8888" => "Uint32",
slouken@1985
    59
);
slouken@1985
    60
slouken@1985
    61
my %get_rgba_string = (
slouken@1985
    62
    "RGB888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel; _A = 0xFF;",
slouken@1985
    63
    "BGR888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel; _A = 0xFF;",
slouken@1985
    64
    "ARGB8888" => "_A = (Uint8)(_pixel >> 24); _R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
slouken@1985
    65
    "RGBA8888" => "_R = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _B = (Uint8)(_pixel >> 8); _A = (Uint8)_pixel;",
slouken@1985
    66
    "ABGR8888" => "_A = (Uint8)(_pixel >> 24); _B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
slouken@1985
    67
    "BGRA8888" => "_B = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _R = (Uint8)(_pixel >> 8); _A = (Uint8)_pixel;",
slouken@1985
    68
);
slouken@1985
    69
slouken@1985
    70
my %set_rgba_string = (
slouken@1985
    71
    "RGB888" => "_pixel = ((Uint32)_R << 16) | ((Uint32)_G << 8) | _B;",
slouken@1985
    72
    "BGR888" => "_pixel = ((Uint32)_B << 16) | ((Uint32)_G << 8) | _R;",
slouken@1985
    73
);
slouken@1985
    74
slouken@1985
    75
sub open_file {
slouken@1985
    76
    my $name = shift;
slouken@1985
    77
    open(FILE, ">$name.new") || die "Cant' open $name.new: $!";
slouken@1985
    78
    print FILE <<__EOF__;
slouken@1985
    79
/* DO NOT EDIT!  This file is generated by sdlgenblit.pl */
slouken@1985
    80
/*
slouken@1985
    81
    SDL - Simple DirectMedia Layer
slouken@1985
    82
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1985
    83
slouken@1985
    84
    This library is free software; you can redistribute it and/or
slouken@1985
    85
    modify it under the terms of the GNU Lesser General Public
slouken@1985
    86
    License as published by the Free Software Foundation; either
slouken@1985
    87
    version 2.1 of the License, or (at your option) any later version.
slouken@1985
    88
slouken@1985
    89
    This library is distributed in the hope that it will be useful,
slouken@1985
    90
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1985
    91
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1985
    92
    Lesser General Public License for more details.
slouken@1985
    93
slouken@1985
    94
    You should have received a copy of the GNU Lesser General Public
slouken@1985
    95
    License along with this library; if not, write to the Free Software
slouken@1985
    96
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1985
    97
slouken@1985
    98
    Sam Lantinga
slouken@1985
    99
    slouken\@libsdl.org
slouken@1985
   100
*/
slouken@1985
   101
#include "SDL_config.h"
slouken@1985
   102
slouken@1985
   103
/* *INDENT-OFF* */
slouken@1985
   104
slouken@1985
   105
__EOF__
slouken@1985
   106
}
slouken@1985
   107
slouken@1985
   108
sub close_file {
slouken@1985
   109
    my $name = shift;
slouken@1985
   110
    print FILE <<__EOF__;
slouken@1985
   111
/* *INDENT-ON* */
slouken@1985
   112
slouken@1985
   113
/* vi: set ts=4 sw=4 expandtab: */
slouken@1985
   114
__EOF__
slouken@1985
   115
    close FILE;
slouken@1985
   116
    if ( ! -f $name || system("cmp -s $name $name.new") != 0 ) {
slouken@1985
   117
        rename("$name.new", "$name");
slouken@1985
   118
    } else {
slouken@1985
   119
        unlink("$name.new");
slouken@1985
   120
    }
slouken@1985
   121
}
slouken@1985
   122
slouken@1985
   123
sub output_copydefs
slouken@1985
   124
{
slouken@1985
   125
    print FILE <<__EOF__;
slouken@1985
   126
#define SDL_RENDERCOPY_MODULATE_COLOR   0x0001
slouken@1985
   127
#define SDL_RENDERCOPY_MODULATE_ALPHA   0x0002
slouken@1985
   128
#define SDL_RENDERCOPY_BLEND            0x0010
slouken@1985
   129
#define SDL_RENDERCOPY_ADD              0x0020
slouken@1985
   130
#define SDL_RENDERCOPY_MOD              0x0040
slouken@1985
   131
#define SDL_RENDERCOPY_NEAREST          0x0100
slouken@1985
   132
slouken@1985
   133
typedef struct {
slouken@1985
   134
    void *src;
slouken@1985
   135
    int src_w, src_h;
slouken@1985
   136
    int src_pitch;
slouken@1985
   137
    void *dst;
slouken@1985
   138
    int dst_w, dst_h;
slouken@1985
   139
    int dst_pitch;
slouken@1985
   140
    void *aux_data;
slouken@1985
   141
    int flags;
slouken@1985
   142
    Uint8 r, g, b, a;
slouken@1985
   143
} SDL_RenderCopyData;
slouken@1985
   144
slouken@1985
   145
typedef int (*SDL_RenderCopyFunc)(SDL_RenderCopyData *data);
slouken@1985
   146
slouken@1985
   147
extern SDL_RenderCopyFunc SDLCALL SDL_GetRenderCopyFunc(Uint32 src_format, Uint32 dst_format, int modMode, int blendMode, int scaleMode);
slouken@1985
   148
slouken@1985
   149
__EOF__
slouken@1985
   150
}
slouken@1985
   151
slouken@1985
   152
sub output_copyfuncname
slouken@1985
   153
{
slouken@1985
   154
    my $prefix = shift;
slouken@1985
   155
    my $src = shift;
slouken@1985
   156
    my $dst = shift;
slouken@1985
   157
    my $modulate = shift;
slouken@1985
   158
    my $blend = shift;
slouken@1985
   159
    my $scale = shift;
slouken@1985
   160
    my $args = shift;
slouken@1985
   161
    my $suffix = shift;
slouken@1985
   162
slouken@1985
   163
    print FILE "$prefix SDL_RenderCopy_${src}_${dst}";
slouken@1985
   164
    if ( $modulate ) {
slouken@1985
   165
        print FILE "_Modulate";
slouken@1985
   166
    }
slouken@1985
   167
    if ( $blend ) {
slouken@1985
   168
        print FILE "_Blend";
slouken@1985
   169
    }
slouken@1985
   170
    if ( $scale ) {
slouken@1985
   171
        print FILE "_Scale";
slouken@1985
   172
    }
slouken@1985
   173
    if ( $args ) {
slouken@1985
   174
        print FILE "(SDL_RenderCopyData *data)";
slouken@1985
   175
    }
slouken@1985
   176
    print FILE "$suffix";
slouken@1985
   177
}
slouken@1985
   178
slouken@1985
   179
sub get_rgba
slouken@1985
   180
{
slouken@1985
   181
    my $prefix = shift;
slouken@1985
   182
    my $format = shift;
slouken@1985
   183
    my $string = $get_rgba_string{$format};
slouken@1985
   184
    $string =~ s/_/$prefix/g;
slouken@1985
   185
    if ( $prefix ne "" ) {
slouken@1985
   186
        print FILE <<__EOF__;
slouken@1985
   187
            ${prefix}pixel = *$prefix;
slouken@1985
   188
__EOF__
slouken@1985
   189
    } else {
slouken@1985
   190
        print FILE <<__EOF__;
slouken@1985
   191
            pixel = *src;
slouken@1985
   192
__EOF__
slouken@1985
   193
    }
slouken@1985
   194
    print FILE <<__EOF__;
slouken@1985
   195
            $string
slouken@1985
   196
__EOF__
slouken@1985
   197
}
slouken@1985
   198
slouken@1985
   199
sub set_rgba
slouken@1985
   200
{
slouken@1985
   201
    my $prefix = shift;
slouken@1985
   202
    my $format = shift;
slouken@1985
   203
    my $string = $set_rgba_string{$format};
slouken@1985
   204
    $string =~ s/_/$prefix/g;
slouken@1985
   205
    print FILE <<__EOF__;
slouken@1985
   206
            $string
slouken@1985
   207
            *dst = ${prefix}pixel;
slouken@1985
   208
__EOF__
slouken@1985
   209
}
slouken@1985
   210
slouken@1985
   211
sub output_copycore
slouken@1985
   212
{
slouken@1985
   213
    my $src = shift;
slouken@1985
   214
    my $dst = shift;
slouken@1985
   215
    my $modulate = shift;
slouken@1985
   216
    my $blend = shift;
slouken@1985
   217
    if ( $modulate ) {
slouken@1985
   218
        print FILE <<__EOF__;
slouken@1985
   219
            if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
slouken@1985
   220
                ${src}R = (${src}R * modulateR) / 255;
slouken@1985
   221
                ${src}G = (${src}G * modulateG) / 255;
slouken@1985
   222
                ${src}B = (${src}B * modulateB) / 255;
slouken@1985
   223
            }
slouken@1985
   224
__EOF__
slouken@1985
   225
    }
slouken@1985
   226
    if ( $modulate && $blend ) {
slouken@1985
   227
        print FILE <<__EOF__;
slouken@1985
   228
            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
slouken@1985
   229
                ${src}A = (${src}A * modulateA) / 255;
slouken@1985
   230
            }
slouken@1985
   231
__EOF__
slouken@1985
   232
    }
slouken@1985
   233
    if ( $blend ) {
slouken@1985
   234
        print FILE <<__EOF__;
slouken@1985
   235
            if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
slouken@1985
   236
                /* This goes away if we ever use premultiplied alpha */
slouken@1985
   237
                ${src}R = (${src}R * ${src}A) / 255;
slouken@1985
   238
                ${src}G = (${src}G * ${src}A) / 255;
slouken@1985
   239
                ${src}B = (${src}B * ${src}A) / 255;
slouken@1985
   240
            }
slouken@1985
   241
            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
slouken@1985
   242
            case SDL_RENDERCOPY_BLEND:
slouken@1985
   243
                ${dst}R = ${src}R + ((255 - ${src}A) * ${dst}R) / 255;
slouken@1985
   244
                ${dst}G = ${src}G + ((255 - ${src}A) * ${dst}G) / 255;
slouken@1985
   245
                ${dst}B = ${src}B + ((255 - ${src}A) * ${dst}B) / 255;
slouken@1985
   246
                break;
slouken@1985
   247
            case SDL_RENDERCOPY_ADD:
slouken@1985
   248
                ${dst}R = ${src}R + ${dst}R; if (${dst}R > 255) ${dst}R = 255;
slouken@1985
   249
                ${dst}G = ${src}G + ${dst}G; if (${dst}G > 255) ${dst}G = 255;
slouken@1985
   250
                ${dst}B = ${src}B + ${dst}B; if (${dst}B > 255) ${dst}B = 255;
slouken@1985
   251
                break;
slouken@1985
   252
            case SDL_RENDERCOPY_MOD:
slouken@1985
   253
                ${dst}R = (${src}R * ${dst}R) / 255;
slouken@1985
   254
                ${dst}G = (${src}G * ${dst}G) / 255;
slouken@1985
   255
                ${dst}B = (${src}B * ${dst}B) / 255;
slouken@1985
   256
                break;
slouken@1985
   257
            }
slouken@1985
   258
__EOF__
slouken@1985
   259
    }
slouken@1985
   260
}
slouken@1985
   261
slouken@1985
   262
sub output_copyfunc
slouken@1985
   263
{
slouken@1985
   264
    my $src = shift;
slouken@1985
   265
    my $dst = shift;
slouken@1985
   266
    my $modulate = shift;
slouken@1985
   267
    my $blend = shift;
slouken@1985
   268
    my $scale = shift;
slouken@1985
   269
slouken@1985
   270
    output_copyfuncname("int", $src, $dst, $modulate, $blend, $scale, 1, "\n");
slouken@1985
   271
    print FILE <<__EOF__;
slouken@1985
   272
{
slouken@1985
   273
    const int flags = data->flags;
slouken@1985
   274
__EOF__
slouken@1985
   275
    if ( $modulate ) {
slouken@1985
   276
        print FILE <<__EOF__;
slouken@1985
   277
    const Uint32 modulateR = data->r;
slouken@1985
   278
    const Uint32 modulateG = data->g;
slouken@1985
   279
    const Uint32 modulateB = data->b;
slouken@1985
   280
    const Uint32 modulateA = data->a;
slouken@1985
   281
__EOF__
slouken@1985
   282
    }
slouken@1985
   283
    if ( $blend ) {
slouken@1985
   284
        print FILE <<__EOF__;
slouken@1985
   285
    Uint32 srcpixel;
slouken@1985
   286
    Uint32 srcR, srcG, srcB, srcA;
slouken@1985
   287
    Uint32 dstpixel;
slouken@1985
   288
    Uint32 dstR, dstG, dstB, dstA;
slouken@1985
   289
__EOF__
slouken@1985
   290
    } elsif ( $modulate || $src ne $dst ) {
slouken@1985
   291
        print FILE <<__EOF__;
slouken@1985
   292
    Uint32 pixel;
slouken@1985
   293
    Uint32 R, G, B, A;
slouken@1985
   294
__EOF__
slouken@1985
   295
    }
slouken@1985
   296
    if ( $scale ) {
slouken@1985
   297
        print FILE <<__EOF__;
slouken@1985
   298
    int srcy, srcx;
slouken@1985
   299
    int posy, posx;
slouken@1985
   300
    int incy, incx;
slouken@1985
   301
slouken@1985
   302
    srcy = 0;
slouken@1985
   303
    posy = 0;
slouken@1985
   304
    incy = (data->src_h << 16) / data->dst_h;
slouken@1985
   305
    incx = (data->src_w << 16) / data->dst_w;
slouken@1985
   306
slouken@1985
   307
    while (data->dst_h--) {
slouken@1985
   308
        $format_type{$src} *src;
slouken@1985
   309
        $format_type{$dst} *dst = ($format_type{$dst} *)data->dst;
slouken@1985
   310
        int n = data->dst_w;
slouken@1985
   311
        srcx = -1;
slouken@1985
   312
        posx = 0x10000L;
slouken@1985
   313
        while (posy >= 0x10000L) {
slouken@1985
   314
            ++srcy;
slouken@1985
   315
            posy -= 0x10000L;
slouken@1985
   316
        }
slouken@1985
   317
        while (n--) {
slouken@1985
   318
            if (posx >= 0x10000L) {
slouken@1985
   319
                while (posx >= 0x10000L) {
slouken@1985
   320
                    ++srcx;
slouken@1985
   321
                    posx -= 0x10000L;
slouken@1985
   322
                }
slouken@1985
   323
                src = ($format_type{$src} *)(data->src + (srcy * data->src_pitch) + (srcx * $format_size{$src}));
slouken@1985
   324
__EOF__
slouken@1985
   325
        print FILE <<__EOF__;
slouken@1985
   326
            }
slouken@1985
   327
__EOF__
slouken@1985
   328
        if ( $blend ) {
slouken@1985
   329
            get_rgba("src", $src);
slouken@1985
   330
            get_rgba("dst", $dst);
slouken@1985
   331
            output_copycore("src", "dst", $modulate, $blend);
slouken@1985
   332
            set_rgba("dst", $dst);
slouken@1985
   333
        } elsif ( $modulate || $src ne $dst ) {
slouken@1985
   334
            get_rgba("", $src);
slouken@1985
   335
            output_copycore("", "", $modulate, $blend);
slouken@1985
   336
            set_rgba("", $dst);
slouken@1985
   337
        } else {
slouken@1985
   338
            print FILE <<__EOF__;
slouken@1985
   339
            *dst = *src;
slouken@1985
   340
__EOF__
slouken@1985
   341
        }
slouken@1985
   342
        print FILE <<__EOF__;
slouken@1985
   343
            posx += incx;
slouken@1985
   344
            ++dst;
slouken@1985
   345
        }
slouken@1985
   346
        posy += incy;
slouken@1985
   347
        data->dst += data->dst_pitch;
slouken@1985
   348
    }
slouken@1985
   349
__EOF__
slouken@1985
   350
    } else {
slouken@1985
   351
        print FILE <<__EOF__;
slouken@1985
   352
slouken@1985
   353
    while (data->dst_h--) {
slouken@1985
   354
        $format_type{$src} *src = ($format_type{$src} *)data->src;
slouken@1985
   355
        $format_type{$dst} *dst = ($format_type{$dst} *)data->dst;
slouken@1985
   356
        int n = data->dst_w;
slouken@1985
   357
        while (n--) {
slouken@1985
   358
__EOF__
slouken@1985
   359
        if ( $blend ) {
slouken@1985
   360
            get_rgba("src", $src);
slouken@1985
   361
            get_rgba("dst", $dst);
slouken@1985
   362
            output_copycore("src", "dst", $modulate, $blend);
slouken@1985
   363
            set_rgba("dst", $dst);
slouken@1985
   364
        } elsif ( $modulate || $src ne $dst ) {
slouken@1985
   365
            get_rgba("", $src);
slouken@1985
   366
            output_copycore("", "", $modulate, $blend);
slouken@1985
   367
            set_rgba("", $dst);
slouken@1985
   368
        } else {
slouken@1985
   369
            print FILE <<__EOF__;
slouken@1985
   370
            *dst = *src;
slouken@1985
   371
__EOF__
slouken@1985
   372
        }
slouken@1985
   373
        print FILE <<__EOF__;
slouken@1985
   374
            ++src;
slouken@1985
   375
            ++dst;
slouken@1985
   376
        }
slouken@1985
   377
        data->src += data->src_pitch;
slouken@1985
   378
        data->dst += data->dst_pitch;
slouken@1985
   379
    }
slouken@1985
   380
__EOF__
slouken@1985
   381
    }
slouken@1985
   382
    print FILE <<__EOF__;
slouken@1985
   383
    return 0;
slouken@1985
   384
}
slouken@1985
   385
slouken@1985
   386
__EOF__
slouken@1985
   387
}
slouken@1985
   388
slouken@1985
   389
sub output_copyfunc_h
slouken@1985
   390
{
slouken@1985
   391
    my $src = shift;
slouken@1985
   392
    my $dst = shift;
slouken@1985
   393
    for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   394
        for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   395
            for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1985
   396
                if ( $modulate != 0 || $blend != 0 || $scale != 0 || $src ne $dst ) {
slouken@1985
   397
                    output_copyfuncname("extern int SDLCALL", $src, $dst, $modulate, $blend, $scale, 1, ";\n");
slouken@1985
   398
                }
slouken@1985
   399
            }
slouken@1985
   400
        }
slouken@1985
   401
    }
slouken@1985
   402
}
slouken@1985
   403
slouken@1985
   404
sub output_copyinc
slouken@1985
   405
{
slouken@1985
   406
    print FILE <<__EOF__;
slouken@1985
   407
#include "SDL_video.h"
slouken@1985
   408
#include "SDL_rendercopy.h"
slouken@1985
   409
slouken@1985
   410
__EOF__
slouken@1985
   411
}
slouken@1985
   412
slouken@1985
   413
sub output_copyfunctable
slouken@1985
   414
{
slouken@1985
   415
    print FILE <<__EOF__;
slouken@1985
   416
static struct {
slouken@1985
   417
    Uint32 src_format;
slouken@1985
   418
    Uint32 dst_format;
slouken@1985
   419
    int modMode;
slouken@1985
   420
    int blendMode;
slouken@1985
   421
    int scaleMode;
slouken@1985
   422
    SDL_RenderCopyFunc func;
slouken@1985
   423
} SDL_RenderCopyFuncTable[] = {
slouken@1985
   424
__EOF__
slouken@1985
   425
    for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   426
        my $src = $src_formats[$i];
slouken@1985
   427
        for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   428
            my $dst = $dst_formats[$j];
slouken@1985
   429
            for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   430
                for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   431
                    for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1985
   432
                        if ( $modulate != 0 || $blend != 0 || $scale != 0 || $src ne $dst ) {
slouken@1985
   433
                            print FILE "    { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, ";
slouken@1985
   434
                            if ( $modulate ) {
slouken@1985
   435
                                print FILE "(SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), ";
slouken@1985
   436
                            } else {
slouken@1985
   437
                                print FILE "0, ";
slouken@1985
   438
                            }
slouken@1985
   439
                            if ( $blend ) {
slouken@1985
   440
                                print FILE "(SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), ";
slouken@1985
   441
                            } else {
slouken@1985
   442
                                print FILE "0, ";
slouken@1985
   443
                            }
slouken@1985
   444
                            if ( $scale ) {
slouken@1985
   445
                                print FILE "SDL_TEXTURESCALEMODE_FAST, ";
slouken@1985
   446
                            } else {
slouken@1985
   447
                                print FILE "0, ";
slouken@1985
   448
                            }
slouken@1985
   449
                            output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n");
slouken@1985
   450
                        }
slouken@1985
   451
                    }
slouken@1985
   452
                }
slouken@1985
   453
            }
slouken@1985
   454
        }
slouken@1985
   455
    }
slouken@1985
   456
    print FILE <<__EOF__;
slouken@1985
   457
};
slouken@1985
   458
slouken@1985
   459
SDL_RenderCopyFunc SDL_GetRenderCopyFunc(Uint32 src_format, Uint32 dst_format, int modMode, int blendMode, int scaleMode)
slouken@1985
   460
{
slouken@1985
   461
    int i;
slouken@1985
   462
slouken@1985
   463
    for (i = 0; i < SDL_arraysize(SDL_RenderCopyFuncTable); ++i) {
slouken@1985
   464
        if (src_format != SDL_RenderCopyFuncTable[i].src_format) {
slouken@1985
   465
            continue;
slouken@1985
   466
        }
slouken@1985
   467
        if (dst_format != SDL_RenderCopyFuncTable[i].dst_format) {
slouken@1985
   468
            continue;
slouken@1985
   469
        }
slouken@1985
   470
        if ((modMode & SDL_RenderCopyFuncTable[i].modMode) != modMode) {
slouken@1985
   471
            continue;
slouken@1985
   472
        }
slouken@1985
   473
        if ((blendMode & SDL_RenderCopyFuncTable[i].blendMode) != blendMode) {
slouken@1985
   474
            continue;
slouken@1985
   475
        }
slouken@1985
   476
        if ((scaleMode & SDL_RenderCopyFuncTable[i].scaleMode) != scaleMode) {
slouken@1985
   477
            continue;
slouken@1985
   478
        }
slouken@1985
   479
        return SDL_RenderCopyFuncTable[i].func;
slouken@1985
   480
    }
slouken@1985
   481
    return NULL;
slouken@1985
   482
}
slouken@1985
   483
slouken@1985
   484
__EOF__
slouken@1985
   485
}
slouken@1985
   486
slouken@1985
   487
sub output_copyfunc_c
slouken@1985
   488
{
slouken@1985
   489
    my $src = shift;
slouken@1985
   490
    my $dst = shift;
slouken@1985
   491
slouken@1985
   492
    for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   493
        for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   494
            for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1985
   495
                if ( $modulate != 0 || $blend != 0 || $scale != 0 || $src ne $dst ) {
slouken@1985
   496
                    output_copyfunc($src, $dst, $modulate, $blend, $scale);
slouken@1985
   497
                }
slouken@1985
   498
            }
slouken@1985
   499
        }
slouken@1985
   500
    }
slouken@1985
   501
}
slouken@1985
   502
slouken@1985
   503
open_file("SDL_rendercopy.h");
slouken@1985
   504
output_copydefs();
slouken@1985
   505
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   506
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   507
        output_copyfunc_h($src_formats[$i], $dst_formats[$j]);
slouken@1985
   508
    }
slouken@1985
   509
}
slouken@1985
   510
print FILE "\n";
slouken@1985
   511
close_file("SDL_rendercopy.h");
slouken@1985
   512
slouken@1985
   513
open_file("SDL_rendercopy.c");
slouken@1985
   514
output_copyinc();
slouken@1985
   515
output_copyfunctable();
slouken@1985
   516
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   517
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   518
        output_copyfunc_c($src_formats[$i], $dst_formats[$j]);
slouken@1985
   519
    }
slouken@1985
   520
}
slouken@1985
   521
close_file("SDL_rendercopy.c");