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

300 lines
7.2 KiB
C#

using System;
using System.IO;
using System.Text;
using Hjg.Pngcs.Zlib;
namespace Hjg.Pngcs
{
// Token: 0x02000034 RID: 52
public class PngHelperInternal
{
// Token: 0x060001C4 RID: 452 RVA: 0x0000783C File Offset: 0x00005A3C
public static CRC32 GetCRC()
{
if (PngHelperInternal.crc32Engine == null)
{
PngHelperInternal.crc32Engine = new CRC32();
}
return PngHelperInternal.crc32Engine;
}
// Token: 0x060001C5 RID: 453 RVA: 0x00007854 File Offset: 0x00005A54
public static int DoubleToInt100000(double d)
{
return (int)(d * 100000.0 + 0.5);
}
// Token: 0x060001C6 RID: 454 RVA: 0x0000786C File Offset: 0x00005A6C
public static double IntToDouble100000(int i)
{
return (double)i / 100000.0;
}
// Token: 0x060001C7 RID: 455 RVA: 0x0000787C File Offset: 0x00005A7C
public static void WriteInt2(Stream os, int n)
{
byte[] array = new byte[]
{
(byte)((n >> 8) & 255),
(byte)(n & 255)
};
PngHelperInternal.WriteBytes(os, array);
}
// Token: 0x060001C8 RID: 456 RVA: 0x000078B4 File Offset: 0x00005AB4
public static int ReadInt2(Stream mask0)
{
int num3;
try
{
int num = mask0.ReadByte();
int num2 = mask0.ReadByte();
if (num == -1 || num2 == -1)
{
num3 = -1;
}
else
{
num3 = (num << 8) + num2;
}
}
catch (IOException ex)
{
throw new PngjInputException("error reading readInt2", ex);
}
return num3;
}
// Token: 0x060001C9 RID: 457 RVA: 0x00007904 File Offset: 0x00005B04
public static int ReadInt4(Stream mask0)
{
int num5;
try
{
int num = mask0.ReadByte();
int num2 = mask0.ReadByte();
int num3 = mask0.ReadByte();
int num4 = mask0.ReadByte();
if (num == -1 || num2 == -1 || num3 == -1 || num4 == -1)
{
num5 = -1;
}
else
{
num5 = (num << 24) + (num2 << 16) + (num3 << 8) + num4;
}
}
catch (IOException ex)
{
throw new PngjInputException("error reading readInt4", ex);
}
return num5;
}
// Token: 0x060001CA RID: 458 RVA: 0x00007978 File Offset: 0x00005B78
public static int ReadInt1fromByte(byte[] b, int offset)
{
return (int)(b[offset] & byte.MaxValue);
}
// Token: 0x060001CB RID: 459 RVA: 0x00007983 File Offset: 0x00005B83
public static int ReadInt2fromBytes(byte[] b, int offset)
{
return ((int)(b[offset] & byte.MaxValue) << 16) | (int)(b[offset + 1] & byte.MaxValue);
}
// Token: 0x060001CC RID: 460 RVA: 0x0000799D File Offset: 0x00005B9D
public static int ReadInt4fromBytes(byte[] b, int offset)
{
return ((int)(b[offset] & byte.MaxValue) << 24) | ((int)(b[offset + 1] & byte.MaxValue) << 16) | ((int)(b[offset + 2] & byte.MaxValue) << 8) | (int)(b[offset + 3] & byte.MaxValue);
}
// Token: 0x060001CD RID: 461 RVA: 0x000079D4 File Offset: 0x00005BD4
public static void WriteInt2tobytes(int n, byte[] b, int offset)
{
b[offset] = (byte)((n >> 8) & 255);
b[offset + 1] = (byte)(n & 255);
}
// Token: 0x060001CE RID: 462 RVA: 0x000079F0 File Offset: 0x00005BF0
public static void WriteInt4tobytes(int n, byte[] b, int offset)
{
b[offset] = (byte)((n >> 24) & 255);
b[offset + 1] = (byte)((n >> 16) & 255);
b[offset + 2] = (byte)((n >> 8) & 255);
b[offset + 3] = (byte)(n & 255);
}
// Token: 0x060001CF RID: 463 RVA: 0x00007A2C File Offset: 0x00005C2C
public static void WriteInt4(Stream os, int n)
{
byte[] array = new byte[4];
PngHelperInternal.WriteInt4tobytes(n, array, 0);
PngHelperInternal.WriteBytes(os, array);
}
// Token: 0x060001D0 RID: 464 RVA: 0x00007A50 File Offset: 0x00005C50
public static void ReadBytes(Stream mask0, byte[] b, int offset, int len)
{
if (len == 0)
{
return;
}
try
{
int num;
for (int i = 0; i < len; i += num)
{
num = mask0.Read(b, offset + i, len - i);
if (num < 1)
{
throw new Exception(string.Concat(new object[] { "error reading, ", num, " !=", len }));
}
}
}
catch (IOException ex)
{
throw new PngjInputException("error reading", ex);
}
}
// Token: 0x060001D1 RID: 465 RVA: 0x00007AD4 File Offset: 0x00005CD4
public static void SkipBytes(Stream ist, int len)
{
byte[] array = new byte[32768];
int i = len;
try
{
while (i > 0)
{
int num = ist.Read(array, 0, (i > array.Length) ? array.Length : i);
if (num < 0)
{
throw new PngjInputException("error reading (skipping) : EOF");
}
i -= num;
}
}
catch (IOException ex)
{
throw new PngjInputException("error reading (skipping)", ex);
}
}
// Token: 0x060001D2 RID: 466 RVA: 0x00007B3C File Offset: 0x00005D3C
public static void WriteBytes(Stream os, byte[] b)
{
try
{
os.Write(b, 0, b.Length);
}
catch (IOException ex)
{
throw new PngjOutputException(ex);
}
}
// Token: 0x060001D3 RID: 467 RVA: 0x00007B70 File Offset: 0x00005D70
public static void WriteBytes(Stream os, byte[] b, int offset, int n)
{
try
{
os.Write(b, offset, n);
}
catch (IOException ex)
{
throw new PngjOutputException(ex);
}
}
// Token: 0x060001D4 RID: 468 RVA: 0x00007BA0 File Offset: 0x00005DA0
public static int ReadByte(Stream mask0)
{
int num;
try
{
num = mask0.ReadByte();
}
catch (IOException ex)
{
throw new PngjOutputException(ex);
}
return num;
}
// Token: 0x060001D5 RID: 469 RVA: 0x00007BD0 File Offset: 0x00005DD0
public static void WriteByte(Stream os, byte b)
{
try
{
os.WriteByte(b);
}
catch (IOException ex)
{
throw new PngjOutputException(ex);
}
}
// Token: 0x060001D6 RID: 470 RVA: 0x00007C00 File Offset: 0x00005E00
public static int UnfilterRowPaeth(int r, int a, int b, int c)
{
return (r + PngHelperInternal.FilterPaethPredictor(a, b, c)) & 255;
}
// Token: 0x060001D7 RID: 471 RVA: 0x00007C14 File Offset: 0x00005E14
public static int FilterPaethPredictor(int a, int b, int c)
{
int num = a + b - c;
int num2 = ((num >= a) ? (num - a) : (a - num));
int num3 = ((num >= b) ? (num - b) : (b - num));
int num4 = ((num >= c) ? (num - c) : (c - num));
if (num2 <= num3 && num2 <= num4)
{
return a;
}
if (num3 <= num4)
{
return b;
}
return c;
}
// Token: 0x060001D8 RID: 472 RVA: 0x00007C5F File Offset: 0x00005E5F
public static void Logdebug(string msg)
{
if (PngHelperInternal.DEBUG)
{
Console.Out.WriteLine(msg);
}
}
// Token: 0x060001D9 RID: 473 RVA: 0x00007C73 File Offset: 0x00005E73
public static void InitCrcForTests(PngReader pngr)
{
pngr.InitCrctest();
}
// Token: 0x060001DA RID: 474 RVA: 0x00007C7B File Offset: 0x00005E7B
public static long GetCrctestVal(PngReader pngr)
{
return pngr.GetCrctestVal();
}
// Token: 0x040000FE RID: 254
[ThreadStatic]
private static CRC32 crc32Engine = null;
// Token: 0x040000FF RID: 255
public static readonly byte[] PNG_ID_SIGNATURE = new byte[] { 137, 80, 78, 71, 13, 10, 26, 10 };
// Token: 0x04000100 RID: 256
public static Encoding charsetLatin1 = Encoding.GetEncoding("ISO-8859-1");
// Token: 0x04000101 RID: 257
public static Encoding charsetUtf8 = Encoding.GetEncoding("UTF-8");
// Token: 0x04000102 RID: 258
public static bool DEBUG = false;
}
}