diff --git a/src/add-ons/print/drivers/canon_lips/libprint/DbgMsg.h b/src/add-ons/print/drivers/canon_lips/libprint/DbgMsg.h index fca1ebdc36..60263b104e 100644 --- a/src/add-ons/print/drivers/canon_lips/libprint/DbgMsg.h +++ b/src/add-ons/print/drivers/canon_lips/libprint/DbgMsg.h @@ -6,7 +6,7 @@ #ifndef __DBGMSG_H #define __DBGMSG_H -//#define DBG +// #define DBG #ifdef DBG void write_debug_stream(const char *, ...); diff --git a/src/add-ons/print/drivers/canon_lips/libprint/Jamfile b/src/add-ons/print/drivers/canon_lips/libprint/Jamfile index 3aacd6a4a5..921621f086 100644 --- a/src/add-ons/print/drivers/canon_lips/libprint/Jamfile +++ b/src/add-ons/print/drivers/canon_lips/libprint/Jamfile @@ -7,6 +7,7 @@ StaticLibrary print : Halftone.cpp JobData.cpp JobSetupDlg.cpp + PackBits.cpp PageSetupDlg.cpp Preview.cpp PrinterData.cpp diff --git a/src/add-ons/print/drivers/canon_lips/libprint/PackBits.cpp b/src/add-ons/print/drivers/canon_lips/libprint/PackBits.cpp new file mode 100644 index 0000000000..409025ae7d --- /dev/null +++ b/src/add-ons/print/drivers/canon_lips/libprint/PackBits.cpp @@ -0,0 +1,158 @@ +/* + * PackBits.cpp + * Copyright 1999-2000 Y.Takagi. All Rights Reserved. + */ + +//#define DBG_CON_STREAM + +#ifdef DBG_CON_STREAM +#include +#endif + +#include +#include "PackBits.h" + +#if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE)) +using namespace std; +#else +#define std +#endif + +#define MAXINBYTES 127 +#define CONTROL1(i) -i +#define CONTROL2(i) i + +enum STATUS { + INITIAL, + UNDECIDED, + UNMATCHED, + MATCHED +}; + +int pack_bits(unsigned char *pOut, unsigned char *pIn, int n) +{ + int i; + unsigned char *control; + unsigned char *runbuf; + unsigned char thisbyte; + unsigned char runbyte; + STATUS status; + + i = 0; + status = INITIAL; + control = runbuf = pOut; + runbyte = *pIn++; + + while (--n) { + thisbyte = *pIn++; + switch (status) { + case INITIAL: + control = runbuf++; + *runbuf++ = runbyte; + if (thisbyte == runbyte) { + status = UNDECIDED; + } else { + runbyte = thisbyte; + status = UNMATCHED; + } + i = 1; + break; + + case UNDECIDED: + if (i == MAXINBYTES) { + *control = CONTROL2(i); + *runbuf++ = runbyte; + runbyte = thisbyte; + status = INITIAL; + } else if (thisbyte == runbyte) { + if (i > 1) { + *control = CONTROL2(i - 2); + control = runbuf - 1; + } + i = 2; + status = MATCHED; + } else { + *runbuf++ = runbyte; + runbyte = thisbyte; + status = UNMATCHED; + i++; + } + break; + + case UNMATCHED: + if (i == MAXINBYTES) { + *control = CONTROL2(i); + status = INITIAL; + } else { + if (thisbyte == runbyte) { + status = UNDECIDED; + } + i++; + } + *runbuf++ = runbyte; + runbyte = thisbyte; + break; + + case MATCHED: + if ((thisbyte != runbyte) || (i == MAXINBYTES)) { + runbuf = control; + *runbuf++ = CONTROL1(i); + *runbuf++ = runbyte; + runbyte = thisbyte; + status = INITIAL; + } else { + i++; + } + break; + } + } + + switch (status) { + case INITIAL: + *runbuf++ = CONTROL2(1); + break; + case UNDECIDED: + case UNMATCHED: + *control = CONTROL2(i); + break; + case MATCHED: + runbuf = control; + *runbuf++ = CONTROL1(i); + break; + } + *runbuf++ = runbyte; + + return runbuf - pOut; +} + +#ifdef DBG_CON_STREAM +int main(int argc, char **argv) +{ + if (argc < 2) { + return -1; + } + + ifstream ifs(*++argv, ios::binary | ios::nocreate); + if (!ifs) { + return -1; + } + + ifs.seekg(0, ios::end); + long size = ifs.tellg(); + ifs.seekg(0, ios::beg); + + unsigned char *pIn = new unsigned char[size]; + unsigned char *pOut = new unsigned char[size * 3]; + + ifs.read(pIn, size); + + int cnt = PackBits(pOut, pIn, size); + + ofstream ofs("test.bin", ios::binary); + ofs.write(pOut, cnt); + + delete [] pIn; + delete [] pOut; + +} +#endif diff --git a/src/add-ons/print/drivers/canon_lips/libprint/PackBits.h b/src/add-ons/print/drivers/canon_lips/libprint/PackBits.h new file mode 100644 index 0000000000..faf4ec5083 --- /dev/null +++ b/src/add-ons/print/drivers/canon_lips/libprint/PackBits.h @@ -0,0 +1,11 @@ +/* + * PackBits.h + * Copyright 1999-2000 Y.Takagi. All Rights Reserved. + */ + +#ifndef __PACKBITS_H +#define __PACKBITS_H + +int pack_bits(unsigned char *out, unsigned char *in, int bytes); + +#endif /* __PACKBITS_H */