001: /*
002: * $Id: ImgCCITT.java 2752 2007-05-15 14:58:33Z blowagie $
003: * $Name$
004: *
005: * Copyright 2000, 2001, 2002 by Paulo Soares.
006: *
007: * The contents of this file are subject to the Mozilla Public License Version 1.1
008: * (the "License"); you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the License.
014: *
015: * The Original Code is 'iText, a free JAVA-PDF library'.
016: *
017: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
018: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
019: * All Rights Reserved.
020: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
021: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
022: *
023: * Contributor(s): all the names of the contributors are added in the source code
024: * where applicable.
025: *
026: * Alternatively, the contents of this file may be used under the terms of the
027: * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
028: * provisions of LGPL are applicable instead of those above. If you wish to
029: * allow use of your version of this file only under the terms of the LGPL
030: * License and not to allow others to use your version of this file under
031: * the MPL, indicate your decision by deleting the provisions above and
032: * replace them with the notice and other provisions required by the LGPL.
033: * If you do not delete the provisions above, a recipient may use your version
034: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
035: *
036: * This library is free software; you can redistribute it and/or modify it
037: * under the terms of the MPL as stated above or under the terms of the GNU
038: * Library General Public License as published by the Free Software Foundation;
039: * either version 2 of the License, or any later version.
040: *
041: * This library is distributed in the hope that it will be useful, but WITHOUT
042: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
043: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
044: * details.
045: *
046: * If you didn't download this code from the following link, you should check if
047: * you aren't using an obsolete version:
048: * http://www.lowagie.com/iText/
049: */
050:
051: package com.lowagie.text;
052:
053: import java.net.URL;
054:
055: /**
056: * CCITT Image data that has to be inserted into the document
057: *
058: * @see Element
059: * @see Image
060: *
061: * @author Paulo Soares
062: */
063:
064: public class ImgCCITT extends Image {
065: /** A table to do fast bit reversal.
066: */
067: static final byte bitReversal[] = { (byte) 0x00, (byte) 0x80,
068: (byte) 0x40, (byte) 0xc0, (byte) 0x20, (byte) 0xa0,
069: (byte) 0x60, (byte) 0xe0, (byte) 0x10, (byte) 0x90,
070: (byte) 0x50, (byte) 0xd0, (byte) 0x30, (byte) 0xb0,
071: (byte) 0x70, (byte) 0xf0, (byte) 0x08, (byte) 0x88,
072: (byte) 0x48, (byte) 0xc8, (byte) 0x28, (byte) 0xa8,
073: (byte) 0x68, (byte) 0xe8, (byte) 0x18, (byte) 0x98,
074: (byte) 0x58, (byte) 0xd8, (byte) 0x38, (byte) 0xb8,
075: (byte) 0x78, (byte) 0xf8, (byte) 0x04, (byte) 0x84,
076: (byte) 0x44, (byte) 0xc4, (byte) 0x24, (byte) 0xa4,
077: (byte) 0x64, (byte) 0xe4, (byte) 0x14, (byte) 0x94,
078: (byte) 0x54, (byte) 0xd4, (byte) 0x34, (byte) 0xb4,
079: (byte) 0x74, (byte) 0xf4, (byte) 0x0c, (byte) 0x8c,
080: (byte) 0x4c, (byte) 0xcc, (byte) 0x2c, (byte) 0xac,
081: (byte) 0x6c, (byte) 0xec, (byte) 0x1c, (byte) 0x9c,
082: (byte) 0x5c, (byte) 0xdc, (byte) 0x3c, (byte) 0xbc,
083: (byte) 0x7c, (byte) 0xfc, (byte) 0x02, (byte) 0x82,
084: (byte) 0x42, (byte) 0xc2, (byte) 0x22, (byte) 0xa2,
085: (byte) 0x62, (byte) 0xe2, (byte) 0x12, (byte) 0x92,
086: (byte) 0x52, (byte) 0xd2, (byte) 0x32, (byte) 0xb2,
087: (byte) 0x72, (byte) 0xf2, (byte) 0x0a, (byte) 0x8a,
088: (byte) 0x4a, (byte) 0xca, (byte) 0x2a, (byte) 0xaa,
089: (byte) 0x6a, (byte) 0xea, (byte) 0x1a, (byte) 0x9a,
090: (byte) 0x5a, (byte) 0xda, (byte) 0x3a, (byte) 0xba,
091: (byte) 0x7a, (byte) 0xfa, (byte) 0x06, (byte) 0x86,
092: (byte) 0x46, (byte) 0xc6, (byte) 0x26, (byte) 0xa6,
093: (byte) 0x66, (byte) 0xe6, (byte) 0x16, (byte) 0x96,
094: (byte) 0x56, (byte) 0xd6, (byte) 0x36, (byte) 0xb6,
095: (byte) 0x76, (byte) 0xf6, (byte) 0x0e, (byte) 0x8e,
096: (byte) 0x4e, (byte) 0xce, (byte) 0x2e, (byte) 0xae,
097: (byte) 0x6e, (byte) 0xee, (byte) 0x1e, (byte) 0x9e,
098: (byte) 0x5e, (byte) 0xde, (byte) 0x3e, (byte) 0xbe,
099: (byte) 0x7e, (byte) 0xfe, (byte) 0x01, (byte) 0x81,
100: (byte) 0x41, (byte) 0xc1, (byte) 0x21, (byte) 0xa1,
101: (byte) 0x61, (byte) 0xe1, (byte) 0x11, (byte) 0x91,
102: (byte) 0x51, (byte) 0xd1, (byte) 0x31, (byte) 0xb1,
103: (byte) 0x71, (byte) 0xf1, (byte) 0x09, (byte) 0x89,
104: (byte) 0x49, (byte) 0xc9, (byte) 0x29, (byte) 0xa9,
105: (byte) 0x69, (byte) 0xe9, (byte) 0x19, (byte) 0x99,
106: (byte) 0x59, (byte) 0xd9, (byte) 0x39, (byte) 0xb9,
107: (byte) 0x79, (byte) 0xf9, (byte) 0x05, (byte) 0x85,
108: (byte) 0x45, (byte) 0xc5, (byte) 0x25, (byte) 0xa5,
109: (byte) 0x65, (byte) 0xe5, (byte) 0x15, (byte) 0x95,
110: (byte) 0x55, (byte) 0xd5, (byte) 0x35, (byte) 0xb5,
111: (byte) 0x75, (byte) 0xf5, (byte) 0x0d, (byte) 0x8d,
112: (byte) 0x4d, (byte) 0xcd, (byte) 0x2d, (byte) 0xad,
113: (byte) 0x6d, (byte) 0xed, (byte) 0x1d, (byte) 0x9d,
114: (byte) 0x5d, (byte) 0xdd, (byte) 0x3d, (byte) 0xbd,
115: (byte) 0x7d, (byte) 0xfd, (byte) 0x03, (byte) 0x83,
116: (byte) 0x43, (byte) 0xc3, (byte) 0x23, (byte) 0xa3,
117: (byte) 0x63, (byte) 0xe3, (byte) 0x13, (byte) 0x93,
118: (byte) 0x53, (byte) 0xd3, (byte) 0x33, (byte) 0xb3,
119: (byte) 0x73, (byte) 0xf3, (byte) 0x0b, (byte) 0x8b,
120: (byte) 0x4b, (byte) 0xcb, (byte) 0x2b, (byte) 0xab,
121: (byte) 0x6b, (byte) 0xeb, (byte) 0x1b, (byte) 0x9b,
122: (byte) 0x5b, (byte) 0xdb, (byte) 0x3b, (byte) 0xbb,
123: (byte) 0x7b, (byte) 0xfb, (byte) 0x07, (byte) 0x87,
124: (byte) 0x47, (byte) 0xc7, (byte) 0x27, (byte) 0xa7,
125: (byte) 0x67, (byte) 0xe7, (byte) 0x17, (byte) 0x97,
126: (byte) 0x57, (byte) 0xd7, (byte) 0x37, (byte) 0xb7,
127: (byte) 0x77, (byte) 0xf7, (byte) 0x0f, (byte) 0x8f,
128: (byte) 0x4f, (byte) 0xcf, (byte) 0x2f, (byte) 0xaf,
129: (byte) 0x6f, (byte) 0xef, (byte) 0x1f, (byte) 0x9f,
130: (byte) 0x5f, (byte) 0xdf, (byte) 0x3f, (byte) 0xbf,
131: (byte) 0x7f, (byte) 0xff };
132:
133: /** Reverses the bits in the array.
134: * @param data data to reverse bits
135: */
136: public static void ReverseBits(byte data[]) {
137: for (int k = 0; k < data.length; ++k)
138: data[k] = bitReversal[(int) data[k] & 0xff];
139: }
140:
141: ImgCCITT(Image image) {
142: super (image);
143: }
144:
145: /** Creates an Image with CCITT compression.
146: *
147: * @param width the exact width of the image
148: * @param height the exact height of the image
149: * @param reverseBits reverses the bits in <code>data</code>.
150: * Bit 0 is swapped with bit 7 and so on
151: * @param typeCCITT the type of compression in <code>data</code>. It can be
152: * CCITTG4, CCITTG31D, CCITTG32D
153: * @param parameters parameters associated with this stream. Possible values are
154: * CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFLINE and CCITT_ENDOFBLOCK or a
155: * combination of them
156: * @param data the image data
157: * @throws BadElementException on error
158: */
159:
160: public ImgCCITT(int width, int height, boolean reverseBits,
161: int typeCCITT, int parameters, byte[] data)
162: throws BadElementException {
163: super ((URL) null);
164: if (typeCCITT != CCITTG4 && typeCCITT != CCITTG3_1D
165: && typeCCITT != CCITTG3_2D)
166: throw new BadElementException(
167: "The CCITT compression type must be CCITTG4, CCITTG3_1D or CCITTG3_2D");
168: if (reverseBits)
169: ReverseBits(data);
170: type = IMGRAW;
171: scaledHeight = height;
172: setTop(scaledHeight);
173: scaledWidth = width;
174: setRight(scaledWidth);
175: colorspace = parameters;
176: bpc = typeCCITT;
177: rawData = data;
178: plainWidth = getWidth();
179: plainHeight = getHeight();
180: }
181: }
|