Page 1 of 1

Magic++ and Pixel-level access

Posted: 2010-10-18T14:39:40-07:00
by rjzak
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;
}

Re: Magic++ and Pixel-level access

Posted: 2010-10-18T18:13:19-07:00
by magick
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.

Re: Magic++ and Pixel-level access

Posted: 2010-10-19T08:34:03-07:00
by rjzak
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!

Re: Magic++ and Pixel-level access

Posted: 2010-10-19T08:59:35-07:00
by magick
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++) {
         ...
      }
   }

Re: Magic++ and Pixel-level access

Posted: 2010-10-19T12:06:45-07:00
by rjzak
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?

Re: Magic++ and Pixel-level access

Posted: 2010-10-19T12:41:28-07:00
by magick
How would I iterate over the individual pixels in the second for loop?
Just access the pixels pointer then increment (e.g. pixels++).