src/video/sdlgenblit.pl
changeset 1989 5b5f5de5433f
parent 1985 8055185ae4ed
child 1992 7387e0514595
     1.1 --- a/src/video/sdlgenblit.pl	Mon Aug 28 04:39:37 2006 +0000
     1.2 +++ b/src/video/sdlgenblit.pl	Mon Aug 28 14:10:46 2006 +0000
     1.3 @@ -125,9 +125,10 @@
     1.4      print FILE <<__EOF__;
     1.5  #define SDL_RENDERCOPY_MODULATE_COLOR   0x0001
     1.6  #define SDL_RENDERCOPY_MODULATE_ALPHA   0x0002
     1.7 -#define SDL_RENDERCOPY_BLEND            0x0010
     1.8 -#define SDL_RENDERCOPY_ADD              0x0020
     1.9 -#define SDL_RENDERCOPY_MOD              0x0040
    1.10 +#define SDL_RENDERCOPY_MASK             0x0010
    1.11 +#define SDL_RENDERCOPY_BLEND            0x0020
    1.12 +#define SDL_RENDERCOPY_ADD              0x0040
    1.13 +#define SDL_RENDERCOPY_MOD              0x0080
    1.14  #define SDL_RENDERCOPY_NEAREST          0x0100
    1.15  
    1.16  typedef struct {
    1.17 @@ -214,19 +215,35 @@
    1.18      my $dst = shift;
    1.19      my $modulate = shift;
    1.20      my $blend = shift;
    1.21 +    my $s = "";
    1.22 +    my $d = "";
    1.23 +
    1.24 +    # Nice and easy...
    1.25 +    if ( $src eq $dst && !$modulate && !$blend ) {
    1.26 +        print FILE <<__EOF__;
    1.27 +            *dst = *src;
    1.28 +__EOF__
    1.29 +        return;
    1.30 +    }
    1.31 +        
    1.32 +    if ( $blend ) {
    1.33 +        get_rgba("src", $src);
    1.34 +        get_rgba("dst", $dst);
    1.35 +        $s = "src";
    1.36 +        $d = "dst";
    1.37 +    } else {
    1.38 +        get_rgba("", $src);
    1.39 +    }
    1.40 +
    1.41      if ( $modulate ) {
    1.42          print FILE <<__EOF__;
    1.43              if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
    1.44 -                ${src}R = (${src}R * modulateR) / 255;
    1.45 -                ${src}G = (${src}G * modulateG) / 255;
    1.46 -                ${src}B = (${src}B * modulateB) / 255;
    1.47 +                ${s}R = (${s}R * modulateR) / 255;
    1.48 +                ${s}G = (${s}G * modulateG) / 255;
    1.49 +                ${s}B = (${s}B * modulateB) / 255;
    1.50              }
    1.51 -__EOF__
    1.52 -    }
    1.53 -    if ( $modulate && $blend ) {
    1.54 -        print FILE <<__EOF__;
    1.55              if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
    1.56 -                ${src}A = (${src}A * modulateA) / 255;
    1.57 +                ${s}A = (${s}A * modulateA) / 255;
    1.58              }
    1.59  __EOF__
    1.60      }
    1.61 @@ -234,29 +251,43 @@
    1.62          print FILE <<__EOF__;
    1.63              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
    1.64                  /* This goes away if we ever use premultiplied alpha */
    1.65 -                ${src}R = (${src}R * ${src}A) / 255;
    1.66 -                ${src}G = (${src}G * ${src}A) / 255;
    1.67 -                ${src}B = (${src}B * ${src}A) / 255;
    1.68 +                if (${s}A < 255) {
    1.69 +                    ${s}R = (${s}R * ${s}A) / 255;
    1.70 +                    ${s}G = (${s}G * ${s}A) / 255;
    1.71 +                    ${s}B = (${s}B * ${s}A) / 255;
    1.72 +                }
    1.73              }
    1.74 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    1.75 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    1.76 +            case SDL_RENDERCOPY_MASK:
    1.77 +                if (${s}A) {
    1.78 +                    ${d}R = ${s}R;
    1.79 +                    ${d}G = ${s}G;
    1.80 +                    ${d}B = ${s}B;
    1.81 +                }
    1.82 +                break;
    1.83              case SDL_RENDERCOPY_BLEND:
    1.84 -                ${dst}R = ${src}R + ((255 - ${src}A) * ${dst}R) / 255;
    1.85 -                ${dst}G = ${src}G + ((255 - ${src}A) * ${dst}G) / 255;
    1.86 -                ${dst}B = ${src}B + ((255 - ${src}A) * ${dst}B) / 255;
    1.87 +                ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255;
    1.88 +                ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255;
    1.89 +                ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255;
    1.90                  break;
    1.91              case SDL_RENDERCOPY_ADD:
    1.92 -                ${dst}R = ${src}R + ${dst}R; if (${dst}R > 255) ${dst}R = 255;
    1.93 -                ${dst}G = ${src}G + ${dst}G; if (${dst}G > 255) ${dst}G = 255;
    1.94 -                ${dst}B = ${src}B + ${dst}B; if (${dst}B > 255) ${dst}B = 255;
    1.95 +                ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
    1.96 +                ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255;
    1.97 +                ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255;
    1.98                  break;
    1.99              case SDL_RENDERCOPY_MOD:
   1.100 -                ${dst}R = (${src}R * ${dst}R) / 255;
   1.101 -                ${dst}G = (${src}G * ${dst}G) / 255;
   1.102 -                ${dst}B = (${src}B * ${dst}B) / 255;
   1.103 +                ${d}R = (${s}R * ${d}R) / 255;
   1.104 +                ${d}G = (${s}G * ${d}G) / 255;
   1.105 +                ${d}B = (${s}B * ${d}B) / 255;
   1.106                  break;
   1.107              }
   1.108  __EOF__
   1.109      }
   1.110 +    if ( $blend ) {
   1.111 +        set_rgba("dst", $dst);
   1.112 +    } else {
   1.113 +        set_rgba("", $dst);
   1.114 +    }
   1.115  }
   1.116  
   1.117  sub output_copyfunc
   1.118 @@ -325,20 +356,7 @@
   1.119          print FILE <<__EOF__;
   1.120              }
   1.121  __EOF__
   1.122 -        if ( $blend ) {
   1.123 -            get_rgba("src", $src);
   1.124 -            get_rgba("dst", $dst);
   1.125 -            output_copycore("src", "dst", $modulate, $blend);
   1.126 -            set_rgba("dst", $dst);
   1.127 -        } elsif ( $modulate || $src ne $dst ) {
   1.128 -            get_rgba("", $src);
   1.129 -            output_copycore("", "", $modulate, $blend);
   1.130 -            set_rgba("", $dst);
   1.131 -        } else {
   1.132 -            print FILE <<__EOF__;
   1.133 -            *dst = *src;
   1.134 -__EOF__
   1.135 -        }
   1.136 +        output_copycore($src, $dst, $modulate, $blend);
   1.137          print FILE <<__EOF__;
   1.138              posx += incx;
   1.139              ++dst;
   1.140 @@ -356,20 +374,7 @@
   1.141          int n = data->dst_w;
   1.142          while (n--) {
   1.143  __EOF__
   1.144 -        if ( $blend ) {
   1.145 -            get_rgba("src", $src);
   1.146 -            get_rgba("dst", $dst);
   1.147 -            output_copycore("src", "dst", $modulate, $blend);
   1.148 -            set_rgba("dst", $dst);
   1.149 -        } elsif ( $modulate || $src ne $dst ) {
   1.150 -            get_rgba("", $src);
   1.151 -            output_copycore("", "", $modulate, $blend);
   1.152 -            set_rgba("", $dst);
   1.153 -        } else {
   1.154 -            print FILE <<__EOF__;
   1.155 -            *dst = *src;
   1.156 -__EOF__
   1.157 -        }
   1.158 +        output_copycore($src, $dst, $modulate, $blend);
   1.159          print FILE <<__EOF__;
   1.160              ++src;
   1.161              ++dst;