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

Go to the source code of this file.

Macros

#define NO_DECLARE_MALLOC   /* ppm.h does it */
 
#define VPRINTF   if (verbose || header) fprintf
 
#define GRAYSCALE   001 /* 8 bits, no colormap */
 
#define PSEUDOCOLOR   010 /* 8 bits, colormap */
 
#define TRUECOLOR   011 /* 24 bits, colormap */
 
#define DIRECTCOLOR   100 /* 24 bits, no colormap */
 

Functions

void read_rle_header ()
 
void write_ppm_data ()
 
int main (int argc, char **argv)
 

Variables

static char rcsid [] = "$Header: /l/spencer/src/urt/cnv/RCS/rletoppm.c,v 3.0.1.4 1992/03/04 19:30:10 spencer Exp $"
 
pixval maxval = 255
 
rle_hdr hdr
 
rle_mapcolormap
 
FILE * fpin
 
int visual
 
int maplen
 
int width
 
int height
 
int verbose = 0
 
int header = 0
 
int plain = 0
 

Macro Definition Documentation

#define DIRECTCOLOR   100 /* 24 bits, no colormap */

Definition at line 47 of file rletoppm.c.

#define GRAYSCALE   001 /* 8 bits, no colormap */

Definition at line 44 of file rletoppm.c.

#define NO_DECLARE_MALLOC   /* ppm.h does it */

Definition at line 38 of file rletoppm.c.

#define PSEUDOCOLOR   010 /* 8 bits, colormap */

Definition at line 45 of file rletoppm.c.

#define TRUECOLOR   011 /* 24 bits, colormap */

Definition at line 46 of file rletoppm.c.

#define VPRINTF   if (verbose || header) fprintf

Definition at line 43 of file rletoppm.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 225 of file rletoppm.c.

228 {
229  char *fname = NULL;
230 /*
231  * Get those options.
232  */
233  if (!scanargs(argc,argv,
234  "% v%- h%- p%- infile%s\n(\
235 \tConvert an RLE image to ppm true color.\n\
236 \t-v\tVerbose -- print out progress.\n\
237 \t-h\tPrint RLE header information and exit.\n\
238 \t-p\tWrite output image in \"plain\" mode.)",
239  &verbose,
240  &header,
241  &plain,
242  &fname))
243  exit(-1);
244 /*
245  * Open the file.
246  */
247  /* Initialize header. */
248  hdr = *rle_hdr_init( (rle_hdr *)NULL );
249  rle_names( &hdr, cmd_name( argv ), fname, 0 );
250 
251  fpin = rle_open_f( hdr.cmd, fname, "r" );
252 /*
253  * Read the rle file header.
254  */
255  read_rle_header();
256  if (header)
257  exit(0);
258 /*
259  * Write the ppm file header.
260  */
261  ppm_writeppminit(stdout, width, height, maxval, plain);
262 /*
263  * Write the rest of the ppm file.
264  */
265  write_ppm_data();
266  fclose(fpin);
267 
268  return 0;
269 }
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
pixval maxval
Definition: rletoppm.c:51
int height
Definition: rletoppm.c:62
rle_hdr hdr
Definition: rletoppm.c:55
int verbose
Definition: rletoppm.c:63
char * fname[3]
Definition: show3.c:31
void read_rle_header()
Definition: rletoppm.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
int header
Definition: rletoppm.c:63
Definition: rle.h:96
int width
Definition: rletoppm.c:62
void write_ppm_data()
Definition: rletoppm.c:150
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
int plain
Definition: rletoppm.c:64
char * cmd_name(char **argv)
Definition: cmd_name.c:31
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
FILE * fpin
Definition: rletoppm.c:60
void read_rle_header ( )

Definition at line 68 of file rletoppm.c.

References rle_hdr::alpha, rle_hdr::background, rle_hdr::bg_color, rle_hdr::cmap, rle_hdr::cmaplen, colormap, rle_hdr::comments, fpin, hdr, height, maplen, rle_hdr::ncmap, rle_hdr::ncolors, rle_hdr::rle_file, rle_get_setup(), visual, width, rle_hdr::xmax, rle_hdr::xmin, rle_hdr::ymax, and rle_hdr::ymin.

69 {
70  int i;
71  hdr.rle_file = fpin;
73  width = hdr.xmax - hdr.xmin + 1;
74  height = hdr.ymax - hdr.ymin + 1;
75  VPRINTF(stderr, "Image size: %dx%d\n", width, height);
76  if (hdr.ncolors == 1 && hdr.ncmap == 3) {
78  colormap = hdr.cmap;
79  maplen = (1 << hdr.cmaplen);
80  VPRINTF(stderr, "Mapped color image with a map of length %d.\n", maplen);
81  }
82  else if (hdr.ncolors == 3 && hdr.ncmap == 0) {
84  VPRINTF(stderr, "24 bit color image, no colormap.\n");
85  }
86  else if (hdr.ncolors == 3 && hdr.ncmap == 3) {
87  visual = TRUECOLOR;
88  colormap = hdr.cmap;
89  maplen = (1 << hdr.cmaplen);
90  VPRINTF(stderr, "24 bit color image with color map of length %d\n" ,maplen);
91  }
92  else if (hdr.ncolors == 1 && hdr.ncmap == 0) {
93  visual = GRAYSCALE;
94  VPRINTF(stderr, "Grayscale image.\n");
95  }
96  else {
97  fprintf(stderr,
98  "ncolors = %d, ncmap = %d, I don't know how to handle this!\n",
99  hdr.ncolors, hdr.ncmap);
100  exit(-1);
101  }
102  if (hdr.alpha == 0)
103  VPRINTF(stderr, "No alpha channel.\n");
104  else if (hdr.alpha == 1)
105  VPRINTF(stderr, "Alpha channel exists!\n");
106  else {
107  fprintf(stderr, "alpha = %d, I don't know how to handle this!\n",
108  hdr.alpha);
109  exit(-1);
110  }
111  switch (hdr.background) {
112  case 0:
113  VPRINTF(stderr, "Use all pixels, ignore background color.");
114  break;
115  case 1:
116  VPRINTF(stderr,
117  "Use only non-background pixels, ignore background color.");
118  break;
119  case 2:
120  VPRINTF(stderr,
121  "Use only non-background pixels, clear to background color (default).");
122  break;
123  default:
124  VPRINTF(stderr, "Unknown background flag!\n");
125  break;
126  }
127  for (i = 0; i < hdr.ncolors; i++)
128  VPRINTF(stderr, " %d", hdr.bg_color[i]);
129  if (hdr.ncolors == 1 && hdr.ncmap == 3) {
130  VPRINTF(stderr, " (%d %d %d)\n",
131  hdr.cmap[hdr.bg_color[0]]>>8,
132  hdr.cmap[hdr.bg_color[0]+256]>>8,
133  hdr.cmap[hdr.bg_color[0]+512]>>8);
134  }
135  else if (hdr.ncolors == 3 && hdr.ncmap == 3) {
136  VPRINTF(stderr, " (%d %d %d)\n",
137  hdr.cmap[hdr.bg_color[0]]>>8,
138  hdr.cmap[hdr.bg_color[1]+256]>>8,
139  hdr.cmap[hdr.bg_color[2]+512]>>8);
140  }
141  else
142  VPRINTF(stderr, "\n");
143  if (hdr.comments)
144  for (i = 0; hdr.comments[i] != NULL; i++)
145  VPRINTF(stderr, "%s\n", hdr.comments[i]);
146 }
int xmin
Definition: rle.h:100
const char ** comments
Definition: rle.h:113
int maplen
Definition: rletoppm.c:61
int height
Definition: rletoppm.c:62
#define PSEUDOCOLOR
Definition: rletoppm.c:45
#define GRAYSCALE
Definition: rletoppm.c:44
rle_map * cmap
Definition: rle.h:112
rle_hdr hdr
Definition: rletoppm.c:55
int * bg_color
Definition: rle.h:100
int ymin
Definition: rle.h:100
rle_map * colormap
Definition: rletoppm.c:56
int visual
Definition: rletoppm.c:61
#define TRUECOLOR
Definition: rletoppm.c:46
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
#define DIRECTCOLOR
Definition: rletoppm.c:47
int xmax
Definition: rle.h:100
#define VPRINTF
Definition: rletoppm.c:43
int background
Definition: rle.h:100
int width
Definition: rletoppm.c:62
int ncmap
Definition: rle.h:100
int ymax
Definition: rle.h:100
int cmaplen
Definition: rle.h:100
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
FILE * fpin
Definition: rletoppm.c:60

Here is the call graph for this function:

void write_ppm_data ( )

Definition at line 150 of file rletoppm.c.

References rle_hdr::cmd, hdr, height, rle_getrow(), rle_row_alloc(), rle_row_free(), visual, and width.

151 {
152  rle_pixel ***scanlines, **scanline;
153  register pixval r, g, b;
154  register pixel *pixelrow, *pP;
155  register int scan, x, y;
156 /*
157  * Allocate some stuff.
158  */
159  pixelrow = ppm_allocrow(width);
160 
161  scanlines = (rle_pixel ***)malloc( height * sizeof(rle_pixel **) );
162  RLE_CHECK_ALLOC( hdr.cmd, scanlines, "scanline pointers" );
163 
164  for ( scan = 0; scan < height; scan++ )
165  RLE_CHECK_ALLOC( hdr.cmd, (rle_row_alloc(&hdr, &scanlines[scan]) >= 0),
166  "pixel memory" );
167 /*
168  * Loop through those scan lines.
169  */
170  for (scan = 0; scan < height; scan++)
171  y = rle_getrow(&hdr, scanlines[height - scan - 1]);
172  for (scan = 0; scan < height; scan++) {
173  scanline = scanlines[scan];
174  switch (visual) {
175  case GRAYSCALE: /* 8 bits without colormap */
176  for (x = 0, pP = pixelrow; x < width; x++, pP++) {
177  r = scanline[0][x];
178  g = scanline[0][x];
179  b = scanline[0][x];
180  PPM_ASSIGN(*pP, r, g, b);
181  }
182  break;
183  case TRUECOLOR: /* 24 bits with colormap */
184  for (x = 0, pP = pixelrow; x < width; x++, pP++) {
185  r = colormap[scanline[0][x]]>>8;
186  g = colormap[scanline[1][x]+256]>>8;
187  b = colormap[scanline[2][x]+512]>>8;
188  PPM_ASSIGN(*pP, r, g, b);
189  }
190  break;
191  case DIRECTCOLOR: /* 24 bits without colormap */
192  for (x = 0, pP = pixelrow; x < width; x++, pP++) {
193  r = scanline[0][x];
194  g = scanline[1][x];
195  b = scanline[2][x];
196  PPM_ASSIGN(*pP, r, g, b);
197  }
198  break;
199  case PSEUDOCOLOR: /* 8 bits with colormap */
200  for (x = 0, pP = pixelrow; x < width; x++, pP++) {
201  r = colormap[scanline[0][x]]>>8;
202  g = colormap[scanline[0][x]+256]>>8;
203  b = colormap[scanline[0][x]+512]>>8;
204  PPM_ASSIGN(*pP, r, g, b);
205  }
206  break;
207  default:
208  break;
209  }
210  /*
211  * Write the scan line.
212  */
213  ppm_writeppmrow(stdout, pixelrow, width, maxval, plain);
214  } /* end of for scan = 0 to height */
215 
216  /* Free scanline memory. */
217  for ( scan = 0; scan < height; scan++ )
218  rle_row_free( &hdr, scanlines[scan] );
219  free( scanlines );
220 }
static unsigned char g
Definition: getami.c:692
void rle_row_free(rle_hdr *the_hdr, rle_pixel **scanp)
Definition: rle_row_alc.c:114
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
pixval maxval
Definition: rletoppm.c:51
int height
Definition: rletoppm.c:62
#define PSEUDOCOLOR
Definition: rletoppm.c:45
static unsigned char r
Definition: getami.c:692
#define GRAYSCALE
Definition: rletoppm.c:44
rle_hdr hdr
Definition: rletoppm.c:55
static int y
Definition: getami.c:691
rle_map * colormap
Definition: rletoppm.c:56
unsigned char ** scan
Definition: rle.c:26
int visual
Definition: rletoppm.c:61
static unsigned char b
Definition: getami.c:692
#define TRUECOLOR
Definition: rletoppm.c:46
const char * cmd
Definition: rle.h:133
#define DIRECTCOLOR
Definition: rletoppm.c:47
static int x
Definition: getami.c:691
int width
Definition: rletoppm.c:62
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int plain
Definition: rletoppm.c:64
unsigned char scanline[4][1280]
Definition: get_orion.c:37
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86

Here is the call graph for this function:

Variable Documentation

rle_map* colormap

Definition at line 56 of file rletoppm.c.

FILE* fpin

Definition at line 60 of file rletoppm.c.

rle_hdr hdr

Definition at line 55 of file rletoppm.c.

int header = 0

Definition at line 63 of file rletoppm.c.

int height
int maplen

Definition at line 61 of file rletoppm.c.

pixval maxval = 255

Definition at line 51 of file rletoppm.c.

int plain = 0

Definition at line 64 of file rletoppm.c.

char rcsid[] = "$Header: /l/spencer/src/urt/cnv/RCS/rletoppm.c,v 3.0.1.4 1992/03/04 19:30:10 spencer Exp $"
static

Definition at line 29 of file rletoppm.c.

int verbose = 0

Definition at line 63 of file rletoppm.c.

int visual

Definition at line 61 of file rletoppm.c.

int width