24Bit BMP image treated as a 48Bits image?

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
cam
Posts: 12
Joined: 2013-11-29T23:24:10-07:00
Authentication code: 6789

24Bit BMP image treated as a 48Bits image?

Post by cam »

Hello,

This is my first time with ImageMagick. I read a 24bit BMP file (8 bits per channel) and when i iterate pixel by pixel the pixels are 16bits per channel. What is happening?

this is my code:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <wand/MagickWand.h>
#include <string.h>


int main(int argc,char **argv)
{
	MagickWand *imagen, *imagen_salida;
	PixelIterator *iterator;
	
	imagen = NewMagickWand();
	MagickReadImage(imagen,argv[1]);
	
	PixelWand **pixels;
	
	iterator = NewPixelIterator(imagen);
	
	MagickPixelPacket pixel;
	
	///////////
	register ssize_t x;
	size_t width;
	ssize_t y;
	///////////


	//******************ITERACION PIXEL POR PIXEL***********************
	for (y=0; y < (ssize_t) MagickGetImageHeight(imagen); y++)
	{
		pixels = PixelGetNextIteratorRow(iterator,&width);
		if (pixels == (PixelWand **) NULL) break;
		
		for (x=0; x < (ssize_t) width; x++)
		{
			PixelGetMagickColor(pixels[x],&pixel);
			
			pixel.red = 65535 - pixel.red;
			pixel.green = 65535 - pixel.green;
			pixel.blue = 65535 - pixel.blue;
			//pixel.index = SigmoidalContrast(pixel.index);
			//printf("\nr: %g", pixel.red);
			PixelSetMagickColor(pixels[x],&pixel);
		}
		(void) PixelSyncIterator(iterator);
	}
	//******************************************************************
	

	/* Write the image then destroy it. */
	MagickWriteImages(imagen,argv[2],MagickTrue);
	imagen = DestroyMagickWand(imagen);
	iterator = DestroyPixelIterator(iterator);
  
	MagickWandTerminus();
	
	return 0;
}

If i read a 24 bits image i think i should edit it like a 24 bits image. what can i do?

Thanks a lot!.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: 24Bit BMP image treated as a 48Bits image?

Post by dlemstra »

You are probably using the Q16 version of ImageMagick that uses 16 bits per channel. You can find a detailed explanation here: http://www.imagemagick.org/script/architecture.php
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
cam
Posts: 12
Joined: 2013-11-29T23:24:10-07:00
Authentication code: 6789

Re: 24Bit BMP image treated as a 48Bits image?

Post by cam »

Hi,

and how can i change my MagicWand version to Q8? Any idea?

Thank you very much
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: 24Bit BMP image treated as a 48Bits image?

Post by magick »

Set the image depth to 8 before you write it. That should fix the problem, the Q8 version of ImageMagick is not required.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: 24Bit BMP image treated as a 48Bits image?

Post by fmw42 »

convert image ...processing... -depth 8 result
cam
Posts: 12
Joined: 2013-11-29T23:24:10-07:00
Authentication code: 6789

Re: 24Bit BMP image treated as a 48Bits image?

Post by cam »

The image that i open is 24bits and the image that my code writes in disk is 24bits, but in pixel iterators i treat the image as it was 48bits (16bits per channel).

I want to treat the image as 24bits (0-255 for each channel, not 0-65535 for each channel) image.

Thank you very much for your time.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: 24Bit BMP image treated as a 48Bits image?

Post by dlemstra »

Can you explain why it is a problem that the pixel iterator has 16 bits per channel? And instead of modifying the pixels by yourself you could also call the MagickNegateImage method that does the same as what you are trying to do.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
cam
Posts: 12
Joined: 2013-11-29T23:24:10-07:00
Authentication code: 6789

Re: 24Bit BMP image treated as a 48Bits image?

Post by cam »

Hi,

I reinstalled imagemagick with Q8 option and now every image has 8bits per channel with this command in the instalation from console:

Code: Select all

./configure --with-quantum-depth=8
Thanks a lot.
Post Reply