Page 1 of 1

use MagickExportImagePixels after transform

Posted: 2011-03-10T16:10:28-07:00
by inx
hello.

i have a problem when i use MagickExportImagePixels after a MagickResizeImage...
the input is a color image RGB 8bit, the outcome is a grayscalish-image with some color-lines, and the image is sheared...
using the code below:

Code: Select all

size_t width,height;
MagickBooleanType status;
MagickWand *magick_wand = NULL;
unsigned char *Buffer = NULL;

magick_wand = NewMagickWand();
MagickReadImage(magick_wand,"tt.jpg");

MagickResizeImage(magick_wand,774,518,LanczosFilter,1.0);

width = MagickGetImageWidth(magick_wand);
height = MagickGetImageHeight(magick_wand);
//correct size here: 774x518px

Buffer = malloc(3*width*height);

// Export the whole image
MagickExportImagePixels(magick_wand,0,0,width,height,"RGB",CharPixel,Buffer);

if i spare the transformation out, the image is colored and not sheared.

thanks for any help.
inx

Re: use MagickExportImagePixels after transform

Posted: 2011-03-10T17:03:50-07:00
by magick
Set the image depth to 8. If you are using the Q16 version of ImageMagick, the image depth is promoted from 8 to 16 when the image is resized.

Re: use MagickExportImagePixels after transform

Posted: 2011-03-10T17:11:41-07:00
by el_supremo
Your code looks OK.
What are the dimensions of the original (tt.jpg) image and what do you with the Buffer after MagickExportImagePixels?

Pete

Re: use MagickExportImagePixels after transform

Posted: 2011-03-11T01:20:25-07:00
by inx
Thanks for the answers.

I tried to set the depth of the image to 8, without any change...
after getting the pixel-data into the buffer, i use it as a open-gl texture.

the original size of my test-image is 280x271... but i also tried with an image of the size 4000x3000. same result in both cases

see the code below...

Code: Select all

size_t width,height;
MagickBooleanType status;
MagickWand *magick_wand = NULL;
unsigned char *Buffer = NULL;

magick_wand = NewMagickWand();
MagickReadImage(magick_wand,"tt.jpg");

MagickResizeImage(magick_wand,774,518,LanczosFilter,1.0);

width = MagickGetImageWidth(magick_wand);
height = MagickGetImageHeight(magick_wand);
//correct size here: 774x518px

Buffer = malloc(3*width*height);

//attempt to set Image depth
MagickSetImageDepth(magick_wand, 8);

// Export the whole image
MagickExportImagePixels(magick_wand,0,0,width,height,"RGB",CharPixel,Buffer);

//destroy the wand
magick_wand = DestroyMagickWand(magick_wand);

//make a texture
gluBuild2DMipmaps (GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_UNSIGNED_BYTE,  Buffer);
inx