Ejemplo n.º 1
0
/**
 * Utility method, creates the preview image bitmap and modifies the palette to
 * be a grayscale palette.
 * @param size Size of the image.
 * @param pixels The pixels.
 */
Gdiplus::Bitmap* PreviewControl::createPreview( const FitsLiberator::Size& size, Byte* pixels ) {
    Bitmap* previewImage = new Bitmap( size.width, size.height, size.width, PixelFormat8bppIndexed, pixels );
    UInt paletteSize = previewImage->GetPaletteSize();
    if( paletteSize > 0 ) {
        ColorPalette* palette = (ColorPalette*)malloc( paletteSize );
        previewImage->GetPalette( palette, paletteSize );
        for( UInt i = 0; i < palette->Count; i++ ) {
            palette->Entries[i] = Gdiplus::Color::MakeARGB( 0xFF, (Byte)i, (Byte)i, (Byte)i );
        }
        previewImage->SetPalette( palette );
        free( palette );
    }

    return previewImage;
}
Ejemplo n.º 2
0
/**
 * Utiliy method, creates a mask bitmap and modifes the palette accordingly.
 * @param size Size of the mask.
 * @param color Color of the mask.
 * @param pixels The pixels.
 */
Gdiplus::Bitmap* PreviewControl::createMask( const FitsLiberator::Size& size, const Gdiplus::Color& color, Byte* pixels ) {
    Bitmap* mask = new Bitmap( size.width, size.height, size.width, PixelFormat8bppIndexed, pixels );
    UInt paletteSize = mask->GetPaletteSize();
    if( paletteSize > 0 ) {
        ColorPalette* palette = (ColorPalette*)malloc( paletteSize );
        mask->GetPalette( palette, paletteSize );
        if( palette->Count >= 256 ) {
            palette->Entries[255] = 0;  // Transparent black
            palette->Entries[0]   = Gdiplus::Color::MakeARGB( 0xFF, color.GetR(), color.GetG(), color.GetB() );
        }
        mask->SetPalette( palette );
        free( palette );
    }   

    return mask;
}