Cannot get TIFF img w/ changed pixels to write/sync properly

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
dc87
Posts: 4
Joined: 2012-02-14T13:51:23-07:00
Authentication code: 8675308

Cannot get TIFF img w/ changed pixels to write/sync properly

Post by dc87 » 2012-02-14T17:16:23-07:00

Hey everyone,

I am trying to read in a TIFF file to Image, manipulate the pixels and write it back to disk in TIFF format. Using the pixel cache (PixelPacket *), it seems to work for jpg but not TIFF. The following code should just make the entire image yellow, but for TIFF, the outputted image is half white and half black, spilt on the vertical line. The solid yellow image works for output.jpg but not output.tif

The original image is just a black blackground with a red box near the top. When examining the TIFF pixelpacket by each pixel, the data for RGB colours seems correct. Maybe its related to the write or sync, but I'm not sure, does anyone have any suggestions?

Code: Select all

#include <Magick++.h>
#include <iostream>

using namespace std;
using namespace Magick;
int main(void) {

    Color yellow("yellow");
    Image tifImage("input.tif");
    Image jpgImage("input.jpg");
    size_t rows=1586, columns=1256;
    
    
    tifImage.modifyImage();
    jpgImage.modifyImage();
    
    PixelPacket *tifPixels = tifImage.getPixels(0,0,columns,rows);
    PixelPacket *jpgPixels = jpgImage.getPixels(0,0,columns,rows);
    
    for(ssize_t i=0; i<columns*rows; i++){
        *(tifPixels+i) = yellow;
        *(jpgPixels+i) = yellow;
    }
    tifImage.syncPixels();
    jpgImage.syncPixels();
    
    tifImage.write("output.tif");
    jpgImage.write("output.jpg");
        
    return 0;
}

User avatar
magick
Site Admin
Posts: 11066
Joined: 2003-05-31T11:32:55-07:00

Re: Cannot get TIFF img w/ changed pixels to write/sync prop

Post by magick » 2012-02-14T18:24:38-07:00

Add this line:
  • tifImage.classType( DirectClass );
to promote your colormapped image to truecolor.

dc87
Posts: 4
Joined: 2012-02-14T13:51:23-07:00
Authentication code: 8675308

Re: Cannot get TIFF img w/ changed pixels to write/sync prop

Post by dc87 » 2012-02-14T19:03:58-07:00

Thanks for the quick response, so I added the line
tifImage.classType( DirectClass );
But the output was still the half black and white .tif, then I removed the line
tifImage.syncPixels();
And output.tif is a full yellow 1256x1586 .tif image. Then I tried some different operations like replacing all of one color with another and It worked too.
So everything seems to be working great, but I find it odd that I don't need to call tifImage.syncPixels() since in getPixels()'s description is says 'Modified pixels may be subsequently transferred back to the image via syncPixels.'

But anyways, thank you for your help

User avatar
magick
Site Admin
Posts: 11066
Joined: 2003-05-31T11:32:55-07:00

Re: Cannot get TIFF img w/ changed pixels to write/sync prop

Post by magick » 2012-02-14T19:22:48-07:00

We tested your program after adding classType() and it produced yellow pixels for TIFF and JPEG while calling syncPixels() as required. We're using ImageMagick 6.7.5-6.

dc87
Posts: 4
Joined: 2012-02-14T13:51:23-07:00
Authentication code: 8675308

Re: Cannot get TIFF img w/ changed pixels to write/sync prop

Post by dc87 » 2012-02-15T06:52:29-07:00

K, I was using ImageMagick 6.4.0 with a cygwin compiler. I'll see if I can update to 6.7.5-6, since the syncPixels() should be working.

After updating Magick++ to 6.7.5-6 on cygwin, I was able to get the program producing all yellow pixels (working correctly) with
tifImage.classType ( DirectClass);
tifImage.syncPixels();

So everything is working great, Thanks again for the help

Post Reply