//not implemented into decode loop yet but debugged already... public static byte[] FaxDecode(byte[] src, int columns, int rows, int k, int encodedByteAlign, int blackIs1) { sbyte[] source = (sbyte[])(Array)src; int size = rows * ((columns + 7) >> 3); sbyte[] destination = new sbyte[size]; CCITTFaxDecoder decoder = new CCITTFaxDecoder(1, columns, rows); decoder.alignProperty = encodedByteAlign == 0 ? true : false; if (k == 0) { decoder.decodeT41D(destination, source, 0, rows); } else if (k > 0) { decoder.decodeT42D(destination, source, 0, rows); } else if (k < 0) { decoder.decodeT6(destination, source, 0, rows); } if (blackIs1 == 0) { for (int i = 0; i < destination.Length; i++) { // bitwise not destination[i] = (sbyte)~destination[i]; } } return((byte[])(Array)destination); }
public override byte[] Decode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header) { // get decode parameters PdfDictionary decodeParms = parameters as PdfDictionary; var ccittFaxParams = new CCITTFaxParams( K: decodeParms.GetInt(PdfName.K), endOfLine: decodeParms.GetBool(PdfName.EndOfLine), encodedByteAlign: decodeParms.GetBool(PdfName.EncodedByteAlign), columns: decodeParms.GetInt(PdfName.Columns), rows: decodeParms.GetInt(PdfName.Rows), endOfBlock: decodeParms.GetBool(PdfName.EndOfBlock), blackIs1: decodeParms.GetBool(PdfName.BlackIs1) ); var decoder = new CCITTFaxDecoder(data, ccittFaxParams); using (var output = new Bytes.Buffer()) { var currentByte = 0; while ((currentByte = decoder.ReadNextChar()) > -1) { output.Append(FiltersExtension.ToByte(currentByte)); } return(output.GetBuffer()); } }