1999.07.15 23:47 "RGB Gradient Code, adapted from Andreas Neumann", by Eric B. Middlecamp
I made a simple extension to Andreas Neumann's gradient code, (see http://www.gis.univie.ac.at/strv/strv/leute/andi/computer/graphics/raster-formats/example_tiff_main.html) but the output TIFF image has some odd contamination. Looking at the image, you wouldn't be able to tell -- however a histogram reveals that some levels are omitted and others are doubled.
Has anyone else experienced bizarre anomalies like this?
Thanks,
Eric Middlecamp
// ======================================================
#include "tiffio.h"
void RGBGradient( char *tiff_fname )
{
unsigned char color_ptr[256*3];
int i, j;
TIFF* tif = TIFFOpen(tiff_fname , "w");
if (tif == NULL) {
return;
}
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 256);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 256);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {
color_ptr[j*3+0] = i;
color_ptr[j*3+1] = i;
color_ptr[j*3+2] = i;
}
TIFFWriteScanline(tif, color_ptr, i);
}
TIFFFlushData(tif);
TIFFClose(tif);
}
// ======================================================