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

Go to the source code of this file.

Functions

void read_cubi_hdr ()
 
void read_cubi_row ()
 
void read_cubi_chan ()
 
void bit_read ()
 
void main (int argc, argv)
 
void read_cubi_hdr (cubifiles, short *xlen, short *ylen)
 
void read_cubi_row (cubifiles, rle_pixel **rows)
 
void read_cubi_chan (FILE *infile, rle_pixel **rows, int chan)
 
void bit_read (FILE *infile, char headchar, int bit, rle_pixel **rows, int chan, int *xpos)
 

Function Documentation

void bit_read ( )
void bit_read ( FILE *  infile,
char  headchar,
int  bit,
rle_pixel **  rows,
int  chan,
int xpos 
)

Definition at line 152 of file cubitorle.c.

157 {
158  unsigned char runlength, rundata, bytedata;
159  int i;
160 
161  if (headchar & (1 << bit))
162  {
163  /* bit set, run data */
164  rundata = fgetc(infile);
165  runlength = fgetc(infile);
166  for (i=(*xpos); i < runlength+(*xpos); i++)
167  rows[chan][i] = rundata;
168  *xpos += (int) runlength;
169  }
170  else
171  {
172  /* bit not set, byte data */
173  bytedata = fgetc(infile);
174  rows[chan][*xpos] = bytedata;
175  (*xpos)++;
176  }
177 }
rle_pixel ** rows
Definition: rletopaint.c:57
static byte bit[9]
Definition: hilbert.c:52
int
Definition: getami.c:848
FILE * infile
Definition: targatorle.c:102
int i
Definition: rletorla.c:82
void main ( int  argc,
argv   
)

Definition at line 35 of file cubitorle.c.

38 {
39  FILE *cubifiles[4];
40  int i, j, oflag=0;
41  rle_pixel ** rows;
42  int xlen;
43  int cubi_xlen, cubi_ylen;
44  char *infname = NULL, *outfname = NULL;
45  char filename[256];
46  rle_hdr hdr;
47 
48  if ( scanargs( argc, argv,
49  "% o%-outfile!s inprefix!s\n(\
50 \tConvert Cubicomp image to URT image. Input image is in 3 files,\n\
51 \tinprefix.r, inprefix.g, inprefix.b.)",
52  &oflag, &outfname, &infname ) == 0 )
53  exit( 1 );
54  hdr = *rle_hdr_init( (rle_hdr *)NULL );
55  rle_names( &hdr, cmd_name( argv ), outfname, 0 );
56  hdr.rle_file = rle_open_f(hdr.cmd, outfname, "w");
57 
58  for ( i = 0; i < 3; i++ )
59  {
60  sprintf( filename, "%s.%c8", infname, "rgb"[i] );
61  cubifiles[i] = rle_open_f( hdr.cmd, filename, "r" );
62  }
63 
64  read_cubi_hdr(cubifiles, &cubi_xlen, &cubi_ylen);
65 
66  rle_dflt_hdr.alpha = 0;
68  rle_dflt_hdr.xmin = 0;
69  rle_dflt_hdr.xmax = cubi_xlen - 1;
70  rle_dflt_hdr.ymin = 0;
71  rle_dflt_hdr.ymax = cubi_ylen - 1;
72  xlen = rle_dflt_hdr.xmax - rle_dflt_hdr.xmin + 1;
73 
74  rle_addhist( argv, (rle_hdr *)NULL, &rle_dflt_hdr );
76 
77  if (rle_row_alloc( &rle_dflt_hdr, &rows ))
78  {
79  fprintf( stderr, "%s: malloc failed\n", hdr.cmd );
80  exit( -2 );
81  }
82 
83  for (j=rle_dflt_hdr.ymin; j <= rle_dflt_hdr.ymax; j++)
84  {
85  read_cubi_row( cubifiles, rows );
86  rle_putrow( rows, xlen, &rle_dflt_hdr);
87  }
88 
89 }
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
rle_hdr rle_dflt_hdr
Definition: rle_global.c:66
rle_hdr hdr
Definition: iristorle.c:35
int ymin
Definition: rle.h:100
void read_cubi_hdr()
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
Definition: rle.h:96
int xmax
Definition: rle.h:100
void read_cubi_row()
rle_pixel ** rows
Definition: rletopaint.c:57
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int oflag
Definition: painttorle.c:45
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 read_cubi_chan ( )
void read_cubi_chan ( FILE *  infile,
rle_pixel **  rows,
int  chan 
)

Definition at line 123 of file cubitorle.c.

127 {
128  static char headchar[3];
129  static int scanfull[3] = {-1, -1, -1};
130  int xpos = 0, bit;
131 
132  while (xpos < 512)
133  {
134  if (scanfull[chan] == -1)
135  headchar[chan] = fgetc(infile);
136 
137  for (bit = 0; bit < 8; bit++)
138  if (scanfull[chan] <= bit)
139  {
140  bit_read(infile, headchar[chan], bit, rows, chan, &xpos);
141  if (xpos >= 512)
142  {
143  scanfull[chan] = bit + 1;
144  break;
145  }
146  }
147  if (bit >= 7) scanfull[chan] = -1;
148  }
149 }
rle_pixel ** rows
Definition: rletopaint.c:57
static byte bit[9]
Definition: hilbert.c:52
FILE * infile
Definition: targatorle.c:102
void bit_read()
void read_cubi_hdr ( )
void read_cubi_hdr ( cubifiles  ,
short *  xlen,
short *  ylen 
)

Definition at line 92 of file cubitorle.c.

95 {
96  char junk[128];
97  short xmin, ymin, xmax, ymax;
98 
99  fread(junk, sizeof(char), 12, cubifiles[0]);
100  fread(xlen, sizeof(short), 1, cubifiles[0]);
101  fread(ylen, sizeof(short), 1, cubifiles[0]);
102  fread(&xmin, sizeof(short), 1, cubifiles[0]);
103  fread(&ymin, sizeof(short), 1, cubifiles[0]);
104  fread(&xmax, sizeof(short), 1, cubifiles[0]);
105  fread(&ymax, sizeof(short), 1, cubifiles[0]);
106  fread(junk, sizeof(char), 104, cubifiles[0]);
107 
108  fread(junk, sizeof(char), 128, cubifiles[1]);
109  fread(junk, sizeof(char), 128, cubifiles[2]);
110 }
void read_cubi_row ( )
void read_cubi_row ( cubifiles  ,
rle_pixel **  rows 
)

Definition at line 113 of file cubitorle.c.

116 {
117  read_cubi_chan(cubifiles[0],rows,0);
118  read_cubi_chan(cubifiles[1],rows,1);
119  read_cubi_chan(cubifiles[2],rows,2);
120 }
void read_cubi_chan()
rle_pixel ** rows
Definition: rletopaint.c:57