1997.03.09 15:34 "Question from a Starter..", by Manish Rathi
Hello Everyone:
Here is a small trivial problem from a newcomer. I would really appreciate any help with regards to it.
this is what I want to do: I have a tiff file.. What I was trying to open & read this file and write the contents of it to another file. The sample code which I have written down is given below. I would like to know whether it can be done or not and if yes, where am I going wrong in the code...
thanks in advance...
Regards,
Manish Rathi
mrathi@cs.wmich.edu
___________________________________________________________________
#include <stdio.h>
#include "tiffio.h"
void main() {
TIFF* read_tif = TIFFOpen("penny.tiff", "r");
TIFF* write_tif = TIFFOpen("my_penny.tiff", "wa");
if ( (read_tif == 1) & (write_tif == 1) ) {
int imageWidth, imageLength;
int x, y;
int i;
unsigned int* buf;
unsigned int** final_buf;
TIFFGetField(read_tif, TIFFTAG_IMAGEWIDTH, &imageWidth);
TIFFGetField(read_tif, TIFFTAG_IMAGELENGTH, &imageLength);
buf = (unsigned int*)
malloc( imageWidth * sizeof(unsigned int));
final_buf = (unsigned int**)
malloc( imageLength * sizeof(unsigned int));
for ( i = 0; i < imageWidth; i++)
final_buf[i] = (unsigned int*)
malloc (imageWidth * sizeof(unsigned int) );
if ( buf != NULL) {
int row;
for ( row = 0; row < imageLength; row++) {
TIFFReadScanline( read_tif, buf, row, 0 );
for ( i = 0; i < imageWidth; i++ )
final_buf[row][i] = buf[i];
}
for ( row = 0; row < imageLength; row++)
TIFFWriteScanline( write_tif, final_buf[row], row, 0);
}
TIFFClose(read_tif);
TIFFClose(write_tif);
}
}