|
kusano |
7d535a |
/* $Id: tiff-rgb.c,v 1.4 2010-06-08 18:55:15 bfriesen Exp $ */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* tiff-rgb.c -- create a 24-bit Class R (rgb) TIFF file
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* All Rights Reserved
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Permission to use, copy, modify, and distribute this software and its
|
|
kusano |
7d535a |
* documentation for any purpose and without fee is hereby granted,
|
|
kusano |
7d535a |
* provided that the above copyright notice appear in all copies and that
|
|
kusano |
7d535a |
* both that copyright notice and this permission notice appear in
|
|
kusano |
7d535a |
* supporting documentation, and that the name of Digital not be
|
|
kusano |
7d535a |
* used in advertising or publicity pertaining to distribution of the
|
|
kusano |
7d535a |
* software without specific, written prior permission.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
kusano |
7d535a |
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
kusano |
7d535a |
* DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
kusano |
7d535a |
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
kusano |
7d535a |
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
kusano |
7d535a |
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
kusano |
7d535a |
* SOFTWARE.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include <math.h></math.h>
|
|
kusano |
7d535a |
#include <stdio.h></stdio.h>
|
|
kusano |
7d535a |
#include <stdlib.h></stdlib.h>
|
|
kusano |
7d535a |
#include <string.h></string.h>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include "tiffio.h"
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define ROUND(x) (uint16) ((x) + 0.5)
|
|
kusano |
7d535a |
#define CMSIZE 256
|
|
kusano |
7d535a |
#define WIDTH 525
|
|
kusano |
7d535a |
#define HEIGHT 512
|
|
kusano |
7d535a |
#define TIFF_GAMMA 2.2
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void Usage();
|
|
kusano |
7d535a |
char * programName;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int main(int argc, char **argv)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
char * input_file = NULL;
|
|
kusano |
7d535a |
double image_gamma = TIFF_GAMMA;
|
|
kusano |
7d535a |
int i, j;
|
|
kusano |
7d535a |
TIFF * tif;
|
|
kusano |
7d535a |
unsigned char * scan_line;
|
|
kusano |
7d535a |
uint16 red[CMSIZE], green[CMSIZE], blue[CMSIZE];
|
|
kusano |
7d535a |
float refblackwhite[2*3];
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
programName = argv[0];
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
switch (argc) {
|
|
kusano |
7d535a |
case 2:
|
|
kusano |
7d535a |
image_gamma = TIFF_GAMMA;
|
|
kusano |
7d535a |
input_file = argv[1];
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case 4:
|
|
kusano |
7d535a |
if (!strcmp(argv[1], "-gamma")) {
|
|
kusano |
7d535a |
image_gamma = atof(argv[2]);
|
|
kusano |
7d535a |
input_file = argv[3];
|
|
kusano |
7d535a |
} else
|
|
kusano |
7d535a |
Usage();
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
default:
|
|
kusano |
7d535a |
Usage();
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
for (i = 0; i < CMSIZE; i++) {
|
|
kusano |
7d535a |
if (i == 0)
|
|
kusano |
7d535a |
red[i] = green[i] = blue[i] = 0;
|
|
kusano |
7d535a |
else {
|
|
kusano |
7d535a |
red[i] = ROUND((pow(i / 255.0, 1.0 / image_gamma) * 65535.0));
|
|
kusano |
7d535a |
green[i] = ROUND((pow(i / 255.0, 1.0 / image_gamma) * 65535.0));
|
|
kusano |
7d535a |
blue[i] = ROUND((pow(i / 255.0, 1.0 / image_gamma) * 65535.0));
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
refblackwhite[0] = 0.0; refblackwhite[1] = 255.0;
|
|
kusano |
7d535a |
refblackwhite[2] = 0.0; refblackwhite[3] = 255.0;
|
|
kusano |
7d535a |
refblackwhite[4] = 0.0; refblackwhite[5] = 255.0;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if ((tif = TIFFOpen(input_file, "w")) == NULL) {
|
|
kusano |
7d535a |
fprintf(stderr, "can't open %s as a TIFF file\n", input_file);
|
|
kusano |
7d535a |
exit(0);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, WIDTH);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, HEIGHT);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);
|
|
kusano |
7d535a |
#ifdef notdef
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_WHITEPOINT, whitex, whitey);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_PRIMARYCHROMATICITIES, primaries);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_REFERENCEBLACKWHITE, refblackwhite);
|
|
kusano |
7d535a |
TIFFSetField(tif, TIFFTAG_TRANSFERFUNCTION, red, green, blue);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
scan_line = (unsigned char *) malloc(WIDTH * 3);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
for (i = 0; i < 255; i++) {
|
|
kusano |
7d535a |
for (j = 0; j < 75; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = 255;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = 255 - i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = 255 - i;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 75; j < 150; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = 255 - i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = 255;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = 255 - i;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 150; j < 225; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = 255 - i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = 255 - i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = 255;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 225; j < 300; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = (i - 1) / 2;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = (i - 1) / 2;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = (i - 1) / 2;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 300; j < 375; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = 255 - i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = 255;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = 255;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 375; j < 450; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = 255;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = 255 - i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = 255;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 450; j < 525; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = 255;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = 255;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = 255 - i;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
TIFFWriteScanline(tif, scan_line, i, 0);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (i = 255; i < 512; i++) {
|
|
kusano |
7d535a |
for (j = 0; j < 75; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = 0;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = 0;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 75; j < 150; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = 0;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = 0;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 150; j < 225; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = 0;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = 0;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = i;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 225; j < 300; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = (i - 1) / 2;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = (i - 1) / 2;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = (i - 1) / 2;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 300; j < 375; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = 0;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = i;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 375; j < 450; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = 0;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = i;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (j = 450; j < 525; j++) {
|
|
kusano |
7d535a |
scan_line[j * 3] = i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 1] = i;
|
|
kusano |
7d535a |
scan_line[(j * 3) + 2] = 0;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
TIFFWriteScanline(tif, scan_line, i, 0);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
free(scan_line);
|
|
kusano |
7d535a |
TIFFClose(tif);
|
|
kusano |
7d535a |
exit(0);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void
|
|
kusano |
7d535a |
Usage()
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
fprintf(stderr, "Usage: %s -gamma gamma tiff-image\n", programName);
|
|
kusano |
7d535a |
exit(0);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Local Variables:
|
|
kusano |
7d535a |
* mode: c
|
|
kusano |
7d535a |
* c-basic-offset: 8
|
|
kusano |
7d535a |
* fill-column: 78
|
|
kusano |
7d535a |
* End:
|
|
kusano |
7d535a |
*/
|