src/video/sdlgenblit.pl
changeset 8659 d3a9836732ea
parent 8149 681eb46b8ac4
child 8661 e9e62c8fffb6
     1.1 --- a/src/video/sdlgenblit.pl	Thu Mar 20 17:00:33 2014 -0400
     1.2 +++ b/src/video/sdlgenblit.pl	Thu Mar 20 17:55:24 2014 -0400
     1.3 @@ -58,12 +58,22 @@
     1.4      "BGRA8888" => "Uint32",
     1.5  );
     1.6  
     1.7 +my %get_rgba_string_ignore_alpha = (
     1.8 +    "RGB888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
     1.9 +    "BGR888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
    1.10 +    "ARGB8888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
    1.11 +    "RGBA8888" => "_R = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _B = (Uint8)(_pixel >> 8);",
    1.12 +    "ABGR8888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
    1.13 +    "BGRA8888" => "_B = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _R = (Uint8)(_pixel >> 8);",
    1.14 +);
    1.15 +
    1.16  my %get_rgba_string = (
    1.17 -    "RGB888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel; _A = 0xFF;",
    1.18 -    "BGR888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel; _A = 0xFF;", "ARGB8888" => "_A = (Uint8)(_pixel >> 24); _R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
    1.19 -    "RGBA8888" => "_R = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _B = (Uint8)(_pixel >> 8); _A = (Uint8)_pixel;",
    1.20 -    "ABGR8888" => "_A = (Uint8)(_pixel >> 24); _B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
    1.21 -    "BGRA8888" => "_B = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _R = (Uint8)(_pixel >> 8); _A = (Uint8)_pixel;",
    1.22 +    "RGB888" => $get_rgba_string_ignore_alpha{"RGB888"} . " _A = 0xFF;",
    1.23 +    "BGR888" => $get_rgba_string_ignore_alpha{"BGR888"} . " _A = 0xFF;",
    1.24 +    "ARGB8888" => $get_rgba_string_ignore_alpha{"ARGB8888"} . " _A = (Uint8)(_pixel >> 24);",
    1.25 +    "RGBA8888" => $get_rgba_string_ignore_alpha{"RGBA8888"} . " _A = (Uint8)_pixel;",
    1.26 +    "ABGR8888" => $get_rgba_string_ignore_alpha{"ABGR8888"} . " _A = (Uint8)(_pixel >> 24);",
    1.27 +    "BGRA8888" => $get_rgba_string_ignore_alpha{"BGRA8888"} . " _A = (Uint8)_pixel;",
    1.28  );
    1.29  
    1.30  my %set_rgba_string = (
    1.31 @@ -160,7 +170,15 @@
    1.32  {
    1.33      my $prefix = shift;
    1.34      my $format = shift;
    1.35 -    my $string = $get_rgba_string{$format};
    1.36 +    my $ignore_alpha = shift;
    1.37 +
    1.38 +    my $string;
    1.39 +    if ($ignore_alpha) {
    1.40 +        $string = $get_rgba_string_ignore_alpha{$format};
    1.41 +    } else {
    1.42 +        $string = $get_rgba_string{$format};
    1.43 +    }
    1.44 +
    1.45      $string =~ s/_/$prefix/g;
    1.46      if ( $prefix ne "" ) {
    1.47          print FILE <<__EOF__;
    1.48 @@ -196,6 +214,7 @@
    1.49      my $blend = shift;
    1.50      my $s = "";
    1.51      my $d = "";
    1.52 +    my $ignore_dst_alpha = 0;
    1.53  
    1.54      # Nice and easy...
    1.55      if ( $src eq $dst && !$modulate && !$blend ) {
    1.56 @@ -205,13 +224,17 @@
    1.57          return;
    1.58      }
    1.59  
    1.60 +    if (not $dst =~ /A/) {
    1.61 +        $ignore_dst_alpha = !$blend;
    1.62 +    }
    1.63 +
    1.64      if ( $blend ) {
    1.65 -        get_rgba("src", $src);
    1.66 -        get_rgba("dst", $dst);
    1.67 +        get_rgba("src", $src, $ignore_dst_alpha);
    1.68 +        get_rgba("dst", $dst, $ignore_dst_alpha);
    1.69          $s = "src";
    1.70          $d = "dst";
    1.71      } else {
    1.72 -        get_rgba("", $src);
    1.73 +        get_rgba("", $src, $ignore_dst_alpha);
    1.74      }
    1.75  
    1.76      if ( $modulate ) {
    1.77 @@ -221,10 +244,14 @@
    1.78                  ${s}G = (${s}G * modulateG) / 255;
    1.79                  ${s}B = (${s}B * modulateB) / 255;
    1.80              }
    1.81 +__EOF__
    1.82 +        if (not $ignore_dst_alpha) {
    1.83 +            print FILE <<__EOF__;
    1.84              if (flags & SDL_COPY_MODULATE_ALPHA) {
    1.85                  ${s}A = (${s}A * modulateA) / 255;
    1.86              }
    1.87  __EOF__
    1.88 +        }
    1.89      }
    1.90      if ( $blend ) {
    1.91          print FILE <<__EOF__;
    1.92 @@ -306,6 +333,23 @@
    1.93      int srcy, srcx;
    1.94      int posy, posx;
    1.95      int incy, incx;
    1.96 +__EOF__
    1.97 +
    1.98 +    # !!! FIXME: the script should just exclude in these cases.
    1.99 +    if ( (!$blend) && ($modulate || $src ne $dst) ) {
   1.100 +        print FILE <<__EOF__;
   1.101 +    (void) A;  /* not all formats use alpha. */
   1.102 +__EOF__
   1.103 +    }
   1.104 +
   1.105 +    # !!! FIXME: the script should just exclude in these cases.
   1.106 +    if ( $modulate ) {
   1.107 +        print FILE <<__EOF__;
   1.108 +    (void) modulateA;  /* not all formats use alpha. */
   1.109 +__EOF__
   1.110 +    }
   1.111 +
   1.112 +    print FILE <<__EOF__;
   1.113  
   1.114      srcy = 0;
   1.115      posy = 0;
   1.116 @@ -343,6 +387,20 @@
   1.117      }
   1.118  __EOF__
   1.119      } else {
   1.120 +        # !!! FIXME: the script should just exclude in these cases.
   1.121 +        if ( (!$blend) && ($modulate || $src ne $dst) ) {
   1.122 +            print FILE <<__EOF__;
   1.123 +    (void) A;  /* not all formats use alpha. */
   1.124 +__EOF__
   1.125 +        }
   1.126 +
   1.127 +        # !!! FIXME: the script should just exclude in these cases.
   1.128 +        if ( $modulate ) {
   1.129 +            print FILE <<__EOF__;
   1.130 +    (void) modulateA;  /* not all formats use alpha. */
   1.131 +__EOF__
   1.132 +        }
   1.133 +
   1.134          print FILE <<__EOF__;
   1.135  
   1.136      while (info->dst_h--) {