diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2022-03-06 21:46:13 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2022-03-06 21:46:13 +0000 |
commit | 7ce03ea0b7d6bdf3d06cb0c7d16ad16f46f29405 (patch) | |
tree | 338d68cd430e37880e385f3f9fb2f4b9359a8756 /urt | |
parent | c49e2bfb92ebe11c4b04342dc0aa81898b53e8fc (diff) | |
download | netpbm-mirror-7ce03ea0b7d6bdf3d06cb0c7d16ad16f46f29405.tar.gz netpbm-mirror-7ce03ea0b7d6bdf3d06cb0c7d16ad16f46f29405.tar.xz netpbm-mirror-7ce03ea0b7d6bdf3d06cb0c7d16ad16f46f29405.zip |
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4294 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'urt')
-rw-r--r-- | urt/Makefile | 6 | ||||
-rw-r--r-- | urt/README | 5 | ||||
-rw-r--r-- | urt/Runput.c | 300 | ||||
-rw-r--r-- | urt/Runput.h | 2 | ||||
-rw-r--r-- | urt/cmd_name.c | 30 | ||||
-rw-r--r-- | urt/rle.h | 147 | ||||
-rw-r--r-- | urt/rle_addhist.c | 20 | ||||
-rw-r--r-- | urt/rle_code.h | 57 | ||||
-rw-r--r-- | urt/rle_config.h | 10 | ||||
-rw-r--r-- | urt/rle_getcom.c | 44 | ||||
-rw-r--r-- | urt/rle_getrow.c | 89 | ||||
-rw-r--r-- | urt/rle_getskip.c | 198 | ||||
-rw-r--r-- | urt/rle_global.c | 78 | ||||
-rw-r--r-- | urt/rle_hdr.c | 2 | ||||
-rw-r--r-- | urt/rle_open_f.c | 28 | ||||
-rw-r--r-- | urt/rle_put.h | 64 | ||||
-rw-r--r-- | urt/rle_putcom.c | 57 | ||||
-rw-r--r-- | urt/rle_putrow.c | 753 | ||||
-rw-r--r-- | urt/rle_row_alc.c | 100 | ||||
-rw-r--r-- | urt/vaxshort.c | 32 |
20 files changed, 830 insertions, 1192 deletions
diff --git a/urt/Makefile b/urt/Makefile index 0aef5290..8c85dab4 100644 --- a/urt/Makefile +++ b/urt/Makefile @@ -10,10 +10,10 @@ default: all include $(BUILDDIR)/config.mk LIBOBJECTS = Runput.o cmd_name.o \ - rle_addhist.o rle_error.o rle_getcom.o rle_getrow.o rle_getskip.o \ + rle_addhist.o rle_getcom.o rle_getrow.o rle_getskip.o \ rle_global.o rle_hdr.o rle_open_f.o rle_putcom.o rle_putrow.o \ - rle_row_alc.o \ - scanargs.o vaxshort.o + rle_row_alc.o \ + vaxshort.o MERGE_OBJECTS = diff --git a/urt/README b/urt/README index dc68889d..2cfbb3e2 100644 --- a/urt/README +++ b/urt/README @@ -18,3 +18,8 @@ in its initializer in the original. But GNU C Library Version 2 defines stdout as a variable, so that wouldn't compile. So I changed it to NULL and added a line to rle_hdr_init to set that field to 'stdout' dynamically. 2000.06.02 BJH. + +--- + +Cleanup by Akira F Urushibata 2022.03.06 +Unused functions removed. \ No newline at end of file diff --git a/urt/Runput.c b/urt/Runput.c index 3bc562ac..1a7f2f7b 100644 --- a/urt/Runput.c +++ b/urt/Runput.c @@ -1,14 +1,14 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the @@ -18,146 +18,146 @@ * Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire * to have all "void" functions so declared. */ -/* +/* * Runput.c - General purpose Run Length Encoding. - * - * Author: Spencer W. Thomas - * Computer Science Dept. - * University of Utah - * Date: Mon Aug 9 1982 + * + * Author: Spencer W. Thomas + * Computer Science Dept. + * University of Utah + * Date: Mon Aug 9 1982 * Copyright (c) 1982,1986 Spencer W. Thomas - * + * * $Id: Runput.c,v 3.0.1.1 1992/01/28 18:17:40 spencer Exp $ - * - * Modified by: Todd W. Fuqua - * Date: Jul 22 1984 + * + * Modified by: Todd W. Fuqua + * Date: Jul 22 1984 * convert to new RLE format to make room for larger frame buffers */ /* THIS IS WAY OUT OF DATE. See rle.5. * The output file format is: - * - * Word 0: A "magic" number. The top byte of the word contains - * the letter 'R' or the letter 'W'. 'W' indicates that - * only black and white information was saved. The bottom - * byte is one of the following: - * ' ': Means a straight "box" save, -S flag was given. - * 'B': Image saved with background color, clear screen to - * background before restoring image. - * 'O': Image saved in overlay mode. - * - * Words 1-6: The structure - * { short xpos, Lower left corner + * + * Word 0: A "magic" number. The top byte of the word contains + * the letter 'R' or the letter 'W'. 'W' indicates that + * only black and white information was saved. The bottom + * byte is one of the following: + * ' ': Means a straight "box" save, -S flag was given. + * 'B': Image saved with background color, clear screen to + * background before restoring image. + * 'O': Image saved in overlay mode. + * + * Words 1-6: The structure + * { short xpos, Lower left corner * ypos, - * xsize, Size of saved box + * xsize, Size of saved box * ysize; - * char rgb[3]; Background color - * char map; flag for map presence + * char rgb[3]; Background color + * char map; flag for map presence * } - * - * If the map flag is non-zero, then the color map will follow as + * + * If the map flag is non-zero, then the color map will follow as * 3*256 16 bit words, first the red map, then the green map, and * finally the blue map. - * + * * Following the setup information is the Run Length Encoded image. * Each instruction consists of a 4-bit opcode, a 12-bit datum and * possibly one or more following words (all words are 16 bits). The * instruction opcodes are: - * + * * SkipLines (1): The bottom 10 bits are an unsigned number to be added to - * current Y position. - * + * current Y position. + * * SetColor (2): The datum indicates which color is to be loaded with - * the data described by the following ByteData and - * RunData instructions. 0->red, 1->green, 2->blue. The - * operation also resets the X position to the initial - * X (i.e. a carriage return operation is performed). - * + * the data described by the following ByteData and + * RunData instructions. 0->red, 1->green, 2->blue. The + * operation also resets the X position to the initial + * X (i.e. a carriage return operation is performed). + * * SkipPixels (3): The bottom 10 bits are an unsigned number to be - * added to the current X position. - * + * added to the current X position. + * * ByteData (5): The datum is one less than the number of bytes of - * color data following. If the number of bytes is - * odd, a filler byte will be appended to the end of - * the byte string to make an integral number of 16-bit - * words. The bytes are in PDP-11 order. The X - * position is incremented to follow the last byte of - * data. - * - * RunData (6): The datum is one less than the run length. The - * following word contains (in its lower 8 bits) the - * color of the run. The X position is incremented to - * follow the last byte in the run. + * color data following. If the number of bytes is + * odd, a filler byte will be appended to the end of + * the byte string to make an integral number of 16-bit + * words. The bytes are in PDP-11 order. The X + * position is incremented to follow the last byte of + * data. + * + * RunData (6): The datum is one less than the run length. The + * following word contains (in its lower 8 bits) the + * color of the run. The X position is incremented to + * follow the last byte in the run. */ #include <string.h> -#include <stdio.h> +#include <stdio.h> -#include "rle_put.h" -#include "rle.h" -#include "rle_code.h" +#include "rle_put.h" +#include "rle.h" +#include "rle_code.h" #include "vaxshort.h" #include "Runput.h" -#define UPPER 255 /* anything bigger ain't a byte */ +#define UPPER 255 /* anything bigger ain't a byte */ /* * Macros to make writing instructions with correct byte order easier. */ /* Write a two-byte value in little_endian order. */ -#define put16(a) (putc((a)&0xff,rle_fd),putc((char)(((a)>>8)&0xff),rle_fd)) +#define put16(a) (putc((a)&0xff,rle_fd),putc((char)(((a)>>8)&0xff),rle_fd)) /* short instructions */ -#define mk_short_1(oper,a1) /* one argument short */ \ +#define mk_short_1(oper,a1) /* one argument short */ \ putc(oper,rle_fd), putc((char)a1,rle_fd) -#define mk_short_2(oper,a1,a2) /* two argument short */ \ +#define mk_short_2(oper,a1,a2) /* two argument short */ \ putc(oper,rle_fd), putc((char)a1,rle_fd), put16(a2) /* long instructions */ -#define mk_long_1(oper,a1) /* one argument long */ \ +#define mk_long_1(oper,a1) /* one argument long */ \ putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), put16(a1) -#define mk_long_2(oper,a1,a2) /* two argument long */ \ +#define mk_long_2(oper,a1,a2) /* two argument long */ \ putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), \ put16(a1), put16(a2) /* choose between long and short format instructions */ /* NOTE: these macros can only be used where a STATEMENT is legal */ -#define mk_inst_1(oper,a1) /* one argument inst */ \ +#define mk_inst_1(oper,a1) /* one argument inst */ \ if (a1>UPPER) (mk_long_1(oper,a1)); else (mk_short_1(oper,a1)) -#define mk_inst_2(oper,a1,a2) /* two argument inst */ \ +#define mk_inst_2(oper,a1,a2) /* two argument inst */ \ if (a1>UPPER) (mk_long_2(oper,a1,a2)); else (mk_short_2(oper,a1,a2)) -/* +/* * Opcode definitions */ -#define RSkipLines(n) mk_inst_1(RSkipLinesOp,(n)) +#define RSkipLines(n) mk_inst_1(RSkipLinesOp,(n)) -#define RSetColor(c) mk_short_1(RSetColorOp,(c)) - /* has side effect of performing */ - /* "carriage return" action */ +#define RSetColor(c) mk_short_1(RSetColorOp,(c)) + /* has side effect of performing */ + /* "carriage return" action */ -#define RSkipPixels(n) mk_inst_1(RSkipPixelsOp,(n)) +#define RSkipPixels(n) mk_inst_1(RSkipPixelsOp,(n)) -#define RNewLine RSkipLines(1) +#define RNewLine RSkipLines(1) -#define RByteData(n) mk_inst_1(RByteDataOp,n) - /* followed by ((n+1)/2)*2 bytes */ - /* of data. If n is odd, last */ - /* byte will be ignored */ - /* "cursor" is left at pixel */ - /* following last pixel written */ +#define RByteData(n) mk_inst_1(RByteDataOp,n) + /* followed by ((n+1)/2)*2 bytes */ + /* of data. If n is odd, last */ + /* byte will be ignored */ + /* "cursor" is left at pixel */ + /* following last pixel written */ -#define RRunData(n,c) mk_inst_2(RRunDataOp,(n),(c)) - /* next word contains color data */ - /* "cursor" is left at pixel after */ - /* end of run */ +#define RRunData(n,c) mk_inst_2(RRunDataOp,(n),(c)) + /* next word contains color data */ + /* "cursor" is left at pixel after */ + /* end of run */ -#define REOF mk_inst_1(REOFOp,0) - /* Really opcode only */ +#define REOF mk_inst_1(REOFOp,0) + /* Really opcode only */ /***************************************************************** * TAG( RunSetup ) @@ -167,33 +167,33 @@ void RunSetup(rle_hdr * the_hdr) { struct XtndRsetup setup; - register FILE * rle_fd = the_hdr->rle_file; + FILE * rle_fd = the_hdr->rle_file; put16( RLE_MAGIC ); if ( the_hdr->background == 2 ) - setup.h_flags = H_CLEARFIRST; + setup.h_flags = H_CLEARFIRST; else if ( the_hdr->background == 0 ) - setup.h_flags = H_NO_BACKGROUND; + setup.h_flags = H_NO_BACKGROUND; else - setup.h_flags = 0; + setup.h_flags = 0; if ( the_hdr->alpha ) - setup.h_flags |= H_ALPHA; + setup.h_flags |= H_ALPHA; if ( the_hdr->comments != NULL && *the_hdr->comments != NULL ) - setup.h_flags |= H_COMMENT; + setup.h_flags |= H_COMMENT; setup.h_ncolors = the_hdr->ncolors; - setup.h_pixelbits = 8; /* Grinnell dependent */ + setup.h_pixelbits = 8; /* Grinnell dependent */ if ( the_hdr->ncmap > 0 && the_hdr->cmap == NULL ) { - fprintf( stderr, + fprintf( stderr, "%s: Color map of size %d*%d specified, but not supplied, writing %s\n", - the_hdr->cmd, the_hdr->ncmap, (1 << the_hdr->cmaplen), - the_hdr->file_name ); - the_hdr->ncmap = 0; + the_hdr->cmd, the_hdr->ncmap, (1 << the_hdr->cmaplen), + the_hdr->file_name ); + the_hdr->ncmap = 0; } - setup.h_cmaplen = the_hdr->cmaplen; /* log2 of color map size */ - setup.h_ncmap = the_hdr->ncmap; /* no of color channels */ + setup.h_cmaplen = the_hdr->cmaplen; /* log2 of color map size */ + setup.h_ncmap = the_hdr->ncmap; /* no of color channels */ vax_pshort(setup.hc_xpos,the_hdr->xmin); vax_pshort(setup.hc_ypos,the_hdr->ymin); vax_pshort(setup.hc_xlen,the_hdr->xmax - the_hdr->xmin + 1); @@ -201,61 +201,61 @@ RunSetup(rle_hdr * the_hdr) fwrite((char *)&setup, SETUPSIZE, 1, rle_fd); if ( the_hdr->background != 0 ) { - register int i; - register rle_pixel *background = - (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); - register int *bg_color; - /* - * If even number of bg color bytes, put out one more to get to - * 16 bit boundary. - */ - bg_color = the_hdr->bg_color; - for ( i = 0; i < the_hdr->ncolors; i++ ) - background[i] = *bg_color++; - /* Extra byte, if written, should be 0. */ - background[i] = 0; - fwrite((char *)background, (the_hdr->ncolors / 2) * 2 + 1, 1, rle_fd); - free( background ); + int i; + rle_pixel *background = + (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); + int *bg_color; + /* + * If even number of bg color bytes, put out one more to get to + * 16 bit boundary. + */ + bg_color = the_hdr->bg_color; + for ( i = 0; i < the_hdr->ncolors; i++ ) + background[i] = *bg_color++; + /* Extra byte, if written, should be 0. */ + background[i] = 0; + fwrite((char *)background, (the_hdr->ncolors / 2) * 2 + 1, 1, rle_fd); + free( background ); } else - putc( '\0', rle_fd ); + putc( '\0', rle_fd ); if (the_hdr->ncmap > 0) { - /* Big-endian machines are harder */ - register int i, nmap = (1 << the_hdr->cmaplen) * - the_hdr->ncmap; - register char *h_cmap = (char *)malloc( nmap * 2 ); - if ( h_cmap == NULL ) - { - fprintf( stderr, - "%s: Malloc failed for color map of size %d, writing %s\n", - the_hdr->cmd, nmap, the_hdr->file_name ); - exit( 1 ); - } - for ( i = 0; i < nmap; i++ ) - vax_pshort( &h_cmap[i*2], the_hdr->cmap[i] ); - - fwrite( h_cmap, nmap, 2, rle_fd ); - free( h_cmap ); + /* Big-endian machines are harder */ + int i, nmap = (1 << the_hdr->cmaplen) * + the_hdr->ncmap; + char *h_cmap = (char *)malloc( nmap * 2 ); + if ( h_cmap == NULL ) + { + fprintf( stderr, + "%s: Malloc failed for color map of size %d, writing %s\n", + the_hdr->cmd, nmap, the_hdr->file_name ); + exit( 1 ); + } + for ( i = 0; i < nmap; i++ ) + vax_pshort( &h_cmap[i*2], the_hdr->cmap[i] ); + + fwrite( h_cmap, nmap, 2, rle_fd ); + free( h_cmap ); } /* Now write out comments if given */ if ( setup.h_flags & H_COMMENT ) { - int comlen; - register CONST_DECL char ** com_p; + int comlen; + CONST_DECL char ** com_p; - /* Get the total length of comments */ - comlen = 0; - for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ ) - comlen += 1 + strlen( *com_p ); + /* Get the total length of comments */ + comlen = 0; + for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ ) + comlen += 1 + strlen( *com_p ); - put16( comlen ); - for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ ) - fwrite( *com_p, 1, strlen( *com_p ) + 1, rle_fd ); + put16( comlen ); + for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ ) + fwrite( *com_p, 1, strlen( *com_p ) + 1, rle_fd ); - if ( comlen & 1 ) /* if odd length, round up */ - putc( '\0', rle_fd ); + if ( comlen & 1 ) /* if odd length, round up */ + putc( '\0', rle_fd ); } } @@ -266,7 +266,7 @@ RunSetup(rle_hdr * the_hdr) void RunSkipBlankLines(int nblank, rle_hdr * the_hdr) { - register FILE * rle_fd = the_hdr->rle_file; + FILE * rle_fd = the_hdr->rle_file; RSkipLines(nblank); } @@ -278,7 +278,7 @@ RunSkipBlankLines(int nblank, rle_hdr * the_hdr) void RunSetColor(int c, rle_hdr * the_hdr) { - register FILE * rle_fd = the_hdr->rle_file; + FILE * rle_fd = the_hdr->rle_file; RSetColor(c); } @@ -291,10 +291,10 @@ RunSetColor(int c, rle_hdr * the_hdr) void RunSkipPixels(int nskip, int last, int wasrun, rle_hdr * the_hdr) { - register FILE * rle_fd = the_hdr->rle_file; + FILE * rle_fd = the_hdr->rle_file; if (! last && nskip > 0) { - RSkipPixels(nskip); + RSkipPixels(nskip); } } @@ -306,10 +306,10 @@ RunSkipPixels(int nskip, int last, int wasrun, rle_hdr * the_hdr) void RunNewScanLine(int flag, rle_hdr * the_hdr) { - register FILE * rle_fd = the_hdr->rle_file; + FILE * rle_fd = the_hdr->rle_file; if (flag) { - RNewLine; + RNewLine; } } @@ -320,14 +320,14 @@ RunNewScanLine(int flag, rle_hdr * the_hdr) void Runputdata(rle_pixel * buf, int n, rle_hdr * the_hdr) { - register FILE * rle_fd = the_hdr->rle_file; + FILE * rle_fd = the_hdr->rle_file; if (n == 0) - return; + return; RByteData(n-1); fwrite((char *)buf, n, 1, rle_fd); if ( n & 1 ) - putc( 0, rle_fd ); + putc( 0, rle_fd ); } /***************************************************************** @@ -339,7 +339,7 @@ Runputdata(rle_pixel * buf, int n, rle_hdr * the_hdr) void Runputrun(int color, int n, int last, rle_hdr * the_hdr) { - register FILE * rle_fd = the_hdr->rle_file; + FILE * rle_fd = the_hdr->rle_file; RRunData(n-1,color); } @@ -351,6 +351,6 @@ Runputrun(int color, int n, int last, rle_hdr * the_hdr) void RunputEof(rle_hdr * the_hdr) { - register FILE * rle_fd = the_hdr->rle_file; + FILE * rle_fd = the_hdr->rle_file; REOF; } diff --git a/urt/Runput.h b/urt/Runput.h index 776e3ec5..1d22a971 100644 --- a/urt/Runput.h +++ b/urt/Runput.h @@ -1,4 +1,4 @@ -void +void RunSetup(rle_hdr * the_hdr); void diff --git a/urt/cmd_name.c b/urt/cmd_name.c index 31fe5f42..4b3f169b 100644 --- a/urt/cmd_name.c +++ b/urt/cmd_name.c @@ -1,27 +1,27 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the * name of the person performing the modification, the date of modification, * and the reason for such modification. */ -/* +/* * cmd_name.c - Extract command name from argv[0]. - * - * Author: Spencer W. Thomas - * EECS Dept. - * University of Michigan - * Date: Wed Jun 27 1990 + * + * Author: Spencer W. Thomas + * EECS Dept. + * University of Michigan + * Date: Wed Jun 27 1990 * Copyright (c) 1990, University of Michigan */ @@ -35,23 +35,23 @@ char * cmd_name( argv ) char **argv; { - register char *cp, *a; + char *cp, *a; /* Be paranoid. */ if ( !argv || !(a = *argv) ) - return no_name; + return no_name; /* Find end of file name. */ for ( cp = a; *cp; cp++ ) - ; + ; /* Find last / or beginning of command name. */ for ( cp--; *cp != '/' && cp > a; cp-- ) - ; - + ; + /* If it's a /, skip it. */ if ( *cp == '/' ) - cp++; + cp++; return cp; } diff --git a/urt/rle.h b/urt/rle.h index 00717748..1e7ddd0c 100644 --- a/urt/rle.h +++ b/urt/rle.h @@ -50,19 +50,19 @@ typedef unsigned short rle_map; /* * Defines for traditional channel numbers. */ -#define RLE_RED 0 /* Red channel traditionally here. */ -#define RLE_GREEN 1 /* Green channel traditionally here. */ -#define RLE_BLUE 2 /* Blue channel traditionally here. */ -#define RLE_ALPHA -1 /* Alpha channel here. */ +#define RLE_RED 0 /* Red channel traditionally here. */ +#define RLE_GREEN 1 /* Green channel traditionally here. */ +#define RLE_BLUE 2 /* Blue channel traditionally here. */ +#define RLE_ALPHA -1 /* Alpha channel here. */ /* * Return values from rle_get_setup. */ -#define RLE_SUCCESS 0 -#define RLE_NOT_RLE -1 -#define RLE_NO_SPACE -2 -#define RLE_EMPTY -3 -#define RLE_EOF -4 +#define RLE_SUCCESS 0 +#define RLE_NOT_RLE -1 +#define RLE_NO_SPACE -2 +#define RLE_EMPTY -3 +#define RLE_EOF -4 /* * "Magic" value for is_init field. Pi * 2^29. @@ -103,7 +103,7 @@ typedef * bits[c/8] & (1 << (c%8)) */ #define RLE_SET_BIT(glob,bit) \ - ((glob).bits[((bit)&0xff)/8] |= (1<<((bit)&0x7))) + ((glob).bits[((bit)&0xff)/8] |= (1<<((bit)&0x7))) #define RLE_CLR_BIT(glob,bit) \ ((glob).bits[((bit)&0xff)/8] &= ~(1<<((bit)&0x7))) #define RLE_BIT(glob,bit) \ @@ -167,13 +167,6 @@ extern int rle_get_error( int code, /* From rle_getrow.c */ -/***************************************************************** - * TAG( rle_debug ) - * - * Turn RLE debugging on or off. - */ -extern void rle_debug( int on_off ); - int rle_get_setup(rle_hdr * const the_hdr); @@ -239,16 +232,6 @@ extern void rle_hdr_clear( rle_hdr *the_hdr ); /* From rle_putrow.c. */ -/***************************************************************** - * TAG( rgb_to_bw ) - * - * Converts RGB data to gray data via the NTSC Y transform. - */ -extern void rgb_to_bw( rle_pixel *red_row, - rle_pixel *green_row, - rle_pixel *blue_row, - rle_pixel *bw_row, - int rowlen ); /***************************************************************** * TAG( rle_puteof ) @@ -285,13 +268,6 @@ extern void rle_put_setup( rle_hdr * the_hdr ); */ extern void rle_skiprow( rle_hdr *the_hdr, int nrow ); -/* From rle_cp.c */ -/***************************************************************** - * TAG( rle_cp ) - * Copy image data from input to output with minimal interpretation. - */ -extern void rle_cp( rle_hdr *in_hdr, rle_hdr *out_hdr ); - /* From rle_row_alc.c. */ /***************************************************************** * TAG( rle_row_alloc ) @@ -308,14 +284,6 @@ extern int rle_row_alloc( rle_hdr * the_hdr, */ extern void rle_row_free( rle_hdr *the_hdr, rle_pixel **scanp ); -/* From buildmap.c. */ -/* - * buildmap - build a more usable colormap from data in the_hdr struct. - */ -extern rle_pixel **buildmap( rle_hdr *the_hdr, - int minmap, - double orig_gamma, - double new_gamma ); /* From rle_getcom.c. */ /***************************************************************** @@ -329,55 +297,11 @@ rle_getcom(const char * const name, /* From rle_putcom.c. */ -/* Delete a specific comment from the image comments. */ -const char * -rle_delcom(const char * const name, - rle_hdr * const the_hdr); - /* Put (or replace) a comment into the image comments. */ const char * rle_putcom(const char * const value, rle_hdr * const the_hdr); -/* From dither.c. */ -/***************************************************************** - * TAG( bwdithermap ) - * Create a color map for ordered dithering in grays. - */ -extern void bwdithermap( int levels, double gamma, int bwmap[], - int divN[256], int modN[256], int magic[16][16] ); -/***************************************************************** - * TAG( ditherbw ) - * Dither a gray-scale value. - */ -extern int ditherbw( int x, int y, int val, - int divN[256], int modN[256], int magic[16][16] ); -/***************************************************************** - * TAG( dithergb ) - * Dither a color value. - */ -extern int dithergb( int x, int y, int r, int g, int b, - int divN[256], int modN[256], int magic[16][16] ); -/***************************************************************** - * TAG( dithermap ) - * Create a color map for ordered dithering in color. - */ -extern void dithermap( int levels, double gamma, int rgbmap[][3], - int divN[256], int modN[256], int magic[16][16] ); -/***************************************************************** - * TAG( make_square ) - * Make a 16x16 magic square for ordered dithering. - */ -extern void make_square( double N, int divN[256], int modN[256], - int magic[16][16] ); - -/* From float_to_exp.c. */ -/***************************************************************** - * TAG( float_to_exp ) - * Convert a list of floating point numbers to "exp" format. - */ -extern void float_to_exp( int count, float * floats, rle_pixel * pixels ); - /* From rle_open_f.c. */ /***************************************************************** * TAG( rle_open_f ) @@ -398,24 +322,6 @@ rle_open_f_noexit(const char * const prog_name, const char * const file_name, const char * const mode); -/***************************************************************** - * TAG( rle_close_f ) - * - * Close a file opened by rle_open_f. If the file is stdin or stdout, - * it will not be closed. - */ -extern void -rle_close_f( FILE *fd ); - -/* From colorquant.c. */ -/***************************************************************** - * TAG( colorquant ) - * Compute a colormap for quantizing an image to a limited set of colors. - */ -extern int colorquant( rle_pixel *red, rle_pixel *green, rle_pixel *blue, - unsigned long pixels, rle_pixel *colormap[3], - int colors, int bits, - rle_pixel *rgbmap, int fast, int otherimages ); /* From rle_addhist.c. */ @@ -432,38 +338,5 @@ rle_addhist(char * argv[], */ extern char *cmd_name( char **argv ); -/* From scanargs.c. */ -/***************************************************************** - * TAG( scanargs ) - * Scan command argument list and parse arguments. - */ -extern int scanargs( int argc, - char **argv, - const char *format, - ... ); - -/* From hilbert.c */ -/***************************************************************** - * TAG( hilbert_i2c ) - * Convert an index into a Hilbert curve to a set of coordinates. - */ -extern void hilbert_c2i( int n, int m, int a[], long int *r ); - -/***************************************************************** - * TAG( hilbert_c2i ) - * Convert coordinates of a point on a Hilbert curve to its index. - */ -extern void hilbert_i2c( int n, int m, long int r, int a[] ); - -/* From inv_cmap.c */ -/***************************************************************** - * TAG( inv_cmap ) - * Compute an inverse colormap efficiently. - */ -extern void inv_cmap( int colors, - unsigned char *colormap[3], - int bits, - unsigned long *dist_buf, - unsigned char *rgbmap ); #endif /* RLE_H */ diff --git a/urt/rle_addhist.c b/urt/rle_addhist.c index b1651754..45c3dbfd 100644 --- a/urt/rle_addhist.c +++ b/urt/rle_addhist.c @@ -1,25 +1,25 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the * name of the person performing the modification, the date of modification, * and the reason for such modification. */ -/* +/* * rle_addhist.c - Add to the HISTORY comment in header - * + * * Author: Andrew Marriott. - * School of Computer Science + * School of Computer Science * Curtin University of Technology * Date: Mon Sept 10 1988 * Copyright (c) 1988, Curtin University of Technology @@ -35,7 +35,7 @@ /***************************************************************** * TAG( rle_addhist ) - * + * * Put a history comment into the header struct. * Inputs: * argv: Command line history to add to comments. @@ -68,7 +68,7 @@ rle_addhist(char * argv[], if (getenv("NO_ADD_RLE_HISTORY")) return; - + length = 0; for (i = 0; argv[i]; ++i) length += strlen(argv[i]) +1; /* length of each arg plus space. */ @@ -83,7 +83,7 @@ rle_addhist(char * argv[], old = rle_getcom(histoire, in_hdr); /* get old comment. */ else old = NULL; - + if (old && *old) length += strlen(old); /* add length if there. */ @@ -104,6 +104,6 @@ rle_addhist(char * argv[], strcat(newc,"on "); strcat(newc,timedate); /* \n supplied by time. */ strcat(newc,padding); /* to line up multiple histories.*/ - + rle_putcom(newc, out_hdr); } diff --git a/urt/rle_code.h b/urt/rle_code.h index 955e7d42..493cdc02 100644 --- a/urt/rle_code.h +++ b/urt/rle_code.h @@ -1,50 +1,50 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the * name of the person performing the modification, the date of modification, * and the reason for such modification. */ -/* +/* * rle_code.h - Definitions for Run Length Encoding. - * - * Author: Spencer W. Thomas - * Computer Science Dept. - * University of Utah - * Date: Mon Aug 9 1982 + * + * Author: Spencer W. Thomas + * Computer Science Dept. + * University of Utah + * Date: Mon Aug 9 1982 * Copyright (c) 1982 Spencer W. Thomas - * + * * $Header: /usr/users/spencer/src/urt/include/RCS/rle_code.h,v 3.0 90/08/03 15:19:48 spencer Exp $ */ #ifndef RLE_MAGIC -/* +/* * Opcode definitions */ #define LONG 0x40 -#define RSkipLinesOp 1 -#define RSetColorOp 2 -#define RSkipPixelsOp 3 -#define RByteDataOp 5 -#define RRunDataOp 6 -#define REOFOp 7 +#define RSkipLinesOp 1 +#define RSetColorOp 2 +#define RSkipPixelsOp 3 +#define RByteDataOp 5 +#define RRunDataOp 6 +#define REOFOp 7 -#define H_CLEARFIRST 0x1 /* clear framebuffer flag */ -#define H_NO_BACKGROUND 0x2 /* if set, no bg color supplied */ -#define H_ALPHA 0x4 /* if set, alpha channel (-1) present */ -#define H_COMMENT 0x8 /* if set, comments present */ +#define H_CLEARFIRST 0x1 /* clear framebuffer flag */ +#define H_NO_BACKGROUND 0x2 /* if set, no bg color supplied */ +#define H_ALPHA 0x4 /* if set, alpha channel (-1) present */ +#define H_COMMENT 0x8 /* if set, comments present */ struct XtndRsetup { @@ -54,17 +54,16 @@ struct XtndRsetup hc_ylen[2]; char h_flags, h_ncolors, - h_pixelbits, - h_ncmap, - h_cmaplen; + h_pixelbits, + h_ncmap, + h_cmaplen; }; -#define SETUPSIZE ((4*2)+5) +#define SETUPSIZE ((4*2)+5) /* "Old" RLE format magic numbers */ -#define RMAGIC ('R' << 8) /* top half of magic number */ -#define WMAGIC ('W' << 8) /* black&white rle image */ +#define RMAGIC ('R' << 8) /* top half of magic number */ +#define WMAGIC ('W' << 8) /* black&white rle image */ -#define RLE_MAGIC ((short)0xcc52) /* RLE file magic number */ +#define RLE_MAGIC ((short)0xcc52) /* RLE file magic number */ #endif /* RLE_MAGIC */ - diff --git a/urt/rle_config.h b/urt/rle_config.h index 57126a18..5923c00d 100644 --- a/urt/rle_config.h +++ b/urt/rle_config.h @@ -49,7 +49,7 @@ /* Typedef for void * so we can use it consistently. */ #ifdef VOID_STAR -typedef void *void_star; +typedef void *void_star; #else typedef char *void_star; #endif @@ -59,7 +59,7 @@ typedef char *void_star; * before including this file. */ #ifndef NO_DECLARE_MALLOC -# include <sys/types.h> /* For size_t. */ +# include <sys/types.h> /* For size_t. */ extern void_star malloc( size_t ); extern void_star calloc( size_t, size_t ); extern void_star realloc( void_star, size_t ); @@ -75,12 +75,12 @@ extern char *getenv( CONST_DECL char *name ); * TAG( bstring bzero ) * 'Byte string' functions. */ -# define bzero( _str, _n ) memset( _str, '\0', _n ) -# define bcopy( _from, _to, _count ) memcpy( _to, _from, _count ) +# define bzero( _str, _n ) memset( _str, '\0', _n ) +# define bcopy( _from, _to, _count ) memcpy( _to, _from, _count ) #endif #ifdef NEED_SETLINEBUF -# define setlinebuf( _s ) setvbuf( (_s), NULL, _IOLBF, 0 ) +# define setlinebuf( _s ) setvbuf( (_s), NULL, _IOLBF, 0 ) #endif #endif diff --git a/urt/rle_getcom.c b/urt/rle_getcom.c index 4226eaaf..a0a1e5ae 100644 --- a/urt/rle_getcom.c +++ b/urt/rle_getcom.c @@ -1,27 +1,27 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the * name of the person performing the modification, the date of modification, * and the reason for such modification. */ -/* +/* * rle_getcom.c - Get specific comments from the_hdr structure. - * - * Author: Spencer W. Thomas - * Computer Science Dept. - * University of Utah - * Date: Sun Jan 25 1987 + * + * Author: Spencer W. Thomas + * Computer Science Dept. + * University of Utah + * Date: Sun Jan 25 1987 * Copyright (c) 1987, University of Utah */ @@ -31,21 +31,21 @@ /***************************************************************** * TAG( match ) - * + * * Match a name against a test string for "name=value" or "name". * If it matches name=value, return pointer to value part, if just * name, return pointer to NUL at end of string. If no match, return NULL. * * Inputs: - * n: Name to match. May also be "name=value" to make it easier - * to replace comments. - * v: Test string. + * n: Name to match. May also be "name=value" to make it easier + * to replace comments. + * v: Test string. * Outputs: - * Returns pointer as above. + * Returns pointer as above. * Assumptions: - * [None] + * [None] * Algorithm: - * [None] + * [None] */ static const char * match(const char * const nArg, @@ -69,17 +69,17 @@ match(const char * const nArg, /***************************************************************** * TAG( rle_getcom ) - * + * * Return a pointer to the value part of a name=value pair in the comments. * Inputs: - * name: Name part of the comment to search for. - * the_hdr: rle_dflt_hdr structure. + * name: Name part of the comment to search for. + * the_hdr: rle_dflt_hdr structure. * Outputs: - * Returns pointer to value part of comment or NULL if no match. + * Returns pointer to value part of comment or NULL if no match. * Assumptions: - * [None] + * [None] * Algorithm: - * [None] + * [None] */ const char * rle_getcom(const char * const name, diff --git a/urt/rle_getrow.c b/urt/rle_getrow.c index ae220f5b..a24870ac 100644 --- a/urt/rle_getrow.c +++ b/urt/rle_getrow.c @@ -1,14 +1,14 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the @@ -18,15 +18,15 @@ * Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire * to have all "void" functions so declared. */ -/* +/* * rle_getrow.c - Read an RLE file in. - * + * * Author: Spencer W. Thomas * Computer Science Dept. * University of Utah * Date: Wed Apr 10 1985 * Copyright (c) 1985 Spencer W. Thomas - * + * * $Id: rle_getrow.c,v 3.0.1.5 1992/03/04 19:33:08 spencer Exp spencer $ */ @@ -43,7 +43,7 @@ /* Read a two-byte "short" that started in VAX (LITTLE_ENDIAN) order */ #define VAXSHORT( var, fp )\ { var = fgetc(fp)&0xFF; var |= (fgetc(fp)) << 8; } - + /* Instruction format -- first byte is opcode, second is datum. */ #define OPCODE(inst) (inst[0] & ~LONG) @@ -77,7 +77,7 @@ rle_get_setup(rle_hdr * const the_hdr) { FILE * infile = the_hdr->rle_file; int i; char * comment_buf; - + /* Clear old stuff out of the header. */ rle_hdr_clear(the_hdr); if (the_hdr->is_init != RLE_INIT_MAGIC) @@ -167,7 +167,7 @@ rle_get_setup(rle_hdr * const the_hdr) { evenlen = (comlen + 1) & ~1; /* make it even */ if (evenlen) { MALLOCARRAY(comment_buf, evenlen); - + if (comment_buf == NULL) { pm_error("Malloc failed for comment buffer of size %d " "in rle_get_setup, reading '%s'", @@ -218,78 +218,13 @@ rle_get_setup(rle_hdr * const the_hdr) { -void -rle_get_setup_ok(rle_hdr * const the_hdr, - const char * const prog_name, - const char * const file_name) { -/*----------------------------------------------------------------------------- - Read the initialization information from an RLE file. - - Inputs: - the_hdr: Contains pointer to the input file. - prog_name: Program name to be printed in the error message. - file_name: File name to be printed in the error message. - If NULL, the string "stdin" is generated. - - Outputs: - the_hdr: Initialized with information from the input file. - If reading the header fails, it prints an error message - and exits with the appropriate status code. - Algorithm: - rle_get_setup does all the work. ----------------------------------------------------------------------------- */ - int code; - - /* Backwards compatibility: if is_init is not properly set, - * initialize the header. - */ - if (the_hdr->is_init != RLE_INIT_MAGIC) { - FILE * const f = the_hdr->rle_file; - rle_hdr_init( the_hdr ); - the_hdr->rle_file = f; - rle_names(the_hdr, prog_name, file_name, 0); - } - - code = rle_get_error(rle_get_setup(the_hdr), - the_hdr->cmd, the_hdr->file_name); - if (code) - exit(code); -} - - - -void -rle_debug( on_off ) - int on_off; -{ -/*----------------------------------------------------------------------------- - Turn RLE debugging on or off. - Inputs: - on_off: if 0, stop debugging, else start. - Outputs: - Sets internal debug flag. - Assumptions: - [None] - Algorithm: - [None] ----------------------------------------------------------------------------- */ - debug_f = on_off; - - /* Set line buffering on stderr. Character buffering is the default, and - * it is SLOOWWW for large amounts of output. - */ - setvbuf(stderr, NULL, _IOLBF, 0); -} - - - int rle_getrow(rle_hdr * const the_hdr, rle_pixel ** const scanline) { /*----------------------------------------------------------------------------- Get a scanline from the input file. Inputs: - the_hdr: Header structure containing information about + the_hdr: Header structure containing information about the input file. Outputs: scanline: an array of pointers to the individual color @@ -304,10 +239,10 @@ rle_getrow(rle_hdr * const the_hdr, specified (the_hdr->background is true), just set the scanlines to the background color. If clear-to-background is not set, just increment the scanline number and return. - + Otherwise, read input until a vertical skip is encountered, decoding the instructions into scanline data. - + If ymax is reached (or, somehow, passed), continue reading and discarding input until end of image. ---------------------------------------------------------------------------- */ diff --git a/urt/rle_getskip.c b/urt/rle_getskip.c index 1366e162..3d36fba4 100644 --- a/urt/rle_getskip.c +++ b/urt/rle_getskip.c @@ -1,27 +1,27 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the * name of the person performing the modification, the date of modification, * and the reason for such modification. */ -/* +/* * rle_getskip.c - Skip scanlines on input. - * - * Author: Spencer W. Thomas - * EECS Dept. - * University of Michigan - * Date: Wed Jun 27 1990 + * + * Author: Spencer W. Thomas + * EECS Dept. + * University of Michigan + * Date: Wed Jun 27 1990 * Copyright (c) 1990, University of Michigan */ @@ -32,133 +32,133 @@ /* Read a two-byte "short" that started in VAX (LITTLE_ENDIAN) order */ #define VAXSHORT( var, fp )\ - { var = fgetc(fp)&0xFF; var |= (fgetc(fp)) << 8; } - + { var = fgetc(fp)&0xFF; var |= (fgetc(fp)) << 8; } + /* Instruction format -- first byte is opcode, second is datum. */ #define OPCODE(inst) (inst[0] & ~LONG) #define LONGP(inst) (inst[0] & LONG) -#define DATUM(inst) (inst[1] & 0xff) /* Make sure it's unsigned. */ +#define DATUM(inst) (inst[1] & 0xff) /* Make sure it's unsigned. */ /***************************************************************** * TAG( rle_getskip ) - * + * * Skip the next scanline with data on it. * Most useful for skipping to end-of-image. * Inputs: - * the_hdr: Describes input image. + * the_hdr: Describes input image. * Outputs: - * Returns the number of the next scanline. At EOF returns 32768. + * Returns the number of the next scanline. At EOF returns 32768. * Assumptions: - * rle_get_setup has been called. + * rle_get_setup has been called. * Algorithm: - * Read input to the beginning of the next scanline, or to EOF or - * end of image. + * Read input to the beginning of the next scanline, or to EOF or + * end of image. */ unsigned int rle_getskip( the_hdr ) rle_hdr *the_hdr; { unsigned char inst[2]; - register FILE *infile = the_hdr->rle_file; + FILE *infile = the_hdr->rle_file; int nc; /* Add in vertical skip from last scanline */ - if ( the_hdr->priv.get.vert_skip > 0) - the_hdr->priv.get.scan_y += the_hdr->priv.get.vert_skip; + if ( the_hdr->priv.get.vert_skip > 0) + the_hdr->priv.get.scan_y += the_hdr->priv.get.vert_skip; the_hdr->priv.get.vert_skip = 0; if ( the_hdr->priv.get.is_eof ) - return 32768; /* too big for 16 bits, signal EOF */ - + return 32768; /* too big for 16 bits, signal EOF */ + /* Otherwise, read and interpret instructions until a skipLines * instruction is encountered. */ for (;;) { inst[0] = getc( infile ); - inst[1] = getc( infile ); - if ( feof(infile) ) - { - the_hdr->priv.get.is_eof = 1; - break; /* <--- one of the exits */ - } - - switch( OPCODE(inst) ) - { - case RSkipLinesOp: - if ( LONGP(inst) ) - { - VAXSHORT( the_hdr->priv.get.vert_skip, infile ); - } - else - the_hdr->priv.get.vert_skip = DATUM(inst); - break; /* need to break for() here, too */ - - case RSetColorOp: - /* No-op here. */ - break; - - case RSkipPixelsOp: - if ( LONGP(inst) ) - { - (void)getc( infile ); - (void)getc( infile ); - } - break; - - case RByteDataOp: - if ( LONGP(inst) ) - { - VAXSHORT( nc, infile ); - } - else - nc = DATUM(inst); - nc++; - if ( the_hdr->priv.get.is_seek ) - fseek( infile, ((nc + 1) / 2) * 2, 1 ); - else - { - register int ii; - for ( ii = ((nc + 1) / 2) * 2; ii > 0; ii-- ) - (void) getc( infile ); /* discard it */ - } - - break; - - case RRunDataOp: - if ( LONGP(inst) ) - { - (void)getc( infile ); - (void)getc( infile ); - } - (void)getc( infile ); - (void)getc( infile ); - break; - - case REOFOp: - the_hdr->priv.get.is_eof = 1; - break; - - default: - fprintf( stderr, - "%s: rle_getskip: Unrecognized opcode: %d, reading %s\n", - the_hdr->cmd, OPCODE(inst), the_hdr->file_name ); - exit(1); - } - if ( OPCODE(inst) == REOFOp ) - break; /* <--- the other loop exit */ - if ( OPCODE(inst) == RSkipLinesOp ) - break; + inst[1] = getc( infile ); + if ( feof(infile) ) + { + the_hdr->priv.get.is_eof = 1; + break; /* <--- one of the exits */ + } + + switch( OPCODE(inst) ) + { + case RSkipLinesOp: + if ( LONGP(inst) ) + { + VAXSHORT( the_hdr->priv.get.vert_skip, infile ); + } + else + the_hdr->priv.get.vert_skip = DATUM(inst); + break; /* need to break for() here, too */ + + case RSetColorOp: + /* No-op here. */ + break; + + case RSkipPixelsOp: + if ( LONGP(inst) ) + { + (void)getc( infile ); + (void)getc( infile ); + } + break; + + case RByteDataOp: + if ( LONGP(inst) ) + { + VAXSHORT( nc, infile ); + } + else + nc = DATUM(inst); + nc++; + if ( the_hdr->priv.get.is_seek ) + fseek( infile, ((nc + 1) / 2) * 2, 1 ); + else + { + int ii; + for ( ii = ((nc + 1) / 2) * 2; ii > 0; ii-- ) + (void) getc( infile ); /* discard it */ + } + + break; + + case RRunDataOp: + if ( LONGP(inst) ) + { + (void)getc( infile ); + (void)getc( infile ); + } + (void)getc( infile ); + (void)getc( infile ); + break; + + case REOFOp: + the_hdr->priv.get.is_eof = 1; + break; + + default: + fprintf( stderr, + "%s: rle_getskip: Unrecognized opcode: %d, reading %s\n", + the_hdr->cmd, OPCODE(inst), the_hdr->file_name ); + exit(1); + } + if ( OPCODE(inst) == REOFOp ) + break; /* <--- the other loop exit */ + if ( OPCODE(inst) == RSkipLinesOp ) + break; } /* Return the number of the NEXT scanline. */ the_hdr->priv.get.scan_y += - the_hdr->priv.get.vert_skip; + the_hdr->priv.get.vert_skip; the_hdr->priv.get.vert_skip = 0; if ( the_hdr->priv.get.is_eof ) - return 32768; /* too big for 16 bits, signal EOF */ + return 32768; /* too big for 16 bits, signal EOF */ else - return the_hdr->priv.get.scan_y; + return the_hdr->priv.get.scan_y; } diff --git a/urt/rle_global.c b/urt/rle_global.c index 6014a229..f7228ea9 100644 --- a/urt/rle_global.c +++ b/urt/rle_global.c @@ -1,14 +1,14 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the @@ -18,15 +18,15 @@ * Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire * to have all "void" functions so declared. */ -/* +/* * rle_global.c - Global variable initialization for rle routines. - * - * Author: Spencer W. Thomas - * Computer Science Dept. - * University of Utah - * Date: Thu Apr 25 1985 + * + * Author: Spencer W. Thomas + * Computer Science Dept. + * University of Utah + * Date: Thu Apr 25 1985 * Copyright (c) 1985,1986 Spencer W. Thomas - * + * * $Id: rle_global.c,v 3.0.1.1 1992/01/28 18:23:03 spencer Exp $ */ @@ -39,40 +39,40 @@ struct rle_dispatch_tab rle_DTable[] = { { - " OB", - RunSetup, - RunSkipBlankLines, - RunSetColor, - RunSkipPixels, - RunNewScanLine, - Runputdata, - Runputrun, - DefaultBlockHook, - RunputEof + " OB", + RunSetup, + RunSkipBlankLines, + RunSetColor, + RunSkipPixels, + RunNewScanLine, + Runputdata, + Runputrun, + DefaultBlockHook, + RunputEof }, }; static int bg_color[3] = { 0, 0, 0 }; rle_hdr rle_dflt_hdr = { - RUN_DISPATCH, /* dispatch value */ - 3, /* 3 colors */ - bg_color, /* background color */ - 0, /* (alpha) if 1, save alpha channel */ - 2, /* (background) 0->just save pixels, */ - /* 1->overlay, 2->clear to bg first */ - 0, 511, /* (xmin, xmax) X bounds to save */ - 0, 511, /* (ymin, ymax) Y bounds to save */ - 0, /* ncmap (if != 0, save color map) */ - 8, /* cmaplen (log2 of length of color map) */ - NULL, /* pointer to color map */ - NULL, /* pointer to comment strings */ - NULL, /* output file -- must be set dynamically */ - { 7 }, /* RGB channels only */ - 0L, /* Can't free name and file fields. */ - "Urt", /* Default "program name". */ - "no file", /* No file name given. */ - 0 /* First image. */ + RUN_DISPATCH, /* dispatch value */ + 3, /* 3 colors */ + bg_color, /* background color */ + 0, /* (alpha) if 1, save alpha channel */ + 2, /* (background) 0->just save pixels, */ + /* 1->overlay, 2->clear to bg first */ + 0, 511, /* (xmin, xmax) X bounds to save */ + 0, 511, /* (ymin, ymax) Y bounds to save */ + 0, /* ncmap (if != 0, save color map) */ + 8, /* cmaplen (log2 of length of color map) */ + NULL, /* pointer to color map */ + NULL, /* pointer to comment strings */ + NULL, /* output file -- must be set dynamically */ + { 7 }, /* RGB channels only */ + 0L, /* Can't free name and file fields. */ + "Urt", /* Default "program name". */ + "no file", /* No file name given. */ + 0 /* First image. */ /* Can't initialize the union */ }; @@ -82,6 +82,6 @@ void NullputEof(the_hdr) rle_hdr * the_hdr; { - /* do nothing */ + /* do nothing */ } #endif diff --git a/urt/rle_hdr.c b/urt/rle_hdr.c index bdb728d2..8ceaa9eb 100644 --- a/urt/rle_hdr.c +++ b/urt/rle_hdr.c @@ -40,7 +40,7 @@ rle_names(rle_hdr * const hdrP, const char * const pgmname, const char * const fname, int const imgNum) { -/*---------------------------------------------------------------------------- +/*---------------------------------------------------------------------------- * Load program and file names into header. * Inputs: * hdrP: Header to modify. diff --git a/urt/rle_open_f.c b/urt/rle_open_f.c index 1aeb6448..65362a53 100644 --- a/urt/rle_open_f.c +++ b/urt/rle_open_f.c @@ -322,31 +322,3 @@ rle_open_f(const char * prog_name, const char * file_name, const char * mode) return fp; } - -/***************************************************************** - * TAG( rle_close_f ) - * - * Close a file opened by rle_open_f. If the file is stdin or stdout, - * it will not be closed. - * Inputs: - * fd: File to close. - * Outputs: - * None. - * Assumptions: - * fd is open. - * Algorithm: - * If fd is NULL, just return. - * If fd is stdin or stdout, don't close it. Otherwise, call fclose. - */ -void -rle_close_f( fd ) - FILE *fd; -{ - if ( fd == NULL || fd == stdin || fd == stdout ) - return; - else - fclose( fd ); -} - - - diff --git a/urt/rle_put.h b/urt/rle_put.h index 1f8cc85b..bfabd617 100644 --- a/urt/rle_put.h +++ b/urt/rle_put.h @@ -1,29 +1,29 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the * name of the person performing the modification, the date of modification, * and the reason for such modification. */ -/* +/* * rle_put.h - Definitions and a few global variables for rle_putrow/putraw. - * - * Author: Spencer W. Thomas - * Computer Science Dept. - * University of Utah - * Date: Mon Aug 9 1982 + * + * Author: Spencer W. Thomas + * Computer Science Dept. + * University of Utah + * Date: Mon Aug 9 1982 * Copyright (c) 1982 Spencer W. Thomas - * + * * $Id: rle_put.h,v 3.0.1.2 1992/02/27 21:14:35 spencer Exp $ */ @@ -35,7 +35,7 @@ */ #ifdef __cplusplus /* Cfront 2.0 or g++ */ #ifndef c_plusplus -#define c_plusplus +#define c_plusplus #endif extern "C" { #endif @@ -67,38 +67,38 @@ struct rle_dispatch_tab { extern struct rle_dispatch_tab rle_DTable[]; -/* +/* * These definitions presume the existence of a variable called * "fileptr", declared "long * fileptr". *fileptr should be * initialized to 0 before calling Setup(). * A pointer "the_hdr" declared "rle_hdr * the_hdr" is also * presumed to exist. */ -#define rle_magic (rle_DTable[(int)the_hdr->dispatch].magic) -#define Setup() (*rle_DTable[(int)the_hdr->dispatch].setup)(the_hdr) -#define SkipBlankLines(n) (*rle_DTable[(int)the_hdr->dispatch].skipBlankLines)(n, the_hdr) -#define SetColor(c) (*rle_DTable[(int)the_hdr->dispatch].setColor)(c, the_hdr) -#define SkipPixels(n, l, r) (*rle_DTable[(int)the_hdr->dispatch].skipPixels)(n,l,r, the_hdr) -#define NewScanLine(flag) (*rle_DTable[(int)the_hdr->dispatch].newScanLine)(flag, the_hdr) -#define putdata(buf, len) (*rle_DTable[(int)the_hdr->dispatch].putdat)(buf, len, the_hdr) -#define putrun(val, len, f) (*rle_DTable[(int)the_hdr->dispatch].putrn)(val,len,f, the_hdr) -#define BlockHook() (*rle_DTable[(int)the_hdr->dispatch].blockHook)(the_hdr) -#define PutEof() (*rle_DTable[(int)the_hdr->dispatch].putEof)(the_hdr) +#define rle_magic (rle_DTable[(int)the_hdr->dispatch].magic) +#define Setup() (*rle_DTable[(int)the_hdr->dispatch].setup)(the_hdr) +#define SkipBlankLines(n) (*rle_DTable[(int)the_hdr->dispatch].skipBlankLines)(n, the_hdr) +#define SetColor(c) (*rle_DTable[(int)the_hdr->dispatch].setColor)(c, the_hdr) +#define SkipPixels(n, l, r) (*rle_DTable[(int)the_hdr->dispatch].skipPixels)(n,l,r, the_hdr) +#define NewScanLine(flag) (*rle_DTable[(int)the_hdr->dispatch].newScanLine)(flag, the_hdr) +#define putdata(buf, len) (*rle_DTable[(int)the_hdr->dispatch].putdat)(buf, len, the_hdr) +#define putrun(val, len, f) (*rle_DTable[(int)the_hdr->dispatch].putrn)(val,len,f, the_hdr) +#define BlockHook() (*rle_DTable[(int)the_hdr->dispatch].blockHook)(the_hdr) +#define PutEof() (*rle_DTable[(int)the_hdr->dispatch].putEof)(the_hdr) void DefaultBlockHook(rle_hdr * the_hdr); -/* +/* * States for run detection */ -#define DATA 0 -#define RUN1 1 -#define RUN2 2 -#define RUN3 3 -#define RUN4 4 -#define RUN5 5 -#define RUN6 6 -#define RUN7 7 -#define INRUN -1 +#define DATA 0 +#define RUN1 1 +#define RUN2 2 +#define RUN3 3 +#define RUN4 4 +#define RUN5 5 +#define RUN6 6 +#define RUN7 7 +#define INRUN -1 #ifdef __cplusplus } diff --git a/urt/rle_putcom.c b/urt/rle_putcom.c index ab2eb208..0bebd8d7 100644 --- a/urt/rle_putcom.c +++ b/urt/rle_putcom.c @@ -1,23 +1,23 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the * name of the person performing the modification, the date of modification, * and the reason for such modification. */ -/* +/* * rle_putcom.c - Add a picture comment to the header struct. - * + * * Author: Spencer W. Thomas * Computer Science Dept. * University of Utah @@ -33,7 +33,7 @@ /***************************************************************** * TAG( match ) - * + * * Match a name against a test string for "name=value" or "name". * If it matches name=value, return pointer to value part, if just * name, return pointer to NUL at end of string. If no match, return NULL. @@ -72,7 +72,7 @@ match(const char * const nArg, /***************************************************************** * TAG( rle_putcom ) - * + * * Put a comment into the header struct. * Inputs: * value: Value to add to comments. @@ -124,46 +124,3 @@ rle_putcom(const char * const value, return NULL; } - - - -/***************************************************************** - * TAG( rle_delcom ) - * - * Delete a comment from header struct. - * Inputs: - * name: Name of comment to delete. - * the_hdr: Header to delete comment from. - * Outputs: - * the_hdr: Modified header struct. - * Returns original comment value. - * Assumptions: - * [None] - * Algorithm: - * [None] - */ -const char * -rle_delcom(const char * const name, - rle_hdr * const the_hdr) { - - const char * v = NULL; - - if (the_hdr->comments == NULL) - v = NULL; - else { - const char ** cp; - - for (cp = the_hdr->comments; *cp != NULL; ++cp) - if (match(name, *cp) != NULL) { - v = *cp; - for ( ; *cp != NULL; ++cp) - *cp = cp[1]; - break; - } - /* Not found */ - if (*the_hdr->comments == NULL) - the_hdr->comments = NULL; - } - - return v; -} diff --git a/urt/rle_putrow.c b/urt/rle_putrow.c index 399633e4..5f808c92 100644 --- a/urt/rle_putrow.c +++ b/urt/rle_putrow.c @@ -1,14 +1,14 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the @@ -18,60 +18,57 @@ * Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire * to have all "void" functions so declared. */ -/* +/* * rle_putrow.c - Save a row of the fb to a file. - * - * Author: Spencer W. Thomas - * Computer Science Dept. - * University of Utah - * Date: 1 April 1981 + * + * Author: Spencer W. Thomas + * Computer Science Dept. + * University of Utah + * Date: 1 April 1981 * Copyright (c) 1981,1986 Spencer W. Thomas * * $Id: rle_putrow.c,v 3.0.1.2 1992/01/28 18:29:22 spencer Exp $ */ - + #include <stdio.h> #include "rle_put.h" #include "rle.h" -#define FASTRUNS /* Faster run finding */ -#ifdef vax -#define LOCC /* Use vax instructions for more speed */ -#endif +#define FASTRUNS /* Faster run finding */ -#define FALSE 0 -#define TRUE 1 +#define FALSE 0 +#define TRUE 1 /* Save some typing. */ #define PBRUN the_hdr->priv.put.brun /***************************************************************** * TAG( findruns ) - * + * * Find runs not a given color in the row. * Inputs: - * row: Row of pixel values - * rowlen: Number of pixels in the row. - * color: Color to compare against. - * nrun: Number of runs already found (in different colors). - * brun: Runs found in other color channels already. + * row: Row of pixel values + * rowlen: Number of pixels in the row. + * color: Color to compare against. + * nrun: Number of runs already found (in different colors). + * brun: Runs found in other color channels already. * Outputs: - * brun: Modified to reflect merging of runs in this color. - * Returns number of runs in brun. + * brun: Modified to reflect merging of runs in this color. + * Returns number of runs in brun. * Assumptions: * * Algorithm: - * Search for occurrences of pixels not of the given color outside - * the runs already found. When some are found, add a new run or - * extend an existing one. Adjacent runs with fewer than two - * pixels intervening are merged. + * Search for occurrences of pixels not of the given color outside + * the runs already found. When some are found, add a new run or + * extend an existing one. Adjacent runs with fewer than two + * pixels intervening are merged. */ static int -findruns(rle_pixel * const row, - int const rowlen, - int const color, +findruns(rle_pixel * const row, + int const rowlen, + int const color, int const nrunAlready, short (* const brun)[2]) { @@ -99,9 +96,9 @@ findruns(rle_pixel * const row, /* Assert: 0 <= i <= rowlen * brun[i] is the run following the "blank" space being * searched. If i == rowlen, search after brun[i-1]. - */ + */ - /* get lower and upper bounds of search */ + /* get lower and upper bounds of search */ if ( i == 0 ) lower = 0; @@ -118,15 +115,13 @@ findruns(rle_pixel * const row, i, lower, upper ); #endif /* Search for beginning of run != color */ -#if defined(LOCC)&defined(vax) - s = upper - skpc( (char *)row + lower, upper - lower + 1, color ) + 1; -#else + for ( s = lower; s <= upper; s++ ) if ( row[s] != color ) break; -#endif - if ( s <= upper ) /* found a new run? */ + + if ( s <= upper ) /* found a new run? */ { if ( s > lower + 1 || i == 0 ) /* disjoint from preceding run? */ { @@ -144,19 +139,16 @@ findruns(rle_pixel * const row, } else { - i--; /* just add to preceding run */ + i--; /* just add to preceding run */ #ifdef DEBUG fprintf( stderr, "Adding to previous run\n" ); #endif } -#if defined(LOCC)&defined(vax) - s = upper - locc( (char *)row + s, upper - s + 1, color ) + 1; -#else for ( ; s <= upper; s++ ) if ( row[s] == color ) break; -#endif + brun[i][1] = s - 1; #ifdef DEBUG @@ -180,7 +172,7 @@ findruns(rle_pixel * const row, putc( '\n', stderr ); #endif } - + /* Search in next space */ i++; } @@ -193,319 +185,313 @@ findruns(rle_pixel * const row, /***************************************************************** * TAG( rle_putrow ) * Write a scanline to the output file. - * + * * Inputs: - * rows: Pointer to vector of pointers to - * rle_pixel arrays containing the pixel information. - * If NULL, rowlen scanlines are skipped. - * rowlen: The number of pixels in the scanline, or the - * number of scanlines to skip (see above). + * rows: Pointer to vector of pointers to + * rle_pixel arrays containing the pixel information. + * If NULL, rowlen scanlines are skipped. + * rowlen: The number of pixels in the scanline, or the + * number of scanlines to skip (see above). * Outputs: - * Run length encoded information is written to the_hdr.rle_file. + * Run length encoded information is written to the_hdr.rle_file. * Assumptions: - * I'm sure there are lots of assumptions in here. + * I'm sure there are lots of assumptions in here. * Algorithm: - * There are two parts: - * 1. Find all "sufficiently long" runs of background - * color. These will not be saved at all. - * 2. For each run of non-background, for each color - * channel, find runs of identical pixel values - * between "data" segments (of differing pixel - * values). - * For part 1, "sufficiently long" is 2 pixels, if the following - * data is less than 256 pixels long, otherwise it is 4 pixels. - * This is enforced by a post-process merge. + * There are two parts: + * 1. Find all "sufficiently long" runs of background + * color. These will not be saved at all. + * 2. For each run of non-background, for each color + * channel, find runs of identical pixel values + * between "data" segments (of differing pixel + * values). + * For part 1, "sufficiently long" is 2 pixels, if the following + * data is less than 256 pixels long, otherwise it is 4 pixels. + * This is enforced by a post-process merge. * - * Part 1 can be done in two different ways, depending on whether - * FASTRUNS is defined or not. With FASTRUNS defined, it finds - * runs of the background pixel value in each channel - * independently, and then merges the results. With FASTRUNS not - * defined, it scans all channels in parallel. + * Part 1 can be done in two different ways, depending on whether + * FASTRUNS is defined or not. With FASTRUNS defined, it finds + * runs of the background pixel value in each channel + * independently, and then merges the results. With FASTRUNS not + * defined, it scans all channels in parallel. * - * Part 2 uses a state machine. For each run of non-background - * data, it searches for sufficiently long sequences of a single - * value (in each channel independently). Sufficiently long is 4 - * pixels if the following data is < 256 pixels, 6 pixels - * otherwise. This is because the startup cost for the run is 2 - * bytes, and the startup cost for a data segment is 2 bytes if - * it is < 256 pixels long, 4 bytes otherwise. Thus a run - * shorter than 4 or 6 pixels (respectively) would actually make - * the output longer. An additional pixel is required if the - * preceding data is an odd number of pixels long (because a - * filler byte will be output at the end of it.) + * Part 2 uses a state machine. For each run of non-background + * data, it searches for sufficiently long sequences of a single + * value (in each channel independently). Sufficiently long is 4 + * pixels if the following data is < 256 pixels, 6 pixels + * otherwise. This is because the startup cost for the run is 2 + * bytes, and the startup cost for a data segment is 2 bytes if + * it is < 256 pixels long, 4 bytes otherwise. Thus a run + * shorter than 4 or 6 pixels (respectively) would actually make + * the output longer. An additional pixel is required if the + * preceding data is an odd number of pixels long (because a + * filler byte will be output at the end of it.) */ void rle_putrow(rows, rowlen, the_hdr) -register rle_pixel *rows[]; +rle_pixel *rows[]; int rowlen; -register rle_hdr * the_hdr; +rle_hdr * the_hdr; { - register int i, j; + int i, j; int nrun; - register rle_pixel *row; + rle_pixel *row; int mask; char bits[256]; - short state, /* State of run-finding state machine. */ - dstart, /* Starting point for current data segment. */ - dend, /* Ending point of current data segment. */ - rstart = 0, /* Starting point of current run. */ - runval = 0; /* Data value for current run. */ + short state, /* State of run-finding state machine. */ + dstart, /* Starting point for current data segment. */ + dend, /* Ending point of current data segment. */ + rstart = 0, /* Starting point of current run. */ + runval = 0; /* Data value for current run. */ if (rows == NULL) { - the_hdr->priv.put.nblank += rowlen; - return; + the_hdr->priv.put.nblank += rowlen; + return; } - /* + /* * If not done already, allocate space to remember runs of * non-background color. A run of bg color must be at least 2 * bytes long to count, so there can be at most rowlen/3 of them. */ if ( PBRUN == NULL ) { - PBRUN = (short (*)[2])malloc( - (unsigned)((rowlen/3 + 1) * 2 * sizeof(short)) ); - if ( PBRUN == NULL ) - { - fprintf( stderr, "%s: Malloc failed in rle_putrow, writing %s\n", - the_hdr->cmd, the_hdr->file_name ); - exit(1); - } + PBRUN = (short (*)[2])malloc( + (unsigned)((rowlen/3 + 1) * 2 * sizeof(short)) ); + if ( PBRUN == NULL ) + { + fprintf( stderr, "%s: Malloc failed in rle_putrow, writing %s\n", + the_hdr->cmd, the_hdr->file_name ); + exit(1); + } } /* Unpack bitmask in the_hdr struct */ for ( i=0; i < the_hdr->ncolors; i++ ) - bits[i] = RLE_BIT( *the_hdr, i ); + bits[i] = RLE_BIT( *the_hdr, i ); bits[255] = RLE_BIT( *the_hdr, -1 ); - /* + /* * If saving only non-background pixels, find runs of them. Note * that the alpha channel is considered to be background iff it is * zero. */ -#ifdef FASTRUNS +#ifdef FASTRUNS if ( the_hdr->background ) { - /* - * Find runs in each color individually, merging them as we go. - */ - nrun = 0; /* start out with no runs */ - /* Alpha channel first */ - if ( the_hdr->alpha ) - nrun = findruns( rows[-1], rowlen, 0, nrun, PBRUN ); - /* Now the color channels */ - for ( i = 0; i < the_hdr->ncolors; i++ ) - if ( bits[i] ) - nrun = findruns( rows[i], rowlen, the_hdr->bg_color[i], - nrun, PBRUN ); + /* + * Find runs in each color individually, merging them as we go. + */ + nrun = 0; /* start out with no runs */ + /* Alpha channel first */ + if ( the_hdr->alpha ) + nrun = findruns( rows[-1], rowlen, 0, nrun, PBRUN ); + /* Now the color channels */ + for ( i = 0; i < the_hdr->ncolors; i++ ) + if ( bits[i] ) + nrun = findruns( rows[i], rowlen, the_hdr->bg_color[i], + nrun, PBRUN ); } else { - PBRUN[0][0] = 0; - PBRUN[0][1] = rowlen-1; - nrun = 1; + PBRUN[0][0] = 0; + PBRUN[0][1] = rowlen-1; + nrun = 1; } -#else /* FASTRUNS */ - if (the_hdr->background) /* find non-background runs */ +#else /* FASTRUNS */ + if (the_hdr->background) /* find non-background runs */ { - j = 0; - for (i=0; i<rowlen; i++) - if (!same_color( i, rows, the_hdr->bg_color, - the_hdr->ncolors, bits ) || - (the_hdr->alpha && rows[-1][i] != 0)) - { - if (j > 0 && i - PBRUN[j-1][1] <= 2) - j--; - else - PBRUN[j][0] = i; /* start of run */ - for ( i++; - i < rowlen && - ( !same_color( i, rows, the_hdr->bg_color, - the_hdr->ncolors, bits ) || - (the_hdr->alpha && rows[-1][i] != 0) ); - i++) - ; /* find the end of this run */ - PBRUN[j][1] = i-1; /* last in run */ - j++; - } - nrun = j; + j = 0; + for (i=0; i<rowlen; i++) + if (!same_color( i, rows, the_hdr->bg_color, + the_hdr->ncolors, bits ) || + (the_hdr->alpha && rows[-1][i] != 0)) + { + if (j > 0 && i - PBRUN[j-1][1] <= 2) + j--; + else + PBRUN[j][0] = i; /* start of run */ + for ( i++; + i < rowlen && + ( !same_color( i, rows, the_hdr->bg_color, + the_hdr->ncolors, bits ) || + (the_hdr->alpha && rows[-1][i] != 0) ); + i++) + ; /* find the end of this run */ + PBRUN[j][1] = i-1; /* last in run */ + j++; + } + nrun = j; } else { - PBRUN[0][0] = 0; - PBRUN[0][1] = rowlen-1; - nrun = 1; + PBRUN[0][0] = 0; + PBRUN[0][1] = rowlen-1; + nrun = 1; } -#endif /* FASTRUNS */ +#endif /* FASTRUNS */ /* One final pass merges runs with fewer than 4 intervening pixels * if the second run is longer than 255 pixels. This is because * the startup cost for such a run is 4 bytes. */ if ( nrun > 1 ) { - for ( i = nrun - 1; i > 0; i-- ) - { - if ( PBRUN[i][1] - PBRUN[i][0] > 255 && - PBRUN[i-1][1] + 4 > PBRUN[i][0] ) - { - PBRUN[i-1][1] = PBRUN[i][1]; - for ( j = i; j < nrun - 1; j++ ) - { - PBRUN[j][0] = PBRUN[j+1][0]; - PBRUN[j][1] = PBRUN[j+1][1]; - } - nrun--; - } - } + for ( i = nrun - 1; i > 0; i-- ) + { + if ( PBRUN[i][1] - PBRUN[i][0] > 255 && + PBRUN[i-1][1] + 4 > PBRUN[i][0] ) + { + PBRUN[i-1][1] = PBRUN[i][1]; + for ( j = i; j < nrun - 1; j++ ) + { + PBRUN[j][0] = PBRUN[j+1][0]; + PBRUN[j][1] = PBRUN[j+1][1]; + } + nrun--; + } + } } if (nrun > 0) { - if (the_hdr->priv.put.nblank > 0) - { - SkipBlankLines(the_hdr->priv.put.nblank); - the_hdr->priv.put.nblank = 0; - } - for ( mask = (the_hdr->alpha ? -1 : 0); - mask < the_hdr->ncolors; - mask++) /* do all colors */ - { - if ( ! bits[mask & 0xff] ) - { - continue; - } - row = rows[mask]; - SetColor(mask); - if (PBRUN[0][0] > 0) - { - SkipPixels(PBRUN[0][0], FALSE, FALSE); - } - for (j=0; j<nrun; j++) - { - state = DATA; - dstart = PBRUN[j][0]; - dend = PBRUN[j][1]; - for (i=dstart; i<=dend; i++) - { - switch(state) - { - case DATA: - if (i > dstart && runval == row[i]) - { - /* 2 in a row may be a run. */ - /* If odd data length, start with RUN1 */ - if ( ((i - dstart) % 2) == 0) - state = RUN1; - else - state = RUN2; - } - else - { - runval = row[i]; /* maybe a run starts here? */ - rstart = i; - } - break; - - case RUN4: - if (runval == row[i]) - { - /* If the following data might be longer - * than 255 pixels then look for 8 in a - * row, otherwise, 6 in a row is - * sufficient. Fake this by skipping to - * state RUN5. - */ - if ( dend - i > 255 ) - state = RUN5; /* Need some more. */ - else - state = RUN7; /* Next one makes a run. */ - - } - else - { - state = DATA; /* Nope, back to data */ - runval = row[i]; /* but maybe a new run here? */ - rstart = i; - } - break; - - case RUN1: - case RUN2: - case RUN3: - case RUN5: - case RUN6: - if (runval == row[i]) - { - /* Move to the next state. */ - state++; - } - else - { - state = DATA; /* Nope, back to data */ - runval = row[i]; /* but maybe a new run here? */ - rstart = i; - } - break; - - - case RUN7: - if (runval == row[i]) /* enough in a row for a run */ - { - state = INRUN; - putdata(row + dstart, rstart - dstart); + if (the_hdr->priv.put.nblank > 0) + { + SkipBlankLines(the_hdr->priv.put.nblank); + the_hdr->priv.put.nblank = 0; + } + for ( mask = (the_hdr->alpha ? -1 : 0); + mask < the_hdr->ncolors; + mask++) /* do all colors */ + { + if ( ! bits[mask & 0xff] ) + { + continue; + } + row = rows[mask]; + SetColor(mask); + if (PBRUN[0][0] > 0) + { + SkipPixels(PBRUN[0][0], FALSE, FALSE); + } + for (j=0; j<nrun; j++) + { + state = DATA; + dstart = PBRUN[j][0]; + dend = PBRUN[j][1]; + for (i=dstart; i<=dend; i++) + { + switch(state) + { + case DATA: + if (i > dstart && runval == row[i]) + { + /* 2 in a row may be a run. */ + /* If odd data length, start with RUN1 */ + if ( ((i - dstart) % 2) == 0) + state = RUN1; + else + state = RUN2; + } + else + { + runval = row[i]; /* maybe a run starts here? */ + rstart = i; + } + break; + + case RUN4: + if (runval == row[i]) + { + /* If the following data might be longer + * than 255 pixels then look for 8 in a + * row, otherwise, 6 in a row is + * sufficient. Fake this by skipping to + * state RUN5. + */ + if ( dend - i > 255 ) + state = RUN5; /* Need some more. */ + else + state = RUN7; /* Next one makes a run. */ + + } + else + { + state = DATA; /* Nope, back to data */ + runval = row[i]; /* but maybe a new run here? */ + rstart = i; + } + break; + + case RUN1: + case RUN2: + case RUN3: + case RUN5: + case RUN6: + if (runval == row[i]) + { + /* Move to the next state. */ + state++; + } + else + { + state = DATA; /* Nope, back to data */ + runval = row[i]; /* but maybe a new run here? */ + rstart = i; + } + break; + + + case RUN7: + if (runval == row[i]) /* enough in a row for a run */ + { + state = INRUN; + putdata(row + dstart, rstart - dstart); #ifdef FASTRUNS -#ifdef LOCC - /* Shortcut to find end of run! */ - i = dend - skpc( (char *)row + i, dend + 1 - i, - runval ); -#else - while ( row[++i] == runval && i <= dend) - ; /* not quite so good, but not bad */ - i--; -#endif /* LOCC */ + while ( row[++i] == runval && i <= dend) + ; /* not quite so good, but not bad */ + i--; #endif /* FASTRUNS */ - } - else - { - state = DATA; /* not a run, */ - runval = row[i]; /* but may this starts one */ - rstart = i; - } - break; - - case INRUN: - if (runval != row[i]) /* if run out */ - { - state = DATA; - putrun(runval, i - rstart, FALSE); - runval = row[i]; /* who knows, might be more */ - rstart = i; - dstart = i; /* starting a new 'data' run */ - } - break; - } - } - if (state == INRUN) - putrun(runval, i - rstart, TRUE); /* last bit */ - else - putdata(row + dstart, i - dstart); - - if (j < nrun-1) - SkipPixels( - PBRUN[j+1][0] - dend - 1, - FALSE, state == INRUN); - else - { - if (rowlen - dend > 0) - SkipPixels( - rowlen - dend - 1, - TRUE, state == INRUN); - } - } - - if ( mask != the_hdr->ncolors - 1 ) - NewScanLine(FALSE); - } + } + else + { + state = DATA; /* not a run, */ + runval = row[i]; /* but may this starts one */ + rstart = i; + } + break; + + case INRUN: + if (runval != row[i]) /* if run out */ + { + state = DATA; + putrun(runval, i - rstart, FALSE); + runval = row[i]; /* who knows, might be more */ + rstart = i; + dstart = i; /* starting a new 'data' run */ + } + break; + } + } + if (state == INRUN) + putrun(runval, i - rstart, TRUE); /* last bit */ + else + putdata(row + dstart, i - dstart); + + if (j < nrun-1) + SkipPixels( + PBRUN[j+1][0] - dend - 1, + FALSE, state == INRUN); + else + { + if (rowlen - dend > 0) + SkipPixels( + rowlen - dend - 1, + TRUE, state == INRUN); + } + } + + if ( mask != the_hdr->ncolors - 1 ) + NewScanLine(FALSE); + } } /* Increment to next scanline */ @@ -517,55 +503,30 @@ register rle_hdr * the_hdr; /***************************************************************** - * TAG( rle_skiprow ) - * - * Skip rows in RLE file. - * Inputs: - * the_hdr: Header struct for RLE output file. - * nrow: Number of rows to skip. - * Outputs: - * Increments the nblank field in the the_hdr struct, so that a Skiplines - * code will be output the next time rle_putrow or rle_putraw is called. - * Assumptions: - * Only effective when called between rle_putrow or rle_putraw calls (or - * some other routine that follows the same conventions. - * Algorithm: - * [None] - */ -void -rle_skiprow( the_hdr, nrow ) -rle_hdr *the_hdr; -int nrow; -{ - the_hdr->priv.put.nblank += nrow; -} - - -/***************************************************************** * TAG( rle_put_init ) - * - * Initialize the header structure for writing scanlines. + * + * Initialize the header structure for writing scanlines. * Inputs: - * [None] + * [None] * Outputs: - * the_hdr: Private portions initialized for output. + * the_hdr: Private portions initialized for output. * Assumptions: - * [None] + * [None] * Algorithm: - * [None] + * [None] */ void rle_put_init( the_hdr ) -register rle_hdr *the_hdr; +rle_hdr *the_hdr; { the_hdr->dispatch = RUN_DISPATCH; if ( the_hdr->is_init != RLE_INIT_MAGIC ) { - the_hdr->cmd = "Urt"; - the_hdr->file_name = "some file"; + the_hdr->cmd = "Urt"; + the_hdr->file_name = "some file"; } - the_hdr->priv.put.nblank = 0; /* Reinit static vars */ + the_hdr->priv.put.nblank = 0; /* Reinit static vars */ /* Would like to be able to free previously allocated storage, * but can't count on a non-NULL value being a valid pointer. */ @@ -574,37 +535,37 @@ register rle_hdr *the_hdr; /* Only save alpha if alpha AND alpha channel bit are set. */ if ( the_hdr->alpha ) - the_hdr->alpha = (RLE_BIT( *the_hdr, -1 ) != 0); + the_hdr->alpha = (RLE_BIT( *the_hdr, -1 ) != 0); else - RLE_CLR_BIT( *the_hdr, -1 ); + RLE_CLR_BIT( *the_hdr, -1 ); } /***************************************************************** * TAG( rle_put_setup ) - * + * * Initialize for writing RLE, and write header to output file. * Inputs: - * the_hdr: Describes output image. + * the_hdr: Describes output image. * Outputs: - * the_hdr: Initialized. + * the_hdr: Initialized. * Assumptions: - * Lots of them. + * Lots of them. * Algorithm: - * [None] + * [None] */ void rle_put_setup( the_hdr ) -register rle_hdr * the_hdr; +rle_hdr * the_hdr; { rle_put_init( the_hdr ); - the_hdr->img_num++; /* Count output images. */ + the_hdr->img_num++; /* Count output images. */ Setup(); } void DefaultBlockHook(rle_hdr * the_hdr) { - /* Do nothing */ + /* Do nothing */ } /***************************************************************** @@ -613,18 +574,18 @@ DefaultBlockHook(rle_hdr * the_hdr) */ void rle_puteof( the_hdr ) -register rle_hdr * the_hdr; +rle_hdr * the_hdr; { /* Don't puteof twice. */ if ( the_hdr->dispatch == NO_DISPATCH ) - return; + return; PutEof(); fflush( the_hdr->rle_file ); /* Free storage allocated by rle_put_init. */ if ( PBRUN != NULL ) { - free( PBRUN ); - PBRUN = NULL; + free( PBRUN ); + PBRUN = NULL; } /* Signal that puteof has been called. */ the_hdr->dispatch = NO_DISPATCH; @@ -633,97 +594,33 @@ register rle_hdr * the_hdr; #ifndef FASTRUNS /***************************************************************** * TAG( same_color ) - * + * * Determine if the color at the given index position in the scan rows * is the same as the background color. * Inputs: - * index: Index to the pixel position in each row. - * rows: array of pointers to the scanlines - * bg_color: the background color - * ncolors: number of color elements/pixel + * index: Index to the pixel position in each row. + * rows: array of pointers to the scanlines + * bg_color: the background color + * ncolors: number of color elements/pixel * Outputs: - * TRUE if the color at row[*][i] is the same as bg_color[*]. + * TRUE if the color at row[*][i] is the same as bg_color[*]. * Assumptions: - * [None] + * [None] * Algorithm: - * [None] + * [None] */ static int same_color( index, rows, bg_color, ncolors, bits ) -register rle_pixel *rows[]; -register int bg_color[]; +rle_pixel *rows[]; +int bg_color[]; char *bits; { - register int i; + int i; for ( i = 0; i < ncolors; i++, bits++ ) - if ( *bits && - rows[i][index] != bg_color[i] ) - return 0; - return 1; /* all the same */ + if ( *bits && + rows[i][index] != bg_color[i] ) + return 0; + return 1; /* all the same */ } #endif /* !FASTRUNS */ - -/***************************************************************** - * TAG( rgb_to_bw ) - * - * Perform the NTSC Y transform on RGB data to get B&W data. - * Inputs: - * red_row, green_row, blue_row: Given RGB pixel data. - * rowlen: Number of pixels in the rows. - * Outputs: - * bw_row: Output B&W data. May coincide with one of the - * inputs. - * Assumptions: - * [None] - * Algorithm: - * BW = .30*R + .59*G + .11*B - */ -void -rgb_to_bw( red_row, green_row, blue_row, bw_row, rowlen ) -rle_pixel *red_row; -rle_pixel *green_row; -rle_pixel *blue_row; -rle_pixel *bw_row; -int rowlen; -{ - register int x, bw; - - for (x=0; x<rowlen; x++) - { - /* 68000 won't store float > 127 into byte? */ - /* HP compiler blows it */ - bw = 0.5 + .30*red_row[x] + .59*green_row[x] + .11*blue_row[x]; - bw_row[x] = bw; - } -} - -#ifdef LOCC -/*ARGSUSED*/ -locc( p, l, c ) -register char *p; -register int l; -register int c; -{ - asm( "locc r9,r10,(r11)" ); -#ifdef lint - c = (int) p; /* why doesn't ARGSUSED work? */ - l = c; - return l; /* Needs return value, at least */ -#endif -} - -/*ARGSUSED*/ -skpc( p, l, c ) -register char *p; -register int l; -register int c; -{ - asm( "skpc r9,r10,(r11)" ); -#ifdef lint - c = (int) p; /* why doesn't ARGSUSED work? */ - l = c; - return l; /* Needs return value, at least */ -#endif -} -#endif diff --git a/urt/rle_row_alc.c b/urt/rle_row_alc.c index 982e1c5e..d7631744 100644 --- a/urt/rle_row_alc.c +++ b/urt/rle_row_alc.c @@ -1,14 +1,14 @@ /* * This software is copyrighted as noted below. It may be freely copied, - * modified, and redistributed, provided that the copyright notice is + * modified, and redistributed, provided that the copyright notice is * preserved on all copies. - * + * * There is no warranty or other guarantee of fitness for this software, * it is provided solely "as is". Bug reports or fixes may be sent * to the author, who may or may not act on them as he desires. * * You may not include this software in a program or other software product - * without supplying the source, or without informing the end-user that the + * without supplying the source, or without informing the end-user that the * source is available for no extra charge. * * If you modify this software, you should include a notice giving the @@ -18,13 +18,13 @@ * Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire * to have all "void" functions so declared. */ -/* +/* * rle_row_alc.c - Allocate buffers for rle_getrow/rle_putrow. - * - * Author: Spencer W. Thomas - * Computer Science Dept. - * University of Utah - * Date: Fri Nov 14 1986 + * + * Author: Spencer W. Thomas + * Computer Science Dept. + * University of Utah + * Date: Fri Nov 14 1986 * Copyright (c) 1986, Spencer W. Thomas */ @@ -35,24 +35,24 @@ /***************************************************************** * TAG( rle_row_alloc ) - * + * * Allocate buffer space for use by rle_getrow and rle_putrow. * Inputs: - * the_hdr: Header structure for RLE file to be read or - * written. + * the_hdr: Header structure for RLE file to be read or + * written. * Outputs: - * scanp: Pointer to pointer to created scanline buffer. - * This pointer is adjusted for the alpha channel, - * if present. - * Returns 0 for success, -1 if malloc failed. + * scanp: Pointer to pointer to created scanline buffer. + * This pointer is adjusted for the alpha channel, + * if present. + * Returns 0 for success, -1 if malloc failed. * Assumptions: - * No input scanline will extend beyond the declared xmax endpoint. + * No input scanline will extend beyond the declared xmax endpoint. * Algorithm: - * Count number of channels actually used (check bitmap). - * Allocate nchan*rowlength pixels, allocate a buffer - * to hold ncolors+alpha pointers, and give each channel - * rowlength pixels. Rowlength is xmax + 1, to allow for rle_getrow - * usage. + * Count number of channels actually used (check bitmap). + * Allocate nchan*rowlength pixels, allocate a buffer + * to hold ncolors+alpha pointers, and give each channel + * rowlength pixels. Rowlength is xmax + 1, to allow for rle_getrow + * usage. */ int rle_row_alloc( the_hdr, scanp ) @@ -64,33 +64,33 @@ rle_pixel ***scanp; rowlen = the_hdr->xmax + 1; if ( the_hdr->alpha && RLE_BIT( *the_hdr, RLE_ALPHA ) ) - nchan++; + nchan++; for ( i = 0; i < the_hdr->ncolors; i++ ) - if ( RLE_BIT( *the_hdr, i ) ) - nchan++; + if ( RLE_BIT( *the_hdr, i ) ) + nchan++; ncol = the_hdr->ncolors + the_hdr->alpha; if ( (scanbuf = (rle_pixel **)malloc( ncol * sizeof(rle_pixel *) )) == 0 ) - return -1; + return -1; if ( (pixbuf = (rle_pixel *)malloc( nchan * rowlen * - sizeof(rle_pixel) )) == 0 ) + sizeof(rle_pixel) )) == 0 ) { - free( scanbuf ); - return -1; + free( scanbuf ); + return -1; } if ( the_hdr->alpha ) - scanbuf++; + scanbuf++; for ( i = -the_hdr->alpha; i < the_hdr->ncolors; i++ ) - if ( RLE_BIT( *the_hdr, i ) ) - { - scanbuf[i] = pixbuf; - pixbuf += rowlen; - } - else - scanbuf[i] = 0; + if ( RLE_BIT( *the_hdr, i ) ) + { + scanbuf[i] = pixbuf; + pixbuf += rowlen; + } + else + scanbuf[i] = 0; *scanp = scanbuf; return 0; @@ -99,18 +99,18 @@ rle_pixel ***scanp; /***************************************************************** * TAG( rle_row_free ) - * + * * Free storage allocated by rle_row_alloc(). * Inputs: - * the_hdr: Header structure as above. - * scanp: Pointer to scanbuf above. + * the_hdr: Header structure as above. + * scanp: Pointer to scanbuf above. * Outputs: - * Frees storage referenced by scanp and nrawp. + * Frees storage referenced by scanp and nrawp. * Assumptions: - * Storage was allocated by rle_row_alloc, or by use of same - * algorithm, at least. + * Storage was allocated by rle_row_alloc, or by use of same + * algorithm, at least. * Algorithm: - * free scanp[0] and scanp. + * free scanp[0] and scanp. */ void rle_row_free( the_hdr, scanp ) @@ -120,12 +120,12 @@ rle_pixel **scanp; int i; if ( the_hdr->alpha ) - scanp--; + scanp--; for ( i = 0; i < the_hdr->ncolors + the_hdr->alpha; i++ ) - if ( scanp[i] != 0 ) - { - free( (char *)scanp[i] ); - break; - } + if ( scanp[i] != 0 ) + { + free( (char *)scanp[i] ); + break; + } free( (char *)scanp ); } diff --git a/urt/vaxshort.c b/urt/vaxshort.c index 9a83cecb..c39e78ec 100644 --- a/urt/vaxshort.c +++ b/urt/vaxshort.c @@ -1,5 +1,5 @@ /* - * V A X S H O R T + * V A X S H O R T * * Code to manipulate 16-bit integers in VAX order in a * machine independent manner. @@ -7,21 +7,21 @@ * (VAX is a trademark of Digital Equipment Corporation) * * Author - - * Michael John Muuss + * Michael John Muuss * * Source - - * SECAD/VLD Computing Consortium, Bldg 394 - * The U. S. Army Ballistic Research Laboratory - * Aberdeen Proving Ground, Maryland 21005-5066 + * SECAD/VLD Computing Consortium, Bldg 394 + * The U. S. Army Ballistic Research Laboratory + * Aberdeen Proving Ground, Maryland 21005-5066 * * Distribution Status - - * Public Domain, Distribution Unlimited. + * Public Domain, Distribution Unlimited. */ #include "vaxshort.h" /* - * V A X _ G S H O R T + * V A X _ G S H O R T * * Obtain a 16-bit signed integer from two adjacent characters, * stored in VAX order, regardless of word alignment. @@ -29,24 +29,24 @@ int vax_gshort(char *msgp) { - register unsigned char *p = (unsigned char *) msgp; - register int i; + unsigned char *p = (unsigned char *) msgp; + int i; - if( (i = (p[1] << 8) | p[0]) & 0x8000 ) - return(i | ~0xFFFF); /* Sign extend */ - return(i); + if( (i = (p[1] << 8) | p[0]) & 0x8000 ) + return(i | ~0xFFFF); /* Sign extend */ + return(i); } /* - * V A X _ P S H O R T + * V A X _ P S H O R T */ char * vax_pshort(char *msgp, unsigned short s) { - msgp[0] = s & 0xFF; - msgp[1] = s >> 8; - return(msgp+2); + msgp[0] = s & 0xFF; + msgp[1] = s >> 8; + return(msgp+2); } |