Magick++ Image constructor bug

[email protected] Thu, 28 May 2009 17:07:15 -0700 (PDT)
Newsgroups gmane.comp.video.image-magick.bugs
Message-ID <[email protected]>
Hello:

I'm having difficulty with the Magick::Image constructor under Windows
library v 6.5.2.Q16.  The constructor is

Magick::Image(const unsigned int width_,
const unsigned int height_,
std::string map_,
const StorageType type_,
const void *pixels_);

The constructor appears to prepend some garbage characters onto map_,
which causes the routine ImportImagePixels to throw an error.  Example and
output appear below.

I would appreciate a simple workaround, if at all possible.

Sincerely yours
Matthew Britton

#######################


##################
# Source code:   #
##################

#include <iostream>
#include <Magick++.h>


int main() {

  unsigned int n = 128;

  char * c = new char[n*n];

  try {
    std::string s("RGB");
    Magick::Image img(n, n, s, Magick::CharPixel, c);
  } catch(Magick::Exception & error) {
    std::cout << "caught Magick++ exception: "
      << error.what() << std::endl;
  }

  try {
    std::string s("R");
    Magick::Image img(n, n, s, Magick::CharPixel, c);
  } catch(Magick::Exception & error) {
    std::cout << "caught Magick++ exception: "
       << error.what() << std::endl;
  }

  try {
    std::string s("G");
    Magick::Image img(n, n, s, Magick::CharPixel, c);
  } catch(Magick::Exception & error) {
    std::cout << "caught Magick++ exception: "
       << error.what() << std::endl;
  }

  try {
    std::string s("B");
    Magick::Image img(n, n, s, Magick::CharPixel, c);
  } catch(Magick::Exception & error) {
    std::cout << "caught Magick++ exception: "
       << error.what() << std::endl;
  }
}

#############
#  Output:  #
#############

caught Magick++ exception: ImageMagick: unrecognized pixel map
`&#65533;&#65533;&#65533;&#65533;RGB' @ pixel.c/ImportImagePixels/1815
caught Magick++ exception: ImageMagick: unrecognized pixel map
`&#65533;&#65533;&#65533;&#65533;R' @ pixel.c/ImportImagePixels/1815
caught Magick++ exception: ImageMagick: unrecognized pixel map
`&#65533;&#65533;&#65533;&#65533;G' @ pixel.c/ImportImagePixels/1815
caught Magick++ exception: ImageMagick: unrecognized pixel map
`&#65533;&#65533;&#65533;&#65533;B' @ pixel.c/ImportImagePixels/1815