Skip to content

Instantly share code, notes, and snippets.

@lucasb-eyer
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasb-eyer/5f11be72874e66ed6eea to your computer and use it in GitHub Desktop.
Save lucasb-eyer/5f11be72874e66ed6eea to your computer and use it in GitHub Desktop.
Testing JPG -> MagickWand -> raw buffer -> MagickWand -> JPG
#include <wand/magick_wand.h>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
MagickWand *mw_in = NewMagickWand();
MagickWand *mw_out = NewMagickWand();
MagickWandGenesis();
MagickReadImage(mw_in, argc > 1 ? argv[1] : "logo:");
cout << "Image type: " << MagickGetImageType(mw_in) << endl;
cout << "#images: " << MagickGetNumberImages(mw_in) << endl;
cout << "Alpha channel: " << MagickGetImageAlphaChannel(mw_in) << endl;
cout << "Colorspace: " << MagickGetImageColorspace(mw_in) << endl;
cout << "Depth: " << MagickGetImageDepth(mw_in) << endl;
const ssize_t x = 0, y = 0, cols = MagickGetImageWidth(mw_in), rows = MagickGetImageHeight(mw_in);
const StorageType st = CharPixel;
std::vector<unsigned char> buf(3*cols*rows);
cout << "Export result: " << MagickExportImagePixels(mw_in, x, y, cols, rows, "RGB", st, &buf[0]) << endl;
cout << "Constitute result: " << MagickConstituteImage(mw_out, cols, rows, "RGB", CharPixel, &buf[0]) << endl;
cout << "Set colspace result: " << MagickSetImageColorspace(mw_out, RGBColorspace) << endl;
cout << "Set image depth result: " << MagickSetImageDepth(mw_out, 8) << endl;
MagickResetIterator(mw_out);
MagickWriteImage(mw_out, "logo.jpg");
if(mw_in) mw_in = DestroyMagickWand(mw_in);
if(mw_out) mw_out = DestroyMagickWand(mw_out);
MagickWandTerminus();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment