src/video/sdlgenblit.pl
author Ryan C. Gordon <icculus@icculus.org>
Thu, 20 Mar 2014 17:55:24 -0400
changeset 8659 d3a9836732ea
parent 8149 681eb46b8ac4
child 8661 e9e62c8fffb6
permissions -rwxr-xr-x
Static analysis fix: clean up unused variables and dead stores in blitters.
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_RGB332
slouken@1985
    13
# SDL_PIXELFORMAT_RGB444
slouken@1985
    14
# SDL_PIXELFORMAT_RGB555
slouken@1985
    15
# SDL_PIXELFORMAT_ARGB4444
slouken@1985
    16
# SDL_PIXELFORMAT_ARGB1555
slouken@1985
    17
# SDL_PIXELFORMAT_RGB565
slouken@1985
    18
# SDL_PIXELFORMAT_RGB24
slouken@1985
    19
# SDL_PIXELFORMAT_BGR24
slouken@1985
    20
# SDL_PIXELFORMAT_RGB888
slouken@1985
    21
# SDL_PIXELFORMAT_BGR888
slouken@1985
    22
# SDL_PIXELFORMAT_ARGB8888
slouken@1985
    23
# SDL_PIXELFORMAT_RGBA8888
slouken@1985
    24
# SDL_PIXELFORMAT_ABGR8888
slouken@1985
    25
# SDL_PIXELFORMAT_BGRA8888
slouken@1985
    26
# SDL_PIXELFORMAT_ARGB2101010
slouken@1985
    27
slouken@1985
    28
# The formats we're actually creating blitters for:
slouken@1985
    29
my @src_formats = (
slouken@1985
    30
    "RGB888",
slouken@1985
    31
    "BGR888",
slouken@1985
    32
    "ARGB8888",
slouken@1985
    33
    "RGBA8888",
slouken@1985
    34
    "ABGR8888",
slouken@1985
    35
    "BGRA8888",
slouken@1985
    36
);
slouken@1985
    37
my @dst_formats = (
slouken@1985
    38
    "RGB888",
slouken@1985
    39
    "BGR888",
slouken@2800
    40
    "ARGB8888",
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
icculus@8659
    61
my %get_rgba_string_ignore_alpha = (
icculus@8659
    62
    "RGB888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
icculus@8659
    63
    "BGR888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
icculus@8659
    64
    "ARGB8888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
icculus@8659
    65
    "RGBA8888" => "_R = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _B = (Uint8)(_pixel >> 8);",
icculus@8659
    66
    "ABGR8888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
icculus@8659
    67
    "BGRA8888" => "_B = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _R = (Uint8)(_pixel >> 8);",
icculus@8659
    68
);
icculus@8659
    69
slouken@1985
    70
my %get_rgba_string = (
icculus@8659
    71
    "RGB888" => $get_rgba_string_ignore_alpha{"RGB888"} . " _A = 0xFF;",
icculus@8659
    72
    "BGR888" => $get_rgba_string_ignore_alpha{"BGR888"} . " _A = 0xFF;",
icculus@8659
    73
    "ARGB8888" => $get_rgba_string_ignore_alpha{"ARGB8888"} . " _A = (Uint8)(_pixel >> 24);",
icculus@8659
    74
    "RGBA8888" => $get_rgba_string_ignore_alpha{"RGBA8888"} . " _A = (Uint8)_pixel;",
icculus@8659
    75
    "ABGR8888" => $get_rgba_string_ignore_alpha{"ABGR8888"} . " _A = (Uint8)(_pixel >> 24);",
icculus@8659
    76
    "BGRA8888" => $get_rgba_string_ignore_alpha{"BGRA8888"} . " _A = (Uint8)_pixel;",
slouken@1985
    77
);
slouken@1985
    78
slouken@1985
    79
my %set_rgba_string = (
slouken@1985
    80
    "RGB888" => "_pixel = ((Uint32)_R << 16) | ((Uint32)_G << 8) | _B;",
slouken@1985
    81
    "BGR888" => "_pixel = ((Uint32)_B << 16) | ((Uint32)_G << 8) | _R;",
slouken@2800
    82
    "ARGB8888" => "_pixel = ((Uint32)_A << 24) | ((Uint32)_R << 16) | ((Uint32)_G << 8) | _B;",
slouken@2800
    83
    "RGBA8888" => "_pixel = ((Uint32)_R << 24) | ((Uint32)_G << 16) | ((Uint32)_B << 8) | _A;",
slouken@2800
    84
    "ABGR8888" => "_pixel = ((Uint32)_A << 24) | ((Uint32)_B << 16) | ((Uint32)_G << 8) | _R;",
slouken@2800
    85
    "BGRA8888" => "_pixel = ((Uint32)_B << 24) | ((Uint32)_G << 16) | ((Uint32)_R << 8) | _A;",
slouken@1985
    86
);
slouken@1985
    87
slouken@1985
    88
sub open_file {
slouken@1985
    89
    my $name = shift;
slouken@1985
    90
    open(FILE, ">$name.new") || die "Cant' open $name.new: $!";
slouken@1985
    91
    print FILE <<__EOF__;
slouken@1985
    92
/* DO NOT EDIT!  This file is generated by sdlgenblit.pl */
slouken@1985
    93
/*
slouken@5535
    94
  Simple DirectMedia Layer
slouken@8149
    95
  Copyright (C) 1997-2014 Sam Lantinga <slouken\@libsdl.org>
slouken@1985
    96
slouken@5535
    97
  This software is provided 'as-is', without any express or implied
slouken@5535
    98
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
    99
  arising from the use of this software.
slouken@1985
   100
slouken@5535
   101
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
   102
  including commercial applications, and to alter it and redistribute it
slouken@5535
   103
  freely, subject to the following restrictions:
slouken@1985
   104
slouken@5535
   105
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
   106
     claim that you wrote the original software. If you use this software
slouken@5535
   107
     in a product, an acknowledgment in the product documentation would be
slouken@5535
   108
     appreciated but is not required.
slouken@5535
   109
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
   110
     misrepresented as being the original software.
slouken@5535
   111
  3. This notice may not be removed or altered from any source distribution.
slouken@1985
   112
*/
icculus@8093
   113
#include "../SDL_internal.h"
slouken@1985
   114
slouken@1985
   115
/* *INDENT-OFF* */
slouken@1985
   116
slouken@1985
   117
__EOF__
slouken@1985
   118
}
slouken@1985
   119
slouken@1985
   120
sub close_file {
slouken@1985
   121
    my $name = shift;
slouken@1985
   122
    print FILE <<__EOF__;
slouken@1985
   123
/* *INDENT-ON* */
slouken@1985
   124
slouken@1985
   125
/* vi: set ts=4 sw=4 expandtab: */
slouken@1985
   126
__EOF__
slouken@1985
   127
    close FILE;
slouken@1985
   128
    if ( ! -f $name || system("cmp -s $name $name.new") != 0 ) {
slouken@1985
   129
        rename("$name.new", "$name");
slouken@1985
   130
    } else {
slouken@1985
   131
        unlink("$name.new");
slouken@1985
   132
    }
slouken@1985
   133
}
slouken@1985
   134
slouken@1985
   135
sub output_copydefs
slouken@1985
   136
{
slouken@1985
   137
    print FILE <<__EOF__;
slouken@2263
   138
extern SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[];
slouken@1985
   139
__EOF__
slouken@1985
   140
}
slouken@1985
   141
slouken@1985
   142
sub output_copyfuncname
slouken@1985
   143
{
slouken@1985
   144
    my $prefix = shift;
slouken@1985
   145
    my $src = shift;
slouken@1985
   146
    my $dst = shift;
slouken@1985
   147
    my $modulate = shift;
slouken@1985
   148
    my $blend = shift;
slouken@1985
   149
    my $scale = shift;
slouken@1985
   150
    my $args = shift;
slouken@1985
   151
    my $suffix = shift;
slouken@1985
   152
slouken@2262
   153
    print FILE "$prefix SDL_Blit_${src}_${dst}";
slouken@1985
   154
    if ( $modulate ) {
slouken@1985
   155
        print FILE "_Modulate";
slouken@1985
   156
    }
slouken@1985
   157
    if ( $blend ) {
slouken@1985
   158
        print FILE "_Blend";
slouken@1985
   159
    }
slouken@1985
   160
    if ( $scale ) {
slouken@1985
   161
        print FILE "_Scale";
slouken@1985
   162
    }
slouken@1985
   163
    if ( $args ) {
slouken@2262
   164
        print FILE "(SDL_BlitInfo *info)";
slouken@1985
   165
    }
slouken@1985
   166
    print FILE "$suffix";
slouken@1985
   167
}
slouken@1985
   168
slouken@1985
   169
sub get_rgba
slouken@1985
   170
{
slouken@1985
   171
    my $prefix = shift;
slouken@1985
   172
    my $format = shift;
icculus@8659
   173
    my $ignore_alpha = shift;
icculus@8659
   174
icculus@8659
   175
    my $string;
icculus@8659
   176
    if ($ignore_alpha) {
icculus@8659
   177
        $string = $get_rgba_string_ignore_alpha{$format};
icculus@8659
   178
    } else {
icculus@8659
   179
        $string = $get_rgba_string{$format};
icculus@8659
   180
    }
icculus@8659
   181
slouken@1985
   182
    $string =~ s/_/$prefix/g;
slouken@1985
   183
    if ( $prefix ne "" ) {
slouken@1985
   184
        print FILE <<__EOF__;
slouken@1985
   185
            ${prefix}pixel = *$prefix;
slouken@1985
   186
__EOF__
slouken@1985
   187
    } else {
slouken@1985
   188
        print FILE <<__EOF__;
slouken@1985
   189
            pixel = *src;
slouken@1985
   190
__EOF__
slouken@1985
   191
    }
slouken@1985
   192
    print FILE <<__EOF__;
slouken@1985
   193
            $string
slouken@1985
   194
__EOF__
slouken@1985
   195
}
slouken@1985
   196
slouken@1985
   197
sub set_rgba
slouken@1985
   198
{
slouken@1985
   199
    my $prefix = shift;
slouken@1985
   200
    my $format = shift;
slouken@1985
   201
    my $string = $set_rgba_string{$format};
slouken@1985
   202
    $string =~ s/_/$prefix/g;
slouken@1985
   203
    print FILE <<__EOF__;
slouken@1985
   204
            $string
slouken@1985
   205
            *dst = ${prefix}pixel;
slouken@1985
   206
__EOF__
slouken@1985
   207
}
slouken@1985
   208
slouken@1985
   209
sub output_copycore
slouken@1985
   210
{
slouken@1985
   211
    my $src = shift;
slouken@1985
   212
    my $dst = shift;
slouken@1985
   213
    my $modulate = shift;
slouken@1985
   214
    my $blend = shift;
slouken@1989
   215
    my $s = "";
slouken@1989
   216
    my $d = "";
icculus@8659
   217
    my $ignore_dst_alpha = 0;
slouken@1989
   218
slouken@1989
   219
    # Nice and easy...
slouken@1989
   220
    if ( $src eq $dst && !$modulate && !$blend ) {
slouken@1989
   221
        print FILE <<__EOF__;
slouken@1989
   222
            *dst = *src;
slouken@1989
   223
__EOF__
slouken@1989
   224
        return;
slouken@1989
   225
    }
slouken@2262
   226
icculus@8659
   227
    if (not $dst =~ /A/) {
icculus@8659
   228
        $ignore_dst_alpha = !$blend;
icculus@8659
   229
    }
icculus@8659
   230
slouken@1989
   231
    if ( $blend ) {
icculus@8659
   232
        get_rgba("src", $src, $ignore_dst_alpha);
icculus@8659
   233
        get_rgba("dst", $dst, $ignore_dst_alpha);
slouken@1989
   234
        $s = "src";
slouken@1989
   235
        $d = "dst";
slouken@1989
   236
    } else {
icculus@8659
   237
        get_rgba("", $src, $ignore_dst_alpha);
slouken@1989
   238
    }
slouken@1989
   239
slouken@1985
   240
    if ( $modulate ) {
slouken@1985
   241
        print FILE <<__EOF__;
slouken@2262
   242
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@1989
   243
                ${s}R = (${s}R * modulateR) / 255;
slouken@1989
   244
                ${s}G = (${s}G * modulateG) / 255;
slouken@1989
   245
                ${s}B = (${s}B * modulateB) / 255;
slouken@1985
   246
            }
icculus@8659
   247
__EOF__
icculus@8659
   248
        if (not $ignore_dst_alpha) {
icculus@8659
   249
            print FILE <<__EOF__;
slouken@2262
   250
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@1989
   251
                ${s}A = (${s}A * modulateA) / 255;
slouken@1985
   252
            }
slouken@1985
   253
__EOF__
icculus@8659
   254
        }
slouken@1985
   255
    }
slouken@1985
   256
    if ( $blend ) {
slouken@1985
   257
        print FILE <<__EOF__;
slouken@2262
   258
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@1985
   259
                /* This goes away if we ever use premultiplied alpha */
slouken@1989
   260
                if (${s}A < 255) {
slouken@1989
   261
                    ${s}R = (${s}R * ${s}A) / 255;
slouken@1989
   262
                    ${s}G = (${s}G * ${s}A) / 255;
slouken@1989
   263
                    ${s}B = (${s}B * ${s}A) / 255;
slouken@1989
   264
                }
slouken@1985
   265
            }
slouken@5184
   266
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
   267
            case SDL_COPY_BLEND:
slouken@1989
   268
                ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255;
slouken@1989
   269
                ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255;
slouken@1989
   270
                ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255;
slouken@7502
   271
                ${d}A = ${s}A + ((255 - ${s}A) * ${d}A) / 255;
slouken@1985
   272
                break;
slouken@2262
   273
            case SDL_COPY_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@5184
   278
            case SDL_COPY_MOD:
slouken@5184
   279
                ${d}R = (${s}R * ${d}R) / 255;
slouken@5184
   280
                ${d}G = (${s}G * ${d}G) / 255;
slouken@5184
   281
                ${d}B = (${s}B * ${d}B) / 255;
slouken@5184
   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@2263
   301
    output_copyfuncname("static void", $src, $dst, $modulate, $blend, $scale, 1, "\n");
slouken@1985
   302
    print FILE <<__EOF__;
slouken@1985
   303
{
slouken@5426
   304
__EOF__
slouken@5426
   305
    if ( $modulate || $blend ) {
slouken@5426
   306
        print FILE <<__EOF__;
slouken@2262
   307
    const int flags = info->flags;
slouken@1985
   308
__EOF__
slouken@5426
   309
    }
slouken@1985
   310
    if ( $modulate ) {
slouken@1985
   311
        print FILE <<__EOF__;
slouken@2262
   312
    const Uint32 modulateR = info->r;
slouken@2262
   313
    const Uint32 modulateG = info->g;
slouken@2262
   314
    const Uint32 modulateB = info->b;
slouken@2262
   315
    const Uint32 modulateA = info->a;
slouken@1985
   316
__EOF__
slouken@1985
   317
    }
slouken@1985
   318
    if ( $blend ) {
slouken@1985
   319
        print FILE <<__EOF__;
slouken@1985
   320
    Uint32 srcpixel;
slouken@1985
   321
    Uint32 srcR, srcG, srcB, srcA;
slouken@1985
   322
    Uint32 dstpixel;
slouken@1985
   323
    Uint32 dstR, dstG, dstB, dstA;
slouken@1985
   324
__EOF__
slouken@1985
   325
    } elsif ( $modulate || $src ne $dst ) {
slouken@1985
   326
        print FILE <<__EOF__;
slouken@1985
   327
    Uint32 pixel;
slouken@1985
   328
    Uint32 R, G, B, A;
slouken@1985
   329
__EOF__
slouken@1985
   330
    }
slouken@1985
   331
    if ( $scale ) {
slouken@1985
   332
        print FILE <<__EOF__;
slouken@1985
   333
    int srcy, srcx;
slouken@1985
   334
    int posy, posx;
slouken@1985
   335
    int incy, incx;
icculus@8659
   336
__EOF__
icculus@8659
   337
icculus@8659
   338
    # !!! FIXME: the script should just exclude in these cases.
icculus@8659
   339
    if ( (!$blend) && ($modulate || $src ne $dst) ) {
icculus@8659
   340
        print FILE <<__EOF__;
icculus@8659
   341
    (void) A;  /* not all formats use alpha. */
icculus@8659
   342
__EOF__
icculus@8659
   343
    }
icculus@8659
   344
icculus@8659
   345
    # !!! FIXME: the script should just exclude in these cases.
icculus@8659
   346
    if ( $modulate ) {
icculus@8659
   347
        print FILE <<__EOF__;
icculus@8659
   348
    (void) modulateA;  /* not all formats use alpha. */
icculus@8659
   349
__EOF__
icculus@8659
   350
    }
icculus@8659
   351
icculus@8659
   352
    print FILE <<__EOF__;
slouken@1985
   353
slouken@1985
   354
    srcy = 0;
slouken@1985
   355
    posy = 0;
slouken@2262
   356
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
   357
    incx = (info->src_w << 16) / info->dst_w;
slouken@1985
   358
slouken@2262
   359
    while (info->dst_h--) {
slouken@5426
   360
        $format_type{$src} *src = 0;
slouken@2262
   361
        $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
slouken@2262
   362
        int n = info->dst_w;
slouken@1985
   363
        srcx = -1;
slouken@1985
   364
        posx = 0x10000L;
slouken@1985
   365
        while (posy >= 0x10000L) {
slouken@1985
   366
            ++srcy;
slouken@1985
   367
            posy -= 0x10000L;
slouken@1985
   368
        }
slouken@1985
   369
        while (n--) {
slouken@1985
   370
            if (posx >= 0x10000L) {
slouken@1985
   371
                while (posx >= 0x10000L) {
slouken@1985
   372
                    ++srcx;
slouken@1985
   373
                    posx -= 0x10000L;
slouken@1985
   374
                }
slouken@2262
   375
                src = ($format_type{$src} *)(info->src + (srcy * info->src_pitch) + (srcx * $format_size{$src}));
slouken@1985
   376
__EOF__
slouken@1985
   377
        print FILE <<__EOF__;
slouken@1985
   378
            }
slouken@1985
   379
__EOF__
slouken@1989
   380
        output_copycore($src, $dst, $modulate, $blend);
slouken@1985
   381
        print FILE <<__EOF__;
slouken@1985
   382
            posx += incx;
slouken@1985
   383
            ++dst;
slouken@1985
   384
        }
slouken@1985
   385
        posy += incy;
slouken@2262
   386
        info->dst += info->dst_pitch;
slouken@1985
   387
    }
slouken@1985
   388
__EOF__
slouken@1985
   389
    } else {
icculus@8659
   390
        # !!! FIXME: the script should just exclude in these cases.
icculus@8659
   391
        if ( (!$blend) && ($modulate || $src ne $dst) ) {
icculus@8659
   392
            print FILE <<__EOF__;
icculus@8659
   393
    (void) A;  /* not all formats use alpha. */
icculus@8659
   394
__EOF__
icculus@8659
   395
        }
icculus@8659
   396
icculus@8659
   397
        # !!! FIXME: the script should just exclude in these cases.
icculus@8659
   398
        if ( $modulate ) {
icculus@8659
   399
            print FILE <<__EOF__;
icculus@8659
   400
    (void) modulateA;  /* not all formats use alpha. */
icculus@8659
   401
__EOF__
icculus@8659
   402
        }
icculus@8659
   403
slouken@1985
   404
        print FILE <<__EOF__;
slouken@1985
   405
slouken@2262
   406
    while (info->dst_h--) {
slouken@2262
   407
        $format_type{$src} *src = ($format_type{$src} *)info->src;
slouken@2262
   408
        $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
slouken@2262
   409
        int n = info->dst_w;
slouken@1985
   410
        while (n--) {
slouken@1985
   411
__EOF__
slouken@1989
   412
        output_copycore($src, $dst, $modulate, $blend);
slouken@1985
   413
        print FILE <<__EOF__;
slouken@1985
   414
            ++src;
slouken@1985
   415
            ++dst;
slouken@1985
   416
        }
slouken@2262
   417
        info->src += info->src_pitch;
slouken@2262
   418
        info->dst += info->dst_pitch;
slouken@1985
   419
    }
slouken@1985
   420
__EOF__
slouken@1985
   421
    }
slouken@1985
   422
    print FILE <<__EOF__;
slouken@1985
   423
}
slouken@1985
   424
slouken@1985
   425
__EOF__
slouken@1985
   426
}
slouken@1985
   427
slouken@1985
   428
sub output_copyfunc_h
slouken@1985
   429
{
slouken@1985
   430
}
slouken@1985
   431
slouken@1985
   432
sub output_copyinc
slouken@1985
   433
{
slouken@1985
   434
    print FILE <<__EOF__;
slouken@1985
   435
#include "SDL_video.h"
slouken@2262
   436
#include "SDL_blit.h"
slouken@2262
   437
#include "SDL_blit_auto.h"
slouken@1985
   438
slouken@1985
   439
__EOF__
slouken@1985
   440
}
slouken@1985
   441
slouken@1985
   442
sub output_copyfunctable
slouken@1985
   443
{
slouken@1985
   444
    print FILE <<__EOF__;
slouken@2267
   445
SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = {
slouken@1985
   446
__EOF__
slouken@1985
   447
    for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   448
        my $src = $src_formats[$i];
slouken@1985
   449
        for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   450
            my $dst = $dst_formats[$j];
slouken@1985
   451
            for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   452
                for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   453
                    for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1992
   454
                        if ( $modulate || $blend || $scale ) {
slouken@1985
   455
                            print FILE "    { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, ";
slouken@2262
   456
                            my $flags = "";
slouken@2262
   457
                            my $flag = "";
slouken@1985
   458
                            if ( $modulate ) {
slouken@2262
   459
                                $flag = "SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA";
slouken@2262
   460
                                if ( $flags eq "" ) {
slouken@2262
   461
                                    $flags = $flag;
slouken@2262
   462
                                } else {
slouken@2262
   463
                                    $flags = "$flags | $flag";
slouken@2262
   464
                                }
slouken@1985
   465
                            }
slouken@1985
   466
                            if ( $blend ) {
slouken@5184
   467
                                $flag = "SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD";
slouken@2262
   468
                                if ( $flags eq "" ) {
slouken@2262
   469
                                    $flags = $flag;
slouken@2262
   470
                                } else {
slouken@2262
   471
                                    $flags = "$flags | $flag";
slouken@2262
   472
                                }
slouken@1985
   473
                            }
slouken@1985
   474
                            if ( $scale ) {
slouken@2262
   475
                                $flag = "SDL_COPY_NEAREST";
slouken@2262
   476
                                if ( $flags eq "" ) {
slouken@2262
   477
                                    $flags = $flag;
slouken@2262
   478
                                } else {
slouken@2262
   479
                                    $flags = "$flags | $flag";
slouken@2262
   480
                                }
slouken@1985
   481
                            }
slouken@2262
   482
                            if ( $flags eq "" ) {
slouken@2262
   483
                                $flags = "0";
slouken@2262
   484
                            }
slouken@2262
   485
                            print FILE "($flags), SDL_CPU_ANY,";
slouken@1985
   486
                            output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n");
slouken@1985
   487
                        }
slouken@1985
   488
                    }
slouken@1985
   489
                }
slouken@1985
   490
            }
slouken@1985
   491
        }
slouken@1985
   492
    }
slouken@1985
   493
    print FILE <<__EOF__;
slouken@2262
   494
    { 0, 0, 0, 0, NULL }
slouken@1985
   495
};
slouken@1985
   496
slouken@1985
   497
__EOF__
slouken@1985
   498
}
slouken@1985
   499
slouken@1985
   500
sub output_copyfunc_c
slouken@1985
   501
{
slouken@1985
   502
    my $src = shift;
slouken@1985
   503
    my $dst = shift;
slouken@1985
   504
slouken@1985
   505
    for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   506
        for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   507
            for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1992
   508
                if ( $modulate || $blend || $scale ) {
slouken@1985
   509
                    output_copyfunc($src, $dst, $modulate, $blend, $scale);
slouken@1985
   510
                }
slouken@1985
   511
            }
slouken@1985
   512
        }
slouken@1985
   513
    }
slouken@1985
   514
}
slouken@1985
   515
slouken@2262
   516
open_file("SDL_blit_auto.h");
slouken@1985
   517
output_copydefs();
slouken@1985
   518
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   519
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   520
        output_copyfunc_h($src_formats[$i], $dst_formats[$j]);
slouken@1985
   521
    }
slouken@1985
   522
}
slouken@1985
   523
print FILE "\n";
slouken@2262
   524
close_file("SDL_blit_auto.h");
slouken@1985
   525
slouken@2262
   526
open_file("SDL_blit_auto.c");
slouken@1985
   527
output_copyinc();
slouken@1985
   528
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   529
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   530
        output_copyfunc_c($src_formats[$i], $dst_formats[$j]);
slouken@1985
   531
    }
slouken@1985
   532
}
slouken@2263
   533
output_copyfunctable();
slouken@2262
   534
close_file("SDL_blit_auto.c");