{
int w,h;
const Magick::PixelPacket *cacheRead;
Magick::InitializeMagick(NULL);
Magick::Image img;
try
{
img.read ( filename );
}
catch( ... )
{
std::cout << "MagickReader : can't open " << filename << endl;
throw dgtalio;
}
w = img.size().width();
h = img.size().height();
img.type ( Magick::TrueColorType );
img.modifyImage();
cacheRead = img.getConstPixels ( 0, 0, w, h );
typename TImageContainer::Point firstPoint;
typename TImageContainer::Point lastPoint;
firstPoint = TImageContainer::Point::zero;
lastPoint[0] = w-1;
lastPoint[1] = h-1;
typename TImageContainer::Domain domain(firstPoint,lastPoint);
TImageContainer image(domain);
typename TImageContainer::Value val;
typename TImageContainer::Domain::ConstIterator it = domain.begin(),
itend=domain.end();
for(; it != itend; ++it)
{
const Magick::PixelPacket *pixel = cacheRead + w * ((topbotomOrder)? ( h - 1 - (*it)[1] ): (*it)[1] ) + (*it)[0];
val = (pixel->red + pixel->green + pixel->blue) % 256;
image.setValue( (*it), val );
}
return image;
}