bit per pixel

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
EdMarsh

bit per pixel

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: bit per pixel

Post by anthony »

IM Examples, Common File Formats, BMP raw notes, has the answers you want

http://www.imagemagick.org/Usage/formats/#bmp
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
EdMarsh

Re: bit per pixel

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bit per pixel

Post by fmw42 »

I am no expert on bmp images, but read http://www.imagemagick.org/Usage/formats/#bmp
EdMarsh

Re: bit per pixel

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bit per pixel

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: bit per pixel

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply