Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rle.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1988 Research Institute for Advanced Computer Science.
3  * All rights reserved. The RIACS Software Policy contains specific
4  * terms and conditions on the use of this software, and must be
5  * distributed with any copies. This file may be redistributed. This
6  * copyright and notice must be preserved in all copies made of this file.
7  */
8 static char rcsid[] = "$Header:$";
9 
10 /*
11  * Interface routines for Utah Raster Toolkit
12  */
13 
14 #include <stdio.h>
15 #include "rle.h"
16 
17 /*
18  * Globals are stored in a structure.
19  */
20 
21 rle_hdr hdr;
22 
23 static struct {
24  int width;
25  int height;
26  unsigned char **scan;
27  int row;
28 } Globals;
29 
30 void
31 rasterInit(fd, width, height)
32 int fd;
33 int width;
34 int height;
35 {
36  FILE *rleFile;
37  int i;
38 
39  hdr = *rle_hdr_init( (rle_hdr *)NULL );
40  /* Fake the names, since we don't have argv. */
41  rle_names( &hdr, "rletoabA62", fd == 0 ? NULL : "RLE file", 0 );
42 
43  Globals.width = width;
44  Globals.height = height;
45  if (fd == 0) {
46  rleFile = stdin;
47  } else {
48  rleFile = fdopen(fd, "r");
49  }
50  hdr.rle_file = rleFile;
51  rle_get_setup_ok(&hdr, NULL, NULL);
52 
53  if (hdr.xmax > width) {
54  fprintf(stderr, "Warning: RLE width (%d) exceeds maximum (%d)\n",
55  hdr.xmax, width);
56  }
57  if (hdr.ymax > height) {
58  fprintf(stderr, "Warning: RLE height (%d) exceeds maximum (%d)\n",
59  hdr.ymax, height);
60  }
61  Globals.row = 0;
62  Globals.scan = (unsigned char **) malloc((hdr.ncolors +
63  hdr.alpha) *
64  sizeof(unsigned char *));
65  for (i = 0; i < hdr.ncolors + hdr.alpha; i++)
66  Globals.scan[i] =
67  (unsigned char *)malloc(hdr.xmax+1);
68 
69  if (hdr.alpha) {
70  Globals.scan++;
71  }
72 }
73 
74 void
75 rasterRowGet(red, green, blue)
76 unsigned char *red, *green, *blue;
77 {
78  int i, max;
79 
80  if (Globals.row < hdr.ymin || Globals.row > hdr.ymax) {
81  for (i = 0; i < Globals.width; i++) {
82  red[i] = 0;
83  green[i] = 0;
84  blue[i] = 0;
85  }
86  } else {
87  rle_getrow(&hdr, Globals.scan);
88  max = hdr.xmax < Globals.width ?
89  hdr.xmax : Globals.width;
90  for (i = 0 ; i < max; i++) {
91  red[i] = Globals.scan[0][i];
92  green[i] = Globals.scan[1][i];
93  blue[i] = Globals.scan[2][i];
94  }
95  for (; i < Globals.width; i++) {
96  red[i] = green[i] = blue[i] = 0;
97  }
98  }
99  Globals.row++;
100 }
101 
102 void
103 rasterDone()
104 {
106 }
rle_hdr hdr
Definition: getx10.c:84
static char rcsid[]
Definition: rle.c:8
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
int rle_getrow(rle_hdr *the_hdr, scanline)
Definition: rle_getrow.c:333
int ymin
Definition: rle.h:100
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
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
int ymax
Definition: rle.h:100
int alpha
Definition: rle.h:100
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