src/video/sdlgenblit.pl
author Sam Lantinga <slouken@libsdl.org>
Tue, 29 Aug 2006 08:24:16 +0000
changeset 1992 7387e0514595
parent 1989 5b5f5de5433f
child 2262 bee005ace1bf
permissions -rwxr-xr-x
Take advantage of the existing SDL blitters for normal copy blits.
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@1989
   128
#define SDL_RENDERCOPY_MASK             0x0010
slouken@1989
   129
#define SDL_RENDERCOPY_BLEND            0x0020
slouken@1989
   130
#define SDL_RENDERCOPY_ADD              0x0040
slouken@1989
   131
#define SDL_RENDERCOPY_MOD              0x0080
slouken@1985
   132
#define SDL_RENDERCOPY_NEAREST          0x0100
slouken@1985
   133
slouken@1985
   134
typedef struct {
slouken@1985
   135
    void *src;
slouken@1985
   136
    int src_w, src_h;
slouken@1985
   137
    int src_pitch;
slouken@1985
   138
    void *dst;
slouken@1985
   139
    int dst_w, dst_h;
slouken@1985
   140
    int dst_pitch;
slouken@1985
   141
    void *aux_data;
slouken@1985
   142
    int flags;
slouken@1985
   143
    Uint8 r, g, b, a;
slouken@1985
   144
} SDL_RenderCopyData;
slouken@1985
   145
slouken@1985
   146
typedef int (*SDL_RenderCopyFunc)(SDL_RenderCopyData *data);
slouken@1985
   147
slouken@1985
   148
extern SDL_RenderCopyFunc SDLCALL SDL_GetRenderCopyFunc(Uint32 src_format, Uint32 dst_format, int modMode, int blendMode, int scaleMode);
slouken@1985
   149
slouken@1985
   150
__EOF__
slouken@1985
   151
}
slouken@1985
   152
slouken@1985
   153
sub output_copyfuncname
slouken@1985
   154
{
slouken@1985
   155
    my $prefix = shift;
slouken@1985
   156
    my $src = shift;
slouken@1985
   157
    my $dst = shift;
slouken@1985
   158
    my $modulate = shift;
slouken@1985
   159
    my $blend = shift;
slouken@1985
   160
    my $scale = shift;
slouken@1985
   161
    my $args = shift;
slouken@1985
   162
    my $suffix = shift;
slouken@1985
   163
slouken@1985
   164
    print FILE "$prefix SDL_RenderCopy_${src}_${dst}";
slouken@1985
   165
    if ( $modulate ) {
slouken@1985
   166
        print FILE "_Modulate";
slouken@1985
   167
    }
slouken@1985
   168
    if ( $blend ) {
slouken@1985
   169
        print FILE "_Blend";
slouken@1985
   170
    }
slouken@1985
   171
    if ( $scale ) {
slouken@1985
   172
        print FILE "_Scale";
slouken@1985
   173
    }
slouken@1985
   174
    if ( $args ) {
slouken@1985
   175
        print FILE "(SDL_RenderCopyData *data)";
slouken@1985
   176
    }
slouken@1985
   177
    print FILE "$suffix";
slouken@1985
   178
}
slouken@1985
   179
slouken@1985
   180
sub get_rgba
slouken@1985
   181
{
slouken@1985
   182
    my $prefix = shift;
slouken@1985
   183
    my $format = shift;
slouken@1985
   184
    my $string = $get_rgba_string{$format};
slouken@1985
   185
    $string =~ s/_/$prefix/g;
slouken@1985
   186
    if ( $prefix ne "" ) {
slouken@1985
   187
        print FILE <<__EOF__;
slouken@1985
   188
            ${prefix}pixel = *$prefix;
slouken@1985
   189
__EOF__
slouken@1985
   190
    } else {
slouken@1985
   191
        print FILE <<__EOF__;
slouken@1985
   192
            pixel = *src;
slouken@1985
   193
__EOF__
slouken@1985
   194
    }
slouken@1985
   195
    print FILE <<__EOF__;
slouken@1985
   196
            $string
slouken@1985
   197
__EOF__
slouken@1985
   198
}
slouken@1985
   199
slouken@1985
   200
sub set_rgba
slouken@1985
   201
{
slouken@1985
   202
    my $prefix = shift;
slouken@1985
   203
    my $format = shift;
slouken@1985
   204
    my $string = $set_rgba_string{$format};
slouken@1985
   205
    $string =~ s/_/$prefix/g;
slouken@1985
   206
    print FILE <<__EOF__;
slouken@1985
   207
            $string
slouken@1985
   208
            *dst = ${prefix}pixel;
slouken@1985
   209
__EOF__
slouken@1985
   210
}
slouken@1985
   211
slouken@1985
   212
sub output_copycore
slouken@1985
   213
{
slouken@1985
   214
    my $src = shift;
slouken@1985
   215
    my $dst = shift;
slouken@1985
   216
    my $modulate = shift;
slouken@1985
   217
    my $blend = shift;
slouken@1989
   218
    my $s = "";
slouken@1989
   219
    my $d = "";
slouken@1989
   220
slouken@1989
   221
    # Nice and easy...
slouken@1989
   222
    if ( $src eq $dst && !$modulate && !$blend ) {
slouken@1989
   223
        print FILE <<__EOF__;
slouken@1989
   224
            *dst = *src;
slouken@1989
   225
__EOF__
slouken@1989
   226
        return;
slouken@1989
   227
    }
slouken@1989
   228
        
slouken@1989
   229
    if ( $blend ) {
slouken@1989
   230
        get_rgba("src", $src);
slouken@1989
   231
        get_rgba("dst", $dst);
slouken@1989
   232
        $s = "src";
slouken@1989
   233
        $d = "dst";
slouken@1989
   234
    } else {
slouken@1989
   235
        get_rgba("", $src);
slouken@1989
   236
    }
slouken@1989
   237
slouken@1985
   238
    if ( $modulate ) {
slouken@1985
   239
        print FILE <<__EOF__;
slouken@1985
   240
            if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
slouken@1989
   241
                ${s}R = (${s}R * modulateR) / 255;
slouken@1989
   242
                ${s}G = (${s}G * modulateG) / 255;
slouken@1989
   243
                ${s}B = (${s}B * modulateB) / 255;
slouken@1985
   244
            }
slouken@1985
   245
            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
slouken@1989
   246
                ${s}A = (${s}A * modulateA) / 255;
slouken@1985
   247
            }
slouken@1985
   248
__EOF__
slouken@1985
   249
    }
slouken@1985
   250
    if ( $blend ) {
slouken@1985
   251
        print FILE <<__EOF__;
slouken@1985
   252
            if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
slouken@1985
   253
                /* This goes away if we ever use premultiplied alpha */
slouken@1989
   254
                if (${s}A < 255) {
slouken@1989
   255
                    ${s}R = (${s}R * ${s}A) / 255;
slouken@1989
   256
                    ${s}G = (${s}G * ${s}A) / 255;
slouken@1989
   257
                    ${s}B = (${s}B * ${s}A) / 255;
slouken@1989
   258
                }
slouken@1985
   259
            }
slouken@1989
   260
            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
slouken@1989
   261
            case SDL_RENDERCOPY_MASK:
slouken@1989
   262
                if (${s}A) {
slouken@1989
   263
                    ${d}R = ${s}R;
slouken@1989
   264
                    ${d}G = ${s}G;
slouken@1989
   265
                    ${d}B = ${s}B;
slouken@1989
   266
                }
slouken@1989
   267
                break;
slouken@1985
   268
            case SDL_RENDERCOPY_BLEND:
slouken@1989
   269
                ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255;
slouken@1989
   270
                ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255;
slouken@1989
   271
                ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255;
slouken@1985
   272
                break;
slouken@1985
   273
            case SDL_RENDERCOPY_ADD:
slouken@1989
   274
                ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
slouken@1989
   275
                ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255;
slouken@1989
   276
                ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255;
slouken@1985
   277
                break;
slouken@1985
   278
            case SDL_RENDERCOPY_MOD:
slouken@1989
   279
                ${d}R = (${s}R * ${d}R) / 255;
slouken@1989
   280
                ${d}G = (${s}G * ${d}G) / 255;
slouken@1989
   281
                ${d}B = (${s}B * ${d}B) / 255;
slouken@1985
   282
                break;
slouken@1985
   283
            }
slouken@1985
   284
__EOF__
slouken@1985
   285
    }
slouken@1989
   286
    if ( $blend ) {
slouken@1989
   287
        set_rgba("dst", $dst);
slouken@1989
   288
    } else {
slouken@1989
   289
        set_rgba("", $dst);
slouken@1989
   290
    }
slouken@1985
   291
}
slouken@1985
   292
slouken@1985
   293
sub output_copyfunc
slouken@1985
   294
{
slouken@1985
   295
    my $src = shift;
slouken@1985
   296
    my $dst = shift;
slouken@1985
   297
    my $modulate = shift;
slouken@1985
   298
    my $blend = shift;
slouken@1985
   299
    my $scale = shift;
slouken@1985
   300
slouken@1985
   301
    output_copyfuncname("int", $src, $dst, $modulate, $blend, $scale, 1, "\n");
slouken@1985
   302
    print FILE <<__EOF__;
slouken@1985
   303
{
slouken@1985
   304
    const int flags = data->flags;
slouken@1985
   305
__EOF__
slouken@1985
   306
    if ( $modulate ) {
slouken@1985
   307
        print FILE <<__EOF__;
slouken@1985
   308
    const Uint32 modulateR = data->r;
slouken@1985
   309
    const Uint32 modulateG = data->g;
slouken@1985
   310
    const Uint32 modulateB = data->b;
slouken@1985
   311
    const Uint32 modulateA = data->a;
slouken@1985
   312
__EOF__
slouken@1985
   313
    }
slouken@1985
   314
    if ( $blend ) {
slouken@1985
   315
        print FILE <<__EOF__;
slouken@1985
   316
    Uint32 srcpixel;
slouken@1985
   317
    Uint32 srcR, srcG, srcB, srcA;
slouken@1985
   318
    Uint32 dstpixel;
slouken@1985
   319
    Uint32 dstR, dstG, dstB, dstA;
slouken@1985
   320
__EOF__
slouken@1985
   321
    } elsif ( $modulate || $src ne $dst ) {
slouken@1985
   322
        print FILE <<__EOF__;
slouken@1985
   323
    Uint32 pixel;
slouken@1985
   324
    Uint32 R, G, B, A;
slouken@1985
   325
__EOF__
slouken@1985
   326
    }
slouken@1985
   327
    if ( $scale ) {
slouken@1985
   328
        print FILE <<__EOF__;
slouken@1985
   329
    int srcy, srcx;
slouken@1985
   330
    int posy, posx;
slouken@1985
   331
    int incy, incx;
slouken@1985
   332
slouken@1985
   333
    srcy = 0;
slouken@1985
   334
    posy = 0;
slouken@1985
   335
    incy = (data->src_h << 16) / data->dst_h;
slouken@1985
   336
    incx = (data->src_w << 16) / data->dst_w;
slouken@1985
   337
slouken@1985
   338
    while (data->dst_h--) {
slouken@1985
   339
        $format_type{$src} *src;
slouken@1985
   340
        $format_type{$dst} *dst = ($format_type{$dst} *)data->dst;
slouken@1985
   341
        int n = data->dst_w;
slouken@1985
   342
        srcx = -1;
slouken@1985
   343
        posx = 0x10000L;
slouken@1985
   344
        while (posy >= 0x10000L) {
slouken@1985
   345
            ++srcy;
slouken@1985
   346
            posy -= 0x10000L;
slouken@1985
   347
        }
slouken@1985
   348
        while (n--) {
slouken@1985
   349
            if (posx >= 0x10000L) {
slouken@1985
   350
                while (posx >= 0x10000L) {
slouken@1985
   351
                    ++srcx;
slouken@1985
   352
                    posx -= 0x10000L;
slouken@1985
   353
                }
slouken@1985
   354
                src = ($format_type{$src} *)(data->src + (srcy * data->src_pitch) + (srcx * $format_size{$src}));
slouken@1985
   355
__EOF__
slouken@1985
   356
        print FILE <<__EOF__;
slouken@1985
   357
            }
slouken@1985
   358
__EOF__
slouken@1989
   359
        output_copycore($src, $dst, $modulate, $blend);
slouken@1985
   360
        print FILE <<__EOF__;
slouken@1985
   361
            posx += incx;
slouken@1985
   362
            ++dst;
slouken@1985
   363
        }
slouken@1985
   364
        posy += incy;
slouken@1985
   365
        data->dst += data->dst_pitch;
slouken@1985
   366
    }
slouken@1985
   367
__EOF__
slouken@1985
   368
    } else {
slouken@1985
   369
        print FILE <<__EOF__;
slouken@1985
   370
slouken@1985
   371
    while (data->dst_h--) {
slouken@1985
   372
        $format_type{$src} *src = ($format_type{$src} *)data->src;
slouken@1985
   373
        $format_type{$dst} *dst = ($format_type{$dst} *)data->dst;
slouken@1985
   374
        int n = data->dst_w;
slouken@1985
   375
        while (n--) {
slouken@1985
   376
__EOF__
slouken@1989
   377
        output_copycore($src, $dst, $modulate, $blend);
slouken@1985
   378
        print FILE <<__EOF__;
slouken@1985
   379
            ++src;
slouken@1985
   380
            ++dst;
slouken@1985
   381
        }
slouken@1985
   382
        data->src += data->src_pitch;
slouken@1985
   383
        data->dst += data->dst_pitch;
slouken@1985
   384
    }
slouken@1985
   385
__EOF__
slouken@1985
   386
    }
slouken@1985
   387
    print FILE <<__EOF__;
slouken@1985
   388
    return 0;
slouken@1985
   389
}
slouken@1985
   390
slouken@1985
   391
__EOF__
slouken@1985
   392
}
slouken@1985
   393
slouken@1985
   394
sub output_copyfunc_h
slouken@1985
   395
{
slouken@1985
   396
    my $src = shift;
slouken@1985
   397
    my $dst = shift;
slouken@1985
   398
    for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   399
        for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   400
            for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1992
   401
                if ( $modulate || $blend || $scale ) {
slouken@1985
   402
                    output_copyfuncname("extern int SDLCALL", $src, $dst, $modulate, $blend, $scale, 1, ";\n");
slouken@1985
   403
                }
slouken@1985
   404
            }
slouken@1985
   405
        }
slouken@1985
   406
    }
slouken@1985
   407
}
slouken@1985
   408
slouken@1985
   409
sub output_copyinc
slouken@1985
   410
{
slouken@1985
   411
    print FILE <<__EOF__;
slouken@1985
   412
#include "SDL_video.h"
slouken@1985
   413
#include "SDL_rendercopy.h"
slouken@1985
   414
slouken@1985
   415
__EOF__
slouken@1985
   416
}
slouken@1985
   417
slouken@1985
   418
sub output_copyfunctable
slouken@1985
   419
{
slouken@1985
   420
    print FILE <<__EOF__;
slouken@1985
   421
static struct {
slouken@1985
   422
    Uint32 src_format;
slouken@1985
   423
    Uint32 dst_format;
slouken@1985
   424
    int modMode;
slouken@1985
   425
    int blendMode;
slouken@1985
   426
    int scaleMode;
slouken@1985
   427
    SDL_RenderCopyFunc func;
slouken@1985
   428
} SDL_RenderCopyFuncTable[] = {
slouken@1985
   429
__EOF__
slouken@1985
   430
    for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   431
        my $src = $src_formats[$i];
slouken@1985
   432
        for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   433
            my $dst = $dst_formats[$j];
slouken@1985
   434
            for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   435
                for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   436
                    for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1992
   437
                        if ( $modulate || $blend || $scale ) {
slouken@1985
   438
                            print FILE "    { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, ";
slouken@1985
   439
                            if ( $modulate ) {
slouken@1985
   440
                                print FILE "(SDL_TEXTUREMODULATE_COLOR | SDL_TEXTUREMODULATE_ALPHA), ";
slouken@1985
   441
                            } else {
slouken@1985
   442
                                print FILE "0, ";
slouken@1985
   443
                            }
slouken@1985
   444
                            if ( $blend ) {
slouken@1985
   445
                                print FILE "(SDL_TEXTUREBLENDMODE_MASK | SDL_TEXTUREBLENDMODE_BLEND | SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD), ";
slouken@1985
   446
                            } else {
slouken@1985
   447
                                print FILE "0, ";
slouken@1985
   448
                            }
slouken@1985
   449
                            if ( $scale ) {
slouken@1985
   450
                                print FILE "SDL_TEXTURESCALEMODE_FAST, ";
slouken@1985
   451
                            } else {
slouken@1985
   452
                                print FILE "0, ";
slouken@1985
   453
                            }
slouken@1985
   454
                            output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n");
slouken@1985
   455
                        }
slouken@1985
   456
                    }
slouken@1985
   457
                }
slouken@1985
   458
            }
slouken@1985
   459
        }
slouken@1985
   460
    }
slouken@1985
   461
    print FILE <<__EOF__;
slouken@1985
   462
};
slouken@1985
   463
slouken@1985
   464
SDL_RenderCopyFunc SDL_GetRenderCopyFunc(Uint32 src_format, Uint32 dst_format, int modMode, int blendMode, int scaleMode)
slouken@1985
   465
{
slouken@1985
   466
    int i;
slouken@1985
   467
slouken@1985
   468
    for (i = 0; i < SDL_arraysize(SDL_RenderCopyFuncTable); ++i) {
slouken@1985
   469
        if (src_format != SDL_RenderCopyFuncTable[i].src_format) {
slouken@1985
   470
            continue;
slouken@1985
   471
        }
slouken@1985
   472
        if (dst_format != SDL_RenderCopyFuncTable[i].dst_format) {
slouken@1985
   473
            continue;
slouken@1985
   474
        }
slouken@1985
   475
        if ((modMode & SDL_RenderCopyFuncTable[i].modMode) != modMode) {
slouken@1985
   476
            continue;
slouken@1985
   477
        }
slouken@1985
   478
        if ((blendMode & SDL_RenderCopyFuncTable[i].blendMode) != blendMode) {
slouken@1985
   479
            continue;
slouken@1985
   480
        }
slouken@1985
   481
        if ((scaleMode & SDL_RenderCopyFuncTable[i].scaleMode) != scaleMode) {
slouken@1985
   482
            continue;
slouken@1985
   483
        }
slouken@1985
   484
        return SDL_RenderCopyFuncTable[i].func;
slouken@1985
   485
    }
slouken@1985
   486
    return NULL;
slouken@1985
   487
}
slouken@1985
   488
slouken@1985
   489
__EOF__
slouken@1985
   490
}
slouken@1985
   491
slouken@1985
   492
sub output_copyfunc_c
slouken@1985
   493
{
slouken@1985
   494
    my $src = shift;
slouken@1985
   495
    my $dst = shift;
slouken@1985
   496
slouken@1985
   497
    for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   498
        for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   499
            for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1992
   500
                if ( $modulate || $blend || $scale ) {
slouken@1985
   501
                    output_copyfunc($src, $dst, $modulate, $blend, $scale);
slouken@1985
   502
                }
slouken@1985
   503
            }
slouken@1985
   504
        }
slouken@1985
   505
    }
slouken@1985
   506
}
slouken@1985
   507
slouken@1985
   508
open_file("SDL_rendercopy.h");
slouken@1985
   509
output_copydefs();
slouken@1985
   510
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   511
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   512
        output_copyfunc_h($src_formats[$i], $dst_formats[$j]);
slouken@1985
   513
    }
slouken@1985
   514
}
slouken@1985
   515
print FILE "\n";
slouken@1985
   516
close_file("SDL_rendercopy.h");
slouken@1985
   517
slouken@1985
   518
open_file("SDL_rendercopy.c");
slouken@1985
   519
output_copyinc();
slouken@1985
   520
output_copyfunctable();
slouken@1985
   521
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   522
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   523
        output_copyfunc_c($src_formats[$i], $dst_formats[$j]);
slouken@1985
   524
    }
slouken@1985
   525
}
slouken@1985
   526
close_file("SDL_rendercopy.c");