153 lines
4.1 KiB
C#
153 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace Hjg.Pngcs.Chunks
|
|
{
|
|
// Token: 0x02000006 RID: 6
|
|
public class ChunksListForWrite : ChunksList
|
|
{
|
|
// Token: 0x0600002C RID: 44 RVA: 0x000027EE File Offset: 0x000009EE
|
|
internal ChunksListForWrite(ImageInfo info)
|
|
: base(info)
|
|
{
|
|
this.queuedChunks = new List<PngChunk>();
|
|
this.alreadyWrittenKeys = new Dictionary<string, int>();
|
|
}
|
|
|
|
// Token: 0x0600002D RID: 45 RVA: 0x0000280D File Offset: 0x00000A0D
|
|
public List<PngChunk> GetQueuedById(string id)
|
|
{
|
|
return this.GetQueuedById(id, null);
|
|
}
|
|
|
|
// Token: 0x0600002E RID: 46 RVA: 0x00002817 File Offset: 0x00000A17
|
|
public List<PngChunk> GetQueuedById(string id, string innerid)
|
|
{
|
|
return ChunksList.GetXById(this.queuedChunks, id, innerid);
|
|
}
|
|
|
|
// Token: 0x0600002F RID: 47 RVA: 0x00002828 File Offset: 0x00000A28
|
|
public PngChunk GetQueuedById1(string id, string innerid, bool failIfMultiple)
|
|
{
|
|
List<PngChunk> queuedById = this.GetQueuedById(id, innerid);
|
|
if (queuedById.Count == 0)
|
|
{
|
|
return null;
|
|
}
|
|
if (queuedById.Count > 1 && (failIfMultiple || !queuedById[0].AllowsMultiple()))
|
|
{
|
|
throw new PngjException("unexpected multiple chunks id=" + id);
|
|
}
|
|
return queuedById[queuedById.Count - 1];
|
|
}
|
|
|
|
// Token: 0x06000030 RID: 48 RVA: 0x00002881 File Offset: 0x00000A81
|
|
public PngChunk GetQueuedById1(string id, bool failIfMultiple)
|
|
{
|
|
return this.GetQueuedById1(id, null, failIfMultiple);
|
|
}
|
|
|
|
// Token: 0x06000031 RID: 49 RVA: 0x0000288C File Offset: 0x00000A8C
|
|
public PngChunk GetQueuedById1(string id)
|
|
{
|
|
return this.GetQueuedById1(id, false);
|
|
}
|
|
|
|
// Token: 0x06000032 RID: 50 RVA: 0x00002896 File Offset: 0x00000A96
|
|
public bool RemoveChunk(PngChunk c)
|
|
{
|
|
return this.queuedChunks.Remove(c);
|
|
}
|
|
|
|
// Token: 0x06000033 RID: 51 RVA: 0x000028A4 File Offset: 0x00000AA4
|
|
public bool Queue(PngChunk chunk)
|
|
{
|
|
this.queuedChunks.Add(chunk);
|
|
return true;
|
|
}
|
|
|
|
// Token: 0x06000034 RID: 52 RVA: 0x000028B4 File Offset: 0x00000AB4
|
|
private static bool shouldWrite(PngChunk c, int currentGroup)
|
|
{
|
|
if (currentGroup == 2)
|
|
{
|
|
return c.Id.Equals("PLTE");
|
|
}
|
|
if (currentGroup % 2 == 0)
|
|
{
|
|
throw new PngjOutputException("bad chunk group?");
|
|
}
|
|
int num2;
|
|
int num;
|
|
if (c.mustGoBeforePLTE())
|
|
{
|
|
num = (num2 = 1);
|
|
}
|
|
else if (c.mustGoBeforeIDAT())
|
|
{
|
|
num = 3;
|
|
num2 = (c.mustGoAfterPLTE() ? 3 : 1);
|
|
}
|
|
else
|
|
{
|
|
num = 5;
|
|
num2 = 1;
|
|
}
|
|
int num3 = num;
|
|
if (c.Priority)
|
|
{
|
|
num3 = num2;
|
|
}
|
|
if (ChunkHelper.IsUnknown(c) && c.ChunkGroup > 0)
|
|
{
|
|
num3 = c.ChunkGroup;
|
|
}
|
|
return currentGroup == num3 || (currentGroup > num3 && currentGroup <= num);
|
|
}
|
|
|
|
// Token: 0x06000035 RID: 53 RVA: 0x00002948 File Offset: 0x00000B48
|
|
internal int writeChunks(Stream os, int currentGroup)
|
|
{
|
|
List<int> list = new List<int>();
|
|
for (int i = 0; i < this.queuedChunks.Count; i++)
|
|
{
|
|
PngChunk pngChunk = this.queuedChunks[i];
|
|
if (ChunksListForWrite.shouldWrite(pngChunk, currentGroup))
|
|
{
|
|
if (ChunkHelper.IsCritical(pngChunk.Id) && !pngChunk.Id.Equals("PLTE"))
|
|
{
|
|
throw new PngjOutputException("bad chunk queued: " + pngChunk);
|
|
}
|
|
if (this.alreadyWrittenKeys.ContainsKey(pngChunk.Id) && !pngChunk.AllowsMultiple())
|
|
{
|
|
throw new PngjOutputException("duplicated chunk does not allow multiple: " + pngChunk);
|
|
}
|
|
pngChunk.write(os);
|
|
this.chunks.Add(pngChunk);
|
|
this.alreadyWrittenKeys[pngChunk.Id] = (this.alreadyWrittenKeys.ContainsKey(pngChunk.Id) ? (this.alreadyWrittenKeys[pngChunk.Id] + 1) : 1);
|
|
list.Add(i);
|
|
pngChunk.ChunkGroup = currentGroup;
|
|
}
|
|
}
|
|
for (int j = list.Count - 1; j >= 0; j--)
|
|
{
|
|
this.queuedChunks.RemoveAt(list[j]);
|
|
}
|
|
return list.Count;
|
|
}
|
|
|
|
// Token: 0x06000036 RID: 54 RVA: 0x00002A72 File Offset: 0x00000C72
|
|
internal List<PngChunk> GetQueuedChunks()
|
|
{
|
|
return this.queuedChunks;
|
|
}
|
|
|
|
// Token: 0x04000029 RID: 41
|
|
private List<PngChunk> queuedChunks;
|
|
|
|
// Token: 0x0400002A RID: 42
|
|
private Dictionary<string, int> alreadyWrittenKeys;
|
|
}
|
|
}
|