Page 1 of 1

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

Posted: 2012-02-14T17:16:23-07:00
by dc87
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;
    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;
    return 0;

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

Posted: 2012-02-14T18:24:38-07:00
by magick
Add this line:
  • tifImage.classType( DirectClass );
to promote your colormapped image to truecolor.

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

Posted: 2012-02-14T19:03:58-07:00
by dc87
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
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

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

Posted: 2012-02-14T19:22:48-07:00
by magick
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.

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

Posted: 2012-02-15T06:52:29-07:00
by dc87
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);

So everything is working great, Thanks again for the help