Beispiel #1
0
        // yet
        private void WriteChunkIHDR()
        {
            byte[] temp4Bytes = new byte[4];
            byte[] buf        = new byte[13];

            switch (colorType)
            {
            case PNG.PNG_COLOR_TYPE_RGB:
                if (bitDepth != 8 && bitDepth != 16)
                {
                    throw new Exception("Invalid bit depth for RGB image.");
                }
                break;

            default:
                throw new Exception("Can't deal with color type without RGB.");
            }

            // actually, need to verify these parameter
            // colorType, bitDepth, compressionMethod, filterMethod, interlaceMethod

            PNGUtil.GetBigEndian32(temp4Bytes, (uint)width);
            Array.Copy(temp4Bytes, 0, buf, 0, temp4Bytes.Length);
            PNGUtil.GetBigEndian32(temp4Bytes, (uint)height);
            Array.Copy(temp4Bytes, 0, buf, 4, temp4Bytes.Length);
            buf[8]  = bitDepth;
            buf[9]  = colorType;
            buf[10] = compressionMethod;
            buf[11] = filterMethod;
            buf[12] = interlaceMethod;

            WriteChunk(PNGUtil.chunkNameIHDR, buf);
        }
Beispiel #2
0
        // yet
        private void WriteChunk(byte[] chunkName, byte[] data)
        {
            byte[] temp4Bytes = new byte[4];

            PNGUtil.GetBigEndian32(temp4Bytes, (uint)data.Length);

            dataStream.Write(temp4Bytes, 0, temp4Bytes.Length);
            dataStream.Write(chunkName, 0, chunkName.Length);
            dataStream.Write(data, 0, data.Length);

            uint crc = CRCChecker.CRC(chunkName, data);

            PNGUtil.GetBigEndian32(temp4Bytes, crc);
            dataStream.Write(temp4Bytes, 0, temp4Bytes.Length);
        }