Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rletoiris.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  * fromutah -
20  * Convert a UTAH raster toolkit image into an IRIS image.
21  *
22  * To compile:
23  * cc -I/usr/include/gl fromutah.c -o fromutah -lrle -limage
24  *
25  * Paul Haeberli - 1988
26  */
27 #include "stdio.h"
28 #include "image.h"
29 #include "rle.h"
30 
31 short sbuf[4096];
32 
33 rle_hdr hdr;
34 
36 int argc;
37 char *argv[];
38 {
39  unsigned char *rows[3];
40  int i, y, xsize, ysize;
41  IMAGE *oimage;
42  FILE *infile;
43  char *infname = NULL, *outfname = NULL;
44 
45 /* get args */
46  if ( scanargs( argc, argv, "% o!-outimage.rgb!s in.rle%s\n(\
47 Convert URT RLE image in in.rle to SGI image format in outimage.rgb.\n\
48 Must specify -o outimage.rgb.)",
49  &i, &outfname, &infname ) == 0 )
50  exit( 1 );
51 
52 /* open the input file */
53  hdr = *rle_hdr_init( (rle_hdr *)NULL );
54  hdr.rle_file = rle_open_f(cmd_name(argv), infname, "r");
55  rle_names( &hdr, cmd_name(argv), infname, 0 );
56 
58 
60  if(hdr.ncolors != 3) {
61  fprintf(stderr,"%s: input image must have 3 channels\n", hdr.cmd);
62  exit(1);
63  }
64 /* get the size */
65  xsize = hdr.xmax-hdr.xmin+1;
66  ysize = hdr.ymax-hdr.ymin+1;
67 
68 /* open the output file */
69  oimage = iopen(outfname,"w",RLE(1),3,xsize,ysize,3);
70 
71 /* allocate row buffers */
72  rows[0] = (unsigned char*)malloc(xsize);
73  rows[1] = (unsigned char*)malloc(xsize);
74  rows[2] = (unsigned char*)malloc(xsize);
75 
76 /* copy the image data */
77  for(y=0; y<ysize; y++) {
78  rle_getrow( &hdr, rows );
79  ctos(rows[0],sbuf,xsize);
80  putrow(oimage,sbuf,y,0);
81  ctos(rows[1],sbuf,xsize);
82  putrow(oimage,sbuf,y,1);
83  ctos(rows[2],sbuf,xsize);
84  putrow(oimage,sbuf,y,2);
85  }
86 
87 /* close the output file */
88  iclose(oimage);
89  exit(0);
90 }
91 
92 ctos(cptr,sptr,n)
93 register unsigned char *cptr;
94 register unsigned short *sptr;
95 register int n;
96 {
97  while(n--) {
98  if(n>=8) {
99  sptr[0] = cptr[0];
100  sptr[1] = cptr[1];
101  sptr[2] = cptr[2];
102  sptr[3] = cptr[3];
103  sptr[4] = cptr[4];
104  sptr[5] = cptr[5];
105  sptr[6] = cptr[6];
106  sptr[7] = cptr[7];
107  sptr+=8;
108  cptr+=8;
109  n -= 7;
110  } else {
111  *sptr++ = *cptr++;
112  }
113  }
114 }
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
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
int rle_getrow(rle_hdr *the_hdr, scanline)
Definition: rle_getrow.c:333
int ymin
Definition: rle.h:100
short sbuf[4096]
Definition: rletoiris.c:31
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
const char * cmd
Definition: rle.h:133
int xmax
Definition: rle.h:100
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
Definition: rle_getrow.c:254
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
int ymax
Definition: rle.h:100
#define RLE_ALPHA
Definition: rle.h:65
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