Cannot get TIFF img w/ changed pixels to write/sync properly
Posted: 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?
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;
}