Beispiel #1
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new PngjException("Text chunk key must be non empty");
            }
            MemoryStream ba = new MemoryStream();

            ChunkHelper.WriteBytesToStream(ba, ChunkHelper.ToBytes(key));
            ba.WriteByte(0); // separator
            ba.WriteByte(compressed ? (byte)1 : (byte)0);
            ba.WriteByte(0); // compression method (always 0)
            ChunkHelper.WriteBytesToStream(ba, ChunkHelper.ToBytes(langTag));
            ba.WriteByte(0); // separator
            ChunkHelper.WriteBytesToStream(ba, ChunkHelper.ToBytesUTF8(translatedTag));
            ba.WriteByte(0); // separator
            byte[] textbytes = ChunkHelper.ToBytesUTF8(val);
            if (compressed)
            {
                textbytes = ChunkHelper.compressBytes(textbytes, true);
            }
            ChunkHelper.WriteBytesToStream(ba, textbytes);
            byte[]   b     = ba.ToArray();
            ChunkRaw chunk = createEmptyChunk(b.Length, false);

            chunk.Data = b;
            return(chunk);
        }
Beispiel #2
0
        public override ChunkRaw CreateRawChunk()
        {
            MemoryStream ba = new MemoryStream();

            ChunkHelper.WriteBytesToStream(ba, ChunkHelper.ToBytes(PalName));
            ba.WriteByte(0); // separator
            ba.WriteByte((byte)SampleDepth);
            int nentries = GetNentries();

            for (int n = 0; n < nentries; n++)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (SampleDepth == 8)
                    {
                        PngHelperInternal.WriteByte(ba, (byte)Palette[n * 5 + i]);
                    }
                    else
                    {
                        PngHelperInternal.WriteInt2(ba, Palette[n * 5 + i]);
                    }
                }
                PngHelperInternal.WriteInt2(ba, Palette[n * 5 + 4]);
            }
            byte[]   b     = ba.ToArray();
            ChunkRaw chunk = createEmptyChunk(b.Length, false);

            chunk.Data = b;
            return(chunk);
        }
Beispiel #3
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new PngjException("Text chunk key must be non empty");
            }
            MemoryStream ba = new MemoryStream();

            ChunkHelper.WriteBytesToStream(ba, ChunkHelper.ToBytes(key));
            ba.WriteByte(0); // separator
            ba.WriteByte(0); // compression method: 0
            byte[] textbytes = ChunkHelper.compressBytes(ChunkHelper.ToBytes(val), true);
            ChunkHelper.WriteBytesToStream(ba, textbytes);
            byte[]   b     = ba.ToArray();
            ChunkRaw chunk = createEmptyChunk(b.Length, false);

            chunk.Data = b;
            return(chunk);
        }