BugInTheSYS

Untitled

Nov 29th, 2011
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 KB | None | 0 0
  1. // Version 1 (dereferenced by index)
  2.         for ( y = Math.Max( 0, Area.y ); y < Area.y + Area.height; y++ ) {
  3.           off_y = y - Area.y;
  4.           ptr = baseptr + y * _line + area_x * 4;
  5.           for ( x = area_x; x < Area.x + Area.width; x++ ) {
  6.             off_x = x - Area.x;
  7.             if ( ptr[3] != 0xFF ) {
  8.               CurrentPixel = _base[i].pixels[off_x, off_y];
  9.               alphaf = CurrentPixel.a;
  10.               if ( alphaf == 1.0f ) {
  11.                 ptr[0] = ( byte )( CurrentPixel.b * 255 );
  12.                 ptr[1] = ( byte )( CurrentPixel.g * 255 );
  13.                 ptr[2] = ( byte )( CurrentPixel.r * 255 );
  14.                 ptr[3] = ( byte )( alphaf * 255 );
  15.               } else if ( alphaf != 0.0f ) {
  16.                 alpha = ( byte )( alphaf * 255 );
  17.                 ptr[3] = alpha > ptr[3] ? alpha : ptr[3];
  18.                 ptr[2] = ( byte )( ptr[2] + alphaf * ( ( byte )( CurrentPixel.r * 255 ) - ptr[2] ) );
  19.                 ptr[1] = ( byte )( ptr[1] + alphaf * ( ( byte )( CurrentPixel.g * 255 ) - ptr[1] ) );
  20.                 ptr[0] = ( byte )( ptr[0] + alphaf * ( ( byte )( CurrentPixel.b * 255 ) - ptr[0] ) );
  21.               }
  22.             }
  23.             ptr += 4;
  24.           }
  25.         }
  26.  
  27. // Version 2 (dereferenced directly)
  28.         for ( y = Math.Max( 0, Area.y ); y < Area.y + Area.height; y++ ) {
  29.           off_y = y - Area.y;
  30.           ptr = baseptr + y * _line + area_x * 4;
  31.           for ( x = area_x; x < Area.x + Area.width; x++ ) {
  32.             off_x = x - Area.x;
  33.             if ( ptr[3] != 0xFF ) {
  34.               CurrentPixel = _base[i].pixels[off_x, off_y];
  35.               alphaf = CurrentPixel.a;
  36.               if ( alphaf == 1.0f ) {
  37.                 *ptr++ = ( byte )( CurrentPixel.b * 255 );
  38.                 *ptr++ = ( byte )( CurrentPixel.g * 255 );
  39.                 *ptr++ = ( byte )( CurrentPixel.r * 255 );
  40.                 *ptr++ = ( byte )( alphaf * 255 );
  41.               } else if ( alphaf != 0.0f ) {
  42.                 alpha = ( byte )( alphaf * 255 );
  43.                 *ptr++ = ( byte )( *ptr + alphaf * ( ( byte )( CurrentPixel.b * 255 ) - *ptr ) );
  44.                 *ptr++ = ( byte )( *ptr + alphaf * ( ( byte )( CurrentPixel.g * 255 ) - *ptr ) );
  45.                 *ptr++ = ( byte )( *ptr + alphaf * ( ( byte )( CurrentPixel.r * 255 ) - *ptr ) );
  46.                 *ptr++ = alpha > ptr[3] ? alpha : ptr[3];
  47.               } else {
  48.                 ptr += 4;
  49.               }
  50.             }
  51.           }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment