Page 1 of 1

bit per pixel

Posted: 2009-06-09T07:59:39-07:00
by EdMarsh
Helo,

I just started using imagemagick and I end up with something strange...

put it simply if i try to do something really simple

Magick::Image image( "C:\\ds.bmp" ); ( ds.bmp is a 8bpp grayscale image )
image.write( "C:\\ds_test.bmp" );

when I load it to a imagemagick image, the image.depth() return 8 (good), the image.type() return GrayscaleType (good too)

but when i save the image, a obtain a 32 bits-per-pixel image. Is there a way to force the write function to write a 8bpp image?

Thanks.

Re: bit per pixel

Posted: 2009-06-10T01:14:00-07:00
by anthony
IM Examples, Common File Formats, BMP raw notes, has the answers you want

http://www.imagemagick.org/Usage/formats/#bmp

Re: bit per pixel

Posted: 2009-06-10T09:52:05-07:00
by EdMarsh
Thanks Anthony, but it do not solve my problem in my code. I do not use the command line I use code.

I have finaly found a way to read and save a 8bpp BMP image and save it as a 8bpp image

Magick::Image image( "C:\\ds.bmp" ); //8 bpp bmp image
image.compressType(Magick::NoCompression);
image.write( "C:\\ds_test.bmp" ); //8 bpp bmp image _ good!


Now the problem is, if I load that 8bpp bmp file and apply the resize function on it, it end up at 24bpp...


CODE EXEMPLE with comment :



Magick::Image image( "C:\\ds.bmp" ); // (8bpp bmp file - 2541 kb)
Magick::Geometry geo;

int imgDepth = image.depth(); // (got 8 - good)
MagickLib::ImageType imgType = image.type(); //(got GrayscaleType -- good)
std::string imgMAgick = image.magick(); //(got "BMP" -- good)

MagickLib::ColorspaceType imgCS = image.colorSpace(); //(got RGBColorspace -- hummm why?)
image.colorSpace( MagickLib::GRAYColorspace );
imgCS = image.colorSpace(); //(still go RGBColorspace -- why?)

MagickLib::ColorspaceType imgCsT = image.colorspaceType(); //(got UndefinedColorspace .... )
image.colorspaceType( MagickLib::GRAYColorspace );
imgCsT = image.colorspaceType(); //(got GRAYColorspace - ok)

int imgCMS = image.colorMapSize(); //(got 256 -- good)
image.compressType(Magick::NoCompression);


//resize image//////////////////////////////
geo = image.size();
geo.width( (unsigned int) ((double) geo.width() * 1.1) );
geo.height( (unsigned int) ((double) geo.height() * 1.1) );

image.filterType( MagickLib::CubicFilter );
image.resize( geo );
////////////////////////////////////////////


image.write( "C:\\ds_rs.bmp" ); //end up with a 24bpp 9201 kb


////////////////


Ok, so does some one know how to save or force the image.write function to write a 8bpp BMP.
Thanks.

Re: bit per pixel

Posted: 2009-06-10T10:00:34-07:00
by fmw42
I am no expert on bmp images, but read http://www.imagemagick.org/Usage/formats/#bmp

Re: bit per pixel

Posted: 2009-06-10T10:17:27-07:00
by EdMarsh
Hi fmw42,

http://www.imagemagick.org/Usage/formats/#bmp
describe think for command line, but even with that, one interesting think is:

"Add -colors 256 to the end your command line (before the output image filename) to create a 8 bit colormapped BMP image rather than a 24 bit BMP format. Extra colors can be added to images after performing operations like rotates, and resize. "



So in my code, to set the color to 256 it will be:
image.colorMapSize( 256 );

but it will not solve my problem... still end up with a 24bpp image after resizing. Any other idea, or reference for coder?

Thanks.

Re: bit per pixel

Posted: 2009-06-10T10:58:35-07:00
by fmw42
All I can say is there seems to be a fair amount of complaints recently about bmp format. Search the user, developer and bugs forums. I don't know if these are bugs are limitations or misinterpretations. I am having trouble converting from png to bmp8 myself and others cannot even get identify to work on some bmp images.

Sorry I don't know much about using APIs. I use the command line mostly and have little experience with bmp images in any case.

Re: bit per pixel

Posted: 2009-06-13T03:57:14-07:00
by anthony
EdMarsh wrote:Thanks Anthony, but it do not solve my problem in my code. I do not use the command line I use code.
Fair enough. However how a problem is solved on the command line will generally be the same solution for ANY of the ImageMagick APIs.