354 lines
7.5 KiB
C#
354 lines
7.5 KiB
C#
using System;
|
|
|
|
namespace Hjg.Pngcs
|
|
{
|
|
// Token: 0x0200001A RID: 26
|
|
internal class PngDeinterlacer
|
|
{
|
|
// Token: 0x060000D4 RID: 212 RVA: 0x00004448 File Offset: 0x00002648
|
|
internal PngDeinterlacer(ImageInfo iminfo)
|
|
{
|
|
this.imi = iminfo;
|
|
this.pass = 0;
|
|
if (this.imi.Packed)
|
|
{
|
|
this.packedValsPerPixel = 8 / this.imi.BitDepth;
|
|
this.packedShift = this.imi.BitDepth;
|
|
if (this.imi.BitDepth == 1)
|
|
{
|
|
this.packedMask = 128;
|
|
}
|
|
else if (this.imi.BitDepth == 2)
|
|
{
|
|
this.packedMask = 192;
|
|
}
|
|
else
|
|
{
|
|
this.packedMask = 240;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.packedMask = (this.packedShift = (this.packedValsPerPixel = 1));
|
|
}
|
|
this.setPass(1);
|
|
this.setRow(0);
|
|
}
|
|
|
|
// Token: 0x060000D5 RID: 213 RVA: 0x00004514 File Offset: 0x00002714
|
|
internal void setRow(int n)
|
|
{
|
|
this.currRowSubimg = n;
|
|
this.currRowReal = n * this.dY + this.oY;
|
|
if (this.currRowReal < 0 || this.currRowReal >= this.imi.Rows)
|
|
{
|
|
throw new PngjExceptionInternal("bad row - this should not happen");
|
|
}
|
|
}
|
|
|
|
// Token: 0x060000D6 RID: 214 RVA: 0x00004564 File Offset: 0x00002764
|
|
internal void setPass(int p)
|
|
{
|
|
if (this.pass == p)
|
|
{
|
|
return;
|
|
}
|
|
this.pass = p;
|
|
switch (this.pass)
|
|
{
|
|
case 1:
|
|
this.dY = (this.dX = 8);
|
|
this.oX = (this.oY = 0);
|
|
break;
|
|
case 2:
|
|
this.dY = (this.dX = 8);
|
|
this.oX = 4;
|
|
this.oY = 0;
|
|
break;
|
|
case 3:
|
|
this.dX = 4;
|
|
this.dY = 8;
|
|
this.oX = 0;
|
|
this.oY = 4;
|
|
break;
|
|
case 4:
|
|
this.dX = (this.dY = 4);
|
|
this.oX = 2;
|
|
this.oY = 0;
|
|
break;
|
|
case 5:
|
|
this.dX = 2;
|
|
this.dY = 4;
|
|
this.oX = 0;
|
|
this.oY = 2;
|
|
break;
|
|
case 6:
|
|
this.dX = (this.dY = 2);
|
|
this.oX = 1;
|
|
this.oY = 0;
|
|
break;
|
|
case 7:
|
|
this.dX = 1;
|
|
this.dY = 2;
|
|
this.oX = 0;
|
|
this.oY = 1;
|
|
break;
|
|
default:
|
|
throw new PngjExceptionInternal("bad interlace pass" + this.pass);
|
|
}
|
|
this.rows = (this.imi.Rows - this.oY) / this.dY + 1;
|
|
if ((this.rows - 1) * this.dY + this.oY >= this.imi.Rows)
|
|
{
|
|
this.rows--;
|
|
}
|
|
this.cols = (this.imi.Cols - this.oX) / this.dX + 1;
|
|
if ((this.cols - 1) * this.dX + this.oX >= this.imi.Cols)
|
|
{
|
|
this.cols--;
|
|
}
|
|
if (this.cols == 0)
|
|
{
|
|
this.rows = 0;
|
|
}
|
|
this.dXsamples = this.dX * this.imi.Channels;
|
|
this.oXsamples = this.oX * this.imi.Channels;
|
|
}
|
|
|
|
// Token: 0x060000D7 RID: 215 RVA: 0x0000479C File Offset: 0x0000299C
|
|
internal void deinterlaceInt(int[] src, int[] dst, bool readInPackedFormat)
|
|
{
|
|
if (!this.imi.Packed || !readInPackedFormat)
|
|
{
|
|
int i = 0;
|
|
int num = this.oXsamples;
|
|
while (i < this.cols * this.imi.Channels)
|
|
{
|
|
for (int j = 0; j < this.imi.Channels; j++)
|
|
{
|
|
dst[num + j] = src[i + j];
|
|
}
|
|
i += this.imi.Channels;
|
|
num += this.dXsamples;
|
|
}
|
|
return;
|
|
}
|
|
this.deinterlaceIntPacked(src, dst);
|
|
}
|
|
|
|
// Token: 0x060000D8 RID: 216 RVA: 0x0000481C File Offset: 0x00002A1C
|
|
private void deinterlaceIntPacked(int[] src, int[] dst)
|
|
{
|
|
int num = this.packedMask;
|
|
int num2 = -1;
|
|
int i = 0;
|
|
int num3 = this.oX;
|
|
while (i < this.cols)
|
|
{
|
|
int num4 = i / this.packedValsPerPixel;
|
|
num2++;
|
|
if (num2 >= this.packedValsPerPixel)
|
|
{
|
|
num2 = 0;
|
|
}
|
|
num >>= this.packedShift;
|
|
if (num2 == 0)
|
|
{
|
|
num = this.packedMask;
|
|
}
|
|
int num5 = num3 / this.packedValsPerPixel;
|
|
int num6 = num3 % this.packedValsPerPixel;
|
|
int num7 = src[num4] & num;
|
|
int num8 = num6 - num2;
|
|
if (num8 > 0)
|
|
{
|
|
num7 >>= num8 * this.packedShift;
|
|
}
|
|
else if (num8 < 0)
|
|
{
|
|
num7 <<= -num8 * this.packedShift;
|
|
}
|
|
dst[num5] |= num7;
|
|
i++;
|
|
num3 += this.dX;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060000D9 RID: 217 RVA: 0x000048F8 File Offset: 0x00002AF8
|
|
internal void deinterlaceByte(byte[] src, byte[] dst, bool readInPackedFormat)
|
|
{
|
|
if (!this.imi.Packed || !readInPackedFormat)
|
|
{
|
|
int i = 0;
|
|
int num = this.oXsamples;
|
|
while (i < this.cols * this.imi.Channels)
|
|
{
|
|
for (int j = 0; j < this.imi.Channels; j++)
|
|
{
|
|
dst[num + j] = src[i + j];
|
|
}
|
|
i += this.imi.Channels;
|
|
num += this.dXsamples;
|
|
}
|
|
return;
|
|
}
|
|
this.deinterlacePackedByte(src, dst);
|
|
}
|
|
|
|
// Token: 0x060000DA RID: 218 RVA: 0x00004978 File Offset: 0x00002B78
|
|
private void deinterlacePackedByte(byte[] src, byte[] dst)
|
|
{
|
|
int num = this.packedMask;
|
|
int num2 = -1;
|
|
int i = 0;
|
|
int num3 = this.oX;
|
|
while (i < this.cols)
|
|
{
|
|
int num4 = i / this.packedValsPerPixel;
|
|
num2++;
|
|
if (num2 >= this.packedValsPerPixel)
|
|
{
|
|
num2 = 0;
|
|
}
|
|
num >>= this.packedShift;
|
|
if (num2 == 0)
|
|
{
|
|
num = this.packedMask;
|
|
}
|
|
int num5 = num3 / this.packedValsPerPixel;
|
|
int num6 = num3 % this.packedValsPerPixel;
|
|
int num7 = (int)src[num4] & num;
|
|
int num8 = num6 - num2;
|
|
if (num8 > 0)
|
|
{
|
|
num7 >>= num8 * this.packedShift;
|
|
}
|
|
else if (num8 < 0)
|
|
{
|
|
num7 <<= -num8 * this.packedShift;
|
|
}
|
|
int num9 = num5;
|
|
dst[num9] |= (byte)num7;
|
|
i++;
|
|
num3 += this.dX;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060000DB RID: 219 RVA: 0x00004A55 File Offset: 0x00002C55
|
|
internal bool isAtLastRow()
|
|
{
|
|
return this.pass == 7 && this.currRowSubimg == this.rows - 1;
|
|
}
|
|
|
|
// Token: 0x060000DC RID: 220 RVA: 0x00004A72 File Offset: 0x00002C72
|
|
internal int getCurrRowSubimg()
|
|
{
|
|
return this.currRowSubimg;
|
|
}
|
|
|
|
// Token: 0x060000DD RID: 221 RVA: 0x00004A7A File Offset: 0x00002C7A
|
|
internal int getCurrRowReal()
|
|
{
|
|
return this.currRowReal;
|
|
}
|
|
|
|
// Token: 0x060000DE RID: 222 RVA: 0x00004A82 File Offset: 0x00002C82
|
|
internal int getPass()
|
|
{
|
|
return this.pass;
|
|
}
|
|
|
|
// Token: 0x060000DF RID: 223 RVA: 0x00004A8A File Offset: 0x00002C8A
|
|
internal int getRows()
|
|
{
|
|
return this.rows;
|
|
}
|
|
|
|
// Token: 0x060000E0 RID: 224 RVA: 0x00004A92 File Offset: 0x00002C92
|
|
internal int getCols()
|
|
{
|
|
return this.cols;
|
|
}
|
|
|
|
// Token: 0x060000E1 RID: 225 RVA: 0x00004A9A File Offset: 0x00002C9A
|
|
internal int getPixelsToRead()
|
|
{
|
|
return this.getCols();
|
|
}
|
|
|
|
// Token: 0x060000E2 RID: 226 RVA: 0x00004AA2 File Offset: 0x00002CA2
|
|
internal int[][] getImageInt()
|
|
{
|
|
return this.imageInt;
|
|
}
|
|
|
|
// Token: 0x060000E3 RID: 227 RVA: 0x00004AAA File Offset: 0x00002CAA
|
|
internal void setImageInt(int[][] imageInt)
|
|
{
|
|
this.imageInt = imageInt;
|
|
}
|
|
|
|
// Token: 0x060000E4 RID: 228 RVA: 0x00004AB3 File Offset: 0x00002CB3
|
|
internal byte[][] getImageByte()
|
|
{
|
|
return this.imageByte;
|
|
}
|
|
|
|
// Token: 0x060000E5 RID: 229 RVA: 0x00004ABB File Offset: 0x00002CBB
|
|
internal void setImageByte(byte[][] imageByte)
|
|
{
|
|
this.imageByte = imageByte;
|
|
}
|
|
|
|
// Token: 0x04000076 RID: 118
|
|
private readonly ImageInfo imi;
|
|
|
|
// Token: 0x04000077 RID: 119
|
|
private int pass;
|
|
|
|
// Token: 0x04000078 RID: 120
|
|
private int rows;
|
|
|
|
// Token: 0x04000079 RID: 121
|
|
private int cols;
|
|
|
|
// Token: 0x0400007A RID: 122
|
|
private int dY;
|
|
|
|
// Token: 0x0400007B RID: 123
|
|
private int dX;
|
|
|
|
// Token: 0x0400007C RID: 124
|
|
private int oY;
|
|
|
|
// Token: 0x0400007D RID: 125
|
|
private int oX;
|
|
|
|
// Token: 0x0400007E RID: 126
|
|
private int oXsamples;
|
|
|
|
// Token: 0x0400007F RID: 127
|
|
private int dXsamples;
|
|
|
|
// Token: 0x04000080 RID: 128
|
|
private int currRowSubimg = -1;
|
|
|
|
// Token: 0x04000081 RID: 129
|
|
private int currRowReal = -1;
|
|
|
|
// Token: 0x04000082 RID: 130
|
|
private readonly int packedValsPerPixel;
|
|
|
|
// Token: 0x04000083 RID: 131
|
|
private readonly int packedMask;
|
|
|
|
// Token: 0x04000084 RID: 132
|
|
private readonly int packedShift;
|
|
|
|
// Token: 0x04000085 RID: 133
|
|
private int[][] imageInt;
|
|
|
|
// Token: 0x04000086 RID: 134
|
|
private byte[][] imageByte;
|
|
}
|
|
}
|