150 lines
3.8 KiB
C#
150 lines
3.8 KiB
C#
using System;
|
|
|
|
namespace Hjg.Pngcs
|
|
{
|
|
// Token: 0x0200001C RID: 28
|
|
internal class FilterWriteStrategy
|
|
{
|
|
// Token: 0x060000EA RID: 234 RVA: 0x00004B18 File Offset: 0x00002D18
|
|
internal FilterWriteStrategy(ImageInfo imgInfo, FilterType configuredType)
|
|
{
|
|
this.imgInfo = imgInfo;
|
|
this.configuredType = configuredType;
|
|
if (configuredType < FilterType.FILTER_NONE)
|
|
{
|
|
if ((imgInfo.Rows < 8 && imgInfo.Cols < 8) || imgInfo.Indexed || imgInfo.BitDepth < 8)
|
|
{
|
|
this.currentType = FilterType.FILTER_NONE;
|
|
}
|
|
else
|
|
{
|
|
this.currentType = FilterType.FILTER_PAETH;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.currentType = configuredType;
|
|
}
|
|
if (configuredType == FilterType.FILTER_AGGRESSIVE)
|
|
{
|
|
this.discoverEachLines = FilterWriteStrategy.COMPUTE_STATS_EVERY_N_LINES;
|
|
}
|
|
if (configuredType == FilterType.FILTER_VERYAGGRESSIVE)
|
|
{
|
|
this.discoverEachLines = 1;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060000EB RID: 235 RVA: 0x00004BE6 File Offset: 0x00002DE6
|
|
internal bool shouldTestAll(int rown)
|
|
{
|
|
if (this.discoverEachLines > 0 && this.lastRowTested + this.discoverEachLines <= rown)
|
|
{
|
|
this.currentType = FilterType.FILTER_UNKNOWN;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Token: 0x060000EC RID: 236 RVA: 0x00004C0C File Offset: 0x00002E0C
|
|
internal void setPreference(double none, double sub, double up, double ave, double paeth)
|
|
{
|
|
this.preference = new double[] { none, sub, up, ave, paeth };
|
|
}
|
|
|
|
// Token: 0x060000ED RID: 237 RVA: 0x00004C3D File Offset: 0x00002E3D
|
|
internal bool computesStatistics()
|
|
{
|
|
return this.discoverEachLines > 0;
|
|
}
|
|
|
|
// Token: 0x060000EE RID: 238 RVA: 0x00004C48 File Offset: 0x00002E48
|
|
internal void fillResultsForFilter(int rown, FilterType type, double sum, int[] histo, bool tentative)
|
|
{
|
|
this.lastRowTested = rown;
|
|
this.lastSums[(int)type] = sum;
|
|
if (histo != null)
|
|
{
|
|
double num = ((rown == 0) ? 0.0 : 0.3);
|
|
double num2 = 1.0 - num;
|
|
double num3 = 0.0;
|
|
for (int i = 0; i < 256; i++)
|
|
{
|
|
double num4 = (double)histo[i] / (double)this.imgInfo.Cols;
|
|
num4 = this.histogram1[i] * num + num4 * num2;
|
|
if (tentative)
|
|
{
|
|
num3 += ((num4 > 1E-08) ? (num4 * Math.Log(num4)) : 0.0);
|
|
}
|
|
else
|
|
{
|
|
this.histogram1[i] = num4;
|
|
}
|
|
}
|
|
this.lastEntropies[(int)type] = -num3;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060000EF RID: 239 RVA: 0x00004D10 File Offset: 0x00002F10
|
|
internal FilterType gimmeFilterType(int rown, bool useEntropy)
|
|
{
|
|
if (this.currentType == FilterType.FILTER_UNKNOWN)
|
|
{
|
|
if (rown == 0)
|
|
{
|
|
this.currentType = FilterType.FILTER_SUB;
|
|
}
|
|
else
|
|
{
|
|
double num = double.MaxValue;
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
double num2 = (useEntropy ? this.lastEntropies[i] : this.lastSums[i]);
|
|
num2 /= this.preference[i];
|
|
if (num2 <= num)
|
|
{
|
|
num = num2;
|
|
this.currentType = (FilterType)i;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (this.configuredType == FilterType.FILTER_CYCLIC)
|
|
{
|
|
this.currentType = (this.currentType + 1) % (FilterType)5;
|
|
}
|
|
return this.currentType;
|
|
}
|
|
|
|
// Token: 0x04000088 RID: 136
|
|
private static readonly int COMPUTE_STATS_EVERY_N_LINES = 8;
|
|
|
|
// Token: 0x04000089 RID: 137
|
|
private readonly ImageInfo imgInfo;
|
|
|
|
// Token: 0x0400008A RID: 138
|
|
private readonly FilterType configuredType;
|
|
|
|
// Token: 0x0400008B RID: 139
|
|
private FilterType currentType;
|
|
|
|
// Token: 0x0400008C RID: 140
|
|
private int lastRowTested = -1000000;
|
|
|
|
// Token: 0x0400008D RID: 141
|
|
private double[] lastSums = new double[5];
|
|
|
|
// Token: 0x0400008E RID: 142
|
|
private double[] lastEntropies = new double[5];
|
|
|
|
// Token: 0x0400008F RID: 143
|
|
private double[] preference = new double[] { 1.1, 1.1, 1.1, 1.1, 1.2 };
|
|
|
|
// Token: 0x04000090 RID: 144
|
|
private int discoverEachLines = -1;
|
|
|
|
// Token: 0x04000091 RID: 145
|
|
private double[] histogram1 = new double[256];
|
|
}
|
|
}
|