44 #define strrchr rindex
49 extern void *malloc();
51 extern char *malloc();
57 #define VPRINTF if (verbose || header) fprintf
59 #define PSEUDOCOLOR 010
61 #define DIRECTCOLOR 100
86 void read_rle_header(minx, maxx, miny, maxy)
87 int *minx, *maxx, *miny, *maxy;
95 VPRINTF(stderr,
"Image size: %dx%d\n", *maxx-*minx+1, *maxy-*miny+1);
100 VPRINTF(stderr,
"Mapped color image with a map of length %d.\n",
maplen);
104 VPRINTF(stderr,
"24 bit color image, no colormap.\n");
110 VPRINTF(stderr,
"24 bit color image with color map of length %d\n" ,
maplen);
114 VPRINTF(stderr,
"Grayscale image.\n");
118 "ncolors = %d, ncmap = %d, I don't know how to handle this!\n",
124 VPRINTF(stderr,
"No alpha channel.\n");
128 VPRINTF(stderr,
"Alpha channel exists!\n");
131 fprintf(stderr,
"alpha = %d, I don't know how to handle this!\n",
137 VPRINTF(stderr,
"Use all pixels, ignore background color.");
141 "Use only non-background pixels, ignore background color.");
145 "Use only non-background pixels, clear to background color (default).");
148 VPRINTF(stderr,
"Unknown background flag!\n");
154 VPRINTF(stderr,
" (%d %d %d)\n",
160 VPRINTF(stderr,
" (%d %d %d)\n",
174 void write_rlb_header(minx, maxx, miny, maxy, frame_number)
175 int minx, maxx, miny, maxy, frame_number;
204 strcpy(
rlb_head.desc,
"A Wavefront file converted from an rle file.");
208 second = time((
long *)NULL);
209 d_str = ctime(&second);
241 int encode(c_in, c_out, width)
251 if ((width > 1) && (c_in[0] == c_in[1])) {
255 for (ct = 2; ct < width; ct++) {
256 if (c_in[ct] != c_in[ct-1])
278 for (ct = 1; ct < width; ct++) {
279 if ((width - ct > 1) && (c_in[ct] == c_in[ct+1]))
292 for (; ct-- > 0; len++, width--)
301 void write_rlb_data()
304 U_CHAR *red, *green, *blue, *matte;
316 if (!(offset = (
int *)malloc(
sizeof(
int) * height))) {
317 fprintf(stderr,
"Offset malloc failed!\n");
320 offptr = ftell(
fpout);
321 if (fwrite(offset,
sizeof(
int), height,
fpout) != height) {
322 fprintf(stderr,
"Offset table write failed!\n");
325 if (!(buf = (
U_CHAR *)malloc(
sizeof(
U_CHAR) * width * 2))) {
326 fprintf(stderr,
"Buf malloc failed!\n");
329 if (!(red = (
U_CHAR *)malloc(
sizeof(
U_CHAR) * width * 4))) {
330 fprintf(stderr,
"Red scanline malloc failed!\n");
334 blue = &green[width];
335 matte = &blue[width];
340 fprintf(stderr,
"rle row alloc failed!\n");
343 for (scan = 0; scan < height; scan++) {
350 for (x = 0; x < width; x++)
351 matte[x] = (red[x] || green[x] || blue ? 255 : 0);
355 matte = scanline[-1];
356 for (x = 0; x < width; x++) {
357 red[x] =
colormap[scanline[0][x]]>>8;
358 green[x] =
colormap[scanline[1][x]+256]>>8;
359 blue[x] =
colormap[scanline[2][x]+512]>>8;
363 for (x = 0; x < width; x++) {
364 if (
colormap[scanline[0][x]]>>8 != scanline[0][x] ||
365 colormap[scanline[1][x]+256]>>8 != scanline[1][x] ||
366 colormap[scanline[2][x]+512]>>8 != scanline[2][x])
367 fprintf(stderr,
"A truecolor image with colormap whose resulting values don't match!\n");
368 red[x] =
colormap[scanline[0][x]]>>8;
369 green[x] =
colormap[scanline[1][x]+256]>>8;
370 blue[x] =
colormap[scanline[2][x]+512]>>8;
371 matte[x] = (red[x] || green[x] || blue ? 255 : 0);
376 matte = scanline[-1];
385 for (x = 0; x < width; x++)
386 matte[x] = (red[x] || green[x] || blue ? 255 : 0);
390 for (x = 0; x < width; x++) {
391 red[x] =
colormap[scanline[0][x]]>>8;
392 green[x] =
colormap[scanline[0][x]+256]>>8;
393 blue[x] =
colormap[scanline[0][x]+512]>>8;
394 matte[x] = (red[x] || green[x] || blue ? 255 : 0);
403 offset[scan] = ftell(
fpout);
407 len = encode(red, buf, width);
408 fwrite(&len,
sizeof(
short), 1,
fpout);
413 len = encode(green, buf, width);
414 fwrite(&len,
sizeof(
short), 1,
fpout);
419 len = encode(blue, buf, width);
420 fwrite(&len,
sizeof(
short), 1,
fpout);
425 len = encode(matte, buf, width);
426 fwrite(&len,
sizeof(
short), 1,
fpout);
432 fseek(
fpout, offptr, 0);
433 fwrite(offset,
sizeof(
int), height,
fpout);
449 char *lperiodP, *fname = NULL;
450 int minx, maxx, miny, maxy, frame_number = 1;
455 "% v%- h%- infile%s",
466 lperiodP = strrchr(
rlaname,
'.');
468 strcpy(lperiodP,
".rla");
472 fprintf(stderr,
"Cannot open %s for writing.\n",
rlaname);
481 read_rle_header(&minx, &maxx, &miny, &maxy);
487 write_rlb_header(minx, maxx, miny, maxy, frame_number);
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
gpr_ $bmf_group_header_array_t header
char * cmd_name(char **argv)
void main(int argc, char **argv)
int rle_get_setup(rle_hdr *the_hdr)
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
int rle_getrow(rle_hdr *the_hdr, scanline)
int scanargs(int argc, char **argv, const char *format,...)