src/video/sdlgenblit.pl
author Sam Lantinga <slouken@libsdl.org>
Fri, 18 May 2018 13:09:30 -0700
changeset 11983 3a50eb90e4b2
parent 11811 5d94cb6b24d3
child 12503 806492103856
permissions -rwxr-xr-x
Merged latest changes from Steam Link app
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@11811
    95
  Copyright (C) 1997-2018 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 = "";
slouken@1989
   217
slouken@1989
   218
    # Nice and easy...
slouken@1989
   219
    if ( $src eq $dst && !$modulate && !$blend ) {
slouken@1989
   220
        print FILE <<__EOF__;
slouken@1989
   221
            *dst = *src;
slouken@1989
   222
__EOF__
slouken@1989
   223
        return;
slouken@1989
   224
    }
slouken@2262
   225
icculus@8662
   226
    my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
icculus@8662
   227
    my $ignore_dst_alpha = !$dst_has_alpha && !$blend;
icculus@8659
   228
slouken@1989
   229
    if ( $blend ) {
icculus@8659
   230
        get_rgba("src", $src, $ignore_dst_alpha);
icculus@8662
   231
        get_rgba("dst", $dst, !$dst_has_alpha);
slouken@1989
   232
        $s = "src";
slouken@1989
   233
        $d = "dst";
slouken@1989
   234
    } else {
icculus@8659
   235
        get_rgba("", $src, $ignore_dst_alpha);
slouken@1989
   236
    }
slouken@1989
   237
slouken@1985
   238
    if ( $modulate ) {
slouken@1985
   239
        print FILE <<__EOF__;
slouken@2262
   240
            if (flags & SDL_COPY_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
            }
icculus@8659
   245
__EOF__
icculus@8659
   246
        if (not $ignore_dst_alpha) {
icculus@8659
   247
            print FILE <<__EOF__;
slouken@2262
   248
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@1989
   249
                ${s}A = (${s}A * modulateA) / 255;
slouken@1985
   250
            }
slouken@1985
   251
__EOF__
icculus@8659
   252
        }
slouken@1985
   253
    }
slouken@1985
   254
    if ( $blend ) {
slouken@1985
   255
        print FILE <<__EOF__;
slouken@2262
   256
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@1985
   257
                /* This goes away if we ever use premultiplied alpha */
slouken@1989
   258
                if (${s}A < 255) {
slouken@1989
   259
                    ${s}R = (${s}R * ${s}A) / 255;
slouken@1989
   260
                    ${s}G = (${s}G * ${s}A) / 255;
slouken@1989
   261
                    ${s}B = (${s}B * ${s}A) / 255;
slouken@1989
   262
                }
slouken@1985
   263
            }
slouken@5184
   264
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
   265
            case SDL_COPY_BLEND:
slouken@1989
   266
                ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255;
slouken@1989
   267
                ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255;
slouken@1989
   268
                ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255;
icculus@8661
   269
__EOF__
icculus@8661
   270
icculus@8662
   271
        if ( $dst_has_alpha ) {
icculus@8661
   272
            print FILE <<__EOF__;
slouken@7502
   273
                ${d}A = ${s}A + ((255 - ${s}A) * ${d}A) / 255;
icculus@8661
   274
__EOF__
icculus@8661
   275
        }
icculus@8661
   276
icculus@8661
   277
        print FILE <<__EOF__;
slouken@1985
   278
                break;
slouken@2262
   279
            case SDL_COPY_ADD:
slouken@1989
   280
                ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
slouken@1989
   281
                ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255;
slouken@1989
   282
                ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255;
slouken@1985
   283
                break;
slouken@5184
   284
            case SDL_COPY_MOD:
slouken@5184
   285
                ${d}R = (${s}R * ${d}R) / 255;
slouken@5184
   286
                ${d}G = (${s}G * ${d}G) / 255;
slouken@5184
   287
                ${d}B = (${s}B * ${d}B) / 255;
slouken@5184
   288
                break;
slouken@1985
   289
            }
slouken@1985
   290
__EOF__
slouken@1985
   291
    }
slouken@1989
   292
    if ( $blend ) {
slouken@1989
   293
        set_rgba("dst", $dst);
slouken@1989
   294
    } else {
slouken@1989
   295
        set_rgba("", $dst);
slouken@1989
   296
    }
slouken@1985
   297
}
slouken@1985
   298
slouken@1985
   299
sub output_copyfunc
slouken@1985
   300
{
slouken@1985
   301
    my $src = shift;
slouken@1985
   302
    my $dst = shift;
slouken@1985
   303
    my $modulate = shift;
slouken@1985
   304
    my $blend = shift;
slouken@1985
   305
    my $scale = shift;
slouken@1985
   306
icculus@8662
   307
    my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
icculus@8662
   308
    my $ignore_dst_alpha = !$dst_has_alpha && !$blend;
icculus@8662
   309
slouken@2263
   310
    output_copyfuncname("static void", $src, $dst, $modulate, $blend, $scale, 1, "\n");
slouken@1985
   311
    print FILE <<__EOF__;
slouken@1985
   312
{
slouken@5426
   313
__EOF__
slouken@5426
   314
    if ( $modulate || $blend ) {
slouken@5426
   315
        print FILE <<__EOF__;
slouken@2262
   316
    const int flags = info->flags;
slouken@1985
   317
__EOF__
slouken@5426
   318
    }
slouken@1985
   319
    if ( $modulate ) {
slouken@1985
   320
        print FILE <<__EOF__;
slouken@2262
   321
    const Uint32 modulateR = info->r;
slouken@2262
   322
    const Uint32 modulateG = info->g;
slouken@2262
   323
    const Uint32 modulateB = info->b;
icculus@8662
   324
__EOF__
icculus@8662
   325
        if (!$ignore_dst_alpha) {
icculus@8662
   326
            print FILE <<__EOF__;
slouken@2262
   327
    const Uint32 modulateA = info->a;
slouken@1985
   328
__EOF__
icculus@8662
   329
        }
slouken@1985
   330
    }
slouken@1985
   331
    if ( $blend ) {
slouken@1985
   332
        print FILE <<__EOF__;
slouken@1985
   333
    Uint32 srcpixel;
slouken@1985
   334
    Uint32 srcR, srcG, srcB, srcA;
slouken@1985
   335
    Uint32 dstpixel;
icculus@8662
   336
__EOF__
icculus@8662
   337
        if ($dst_has_alpha) {
icculus@8662
   338
            print FILE <<__EOF__;
slouken@1985
   339
    Uint32 dstR, dstG, dstB, dstA;
slouken@1985
   340
__EOF__
icculus@8662
   341
        } else {
icculus@8662
   342
            print FILE <<__EOF__;
icculus@8662
   343
    Uint32 dstR, dstG, dstB;
icculus@8662
   344
__EOF__
icculus@8662
   345
        }
slouken@1985
   346
    } elsif ( $modulate || $src ne $dst ) {
slouken@1985
   347
        print FILE <<__EOF__;
slouken@1985
   348
    Uint32 pixel;
icculus@8662
   349
__EOF__
icculus@8662
   350
        if (!$ignore_dst_alpha) {
icculus@8662
   351
            print FILE <<__EOF__;
slouken@1985
   352
    Uint32 R, G, B, A;
slouken@1985
   353
__EOF__
icculus@8662
   354
        } else {
icculus@8662
   355
            print FILE <<__EOF__;
icculus@8662
   356
    Uint32 R, G, B;
icculus@8662
   357
__EOF__
icculus@8662
   358
        }
slouken@1985
   359
    }
slouken@1985
   360
    if ( $scale ) {
slouken@1985
   361
        print FILE <<__EOF__;
slouken@1985
   362
    int srcy, srcx;
slouken@1985
   363
    int posy, posx;
slouken@1985
   364
    int incy, incx;
icculus@8659
   365
__EOF__
icculus@8659
   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 {
slouken@1985
   405
        print FILE <<__EOF__;
slouken@1985
   406
slouken@2262
   407
    while (info->dst_h--) {
slouken@2262
   408
        $format_type{$src} *src = ($format_type{$src} *)info->src;
slouken@2262
   409
        $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
slouken@2262
   410
        int n = info->dst_w;
slouken@1985
   411
        while (n--) {
slouken@1985
   412
__EOF__
slouken@1989
   413
        output_copycore($src, $dst, $modulate, $blend);
slouken@1985
   414
        print FILE <<__EOF__;
slouken@1985
   415
            ++src;
slouken@1985
   416
            ++dst;
slouken@1985
   417
        }
slouken@2262
   418
        info->src += info->src_pitch;
slouken@2262
   419
        info->dst += info->dst_pitch;
slouken@1985
   420
    }
slouken@1985
   421
__EOF__
slouken@1985
   422
    }
slouken@1985
   423
    print FILE <<__EOF__;
slouken@1985
   424
}
slouken@1985
   425
slouken@1985
   426
__EOF__
slouken@1985
   427
}
slouken@1985
   428
slouken@1985
   429
sub output_copyfunc_h
slouken@1985
   430
{
slouken@1985
   431
}
slouken@1985
   432
slouken@1985
   433
sub output_copyinc
slouken@1985
   434
{
slouken@1985
   435
    print FILE <<__EOF__;
slouken@1985
   436
#include "SDL_video.h"
slouken@2262
   437
#include "SDL_blit.h"
slouken@2262
   438
#include "SDL_blit_auto.h"
slouken@1985
   439
slouken@1985
   440
__EOF__
slouken@1985
   441
}
slouken@1985
   442
slouken@1985
   443
sub output_copyfunctable
slouken@1985
   444
{
slouken@1985
   445
    print FILE <<__EOF__;
slouken@2267
   446
SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = {
slouken@1985
   447
__EOF__
slouken@1985
   448
    for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   449
        my $src = $src_formats[$i];
slouken@1985
   450
        for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   451
            my $dst = $dst_formats[$j];
slouken@1985
   452
            for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   453
                for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   454
                    for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1992
   455
                        if ( $modulate || $blend || $scale ) {
slouken@1985
   456
                            print FILE "    { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, ";
slouken@2262
   457
                            my $flags = "";
slouken@2262
   458
                            my $flag = "";
slouken@1985
   459
                            if ( $modulate ) {
slouken@2262
   460
                                $flag = "SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA";
slouken@2262
   461
                                if ( $flags eq "" ) {
slouken@2262
   462
                                    $flags = $flag;
slouken@2262
   463
                                } else {
slouken@2262
   464
                                    $flags = "$flags | $flag";
slouken@2262
   465
                                }
slouken@1985
   466
                            }
slouken@1985
   467
                            if ( $blend ) {
slouken@5184
   468
                                $flag = "SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD";
slouken@2262
   469
                                if ( $flags eq "" ) {
slouken@2262
   470
                                    $flags = $flag;
slouken@2262
   471
                                } else {
slouken@2262
   472
                                    $flags = "$flags | $flag";
slouken@2262
   473
                                }
slouken@1985
   474
                            }
slouken@1985
   475
                            if ( $scale ) {
slouken@2262
   476
                                $flag = "SDL_COPY_NEAREST";
slouken@2262
   477
                                if ( $flags eq "" ) {
slouken@2262
   478
                                    $flags = $flag;
slouken@2262
   479
                                } else {
slouken@2262
   480
                                    $flags = "$flags | $flag";
slouken@2262
   481
                                }
slouken@1985
   482
                            }
slouken@2262
   483
                            if ( $flags eq "" ) {
slouken@2262
   484
                                $flags = "0";
slouken@2262
   485
                            }
slouken@2262
   486
                            print FILE "($flags), SDL_CPU_ANY,";
slouken@1985
   487
                            output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n");
slouken@1985
   488
                        }
slouken@1985
   489
                    }
slouken@1985
   490
                }
slouken@1985
   491
            }
slouken@1985
   492
        }
slouken@1985
   493
    }
slouken@1985
   494
    print FILE <<__EOF__;
slouken@2262
   495
    { 0, 0, 0, 0, NULL }
slouken@1985
   496
};
slouken@1985
   497
slouken@1985
   498
__EOF__
slouken@1985
   499
}
slouken@1985
   500
slouken@1985
   501
sub output_copyfunc_c
slouken@1985
   502
{
slouken@1985
   503
    my $src = shift;
slouken@1985
   504
    my $dst = shift;
slouken@1985
   505
slouken@1985
   506
    for (my $modulate = 0; $modulate <= 1; ++$modulate) {
slouken@1985
   507
        for (my $blend = 0; $blend <= 1; ++$blend) {
slouken@1985
   508
            for (my $scale = 0; $scale <= 1; ++$scale) {
slouken@1992
   509
                if ( $modulate || $blend || $scale ) {
slouken@1985
   510
                    output_copyfunc($src, $dst, $modulate, $blend, $scale);
slouken@1985
   511
                }
slouken@1985
   512
            }
slouken@1985
   513
        }
slouken@1985
   514
    }
slouken@1985
   515
}
slouken@1985
   516
slouken@2262
   517
open_file("SDL_blit_auto.h");
slouken@1985
   518
output_copydefs();
slouken@1985
   519
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   520
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   521
        output_copyfunc_h($src_formats[$i], $dst_formats[$j]);
slouken@1985
   522
    }
slouken@1985
   523
}
slouken@1985
   524
print FILE "\n";
slouken@2262
   525
close_file("SDL_blit_auto.h");
slouken@1985
   526
slouken@2262
   527
open_file("SDL_blit_auto.c");
slouken@1985
   528
output_copyinc();
slouken@1985
   529
for (my $i = 0; $i <= $#src_formats; ++$i) {
slouken@1985
   530
    for (my $j = 0; $j <= $#dst_formats; ++$j) {
slouken@1985
   531
        output_copyfunc_c($src_formats[$i], $dst_formats[$j]);
slouken@1985
   532
    }
slouken@1985
   533
}
slouken@2263
   534
output_copyfunctable();
slouken@2262
   535
close_file("SDL_blit_auto.c");