diff options
Diffstat (limited to 'converter/ppm/picttoppm.c')
-rw-r--r-- | converter/ppm/picttoppm.c | 323 |
1 files changed, 161 insertions, 162 deletions
diff --git a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c index d91e23e2..812aaa1e 100644 --- a/converter/ppm/picttoppm.c +++ b/converter/ppm/picttoppm.c @@ -309,7 +309,7 @@ static int align = 0; static byte -read_byte(void) { +readByte(void) { int c; if ((c = fgetc(ifp)) == EOF) @@ -322,44 +322,44 @@ read_byte(void) { static word -read_word(void) { - byte b; +readWord(void) { - b = read_byte(); + byte const hi = readByte(); + byte const lo = readByte(); - return (b << 8) | read_byte(); + return (hi << 8) | (lo << 0); } -static void read_point(struct Point * const p) { - p->y = read_word(); - p->x = read_word(); +static void readPoint(struct Point * const p) { + p->y = readWord(); + p->x = readWord(); } static longword -read_long(void) { - word i; +readLong(void) { + word const hi = readWord(); + word const lo = readWord(); - i = read_word(); - return (i << 16) | read_word(); + return (hi << 16) | (lo << 0); } static signed_byte -read_signed_byte(void) { - return (signed_byte)read_byte(); +readSignedByte(void) { + return (signed_byte)readByte(); } static void -read_short_point(struct Point * const p) { - p->x = read_signed_byte(); - p->y = read_signed_byte(); +readShortPoint(struct Point * const p) { + p->x = readSignedByte(); + p->y = readSignedByte(); } @@ -470,10 +470,10 @@ picComment(word const type, case 150: if (verbose) pm_message("TextBegin"); if (length >= 6) { - ps_just = read_byte(); - ps_flip = read_byte(); - ps_rotation = read_word(); - ps_linespace = read_byte(); + ps_just = readByte(); + ps_flip = readByte(); + ps_rotation = readWord(); + ps_linespace = readByte(); remainingLength = length - 5; if (recognize_comment) ps_text = 1; @@ -506,11 +506,11 @@ picComment(word const type, if (length < 8) remainingLength = length; else { - ps_cent_y = read_word(); + ps_cent_y = readWord(); if (ps_cent_y > 32767) ps_cent_y -= 65536; skip(2); /* ignore fractional part */ - ps_cent_x = read_word(); + ps_cent_x = readWord(); if (ps_cent_x > 32767) ps_cent_x -= 65536; skip(2); /* ignore fractional part */ @@ -621,7 +621,7 @@ ShortComment(struct canvas * const canvasP, blitList * const blitListP, int const version) { - picComment(read_word(), 0); + picComment(readWord(), 0); } @@ -635,8 +635,8 @@ LongComment(struct canvas * const canvasP, word type; - type = read_word(); - picComment(type, read_word()); + type = readWord(); + picComment(type, readWord()); } @@ -649,7 +649,7 @@ skip_poly_or_region(struct canvas * const canvasP, int const version) { stage = "skipping polygon or region"; - skip(read_word() - 2); + skip(readWord() - 2); } @@ -788,12 +788,12 @@ dumpRect(const char * const label, static void -read_rect(struct Rect * const r) { +readRect(struct Rect * const r) { - r->top = read_word(); - r->left = read_word(); - r->bottom = read_word(); - r->right = read_word(); + r->top = readWord(); + r->left = readWord(); + r->bottom = readWord(); + r->right = readWord(); if (r->top > r->bottom || r->right < r->left) dumpRect("Invalid rectangle", *r); @@ -1917,37 +1917,36 @@ static word get_op(int const version) { if ((align & 1) && version == 2) { stage = "aligning for opcode"; - read_byte(); + readByte(); } stage = "reading opcode"; if (version == 1) - return read_byte(); + return readByte(); else - return read_word(); + return readWord(); } -static drawFn Clip; +static drawFn ClipRgn; static void -Clip(struct canvas * const canvasP, - blitList * const blitListP, - int const version) { - - word len; +ClipRgn(struct canvas * const canvasP, + blitList * const blitListP, + int const version) { - len = read_word(); + word const len = readWord(); + /* Length in bytes of the parameter (including this word) */ - if (len == 0x000a) { /* null rgn */ - read_rect(&clip_rect); + if (len == 10) { /* null rgn */ + /* Parameter is 2 bytes of length, 8 bytes of rectangle corners */ + readRect(&clip_rect); /* XXX should clip this by picFrame */ if (verbose) dumpRect("clipping to", clip_rect); - } - else + } else skip(len - 2); } @@ -1960,31 +1959,31 @@ OpColor(struct canvas * const canvasP, blitList * const blitListP, int const version) { - op_color.red = read_word(); - op_color.grn = read_word(); - op_color.blu = read_word(); + op_color.red = readWord(); + op_color.grn = readWord(); + op_color.blu = readWord(); } static void -read_pixmap(struct pixMap * const p) { +readPixmap(struct pixMap * const p) { stage = "getting pixMap header"; - read_rect(&p->Bounds); - p->version = read_word(); - p->packType = read_word(); - p->packSize = read_long(); - p->hRes = read_long(); - p->vRes = read_long(); - p->pixelType = read_word(); - p->pixelSize = read_word(); - p->cmpCount = read_word(); - p->cmpSize = read_word(); - p->planeBytes = read_long(); - p->pmTable = read_long(); - p->pmReserved = read_long(); + readRect(&p->Bounds); + p->version = readWord(); + p->packType = readWord(); + p->packSize = readLong(); + p->hRes = readLong(); + p->vRes = readLong(); + p->pixelType = readWord(); + p->pixelSize = readWord(); + p->cmpCount = readWord(); + p->cmpSize = readWord(); + p->planeBytes = readLong(); + p->pmTable = readLong(); + p->pmReserved = readLong(); if (verbose) { pm_message("pixelType: %d", p->pixelType); @@ -2007,7 +2006,7 @@ read_pixmap(struct pixMap * const p) { static struct RGBColor* -read_color_table(void) { +readColorTable(void) { longword ctSeed; word ctFlags; word ctSize; @@ -2017,9 +2016,9 @@ read_color_table(void) { stage = "getting color table info"; - ctSeed = read_long(); - ctFlags = read_word(); - ctSize = read_word(); + ctSeed = readLong(); + ctFlags = readWord(); + ctSize = readWord(); if (verbose) { pm_message("ctSeed: %ld", ctSeed); @@ -2034,7 +2033,7 @@ read_color_table(void) { pm_error("no memory for color table"); for (i = 0; i <= ctSize; i++) { - val = read_word(); + val = readWord(); /* The indices in a device color table are bogus and usually == 0. * so I assume we allocate up the list of colors in order. */ @@ -2042,9 +2041,9 @@ read_color_table(void) { val = i; if (val > ctSize) pm_error("pixel value greater than color table size"); - color_table[val].red = read_word(); - color_table[val].grn = read_word(); - color_table[val].blu = read_word(); + color_table[val].red = readWord(); + color_table[val].grn = readWord(); + color_table[val].blu = readWord(); if (verbose > 1) pm_message("Color %3u: [%u,%u,%u]", val, @@ -2573,9 +2572,9 @@ unpackCompressedBits(FILE * const ifP, unsigned int linelen; if (llsize == 2) - linelen = read_word(); + linelen = readWord(); else - linelen = read_byte(); + linelen = readByte(); reportValidateCompressedLineLen(row, linelen, raster.rowSize); @@ -2651,13 +2650,13 @@ interpretRowBytesWord(word const rowBytesWord, * a pattern in the fabled complete version. */ static void -read_pattern(void) { +readPattern(void) { word PatType; stage = "Reading a pattern"; - PatType = read_word(); + PatType = readWord(); switch (PatType) { case 2: @@ -2673,16 +2672,16 @@ read_pattern(void) { struct RGBColor * ct; skip(8); /* old pattern data */ - rowBytesWord = read_word(); + rowBytesWord = readWord(); interpretRowBytesWord(rowBytesWord, &pixMap, &rowBytes); - read_pixmap(&p); - ct = read_color_table(); + readPixmap(&p); + ct = readColorTable(); unpackbits(ifp, &p.Bounds, rowBytes, p.pixelSize, &raster); freeRaster(raster); free(ct); } break; default: - pm_error("unknown pattern type in read_pattern"); + pm_error("unknown pattern type in readPattern"); } } @@ -2697,7 +2696,7 @@ BkPixPat(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_pattern(); + readPattern(); } @@ -2709,7 +2708,7 @@ PnPixPat(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_pattern(); + readPattern(); } @@ -2721,13 +2720,13 @@ FillPixPat(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_pattern(); + readPattern(); } static void -read_8x8_pattern(struct Pattern * const pat) { +read8x8Pattern(struct Pattern * const pat) { unsigned char buf[8]; unsigned char * exp; unsigned int len; @@ -2756,7 +2755,7 @@ BkPat(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_8x8_pattern(&bkpat); + read8x8Pattern(&bkpat); } @@ -2768,7 +2767,7 @@ PnPat(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_8x8_pattern(&pen_pat); + read8x8Pattern(&pen_pat); } @@ -2780,7 +2779,7 @@ FillPat(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_8x8_pattern(&fillpat); + read8x8Pattern(&fillpat); } @@ -2792,8 +2791,8 @@ PnSize(struct canvas * const canvasP, blitList * const blitListP, int const version) { - pen_height = read_word(); - pen_width = read_word(); + pen_height = readWord(); + pen_width = readWord(); if (verbose) pm_message("pen size %d x %d", pen_width, pen_height); } @@ -2807,7 +2806,7 @@ PnMode(struct canvas * const canvasP, blitList * const blitListP, int const version) { - pen_mode = read_word(); + pen_mode = readWord(); if (pen_mode >= 8 && pen_mode < 15) pen_mode -= 8; @@ -2821,10 +2820,10 @@ PnMode(struct canvas * const canvasP, static void -read_rgb(struct RGBColor * const rgb) { - rgb->red = read_word(); - rgb->grn = read_word(); - rgb->blu = read_word(); +readRgb(struct RGBColor * const rgb) { + rgb->red = readWord(); + rgb->grn = readWord(); + rgb->blu = readWord(); } @@ -2836,7 +2835,7 @@ RGBFgCol(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_rgb(&foreground); + readRgb(&foreground); if (verbose) pm_message("foreground now [%d,%d,%d]", foreground.red, foreground.grn, foreground.blu); @@ -2851,7 +2850,7 @@ RGBBkCol(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_rgb(&background); + readRgb(&background); if (verbose) pm_message("background now [%d,%d,%d]", background.red, background.grn, background.blu); @@ -2869,7 +2868,7 @@ draw_pixel(struct canvas * const canvasP, transfer_func trf) { if (x < clip_rect.left || x >= clip_rect.right || - y < clip_rect.top || y >= clip_rect.bottom) { + y < clip_rect.top || y >= clip_rect.bottom) { } else { unsigned int const i = PIXEL_INDEX(x, y); @@ -3011,8 +3010,8 @@ Line(struct canvas * const canvasP, int const version) { struct Point p1; - read_point(&p1); - read_point(¤t); + readPoint(&p1); + readPoint(¤t); if (verbose) pm_message("(%d,%d) to (%d, %d)", p1.x,p1.y,current.x,current.y); @@ -3029,7 +3028,7 @@ LineFrom(struct canvas * const canvasP, int const version) { struct Point p1; - read_point(&p1); + readPoint(&p1); if (verbose) pm_message("(%d,%d) to (%d, %d)", current.x, current.y, p1.x, p1.y); @@ -3050,8 +3049,8 @@ ShortLine(struct canvas * const canvasP, int const version) { struct Point p1; - read_point(&p1); - read_short_point(¤t); + readPoint(&p1); + readShortPoint(¤t); if (verbose) pm_message("(%d,%d) delta (%d, %d)", p1.x, p1.y, current.x, current.y); current.x += p1.x; @@ -3071,7 +3070,7 @@ ShortLineFrom(struct canvas * const canvasP, int const version) { struct Point p1; - read_short_point(&p1); + readShortPoint(&p1); if (verbose) pm_message("(%d,%d) delta (%d, %d)", current.x,current.y,p1.x,p1.y); @@ -3108,7 +3107,7 @@ paintRect(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_rect(&cur_rect); + readRect(&cur_rect); if (!blitListP) do_paintRect(canvasP, cur_rect); } @@ -3159,7 +3158,7 @@ frameRect(struct canvas * const canvasP, blitList * const blitListP, int const version) { - read_rect(&cur_rect); + readRect(&cur_rect); if (!blitListP) do_frameRect(canvasP, cur_rect); } @@ -3326,11 +3325,11 @@ paintPoly(struct canvas * const canvasP, struct Rect bb; struct Point pts[100]; - int i, np = (read_word() - 10) >> 2; + int i, np = (readWord() - 10) >> 2; - read_rect(&bb); + readRect(&bb); for (i=0; i<np; ++i) - read_point(&pts[i]); + readPoint(&pts[i]); /* scan convert poly ... */ if (!blitListP) @@ -3346,7 +3345,7 @@ PnLocHFrac(struct canvas * const canvasP, blitList * const blitListP, int const version) { - word frac = read_word(); + word frac = readWord(); if (verbose) pm_message("PnLocHFrac = %d", frac); @@ -3361,7 +3360,7 @@ TxMode(struct canvas * const canvasP, blitList * const blitListP, int const version) { - text_mode = read_word(); + text_mode = readWord(); if (text_mode >= 8 && text_mode < 15) text_mode -= 8; @@ -3382,7 +3381,7 @@ TxFont(struct canvas * const canvasP, blitList * const blitListP, int const version) { - text_font = read_word(); + text_font = readWord(); if (verbose) pm_message("text font %s", const_name(font_name, text_font)); } @@ -3396,7 +3395,7 @@ TxFace(struct canvas * const canvasP, blitList * const blitListP, int const version) { - text_face = read_byte(); + text_face = readByte(); if (verbose) pm_message("text face %d", text_face); } @@ -3410,7 +3409,7 @@ TxSize(struct canvas * const canvasP, blitList * const blitListP, int const version) { - text_size = read_word(); + text_size = readWord(); if (verbose) pm_message("text size %d", text_size); } @@ -3420,7 +3419,7 @@ TxSize(struct canvas * const canvasP, static void skip_text(blitList * const blitListP) { - skip(read_byte()); + skip(readByte()); blitListP->unblittableText = true; } @@ -3520,12 +3519,12 @@ do_ps_text(struct canvas * const canvasP, ps_cent_set = 1; } - len = read_byte(); + len = readByte(); /* XXX this width calculation is not completely correct */ width = 0; for (i = 0; i < len; i++) { - ch = str[i] = read_byte(); + ch = str[i] = readByte(); if (tfont->glyph[ch]) width += tfont->glyph[ch]->xadd; } @@ -3591,8 +3590,8 @@ do_text(struct canvas * const canvasP, x = startx; y = starty; - for (len = read_byte(); len > 0; --len) { - struct glyph* const glyph = tfont->glyph[read_byte()]; + for (len = readByte(); len > 0; --len) { + struct glyph* const glyph = tfont->glyph[readByte()]; if (glyph) { int dy; int h; @@ -3628,7 +3627,7 @@ LongText(struct canvas * const canvasP, struct Point p; - read_point(&p); + readPoint(&p); do_text(canvasP, blitListP, p.x, p.y); } @@ -3642,7 +3641,7 @@ DHText(struct canvas * const canvasP, blitList * const blitListP, int const version) { - current.x += read_byte(); + current.x += readByte(); do_text(canvasP, blitListP, current.x, current.y); } @@ -3656,7 +3655,7 @@ DVText(struct canvas * const canvasP, blitList * const blitListP, int const version) { - current.y += read_byte(); + current.y += readByte(); do_text(canvasP, blitListP, current.x, current.y); } @@ -3671,8 +3670,8 @@ DHDVText(struct canvas * const canvasP, int const version) { byte dh, dv; - dh = read_byte(); - dv = read_byte(); + dh = readByte(); + dv = readByte(); if (verbose) pm_message("dh, dv = %d, %d", dh, dv); @@ -3686,7 +3685,7 @@ DHDVText(struct canvas * const canvasP, /* - * This could use read_pixmap, but I'm too lazy to hack read_pixmap. + * This could use readPixmap, but I'm too lazy to hack readPixmap. */ static void @@ -3704,31 +3703,31 @@ directBits(struct canvas * const canvasP, /* skip fake len, and fake EOF */ skip(4); /* Ptr baseAddr == 0x000000ff */ - read_word(); /* version */ - read_rect(&p.Bounds); + readWord(); /* version */ + readRect(&p.Bounds); rectWidth = p.Bounds.right - p.Bounds.left; - p.packType = read_word(); - p.packSize = read_long(); - p.hRes = read_long(); - p.vRes = read_long(); - p.pixelType = read_word(); - p.pixelSize = read_word(); - p.pixelSize = read_word(); /* XXX twice??? */ - p.cmpCount = read_word(); - p.cmpSize = read_word(); - p.planeBytes = read_long(); - p.pmTable = read_long(); - p.pmReserved = read_long(); - - read_rect(&srcRect); + p.packType = readWord(); + p.packSize = readLong(); + p.hRes = readLong(); + p.vRes = readLong(); + p.pixelType = readWord(); + p.pixelSize = readWord(); + p.pixelSize = readWord(); /* XXX twice??? */ + p.cmpCount = readWord(); + p.cmpSize = readWord(); + p.planeBytes = readLong(); + p.pmTable = readLong(); + p.pmReserved = readLong(); + + readRect(&srcRect); if (verbose) dumpRect("source rectangle:", srcRect); - read_rect(&dstRect); + readRect(&dstRect); if (verbose) dumpRect("destination rectangle:", dstRect); - mode = read_word(); + mode = readWord(); if (verbose) pm_message("transfer mode = %s", const_name(transfer_name, mode)); @@ -3788,26 +3787,26 @@ do_pixmap(struct canvas * const canvasP, struct Rect srcRect; struct Rect dstRect; - read_pixmap(&p); + readPixmap(&p); if (verbose) pm_message("%u x %u paletted image", p.Bounds.right - p.Bounds.left, p.Bounds.bottom - p.Bounds.top); - color_table = read_color_table(); + color_table = readColorTable(); - read_rect(&srcRect); + readRect(&srcRect); if (verbose) dumpRect("source rectangle:", srcRect); - read_rect(&dstRect); + readRect(&dstRect); if (verbose) dumpRect("destination rectangle:", dstRect); - mode = read_word(); + mode = readWord(); if (verbose) pm_message("transfer mode = %s", const_name(transfer_name, mode)); @@ -3851,10 +3850,10 @@ do_bitmap(FILE * const ifP, static struct RGBColor color_table[] = { {65535L, 65535L, 65535L}, {0, 0, 0} }; - read_rect(&Bounds); - read_rect(&srcRect); - read_rect(&dstRect); - mode = read_word(); + readRect(&Bounds); + readRect(&srcRect); + readRect(&dstRect); + mode = readWord(); if (verbose) pm_message("transfer mode = %s", const_name(transfer_name, mode)); @@ -3885,7 +3884,7 @@ BitsRect(struct canvas * const canvasP, unsigned int rowBytes; stage = "Reading rowBytes word for bitsrect"; - rowBytesWord = read_word(); + rowBytesWord = readWord(); interpretRowBytesWord(rowBytesWord, &pixMap, &rowBytes); @@ -3909,7 +3908,7 @@ BitsRegion(struct canvas * const canvasP, unsigned int rowBytes; stage = "Reading rowBytes for bitsregion"; - rowBytesWord = read_word(); + rowBytesWord = readWord(); interpretRowBytesWord(rowBytesWord, &pixMap, &rowBytes); @@ -3927,7 +3926,7 @@ BitsRegion(struct canvas * const canvasP, */ static struct opdef const optable[] = { /* 0x00 */ { "NOP", 0, NULL, "nop" }, -/* 0x01 */ { "Clip", NA, Clip, "clip" }, +/* 0x01 */ { "ClipRgn", NA, ClipRgn, "clip region" }, /* 0x02 */ { "BkPat", 8, BkPat, "background pattern" }, /* 0x03 */ { "TxFont", 2, TxFont, "text font (word)" }, /* 0x04 */ { "TxFace", 1, TxFace, "text face (byte)" }, @@ -4120,7 +4119,7 @@ processOpcode(word const opcode, else { switch (optable[opcode].len) { case WORD_LEN: { - word const len = read_word(); + word const len = readWord(); skip(len); } break; default: @@ -4136,7 +4135,7 @@ processOpcode(word const opcode, stage = "skipping reserved"; if (verbose) pm_message("%s 0x%x", stage, opcode); - skip(read_word()); + skip(readWord()); } else if (opcode >= 0xb0 && opcode <= 0xcf) { /* just a reserved opcode, no data */ if (verbose) @@ -4145,7 +4144,7 @@ processOpcode(word const opcode, stage = "skipping reserved"; if (verbose) pm_message("%s 0x%x", stage, opcode); - skip(read_long()); + skip(readLong()); } else if (opcode >= 0x100 && opcode <= 0x7fff) { stage = "skipping reserved"; if (verbose) @@ -4159,7 +4158,7 @@ processOpcode(word const opcode, stage = "skipping reserved"; if (verbose) pm_message("%s 0x%x", stage, opcode); - skip(read_long()); + skip(readLong()); } else pm_error("This program does not understand opcode 0x%04x", opcode); } @@ -4188,13 +4187,13 @@ interpret_pict(FILE * const ofP) { text_trf = transfer(text_mode); stage = "Reading picture size"; - picSize = read_word(); + picSize = readWord(); if (verbose) pm_message("picture size = %u (0x%x)", picSize, picSize); stage = "reading picture frame"; - read_rect(&picFrame); + readRect(&picFrame); if (verbose) { dumpRect("Picture frame:", picFrame); @@ -4212,18 +4211,18 @@ interpret_pict(FILE * const ofP) { clip_rect = picFrame; } - while ((ch = read_byte()) == 0) + while ((ch = readByte()) == 0) ; if (ch != 0x11) pm_error("No version number"); - version = read_byte(); + version = readByte(); switch (version) { case 1: break; case 2: { - unsigned char const subcode = read_byte(); + unsigned char const subcode = readByte(); if (subcode != 0xff) pm_error("The only Version 2 PICT images this program " "undertands are subcode 0xff. This image has " |