33 static char rcs_ident[] =
"$Id: rle_getrow.c,v 3.0.1.5 1992/03/04 19:33:08 spencer Exp spencer $";
41 #define VAXSHORT( var, fp )
42 { var = fgetc(fp)&0xFF
; var |= (fgetc(fp)) << 8
; }
46 #define OPCODE(inst) (inst[0
] & ~LONG)
47 #define LONGP(inst) (inst[0
] & LONG)
48 #define DATUM(inst) (inst[1
] & 0xff
)
111 "background color" );
112 fread( (
char *)bg_color, 1, 1 + (setup
.h_ncolors / 2) * 2, infile );
119 (
void)getc( infile );
146 register int maplen =
149 register char *maptemp;
152 (
unsigned)(
sizeof(
rle_map) * maplen) );
153 maptemp = (
char *)malloc( 2 * maplen );
154 if ( the_hdr
->cmap == NULL || maptemp == NULL )
157 "%s: Malloc failed for color map of size %d*%d in rle_get_setup, reading %s\n",
163 fread( maptemp, 2, maplen, infile );
164 for ( i = 0; i < maplen; i++ )
172 short comlen, evenlen;
176 evenlen = (comlen + 1) & ~1;
179 comment_buf = (
char *)malloc( (
unsigned) evenlen );
181 if ( comment_buf == NULL )
184 "%s: Malloc failed for comment buffer of size %d in rle_get_setup, reading %s\n",
188 fread( comment_buf, 1, evenlen, infile );
190 for ( i = 0, cp = comment_buf; cp < comment_buf + comlen; cp++ )
196 (
CONST_DECL char **)malloc( (
unsigned)(i *
sizeof(
char *)) );
200 "%s: Malloc failed for %d comment pointers in rle_get_setup, reading %s\n",
206 for ( i = 1, cp = comment_buf + 1;
207 cp < comment_buf + comlen;
209 if ( *(cp - 1) == 0 )
220 the_hdr->priv.get.scan_y = the_hdr
->ymin;
221 the_hdr->priv.get.vert_skip = 0;
222 the_hdr->priv.get.is_eof = 0;
223 the_hdr->priv.get.is_seek = ftell( infile ) > 0;
226 if ( !feof( infile ) )
230 the_hdr->priv.get.is_eof = 1;
301 setlinebuf( stderr );
340 int scan_x = the_hdr
->xmin,
344 short word, long_data;
351 bzero( (
char *)scanline[-1] + the_hdr
->xmin,
353 for ( nc = 0; nc < the_hdr
->ncolors; nc++ )
354 if (
RLE_BIT( *the_hdr, nc ) ) {
357 bzero( (
char *)scanline[nc] + the_hdr
->xmin,
367 if ( the_hdr->priv.get.vert_skip > 0 )
369 the_hdr->priv.get.vert_skip--;
370 the_hdr->priv.get.scan_y++;
371 if ( the_hdr->priv.get.vert_skip > 0 ) {
372 if ( the_hdr->priv.get.scan_y >= the_hdr
->ymax )
374 int y = the_hdr->priv.get.scan_y;
380 return the_hdr->priv.get.scan_y;
385 if ( the_hdr->priv.get.is_eof )
386 return ++the_hdr->priv.get.scan_y;
391 if (
RLE_BIT( *the_hdr, channel ) )
392 scanc = scanline[channel] + scan_x;
397 inst[0] = getc( infile );
398 inst[1] = getc( infile );
401 the_hdr->priv.get.is_eof = 1;
410 VAXSHORT( the_hdr->priv.get.vert_skip, infile );
413 the_hdr->priv.get.vert_skip =
DATUM(inst);
415 fprintf(stderr,
"Skip %d Lines (to %d)\n",
416 the_hdr->priv.get.vert_skip,
417 the_hdr->priv.get.scan_y +
418 the_hdr->priv.get.vert_skip );
423 channel =
DATUM(inst);
424 if ( channel == 255 )
427 if (
RLE_BIT( *the_hdr, channel ) )
428 scanc = scanline[channel]+scan_x;
430 fprintf( stderr,
"Set color to %d (reset x to %d)\n",
441 fprintf( stderr,
"Skip %d pixels (to %d)\n",
446 scan_x +=
DATUM(inst);
447 scanc +=
DATUM(inst);
449 fprintf( stderr,
"Skip %d pixels (to %d)\n",
450 DATUM(inst), scan_x );
463 if (
RLE_BIT( *the_hdr, channel ) )
464 fprintf( stderr,
"Pixel data %d (to %d):", nc, scan_x+nc );
466 fprintf( stderr,
"Pixel data %d (to %d)\n", nc, scan_x+nc);
468 if (
RLE_BIT( *the_hdr, channel ) )
471 if ( scan_x + nc > max_x )
473 ns = scan_x + nc - max_x - 1;
478 fread( (
char *)scanc, 1, nc, infile );
480 (
void)getc( infile );
482 (
void)getc( infile );
485 if ( the_hdr->priv.get.is_seek )
486 fseek( infile, ((nc + 1) / 2) * 2, 1 );
490 for ( ii = ((nc + 1) / 2) * 2; ii > 0; ii-- )
491 (
void) getc( infile );
499 for ( ; nc > 0; nc-- )
500 fprintf( stderr,
"%02x", *cp++ );
501 putc(
'\n', stderr );
517 fprintf( stderr,
"Run length %d (to %d), data %02x\n",
519 if (
RLE_BIT( *the_hdr, channel ) )
521 if ( scan_x > max_x )
523 ns = scan_x - max_x - 1;
534 for ( nc--; nc >= 0; nc--, scanc++ )
540 the_hdr->priv.get.is_eof = 1;
542 fprintf( stderr,
"End of Image\n" );
547 "%s: rle_getrow: Unrecognized opcode: %d, reading %s\n",
556 if ( the_hdr->priv.get.scan_y >= the_hdr
->ymax )
558 int y = the_hdr->priv.get.scan_y;
564 return the_hdr->priv.get.scan_y;
575 asm(
" movc5 $0,*4(ap),12(ap),8(ap),*4(ap)");
#define RLE_SET_BIT(glob, bit)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
void rle_debug(int on_off)
int rle_get_setup(rle_hdr *the_hdr)
int vax_gshort(char *msgp)
int rle_getrow(rle_hdr *the_hdr, scanline)
int rle_get_error(int code, const char *pgmname, const char *fname)
static void bfill(char *s, int n, int c)
unsigned int rle_getskip(rle_hdr *the_hdr)
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
#define VAXSHORT(var, fp)
void rle_hdr_clear(rle_hdr *the_hdr)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
#define RLE_CHECK_ALLOC(pgm, ptr, name)
#define RLE_BIT(glob, bit)