public override void EncodeToFile( Stream input, string fileName, object codecData )
{
ImageData data = (ImageData)codecData;
// save the image to file
SDI.PixelFormat pf;
int bpp;
switch ( data.format )
{
case Axiom.Media.PixelFormat.B8G8R8:
pf = SDI.PixelFormat.Format24bppRgb;
bpp = 3;
break;
case Axiom.Media.PixelFormat.A8B8G8R8:
pf = SDI.PixelFormat.Format32bppRgb;
bpp = 4;
break;
default:
throw new ArgumentException( "Unsupported Pixel Format " + data.format );
}
Bitmap image = new Bitmap( data.width, data.height, pf );
//Create a BitmapData and Lock all pixels to be written
SDI.BitmapData imagedta = image.LockBits(
new Rectangle( 0, 0, image.Width, image.Height ),
SDI.ImageLockMode.WriteOnly, image.PixelFormat );
byte[] buffer = new byte[ input.Length ];
input.Read( buffer, 0, buffer.Length );
for ( int c = 0; c < buffer.Length - bpp; c += bpp )
{
byte tmp = buffer[ c ];
buffer[ c ] = buffer[ c + 2 ];
buffer[ c + 2 ] = tmp;
}
//Copy the data from the byte array into BitmapData.Scan0
Marshal.Copy( buffer, 0, imagedta.Scan0, buffer.Length );
//Unlock the pixels
image.UnlockBits( imagedta );
image.Save( fileName, ConvertImageFormat( fileName ) );
}