public static ComplexImage FromBitmap( BitmapData imageData )
{
// check image format
if ( imageData.PixelFormat != PixelFormat.Format8bppIndexed )
{
throw new UnsupportedImageFormatException( "Source image can be graysclae (8bpp indexed) image only." );
}
// get source image size
int width = imageData.Width;
int height = imageData.Height;
int offset = imageData.Stride - width;
// check image size
if ( ( !Tools.IsPowerOf2( width ) ) || ( !Tools.IsPowerOf2( height ) ) )
{
throw new InvalidImagePropertiesException( "Image width and height should be power of 2." );
}
// create new complex image
ComplexImage complexImage = new ComplexImage( width, height );
Complex[,] data = complexImage.data;
// do the job
unsafe
{
byte* src = (byte*) imageData.Scan0.ToPointer( );
// for each line
for ( int y = 0; y < height; y++ )
{
// for each pixel
for ( int x = 0; x < width; x++, src++ )
{
data[y, x].Re = (float) *src / 255;
}
src += offset;
}
}
return complexImage;
}