Page 1 of 1

Convert Image raw data of Unit8_t type to JPEG

Posted: 2019-08-26T15:31:22-07:00
by images
Hi

I am having raw data in an image buffer of uint8_t type. I am trying to convert this data to image format (JPG preferably). I am using MagickConstituteImage() to do this.

Code Snippet for reference:

Code: Select all

wand = NewMagickWand();
MagickConstituteImage(wand,2560,1600,"RGB",CharPixel,buffer);
MagickSetImageDepth(wand, 32);
MagickSetImageColorspace(wand, RGBColorspace);
MagickSetImageFormat(wand, "jpg");    
MagickSetImageExtent(wand, 1920, 1080));
MagickWriteImage(wand, "output.jpg");
ClearMagickWand(wand);
P.S buffer size is 2560 X 1600 x (32 >>3) (where 32 is the number of bits per pixel). I am setting the depth to 32 bits after I am using MagickConstituteImage()

I am able to get an image but its faded and looks like a grayscale image. I cannot create a blob using MagickReadImageBlob() before calling MagickConstituteImage() because there are no images in my wand at first. Any suggestions on how can I fix it or if my sequence of function calls is wrong?

Thanks

Re: Convert Image raw data of Unit8_t type to JPEG

Posted: 2019-08-26T15:45:26-07:00
by snibgo
What version of IM?

JPEG output will be 8 bits/channel/pixel. Setting the depth to 32 bits/channel/pixel is wrong, but may be harmless.

What the the encoding of your input? If (non-linear) sRGB, then don't set it to (linear) RGB.

You have no code that actually writes an output.

Re: Convert Image raw data of Unit8_t type to JPEG

Posted: 2019-08-26T16:09:13-07:00
by images
Thanks for your reply.

I have installed libmagickwand-dev - version (8:6.8.9.9-7ubuntu5.14).

I am new to this image processing so not really sure of the linear and non-linear RGB formats. However, I am capturing data from a Virtual Machine's screen via VGA port. So its is VGA frame buffer captured at multiple instants in time which I want to store as screenshots.

I am using MagickWriteImage(wand, "output.jpg"); to store my images.

Please find the updated code here:
wand = NewMagickWand();
MagickConstituteImage(wand,2560,1600,"RGB",CharPixel,buffer);
MagickSetImageDepth(wand, 32);
MagickSetImageColorspace(wand, RGBColorspace);
MagickSetImageFormat(wand, "jpg");
MagickSetImageExtent(wand, 1920, 1080));
MagickWriteImage(wand, "output.jpg");
ClearMagickWand(wand);

Re: Convert Image raw data of Unit8_t type to JPEG

Posted: 2019-08-26T21:10:07-07:00
by images
My issue got resolved. A small summary of the issue just in case if anybody else needs it.

The buffer I was sending in to MagickConstituteImage(), had image format as BGRP and Since i am using 32 BPP, it has 4 bytes for pixels (1 byte for R, B and G each and 1 additional reserved).

Code flow is as follows

Code: Select all

MagickConstituteImage() -> ConstituteImage() -> ImportImagePixels()-> ImportCharPixel().
A little debugging showed that my data is coming in BGRP format. Since I was sending "RGB" to MagickConstituteImage(), I was getting an inverted image.