Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
rjzak
Post
by rjzak » 2010-10-18T14:39:40-07:00
I am able to compile a C++ application that is able to read an image and display information about it. I found some documentation about how to get to the individual pixels, and my application compiles.
However, when it gets to the reading of a specific pixel (the PixelPacket part), I get this error:
Assertion failed: (list_info != (LinkedListInfo *) NULL), function GetLastValueInLinkedList, file magick/hashmap.c, line 466.
Abort trap
Any thoughts?
Code: Select all
#include <iostream>
#include <Magick++.h>
using namespace std;
using namespace Magick;
int main(int argc, char* argv[]) {
if (argc != 2) {
cerr << "Proper usage: " << argv[0] << " <image-file>" << endl;
return -1;
}
InitializeMagick(*argv);
#ifdef DEBUG
cout << "ImageMagick initialized" << endl;
#endif
Image image;
Blob blob;
try {
image.read( argv[1] );
image.write( &blob );
}
catch( Exception &error_ ) {
cerr << "ImageMagick exception: " << error_.what() << endl;
return -2;
}
#ifdef DEBUG
cout << "About the image file..." << endl;
cout << "File size: " << image.fileSize() << " bytes"<< endl;
cout << "Format: " << image.format() << endl;
cout << "Endian: " << image.endian() << endl;
cout << "Size: " << image.size().height() << "x" << image.size().width() << endl;
cout << "Density: " << image.density().height() << "x" << image.density().width() << endl;
#endif
Pixels view(image);
for(ssize_t i = 0; i < (unsigned) image.size().height(); i++) {
for(ssize_t j = 0; j < (unsigned) image.size().width(); j++) {
PixelPacket *pixels = view.get(i,j,i+1,j+1); // Doesn't work, why?
}
}
return 0;
}
magick
Site Admin
Posts: 11064 Joined: 2003-05-31T11:32:55-07:00
Post
by magick » 2010-10-18T18:13:19-07:00
Change
PixelPacket *pixels = view.get(i,j,i+1,j+1);
to
PixelPacket *pixels = view.get(j,i,1,1) ;
We have a patch for the exception problem you encountered in ImageMagick 6.6.5-1 Beta available by sometime tomorrow. Thanks.
rjzak
Post
by rjzak » 2010-10-19T08:34:03-07:00
magick wrote: Change
PixelPacket *pixels = view.get(i,j,i+1,j+1);
to
PixelPacket *pixels = view.get(j,i,1,1) ;
We have a patch for the exception problem you encountered in ImageMagick 6.6.5-1 Beta available by sometime tomorrow. Thanks.
Works! Thank you!
magick
Site Admin
Posts: 11064 Joined: 2003-05-31T11:32:55-07:00
Post
by magick » 2010-10-19T08:59:35-07:00
Keep in mind, it is much more efficient to get a scanline at a time if your algorithm permits it. For example:
Code: Select all
Pixels view(image);
for(ssize_t i = 0; i < (unsigned) image.size().height(); i++) {
PixelPacket *pixels = view.get(0, i, image.size().width(), 1);
for(ssize_t j = 0; j < (unsigned) image.size().width(); j++) {
...
}
}
rjzak
Post
by rjzak » 2010-10-19T12:06:45-07:00
magick wrote: Keep in mind, it is much more efficient to get a scanline at a time if your algorithm permits it. For example:
Code: Select all
Pixels view(image);
for(ssize_t i = 0; i < (unsigned) image.size().height(); i++) {
PixelPacket *pixels = view.get(0, i, image.size().width(), 1);
for(ssize_t j = 0; j < (unsigned) image.size().width(); j++) {
...
}
}
How would I iterate over the individual pixels in the second for loop?
magick
Site Admin
Posts: 11064 Joined: 2003-05-31T11:32:55-07:00
Post
by magick » 2010-10-19T12:41:28-07:00
How would I iterate over the individual pixels in the second for loop?
Just access the pixels pointer then increment (e.g. pixels++).