Getting a bunch of pixels leads me to segmentation fault...

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

Getting a bunch of pixels leads me to segmentation fault...

Post by Airon65 » 2017-04-20T15:14:51-07:00

This simple code:

Code: Select all

Magick::Image *imagePtr = new Magick::Image( "images/horse.jpg" );
Magick::Pixels view( *imagePtr );
Magick::Quantum *pixels = view.get( 0, 0, imagePtr->columns(), imagePtr->rows() );
unsigned int r = 255 * QuantumScale * ( *( pixels + 0 ) );
gives me segmentation fault. What do I do wrong here? It works only if I use const:

Code: Select all

const Magick::Quantum *pixels = view.getConst( 0, 0, imagePtr->columns(), imagePtr->rows() );
unsigned int r = 255 * QuantumScale * ( *( pixels + 0 ) );
but I need to modify some of those pixels so it shouldn't be const in my case. What's wrong with my code?

ImageMagick 7.0.5-2 Q16 x86_64 2017-03-11

Airon65
Posts: 75
Joined: 2017-02-26T02:19:38-07:00
Authentication code: 1151

Re: Getting a bunch of pixels leads me to segmentation fault...

Post by Airon65 » 2017-04-21T06:34:31-07:00

But according to this article: https://www.imagemagick.org/Magick++/Pixels.html all should work fine but it doesn't

snibgo
Posts: 9378
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Getting a bunch of pixels leads me to segmentation fault...

Post by snibgo » 2017-04-21T06:37:40-07:00

Again, to get the best help, I suggest you post a complete program, not merely a fragment. As your program reads an image file, also post that image.
snibgo's IM pages: im.snibgo.com

Post Reply