|
Line 0
Link Here
|
|
|
1 |
--- flrle.c.orig Mon Jun 25 04:49:20 1990 |
| 2 |
+++ flrle.c Thu Jan 13 17:29:17 2005 |
| 3 |
@@ -31,7 +31,7 @@ |
| 4 |
|
| 5 |
#ifdef RLE |
| 6 |
|
| 7 |
-#include "svfb_global.h" |
| 8 |
+#include "rle.h" |
| 9 |
|
| 10 |
#define CMAP_COLORS 3 |
| 11 |
|
| 12 |
@@ -82,6 +82,9 @@ |
| 13 |
int planes; |
| 14 |
int rowlen; |
| 15 |
int plnlen; |
| 16 |
+ rle_hdr out_hdr; |
| 17 |
+ |
| 18 |
+ out_hdr = *rle_hdr_init( (rle_hdr *)0 ); |
| 19 |
|
| 20 |
if (image->hdr.physbits != 8) { |
| 21 |
fputs ("write_rle: error: can only handle 8 physical bits per pixel\n", |
| 22 |
@@ -95,19 +98,19 @@ |
| 23 |
rowlen = image->hdr.rowlen; |
| 24 |
plnlen = image->hdr.plnlen; |
| 25 |
|
| 26 |
- sv_globals.sv_ncolors = planes; |
| 27 |
- sv_globals.sv_alpha = 0; /* no alpha channel */ |
| 28 |
- sv_globals.sv_background = 2; /* clear background to sv_bg_color */ |
| 29 |
- sv_globals.sv_xmin = 0; |
| 30 |
- sv_globals.sv_xmax = cols - 1; |
| 31 |
- sv_globals.sv_ymin = 0; |
| 32 |
- sv_globals.sv_ymax = rows - 1; |
| 33 |
- sv_globals.sv_cmaplen = 0; /* log2(color_map_length) */ |
| 34 |
+ out_hdr.ncolors = planes; |
| 35 |
+ out_hdr.alpha = 0; /* no alpha channel */ |
| 36 |
+ out_hdr.background = 2; /* clear background to bg_color */ |
| 37 |
+ out_hdr.xmin = 0; |
| 38 |
+ out_hdr.xmax = cols - 1; |
| 39 |
+ out_hdr.ymin = 0; |
| 40 |
+ out_hdr.ymax = rows - 1; |
| 41 |
+ out_hdr.cmaplen = 0; /* log2(color_map_length) */ |
| 42 |
if (image->hdr.clrlen > 0) { |
| 43 |
- sv_globals.sv_ncmap = CMAP_COLORS; |
| 44 |
+ out_hdr.ncmap = CMAP_COLORS; |
| 45 |
|
| 46 |
for (i = 1; i < image->hdr.clrlen / CMAP_COLORS; i <<= 1) |
| 47 |
- sv_globals.sv_cmaplen++; |
| 48 |
+ out_hdr.cmaplen++; |
| 49 |
|
| 50 |
if ((colorMap = (rle_map *)malloc(image->hdr.clrlen*sizeof(rle_map))) == |
| 51 |
(rle_map *)NULL) |
| 52 |
@@ -117,15 +120,15 @@ |
| 53 |
} |
| 54 |
for (i = 0; i < image->hdr.clrlen; i++) |
| 55 |
colorMap[i] = (rle_map)image->cm[i] << 8; |
| 56 |
- sv_globals.sv_cmap = colorMap; |
| 57 |
+ out_hdr.cmap = colorMap; |
| 58 |
} |
| 59 |
else { |
| 60 |
- sv_globals.sv_ncmap = 0; |
| 61 |
- sv_globals.sv_cmap = (rle_map *)NULL; |
| 62 |
+ out_hdr.ncmap = 0; |
| 63 |
+ out_hdr.cmap = (rle_map *)NULL; |
| 64 |
} |
| 65 |
|
| 66 |
for (channel = 0; channel < planes; channel++) |
| 67 |
- SV_SET_BIT (sv_globals, channel); |
| 68 |
+ RLE_SET_BIT (out_hdr, channel); |
| 69 |
|
| 70 |
if (*image->hdr.title != '\0') |
| 71 |
sprintf (CommentBuf (cp++), "%s=%s", |
| 72 |
@@ -144,7 +147,7 @@ |
| 73 |
* in a comment. |
| 74 |
*/ |
| 75 |
if (image->hdr.clrlen > 0 && |
| 76 |
- (1 << sv_globals.sv_cmaplen) != image->hdr.clrlen / CMAP_COLORS) |
| 77 |
+ (1 << out_hdr.cmaplen) != image->hdr.clrlen / CMAP_COLORS) |
| 78 |
{ |
| 79 |
sprintf (CommentBuf (cp++), "%s=%d", |
| 80 |
CMAP_COMMENT, image->hdr.clrlen / CMAP_COLORS); |
| 81 |
@@ -152,11 +155,11 @@ |
| 82 |
|
| 83 |
*cp = (char *)NULL; |
| 84 |
|
| 85 |
- sv_globals.sv_comments = cp > comments ? comments : (char **)NULL; |
| 86 |
+ out_hdr.comments = cp > comments ? comments : (char **)NULL; |
| 87 |
|
| 88 |
- sv_globals.svfb_fd = wfile; |
| 89 |
+ out_hdr.rle_file = wfile; |
| 90 |
|
| 91 |
- sv_setup (RUN_DISPATCH, &sv_globals); |
| 92 |
+ rle_put_setup (&out_hdr); |
| 93 |
|
| 94 |
if ((rowvec = (unsigned char **)malloc (planes*sizeof(unsigned char *))) == |
| 95 |
(unsigned char **)NULL) |
| 96 |
@@ -168,9 +171,9 @@ |
| 97 |
for (j = rows - 1; j >= 0; --j) { |
| 98 |
for (channel = 0; channel < planes; channel ++) |
| 99 |
rowvec[channel] = image->bm + j * rowlen + channel * plnlen; |
| 100 |
- sv_putrow (rowvec, cols, &sv_globals); |
| 101 |
+ rle_putrow (rowvec, cols, &out_hdr); |
| 102 |
} |
| 103 |
- sv_puteof (&sv_globals); |
| 104 |
+ rle_puteof (&out_hdr); |
| 105 |
|
| 106 |
free (rowvec); |
| 107 |
while (cp > comments) |
| 108 |
@@ -203,13 +206,16 @@ |
| 109 |
int plnlen; |
| 110 |
int mapEntries; |
| 111 |
int clearRow; |
| 112 |
+ rle_hdr in_hdr; |
| 113 |
+ |
| 114 |
+ in_hdr = *rle_hdr_init( (rle_hdr *)0 ); |
| 115 |
|
| 116 |
/* must put the magic number back so the setup code can read it */ |
| 117 |
while (mlen--) |
| 118 |
(void)ungetc (*mstr++, rfile); |
| 119 |
|
| 120 |
- sv_globals.svfb_fd = rfile; |
| 121 |
- switch (rle_get_setup (&sv_globals)) { |
| 122 |
+ in_hdr.rle_file = rfile; |
| 123 |
+ switch (rle_get_setup (&in_hdr)) { |
| 124 |
case 0: |
| 125 |
break; /* success */ |
| 126 |
case -1: |
| 127 |
@@ -229,34 +235,34 @@ |
| 128 |
stderr); |
| 129 |
} |
| 130 |
|
| 131 |
- if (sv_globals.sv_alpha) { |
| 132 |
+ if (in_hdr.alpha) { |
| 133 |
fputs ("read_rle: discarding alpha channel.\n", stderr); |
| 134 |
- SV_CLR_BIT (sv_globals, SV_ALPHA); |
| 135 |
+ RLE_CLR_BIT (in_hdr, RLE_ALPHA); |
| 136 |
} |
| 137 |
|
| 138 |
- image->hdr.cols = sv_globals.sv_xmax - sv_globals.sv_xmin + 1; |
| 139 |
- image->hdr.rows = rows = sv_globals.sv_ymax - sv_globals.sv_ymin + 1; |
| 140 |
- image->hdr.planes = planes = sv_globals.sv_ncolors; |
| 141 |
- image->hdr.bits = sv_globals.sv_cmaplen ? sv_globals.sv_cmaplen : 8; |
| 142 |
+ image->hdr.cols = in_hdr.xmax - in_hdr.xmin + 1; |
| 143 |
+ image->hdr.rows = rows = in_hdr.ymax - in_hdr.ymin + 1; |
| 144 |
+ image->hdr.planes = planes = in_hdr.ncolors; |
| 145 |
+ image->hdr.bits = in_hdr.cmaplen ? in_hdr.cmaplen : 8; |
| 146 |
image->hdr.physbits = 8; |
| 147 |
image->hdr.rowlen = rowlen = image->hdr.cols; |
| 148 |
image->hdr.plnlen = plnlen = image->hdr.rows * image->hdr.rowlen; |
| 149 |
|
| 150 |
- image->hdr.clrlen = 1 << sv_globals.sv_cmaplen; |
| 151 |
- if ((comment = rle_getcom (CMAP_COMMENT, &sv_globals)) != (char *)NULL) |
| 152 |
+ image->hdr.clrlen = 1 << in_hdr.cmaplen; |
| 153 |
+ if ((comment = rle_getcom (CMAP_COMMENT, &in_hdr)) != (char *)NULL) |
| 154 |
image->hdr.clrlen = atoi (comment); |
| 155 |
- image->hdr.clrlen *= sv_globals.sv_ncmap; |
| 156 |
+ image->hdr.clrlen *= in_hdr.ncmap; |
| 157 |
|
| 158 |
- if ((comment = rle_getcom (ASPECT_COMMENT, &sv_globals)) != (char *)NULL) |
| 159 |
+ if ((comment = rle_getcom (ASPECT_COMMENT, &in_hdr)) != (char *)NULL) |
| 160 |
image->hdr.aspect = atof (comment); |
| 161 |
else |
| 162 |
image->hdr.aspect = 1.0; |
| 163 |
|
| 164 |
- if ((comment = rle_getcom (TITLE_COMMENT, &sv_globals)) != (char *)NULL) |
| 165 |
+ if ((comment = rle_getcom (TITLE_COMMENT, &in_hdr)) != (char *)NULL) |
| 166 |
(void)strcpy (image->hdr.title, comment); |
| 167 |
else |
| 168 |
image->hdr.title[0] = '\0'; |
| 169 |
- if ((comment = rle_getcom (CREDITS_COMMENT, &sv_globals)) != (char *)NULL) |
| 170 |
+ if ((comment = rle_getcom (CREDITS_COMMENT, &in_hdr)) != (char *)NULL) |
| 171 |
(void)strcpy (image->hdr.credits, comment); |
| 172 |
else |
| 173 |
image->hdr.credits[0] = '\0'; |
| 174 |
@@ -266,9 +272,9 @@ |
| 175 |
alloc_fbm (image); |
| 176 |
|
| 177 |
if (image->hdr.clrlen > 0) { |
| 178 |
- mapEntries = (image->hdr.clrlen / sv_globals.sv_ncmap); |
| 179 |
+ mapEntries = (image->hdr.clrlen / in_hdr.ncmap); |
| 180 |
cp = image->cm; |
| 181 |
- colorMap = buildmap (&sv_globals, CMAP_COLORS, 1.0); |
| 182 |
+ colorMap = buildmap (&in_hdr, CMAP_COLORS, 1.0, 1.0); |
| 183 |
for (channel = 0; channel < CMAP_COLORS; channel++) { |
| 184 |
for (j = 0; j < mapEntries; j++) |
| 185 |
*cp++ = colorMap[channel][j]; |
| 186 |
@@ -278,26 +284,26 @@ |
| 187 |
image->hdr.clrlen = mapEntries * CMAP_COLORS; /* renormalize clrlen */ |
| 188 |
} |
| 189 |
|
| 190 |
- switch (sv_globals.sv_background) { |
| 191 |
+ switch (in_hdr.background) { |
| 192 |
case 0: /* no background color was saved */ |
| 193 |
clearRow = TRUE; /* manually clear rows to 0 */ |
| 194 |
break; |
| 195 |
case 1: /* don't clear to the background color */ |
| 196 |
- sv_globals.sv_background = 2; /* force automatic clearing */ |
| 197 |
+ in_hdr.background = 2; /* force automatic clearing */ |
| 198 |
/* fall through... */ |
| 199 |
case 2: /* clear to the background color */ |
| 200 |
clearRow = FALSE; |
| 201 |
break; |
| 202 |
default: |
| 203 |
fprintf (stderr, "read_rle: unknown background flag '%d'.\n", |
| 204 |
- sv_globals.sv_background); |
| 205 |
+ in_hdr.background); |
| 206 |
} |
| 207 |
|
| 208 |
/* move image to origin */ |
| 209 |
- sv_globals.sv_xmin = 0; |
| 210 |
- sv_globals.sv_xmax = image->hdr.cols - 1; |
| 211 |
- sv_globals.sv_ymin = 0; |
| 212 |
- sv_globals.sv_ymax = image->hdr.rows - 1; |
| 213 |
+ in_hdr.xmin = 0; |
| 214 |
+ in_hdr.xmax = image->hdr.cols - 1; |
| 215 |
+ in_hdr.ymin = 0; |
| 216 |
+ in_hdr.ymax = image->hdr.rows - 1; |
| 217 |
|
| 218 |
if ((rowvec = (unsigned char **)malloc (planes*sizeof(unsigned char *))) == |
| 219 |
(unsigned char **)NULL) |
| 220 |
@@ -312,7 +318,7 @@ |
| 221 |
if (clearRow) |
| 222 |
bzero ((char *)rowvec[channel], rowlen); |
| 223 |
} |
| 224 |
- rle_getrow (&sv_globals, rowvec); |
| 225 |
+ rle_getrow (&in_hdr, rowvec); |
| 226 |
} |
| 227 |
free (rowvec); |
| 228 |
|