Beispiel #1
0
 // Process a source image file
 prImg proc( prImg org )
 {
     if( _opts.mipCount != 0 ) {
     if (org.mips == null)
       org.mips = new List<Image>();
     for( int mipLevel = 1, // a modest for loop
      f = (int)Math.Pow(2,mipLevel),
      w = org.mips[0].Width / f,
      h = org.mips[0].Height / f;
      w != 0 && h != 0;
      mipLevel++,
      f = (int) Math.Pow(2, mipLevel),
      w = org.mips[0].Width / f,
      h = org.mips[0].Height / f ) {
       Bitmap mipImg = new Bitmap( w, h );
       Graphics gtemp = Graphics.FromImage( mipImg );
       gtemp.InterpolationMode = _opts.mode;
       gtemp.DrawImage( org.mips[0], new Rectangle( 0, 0, w, h ) );
       gtemp.Dispose();
       org.mips.Add( mipImg );
     }
       }
       if( Processed != null )
     Processed( this, new ImageEventArgs( org.id, org.file ));
       return org;
 }
Beispiel #2
0
 // Generate empty mipmaps for the image
 void prepMips( prImg img )
 {
     for (int mipLevel = 1, // mega for-loop
        f = (int) Math.Pow( 2, mipLevel ),
        w = img.mips[0].Width / f,
        h = img.mips[0].Height / f;
        w != 0 && h != 0;
        mipLevel++,
        f = (int) Math.Pow( 2, mipLevel ),
        w = img.mips[0].Width / f,
        h = img.mips[0].Height / f) {
     Bitmap mipImg = new Bitmap( w, h );
     img.mips.Add( mipImg );
       }
 }
Beispiel #3
0
 // Add a processed image file to the atlas
 prImg merge( prImg acc, prImg inst )
 {
     int mip = 0;
       //inst.mips.Select(bmp => { return copyMip(mip++, inst, acc); });
       foreach (Image bmp in inst.mips) { copyMip(mip++, inst, acc); }
       if( Packed != null )
     Packed( this, new ImageEventArgs( inst.id, inst.file ) );
       return acc;
 }
Beispiel #4
0
 // Prepare the atlas
 prImg prep( string file )
 {
     var img = new Bitmap( Math.Min(_count, _opts.magnitude.Width) * _texSize.Width,
                     (1 + (_count / _opts.magnitude.Width)) * _texSize.Height );
       var pimg = new prImg( file, img, -1 );
       prepMips( pimg );
       return pimg;
 }
Beispiel #5
0
 // Copy a specific mip-level from the source image to the atlas
 Image copyMip( int mipLevel, prImg src, prImg dest )
 {
     Graphics g = Graphics.FromImage( dest.mips[ mipLevel ] );
       int w = src.mips[ mipLevel ].Width, h = src.mips[ mipLevel ].Height;
       g.InterpolationMode = _opts.mode;
       g.DrawImage( src.mips[ mipLevel ], (src.id % _opts.magnitude.Width) * w, (src.id / _opts.magnitude.Width) * h );
       g.Dispose();
       return src.mips[ mipLevel ];
 }