00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 static char *id="@(#) $Id: shputtiff.c,v 1.2 2006/08/17 19:28:17 mhender Exp $";
00018
00019 #include <shInternal.h>
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <shConfig.h>
00024
00025 #ifdef HAVE_LIBTIFF
00026 #include <tiffio.h>
00027 #include <tiff.h>
00028 #endif
00029
00040 void shputtiff(char *file, int nrows,int ncols,unsigned char *r,unsigned char *g,unsigned char *b)
00041 {
00042 #ifdef HAVE_LIBTIFF
00043 TIFF *out = NULL;
00044
00045 char *fn;
00046 char *buf;
00047 unsigned int i,j;
00048 unsigned red=0;
00049 unsigned green=1;
00050 unsigned blue=2;
00051
00052 int rc;
00053 int ln;
00054 int separate;
00055
00056 separate=0;
00057
00058 ln=nrows*ncols;
00059
00060 fn=(char *)malloc((strlen(file)+1)*sizeof(char));
00061 strcpy(fn,file);
00062
00063
00064
00065
00066 out = TIFFOpen(fn, "w");
00067 free(fn);
00068 if (out == NULL)return;
00069
00070 TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (unsigned long) ncols);
00071 TIFFSetField(out, TIFFTAG_IMAGELENGTH, (unsigned long) nrows);
00072 TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
00073 TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 3);
00074 TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8,8,8);
00075 TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
00076 TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, 1);
00077
00078
00079 TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
00080
00081 if(separate)
00082 {
00083 TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_SEPARATE);
00084 buf=(char *)malloc(ncols*sizeof(char));
00085 }else{
00086 TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
00087 buf=(char *)malloc(3*ncols*sizeof(char));
00088 }
00089 TIFFSetField(out, TIFFTAG_SOFTWARE, "puttiff");
00090
00091 for(i=0;i<nrows;i++)
00092 {
00093 if(separate)
00094 {
00095 for(j=0;j<ncols;j++)buf[j]=r[j+i*ncols];
00096
00097 rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)(nrows-i-1), red);
00098
00099 for(j=0;j<ncols;j++)buf[j]=g[j+i*ncols];
00100
00101 rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)(nrows-i-1), green);
00102
00103 for(j=0;j<ncols;j++)buf[j]=b[j+i*ncols];
00104
00105 rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)(nrows-i-1), blue);
00106 }else{
00107 for(j=0;j<ncols;j++)buf[3*j ]=r[j+i*ncols];
00108 for(j=0;j<ncols;j++)buf[3*j+1]=g[j+i*ncols];
00109 for(j=0;j<ncols;j++)buf[3*j+2]=b[j+i*ncols];
00110
00111 rc=TIFFWriteScanline(out, (unsigned char*)buf, (unsigned)(nrows-i-1), 0);
00112 }
00113 }
00114 free(buf);
00115
00116 TIFFWriteDirectory(out);
00117
00118 TIFFClose(out);
00119 #endif
00120 return;
00121 }