jargon

Alpha Index 255 glitch

Nov 27th, 2021
781
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // http://puzzlum.net/Roe_Web_Builder/mk11TILES.php
  3.  
  4. <?php
  5.  
  6. function combotoc($path = 'bsaves/out' )
  7. {
  8.     $nen=nen_ini();
  9.     $return = '';
  10.    
  11.     $toc = fasttoc( $path, array( '.png' ) );
  12.    
  13.     $toc_index = 0;
  14.     while($toc_index < count( $toc ))
  15.     {
  16.         $toc[ $toc_index ] = str_replace( '.png', '', $toc[ $toc_index ] );
  17.  
  18.         $toc[ $toc_index ] = substr($toc[ $toc_index ], 0, strlen( $toc[ $toc_index ] ) - 4 );
  19.        
  20.         $return.= '<tr><td><h3>'. htmlentities( $toc[ $toc_index ] ). '</h3></td><td style="background-color:springgreen;">'. combo( $toc[ $toc_index ], 127 ). '</td></tr>';
  21.        
  22.         if( $toc_index < count( $toc ) - 1 )
  23.         {
  24.             $toc_index++;
  25.         }
  26.         else
  27.         {
  28.             break;
  29.         }
  30.     }
  31.     return '<table>'.$return.'</table>';
  32. }
  33.  
  34. function combo($filename='dtbykick', $alpha = 127 )
  35. {
  36.     $nen = nen_ini();
  37.     $vga = vga_ini();
  38.     $return = '';
  39.    
  40.     $return.= '<img src="./bsaves/out/'. $filename. '.24x.png">';
  41.    
  42.     $image[ 'rgb' ] = imagecreatefrompng( $nen['root']. 'bsaves/out/'. $filename. '.24x.png' );
  43.    
  44.     $return.= '<img src="./bsaves/out/'. $filename. '.24y.png">';
  45.    
  46.     $image[ 'mask' ] = imagecreatefrompng(  $nen['root']. 'bsaves/out/'. $filename. '.24y.png' );
  47.        
  48.     $image [ 'combo' ] = imagecreatetruecolor( imagesx( $image[ 'rgb' ] ), imagesy( $image[ 'rgb' ] ) );
  49.  
  50.     imagetruecolortopalette( $image[ 'combo' ], false, 255 );
  51.     imagealphablending( $image[ 'combo' ], false );
  52.     imagesavealpha( $image[ 'combo' ], false );
  53.     for( $color = 0; $color < 256; $color++ )
  54.     {
  55.         $vga[ 'color' ][ $color ] = imagecolorallocate(
  56.         $image[ 'combo' ],
  57.         ( $vga[ 'table' ][ $color ] >> 16 ) & 0xFF,
  58.         ( $vga[ 'table' ][ $color ] >> 8 ) & 0xFF,
  59.         ( $vga[ 'table' ][ $color ] >> 0 ) & 0xFF
  60.         );
  61.     }
  62.    
  63.     $vga[ 'color' ][ 255 ] = imagecolorallocatealpha(
  64.     $image[ 'combo' ],
  65.     ( $vga[ 'table' ][ 255 ] >> 16 ) & 0xFF,
  66.     ( $vga[ 'table' ][ 255 ] >> 8 ) & 0xFF,
  67.     ( $vga[ 'table' ][ 255 ] >> 0 ) & 0xFF,
  68.     127
  69.     );
  70.  
  71.     imagefill( $image[ 'combo' ], 0, 0, $vga[ 'color' ][ 255 ] );
  72.    
  73.     $width = imagesx( $image[ 'combo' ] );
  74.     $height = imagesy( $image[ 'combo' ] );
  75.  
  76.     //loop through width and height of source image
  77.     $row=0;
  78.     while( $row < $height )
  79.     {
  80.         $col=0;
  81.         while( $col < $width )
  82.         {
  83.            
  84.             //get color in image $image[ 'mask' ] at pixel ($col, $row)
  85.            
  86.             $pix[ 'mask' ] = imagecolorat( $image[ 'mask' ], $col, $row );
  87.  
  88.             //get color in image $image[ 'rgb' ] at pixel ($col, $row)
  89.            
  90.             $pix[ 'rgb' ] = imagecolorat( $image[ 'rgb' ], $col, $row );
  91.            
  92.             //if pixel in $image['mask'] at ($cow, $row) is white:
  93.                  
  94.             if ( $pix[ 'mask' ] === $vga[ 'color' ][ 15 ] )
  95.             {
  96.                 //set pixel based on Mask layer's ($col, $row) as fully transparent
  97.                 $pix[ 'combo' ] = $vga[ 'color' ][ 255 ];
  98.             }
  99.             //else
  100.             else
  101.             {              
  102.                 //set pixel based on RGB layer's ($col, $row) with full opacity
  103.                 $pix[ 'combo' ] = $pix[ 'rgb' ];           
  104.             }
  105.            
  106.             //assign pixel data to $image['combo'] at ($col , $row)
  107.             imagesetpixel( $image[ 'combo' ], $col, $row, ( $pix[ 'combo' ] % 256 ) + 1 );
  108.            
  109.             if( $col === $width - 1 )
  110.             {
  111.                 break;
  112.             }  
  113.             $col++;
  114.         }
  115.         if( $row === $height - 1 )
  116.         {
  117.             break;
  118.         }
  119.         $row++;
  120.     }
  121.    
  122.     //save resulting image as new file 
  123.     imagepng( $image[ 'combo' ], $nen['root']. 'bsaves/combo/'. $filename. '.png' );
  124.    
  125.     $return.= '<img src="./bsaves/combo/'. $filename. '.png">';
  126.    
  127.     return $return;
  128. }
  129.  
  130. function alphaColor($hexColor,$alpha)
  131. {
  132.         return bindec(decbin($alpha).decbin(hexdec($hexColor)));
  133. }
  134.  
  135. ?>
RAW Paste Data