magick++: read mono8 image, save as PNG
Posted: 2015-11-17T08:55:12-07:00
Hi all.
I have a bunch of GigE network cameras that provide raw grayscale pixel data (aka mono8). I intend to use magick++ to convert this to PNG for human consumption. I'm almost sure that this should be near trivial, but I can't get it to work properly. My code so far:
The final output is not what I would expect. It appears that my gray data is read into a red channel, blue and green are untouched. Then, on GrayScale, a gray value is computed (probably) from all three channels. The final result is, unsurprising, not what I want. Hence, I spent most of the day trying to figure out how to either (a) tell the Image that there is only one channel or (b) how to duplicate the red channel into blue and green, such that I end up with the expected result. Alternatively, (c) find a completely different approach.
Any suggestions on how to proceed before I go bald? Thanks!
I have a bunch of GigE network cameras that provide raw grayscale pixel data (aka mono8). I intend to use magick++ to convert this to PNG for human consumption. I'm almost sure that this should be near trivial, but I can't get it to work properly. My code so far:
Code: Select all
void png::convert(void *dest, size_t *destsize,
void *src, size_t /*srcsize*/, size_t srcwidth, size_t srcheight) {
Magick::Blob blob;
Magick::Image im(srcwidth, srcheight, "R", Magick::CharPixel, src);
im.type(Magick::GrayscaleType);
im.depth(8);
im.magick("png");
im.write(&blob);
memcpy(dest, blob.data(), blob.length());
*destsize = blob.length();
}
Any suggestions on how to proceed before I go bald? Thanks!