Files
2026-06-04 11:42:34 +02:00

905 lines
26 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using Hjg.Pngcs.Chunks;
using Hjg.Pngcs.Zlib;
namespace Hjg.Pngcs
{
// Token: 0x0200003E RID: 62
public class PngReader
{
// Token: 0x1700002F RID: 47
// (get) Token: 0x06000210 RID: 528 RVA: 0x0000825D File Offset: 0x0000645D
// (set) Token: 0x06000211 RID: 529 RVA: 0x00008265 File Offset: 0x00006465
public ImageInfo ImgInfo { get; private set; }
// Token: 0x17000030 RID: 48
// (get) Token: 0x06000212 RID: 530 RVA: 0x0000826E File Offset: 0x0000646E
// (set) Token: 0x06000213 RID: 531 RVA: 0x00008276 File Offset: 0x00006476
public ChunkLoadBehaviour ChunkLoadBehaviour { get; set; }
// Token: 0x17000031 RID: 49
// (get) Token: 0x06000214 RID: 532 RVA: 0x0000827F File Offset: 0x0000647F
// (set) Token: 0x06000215 RID: 533 RVA: 0x00008287 File Offset: 0x00006487
public bool ShouldCloseStream { get; set; }
// Token: 0x17000032 RID: 50
// (get) Token: 0x06000216 RID: 534 RVA: 0x00008290 File Offset: 0x00006490
// (set) Token: 0x06000217 RID: 535 RVA: 0x00008298 File Offset: 0x00006498
public long MaxBytesMetadata { get; set; }
// Token: 0x17000033 RID: 51
// (get) Token: 0x06000218 RID: 536 RVA: 0x000082A1 File Offset: 0x000064A1
// (set) Token: 0x06000219 RID: 537 RVA: 0x000082A9 File Offset: 0x000064A9
public long MaxTotalBytesRead { get; set; }
// Token: 0x17000034 RID: 52
// (get) Token: 0x0600021A RID: 538 RVA: 0x000082B2 File Offset: 0x000064B2
// (set) Token: 0x0600021B RID: 539 RVA: 0x000082BA File Offset: 0x000064BA
public int SkipChunkMaxSize { get; set; }
// Token: 0x17000035 RID: 53
// (get) Token: 0x0600021C RID: 540 RVA: 0x000082C3 File Offset: 0x000064C3
// (set) Token: 0x0600021D RID: 541 RVA: 0x000082CB File Offset: 0x000064CB
public string[] SkipChunkIds { get; set; }
// Token: 0x17000036 RID: 54
// (get) Token: 0x0600021E RID: 542 RVA: 0x000082D4 File Offset: 0x000064D4
// (set) Token: 0x0600021F RID: 543 RVA: 0x000082DC File Offset: 0x000064DC
public int CurrentChunkGroup { get; private set; }
// Token: 0x06000220 RID: 544 RVA: 0x000082E5 File Offset: 0x000064E5
public PngReader(Stream inputStream)
: this(inputStream, "[NO FILENAME AVAILABLE]")
{
}
// Token: 0x06000221 RID: 545 RVA: 0x000082F4 File Offset: 0x000064F4
public PngReader(Stream inputStream, string filename)
{
this.filename = ((filename == null) ? "" : filename);
this.inputStream = inputStream;
this.chunksList = new ChunksList(null);
this.metadata = new PngMetadata(this.chunksList);
this.offset = 0L;
this.CurrentChunkGroup = -1;
this.ShouldCloseStream = true;
this.MaxBytesMetadata = 5242880L;
this.MaxTotalBytesRead = 209715200L;
this.SkipChunkMaxSize = 2097152;
this.SkipChunkIds = new string[] { "fdAT" };
this.ChunkLoadBehaviour = ChunkLoadBehaviour.LOAD_CHUNK_ALWAYS;
byte[] array = new byte[8];
PngHelperInternal.ReadBytes(inputStream, array, 0, array.Length);
this.offset += (long)array.Length;
if (!PngCsUtils.arraysEqual(array, PngHelperInternal.PNG_ID_SIGNATURE))
{
throw new PngjInputException("Bad PNG signature");
}
this.CurrentChunkGroup = 0;
int num = PngHelperInternal.ReadInt4(inputStream);
this.offset += 4L;
if (num != 13)
{
throw new Exception("IDHR chunk len != 13 ?? " + num);
}
byte[] array2 = new byte[4];
PngHelperInternal.ReadBytes(inputStream, array2, 0, 4);
if (!PngCsUtils.arraysEqual4(array2, ChunkHelper.b_IHDR))
{
throw new PngjInputException("IHDR not found as first chunk??? [" + ChunkHelper.ToString(array2) + "]");
}
this.offset += 4L;
PngChunkIHDR pngChunkIHDR = (PngChunkIHDR)this.ReadChunk(array2, num, false);
bool flag = (pngChunkIHDR.Colormodel & 4) != 0;
bool flag2 = (pngChunkIHDR.Colormodel & 1) != 0;
bool flag3 = pngChunkIHDR.Colormodel == 0 || pngChunkIHDR.Colormodel == 4;
this.ImgInfo = new ImageInfo(pngChunkIHDR.Cols, pngChunkIHDR.Rows, pngChunkIHDR.Bitspc, flag, flag3, flag2);
this.rowb = new byte[this.ImgInfo.BytesPerRow + 1];
this.rowbprev = new byte[this.rowb.Length];
this.rowbfilter = new byte[this.rowb.Length];
this.interlaced = pngChunkIHDR.Interlaced == 1;
this.deinterlacer = (this.interlaced ? new PngDeinterlacer(this.ImgInfo) : null);
if (pngChunkIHDR.Filmeth != 0 || pngChunkIHDR.Compmeth != 0 || (pngChunkIHDR.Interlaced & 65534) != 0)
{
throw new PngjInputException("compmethod or filtermethod or interlaced unrecognized");
}
if (pngChunkIHDR.Colormodel < 0 || pngChunkIHDR.Colormodel > 6 || pngChunkIHDR.Colormodel == 1 || pngChunkIHDR.Colormodel == 5)
{
throw new PngjInputException("Invalid colormodel " + pngChunkIHDR.Colormodel);
}
if (pngChunkIHDR.Bitspc != 1 && pngChunkIHDR.Bitspc != 2 && pngChunkIHDR.Bitspc != 4 && pngChunkIHDR.Bitspc != 8 && pngChunkIHDR.Bitspc != 16)
{
throw new PngjInputException("Invalid bit depth " + pngChunkIHDR.Bitspc);
}
}
// Token: 0x06000222 RID: 546 RVA: 0x000085DF File Offset: 0x000067DF
private bool FirstChunksNotYetRead()
{
return this.CurrentChunkGroup < 1;
}
// Token: 0x06000223 RID: 547 RVA: 0x000085EC File Offset: 0x000067EC
private void ReadLastAndClose()
{
if (this.CurrentChunkGroup < 5)
{
try
{
this.idatIstream.Close();
}
catch (Exception)
{
}
this.ReadLastChunks();
}
this.Close();
}
// Token: 0x06000224 RID: 548 RVA: 0x00008630 File Offset: 0x00006830
private void Close()
{
if (this.CurrentChunkGroup < 6)
{
try
{
this.idatIstream.Close();
}
catch (Exception)
{
}
this.CurrentChunkGroup = 6;
}
if (this.ShouldCloseStream)
{
this.inputStream.Close();
}
}
// Token: 0x06000225 RID: 549 RVA: 0x00008680 File Offset: 0x00006880
private void UnfilterRow(int nbytes)
{
int num = (int)this.rowbfilter[0];
switch (num)
{
case 0:
this.UnfilterRowNone(nbytes);
break;
case 1:
this.UnfilterRowSub(nbytes);
break;
case 2:
this.UnfilterRowUp(nbytes);
break;
case 3:
this.UnfilterRowAverage(nbytes);
break;
case 4:
this.UnfilterRowPaeth(nbytes);
break;
default:
throw new PngjInputException("Filter type " + num + " not implemented");
}
if (this.crctest != null)
{
this.crctest.Update(this.rowb, 1, nbytes);
}
}
// Token: 0x06000226 RID: 550 RVA: 0x0000871C File Offset: 0x0000691C
private void UnfilterRowAverage(int nbytes)
{
int num = 1 - this.ImgInfo.BytesPixel;
int i = 1;
while (i <= nbytes)
{
int num2 = (int)((num > 0) ? this.rowb[num] : 0);
this.rowb[i] = (byte)((int)this.rowbfilter[i] + (num2 + (int)(this.rowbprev[i] & byte.MaxValue)) / 2);
i++;
num++;
}
}
// Token: 0x06000227 RID: 551 RVA: 0x0000877C File Offset: 0x0000697C
private void UnfilterRowNone(int nbytes)
{
for (int i = 1; i <= nbytes; i++)
{
this.rowb[i] = this.rowbfilter[i];
}
}
// Token: 0x06000228 RID: 552 RVA: 0x000087A8 File Offset: 0x000069A8
private void UnfilterRowPaeth(int nbytes)
{
int num = 1 - this.ImgInfo.BytesPixel;
int i = 1;
while (i <= nbytes)
{
int num2 = (int)((num > 0) ? this.rowb[num] : 0);
int num3 = (int)((num > 0) ? this.rowbprev[num] : 0);
this.rowb[i] = (byte)((int)this.rowbfilter[i] + PngHelperInternal.FilterPaethPredictor(num2, (int)this.rowbprev[i], num3));
i++;
num++;
}
}
// Token: 0x06000229 RID: 553 RVA: 0x00008814 File Offset: 0x00006A14
private void UnfilterRowSub(int nbytes)
{
int i;
for (i = 1; i <= this.ImgInfo.BytesPixel; i++)
{
this.rowb[i] = this.rowbfilter[i];
}
int num = 1;
i = this.ImgInfo.BytesPixel + 1;
while (i <= nbytes)
{
this.rowb[i] = this.rowbfilter[i] + this.rowb[num];
i++;
num++;
}
}
// Token: 0x0600022A RID: 554 RVA: 0x00008880 File Offset: 0x00006A80
private void UnfilterRowUp(int nbytes)
{
for (int i = 1; i <= nbytes; i++)
{
this.rowb[i] = this.rowbfilter[i] + this.rowbprev[i];
}
}
// Token: 0x0600022B RID: 555 RVA: 0x000088B4 File Offset: 0x00006AB4
private void ReadFirstChunks()
{
if (!this.FirstChunksNotYetRead())
{
return;
}
int num = 0;
bool flag = false;
byte[] array = new byte[4];
this.CurrentChunkGroup = 1;
while (!flag)
{
num = PngHelperInternal.ReadInt4(this.inputStream);
this.offset += 4L;
if (num < 0)
{
break;
}
PngHelperInternal.ReadBytes(this.inputStream, array, 0, 4);
this.offset += 4L;
if (PngCsUtils.arraysEqual4(array, ChunkHelper.b_IDAT))
{
flag = true;
this.CurrentChunkGroup = 4;
this.chunksList.AppendReadChunk(new PngChunkIDAT(this.ImgInfo, num, this.offset - 8L), this.CurrentChunkGroup);
break;
}
if (PngCsUtils.arraysEqual4(array, ChunkHelper.b_IEND))
{
throw new PngjInputException("END chunk found before image data (IDAT) at offset=" + this.offset);
}
string text = ChunkHelper.ToString(array);
if (text.Equals("PLTE"))
{
this.CurrentChunkGroup = 2;
}
this.ReadChunk(array, num, false);
if (text.Equals("PLTE"))
{
this.CurrentChunkGroup = 3;
}
}
int num2 = (flag ? num : (-1));
if (num2 < 0)
{
throw new PngjInputException("first idat chunk not found!");
}
this.iIdatCstream = new PngIDatChunkInputStream(this.inputStream, num2, this.offset);
this.idatIstream = ZlibStreamFactory.createZlibInputStream(this.iIdatCstream, true);
if (!this.crcEnabled)
{
this.iIdatCstream.DisableCrcCheck();
}
}
// Token: 0x0600022C RID: 556 RVA: 0x00008A1C File Offset: 0x00006C1C
private void ReadLastChunks()
{
this.CurrentChunkGroup = 5;
if (!this.iIdatCstream.IsEnded())
{
this.iIdatCstream.ForceChunkEnd();
}
int num = this.iIdatCstream.GetLenLastChunk();
byte[] idLastChunk = this.iIdatCstream.GetIdLastChunk();
bool flag = false;
bool flag2 = true;
while (!flag)
{
bool flag3 = false;
if (!flag2)
{
num = PngHelperInternal.ReadInt4(this.inputStream);
this.offset += 4L;
if (num < 0)
{
throw new PngjInputException("bad len " + num);
}
PngHelperInternal.ReadBytes(this.inputStream, idLastChunk, 0, 4);
this.offset += 4L;
}
flag2 = false;
if (PngCsUtils.arraysEqual4(idLastChunk, ChunkHelper.b_IDAT))
{
flag3 = true;
}
else if (PngCsUtils.arraysEqual4(idLastChunk, ChunkHelper.b_IEND))
{
this.CurrentChunkGroup = 6;
flag = true;
}
this.ReadChunk(idLastChunk, num, flag3);
}
if (!flag)
{
throw new PngjInputException("end chunk not found - offset=" + this.offset);
}
}
// Token: 0x0600022D RID: 557 RVA: 0x00008B20 File Offset: 0x00006D20
private PngChunk ReadChunk(byte[] chunkid, int clen, bool skipforced)
{
if (clen < 0)
{
throw new PngjInputException("invalid chunk lenght: " + clen);
}
if (this.skipChunkIdsSet == null && this.CurrentChunkGroup > 0)
{
this.skipChunkIdsSet = new Dictionary<string, int>();
if (this.SkipChunkIds != null)
{
foreach (string text in this.SkipChunkIds)
{
this.skipChunkIdsSet.Add(text, 1);
}
}
}
string text2 = ChunkHelper.ToString(chunkid);
bool flag = ChunkHelper.IsCritical(text2);
bool flag2 = skipforced;
if (this.MaxTotalBytesRead > 0L && (long)clen + this.offset > this.MaxTotalBytesRead)
{
throw new PngjInputException(string.Concat(new object[] { "Maximum total bytes to read exceeeded: ", this.MaxTotalBytesRead, " offset:", this.offset, " clen=", clen }));
}
if (this.CurrentChunkGroup > 0 && !ChunkHelper.IsCritical(text2))
{
flag2 = flag2 || (this.SkipChunkMaxSize > 0 && clen >= this.SkipChunkMaxSize) || this.skipChunkIdsSet.ContainsKey(text2) || (this.MaxBytesMetadata > 0L && (long)clen > this.MaxBytesMetadata - (long)this.bytesChunksLoaded) || !ChunkHelper.ShouldLoad(text2, this.ChunkLoadBehaviour);
}
PngChunk pngChunk;
if (flag2)
{
PngHelperInternal.SkipBytes(this.inputStream, clen);
PngHelperInternal.ReadInt4(this.inputStream);
pngChunk = new PngChunkSkipped(text2, this.ImgInfo, clen);
}
else
{
ChunkRaw chunkRaw = new ChunkRaw(clen, chunkid, true);
chunkRaw.ReadChunkData(this.inputStream, this.crcEnabled || flag);
pngChunk = PngChunk.Factory(chunkRaw, this.ImgInfo);
if (!pngChunk.Crit)
{
this.bytesChunksLoaded += chunkRaw.Length;
}
}
pngChunk.Offset = this.offset - 8L;
this.chunksList.AppendReadChunk(pngChunk, this.CurrentChunkGroup);
this.offset += (long)clen + 4L;
return pngChunk;
}
// Token: 0x0600022E RID: 558 RVA: 0x00008D32 File Offset: 0x00006F32
internal void logWarn(string warn)
{
Console.Error.WriteLine(warn);
}
// Token: 0x0600022F RID: 559 RVA: 0x00008D3F File Offset: 0x00006F3F
public ChunksList GetChunksList()
{
if (this.FirstChunksNotYetRead())
{
this.ReadFirstChunks();
}
return this.chunksList;
}
// Token: 0x06000230 RID: 560 RVA: 0x00008D55 File Offset: 0x00006F55
public PngMetadata GetMetadata()
{
if (this.FirstChunksNotYetRead())
{
this.ReadFirstChunks();
}
return this.metadata;
}
// Token: 0x06000231 RID: 561 RVA: 0x00008D6B File Offset: 0x00006F6B
public ImageLine ReadRow(int nrow)
{
if (this.imgLine != null && this.imgLine.SampleType == ImageLine.ESampleType.BYTE)
{
return this.ReadRowByte(nrow);
}
return this.ReadRowInt(nrow);
}
// Token: 0x06000232 RID: 562 RVA: 0x00008D94 File Offset: 0x00006F94
public ImageLine ReadRowInt(int nrow)
{
if (this.imgLine == null)
{
this.imgLine = new ImageLine(this.ImgInfo, ImageLine.ESampleType.INT, this.unpackedMode);
}
if (this.imgLine.Rown == nrow)
{
return this.imgLine;
}
this.ReadRowInt(this.imgLine.Scanline, nrow);
this.imgLine.FilterUsed = (FilterType)this.rowbfilter[0];
this.imgLine.Rown = nrow;
return this.imgLine;
}
// Token: 0x06000233 RID: 563 RVA: 0x00008E10 File Offset: 0x00007010
public ImageLine ReadRowByte(int nrow)
{
if (this.imgLine == null)
{
this.imgLine = new ImageLine(this.ImgInfo, ImageLine.ESampleType.BYTE, this.unpackedMode);
}
if (this.imgLine.Rown == nrow)
{
return this.imgLine;
}
this.ReadRowByte(this.imgLine.ScanlineB, nrow);
this.imgLine.FilterUsed = (FilterType)this.rowbfilter[0];
this.imgLine.Rown = nrow;
return this.imgLine;
}
// Token: 0x06000234 RID: 564 RVA: 0x00008E8A File Offset: 0x0000708A
public int[] ReadRow(int[] buffer, int nrow)
{
return this.ReadRowInt(buffer, nrow);
}
// Token: 0x06000235 RID: 565 RVA: 0x00008E94 File Offset: 0x00007094
public int[] ReadRowInt(int[] buffer, int nrow)
{
if (buffer == null)
{
buffer = new int[this.unpackedMode ? this.ImgInfo.SamplesPerRow : this.ImgInfo.SamplesPerRowPacked];
}
if (!this.interlaced)
{
if (nrow <= this.rowNum)
{
throw new PngjInputException("rows must be read in increasing order: " + nrow);
}
int num = 0;
while (this.rowNum < nrow)
{
num = this.ReadRowRaw(this.rowNum + 1);
}
this.decodeLastReadRowToInt(buffer, num);
}
else
{
if (this.deinterlacer.getImageInt() == null)
{
this.deinterlacer.setImageInt(this.ReadRowsInt().Scanlines);
}
Array.Copy(this.deinterlacer.getImageInt()[nrow], 0, buffer, 0, this.unpackedMode ? this.ImgInfo.SamplesPerRow : this.ImgInfo.SamplesPerRowPacked);
}
return buffer;
}
// Token: 0x06000236 RID: 566 RVA: 0x00008F74 File Offset: 0x00007174
public byte[] ReadRowByte(byte[] buffer, int nrow)
{
if (buffer == null)
{
buffer = new byte[this.unpackedMode ? this.ImgInfo.SamplesPerRow : this.ImgInfo.SamplesPerRowPacked];
}
if (!this.interlaced)
{
if (nrow <= this.rowNum)
{
throw new PngjInputException("rows must be read in increasing order: " + nrow);
}
int num = 0;
while (this.rowNum < nrow)
{
num = this.ReadRowRaw(this.rowNum + 1);
}
this.decodeLastReadRowToByte(buffer, num);
}
else
{
if (this.deinterlacer.getImageByte() == null)
{
this.deinterlacer.setImageByte(this.ReadRowsByte().ScanlinesB);
}
Array.Copy(this.deinterlacer.getImageByte()[nrow], 0, buffer, 0, this.unpackedMode ? this.ImgInfo.SamplesPerRow : this.ImgInfo.SamplesPerRowPacked);
}
return buffer;
}
// Token: 0x06000237 RID: 567 RVA: 0x00009051 File Offset: 0x00007251
[Obsolete("GetRow is deprecated, use ReadRow/ReadRowInt/ReadRowByte instead.")]
public ImageLine GetRow(int nrow)
{
return this.ReadRow(nrow);
}
// Token: 0x06000238 RID: 568 RVA: 0x0000905C File Offset: 0x0000725C
private void decodeLastReadRowToInt(int[] buffer, int bytesRead)
{
if (this.ImgInfo.BitDepth <= 8)
{
int i = 0;
int num = 1;
while (i < bytesRead)
{
buffer[i] = (int)this.rowb[num++];
i++;
}
}
else
{
int num2 = 0;
int j = 1;
while (j < bytesRead)
{
buffer[num2] = ((int)this.rowb[j++] << 8) + (int)this.rowb[j++];
num2++;
}
}
if (this.ImgInfo.Packed && this.unpackedMode)
{
ImageLine.unpackInplaceInt(this.ImgInfo, buffer, buffer, false);
}
}
// Token: 0x06000239 RID: 569 RVA: 0x000090E8 File Offset: 0x000072E8
private void decodeLastReadRowToByte(byte[] buffer, int bytesRead)
{
if (this.ImgInfo.BitDepth <= 8)
{
Array.Copy(this.rowb, 1, buffer, 0, bytesRead);
}
else
{
int num = 0;
for (int i = 1; i < bytesRead; i += 2)
{
buffer[num] = this.rowb[i];
num++;
}
}
if (this.ImgInfo.Packed && this.unpackedMode)
{
ImageLine.unpackInplaceByte(this.ImgInfo, buffer, buffer, false);
}
}
// Token: 0x0600023A RID: 570 RVA: 0x00009154 File Offset: 0x00007354
public ImageLines ReadRowsInt(int rowOffset, int nRows, int rowStep)
{
if (nRows < 0)
{
nRows = (this.ImgInfo.Rows - rowOffset) / rowStep;
}
if (rowStep < 1 || rowOffset < 0 || nRows * rowStep + rowOffset > this.ImgInfo.Rows)
{
throw new PngjInputException("bad args");
}
ImageLines imageLines = new ImageLines(this.ImgInfo, ImageLine.ESampleType.INT, this.unpackedMode, rowOffset, nRows, rowStep);
if (!this.interlaced)
{
for (int i = 0; i < this.ImgInfo.Rows; i++)
{
int num = this.ReadRowRaw(i);
int num2 = imageLines.ImageRowToMatrixRowStrict(i);
if (num2 >= 0)
{
this.decodeLastReadRowToInt(imageLines.Scanlines[num2], num);
}
}
}
else
{
int[] array = new int[this.unpackedMode ? this.ImgInfo.SamplesPerRow : this.ImgInfo.SamplesPerRowPacked];
for (int j = 1; j <= 7; j++)
{
this.deinterlacer.setPass(j);
for (int k = 0; k < this.deinterlacer.getRows(); k++)
{
int num3 = this.ReadRowRaw(k);
int currRowReal = this.deinterlacer.getCurrRowReal();
int num4 = imageLines.ImageRowToMatrixRowStrict(currRowReal);
if (num4 >= 0)
{
this.decodeLastReadRowToInt(array, num3);
this.deinterlacer.deinterlaceInt(array, imageLines.Scanlines[num4], !this.unpackedMode);
}
}
}
}
this.End();
return imageLines;
}
// Token: 0x0600023B RID: 571 RVA: 0x000092AE File Offset: 0x000074AE
public ImageLines ReadRowsInt()
{
return this.ReadRowsInt(0, this.ImgInfo.Rows, 1);
}
// Token: 0x0600023C RID: 572 RVA: 0x000092C4 File Offset: 0x000074C4
public ImageLines ReadRowsByte(int rowOffset, int nRows, int rowStep)
{
if (nRows < 0)
{
nRows = (this.ImgInfo.Rows - rowOffset) / rowStep;
}
if (rowStep < 1 || rowOffset < 0 || nRows * rowStep + rowOffset > this.ImgInfo.Rows)
{
throw new PngjInputException("bad args");
}
ImageLines imageLines = new ImageLines(this.ImgInfo, ImageLine.ESampleType.BYTE, this.unpackedMode, rowOffset, nRows, rowStep);
if (!this.interlaced)
{
for (int i = 0; i < this.ImgInfo.Rows; i++)
{
int num = this.ReadRowRaw(i);
int num2 = imageLines.ImageRowToMatrixRowStrict(i);
if (num2 >= 0)
{
this.decodeLastReadRowToByte(imageLines.ScanlinesB[num2], num);
}
}
}
else
{
byte[] array = new byte[this.unpackedMode ? this.ImgInfo.SamplesPerRow : this.ImgInfo.SamplesPerRowPacked];
for (int j = 1; j <= 7; j++)
{
this.deinterlacer.setPass(j);
for (int k = 0; k < this.deinterlacer.getRows(); k++)
{
int num3 = this.ReadRowRaw(k);
int currRowReal = this.deinterlacer.getCurrRowReal();
int num4 = imageLines.ImageRowToMatrixRowStrict(currRowReal);
if (num4 >= 0)
{
this.decodeLastReadRowToByte(array, num3);
this.deinterlacer.deinterlaceByte(array, imageLines.ScanlinesB[num4], !this.unpackedMode);
}
}
}
}
this.End();
return imageLines;
}
// Token: 0x0600023D RID: 573 RVA: 0x0000941E File Offset: 0x0000761E
public ImageLines ReadRowsByte()
{
return this.ReadRowsByte(0, this.ImgInfo.Rows, 1);
}
// Token: 0x0600023E RID: 574 RVA: 0x00009434 File Offset: 0x00007634
private int ReadRowRaw(int nrow)
{
if (nrow == 0 && this.FirstChunksNotYetRead())
{
this.ReadFirstChunks();
}
if (nrow == 0 && this.interlaced)
{
Array.Clear(this.rowb, 0, this.rowb.Length);
}
int num = this.ImgInfo.BytesPerRow;
if (this.interlaced)
{
if (nrow < 0 || nrow > this.deinterlacer.getRows() || (nrow != 0 && nrow != this.deinterlacer.getCurrRowSubimg() + 1))
{
throw new PngjInputException("invalid row in interlaced mode: " + nrow);
}
this.deinterlacer.setRow(nrow);
num = (this.ImgInfo.BitspPixel * this.deinterlacer.getPixelsToRead() + 7) / 8;
if (num < 1)
{
throw new PngjExceptionInternal("wtf??");
}
}
else if (nrow < 0 || nrow >= this.ImgInfo.Rows || nrow != this.rowNum + 1)
{
throw new PngjInputException("invalid row: " + nrow);
}
this.rowNum = nrow;
byte[] array = this.rowb;
this.rowb = this.rowbprev;
this.rowbprev = array;
PngHelperInternal.ReadBytes(this.idatIstream, this.rowbfilter, 0, num + 1);
this.offset = this.iIdatCstream.GetOffset();
if (this.offset < 0L)
{
throw new PngjExceptionInternal("bad offset ??" + this.offset);
}
if (this.MaxTotalBytesRead > 0L && this.offset >= this.MaxTotalBytesRead)
{
throw new PngjInputException(string.Concat(new object[] { "Reading IDAT: Maximum total bytes to read exceeeded: ", this.MaxTotalBytesRead, " offset:", this.offset }));
}
this.rowb[0] = 0;
this.UnfilterRow(num);
this.rowb[0] = this.rowbfilter[0];
if ((this.rowNum == this.ImgInfo.Rows - 1 && !this.interlaced) || (this.interlaced && this.deinterlacer.isAtLastRow()))
{
this.ReadLastAndClose();
}
return num;
}
// Token: 0x0600023F RID: 575 RVA: 0x00009648 File Offset: 0x00007848
public void ReadSkippingAllRows()
{
if (this.FirstChunksNotYetRead())
{
this.ReadFirstChunks();
}
this.iIdatCstream.DisableCrcCheck();
try
{
int num;
do
{
num = this.iIdatCstream.Read(this.rowbfilter, 0, this.rowbfilter.Length);
}
while (num >= 0);
}
catch (IOException ex)
{
throw new PngjInputException("error in raw read of IDAT", ex);
}
this.offset = this.iIdatCstream.GetOffset();
if (this.offset < 0L)
{
throw new PngjExceptionInternal("bad offset ??" + this.offset);
}
if (this.MaxTotalBytesRead > 0L && this.offset >= this.MaxTotalBytesRead)
{
throw new PngjInputException(string.Concat(new object[] { "Reading IDAT: Maximum total bytes to read exceeeded: ", this.MaxTotalBytesRead, " offset:", this.offset }));
}
this.ReadLastAndClose();
}
// Token: 0x06000240 RID: 576 RVA: 0x00009740 File Offset: 0x00007940
public override string ToString()
{
return "filename=" + this.filename + " " + this.ImgInfo.ToString();
}
// Token: 0x06000241 RID: 577 RVA: 0x00009762 File Offset: 0x00007962
public void End()
{
if (this.CurrentChunkGroup < 6)
{
this.Close();
}
}
// Token: 0x06000242 RID: 578 RVA: 0x00009773 File Offset: 0x00007973
public bool IsInterlaced()
{
return this.interlaced;
}
// Token: 0x06000243 RID: 579 RVA: 0x0000977B File Offset: 0x0000797B
public void SetUnpackedMode(bool unPackedMode)
{
this.unpackedMode = unPackedMode;
}
// Token: 0x06000244 RID: 580 RVA: 0x00009784 File Offset: 0x00007984
public bool IsUnpackedMode()
{
return this.unpackedMode;
}
// Token: 0x06000245 RID: 581 RVA: 0x0000978C File Offset: 0x0000798C
public void SetCrcCheckDisabled()
{
this.crcEnabled = false;
}
// Token: 0x06000246 RID: 582 RVA: 0x00009795 File Offset: 0x00007995
internal long GetCrctestVal()
{
return (long)((ulong)this.crctest.GetValue());
}
// Token: 0x06000247 RID: 583 RVA: 0x000097A3 File Offset: 0x000079A3
internal void InitCrctest()
{
this.crctest = new Adler32();
}
// Token: 0x04000118 RID: 280
protected readonly string filename;
// Token: 0x04000119 RID: 281
private Dictionary<string, int> skipChunkIdsSet;
// Token: 0x0400011A RID: 282
private readonly PngMetadata metadata;
// Token: 0x0400011B RID: 283
private readonly ChunksList chunksList;
// Token: 0x0400011C RID: 284
protected ImageLine imgLine;
// Token: 0x0400011D RID: 285
protected byte[] rowb;
// Token: 0x0400011E RID: 286
protected byte[] rowbprev;
// Token: 0x0400011F RID: 287
protected byte[] rowbfilter;
// Token: 0x04000120 RID: 288
public readonly bool interlaced;
// Token: 0x04000121 RID: 289
private readonly PngDeinterlacer deinterlacer;
// Token: 0x04000122 RID: 290
private bool crcEnabled = true;
// Token: 0x04000123 RID: 291
private bool unpackedMode;
// Token: 0x04000124 RID: 292
protected int rowNum = -1;
// Token: 0x04000125 RID: 293
private long offset;
// Token: 0x04000126 RID: 294
private int bytesChunksLoaded;
// Token: 0x04000127 RID: 295
private readonly Stream inputStream;
// Token: 0x04000128 RID: 296
internal AZlibInputStream idatIstream;
// Token: 0x04000129 RID: 297
internal PngIDatChunkInputStream iIdatCstream;
// Token: 0x0400012A RID: 298
protected Adler32 crctest;
}
}