I'm dealing with CIP3 files - they're files with mixed content (binary\text). I've got a file that its image data is compressed with RunLengthDecode filter (from PostScript) and encoded with ASCIIHexDecode.
ASCIIHexDecode its okay (just convert binary to hex), but i can't find a decent RLE Decompression Algorithm. I've searched on google a lot, StackOverflow, everywhere - before asking. Can anyone give me any input on this subject ?
Until now i've tried to decompress by using this algorithm:
public enum EncodingFormat
{
Old,
New,
}
public static class Rle
{
public const char EOF = '\u007F';
public const char ESCAPE = '\\';
private static bool HasChar(StringBuilder input)
{
for (var i = 0; i < input.Length; i++)
{
if (char.IsLetter(input[i]))
{
return true;
}
}
return false;
}
internal static void Decode(string input)
{
int fileCounter = 0;
//var runLengthEncodedString = new StringBuilder();
var baseString = input;
var radix = 0;
for (var i = 0; i < baseString.Length; i++)
{
if (char.IsNumber(baseString[i]))
{
radix++;
}
else
{
if (radix > 0)
{
try
{
var valueRepeat = Convert.ToInt64(baseString.Substring(i - radix, radix));
for (var j = 0; j < valueRepeat; j++)
{
File.AppendAllText(@"C:\test\hexdecoded.txt",baseString[i].ToString());
}
radix = 0;
}
catch(Exception e)
{
var checkI = i;
}
}
else if (radix == 0)
{
File.AppendAllText(@"C:\test\hexdecoded.txt", baseString[i].ToString());
}
}
}
}
internal static double GetPercentage(double x, double y)
{
return (100 * (x - y)) / x;
}
}
Must say that i've found this code on StackOverflow but can't remember where now. I changed to output the contents to the disk because i was getting a memory exception error. But it takes years to decompress my image (waited for one hour and still decompressing). If i manage to correct decompress this RLE image, i can convert it into bytes and then create a proper TIFF file.
I've uploaded a sample of the file i'm using for tests: CIP3 File Sample
Any input is appreciated. Thanks.