142 lines
4.3 KiB
C#
142 lines
4.3 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace Hjg.Pngcs.Chunks
|
|
{
|
|
// Token: 0x02000014 RID: 20
|
|
public class PngChunkSPLT : PngChunkMultiple
|
|
{
|
|
// Token: 0x17000006 RID: 6
|
|
// (get) Token: 0x0600008D RID: 141 RVA: 0x00003757 File Offset: 0x00001957
|
|
// (set) Token: 0x0600008E RID: 142 RVA: 0x0000375F File Offset: 0x0000195F
|
|
public string PalName { get; set; }
|
|
|
|
// Token: 0x17000007 RID: 7
|
|
// (get) Token: 0x0600008F RID: 143 RVA: 0x00003768 File Offset: 0x00001968
|
|
// (set) Token: 0x06000090 RID: 144 RVA: 0x00003770 File Offset: 0x00001970
|
|
public int SampleDepth { get; set; }
|
|
|
|
// Token: 0x17000008 RID: 8
|
|
// (get) Token: 0x06000091 RID: 145 RVA: 0x00003779 File Offset: 0x00001979
|
|
// (set) Token: 0x06000092 RID: 146 RVA: 0x00003781 File Offset: 0x00001981
|
|
public int[] Palette { get; set; }
|
|
|
|
// Token: 0x06000093 RID: 147 RVA: 0x0000378A File Offset: 0x0000198A
|
|
public PngChunkSPLT(ImageInfo info)
|
|
: base("sPLT", info)
|
|
{
|
|
this.PalName = "";
|
|
}
|
|
|
|
// Token: 0x06000094 RID: 148 RVA: 0x000037A3 File Offset: 0x000019A3
|
|
public override PngChunk.ChunkOrderingConstraint GetOrderingConstraint()
|
|
{
|
|
return PngChunk.ChunkOrderingConstraint.BEFORE_IDAT;
|
|
}
|
|
|
|
// Token: 0x06000095 RID: 149 RVA: 0x000037A8 File Offset: 0x000019A8
|
|
public override ChunkRaw CreateRawChunk()
|
|
{
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
ChunkHelper.WriteBytesToStream(memoryStream, ChunkHelper.ToBytes(this.PalName));
|
|
memoryStream.WriteByte(0);
|
|
memoryStream.WriteByte((byte)this.SampleDepth);
|
|
int nentries = this.GetNentries();
|
|
for (int i = 0; i < nentries; i++)
|
|
{
|
|
for (int j = 0; j < 4; j++)
|
|
{
|
|
if (this.SampleDepth == 8)
|
|
{
|
|
PngHelperInternal.WriteByte(memoryStream, (byte)this.Palette[i * 5 + j]);
|
|
}
|
|
else
|
|
{
|
|
PngHelperInternal.WriteInt2(memoryStream, this.Palette[i * 5 + j]);
|
|
}
|
|
}
|
|
PngHelperInternal.WriteInt2(memoryStream, this.Palette[i * 5 + 4]);
|
|
}
|
|
byte[] array = memoryStream.ToArray();
|
|
ChunkRaw chunkRaw = base.createEmptyChunk(array.Length, false);
|
|
chunkRaw.Data = array;
|
|
return chunkRaw;
|
|
}
|
|
|
|
// Token: 0x06000096 RID: 150 RVA: 0x00003864 File Offset: 0x00001A64
|
|
public override void ParseFromRaw(ChunkRaw c)
|
|
{
|
|
int num = -1;
|
|
for (int i = 0; i < c.Data.Length; i++)
|
|
{
|
|
if (c.Data[i] == 0)
|
|
{
|
|
num = i;
|
|
break;
|
|
}
|
|
}
|
|
if (num <= 0 || num > c.Data.Length - 2)
|
|
{
|
|
throw new PngjException("bad sPLT chunk: no separator found");
|
|
}
|
|
this.PalName = ChunkHelper.ToString(c.Data, 0, num);
|
|
this.SampleDepth = PngHelperInternal.ReadInt1fromByte(c.Data, num + 1);
|
|
num += 2;
|
|
int num2 = (c.Data.Length - num) / ((this.SampleDepth == 8) ? 6 : 10);
|
|
this.Palette = new int[num2 * 5];
|
|
int num3 = 0;
|
|
for (int j = 0; j < num2; j++)
|
|
{
|
|
int num4;
|
|
int num5;
|
|
int num6;
|
|
int num7;
|
|
if (this.SampleDepth == 8)
|
|
{
|
|
num4 = PngHelperInternal.ReadInt1fromByte(c.Data, num++);
|
|
num5 = PngHelperInternal.ReadInt1fromByte(c.Data, num++);
|
|
num6 = PngHelperInternal.ReadInt1fromByte(c.Data, num++);
|
|
num7 = PngHelperInternal.ReadInt1fromByte(c.Data, num++);
|
|
}
|
|
else
|
|
{
|
|
num4 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
|
|
num += 2;
|
|
num5 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
|
|
num += 2;
|
|
num6 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
|
|
num += 2;
|
|
num7 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
|
|
num += 2;
|
|
}
|
|
int num8 = PngHelperInternal.ReadInt2fromBytes(c.Data, num);
|
|
num += 2;
|
|
this.Palette[num3++] = num4;
|
|
this.Palette[num3++] = num5;
|
|
this.Palette[num3++] = num6;
|
|
this.Palette[num3++] = num7;
|
|
this.Palette[num3++] = num8;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000097 RID: 151 RVA: 0x00003A18 File Offset: 0x00001C18
|
|
public override void CloneDataFromRead(PngChunk other)
|
|
{
|
|
PngChunkSPLT pngChunkSPLT = (PngChunkSPLT)other;
|
|
this.PalName = pngChunkSPLT.PalName;
|
|
this.SampleDepth = pngChunkSPLT.SampleDepth;
|
|
this.Palette = new int[pngChunkSPLT.Palette.Length];
|
|
Array.Copy(pngChunkSPLT.Palette, 0, this.Palette, 0, this.Palette.Length);
|
|
}
|
|
|
|
// Token: 0x06000098 RID: 152 RVA: 0x00003A72 File Offset: 0x00001C72
|
|
public int GetNentries()
|
|
{
|
|
return this.Palette.Length / 5;
|
|
}
|
|
|
|
// Token: 0x04000050 RID: 80
|
|
public const string ID = "sPLT";
|
|
}
|
|
}
|