diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-09-27 21:44:29 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-09-27 21:44:29 +0000 |
commit | 43939e66b1d4eeb2f3799c124f3598756755005a (patch) | |
tree | 15733092de55d52421a6ea02f5a43d5f8ff24393 /converter/pbm/pbmtog3.c | |
parent | 49f4336c9bba33650573ba780b70bc501b38643e (diff) | |
download | netpbm-mirror-43939e66b1d4eeb2f3799c124f3598756755005a.tar.gz netpbm-mirror-43939e66b1d4eeb2f3799c124f3598756755005a.tar.xz netpbm-mirror-43939e66b1d4eeb2f3799c124f3598756755005a.zip |
Rebase Stable series to current Advanced: 10.47.04
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@995 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/pbm/pbmtog3.c')
-rw-r--r-- | converter/pbm/pbmtog3.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/converter/pbm/pbmtog3.c b/converter/pbm/pbmtog3.c index 0b536390..f53bfaa0 100644 --- a/converter/pbm/pbmtog3.c +++ b/converter/pbm/pbmtog3.c @@ -18,12 +18,14 @@ #include <assert.h> -#include "pbm.h" +#include "pm_c_util.h" #include "shhopt.h" #include "mallocvar.h" #include "bitreverse.h" #include "wordaccess.h" +#include "wordintclz.h" #include "g3.h" +#include "pbm.h" #define TC_MC 64 @@ -55,7 +57,7 @@ struct bitString { struct outStream { struct bitString buffer; - + bool reverseBits; }; @@ -109,6 +111,8 @@ parseCommandLine(int argc, char ** const argv, optParseOptions3(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ + free(option_def); + if (argc-1 == 0) cmdlineP->inputFileName = "-"; else if (argc-1 != 1) @@ -142,7 +146,7 @@ makeBs(wordint const bits, return retval; } - + static __inline__ void putbits(struct bitString const newBits) { @@ -153,7 +157,7 @@ putbits(struct bitString const newBits) { Flush the buffer to stdout as necessary to make room. 'newBits' must be shorter than a whole word. - + N.B. the definition of struct bitString requires upper bits to be zero. -----------------------------------------------------------------------------*/ unsigned int const spaceLeft = @@ -182,11 +186,11 @@ putbits(struct bitString const newBits) { | (newBits.intBuffer >> nextBufBitCount)); if (out.reverseBits) reversebuffer(outbytes, sizeof(outbytes)); - + rc = fwrite(outbytes, 1, sizeof(outbytes), stdout); if (rc != sizeof(outbytes)) pm_error("Output error. Unable to fwrite() to stdout"); - + out.buffer.intBuffer = newBits.intBuffer & ((1<<nextBufBitCount) - 1); out.buffer.bitCount = nextBufBitCount; } @@ -237,7 +241,7 @@ putcode2(int const clr, if (sizeof(wordint) * 8 > 24) { unsigned int const l1 = ttable[loIndex].length; - + putbits( makeBs(mtable[hiIndex].code << l1 | ttable[loIndex].code, mtable[hiIndex].length + l1) @@ -299,7 +303,7 @@ puteol(void) { puts("EOL"); else { struct bitString const eol = {12, 1}; - + putbits(eol); } } @@ -341,7 +345,7 @@ convertRowToRunLengths(unsigned char * const bitrow, wordint * const bitrowByWord = (wordint *) bitrow; int const wordCount = (cols + bitsPerWord - 1)/bitsPerWord; /* Number of full and partial words in the row */ - + if (cols % bitsPerWord != 0) { /* Clean final word in row. For loop simplicity */ @@ -411,7 +415,7 @@ main(int argc, a word of zero padding on the high (right) end for the convenience of code that accesses this buffer in word-size bites. */ - + int rows; int cols; int readcols; @@ -423,7 +427,7 @@ main(int argc, pbm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); - + ifP = pm_openr(cmdline.inputFileName); pbm_readpbminit(ifP, &cols, &rows, &format); @@ -447,9 +451,9 @@ main(int argc, unsigned int i; pbm_readpbmrow_packed(ifP, bitrow, cols, format); - + convertRowToRunLengths(bitrow, readcols, milepost, &nRun); - + padToDesiredWidth(milepost, &nRun, readcols, outwidth); for (i = p = 0; i < nRun; p = milepost[i++]) @@ -459,6 +463,8 @@ main(int argc, } free(milepost); + pbm_freerow_packed(bitrow); + { unsigned int i; for( i = 0; i < 6; ++i) @@ -467,7 +473,7 @@ main(int argc, if (out.buffer.bitCount > 0) { /* flush final partial buffer */ unsigned int const bytesToWrite = (out.buffer.bitCount+7)/8; - + unsigned char outbytes[sizeof(wordint)]; size_t rc; wordintToBytes(&outbytes, |