src/video/sdlgenblit.pl
author Ryan C. Gordon <icculus@icculus.org>
Fri, 21 Mar 2014 00:57:43 -0400
changeset 8661 e9e62c8fffb6
parent 8659 d3a9836732ea
child 8662 f8e55cba0bca
permissions -rwxr-xr-x
Static analysis fix: more dead stores.
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;
icculus@8661
   271
__EOF__
icculus@8661
   272
icculus@8661
   273
        if ( $dst =~ /A/ ) {
icculus@8661
   274
            print FILE <<__EOF__;
slouken@7502
   275
                ${d}A = ${s}A + ((255 - ${s}A) * ${d}A) / 255;
icculus@8661
   276
__EOF__
icculus@8661
   277
        }
icculus@8661
   278
icculus@8661
   279
        print FILE <<__EOF__;
slouken@1985
   280
                break;
slouken@2262
   281
            case SDL_COPY_ADD:
slouken@1989
   282
                ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
slouken@1989
   283
                ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255;
slouken@1989
   284
                ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255;
slouken@1985
   285
                break;
slouken@5184
   286
            case SDL_COPY_MOD:
slouken@5184
   287
                ${d}R = (${s}R * ${d}R) / 255;
slouken@5184
   288
                ${d}G = (${s}G * ${d}G) / 255;
slouken@5184
   289
                ${d}B = (${s}B * ${d}B) / 255;
slouken@5184
   290
                break;
slouken@1985
   291
            }
slouken@1985
   292
__EOF__
slouken@1985
   293
    }
slouken@1989
   294
    if ( $blend ) {
slouken@1989
   295
        set_rgba("dst", $dst);
slouken@1989
   296
    } else {
slouken@1989
   297
        set_rgba("", $dst);
slouken@1989
   298
    }
slouken@1985
   299
}
slouken@1985
   300
slouken@1985
   301
sub output_copyfunc
slouken@1985
   302
{
slouken@1985
   303
    my $src = shift;
slouken@1985
   304
    my $dst = shift;
slouken@1985
   305
    my $modulate = shift;
slouken@1985
   306
    my $blend = shift;
slouken@1985
   307
    my $scale = shift;
slouken@1985
   308
slouken@2263
   309
    output_copyfuncname("static void", $src, $dst, $modulate, $blend, $scale, 1, "\n");
slouken@1985
   310
    print FILE <<__EOF__;
slouken@1985
   311
{
slouken@5426
   312
__EOF__
slouken@5426
   313
    if ( $modulate || $blend ) {
slouken@5426
   314
        print FILE <<__EOF__;
slouken@2262
   315
    const int flags = info->flags;
slouken@1985
   316
__EOF__
slouken@5426
   317
    }
slouken@1985
   318
    if ( $modulate ) {
slouken@1985
   319
        print FILE <<__EOF__;
slouken@2262
   320
    const Uint32 modulateR = info->r;
slouken@2262
   321
    const Uint32 modulateG = info->g;
slouken@2262
   322
    const Uint32 modulateB = info->b;
slouken@2262
   323
    const Uint32 modulateA = info->a;
slouken@1985
   324
__EOF__
slouken@1985
   325
    }
slouken@1985
   326
    if ( $blend ) {
slouken@1985
   327
        print FILE <<__EOF__;
slouken@1985
   328
    Uint32 srcpixel;
slouken@1985
   329
    Uint32 srcR, srcG, srcB, srcA;
slouken@1985
   330
    Uint32 dstpixel;
slouken@1985
   331
    Uint32 dstR, dstG, dstB, dstA;
slouken@1985
   332
__EOF__
slouken@1985
   333
    } elsif ( $modulate || $src ne $dst ) {
slouken@1985
   334
        print FILE <<__EOF__;
slouken@1985
   335
    Uint32 pixel;
slouken@1985
   336
    Uint32 R, G, B, A;
slouken@1985
   337
__EOF__
slouken@1985
   338
    }
slouken@1985
   339
    if ( $scale ) {
slouken@1985
   340
        print FILE <<__EOF__;
slouken@1985
   341
    int srcy, srcx;
slouken@1985
   342
    int posy, posx;
slouken@1985
   343
    int incy, incx;
icculus@8659
   344
__EOF__
icculus@8659
   345
icculus@8659
   346
    # !!! FIXME: the script should just exclude in these cases.
icculus@8659
   347
    if ( (!$blend) && ($modulate || $src ne $dst) ) {
icculus@8659
   348
        print FILE <<__EOF__;
icculus@8659
   349
    (void) A;  /* not all formats use alpha. */
icculus@8659
   350
__EOF__
icculus@8659
   351
    }
icculus@8659
   352
icculus@8659
   353
    # !!! FIXME: the script should just exclude in these cases.
icculus@8659
   354
    if ( $modulate ) {
icculus@8659
   355
        print FILE <<__EOF__;
icculus@8659
   356
    (void) modulateA;  /* not all formats use alpha. */
icculus@8659
   357
__EOF__
icculus@8659
   358
    }
icculus@8659
   359
icculus@8661
   360
    # !!! FIXME: the script should just exclude in these cases.
icculus@8661
   361
    if ( $blend ) {
icculus@8661
   362
        print FILE <<__EOF__;
icculus@8661
   363
    (void) dstA;  /* not all formats use alpha. */
icculus@8661
   364
__EOF__
icculus@8661
   365
    }
icculus@8661
   366
icculus@8659
   367
    print FILE <<__EOF__;
slouken@1985
   368
slouken@1985
   369
    srcy = 0;
slouken@1985
   370
    posy = 0;
slouken@2262
   371
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
   372
    incx = (info->src_w << 16) / info->dst_w;
slouken@1985
   373
slouken@2262
   374
    while (info->dst_h--) {
slouken@5426
   375
        $format_type{$src} *src = 0;
slouken@2262
   376
        $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
slouken@2262
   377
        int n = info->dst_w;
slouken@1985
   378
        srcx = -1;
slouken@1985
   379
        posx = 0x10000L;
slouken@1985
   380
        while (posy >= 0x10000L) {
slouken@1985
   381
            ++srcy;
slouken@1985
   382
            posy -= 0x10000L;
slouken@1985
   383
        }
slouken@1985
   384
        while (n--) {
slouken@1985
   385
            if (posx >= 0x10000L) {
slouken@1985
   386
                while (posx >= 0x10000L) {
slouken@1985
   387
                    ++srcx;
slouken@1985
   388
                    posx -= 0x10000L;
slouken@1985
   389
                }
slouken@2262
   390
                src = ($format_type{$src} *)(info->src + (srcy * info->src_pitch) + (srcx * $format_size{$src}));
slouken@1985
   391
__EOF__
slouken@1985
   392
        print FILE <<__EOF__;
slouken@1985
   393
            }
slouken@1985
   394
__EOF__
slouken@1989
   395
        output_copycore($src, $dst, $modulate, $blend);
slouken@1985
   396
        print FILE <<__EOF__;
slouken@1985
   397
            posx += incx;
slouken@1985
   398
            ++dst;
slouken@1985
   399
        }
slouken@1985
   400
        posy += incy;
slouken@2262
   401
        info->dst += info->dst_pitch;
slouken@1985
   402
    }
slouken@1985
   403
__EOF__
slouken@1985
   404
    } else {
icculus@8659
   405
        # !!! FIXME: the script should just exclude in these cases.
icculus@8659
   406
        if ( (!$blend) && ($modulate || $src ne $dst) ) {
icculus@8659
   407
            print FILE <<__EOF__;
icculus@8659
   408
    (void) A;  /* not all formats use alpha. */
icculus@8659
   409
__EOF__
icculus@8659
   410
        }
icculus@8659
   411
icculus@8659
   412
        # !!! FIXME: the script should just exclude in these cases.
icculus@8659
   413
        if ( $modulate ) {
icculus@8659
   414
            print FILE <<__EOF__;
icculus@8659
   415
    (void) modulateA;  /* not all formats use alpha. */
icculus@8659
   416
__EOF__
icculus@8659
   417
        }
icculus@8659
   418
icculus@8661
   419
        # !!! FIXME: the script should just exclude in these cases.
icculus@8661
   420
        if ( $blend ) {
icculus@8661
   421
            print FILE <<__EOF__;
icculus@8661
   422
    (void) dstA;  /* not all formats use alpha. */
icculus@8661
   423
__EOF__
icculus@8661
   424
        }
icculus@8661
   425
slouken@1985
   426
        print FILE <<__EOF__;
slouken@1985
   427
slouken@2262
   428
    while (info->dst_h--) {
slouken@2262
   429
        $format_type{$src} *src = ($format_type{$src} *)info->src;
slouken@2262
   430
        $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
slouken@2262
   431
        int n = info->dst_w;
slouken@1985
   432
        while (n--) {
slouken@1985
   433
__EOF__
slouken@1989
   434
        output_copycore($src, $dst, $modulate, $blend);
slouken@1985
   435
        print FILE <<__EOF__;
slouken@1985
   436
            ++src;
slouken@1985
   437
            ++dst;
slouken@1985
   438
        }
slouken@2262
   439
        info->src += info->src_pitch;
slouken@2262
   440
        info->dst += info->dst_pitch;
slouken@1985
   441
    }
slouken@1985
   442
__EOF__
slouken@1985
   443
    }
slouken@1985
   444
    print FILE <<__EOF__;
slouken@1985
   445
}
slouken@1985
   446
slouken@1985
   447
__EOF__
slouken@1985
   448
}
slouken@1985
   449
slouken@1985
   450
sub output_copyfunc_h
slouken@1985
   451
{
slouken@1985
   452
}
slouken@1985
   453
slouken@1985
   454
sub output_copyinc
slouken@1985
   455
{
slouken@1985
   456
    print FILE <<__EOF__;
slouken@1985
   457
#include "SDL_video.h"
slouken@2262
   458
#include "SDL_blit.h"
slouken@2262
   459
#include "SDL_blit_auto.h"
slouken@1985
   460
slouken@1985
   461
__EOF__
slouken@1985
   462
}
slouken@1985
   463
slouken@1985
   464
sub output_copyfunctable
slouken@1985
   465
{
slouken@1985
   466
    print FILE <<__EOF__;
slouken@2267
   467
SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = {
slouken@1985
   468
__EOF__
slouken@1985
   469
    for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   470
        my $src = $src_formats[$i];
slouken@1985
   471
        for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   472
            my $dst = $dst_formats[$j];
slouken@1985
   473
            for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   474
                for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   475
                    for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1992
   476
                        if ( $modulate || $blend || $scale ) {
slouken@1985
   477
                            print FILE "    { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, ";
slouken@2262
   478
                            my $flags = "";
slouken@2262
   479
                            my $flag = "";
slouken@1985
   480
                            if ( $modulate ) {
slouken@2262
   481
                                $flag = "SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA";
slouken@2262
   482
                                if ( $flags eq "" ) {
slouken@2262
   483
                                    $flags = $flag;
slouken@2262
   484
                                } else {
slouken@2262
   485
                                    $flags = "$flags | $flag";
slouken@2262
   486
                                }
slouken@1985
   487
                            }
slouken@1985
   488
                            if ( $blend ) {
slouken@5184
   489
                                $flag = "SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD";
slouken@2262
   490
                                if ( $flags eq "" ) {
slouken@2262
   491
                                    $flags = $flag;
slouken@2262
   492
                                } else {
slouken@2262
   493
                                    $flags = "$flags | $flag";
slouken@2262
   494
                                }
slouken@1985
   495
                            }
slouken@1985
   496
                            if ( $scale ) {
slouken@2262
   497
                                $flag = "SDL_COPY_NEAREST";
slouken@2262
   498
                                if ( $flags eq "" ) {
slouken@2262
   499
                                    $flags = $flag;
slouken@2262
   500
                                } else {
slouken@2262
   501
                                    $flags = "$flags | $flag";
slouken@2262
   502
                                }
slouken@1985
   503
                            }
slouken@2262
   504
                            if ( $flags eq "" ) {
slouken@2262
   505
                                $flags = "0";
slouken@2262
   506
                            }
slouken@2262
   507
                            print FILE "($flags), SDL_CPU_ANY,";
slouken@1985
   508
                            output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n");
slouken@1985
   509
                        }
slouken@1985
   510
                    }
slouken@1985
   511
                }
slouken@1985
   512
            }
slouken@1985
   513
        }
slouken@1985
   514
    }
slouken@1985
   515
    print FILE <<__EOF__;
slouken@2262
   516
    { 0, 0, 0, 0, NULL }
slouken@1985
   517
};
slouken@1985
   518
slouken@1985
   519
__EOF__
slouken@1985
   520
}
slouken@1985
   521
slouken@1985
   522
sub output_copyfunc_c
slouken@1985
   523
{
slouken@1985
   524
    my $src = shift;
slouken@1985
   525
    my $dst = shift;
slouken@1985
   526
slouken@1985
   527
    for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   528
        for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   529
            for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1992
   530
                if ( $modulate || $blend || $scale ) {
slouken@1985
   531
                    output_copyfunc($src, $dst, $modulate, $blend, $scale);
slouken@1985
   532
                }
slouken@1985
   533
            }
slouken@1985
   534
        }
slouken@1985
   535
    }
slouken@1985
   536
}
slouken@1985
   537
slouken@2262
   538
open_file("SDL_blit_auto.h");
slouken@1985
   539
output_copydefs();
slouken@1985
   540
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   541
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   542
        output_copyfunc_h($src_formats[$i], $dst_formats[$j]);
slouken@1985
   543
    }
slouken@1985
   544
}
slouken@1985
   545
print FILE "\n";
slouken@2262
   546
close_file("SDL_blit_auto.h");
slouken@1985
   547
slouken@2262
   548
open_file("SDL_blit_auto.c");
slouken@1985
   549
output_copyinc();
slouken@1985
   550
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   551
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   552
        output_copyfunc_c($src_formats[$i], $dst_formats[$j]);
slouken@1985
   553
    }
slouken@1985
   554
}
slouken@2263
   555
output_copyfunctable();
slouken@2262
   556
close_file("SDL_blit_auto.c");