public ImgReaderPGX(System.IO.Stream in_Renamed)
{
System.String header;
//Opens the given file
this.in_Renamed = in_Renamed;
try
{
System.IO.StreamReader in_reader = new System.IO.StreamReader(this.in_Renamed);
//UPGRADE_ISSUE: Method 'java.io.RandomAccessFile.readLine' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioRandomAccessFilereadLine'"
header = in_reader.ReadLine();
}
catch (System.IO.IOException e)
{
throw new System.IO.IOException("Not a PGX file");
}
if (header == null)
{
throw new System.IO.IOException("Empty file");
}
offset = (header.Length + 1);
//Get informations from header
SupportClass.Tokenizer st = new SupportClass.Tokenizer(header);
try
{
int nTokens = st.Count;
// Magic Number
if (!(st.NextToken()).Equals("PG"))
throw new System.IO.IOException("Not a PGX file");
// Endianess
System.String tmp = st.NextToken();
if (tmp.Equals("LM"))
byteOrder = CSJ2K.j2k.io.EndianType_Fields.LITTLE_ENDIAN;
else if (tmp.Equals("ML"))
byteOrder = CSJ2K.j2k.io.EndianType_Fields.BIG_ENDIAN;
else
throw new System.IO.IOException("Not a PGX file");
// Unsigned/signed if present in the header
if (nTokens == 6)
{
tmp = st.NextToken();
if (tmp.Equals("+"))
isSigned = false;
else if (tmp.Equals("-"))
isSigned = true;
else
throw new System.IO.IOException("Not a PGX file");
}
// bit-depth, width, height
try
{
bitDepth = (System.Int32.Parse(st.NextToken()));
// bitDepth must be between 1 and 31
if ((bitDepth <= 0) || (bitDepth > 31))
throw new System.IO.IOException("Not a PGX file");
w = (System.Int32.Parse(st.NextToken()));
h = (System.Int32.Parse(st.NextToken()));
}
catch (System.FormatException e)
{
throw new System.IO.IOException("Not a PGX file");
}
}
catch (System.ArgumentOutOfRangeException e)
{
throw new System.IO.IOException("Not a PGX file");
}
// Number of component
nc = 1;
// Number of bytes per data
if (bitDepth <= 8)
packBytes = 1;
else if (bitDepth <= 16)
packBytes = 2;
// <= 31
else
packBytes = 4;
}