We have a problem with loading RAW images into the ImageMagick++ engine.
A RAW image in our application is an array of 8 bit values (interpreted as grey scale intensity),
to which we have to supply image width, image height and BPP.
Here's our code:
int Width = JPEGImage.getWidth();
int Height = JPEGImage.getHeight();
int Components = JPEGImage.getComponents();
int Length = JPEGImage.getWidth() * JPEGImage.getHeight() * JPEGImage.getComponents();
Magick::Blob MyBlob(JPEGImage.releaseRAW(),Length);
Magick::Image MyImage(MyBlob,Magick::Geometry(Width,Height),8,"GRAY");
JPEGImage is a well tested internal class in our project, the method releaseRAW provides a char * pointer to RAW image data.
For most images this works fine, however, if the first two bytes of image data are "BA", the Magick::Image constructor throws an exception:
terminate called after throwing an instance of 'Magick::ErrorCorruptImage'
what(): ImageMagick: Improper image header `' @ bmp.c/ReadBMPImage/593
Aborted
This is very frustrating because the code explicitly tells ImageMagick++ to handle this data as GRAY, not as BMP data
"GRAY"-images are not always interpreted as RAW
Re: "GRAY"-images are not always interpreted as RAW
Add
- fileName( magick_ + ':');
Re: "GRAY"-images are not always interpreted as RAW
I just tried this - same result
Here are my updated methods in Magick::Image::Image. I also tried putting the fileName call to the beginning of the read methods - same result. Did I do something wrong?
// Read image of specified size, depth, and format from in-memory BLOB
void Magick::Image::read ( const Blob &blob_,
const Geometry &size_,
const unsigned int depth_,
const std::string &magick_ )
{
// Set image size
size( size_ );
// Set image depth
depth( depth_ );
// Set image magick
magick( magick_ );
// do what the guy said online
fileName( magick_ + ':');
// Read from Blob
read( blob_ );
}
// Read image of specified size, and format from in-memory BLOB
void Magick::Image::read ( const Blob &blob_,
const Geometry &size_,
const std::string &magick_ )
{
// Set image size
size( size_ );
// Set image magick
magick( magick_ );
// do what the guy said online
fileName( magick_ + ':');
// Read from Blob
read( blob_ );
}
Here are my updated methods in Magick::Image::Image. I also tried putting the fileName call to the beginning of the read methods - same result. Did I do something wrong?
// Read image of specified size, depth, and format from in-memory BLOB
void Magick::Image::read ( const Blob &blob_,
const Geometry &size_,
const unsigned int depth_,
const std::string &magick_ )
{
// Set image size
size( size_ );
// Set image depth
depth( depth_ );
// Set image magick
magick( magick_ );
// do what the guy said online
fileName( magick_ + ':');
// Read from Blob
read( blob_ );
}
// Read image of specified size, and format from in-memory BLOB
void Magick::Image::read ( const Blob &blob_,
const Geometry &size_,
const std::string &magick_ )
{
// Set image size
size( size_ );
// Set image magick
magick( magick_ );
// do what the guy said online
fileName( magick_ + ':');
// Read from Blob
read( blob_ );
}
Re: "GRAY"-images are not always interpreted as RAW
Does this code work for you? Without the patch we posted, it throws an exception. We're using ImageMagick 6.4.7-8.
Code: Select all
#include <Magick++.h>
#include <string>
#include <iostream>
#include<stdio.h>
using namespace std;
using namespace Magick;
int main(){
Image m_pImage;
for (int i=0; i < 1; i++)
{
try {
int Width = 10;
int Height = 10;
unsigned char blob[100];
blob[0]='B';
blob[1]='A';
Magick::Blob MyBlob(blob,Width*Height);
Magick::Image MyImage(MyBlob,Magick::Geometry(Width,Height),8,"GRAY");
}
catch( Exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
}
catch( exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
}
}
return EXIT_SUCCESS;
}
Re: "GRAY"-images are not always interpreted as RAW
A quick and important update: Yesterday I proclaimed that the patch did no good: THIS WAS WRONG!
I redid the whole thing and now it works. Must have miscompiled or poorly installed ImageMagick
In other words: putting in this fileName( magick_ + ':') works great!
Sorry for the confusion, thanks for your help!
I redid the whole thing and now it works. Must have miscompiled or poorly installed ImageMagick
In other words: putting in this fileName( magick_ + ':') works great!
Sorry for the confusion, thanks for your help!