private static void convertDataTrunk(PngihdrTrunk ihdrTrunk, byte[] conversionBuffer, int nMaxInflateBuffer)
{
if (conversionBuffer == null) throw new ArgumentNullException("conversionBuffer");
inflate(out conversionBuffer);
// Switch the color
int nIndex = 0;
for (int y = 0; y < ihdrTrunk.MnHeight; y++)
{
nIndex++;
for (int x = 0; x < ihdrTrunk.MnWidth; x++)
{
byte nTemp = conversionBuffer[nIndex];
conversionBuffer[nIndex] = conversionBuffer[nIndex + 2];
conversionBuffer[nIndex + 2] = nTemp;
nIndex += 4;
}
}
ZlibCodec deflater = deflate(conversionBuffer, nMaxInflateBuffer);
// Put the result in the first IDAT chunk (the only one to be written out)
PngTrunk firstDataTrunk = getTrunk("IDAT");
var crc32 = new CRC32();
foreach (byte b in System.Text.Encoding.UTF8.GetBytes(firstDataTrunk.getName()))
{
crc32.UpdateCRC(b);
}
crc32.UpdateCRC((byte)deflater.NextOut,(int)deflater.TotalBytesOut);
long lCrcValue = crc32.Crc32Result;
firstDataTrunk.MnData = deflater.OutputBuffer;
firstDataTrunk.MnCrc[0] = (byte) ((lCrcValue & 0xFF000000) >> 24);
firstDataTrunk.MnCrc[1] = (byte) ((lCrcValue & 0xFF0000) >> 16);
firstDataTrunk.MnCrc[2] = (byte) ((lCrcValue & 0xFF00) >> 8);
firstDataTrunk.MnCrc[3] = (byte) (lCrcValue & 0xFF);
firstDataTrunk.MnSize = (int) deflater.TotalBytesOut;
}