001: /*
002: * Copyright 2005 by Paulo Soares.
003: *
004: * The contents of this file are subject to the Mozilla Public License Version 1.1
005: * (the "License"); you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the License.
011: *
012: * The Original Code is 'iText, a free JAVA-PDF library'.
013: *
014: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
015: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
016: * All Rights Reserved.
017: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
018: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
019: *
020: * Contributor(s): all the names of the contributors are added in the source code
021: * where applicable.
022: *
023: * Alternatively, the contents of this file may be used under the terms of the
024: * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
025: * provisions of LGPL are applicable instead of those above. If you wish to
026: * allow use of your version of this file only under the terms of the LGPL
027: * License and not to allow others to use your version of this file under
028: * the MPL, indicate your decision by deleting the provisions above and
029: * replace them with the notice and other provisions required by the LGPL.
030: * If you do not delete the provisions above, a recipient may use your version
031: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
032: *
033: * This library is free software; you can redistribute it and/or modify it
034: * under the terms of the MPL as stated above or under the terms of the GNU
035: * Library General Public License as published by the Free Software Foundation;
036: * either version 2 of the License, or any later version.
037: *
038: * This library is distributed in the hope that it will be useful, but WITHOUT
039: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
040: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
041: * details.
042: *
043: * If you didn't download this code from the following link, you should check if
044: * you aren't using an obsolete version:
045: * http://www.lowagie.com/iText/
046: *
047: * This code is base in the libtiff encoder
048: */
049: package com.lowagie.text.pdf.codec;
050:
051: import com.lowagie.text.pdf.ByteBuffer;
052:
053: /**
054: * Encodes data in the CCITT G4 FAX format.
055: */
056: public class CCITTG4Encoder {
057: private int rowbytes;
058: private int rowpixels;
059: private int bit = 8;
060: private int data;
061: private byte[] refline;
062: private ByteBuffer outBuf = new ByteBuffer(1024);
063: private byte[] dataBp;
064: private int offsetData;
065: private int sizeData;
066:
067: /**
068: * Creates a new encoder.
069: * @param width the line width
070: */
071: public CCITTG4Encoder(int width) {
072: rowpixels = width;
073: rowbytes = (rowpixels + 7) / 8;
074: refline = new byte[rowbytes];
075: }
076:
077: /**
078: * Encodes a number of lines.
079: * @param data the data to be encoded
080: * @param offset the offset into the data
081: * @param size the size of the data to be encoded
082: */
083: public void fax4Encode(byte[] data, int offset, int size) {
084: dataBp = data;
085: offsetData = offset;
086: sizeData = size;
087: while (sizeData > 0) {
088: Fax3Encode2DRow();
089: System.arraycopy(dataBp, offsetData, refline, 0, rowbytes);
090: offsetData += rowbytes;
091: sizeData -= rowbytes;
092: }
093: }
094:
095: /**
096: * Encodes a full image.
097: * @param data the data to encode
098: * @param width the image width
099: * @param height the image height
100: * @return the encoded image
101: */
102: public static byte[] compress(byte[] data, int width, int height) {
103: CCITTG4Encoder g4 = new CCITTG4Encoder(width);
104: g4.fax4Encode(data, 0, g4.rowbytes * height);
105: return g4.close();
106: }
107:
108: /**
109: * Encodes a number of lines.
110: * @param data the data to be encoded
111: * @param height the number of lines to encode
112: */
113: public void fax4Encode(byte[] data, int height) {
114: fax4Encode(data, 0, rowbytes * height);
115: }
116:
117: private void putcode(int[] table) {
118: putBits(table[CODE], table[LENGTH]);
119: }
120:
121: private void putspan(int span, int[][] tab) {
122: int code, length;
123:
124: while (span >= 2624) {
125: int[] te = tab[63 + (2560 >> 6)];
126: code = te[CODE];
127: length = te[LENGTH];
128: putBits(code, length);
129: span -= te[RUNLEN];
130: }
131: if (span >= 64) {
132: int[] te = tab[63 + (span >> 6)];
133: code = te[CODE];
134: length = te[LENGTH];
135: putBits(code, length);
136: span -= te[RUNLEN];
137: }
138: code = tab[span][CODE];
139: length = tab[span][LENGTH];
140: putBits(code, length);
141: }
142:
143: private void putBits(int bits, int length) {
144: while (length > bit) {
145: data |= bits >> (length - bit);
146: length -= bit;
147: outBuf.append((byte) data);
148: data = 0;
149: bit = 8;
150: }
151: data |= (bits & msbmask[length]) << (bit - length);
152: bit -= length;
153: if (bit == 0) {
154: outBuf.append((byte) data);
155: data = 0;
156: bit = 8;
157: }
158: }
159:
160: private void Fax3Encode2DRow() {
161: int a0 = 0;
162: int a1 = (pixel(dataBp, offsetData, 0) != 0 ? 0 : finddiff(
163: dataBp, offsetData, 0, rowpixels, 0));
164: int b1 = (pixel(refline, 0, 0) != 0 ? 0 : finddiff(refline, 0,
165: 0, rowpixels, 0));
166: int a2, b2;
167:
168: for (;;) {
169: b2 = finddiff2(refline, 0, b1, rowpixels, pixel(refline, 0,
170: b1));
171: if (b2 >= a1) {
172: int d = b1 - a1;
173: if (!(-3 <= d && d <= 3)) { /* horizontal mode */
174: a2 = finddiff2(dataBp, offsetData, a1, rowpixels,
175: pixel(dataBp, offsetData, a1));
176: putcode(horizcode);
177: if (a0 + a1 == 0
178: || pixel(dataBp, offsetData, a0) == 0) {
179: putspan(a1 - a0, TIFFFaxWhiteCodes);
180: putspan(a2 - a1, TIFFFaxBlackCodes);
181: } else {
182: putspan(a1 - a0, TIFFFaxBlackCodes);
183: putspan(a2 - a1, TIFFFaxWhiteCodes);
184: }
185: a0 = a2;
186: } else { /* vertical mode */
187: putcode(vcodes[d + 3]);
188: a0 = a1;
189: }
190: } else { /* pass mode */
191: putcode(passcode);
192: a0 = b2;
193: }
194: if (a0 >= rowpixels)
195: break;
196: a1 = finddiff(dataBp, offsetData, a0, rowpixels, pixel(
197: dataBp, offsetData, a0));
198: b1 = finddiff(refline, 0, a0, rowpixels, pixel(dataBp,
199: offsetData, a0) ^ 1);
200: b1 = finddiff(refline, 0, b1, rowpixels, pixel(dataBp,
201: offsetData, a0));
202: }
203: }
204:
205: private void Fax4PostEncode() {
206: putBits(EOL, 12);
207: putBits(EOL, 12);
208: if (bit != 8) {
209: outBuf.append((byte) data);
210: data = 0;
211: bit = 8;
212: }
213: }
214:
215: /**
216: * Closes the encoder and returns the encoded data.
217: * @return the encoded data
218: */
219: public byte[] close() {
220: Fax4PostEncode();
221: return outBuf.toByteArray();
222: }
223:
224: private int pixel(byte[] data, int offset, int bit) {
225: if (bit >= rowpixels)
226: return 0;
227: return ((data[offset + (bit >> 3)] & 0xff) >> (7 - ((bit) & 7))) & 1;
228: }
229:
230: private static int find1span(byte[] bp, int offset, int bs, int be) {
231: int bits = be - bs;
232: int n, span;
233:
234: int pos = offset + (bs >> 3);
235: /*
236: * Check partial byte on lhs.
237: */
238: if (bits > 0 && (n = (bs & 7)) != 0) {
239: span = oneruns[((int) bp[pos] << n) & 0xff];
240: if (span > 8 - n) /* table value too generous */
241: span = 8 - n;
242: if (span > bits) /* constrain span to bit range */
243: span = bits;
244: if (n + span < 8) /* doesn't extend to edge of byte */
245: return span;
246: bits -= span;
247: pos++;
248: } else
249: span = 0;
250: /*
251: * Scan full bytes for all 1's.
252: */
253: while (bits >= 8) {
254: if (bp[pos] != -1) /* end of run */
255: return (span + oneruns[bp[pos] & 0xff]);
256: span += 8;
257: bits -= 8;
258: pos++;
259: }
260: /*
261: * Check partial byte on rhs.
262: */
263: if (bits > 0) {
264: n = oneruns[bp[pos] & 0xff];
265: span += (n > bits ? bits : n);
266: }
267: return span;
268: }
269:
270: private static int find0span(byte[] bp, int offset, int bs, int be) {
271: int bits = be - bs;
272: int n, span;
273:
274: int pos = offset + (bs >> 3);
275: /*
276: * Check partial byte on lhs.
277: */
278: if (bits > 0 && (n = (bs & 7)) != 0) {
279: span = zeroruns[((int) bp[pos] << n) & 0xff];
280: if (span > 8 - n) /* table value too generous */
281: span = 8 - n;
282: if (span > bits) /* constrain span to bit range */
283: span = bits;
284: if (n + span < 8) /* doesn't extend to edge of byte */
285: return span;
286: bits -= span;
287: pos++;
288: } else
289: span = 0;
290: /*
291: * Scan full bytes for all 1's.
292: */
293: while (bits >= 8) {
294: if (bp[pos] != 0) /* end of run */
295: return (span + zeroruns[bp[pos] & 0xff]);
296: span += 8;
297: bits -= 8;
298: pos++;
299: }
300: /*
301: * Check partial byte on rhs.
302: */
303: if (bits > 0) {
304: n = zeroruns[bp[pos] & 0xff];
305: span += (n > bits ? bits : n);
306: }
307: return span;
308: }
309:
310: private static int finddiff(byte[] bp, int offset, int bs, int be,
311: int color) {
312: return bs
313: + (color != 0 ? find1span(bp, offset, bs, be)
314: : find0span(bp, offset, bs, be));
315: }
316:
317: private static int finddiff2(byte[] bp, int offset, int bs, int be,
318: int color) {
319: return bs < be ? finddiff(bp, offset, bs, be, color) : be;
320: }
321:
322: private static byte zeroruns[] = { 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4,
323: 4, 4, 4, 4, 4, /* 0x00 - 0x0f */
324: 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0x10 - 0x1f */
325: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x20 - 0x2f */
326: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x30 - 0x3f */
327: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4f */
328: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x50 - 0x5f */
329: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6f */
330: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x70 - 0x7f */
331: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8f */
332: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9f */
333: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 - 0xaf */
334: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 - 0xbf */
335: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 - 0xcf */
336: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 - 0xdf */
337: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 - 0xef */
338: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xf0 - 0xff */
339: };
340:
341: private static byte oneruns[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
342: 0, 0, 0, 0, 0, /* 0x00 - 0x0f */
343: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */
344: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 - 0x2f */
345: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30 - 0x3f */
346: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x4f */
347: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */
348: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6f */
349: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7f */
350: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x80 - 0x8f */
351: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x90 - 0x9f */
352: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xa0 - 0xaf */
353: 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xb0 - 0xbf */
354: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xc0 - 0xcf */
355: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xd0 - 0xdf */
356: 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xe0 - 0xef */
357: 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8 /* 0xf0 - 0xff */
358: };
359:
360: private static final int LENGTH = 0; /* bit length of g3 code */
361: private static final int CODE = 1; /* g3 code */
362: private static final int RUNLEN = 2; /* run length in bits */
363:
364: private static final int EOL = 0x001; /* EOL code value - 0000 0000 0000 1 */
365:
366: /* status values returned instead of a run length */
367: private static final int G3CODE_EOL = -1; /* NB: ACT_EOL - ACT_WRUNT */
368: private static final int G3CODE_INVALID = -2; /* NB: ACT_INVALID - ACT_WRUNT */
369: private static final int G3CODE_EOF = -3; /* end of input data */
370: private static final int G3CODE_INCOMP = -4; /* incomplete run code */
371:
372: private int[][] TIFFFaxWhiteCodes = { { 8, 0x35, 0 }, /* 0011 0101 */
373: { 6, 0x7, 1 }, /* 0001 11 */
374: { 4, 0x7, 2 }, /* 0111 */
375: { 4, 0x8, 3 }, /* 1000 */
376: { 4, 0xB, 4 }, /* 1011 */
377: { 4, 0xC, 5 }, /* 1100 */
378: { 4, 0xE, 6 }, /* 1110 */
379: { 4, 0xF, 7 }, /* 1111 */
380: { 5, 0x13, 8 }, /* 1001 1 */
381: { 5, 0x14, 9 }, /* 1010 0 */
382: { 5, 0x7, 10 }, /* 0011 1 */
383: { 5, 0x8, 11 }, /* 0100 0 */
384: { 6, 0x8, 12 }, /* 0010 00 */
385: { 6, 0x3, 13 }, /* 0000 11 */
386: { 6, 0x34, 14 }, /* 1101 00 */
387: { 6, 0x35, 15 }, /* 1101 01 */
388: { 6, 0x2A, 16 }, /* 1010 10 */
389: { 6, 0x2B, 17 }, /* 1010 11 */
390: { 7, 0x27, 18 }, /* 0100 111 */
391: { 7, 0xC, 19 }, /* 0001 100 */
392: { 7, 0x8, 20 }, /* 0001 000 */
393: { 7, 0x17, 21 }, /* 0010 111 */
394: { 7, 0x3, 22 }, /* 0000 011 */
395: { 7, 0x4, 23 }, /* 0000 100 */
396: { 7, 0x28, 24 }, /* 0101 000 */
397: { 7, 0x2B, 25 }, /* 0101 011 */
398: { 7, 0x13, 26 }, /* 0010 011 */
399: { 7, 0x24, 27 }, /* 0100 100 */
400: { 7, 0x18, 28 }, /* 0011 000 */
401: { 8, 0x2, 29 }, /* 0000 0010 */
402: { 8, 0x3, 30 }, /* 0000 0011 */
403: { 8, 0x1A, 31 }, /* 0001 1010 */
404: { 8, 0x1B, 32 }, /* 0001 1011 */
405: { 8, 0x12, 33 }, /* 0001 0010 */
406: { 8, 0x13, 34 }, /* 0001 0011 */
407: { 8, 0x14, 35 }, /* 0001 0100 */
408: { 8, 0x15, 36 }, /* 0001 0101 */
409: { 8, 0x16, 37 }, /* 0001 0110 */
410: { 8, 0x17, 38 }, /* 0001 0111 */
411: { 8, 0x28, 39 }, /* 0010 1000 */
412: { 8, 0x29, 40 }, /* 0010 1001 */
413: { 8, 0x2A, 41 }, /* 0010 1010 */
414: { 8, 0x2B, 42 }, /* 0010 1011 */
415: { 8, 0x2C, 43 }, /* 0010 1100 */
416: { 8, 0x2D, 44 }, /* 0010 1101 */
417: { 8, 0x4, 45 }, /* 0000 0100 */
418: { 8, 0x5, 46 }, /* 0000 0101 */
419: { 8, 0xA, 47 }, /* 0000 1010 */
420: { 8, 0xB, 48 }, /* 0000 1011 */
421: { 8, 0x52, 49 }, /* 0101 0010 */
422: { 8, 0x53, 50 }, /* 0101 0011 */
423: { 8, 0x54, 51 }, /* 0101 0100 */
424: { 8, 0x55, 52 }, /* 0101 0101 */
425: { 8, 0x24, 53 }, /* 0010 0100 */
426: { 8, 0x25, 54 }, /* 0010 0101 */
427: { 8, 0x58, 55 }, /* 0101 1000 */
428: { 8, 0x59, 56 }, /* 0101 1001 */
429: { 8, 0x5A, 57 }, /* 0101 1010 */
430: { 8, 0x5B, 58 }, /* 0101 1011 */
431: { 8, 0x4A, 59 }, /* 0100 1010 */
432: { 8, 0x4B, 60 }, /* 0100 1011 */
433: { 8, 0x32, 61 }, /* 0011 0010 */
434: { 8, 0x33, 62 }, /* 0011 0011 */
435: { 8, 0x34, 63 }, /* 0011 0100 */
436: { 5, 0x1B, 64 }, /* 1101 1 */
437: { 5, 0x12, 128 }, /* 1001 0 */
438: { 6, 0x17, 192 }, /* 0101 11 */
439: { 7, 0x37, 256 }, /* 0110 111 */
440: { 8, 0x36, 320 }, /* 0011 0110 */
441: { 8, 0x37, 384 }, /* 0011 0111 */
442: { 8, 0x64, 448 }, /* 0110 0100 */
443: { 8, 0x65, 512 }, /* 0110 0101 */
444: { 8, 0x68, 576 }, /* 0110 1000 */
445: { 8, 0x67, 640 }, /* 0110 0111 */
446: { 9, 0xCC, 704 }, /* 0110 0110 0 */
447: { 9, 0xCD, 768 }, /* 0110 0110 1 */
448: { 9, 0xD2, 832 }, /* 0110 1001 0 */
449: { 9, 0xD3, 896 }, /* 0110 1001 1 */
450: { 9, 0xD4, 960 }, /* 0110 1010 0 */
451: { 9, 0xD5, 1024 }, /* 0110 1010 1 */
452: { 9, 0xD6, 1088 }, /* 0110 1011 0 */
453: { 9, 0xD7, 1152 }, /* 0110 1011 1 */
454: { 9, 0xD8, 1216 }, /* 0110 1100 0 */
455: { 9, 0xD9, 1280 }, /* 0110 1100 1 */
456: { 9, 0xDA, 1344 }, /* 0110 1101 0 */
457: { 9, 0xDB, 1408 }, /* 0110 1101 1 */
458: { 9, 0x98, 1472 }, /* 0100 1100 0 */
459: { 9, 0x99, 1536 }, /* 0100 1100 1 */
460: { 9, 0x9A, 1600 }, /* 0100 1101 0 */
461: { 6, 0x18, 1664 }, /* 0110 00 */
462: { 9, 0x9B, 1728 }, /* 0100 1101 1 */
463: { 11, 0x8, 1792 }, /* 0000 0001 000 */
464: { 11, 0xC, 1856 }, /* 0000 0001 100 */
465: { 11, 0xD, 1920 }, /* 0000 0001 101 */
466: { 12, 0x12, 1984 }, /* 0000 0001 0010 */
467: { 12, 0x13, 2048 }, /* 0000 0001 0011 */
468: { 12, 0x14, 2112 }, /* 0000 0001 0100 */
469: { 12, 0x15, 2176 }, /* 0000 0001 0101 */
470: { 12, 0x16, 2240 }, /* 0000 0001 0110 */
471: { 12, 0x17, 2304 }, /* 0000 0001 0111 */
472: { 12, 0x1C, 2368 }, /* 0000 0001 1100 */
473: { 12, 0x1D, 2432 }, /* 0000 0001 1101 */
474: { 12, 0x1E, 2496 }, /* 0000 0001 1110 */
475: { 12, 0x1F, 2560 }, /* 0000 0001 1111 */
476: { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */
477: { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */
478: { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */
479: { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */
480: { 12, 0x0, G3CODE_INVALID } /* 0000 0000 0000 */
481: };
482:
483: private int[][] TIFFFaxBlackCodes = { { 10, 0x37, 0 }, /* 0000 1101 11 */
484: { 3, 0x2, 1 }, /* 010 */
485: { 2, 0x3, 2 }, /* 11 */
486: { 2, 0x2, 3 }, /* 10 */
487: { 3, 0x3, 4 }, /* 011 */
488: { 4, 0x3, 5 }, /* 0011 */
489: { 4, 0x2, 6 }, /* 0010 */
490: { 5, 0x3, 7 }, /* 0001 1 */
491: { 6, 0x5, 8 }, /* 0001 01 */
492: { 6, 0x4, 9 }, /* 0001 00 */
493: { 7, 0x4, 10 }, /* 0000 100 */
494: { 7, 0x5, 11 }, /* 0000 101 */
495: { 7, 0x7, 12 }, /* 0000 111 */
496: { 8, 0x4, 13 }, /* 0000 0100 */
497: { 8, 0x7, 14 }, /* 0000 0111 */
498: { 9, 0x18, 15 }, /* 0000 1100 0 */
499: { 10, 0x17, 16 }, /* 0000 0101 11 */
500: { 10, 0x18, 17 }, /* 0000 0110 00 */
501: { 10, 0x8, 18 }, /* 0000 0010 00 */
502: { 11, 0x67, 19 }, /* 0000 1100 111 */
503: { 11, 0x68, 20 }, /* 0000 1101 000 */
504: { 11, 0x6C, 21 }, /* 0000 1101 100 */
505: { 11, 0x37, 22 }, /* 0000 0110 111 */
506: { 11, 0x28, 23 }, /* 0000 0101 000 */
507: { 11, 0x17, 24 }, /* 0000 0010 111 */
508: { 11, 0x18, 25 }, /* 0000 0011 000 */
509: { 12, 0xCA, 26 }, /* 0000 1100 1010 */
510: { 12, 0xCB, 27 }, /* 0000 1100 1011 */
511: { 12, 0xCC, 28 }, /* 0000 1100 1100 */
512: { 12, 0xCD, 29 }, /* 0000 1100 1101 */
513: { 12, 0x68, 30 }, /* 0000 0110 1000 */
514: { 12, 0x69, 31 }, /* 0000 0110 1001 */
515: { 12, 0x6A, 32 }, /* 0000 0110 1010 */
516: { 12, 0x6B, 33 }, /* 0000 0110 1011 */
517: { 12, 0xD2, 34 }, /* 0000 1101 0010 */
518: { 12, 0xD3, 35 }, /* 0000 1101 0011 */
519: { 12, 0xD4, 36 }, /* 0000 1101 0100 */
520: { 12, 0xD5, 37 }, /* 0000 1101 0101 */
521: { 12, 0xD6, 38 }, /* 0000 1101 0110 */
522: { 12, 0xD7, 39 }, /* 0000 1101 0111 */
523: { 12, 0x6C, 40 }, /* 0000 0110 1100 */
524: { 12, 0x6D, 41 }, /* 0000 0110 1101 */
525: { 12, 0xDA, 42 }, /* 0000 1101 1010 */
526: { 12, 0xDB, 43 }, /* 0000 1101 1011 */
527: { 12, 0x54, 44 }, /* 0000 0101 0100 */
528: { 12, 0x55, 45 }, /* 0000 0101 0101 */
529: { 12, 0x56, 46 }, /* 0000 0101 0110 */
530: { 12, 0x57, 47 }, /* 0000 0101 0111 */
531: { 12, 0x64, 48 }, /* 0000 0110 0100 */
532: { 12, 0x65, 49 }, /* 0000 0110 0101 */
533: { 12, 0x52, 50 }, /* 0000 0101 0010 */
534: { 12, 0x53, 51 }, /* 0000 0101 0011 */
535: { 12, 0x24, 52 }, /* 0000 0010 0100 */
536: { 12, 0x37, 53 }, /* 0000 0011 0111 */
537: { 12, 0x38, 54 }, /* 0000 0011 1000 */
538: { 12, 0x27, 55 }, /* 0000 0010 0111 */
539: { 12, 0x28, 56 }, /* 0000 0010 1000 */
540: { 12, 0x58, 57 }, /* 0000 0101 1000 */
541: { 12, 0x59, 58 }, /* 0000 0101 1001 */
542: { 12, 0x2B, 59 }, /* 0000 0010 1011 */
543: { 12, 0x2C, 60 }, /* 0000 0010 1100 */
544: { 12, 0x5A, 61 }, /* 0000 0101 1010 */
545: { 12, 0x66, 62 }, /* 0000 0110 0110 */
546: { 12, 0x67, 63 }, /* 0000 0110 0111 */
547: { 10, 0xF, 64 }, /* 0000 0011 11 */
548: { 12, 0xC8, 128 }, /* 0000 1100 1000 */
549: { 12, 0xC9, 192 }, /* 0000 1100 1001 */
550: { 12, 0x5B, 256 }, /* 0000 0101 1011 */
551: { 12, 0x33, 320 }, /* 0000 0011 0011 */
552: { 12, 0x34, 384 }, /* 0000 0011 0100 */
553: { 12, 0x35, 448 }, /* 0000 0011 0101 */
554: { 13, 0x6C, 512 }, /* 0000 0011 0110 0 */
555: { 13, 0x6D, 576 }, /* 0000 0011 0110 1 */
556: { 13, 0x4A, 640 }, /* 0000 0010 0101 0 */
557: { 13, 0x4B, 704 }, /* 0000 0010 0101 1 */
558: { 13, 0x4C, 768 }, /* 0000 0010 0110 0 */
559: { 13, 0x4D, 832 }, /* 0000 0010 0110 1 */
560: { 13, 0x72, 896 }, /* 0000 0011 1001 0 */
561: { 13, 0x73, 960 }, /* 0000 0011 1001 1 */
562: { 13, 0x74, 1024 }, /* 0000 0011 1010 0 */
563: { 13, 0x75, 1088 }, /* 0000 0011 1010 1 */
564: { 13, 0x76, 1152 }, /* 0000 0011 1011 0 */
565: { 13, 0x77, 1216 }, /* 0000 0011 1011 1 */
566: { 13, 0x52, 1280 }, /* 0000 0010 1001 0 */
567: { 13, 0x53, 1344 }, /* 0000 0010 1001 1 */
568: { 13, 0x54, 1408 }, /* 0000 0010 1010 0 */
569: { 13, 0x55, 1472 }, /* 0000 0010 1010 1 */
570: { 13, 0x5A, 1536 }, /* 0000 0010 1101 0 */
571: { 13, 0x5B, 1600 }, /* 0000 0010 1101 1 */
572: { 13, 0x64, 1664 }, /* 0000 0011 0010 0 */
573: { 13, 0x65, 1728 }, /* 0000 0011 0010 1 */
574: { 11, 0x8, 1792 }, /* 0000 0001 000 */
575: { 11, 0xC, 1856 }, /* 0000 0001 100 */
576: { 11, 0xD, 1920 }, /* 0000 0001 101 */
577: { 12, 0x12, 1984 }, /* 0000 0001 0010 */
578: { 12, 0x13, 2048 }, /* 0000 0001 0011 */
579: { 12, 0x14, 2112 }, /* 0000 0001 0100 */
580: { 12, 0x15, 2176 }, /* 0000 0001 0101 */
581: { 12, 0x16, 2240 }, /* 0000 0001 0110 */
582: { 12, 0x17, 2304 }, /* 0000 0001 0111 */
583: { 12, 0x1C, 2368 }, /* 0000 0001 1100 */
584: { 12, 0x1D, 2432 }, /* 0000 0001 1101 */
585: { 12, 0x1E, 2496 }, /* 0000 0001 1110 */
586: { 12, 0x1F, 2560 }, /* 0000 0001 1111 */
587: { 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */
588: { 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */
589: { 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */
590: { 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */
591: { 12, 0x0, G3CODE_INVALID } /* 0000 0000 0000 */
592: };
593:
594: private int[] horizcode = { 3, 0x1, 0 }; /* 001 */
595: private int[] passcode = { 4, 0x1, 0 }; /* 0001 */
596: private int[][] vcodes = { { 7, 0x03, 0 }, /* 0000 011 */
597: { 6, 0x03, 0 }, /* 0000 11 */
598: { 3, 0x03, 0 }, /* 011 */
599: { 1, 0x1, 0 }, /* 1 */
600: { 3, 0x2, 0 }, /* 010 */
601: { 6, 0x02, 0 }, /* 0000 10 */
602: { 7, 0x02, 0 } /* 0000 010 */
603: };
604: private int[] msbmask = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f,
605: 0x7f, 0xff };
606: }
|