Issue using an Image to resize a 1-bit (two colour) mask in DIB format
Julian Male <[email protected]>
| Newsgroups | gmane.comp.video.graphicsmagick.help |
|---|---|
| Message-ID | <HE1PR05MB1515E076FE12539469227131E33F0@HE1PR05MB1515.eurprd05.prod.outlook.com> |
Hi,
We are using DIBs as an internal format. I am using GraphicsMagick v1.3.19.
My issue occurs when I try to resize a 1-bit mask DIB, when I write it back out to a DIB it has become an 8-bit image with multiple colours.
Debugging through the source would seem to suggest that the GM internal image is ok upto the point the image.write( blob) function is called.
Any ideas ?
See source snippets below for details:
// GM Image & Blob objects to do the conversion work
Blob blob( m_imageDib, dibSize );
Image image( blob );
Int srcBitCount = m_imageDib->m_biBitCount;
if ( srcBitCount == 1 )
{
// Force to monochrome
image.monochrome(true);
image.classType( PseudoClass );
image.depth(1);
}
if ( !image.isValid() )
{
Dbg::msg( "GraphicsMagickTrash::resize() GraphicsMagick INVALID IMAGE\n" );
m_valid = false;
return TRASH_InvalidRaster;
}
// Create GM Geometry object
Geometry geom( width, height );
// Determine Filter Type
FilterTypes filter = CatromFilter;
switch ( interpolation )
{
case TRASH_NoInterpolation:
filter = BoxFilter;
Dbg::msg("GraphicsMagickTrash::resize using GraphicsMagick TRASH_NoInterpolation - BoxFilter\n" );
break;
case TRASH_AveragingInterpolation:
filter = BoxFilter;
Dbg::msg("GraphicsMagickTrash::resize using GraphicsMagick TRASH_AveragingInterpolation - BoxFilter\n" );
break;
case TRASH_BicubicInterpolation:
filter = LanczosFilter;
Dbg::msg("GraphicsMagickTrash::resize using GraphicsMagick TRASH_BicubicInterpolation - LanczosFilter\n" );
break;
case TRASH_Advanced4x4:
filter = SincFilter;
Dbg::msg("GraphicsMagickTrash::resize using GraphicsMagick TRASH_Advanced4x4 - SincFilter\n" );
break;
default:
filter = CatromFilter;
Dbg::msg("GraphicsMagickTrash::resize using GraphicsMagick default - CatRomFilter\n" );
break;
}
// Resize image
if ( srcBitCount == 1 )
{
image.resize( geom );
}
else
{
image.resize( geom, filter );
}
if ( srcBitCount == 1 )
{
// Force back to monochrome
// image.classType( PseudoClass );
// image.quantizeColors( 2 );
image.monochrome(true);
image.depth(1);
Dbg::msg("GraphicsMagickTrash::resize using GraphicsMagick forcing back to Monochrome\n" );
}
// Now need to put back into m_imageDib
// First free up what exists
if ( m_imageDib )
{
free( m_imageDib );
m_imageDib = NULL;
m_valid = false;
}
// Write to memory
// setImage( image );
image.write( &blob );
size_t blobOutSize = blob.length();
m_imageDib = ( TRASHDIB* )malloc( blobOutSize );
memcpy( m_imageDib, blob.data(), blobOutSize );
DEBUG_ONLY( debugDIB( m_imageDib ); )
m_valid = true;
Thanks.
Julian
------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Graphicsmagick-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-help