Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Macros | Typedefs | Functions | Variables
rletotiff.c File Reference
#include "rle.h"
#include <stdio.h>
#include "tiffio.h"
Include dependency graph for rletotiff.c:

Go to the source code of this file.

Macros

#define NO_DECLARE_MALLOC   /* tiffcompat.h declares it. */
 
#define USE_PROTOTYPES   1 /* Needs to have a value for tiffcompat.h. */
 
#define SETFIELD(tif, fieldname, arg)   TIFFSetField(tif,fieldname,arg)
 

Typedefs

typedef unsigned char tiff_sample
 

Functions

void error (const char *s)
 
void get_tiff_scanline (tiff_sample *buf, int row)
 
void usage (void)
 
void get_scanlines ()
 
void main (int argc, argv)
 
void error (char *s) const
 

Variables

static rle_hdr in_hdr
 
static rle_pixel ** scan_red
 
static rle_pixel ** scan_green
 
static rle_pixel ** scan_blue
 
static tiff_sampleRGBscanline
 
TIFFtif
 
static unsigned short compression = 5
 
static int flip = 0
 

Macro Definition Documentation

#define NO_DECLARE_MALLOC   /* tiffcompat.h declares it. */

Definition at line 10 of file rletotiff.c.

#define SETFIELD (   tif,
  fieldname,
  arg 
)    TIFFSetField(tif,fieldname,arg)

Definition at line 24 of file rletotiff.c.

#define USE_PROTOTYPES   1 /* Needs to have a value for tiffcompat.h. */

Definition at line 18 of file rletotiff.c.

Typedef Documentation

typedef unsigned char tiff_sample

Definition at line 25 of file rletotiff.c.

Function Documentation

void error ( const char *  s)
void error ( char *  s) const

Definition at line 198 of file rletotiff.c.

200 {
201  fprintf(stderr,"%s: %s\n", in_hdr.cmd, s);
202  exit(2);
203 }
static rle_hdr in_hdr
Definition: rletotiff.c:38
_urt_stack * s
Definition: rleClock.c:919
const char * cmd
Definition: rle.h:133
void get_scanlines ( )

Definition at line 137 of file rletotiff.c.

References flip, in_hdr, rle_hdr::ncolors, rle_getrow(), scan_blue, scan_green, scan_red, rle_hdr::xmax, rle_hdr::ymax, and rle_hdr::ymin.

138 {
139  int i,j;
140  rle_pixel **scan;
141 
142  scan = (rle_pixel **)malloc( in_hdr.ncolors * sizeof(rle_pixel *) );
143  if ( scan == 0 ) error("can't allocate scan");
144  scan_red = (rle_pixel**)malloc(sizeof(rle_pixel*)*
145  (in_hdr.ymax-in_hdr.ymin+1));
146  scan_green = (rle_pixel**)malloc(sizeof(rle_pixel*)*
147  (in_hdr.ymax-in_hdr.ymin+1));
148  scan_blue = (rle_pixel**)malloc(sizeof(rle_pixel*)*
149  (in_hdr.ymax-in_hdr.ymin+1));
150  if (!(scan_red && scan_green && scan_blue))
151  error("can't allocate a scan buffer");
152  if (flip) {
153  for (i = 0; i < in_hdr.ymax-in_hdr.ymin+1; i++) {
154  for (j=0; j < 3; j++) {
155  scan[j] = (rle_pixel*)malloc(sizeof(rle_pixel)*(in_hdr.xmax+1));
156  if (scan[j] == NULL) error("can't allocate current scanline");
157  }
158  rle_getrow(&in_hdr, scan);
159  scan_red[i] = scan[0];
160  scan_green[i] = scan[1];
161  scan_blue[i] = scan[2];
162  for (j=0; j < 3; j++) {
163  scan[j] = (rle_pixel*)malloc(sizeof(rle_pixel)*(in_hdr.xmax+1));
164  if (scan[j] == NULL) error("can't allocate current scanline");
165  }
166  }
167  } else {
168  for (i = 0; i < in_hdr.ymax-in_hdr.ymin+1; i++) {
169  for (j=0; j < 3; j++) {
170  scan[j] = (rle_pixel*)malloc(sizeof(rle_pixel)*(in_hdr.xmax+1));
171  if (scan[j] == NULL) error("can't allocate current scanline");
172  }
173  rle_getrow(&in_hdr, scan);
174  scan_red[in_hdr.ymax - in_hdr.ymin - i] = scan[0];
175  scan_green[in_hdr.ymax - in_hdr.ymin - i] = scan[1];
176  scan_blue[in_hdr.ymax - in_hdr.ymin - i] = scan[2];
177  }
178  }
179  free( scan );
180 }
static rle_pixel ** scan_green
Definition: rletotiff.c:42
static rle_hdr in_hdr
Definition: rletotiff.c:38
int ymin
Definition: rle.h:100
unsigned char ** scan
Definition: rle.c:26
static rle_pixel ** scan_blue
Definition: rletotiff.c:43
int xmax
Definition: rle.h:100
static rle_pixel ** scan_red
Definition: rletotiff.c:41
static int flip
Definition: rletotiff.c:49
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int i
Definition: rletorla.c:82
void error(const char *s)
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
int ncolors
Definition: rle.h:100

Here is the call graph for this function:

void get_tiff_scanline ( tiff_sample buf,
int  row 
)

Definition at line 183 of file rletotiff.c.

186 {
187  register int i;
188  register int k;
189 
190  for (i=k=0; i < in_hdr.xmax+1; i++, k +=3) {
191  buf[k] = scan_red[row][i];
192  buf[k+1] = scan_green[row][i];
193  buf[k+2] = scan_blue[row][i];
194  }
195 }
static rle_pixel ** scan_green
Definition: rletotiff.c:42
static rle_hdr in_hdr
Definition: rletotiff.c:38
static rle_pixel ** scan_blue
Definition: rletotiff.c:43
int xmax
Definition: rle.h:100
static char buf[4096 +1]
Definition: into.c:46
static rle_pixel ** scan_red
Definition: rletotiff.c:41
int i
Definition: rletorla.c:82
int row
Definition: rle.c:27
void main ( int  argc,
argv   
)

Definition at line 52 of file rletotiff.c.

55 {
56  int i;
57  long int rows_per_strip;
58  int cflag = 0;
59  char *outfname = NULL, *infname = NULL;
60 
61  in_hdr = *rle_hdr_init( (rle_hdr *)NULL );
62 
63  if (sizeof(rle_pixel) != sizeof(tiff_sample))
64  error("tiff_sample and rle_pixel not same size");
65 
66  if ( scanargs( argc, argv, "% Cc%- f%- o!-outfile.tiff!s infile.rle%s\n(\
67 \tConvert URT image to 24-bit TIFF image.\n\
68 \t-c\tUse LZW compression (default)\n\
69 \t-C\tUse no compression\n\
70 \t-f\tDon't flip image top to bottom\n\
71 \t-o outfile.tiff is required)",
72  &cflag, &flip, &i, &outfname, &infname ) == 0 )
73  exit( 1 );
74 
75  if ( cflag == 1 )
76  compression = COMPRESSION_LZW;
77  else if ( cflag == 2 )
78  compression = COMPRESSION_NONE;
79 
80  rle_names( &in_hdr, cmd_name( argv ), infname, 0 );
81  in_hdr.rle_file = rle_open_f(in_hdr.cmd, infname, "r");
82  rle_get_setup_ok( &in_hdr, in_hdr.cmd, infname );
83 
85  in_hdr.xmin = 0;
86  if (in_hdr.ncolors != 3) error("infile must be 24-bit RGB");
87  /* No alpha channel, either. */
89  get_scanlines();
90 /* rletotiff specific code comes after here */
92  sizeof(tiff_sample)*3*(in_hdr.xmax+1));
93  if (RGBscanline == NULL) error("can't allocate RGB scanline");
94  tif = TIFFOpen(outfname, "w");
95  if (!tif) error("tiffopen ret null");
96 #ifndef TIFF2p4
97  SETFIELD(tif,TIFFTAG_IMAGEWIDTH, in_hdr.xmax + 1);
98  SETFIELD(tif,TIFFTAG_IMAGELENGTH, in_hdr.ymax - in_hdr.ymin + 1);
99 #else /* TIFF2p4 */
100  SETFIELD(tif,TIFFTAG_IMAGEWIDTH, (unsigned long)(in_hdr.xmax + 1));
101  SETFIELD(tif,TIFFTAG_IMAGELENGTH,
102  (unsigned long)(in_hdr.ymax - in_hdr.ymin + 1));
103 #endif /* TIFF2p4 */
104  SETFIELD(tif, TIFFTAG_COMPRESSION, compression);
105  rows_per_strip = (long)8*1024/(in_hdr.xmax+1);
106  if (rows_per_strip < 1) rows_per_strip = 1L;
107  SETFIELD(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip);
108  SETFIELD(tif, TIFFTAG_XRESOLUTION, 1.0);
109  SETFIELD(tif, TIFFTAG_YRESOLUTION, 1.0);
110  SETFIELD(tif, TIFFTAG_RESOLUTIONUNIT, 1);
111  SETFIELD(tif, TIFFTAG_BITSPERSAMPLE, 8);
112  SETFIELD(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
113  SETFIELD(tif, TIFFTAG_PLANARCONFIG, 1);
114  SETFIELD(tif, TIFFTAG_PHOTOMETRIC, 2);
115  for (i = 0; i < in_hdr.ymax - in_hdr.ymin + 1; i++) {
117  TIFFWriteScanline(tif, RGBscanline, i, 1);
118  }
119  TIFFClose(tif);
120 /* rletotiff specific code comes before here */
121  for (i = 0; i < in_hdr.ymax - in_hdr.ymin + 1; i++ ) {
122  free(scan_red[i]);
123  free(scan_green[i]);
124  free(scan_blue[i]);
125  }
126  free(scan_red);
127  free(scan_green);
128  free(scan_blue);
129 }
static rle_pixel ** scan_green
Definition: rletotiff.c:42
static tiff_sample * RGBscanline
Definition: rletotiff.c:44
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
static rle_hdr in_hdr
Definition: rletotiff.c:38
TIFF * tif
Definition: rletotiff.c:46
void get_tiff_scanline(tiff_sample *buf, int row)
Definition: rletotiff.c:183
static unsigned short compression
Definition: rletotiff.c:48
int ymin
Definition: rle.h:100
string infname
Definition: getbob.c:68
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
const char * cmd
Definition: rle.h:133
static rle_pixel ** scan_blue
Definition: rletotiff.c:43
Definition: rle.h:96
int xmax
Definition: rle.h:100
#define SETFIELD(tif, fieldname, arg)
Definition: rletotiff.c:24
static rle_pixel ** scan_red
Definition: rletotiff.c:41
void get_scanlines()
Definition: rletotiff.c:137
unsigned char tiff_sample
Definition: rletotiff.c:25
static int flip
Definition: rletotiff.c:49
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int i
Definition: rletorla.c:82
#define RLE_ALPHA
Definition: rle.h:65
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
int cflag
Definition: getgmr.c:19
void error(const char *s)
char * cmd_name(char **argv)
Definition: cmd_name.c:31
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
void usage ( void  )

Definition at line 206 of file rletotiff.c.

207 {
208  fprintf(stderr,"Usage:\n");
209  fprintf(stderr,"\trletotiff [options] infile outfile\n");
210  fprintf(stderr,"options:\n");
211  fprintf(stderr,"\t-c lzw or -c none (compression, default lzw)\n");
212  fprintf(stderr,"\t-v (vertical flip, default not)\n");
213  exit(2);
214 }

Variable Documentation

unsigned short compression = 5
static

Definition at line 48 of file rletotiff.c.

int flip = 0
static

Definition at line 49 of file rletotiff.c.

Referenced by get_scanlines().

rle_hdr in_hdr
static

Definition at line 38 of file rletotiff.c.

Referenced by get_scanlines().

tiff_sample* RGBscanline
static

Definition at line 44 of file rletotiff.c.

rle_pixel** scan_blue
static

Definition at line 43 of file rletotiff.c.

Referenced by get_scanlines().

rle_pixel** scan_green
static

Definition at line 42 of file rletotiff.c.

Referenced by get_scanlines().

rle_pixel** scan_red
static

Definition at line 41 of file rletotiff.c.

Referenced by get_scanlines().

TIFF* tif

Definition at line 46 of file rletotiff.c.