internal int Read(IDataStream data) { int count = 0; int length = data.Get16(); count += 2; Precision = data.Get8(); count++; DimY = data.Get16(); count += 2; DimX = data.Get16(); count += 2; NumComponents = data.Get8(); count++; //components = new ComponentSpec[numComp]; // some image exceed this range... Components = new ComponentSpec[256]; // setting to 256 -- not sure what it should be. for (int i = 1; i <= NumComponents; i++) { if (count > length) { throw new IOException("ERROR: frame format error"); } int c = data.Get8(); count++; if (count >= length) { throw new IOException("ERROR: frame format error [c>=Lf]"); } int temp = data.Get8(); count++; if (Components[c] == null) { Components[c] = new ComponentSpec(); } Components[c].hSamp = temp >> 4; Components[c].vSamp = temp & 0x0F; Components[c].quantTableSel = data.Get8(); count++; } if (count != length) { throw new IOException("ERROR: frame format error [Lf!=count]"); } return(1); }
internal int Read(IDataStream data) { int count = 0; int length = data.Get16(); count += 2; NumComponents = data.Get8(); count++; components = new ScanComponent[NumComponents]; for (int i = 0; i < NumComponents; i++) { components[i] = new ScanComponent(); if (count > length) { throw new IOException("ERROR: scan header format error"); } components[i].ScanCompSel = data.Get8(); count++; int tempval = data.Get8(); count++; components[i].DcTabSel = tempval >> 4; components[i].AcTabSel = tempval & 0x0F; } Selection = data.Get8(); count++; SpectralEnd = data.Get8(); count++; int temp = data.Get8(); Ah = temp >> 4; Al = temp & 0x0F; count++; if (count != length) { throw new IOException("ERROR: scan header format error [count!=Ns]"); } return(1); }
internal int Read(IDataStream data, int[] table) { int count = 0; int length = data.Get16(); count += 2; while (count < length) { int temp = data.Get8(); count++; int t = temp & 0x0F; if (t > 3) { throw new IOException("ERROR: Quantization table ID > 3"); } _precision[t] = temp >> 4; if (_precision[t] == 0) { _precision[t] = 8; } else if (_precision[t] == 1) { _precision[t] = 16; } else { throw new IOException("ERROR: Quantization table precision error"); } _tq[t] = 1; if (_precision[t] == 8) { for (int i = 0; i < 64; i++) { if (count > length) { throw new IOException("ERROR: Quantization table format error"); } quantTables[t][i] = data.Get8(); count++; } EnhanceQuantizationTable(quantTables[t], table); } else { for (int i = 0; i < 64; i++) { if (count > length) { throw new IOException("ERROR: Quantization table format error"); } quantTables[t][i] = data.Get16(); count += 2; } EnhanceQuantizationTable(quantTables[t], table); } } if (count != length) { throw new IOException("ERROR: Quantization table error [count!=Lq]"); } return(1); }
internal int Read(IDataStream data, int[, ][] HuffTab) { int count = 0; int length = data.Get16(); count += 2; while (count < length) { int temp = data.Get8(); count++; int t = temp & 0x0F; if (t > 3) { throw new IOException("ERROR: Huffman table ID > 3"); } int c = temp >> 4; if (c > 2) { throw new IOException("ERROR: Huffman table [Table class > 2 ]"); } _th[t] = 1; _tc[t, c] = 1; for (int i = 0; i < 16; i++) { _l[t, c][i] = data.Get8(); count++; } for (int i = 0; i < 16; i++) { for (int j = 0; j < _l[t, c][i]; j++) { if (count > length) { throw new IOException("ERROR: Huffman table format error [count>Lh]"); } _v[t, c][i, j] = data.Get8(); count++; } } } if (count != length) { throw new IOException("ERROR: Huffman table format error [count!=Lf]"); } for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { if (_tc[i, j] != 0) { BuildHuffTable(HuffTab[i, j], _l[i, j], _v[i, j]); } } } return(1); }