public bool Decode(ref int address, ref int bufSize, mDecoders method) { byte[] buf; byte[] bufIn = new byte[bufSize]; if (mAllocAddr != 0) ReleaseMem(); try { Marshal.Copy((IntPtr)address, bufIn, 0, bufSize); if (DebugMode) MessageBox.Show("itf> Received Data size: " + bufIn.Length.ToString("X") + "Data:\n\n" + HexDumper.HexDump(bufIn)); switch (method) { case mDecoders.FlateDecode: buf = ByteDecoder.FlateDecode(bufIn, true); break; case mDecoders.ASCIIHexDecode: buf = ByteDecoder.ASCIIHexDecode(bufIn); break; case mDecoders.ASCII85Decode: buf = ByteDecoder.ASCII85Decode(bufIn); break; case mDecoders.LzwDecode: buf = ByteDecoder.LzwDecode(bufIn); break; case mDecoders.RunLengthDecode: buf = ByteDecoder.RunLengthDecode(bufIn); break; case mDecoders.DecodePredictor: buf = ByteDecoder.DecodePredictor(bufIn, mpredictor, mcolumns, mcolors, mbitspercomponent); break; case mDecoders.CCITTFaxDecode: buf = ByteDecoder.FaxDecode(bufIn, mcolumns, mrows, mk, mencoded_byte_align, mblack_is1); break; default: mErrorMessage = "Unknown decode method: " + method ; return false; } if (buf.Length == 0) { mErrorMessage = "iText_Filters Error: decoded buffer length=0"; return false; } if (DebugMode) MessageBox.Show("itf> ByteDecoder output size: " + buf.Length.ToString("X") + "Data:\n\n" + HexDumper.HexDump(buf)); mAllocSize = buf.Length; mAllocAddr = (int)Marshal.AllocHGlobal(mAllocSize); Marshal.Copy(buf, 0, (IntPtr)mAllocAddr, mAllocSize); address = mAllocAddr; //these are byref so we pass back the new memory address and size like this bufSize = mAllocSize; return true; } catch (Exception e) { if (DebugMode) MessageBox.Show("itf> Exception Caught: " + e.ToString() ); mErrorMessage = "iText_Filters Error: Caught Exception: " + e.ToString(); return false; } }
public bool Decode(ref int address, ref int bufSize, mDecoders method) { byte[] buf; byte[] bufIn = new byte[bufSize]; if (mAllocAddr != 0) { ReleaseMem(); } try { Marshal.Copy((IntPtr)address, bufIn, 0, bufSize); if (DebugMode) { MessageBox.Show("itf> Received Data size: " + bufIn.Length.ToString("X") + "Data:\n\n" + HexDumper.HexDump(bufIn)); } switch (method) { case mDecoders.FlateDecode: buf = ByteDecoder.FlateDecode(bufIn, true); break; case mDecoders.ASCIIHexDecode: buf = ByteDecoder.ASCIIHexDecode(bufIn); break; case mDecoders.ASCII85Decode: buf = ByteDecoder.ASCII85Decode(bufIn); break; case mDecoders.LzwDecode: buf = ByteDecoder.LzwDecode(bufIn); break; case mDecoders.RunLengthDecode: buf = ByteDecoder.RunLengthDecode(bufIn); break; case mDecoders.DecodePredictor: buf = ByteDecoder.DecodePredictor(bufIn, mpredictor, mcolumns, mcolors, mbitspercomponent); break; case mDecoders.CCITTFaxDecode: buf = ByteDecoder.FaxDecode(bufIn, mcolumns, mrows, mk, mencoded_byte_align, mblack_is1); break; default: mErrorMessage = "Unknown decode method: " + method; return(false); } if (buf.Length == 0) { mErrorMessage = "iText_Filters Error: decoded buffer length=0"; return(false); } if (DebugMode) { MessageBox.Show("itf> ByteDecoder output size: " + buf.Length.ToString("X") + "Data:\n\n" + HexDumper.HexDump(buf)); } mAllocSize = buf.Length; mAllocAddr = (int)Marshal.AllocHGlobal(mAllocSize); Marshal.Copy(buf, 0, (IntPtr)mAllocAddr, mAllocSize); address = mAllocAddr; //these are byref so we pass back the new memory address and size like this bufSize = mAllocSize; return(true); } catch (Exception e) { if (DebugMode) { MessageBox.Show("itf> Exception Caught: " + e.ToString()); } mErrorMessage = "iText_Filters Error: Caught Exception: " + e.ToString(); return(false); } }