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

Go to the source code of this file.

Functions

void init ()
 
void read_scan ()
 
void write_scan ()
 
void main (int argc, argv)
 
void read_scan (FILE *infile)
 
void write_scan (rle_hdr *hdr)
 

Variables

int redval = 255
 
int grnval = 255
 
int bluval = 255
 
int alfval = 255
 
unsigned char in_line [72]
 
rle_pixel ** outrows
 
int xlat [256]
 
int invert_flag = 0
 
int oflag = 0
 

Function Documentation

void init ( )

Definition at line 177 of file painttorle.c.

References xlat.

178 {
179  int bits[8], i, j;
180 
181  /* initialize translation table */
182  j = 1;
183  for( i=0; i<8; i++ )
184  {
185  bits[i] = j;
186  j *= (1 << 1);
187  }
188 
189  for( i=0; i<256; i++ )
190  {
191  if( i & 1 ) xlat[i] = bits[0];
192  else xlat[i] = 0;
193 
194  if( i & 2 ) xlat[i] += bits[1];
195  if( i & 4 ) xlat[i] += bits[2];
196  if( i & 8 ) xlat[i] += bits[3];
197  if( i & 16 ) xlat[i] += bits[4];
198  if( i & 32 ) xlat[i] += bits[5];
199  if( i & 64 ) xlat[i] += bits[6];
200  if( i & 128 ) xlat[i] += bits[7];
201  }
202 }
int xlat[256]
Definition: painttorle.c:44
int i
Definition: rletorla.c:82
void main ( int  argc,
argv   
)

Definition at line 50 of file painttorle.c.

53 {
54  char *in_fname = NULL,
55  *out_fname = NULL;
56  int cflag = 0;
57  FILE *infile;
58  int i;
59  rle_hdr hdr;
60 
61  if ( scanargs( argc, argv,
62  "% c%-red%dgreen%dblue%dalpha%d r%- o%-outfile!s infile.paint%s\n(\
63 \tConvert MacPaint file to RLE.\n\
64 \t-c\tSpecify \"white\" color, optionally include alpha value.\n\
65 \t-r\tReverse image (foreground colored, background black).)",
66  &cflag, &redval, &grnval, &bluval, &alfval, &invert_flag,
67  &oflag, &out_fname, &in_fname ) == 0)
68  exit(-1);
69 
70  hdr = *rle_hdr_init( (rle_hdr *)NULL );
71  rle_names( &hdr, cmd_name( argv ), in_fname, 0 );
72  infile = rle_open_f( hdr.cmd, in_fname, "r" );
73  hdr.rle_file = rle_open_f(hdr.cmd, out_fname, "w");
74 
75  hdr.xmax = 575;
76  hdr.ymax = 719;
77  hdr.alpha = 1;
78  hdr.ncolors = 3;
79  RLE_SET_BIT( hdr, RLE_ALPHA ); /* So it gets generated */
80 
81  if (rle_row_alloc( &hdr, &outrows ))
82  {
83  fprintf(stderr, "%s: No heap space\n", hdr.cmd);
84  exit(-2);
85  }
86 
87  rle_addhist( argv, (rle_hdr *)NULL, &hdr );
88  rle_put_setup( &hdr );
89  /* initialize bit-twiddling tables */
90  init();
91 
92  /* read and discard 512 byte MacPaint header */
93  for (i=0; i<512; i++)
94  getc(infile);
95 
96  /* Read and process each of the 720 MacPaint scan lines */
97  for (i=0; i < 720; i++)
98  {
99  read_scan( infile );
100  write_scan( &hdr );
101  }
102 
103  rle_puteof( &hdr );
104  exit(0);
105 }
#define RLE_SET_BIT(glob, bit)
Definition: rle.h:122
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
int grnval
Definition: painttorle.c:41
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
void read_scan()
int bluval
Definition: painttorle.c:41
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
rle_hdr hdr
Definition: iristorle.c:35
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
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
int alfval
Definition: painttorle.c:41
FILE * infile
Definition: targatorle.c:102
int ymax
Definition: rle.h:100
int invert_flag
Definition: painttorle.c:45
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
#define RLE_ALPHA
Definition: rle.h:65
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
void write_scan()
int cflag
Definition: getgmr.c:19
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
rle_pixel ** outrows
Definition: painttorle.c:43
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
void init()
Definition: painttorle.c:177
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
int redval
Definition: painttorle.c:41
void read_scan ( )
void read_scan ( FILE *  infile)

Definition at line 111 of file painttorle.c.

113 {
114  int in_pos, count, data_byte;
115 
116  in_pos = 0;
117  while (in_pos < 72)
118  {
119  count = getc(infile);
120  if (count > 127) count -= 256;
121 
122  if (count >= 0) { /* run of raw bytes */
123  count++; /* # of bytes to read */
124  while (count--)
125  in_line[in_pos++] = getc(infile);
126  }
127  else { /* run of repeated byte */
128  count = -count+1; /* repetition factor */
129  data_byte = getc(infile); /* byte to repeat */
130 
131  while (count--)
132  in_line[in_pos++] = data_byte;
133  }
134  }
135 }
unsigned char in_line[72]
Definition: painttorle.c:42
FILE * infile
Definition: targatorle.c:102
void write_scan ( )
void write_scan ( rle_hdr hdr)

Definition at line 141 of file painttorle.c.

143 {
144  register int i, j;
145  register int bit;
146  int outval, outpos;
147 
148  /* Convert the array of bits to an array of pixels */
149 
150  for (i = 0; i < 72; i++ )
151  {
152  for (bit = 7; bit >= 0; bit--)
153  {
154  outval = xlat[in_line[i] & 0xff] & 0xff;
155  outval = (outval >> bit) & 1; /* Convert to boolean */
156  if (invert_flag) outval = 1-outval;
157  outpos = i*8 + (7-bit);
158  if (outval)
159  {
160  outrows[RLE_ALPHA][outpos] = alfval;
161  outrows[RLE_RED][outpos] = redval;
162  outrows[RLE_GREEN][outpos] = grnval;
163  outrows[RLE_BLUE][outpos] = bluval;
164  }
165  else
166  {
167  for( j = RLE_ALPHA; j <= RLE_BLUE; j++ )
168  outrows[j][outpos] = 0;
169  }
170  }
171  }
172  rle_putrow( outrows, 576, hdr );
173 }
int grnval
Definition: painttorle.c:41
unsigned char in_line[72]
Definition: painttorle.c:42
int bluval
Definition: painttorle.c:41
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
#define RLE_GREEN
Definition: rle.h:63
#define RLE_BLUE
Definition: rle.h:64
#define RLE_RED
Definition: rle.h:62
int xlat[256]
Definition: painttorle.c:44
static byte bit[9]
Definition: hilbert.c:52
int alfval
Definition: painttorle.c:41
int invert_flag
Definition: painttorle.c:45
int i
Definition: rletorla.c:82
#define RLE_ALPHA
Definition: rle.h:65
rle_pixel ** outrows
Definition: painttorle.c:43
int redval
Definition: painttorle.c:41

Variable Documentation

int alfval = 255

Definition at line 41 of file painttorle.c.

int bluval = 255

Definition at line 41 of file painttorle.c.

int grnval = 255

Definition at line 41 of file painttorle.c.

unsigned char in_line[72]

Definition at line 42 of file painttorle.c.

int invert_flag = 0

Definition at line 45 of file painttorle.c.

int oflag = 0

Definition at line 45 of file painttorle.c.

rle_pixel** outrows

Definition at line 43 of file painttorle.c.

int redval = 255

Definition at line 41 of file painttorle.c.

int xlat[256]

Definition at line 44 of file painttorle.c.

Referenced by init().