Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
iristorle.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 /*
19  * toutah -
20  * Convert a IRIS image to Utah raster toolkit.
21  *
22  * To comple:
23  * cc -I/usr/include/gl toutah.c -o toutah -lrle -limage
24  *
25  * Paul Haeberli - 1990
26  */
27 #include "stdio.h"
28 #include "image.h"
29 #include "rle.h"
30 
31 short rbuf[8192];
32 short gbuf[8192];
33 short bbuf[8192];
34 
35 rle_hdr hdr;
36 
38 int argc;
39 char **argv;
40 {
41  IMAGE *image;
42  int i, y, z;
43  int xsize, ysize, zsize;
44  unsigned char *rows[3];
45  char *infname = NULL, *outfname = NULL;
46 
47  if ( scanargs( argc, argv, "% o%-outfile.rle!s, infile.rgb!s\n\
48 (Convert SGI image in infile.rgb to URT RLE image in outfile.rle.)",
49  &i, &outfname, &infname ) == 0 )
50  exit( 1 );
51 
52 /* open the input file */
53  image=iopen(infname,"r");
54  if(!image) {
55  fprintf(stderr,"%s: can't open input file %s\n",cmd_name(argv),infname);
56  exit(1);
57  }
58  xsize = image->xsize;
59  ysize = image->ysize;
60  zsize = image->zsize;
61 
62 /* open the output file */
63  hdr = *rle_hdr_init( NULL );
64  rle_names( &hdr, cmd_name( argv ), outfname, 0 );
65  rle_addhist( argv, (rle_hdr *)NULL, &hdr );
67 
68 /* allocate row buffers */
69  rows[0] = (unsigned char *)malloc(xsize*sizeof(unsigned char));
70  rows[1] = (unsigned char *)malloc(xsize*sizeof(unsigned char));
71  rows[2] = (unsigned char *)malloc(xsize*sizeof(unsigned char));
72 
73 /* set up the header */
74  hdr.xmin = 0;
75  hdr.xmax = xsize - 1;
76  hdr.ymin = 0;
77  hdr.ymax = ysize - 1;
78  hdr.ncolors = 3;
79  hdr.background = 0;
80  hdr.alpha = 0;
81  hdr.ncmap = 0;
86 
87 /* copy image data */
88  for(y=0; y<ysize; y++) {
89  if(image->zsize<3) {
90  getrow(image,rbuf,y,0);
91  stoc(rbuf,rows[0],xsize);
92  stoc(rbuf,rows[1],xsize);
93  stoc(rbuf,rows[2],xsize);
94  } else {
95  getrow(image,rbuf,y,0);
96  getrow(image,gbuf,y,1);
97  getrow(image,bbuf,y,2);
98  stoc(rbuf,rows[0],xsize);
99  stoc(gbuf,rows[1],xsize);
100  stoc(bbuf,rows[2],xsize);
101  }
102  rle_putrow(rows,xsize,&hdr);
103  }
104 
105 /* close the output file */
107  exit(0);
108 }
109 
110 stoc(sptr,cptr,n)
111 register unsigned short *sptr;
112 register unsigned char *cptr;
113 register int n;
114 {
115  while(n--) {
116  if(n>=8) {
117  cptr[0] = sptr[0];
118  cptr[1] = sptr[1];
119  cptr[2] = sptr[2];
120  cptr[3] = sptr[3];
121  cptr[4] = sptr[4];
122  cptr[5] = sptr[5];
123  cptr[6] = sptr[6];
124  cptr[7] = sptr[7];
125  sptr+=8;
126  cptr+=8;
127  n -= 7;
128  } else {
129  *cptr++ = *sptr++;
130  }
131  }
132 }
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:216
rle_hdr hdr
Definition: getx10.c:84
#define RLE_SET_BIT(glob, bit)
Definition: rle.h:122
int xmin
Definition: rle.h:100
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
char * cmd_name(char **argv)
Definition: cmd_name.c:31
void main(int argc, char **argv)
Definition: aliastorle.c:121
#define RLE_GREEN
Definition: rle.h:63
int ymin
Definition: rle.h:100
#define RLE_BLUE
Definition: rle.h:64
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
const char * cmd
Definition: rle.h:133
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
#define RLE_RED
Definition: rle.h:62
void rle_putrow(rows, int rowlen, rle_hdr *the_hdr)
Definition: rle_putrow.c:96
int xmax
Definition: rle.h:100
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
Definition: rle_addhist.c:54
int background
Definition: rle.h:100
int ncmap
Definition: rle.h:100
int ymax
Definition: rle.h:100
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
short bbuf[8192]
Definition: iristorle.c:33
int alpha
Definition: rle.h:100
short rbuf[8192]
Definition: iristorle.c:31
short gbuf[8192]
Definition: iristorle.c:32
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100