219 lines
5.9 KiB
C#
219 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Hjg.Pngcs.Chunks
|
|
{
|
|
// Token: 0x02000011 RID: 17
|
|
public class PngMetadata
|
|
{
|
|
// Token: 0x06000067 RID: 103 RVA: 0x0000310B File Offset: 0x0000130B
|
|
internal PngMetadata(ChunksList chunks)
|
|
{
|
|
this.chunkList = chunks;
|
|
if (chunks is ChunksListForWrite)
|
|
{
|
|
this.ReadOnly = false;
|
|
return;
|
|
}
|
|
this.ReadOnly = true;
|
|
}
|
|
|
|
// Token: 0x06000068 RID: 104 RVA: 0x00003134 File Offset: 0x00001334
|
|
public void QueueChunk(PngChunk chunk, bool lazyOverwrite)
|
|
{
|
|
ChunksListForWrite chunkListW = this.getChunkListW();
|
|
if (this.ReadOnly)
|
|
{
|
|
throw new PngjException("cannot set chunk : readonly metadata");
|
|
}
|
|
if (lazyOverwrite)
|
|
{
|
|
ChunkHelper.TrimList(chunkListW.GetQueuedChunks(), new ChunkPredicateEquiv(chunk));
|
|
}
|
|
chunkListW.Queue(chunk);
|
|
}
|
|
|
|
// Token: 0x06000069 RID: 105 RVA: 0x00003178 File Offset: 0x00001378
|
|
public void QueueChunk(PngChunk chunk)
|
|
{
|
|
this.QueueChunk(chunk, true);
|
|
}
|
|
|
|
// Token: 0x0600006A RID: 106 RVA: 0x00003182 File Offset: 0x00001382
|
|
private ChunksListForWrite getChunkListW()
|
|
{
|
|
return (ChunksListForWrite)this.chunkList;
|
|
}
|
|
|
|
// Token: 0x0600006B RID: 107 RVA: 0x00003190 File Offset: 0x00001390
|
|
public double[] GetDpi()
|
|
{
|
|
PngChunk byId = this.chunkList.GetById1("pHYs", true);
|
|
if (byId == null)
|
|
{
|
|
return new double[] { -1.0, -1.0 };
|
|
}
|
|
return ((PngChunkPHYS)byId).GetAsDpi2();
|
|
}
|
|
|
|
// Token: 0x0600006C RID: 108 RVA: 0x000031E0 File Offset: 0x000013E0
|
|
public void SetDpi(double dpix, double dpiy)
|
|
{
|
|
PngChunkPHYS pngChunkPHYS = new PngChunkPHYS(this.chunkList.imageInfo);
|
|
pngChunkPHYS.SetAsDpi2(dpix, dpiy);
|
|
this.QueueChunk(pngChunkPHYS);
|
|
}
|
|
|
|
// Token: 0x0600006D RID: 109 RVA: 0x0000320D File Offset: 0x0000140D
|
|
public void SetDpi(double dpi)
|
|
{
|
|
this.SetDpi(dpi, dpi);
|
|
}
|
|
|
|
// Token: 0x0600006E RID: 110 RVA: 0x00003218 File Offset: 0x00001418
|
|
public PngChunkTIME SetTimeNow(int nsecs)
|
|
{
|
|
PngChunkTIME pngChunkTIME = new PngChunkTIME(this.chunkList.imageInfo);
|
|
pngChunkTIME.SetNow(nsecs);
|
|
this.QueueChunk(pngChunkTIME);
|
|
return pngChunkTIME;
|
|
}
|
|
|
|
// Token: 0x0600006F RID: 111 RVA: 0x00003245 File Offset: 0x00001445
|
|
public PngChunkTIME SetTimeNow()
|
|
{
|
|
return this.SetTimeNow(0);
|
|
}
|
|
|
|
// Token: 0x06000070 RID: 112 RVA: 0x00003250 File Offset: 0x00001450
|
|
public PngChunkTIME SetTimeYMDHMS(int year, int mon, int day, int hour, int min, int sec)
|
|
{
|
|
PngChunkTIME pngChunkTIME = new PngChunkTIME(this.chunkList.imageInfo);
|
|
pngChunkTIME.SetYMDHMS(year, mon, day, hour, min, sec);
|
|
this.QueueChunk(pngChunkTIME, true);
|
|
return pngChunkTIME;
|
|
}
|
|
|
|
// Token: 0x06000071 RID: 113 RVA: 0x00003286 File Offset: 0x00001486
|
|
public PngChunkTIME GetTime()
|
|
{
|
|
return (PngChunkTIME)this.chunkList.GetById1("tIME");
|
|
}
|
|
|
|
// Token: 0x06000072 RID: 114 RVA: 0x000032A0 File Offset: 0x000014A0
|
|
public string GetTimeAsString()
|
|
{
|
|
PngChunkTIME time = this.GetTime();
|
|
if (time != null)
|
|
{
|
|
return time.GetAsString();
|
|
}
|
|
return "";
|
|
}
|
|
|
|
// Token: 0x06000073 RID: 115 RVA: 0x000032C4 File Offset: 0x000014C4
|
|
public PngChunkTextVar SetText(string key, string val, bool useLatin1, bool compress)
|
|
{
|
|
if (compress && !useLatin1)
|
|
{
|
|
throw new PngjException("cannot compress non latin text");
|
|
}
|
|
PngChunkTextVar pngChunkTextVar;
|
|
if (useLatin1)
|
|
{
|
|
if (compress)
|
|
{
|
|
pngChunkTextVar = new PngChunkZTXT(this.chunkList.imageInfo);
|
|
}
|
|
else
|
|
{
|
|
pngChunkTextVar = new PngChunkTEXT(this.chunkList.imageInfo);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
pngChunkTextVar = new PngChunkITXT(this.chunkList.imageInfo);
|
|
((PngChunkITXT)pngChunkTextVar).SetLangtag(key);
|
|
}
|
|
pngChunkTextVar.SetKeyVal(key, val);
|
|
this.QueueChunk(pngChunkTextVar, true);
|
|
return pngChunkTextVar;
|
|
}
|
|
|
|
// Token: 0x06000074 RID: 116 RVA: 0x0000333E File Offset: 0x0000153E
|
|
public PngChunkTextVar SetText(string key, string val)
|
|
{
|
|
return this.SetText(key, val, false, false);
|
|
}
|
|
|
|
// Token: 0x06000075 RID: 117 RVA: 0x0000334C File Offset: 0x0000154C
|
|
public List<PngChunkTextVar> GetTxtsForKey(string key)
|
|
{
|
|
List<PngChunkTextVar> list = new List<PngChunkTextVar>();
|
|
foreach (PngChunk pngChunk in this.chunkList.GetById("tEXt", key))
|
|
{
|
|
list.Add((PngChunkTextVar)pngChunk);
|
|
}
|
|
foreach (PngChunk pngChunk2 in this.chunkList.GetById("zTXt", key))
|
|
{
|
|
list.Add((PngChunkTextVar)pngChunk2);
|
|
}
|
|
foreach (PngChunk pngChunk3 in this.chunkList.GetById("iTXt", key))
|
|
{
|
|
list.Add((PngChunkTextVar)pngChunk3);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
// Token: 0x06000076 RID: 118 RVA: 0x00003460 File Offset: 0x00001660
|
|
public string GetTxtForKey(string key)
|
|
{
|
|
string text = "";
|
|
List<PngChunkTextVar> txtsForKey = this.GetTxtsForKey(key);
|
|
if (txtsForKey.Count == 0)
|
|
{
|
|
return text;
|
|
}
|
|
foreach (PngChunkTextVar pngChunkTextVar in txtsForKey)
|
|
{
|
|
text = text + pngChunkTextVar.GetVal() + "\n";
|
|
}
|
|
return text.Trim();
|
|
}
|
|
|
|
// Token: 0x06000077 RID: 119 RVA: 0x000034D8 File Offset: 0x000016D8
|
|
public PngChunkPLTE GetPLTE()
|
|
{
|
|
return (PngChunkPLTE)this.chunkList.GetById1("PLTE");
|
|
}
|
|
|
|
// Token: 0x06000078 RID: 120 RVA: 0x000034F0 File Offset: 0x000016F0
|
|
public PngChunkPLTE CreatePLTEChunk()
|
|
{
|
|
PngChunkPLTE pngChunkPLTE = new PngChunkPLTE(this.chunkList.imageInfo);
|
|
this.QueueChunk(pngChunkPLTE);
|
|
return pngChunkPLTE;
|
|
}
|
|
|
|
// Token: 0x06000079 RID: 121 RVA: 0x00003516 File Offset: 0x00001716
|
|
public PngChunkTRNS GetTRNS()
|
|
{
|
|
return (PngChunkTRNS)this.chunkList.GetById1("tRNS");
|
|
}
|
|
|
|
// Token: 0x0600007A RID: 122 RVA: 0x00003530 File Offset: 0x00001730
|
|
public PngChunkTRNS CreateTRNSChunk()
|
|
{
|
|
PngChunkTRNS pngChunkTRNS = new PngChunkTRNS(this.chunkList.imageInfo);
|
|
this.QueueChunk(pngChunkTRNS);
|
|
return pngChunkTRNS;
|
|
}
|
|
|
|
// Token: 0x04000048 RID: 72
|
|
private readonly ChunksList chunkList;
|
|
|
|
// Token: 0x04000049 RID: 73
|
|
private readonly bool ReadOnly;
|
|
}
|
|
}
|