I'm new to MagickWand, and am trying to read an 8-bit per channel image using the code I wrote (see below). While it seems to be able to read 16-bits per channel images perfectly, it appears to convert the 8-bit data into 16-bits. Am I missing something?
I'm using a test image at http://www.astro.lsa.umich.edu/~dmaitra/tt.tif
Here's the convert output
Code: Select all
$ convert tt.tif txt:-
# ImageMagick pixel enumeration: 3,2,255,rgb
0,0: ( 0, 0, 0) #000000 black
1,0: ( 1, 0, 0) #010000 rgb(1,0,0)
2,0: ( 2, 0, 0) #020000 rgb(2,0,0)
0,1: (255,255, 0) #FFFF00 yellow
1,1: (255,255,255) #FFFFFF white
2,1: ( 0, 0, 0) #000000 black
$
Code: Select all
$ ./minimal tt.tif
wd=3 ht=2 depth=8
0 0 => 0 0 0
1 0 => 257 0 0
2 0 => 514 0 0
0 1 => 65535 65535 0
1 1 => 65535 65535 65535
2 1 => 0 0 0
$
Code: Select all
/*
gcc `MagickWand-config --cflags --cppflags` -o minimal minimal.c \
`MagickWand-config --ldflags --libs` -lm -Wall -W -Wextra -g \
*/
/* Includes and functions */ /*{{{*/
#include <math.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>
/* For some reason this is not defined in the .h headers!!! */
void PixelGetMagickColor (const PixelWand *, MagickPixelPacket *);
/*}}}*/
int main(int argc,char **argv)/*{{{*/
{
/* Define ThrowWandException */ /*{{{*/
#define ThrowWandException(wand) \
{ \
char \
*description; \
\
ExceptionType \
severity; \
\
description=MagickGetException(wand,&severity); \
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
description=(char *) MagickRelinquishMemory(description); \
exit(-1); \
}/*}}}*/
/* Declare variables and stuff */ /*{{{*/
unsigned long wd, ht, x, y;
int dp;
MagickBooleanType status;
MagickPixelPacket pixel;
MagickWand *image_wand;
PixelIterator *iterator;
PixelWand **pixels;
/*}}}*/
if (argc != 2){/*{{{*/
(void) fprintf(stdout,"Usage: %s image\n",argv[0]);
exit(0);
}/*}}}*/
/* Read an image, get dimensions */ /*{{{*/
MagickWandGenesis();
image_wand=NewMagickWand();
status=MagickReadImage(image_wand,argv[1]);
if (status == MagickFalse) ThrowWandException(image_wand);
wd = (unsigned long)MagickGetImageWidth(image_wand);
ht = (unsigned long)MagickGetImageHeight(image_wand);
dp = (int)MagickGetImageDepth(image_wand);
printf("wd=%lu ht=%lu depth=%d\n",wd,ht,dp);
/*}}}*/
/* Get pixel values */ /*{{{*/
iterator=NewPixelIterator(image_wand);
if (iterator == (PixelIterator *)NULL) ThrowWandException(image_wand);
for (y=0; y<ht; y++){
pixels=PixelGetNextIteratorRow(iterator,&wd);
if (pixels == (PixelWand **)NULL) break;
for (x=0; x<wd; x++){
PixelGetMagickColor(pixels[x],&pixel);
printf("%lu %lu => %g %g %g\n",x,y,pixel.red,
pixel.green,pixel.blue);
}
}/*}}}*/
iterator=DestroyPixelIterator(iterator);
/* Clean up */ /*{{{*/
image_wand=DestroyMagickWand(image_wand);
MagickWandTerminus();
/*}}}*/
return 0;
}/*}}}*/
Thanks,
Dipankar