From 03dbb73eec19f2a8874cd9aab327ed6bc6f97867 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 15 Oct 2023 19:28:42 +0000 Subject: cleanup git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4758 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- urt/Runput.c | 333 ++++++++++++++++++++++++++++++------------------------- urt/Runput.h | 32 ++++-- urt/rle.h | 2 +- urt/rle_code.h | 23 ++-- urt/rle_getrow.c | 203 ++++++++++++++++----------------- urt/rle_put.h | 8 +- urt/vaxshort.c | 28 ++--- urt/vaxshort.h | 6 +- 8 files changed, 344 insertions(+), 291 deletions(-) diff --git a/urt/Runput.c b/urt/Runput.c index e9f2a6b8..83250814 100644 --- a/urt/Runput.c +++ b/urt/Runput.c @@ -90,14 +90,18 @@ * follow the last byte in the run. */ -#include -#include +#include +#include +#include -#include "rle_put.h" -#include "rle.h" -#include "rle_code.h" -#include "vaxshort.h" -#include "Runput.h" +#include "mallocvar.h" +#include "pm.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 */ @@ -105,7 +109,7 @@ * 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 */ \ @@ -119,8 +123,8 @@ putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), put16(a1) #define mk_long_2(oper,a1,a2) /* two argument long */ \ - putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), \ - put16(a1), put16(a2) + 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 */ @@ -159,214 +163,245 @@ #define REOF mk_inst_1(REOFOp,0) /* Really opcode only */ -/***************************************************************** - * TAG( RunSetup ) - * Put out initial setup data for RLE files. - */ + void -RunSetup(rle_hdr * the_hdr) -{ +RunSetup(rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Put out initial setup data for RLE files. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + struct XtndRsetup setup; - FILE * rle_fd = the_hdr->rle_file; - put16( RLE_MAGIC ); + put16(RLE_MAGIC); - if ( the_hdr->background == 2 ) + if (hdrP->background == 2) setup.h_flags = H_CLEARFIRST; - else if ( the_hdr->background == 0 ) + else if (hdrP->background == 0) setup.h_flags = H_NO_BACKGROUND; else setup.h_flags = 0; - if ( the_hdr->alpha ) + + if (hdrP->alpha) setup.h_flags |= H_ALPHA; - if ( the_hdr->comments != NULL && *the_hdr->comments != NULL ) + + if (hdrP->comments != NULL && *hdrP->comments != NULL) setup.h_flags |= H_COMMENT; - setup.h_ncolors = the_hdr->ncolors; + if (hdrP->ncolors > 255) + pm_error("Too many colors (%u) for RLE format. Maximum is 255", + hdrP->ncolors); + + setup.h_ncolors = (unsigned char)hdrP->ncolors; setup.h_pixelbits = 8; /* Grinnell dependent */ - if ( the_hdr->ncmap > 0 && the_hdr->cmap == NULL ) - { - 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; + + if ((hdrP->cmaplen) > sizeof(UINT_MAX) * 8 - 1) { + pm_error("Color map size logarithm (%u) " + "is too large for computation. Maximum is %lu", + hdrP->cmaplen, sizeof(UINT_MAX) * 8 - 2); + } + /* We need to be able to count 2 bytes for each channel of each entry + in the color map: + */ + if (1 << hdrP->cmaplen > UINT_MAX/2/hdrP->ncmap) { + pm_error("Color map length %u and number of color channels in the " + "color map %u are too large for computation", + 1 << hdrP->cmaplen, hdrP->ncmap); } - 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); - vax_pshort(setup.hc_ylen,the_hdr->ymax - the_hdr->ymin + 1); + + if (hdrP->ncmap > 255) + pm_error("Too many color channels in the color map (%u) " + "for the RLE format. Maximum is 255", hdrP->ncmap); + setup.h_ncmap = hdrP->ncmap; /* no of color channels */ + + if (hdrP->ncmap > 0 && hdrP->cmap == NULL) { + pm_message("Warning: " + "Color map of size %d*%d specified, but not supplied, " + "writing '%s'", + hdrP->ncmap, (1 << hdrP->cmaplen), hdrP->file_name); + hdrP->ncmap = 0; + } + setup.h_cmaplen = (unsigned char)hdrP->cmaplen; + + vax_pshort(setup.hc_xpos,hdrP->xmin); + vax_pshort(setup.hc_ypos,hdrP->ymin); + vax_pshort(setup.hc_xlen,hdrP->xmax - hdrP->xmin + 1); + vax_pshort(setup.hc_ylen,hdrP->ymax - hdrP->ymin + 1); + fwrite((char *)&setup, SETUPSIZE, 1, rle_fd); - if ( the_hdr->background != 0 ) - { - 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++ ) + + if (hdrP->background != 0) { + unsigned int i; + rle_pixel * background; + int * bg_color; + + assert(hdrP->ncolors < UINT_MAX); + + MALLOCARRAY_NOFAIL(background, hdrP->ncolors + 1); + + /* If even number of bg color bytes, put out one more to get to + 16 bit boundary. + */ + + for (i = 0, bg_color = hdrP->bg_color; i < hdrP->ncolors; ++i) background[i] = *bg_color++; - /* Extra byte, if written, should be 0. */ + + /* 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 ); - if (the_hdr->ncmap > 0) - { + + fwrite(background, (hdrP->ncolors / 2) * 2 + 1, 1, rle_fd); + + free(background); + } else + putc('\0', rle_fd); + + if (hdrP->ncmap > 0) { /* 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 ); + unsigned int const nmap = (1 << hdrP->cmaplen) * hdrP->ncmap; + + unsigned char * h_cmap; + unsigned int i; + + MALLOCARRAY(h_cmap, nmap * 2); + + if (!h_cmap) { + pm_error("Failed to allocate memory for color map of size %u, " + "writing '%s'", + nmap, hdrP->file_name); } - for ( i = 0; i < nmap; i++ ) - vax_pshort( &h_cmap[i*2], the_hdr->cmap[i] ); + for (i = 0; i < nmap; ++i) + vax_pshort(&h_cmap[i*2], hdrP->cmap[i]); + + fwrite(h_cmap, nmap, 2, rle_fd); - fwrite( h_cmap, nmap, 2, rle_fd ); - free( h_cmap ); + free(h_cmap); } /* Now write out comments if given */ - if ( setup.h_flags & H_COMMENT ) - { - int comlen; - CONST_DECL char ** com_p; + if (setup.h_flags & H_COMMENT) { + unsigned int comlen; + const char ** comP; /* Get the total length of comments */ - comlen = 0; - for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ ) - comlen += 1 + strlen( *com_p ); + for (comP = hdrP->comments, comlen = 0; *comP != NULL; ++comP) + comlen += 1 + strlen(*comP); + + put16(comlen); - put16( comlen ); - for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ ) - fwrite( *com_p, 1, strlen( *com_p ) + 1, rle_fd ); + for (comP = hdrP->comments; *comP != NULL; ++comP) + fwrite(*comP, 1, strlen(*comP) + 1, rle_fd); - if ( comlen & 1 ) /* if odd length, round up */ - putc( '\0', rle_fd ); + if (comlen & 0x1) /* if odd length, round up */ + putc('\0', rle_fd); } } -/***************************************************************** - * TAG( RunSkipBlankLines ) - * Skip one or more blank lines in the RLE file. - */ void -RunSkipBlankLines(int nblank, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; +RunSkipBlankLines(unsigned int const nblank, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Skip one or more blank lines in the RLE file. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + RSkipLines(nblank); } -/***************************************************************** - * TAG( RunSetColor ) - * Select a color and do carriage return. - * color: 0 = Red, 1 = Green, 2 = Blue. - */ void -RunSetColor(int c, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; +RunSetColor(int const c, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Select a color and do carriage return. + color: 0 = Red, 1 = Green, 2 = Blue. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + RSetColor(c); } -/***************************************************************** - * TAG( RunSkipPixels ) - * Skip a run of background. - */ - -/* ARGSUSED */ void -RunSkipPixels(int nskip, int last, int wasrun, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; - if (! last && nskip > 0) - { +RunSkipPixels(unsigned int const nskip, + int const last, + int const wasrun, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Skip a run of background. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + + if (!last && nskip > 0) { RSkipPixels(nskip); } } -/***************************************************************** - * TAG( RunNewScanLine ) - * Perform a newline action. Since CR is implied by the Set Color - * operation, only generate code if the newline flag is true. - */ void -RunNewScanLine(int flag, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; - if (flag) - { +RunNewScanLine(int const flag, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Perform a newline action. Since CR is implied by the Set Color operation, + only generate code if the newline flag is true. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + + if (flag) { RNewLine; } } -/***************************************************************** - * TAG( Runputdata ) - * Put one or more pixels of byte data into the output file. - */ void -Runputdata(rle_pixel * buf, int n, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; - if (n == 0) - return; - - RByteData(n-1); - fwrite((char *)buf, n, 1, rle_fd); - if ( n & 1 ) - putc( 0, rle_fd ); -} +Runputdata(rle_pixel * const buf, + unsigned int const n, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Put one or more pixels of byte data into the output file. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + if (n != 0) { + RByteData(n - 1); + + fwrite(buf, n, 1, rle_fd); + + if (n & 0x1) + putc(0, rle_fd); + } +} -/***************************************************************** - * TAG( Runputrun ) - * Output a single color run. - */ -/* ARGSUSED */ void -Runputrun(int color, int n, int last, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; - RRunData(n-1,color); +Runputrun(int const color, + unsigned int const n, + int const last, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Output a single color run. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + + RRunData(n - 1, color); } -/***************************************************************** - * TAG( RunputEof ) - * Output an EOF opcode - */ void -RunputEof(rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; +RunputEof(rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Output an EOF opcode +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + REOF; } - diff --git a/urt/Runput.h b/urt/Runput.h index 1d22a971..57a45564 100644 --- a/urt/Runput.h +++ b/urt/Runput.h @@ -1,23 +1,39 @@ +#ifndef RUNPUT_H_INCLUDED +#define RUNPUT_H_INCLUDED + void -RunSetup(rle_hdr * the_hdr); +RunSetup(rle_hdr * const hdrP); void -RunSkipBlankLines(int nblank, rle_hdr * the_hdr); +RunSkipBlankLines(unsigned int const nblank, + rle_hdr * const hdrP); void -RunSetColor(int c, rle_hdr * the_hdr); +RunSetColor(int const c, + rle_hdr * const hdrP); void -RunSkipPixels(int nskip, int last, int wasrun, rle_hdr * the_hdr); +RunSkipPixels(unsigned int const nskip, + int const last, + int const wasrun, + rle_hdr * const hdrP); void -RunNewScanLine(int flag, rle_hdr * the_hdr); +RunNewScanLine(int const flag, + rle_hdr * const hdrP); void -Runputdata(rle_pixel * buf, int n, rle_hdr * the_hdr); +Runputdata(rle_pixel * const buf, + unsigned int const n, + rle_hdr * const hdrP); void -Runputrun(int color, int n, int last, rle_hdr * the_hdr); +Runputrun(int const color, + unsigned int const n, + int const last, + rle_hdr * const hdrP); void -RunputEof(rle_hdr * the_hdr); +RunputEof(rle_hdr * const hdrP); + +#endif diff --git a/urt/rle.h b/urt/rle.h index 1e7ddd0c..b3263049 100644 --- a/urt/rle.h +++ b/urt/rle.h @@ -80,7 +80,7 @@ typedef #endif struct rle_hdr { enum rle_dispatch dispatch; /* Type of file to create. */ - int ncolors; /* Number of color channels. */ + unsigned int ncolors; /* Number of color channels. */ int * bg_color; /* Pointer to bg color vector. */ int alpha; /* If !0, save alpha channel. */ int background; /* 0->just save all pixels, */ diff --git a/urt/rle_code.h b/urt/rle_code.h index 493cdc02..525066d4 100644 --- a/urt/rle_code.h +++ b/urt/rle_code.h @@ -46,17 +46,18 @@ #define H_ALPHA 0x4 /* if set, alpha channel (-1) present */ #define H_COMMENT 0x8 /* if set, comments present */ -struct XtndRsetup -{ - char hc_xpos[2], - hc_ypos[2], - hc_xlen[2], - hc_ylen[2]; - char h_flags, - h_ncolors, - h_pixelbits, - h_ncmap, - h_cmaplen; +struct XtndRsetup { + /* This maps the layout of the header text in the file */ + + unsigned char hc_xpos[2]; + unsigned char hc_ypos[2]; + unsigned char hc_xlen[2]; + unsigned char hc_ylen[2]; + unsigned char h_flags; + unsigned char h_ncolors; + unsigned char h_pixelbits; + unsigned char h_ncmap; + unsigned char h_cmaplen; /* log2 of color map size */ }; #define SETUPSIZE ((4*2)+5) diff --git a/urt/rle_getrow.c b/urt/rle_getrow.c index a24870ac..5d71cda7 100644 --- a/urt/rle_getrow.c +++ b/urt/rle_getrow.c @@ -53,13 +53,13 @@ static int debug_f; /* If non-zero, print debug info. */ int -rle_get_setup(rle_hdr * const the_hdr) { +rle_get_setup(rle_hdr * const hdrP) { /*----------------------------------------------------------------------------- Read the initialization information from an RLE file. Inputs: - the_hdr: Contains pointer to the input file. + hdrP: Contains pointer to the input file. Outputs: - the_hdr: Initialized with information from the input file. + hdrP: Initialized with information from the input file. Returns 0 on success, -1 if the file is not an RLE file, @@ -70,19 +70,19 @@ rle_get_setup(rle_hdr * const the_hdr) { infile points to the "magic" number in an RLE file (usually byte 0 in the file). Algorithm: - Read in the setup info and fill in the_hdr. + Read in the setup info and fill in *hdrP. ---------------------------------------------------------------------------- */ struct XtndRsetup setup; short magic; - FILE * infile = the_hdr->rle_file; + FILE * infile = hdrP->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) - rle_names(the_hdr, "Urt", "some file", 0); - ++the_hdr->img_num; /* Count images. */ + rle_hdr_clear(hdrP); + if (hdrP->is_init != RLE_INIT_MAGIC) + rle_names(hdrP, "Urt", "some file", 0); + ++hdrP->img_num; /* Count images. */ VAXSHORT(magic, infile); if (feof(infile)) @@ -94,15 +94,15 @@ rle_get_setup(rle_hdr * const the_hdr) { return RLE_EOF; /* Extract information from setup */ - the_hdr->ncolors = setup.h_ncolors; - for (i = 0; i < the_hdr->ncolors; ++i) - RLE_SET_BIT(*the_hdr, i); + hdrP->ncolors = setup.h_ncolors; + for (i = 0; i < hdrP->ncolors; ++i) + RLE_SET_BIT(*hdrP, i); if (!(setup.h_flags & H_NO_BACKGROUND) && setup.h_ncolors > 0) { rle_pixel * bg_color; - MALLOCARRAY(the_hdr->bg_color, setup.h_ncolors); - if (!the_hdr->bg_color) + MALLOCARRAY(hdrP->bg_color, setup.h_ncolors); + if (!hdrP->bg_color) pm_error("Failed to allocation array for %u background colors", setup.h_ncolors); MALLOCARRAY(bg_color, 1 + (setup.h_ncolors / 2) * 2); @@ -111,50 +111,51 @@ rle_get_setup(rle_hdr * const the_hdr) { 1+(setup.h_ncolors / 2) * 2); fread((char *)bg_color, 1, 1 + (setup.h_ncolors / 2) * 2, infile); for (i = 0; i < setup.h_ncolors; ++i) - the_hdr->bg_color[i] = bg_color[i]; + hdrP->bg_color[i] = bg_color[i]; free(bg_color); } else { getc(infile); /* skip filler byte */ - the_hdr->bg_color = NULL; + hdrP->bg_color = NULL; } if (setup.h_flags & H_NO_BACKGROUND) - the_hdr->background = 0; + hdrP->background = 0; else if (setup.h_flags & H_CLEARFIRST) - the_hdr->background = 2; + hdrP->background = 2; else - the_hdr->background = 1; + hdrP->background = 1; if (setup.h_flags & H_ALPHA) { - the_hdr->alpha = 1; - RLE_SET_BIT( *the_hdr, RLE_ALPHA ); + hdrP->alpha = 1; + RLE_SET_BIT( *hdrP, RLE_ALPHA ); } else - the_hdr->alpha = 0; + hdrP->alpha = 0; - the_hdr->xmin = vax_gshort(setup.hc_xpos); - the_hdr->ymin = vax_gshort(setup.hc_ypos); - the_hdr->xmax = the_hdr->xmin + vax_gshort(setup.hc_xlen) - 1; - the_hdr->ymax = the_hdr->ymin + vax_gshort(setup.hc_ylen) - 1; + hdrP->xmin = vax_gshort(setup.hc_xpos); + hdrP->ymin = vax_gshort(setup.hc_ypos); + hdrP->xmax = hdrP->xmin + vax_gshort(setup.hc_xlen) - 1; + hdrP->ymax = hdrP->ymin + vax_gshort(setup.hc_ylen) - 1; - the_hdr->ncmap = setup.h_ncmap; - the_hdr->cmaplen = setup.h_cmaplen; - if (the_hdr->ncmap > 0) { - int const maplen = the_hdr->ncmap * (1 << the_hdr->cmaplen); + hdrP->ncmap = setup.h_ncmap; + hdrP->cmaplen = setup.h_cmaplen; - int i; - char *maptemp; + if (hdrP->ncmap > 0) { + int const maplen = hdrP->ncmap * (1 << hdrP->cmaplen); - MALLOCARRAY(the_hdr->cmap, maplen); + unsigned int i; + unsigned char *maptemp; + + MALLOCARRAY(hdrP->cmap, maplen); MALLOCARRAY(maptemp, 2 * maplen); - if (the_hdr->cmap == NULL || maptemp == NULL) { + if (hdrP->cmap == NULL || maptemp == NULL) { pm_error("Malloc failed for color map of size %d*%d " "in rle_get_setup, reading '%s'", - the_hdr->ncmap, (1 << the_hdr->cmaplen), - the_hdr->file_name ); + hdrP->ncmap, (1 << hdrP->cmaplen), + hdrP->file_name ); return RLE_NO_SPACE; } fread(maptemp, 2, maplen, infile); for (i = 0; i < maplen; ++i) - the_hdr->cmap[i] = vax_gshort(&maptemp[i * 2]); + hdrP->cmap[i] = vax_gshort(&maptemp[i * 2]); free(maptemp); } @@ -171,7 +172,7 @@ rle_get_setup(rle_hdr * const the_hdr) { if (comment_buf == NULL) { pm_error("Malloc failed for comment buffer of size %d " "in rle_get_setup, reading '%s'", - comlen, the_hdr->file_name ); + comlen, hdrP->file_name ); return RLE_NO_SPACE; } fread(comment_buf, 1, evenlen, infile); @@ -181,37 +182,37 @@ rle_get_setup(rle_hdr * const the_hdr) { ++i; ++i; /* extra for NULL pointer at end */ /* Get space to put pointers to comments */ - MALLOCARRAY(the_hdr->comments, i); - if (the_hdr->comments == NULL) { + MALLOCARRAY(hdrP->comments, i); + if (hdrP->comments == NULL) { pm_error("Malloc failed for %d comment pointers " "in rle_get_setup, reading '%s'", - i, the_hdr->file_name ); + i, hdrP->file_name ); return RLE_NO_SPACE; } /* Get pointers to the comments */ - *the_hdr->comments = comment_buf; + *hdrP->comments = comment_buf; for (i = 1, cp = comment_buf + 1; cp < comment_buf + comlen; ++cp) if (*(cp - 1) == '\0') - the_hdr->comments[i++] = cp; - the_hdr->comments[i] = NULL; + hdrP->comments[i++] = cp; + hdrP->comments[i] = NULL; } else - the_hdr->comments = NULL; + hdrP->comments = NULL; } else - the_hdr->comments = NULL; + hdrP->comments = NULL; /* Initialize state for rle_getrow */ - the_hdr->priv.get.scan_y = the_hdr->ymin; - the_hdr->priv.get.vert_skip = 0; - the_hdr->priv.get.is_eof = 0; - the_hdr->priv.get.is_seek = ftell(infile) > 0; + hdrP->priv.get.scan_y = hdrP->ymin; + hdrP->priv.get.vert_skip = 0; + hdrP->priv.get.is_eof = 0; + hdrP->priv.get.is_seek = ftell(infile) > 0; debug_f = 0; if (!feof(infile)) return RLE_SUCCESS; /* success! */ else { - the_hdr->priv.get.is_eof = 1; + hdrP->priv.get.is_eof = 1; return RLE_EOF; } } @@ -219,24 +220,24 @@ rle_get_setup(rle_hdr * const the_hdr) { int -rle_getrow(rle_hdr * const the_hdr, +rle_getrow(rle_hdr * const hdrP, rle_pixel ** const scanline) { /*----------------------------------------------------------------------------- Get a scanline from the input file. Inputs: - the_hdr: Header structure containing information about + hdrP: Header structure containing information about the input file. Outputs: scanline: an array of pointers to the individual color scanlines. Scanline is assumed to have - the_hdr->ncolors pointers to arrays of rle_pixel, - each of which is at least the_hdr->xmax+1 long. + hdrP->ncolors pointers to arrays of rle_pixel, + each of which is at least hdrP->xmax+1 long. Returns the current scanline number. Assumptions: rle_get_setup has already been called. Algorithm: If a vertical skip is being executed, and clear-to-background is - specified (the_hdr->background is true), just set the + specified (hdrP->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. @@ -246,7 +247,7 @@ rle_getrow(rle_hdr * const the_hdr, If ymax is reached (or, somehow, passed), continue reading and discarding input until end of image. ---------------------------------------------------------------------------- */ - FILE * const infile = the_hdr->rle_file; + FILE * const infile = hdrP->rle_file; rle_pixel * scanc; @@ -258,51 +259,51 @@ rle_getrow(rle_hdr * const the_hdr, short word, long_data; char inst[2]; - scan_x = the_hdr->xmin; /* initial value */ - max_x = the_hdr->xmax; /* initial value */ + scan_x = hdrP->xmin; /* initial value */ + max_x = hdrP->xmax; /* initial value */ channel = 0; /* initial value */ /* Clear to background if specified */ - if (the_hdr->background != 1) { - if (the_hdr->alpha && RLE_BIT( *the_hdr, -1)) - memset((char *)scanline[-1] + the_hdr->xmin, 0, - the_hdr->xmax - the_hdr->xmin + 1); - for (nc = 0; nc < the_hdr->ncolors; ++nc) { - if (RLE_BIT( *the_hdr, nc)) { + if (hdrP->background != 1) { + if (hdrP->alpha && RLE_BIT( *hdrP, -1)) + memset((char *)scanline[-1] + hdrP->xmin, 0, + hdrP->xmax - hdrP->xmin + 1); + for (nc = 0; nc < hdrP->ncolors; ++nc) { + if (RLE_BIT( *hdrP, nc)) { /* Unless bg color given explicitly, use 0. */ - if (the_hdr->background != 2 || the_hdr->bg_color[nc] == 0) - memset((char *)scanline[nc] + the_hdr->xmin, 0, - the_hdr->xmax - the_hdr->xmin + 1); + if (hdrP->background != 2 || hdrP->bg_color[nc] == 0) + memset((char *)scanline[nc] + hdrP->xmin, 0, + hdrP->xmax - hdrP->xmin + 1); else - memset((char *)scanline[nc] + the_hdr->xmin, - the_hdr->bg_color[nc], - the_hdr->xmax - the_hdr->xmin + 1); + memset((char *)scanline[nc] + hdrP->xmin, + hdrP->bg_color[nc], + hdrP->xmax - hdrP->xmin + 1); } } } /* If skipping, then just return */ - if (the_hdr->priv.get.vert_skip > 0) { - --the_hdr->priv.get.vert_skip; - ++the_hdr->priv.get.scan_y; - if (the_hdr->priv.get.vert_skip > 0) { - if (the_hdr->priv.get.scan_y >= the_hdr->ymax) { - int const y = the_hdr->priv.get.scan_y; - while (rle_getskip(the_hdr) != 32768) + if (hdrP->priv.get.vert_skip > 0) { + --hdrP->priv.get.vert_skip; + ++hdrP->priv.get.scan_y; + if (hdrP->priv.get.vert_skip > 0) { + if (hdrP->priv.get.scan_y >= hdrP->ymax) { + int const y = hdrP->priv.get.scan_y; + while (rle_getskip(hdrP) != 32768) ; return y; } else - return the_hdr->priv.get.scan_y; + return hdrP->priv.get.scan_y; } } /* If EOF has been encountered, return also */ - if (the_hdr->priv.get.is_eof) - return ++the_hdr->priv.get.scan_y; + if (hdrP->priv.get.is_eof) + return ++hdrP->priv.get.scan_y; /* Otherwise, read and interpret instructions until a skipLines instruction is encountered. */ - if (RLE_BIT(*the_hdr, channel)) + if (RLE_BIT(*hdrP, channel)) scanc = scanline[channel] + scan_x; else scanc = NULL; @@ -310,21 +311,21 @@ rle_getrow(rle_hdr * const the_hdr, inst[0] = getc(infile); inst[1] = getc(infile); if (feof(infile)) { - the_hdr->priv.get.is_eof = 1; + hdrP->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); + VAXSHORT(hdrP->priv.get.vert_skip, infile); } else - the_hdr->priv.get.vert_skip = DATUM(inst); + hdrP->priv.get.vert_skip = DATUM(inst); if (debug_f) pm_message("Skip %d Lines (to %d)", - the_hdr->priv.get.vert_skip, - the_hdr->priv.get.scan_y + - the_hdr->priv.get.vert_skip); + hdrP->priv.get.vert_skip, + hdrP->priv.get.scan_y + + hdrP->priv.get.vert_skip); break; /* need to break for() here, too */ @@ -332,8 +333,8 @@ rle_getrow(rle_hdr * const the_hdr, channel = DATUM(inst); /* select color channel */ if (channel == 255) channel = -1; - scan_x = the_hdr->xmin; - if (RLE_BIT(*the_hdr, channel)) + scan_x = hdrP->xmin; + if (RLE_BIT(*hdrP, channel)) scanc = scanline[channel]+scan_x; if (debug_f) pm_message("Set color to %d (reset x to %d)", @@ -362,12 +363,12 @@ rle_getrow(rle_hdr * const the_hdr, nc = DATUM(inst); ++nc; if (debug_f) { - if (RLE_BIT(*the_hdr, channel)) + if (RLE_BIT(*hdrP, channel)) pm_message("Pixel data %d (to %d):", nc, scan_x + nc); else pm_message("Pixel data %d (to %d)", nc, scan_x + nc); } - if (RLE_BIT(*the_hdr, channel)) { + if (RLE_BIT(*hdrP, channel)) { /* Don't fill past end of scanline! */ if (scan_x + nc > max_x) { ns = scan_x + nc - max_x - 1; @@ -380,7 +381,7 @@ rle_getrow(rle_hdr * const the_hdr, if (nc & 0x1) getc(infile); /* throw away odd byte */ } else { - if (the_hdr->priv.get.is_seek) + if (hdrP->priv.get.is_seek) fseek(infile, ((nc + 1) / 2) * 2, 1); else { int ii; @@ -390,7 +391,7 @@ rle_getrow(rle_hdr * const the_hdr, } scanc += nc; scan_x += nc; - if (debug_f && RLE_BIT(*the_hdr, channel)) { + if (debug_f && RLE_BIT(*hdrP, channel)) { rle_pixel * cp; for (cp = scanc - nc; nc > 0; --nc) fprintf(stderr, "%02x", *cp++); @@ -410,7 +411,7 @@ rle_getrow(rle_hdr * const the_hdr, if (debug_f) pm_message("Run length %d (to %d), data %02x", nc, scan_x, word); - if (RLE_BIT(*the_hdr, channel)) { + if (RLE_BIT(*hdrP, channel)) { if (scan_x > max_x) { ns = scan_x - max_x - 1; nc -= ns; @@ -427,28 +428,28 @@ rle_getrow(rle_hdr * const the_hdr, break; case REOFOp: - the_hdr->priv.get.is_eof = 1; + hdrP->priv.get.is_eof = 1; if (debug_f) pm_message("End of Image"); break; default: pm_error("rle_getrow: Unrecognized opcode: %d, reading %s", - inst[0], the_hdr->file_name); + inst[0], hdrP->file_name); } if (OPCODE(inst) == RSkipLinesOp || OPCODE(inst) == REOFOp) break; /* <--- the other loop exit */ } /* If at end, skip the rest of a malformed image. */ - if (the_hdr->priv.get.scan_y >= the_hdr->ymax) { - int const y = the_hdr->priv.get.scan_y; - while (rle_getskip(the_hdr) != 32768 ) + if (hdrP->priv.get.scan_y >= hdrP->ymax) { + int const y = hdrP->priv.get.scan_y; + while (rle_getskip(hdrP) != 32768 ) ; return y; } - return the_hdr->priv.get.scan_y; + return hdrP->priv.get.scan_y; } diff --git a/urt/rle_put.h b/urt/rle_put.h index bfabd617..015a15f3 100644 --- a/urt/rle_put.h +++ b/urt/rle_put.h @@ -52,13 +52,13 @@ typedef int rle_fn( ARB_ARGS ); struct rle_dispatch_tab { CONST_DECL char *magic; /* magic type flags */ void (*setup)(rle_hdr * the_hdr); /* startup function */ - void (*skipBlankLines)(int nblank, rle_hdr * the_hdr); + void (*skipBlankLines)(unsigned int nblank, rle_hdr * the_hdr); void(*setColor)(int c, rle_hdr * the_hdr); - void(*skipPixels)(int nskip, int last, int wasrun, rle_hdr * the_hdr); + void(*skipPixels)(unsigned int nskip, int last, int wasrun, rle_hdr * the_hdr); void(*newScanLine)(int flag, rle_hdr * the_hdr); - void(*putdat)(rle_pixel * buf, int n, rle_hdr * the_hdr); + void(*putdat)(rle_pixel * buf, unsigned int n, rle_hdr * the_hdr); /* put a set of differing pixels */ - void(*putrn)(int color, int n, int last, rle_hdr * the_hdr); + void(*putrn)(int color, unsigned int n, int last, rle_hdr * the_hdr); /* put a run all the same */ void (*blockHook)(rle_hdr * the_hdr); /* hook called at start of new output block */ diff --git a/urt/vaxshort.c b/urt/vaxshort.c index 182083ca..b9c8e1ce 100644 --- a/urt/vaxshort.c +++ b/urt/vaxshort.c @@ -27,14 +27,13 @@ * stored in VAX order, regardless of word alignment. */ int -vax_gshort(char *msgp) -{ - unsigned char *p = (unsigned char *) msgp; - int i; - - if( (i = (p[1] << 8) | p[0]) & 0x8000 ) - return(i | ~0xFFFF); /* Sign extend */ - return(i); +vax_gshort(unsigned char * const msgp) { + + int i; + + if ((i = (msgp[1] << 8) | msgp[0]) & 0x8000) + return i | ~0xFFFF; /* Sign extend */ + return(i); } @@ -42,13 +41,14 @@ vax_gshort(char *msgp) /* * V A X _ P S H O R T */ -char * -vax_pshort(char *msgp, unsigned short s) -{ +unsigned char * +vax_pshort(unsigned char * const msgp, + unsigned short const s) { + + msgp[0] = s & 0xFF; + msgp[1] = s >> 8; - msgp[0] = s & 0xFF; - msgp[1] = s >> 8; - return(msgp+2); + return msgp + 2; } diff --git a/urt/vaxshort.h b/urt/vaxshort.h index daeb856b..7a1d14ae 100644 --- a/urt/vaxshort.h +++ b/urt/vaxshort.h @@ -1,5 +1,5 @@ int -vax_gshort(char *msgp); +vax_gshort(unsigned char *msgp); -char * -vax_pshort(char *msgp, unsigned short s); +unsigned char * +vax_pshort(unsigned char *msgp, unsigned short s); -- cgit 1.4.1