001: package org.libtiff.jai.codecimpl;
002:
003: import org.libtiff.jai.codec.XTIFFTileCodecImpl;
004: import org.libtiff.jai.codec.XTIFFTileCodec;
005: import org.libtiff.jai.codec.XTIFFEncodeParam;
006: import org.libtiff.jai.codec.XTIFFField;
007: import org.libtiff.jai.codec.XTIFF;
008: import java.awt.Rectangle;
009:
010: /**
011: * This codec encapsulates all the logic for the TIFF
012: * "lzw" decoding codec algorithm.
013: */
014: public class XTIFFFaxTileCodec extends XTIFFTileCodecImpl {
015:
016: private XTIFFFaxDecoder decoder = null;
017:
018: // Fax compression related variables
019: long tiffT4Options;
020: long tiffT6Options;
021: int fillOrder;
022:
023: /**
024: * Public constructor
025: */
026: public XTIFFFaxTileCodec() {
027: }
028:
029: /**
030: * Creation method
031: */
032: public XTIFFTileCodec create() {
033: return new XTIFFFaxTileCodec();
034: }
035:
036: public boolean canEncode() {
037: return false;
038: }
039:
040: /**
041: * Registration method
042: */
043: public void register() {
044: register(XTIFF.COMPRESSION_FAX_G3_1D);
045: register(XTIFF.COMPRESSION_FAX_G3_2D);
046: register(XTIFF.COMPRESSION_FAX_G4_2D);
047: }
048:
049: /**
050: * The initialization method particular to Fax decoding.
051: */
052: public void initializeDecoding() {
053:
054: XTIFFField fillOrderField = directory
055: .getField(XTIFF.TIFFTAG_FILL_ORDER);
056: if (fillOrderField != null) {
057: fillOrder = fillOrderField.getAsInt(0);
058: } else {
059: // Default Fill Order
060: fillOrder = 1;
061: }
062: // Fax T.4 compression options
063: if (compression == 3) {
064: XTIFFField t4OptionsField = directory
065: .getField(XTIFF.TIFFTAG_T4_OPTIONS);
066: if (t4OptionsField != null) {
067: tiffT4Options = t4OptionsField.getAsLong(0);
068: } else {
069: // Use default value
070: tiffT4Options = 0;
071: }
072: }
073:
074: // Fax T.6 compression options
075: if (compression == 4) {
076: XTIFFField t6OptionsField = directory
077: .getField(XTIFF.TIFFTAG_T6_OPTIONS);
078: if (t6OptionsField != null) {
079: tiffT6Options = t6OptionsField.getAsLong(0);
080: } else {
081: // Use default value
082: tiffT6Options = 0;
083: }
084: }
085:
086: decoder = new XTIFFFaxDecoder(fillOrder, tileWidth, tileLength);
087:
088: }
089:
090: /**
091: * Decode a rectangle of pixels
092: */
093: public void decodeTilePixels(byte[] input, Rectangle newRect,
094: byte[] bdata) {
095: if (compression == XTIFF.COMPRESSION_FAX_G3_1D) {
096: decoder.decode1D(bdata, input, newRect.x, newRect.height);
097: } else if (compression == XTIFF.COMPRESSION_FAX_G3_2D) {
098: decoder.decode2D(bdata, input, newRect.x, newRect.height,
099: tiffT4Options);
100: } else if (compression == XTIFF.COMPRESSION_FAX_G4_2D) {
101: decoder.decodeT6(bdata, input, newRect.x, newRect.height,
102: tiffT6Options);
103: }
104: }
105:
106: /**
107: * Decode a rectangle of pixels
108: */
109: public void decodeTilePixels(byte[] input, Rectangle newRect,
110: short[] sdata) {
111: //not used for fax.
112: }
113: }
|