Files
Dec2017-Script-Dump/Pngcs/Chunks/ChunkHelper.cs
T
2026-06-04 11:42:34 +02:00

295 lines
7.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using Hjg.Pngcs.Zlib;
namespace Hjg.Pngcs.Chunks
{
// Token: 0x02000002 RID: 2
public class ChunkHelper
{
// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
public static byte[] ToBytes(string x)
{
return PngHelperInternal.charsetLatin1.GetBytes(x);
}
// Token: 0x06000002 RID: 2 RVA: 0x0000205D File Offset: 0x0000025D
public static string ToString(byte[] x)
{
return PngHelperInternal.charsetLatin1.GetString(x);
}
// Token: 0x06000003 RID: 3 RVA: 0x0000206A File Offset: 0x0000026A
public static string ToString(byte[] x, int offset, int len)
{
return PngHelperInternal.charsetLatin1.GetString(x, offset, len);
}
// Token: 0x06000004 RID: 4 RVA: 0x00002079 File Offset: 0x00000279
public static byte[] ToBytesUTF8(string x)
{
return PngHelperInternal.charsetUtf8.GetBytes(x);
}
// Token: 0x06000005 RID: 5 RVA: 0x00002086 File Offset: 0x00000286
public static string ToStringUTF8(byte[] x)
{
return PngHelperInternal.charsetUtf8.GetString(x);
}
// Token: 0x06000006 RID: 6 RVA: 0x00002093 File Offset: 0x00000293
public static string ToStringUTF8(byte[] x, int offset, int len)
{
return PngHelperInternal.charsetUtf8.GetString(x, offset, len);
}
// Token: 0x06000007 RID: 7 RVA: 0x000020A2 File Offset: 0x000002A2
public static void WriteBytesToStream(Stream stream, byte[] bytes)
{
stream.Write(bytes, 0, bytes.Length);
}
// Token: 0x06000008 RID: 8 RVA: 0x000020AF File Offset: 0x000002AF
public static bool IsCritical(string id)
{
return char.IsUpper(id[0]);
}
// Token: 0x06000009 RID: 9 RVA: 0x000020BD File Offset: 0x000002BD
public static bool IsPublic(string id)
{
return char.IsUpper(id[1]);
}
// Token: 0x0600000A RID: 10 RVA: 0x000020CB File Offset: 0x000002CB
public static bool IsSafeToCopy(string id)
{
return !char.IsUpper(id[3]);
}
// Token: 0x0600000B RID: 11 RVA: 0x000020DC File Offset: 0x000002DC
public static bool IsUnknown(PngChunk chunk)
{
return chunk is PngChunkUNKNOWN;
}
// Token: 0x0600000C RID: 12 RVA: 0x000020E8 File Offset: 0x000002E8
public static int PosNullByte(byte[] bytes)
{
for (int i = 0; i < bytes.Length; i++)
{
if (bytes[i] == 0)
{
return i;
}
}
return -1;
}
// Token: 0x0600000D RID: 13 RVA: 0x0000210C File Offset: 0x0000030C
public static bool ShouldLoad(string id, ChunkLoadBehaviour behav)
{
if (ChunkHelper.IsCritical(id))
{
return true;
}
bool flag = PngChunk.isKnown(id);
switch (behav)
{
case ChunkLoadBehaviour.LOAD_CHUNK_NEVER:
return false;
case ChunkLoadBehaviour.LOAD_CHUNK_KNOWN:
return flag;
case ChunkLoadBehaviour.LOAD_CHUNK_IF_SAFE:
return flag || ChunkHelper.IsSafeToCopy(id);
case ChunkLoadBehaviour.LOAD_CHUNK_ALWAYS:
return true;
default:
return false;
}
}
// Token: 0x0600000E RID: 14 RVA: 0x00002157 File Offset: 0x00000357
internal static byte[] compressBytes(byte[] ori, bool compress)
{
return ChunkHelper.compressBytes(ori, 0, ori.Length, compress);
}
// Token: 0x0600000F RID: 15 RVA: 0x00002164 File Offset: 0x00000364
internal static byte[] compressBytes(byte[] ori, int offset, int len, bool compress)
{
byte[] array2;
try
{
MemoryStream memoryStream = new MemoryStream(ori, offset, len);
Stream stream = memoryStream;
if (!compress)
{
stream = ZlibStreamFactory.createZlibInputStream(memoryStream);
}
MemoryStream memoryStream2 = new MemoryStream();
Stream stream2 = memoryStream2;
if (compress)
{
stream2 = ZlibStreamFactory.createZlibOutputStream(memoryStream2);
}
ChunkHelper.shovelInToOut(stream, stream2);
stream.Close();
stream2.Close();
byte[] array = memoryStream2.ToArray();
array2 = array;
}
catch (Exception ex)
{
throw new PngjException(ex);
}
return array2;
}
// Token: 0x06000010 RID: 16 RVA: 0x000021D8 File Offset: 0x000003D8
private static void shovelInToOut(Stream inx, Stream outx)
{
byte[] array = new byte[1024];
int num;
while ((num = inx.Read(array, 0, 1024)) > 0)
{
outx.Write(array, 0, num);
}
}
// Token: 0x06000011 RID: 17 RVA: 0x0000220D File Offset: 0x0000040D
internal static bool maskMatch(int v, int mask)
{
return (v & mask) != 0;
}
// Token: 0x06000012 RID: 18 RVA: 0x00002218 File Offset: 0x00000418
public static List<PngChunk> FilterList(List<PngChunk> list, ChunkPredicate predicateKeep)
{
List<PngChunk> list2 = new List<PngChunk>();
foreach (PngChunk pngChunk in list)
{
if (predicateKeep.Matches(pngChunk))
{
list2.Add(pngChunk);
}
}
return list2;
}
// Token: 0x06000013 RID: 19 RVA: 0x00002278 File Offset: 0x00000478
public static int TrimList(List<PngChunk> list, ChunkPredicate predicateRemove)
{
int num = 0;
for (int i = list.Count - 1; i >= 0; i--)
{
if (predicateRemove.Matches(list[i]))
{
list.RemoveAt(i);
num++;
}
}
return num;
}
// Token: 0x06000014 RID: 20 RVA: 0x000022B8 File Offset: 0x000004B8
public static bool Equivalent(PngChunk c1, PngChunk c2)
{
if (c1 == c2)
{
return true;
}
if (c1 == null || c2 == null || !c1.Id.Equals(c2.Id))
{
return false;
}
if (c1.GetType() != c2.GetType())
{
return false;
}
if (!c2.AllowsMultiple())
{
return true;
}
if (c1 is PngChunkTextVar)
{
return ((PngChunkTextVar)c1).GetKey().Equals(((PngChunkTextVar)c2).GetKey());
}
return c1 is PngChunkSPLT && ((PngChunkSPLT)c1).PalName.Equals(((PngChunkSPLT)c2).PalName);
}
// Token: 0x06000015 RID: 21 RVA: 0x00002349 File Offset: 0x00000549
public static bool IsText(PngChunk c)
{
return c is PngChunkTextVar;
}
// Token: 0x04000001 RID: 1
internal const string IHDR = "IHDR";
// Token: 0x04000002 RID: 2
internal const string PLTE = "PLTE";
// Token: 0x04000003 RID: 3
internal const string IDAT = "IDAT";
// Token: 0x04000004 RID: 4
internal const string IEND = "IEND";
// Token: 0x04000005 RID: 5
internal const string cHRM = "cHRM";
// Token: 0x04000006 RID: 6
internal const string gAMA = "gAMA";
// Token: 0x04000007 RID: 7
internal const string iCCP = "iCCP";
// Token: 0x04000008 RID: 8
internal const string sBIT = "sBIT";
// Token: 0x04000009 RID: 9
internal const string sRGB = "sRGB";
// Token: 0x0400000A RID: 10
internal const string bKGD = "bKGD";
// Token: 0x0400000B RID: 11
internal const string hIST = "hIST";
// Token: 0x0400000C RID: 12
internal const string tRNS = "tRNS";
// Token: 0x0400000D RID: 13
internal const string pHYs = "pHYs";
// Token: 0x0400000E RID: 14
internal const string sPLT = "sPLT";
// Token: 0x0400000F RID: 15
internal const string tIME = "tIME";
// Token: 0x04000010 RID: 16
internal const string iTXt = "iTXt";
// Token: 0x04000011 RID: 17
internal const string tEXt = "tEXt";
// Token: 0x04000012 RID: 18
internal const string zTXt = "zTXt";
// Token: 0x04000013 RID: 19
internal static readonly byte[] b_IHDR = ChunkHelper.ToBytes("IHDR");
// Token: 0x04000014 RID: 20
internal static readonly byte[] b_PLTE = ChunkHelper.ToBytes("PLTE");
// Token: 0x04000015 RID: 21
internal static readonly byte[] b_IDAT = ChunkHelper.ToBytes("IDAT");
// Token: 0x04000016 RID: 22
internal static readonly byte[] b_IEND = ChunkHelper.ToBytes("IEND");
}
}