Status Access Violation

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?".
Post Reply
WaterIsPoison

Status Access Violation

Post by WaterIsPoison »

Code: Select all

#include <Magick++.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
//g++ `Magick++-config --cxxflags --cppflags` -o -imageTest imageTest.cpp `Magick++-config --ldflags --libs`
using namespace std;
using namespace Magick;



int main(int argc, char *argv[])
{
	Image my_image;  // create an *empty* image using the default Image constructor
	my_image.read("out.jpg");
	
	
	//make safe changes to image
	my_image.modifyImage();
	
	Pixels view(my_image);

	//final destination for region. Cover (0, 160) to (640, 320)
	int columns = 640; int rows = 320;
	
	PixelPacket *pixel_cache = view.get(0,160,columns, rows);
	for(int row = 160; row < rows; row++)
		for(int col = 0;col < columns; col++)
		{
			//search for blue pixels
			//R:65 G:118 B:188
			*pixel_cache++;
			//printf(colr);
			Color cnvrt = *pixel_cache;//THIS IS THE LINE WHICH CAUSES ISSUES
			Quantum b = cnvrt.blueQuantum();
			Quantum r = cnvrt.redQuantum();
				
			
			if(b > 26000)
				if(r < 30000)
				{
					*pixel_cache = green;	
				}	
		}
	
	view.sync();

	
	
	my_image.write("outMOD.jpg");

}
Hello all, I'm using Cygwin to run this program in which I search for a pixel of a certain color, and change it to another color. However, when I run this code, I get a segmentation fault (gdb revealed it to be a STATUS_ACCESS_VIOLATION). Do you guys know of a better way to access the pixels or help me figure this problem out?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Status Access Violation

Post by magick »

Your program worked without complaint for us (ImageMagick 6.5.0-10) once we changed green to Color("green") and moved the pixel_cache update to the end of the loop:

Code: Select all

      for(int col = 0;col < columns; col++)
      {
         Color cnvrt = *pixel_cache;
         Quantum b = cnvrt.blueQuantum();
         Quantum r = cnvrt.redQuantum();
         if(b > 26000)
            if(r < 30000)
            {
               *pixel_cache = Color("green");
            }
         pixel_cache++;
      }
Post Reply