[MagickCore] Reading an image from memory
Posted: 2018-08-17T10:14:13-07:00
I'm using the MagickCore API to load images in a game engine. I have an in-memory file buffer that I'm loading an image (such as a .png) out of. I'm then sticking the decoded data into another in-memory buffer. My current idea requires an extra copy that I'd like to get rid of:
What's the proper way to do a fully in-memory decode without an extra copy?
For additional context, I'm trying to decode a .bmp that has 3 8-bit channels into raw pixel data that has 4 32-bit channels and I want to do it efficiently.
Code: Select all
std::vector<uint8> inputData;
std::vector<uint32> outputData;
int desiredChannelCount;
ImageInfo* imInfo = AcquireImageInfo();
SetImageInfoBlob(imInfo, inputData.data(), inputData.size());
Image* imImage = ReadImage(imInfo, exInfo);
Quantum* pixels = GetAuthenticPixels(imImage, 0, 0, imImage->columns, imImage->rows, exInfo);
size_t pixelsSize = imImage->columns * imImage->rows * desiredChannelCount * sizeof(Quantum);
memcpy(image.data.data(), pixels, pixelsSize);
For additional context, I'm trying to decode a .bmp that has 3 8-bit channels into raw pixel data that has 4 32-bit channels and I want to do it efficiently.