compressBytes() static private method

static private compressBytes ( byte ori, bool compress ) : byte[]
ori byte
compress bool
return byte[]
コード例 #1
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            int nullsep = -1;

            for (int i = 0; i < c.Data.Length; i++)   // look for first zero
            {
                if (c.Data[i] != 0)
                {
                    continue;
                }
                nullsep = i;
                break;
            }
            if (nullsep < 0 || nullsep > c.Data.Length - 2)
            {
                throw new PngjException("bad zTXt chunk: no separator found");
            }
            key = ChunkHelper.ToString(c.Data, 0, nullsep);
            int compmet = c.Data[nullsep + 1];

            if (compmet != 0)
            {
                throw new PngjException("bad zTXt chunk: unknown compression method");
            }
            byte[] uncomp = ChunkHelper.compressBytes(c.Data, nullsep + 2, c.Data.Length - nullsep - 2, false); // uncompress
            val = ChunkHelper.ToString(uncomp);
        }
コード例 #2
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new PngjException("Text chunk key must be non empty");
            }
            MemoryStream memoryStream = new MemoryStream();

            ChunkHelper.WriteBytesToStream(memoryStream, ChunkHelper.ToBytes(key));
            memoryStream.WriteByte(0);
            memoryStream.WriteByte((byte)(compressed ? 1 : 0));
            memoryStream.WriteByte(0);
            ChunkHelper.WriteBytesToStream(memoryStream, ChunkHelper.ToBytes(langTag));
            memoryStream.WriteByte(0);
            ChunkHelper.WriteBytesToStream(memoryStream, ChunkHelper.ToBytesUTF8(translatedTag));
            memoryStream.WriteByte(0);
            byte[] array = ChunkHelper.ToBytesUTF8(val);
            if (compressed)
            {
                array = ChunkHelper.compressBytes(array, compress: true);
            }
            ChunkHelper.WriteBytesToStream(memoryStream, array);
            byte[]   array2   = memoryStream.ToArray();
            ChunkRaw chunkRaw = createEmptyChunk(array2.Length, alloc: false);

            chunkRaw.Data = array2;
            return(chunkRaw);
        }
コード例 #3
0
ファイル: PngChunkITXT.cs プロジェクト: Jorch72/CS-pngcs
        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);
        }
コード例 #4
0
ファイル: PngChunkITXT.cs プロジェクト: Jorch72/CS-pngcs
        public override void ParseFromRaw(ChunkRaw c)
        {
            int nullsFound = 0;

            int[] nullsIdx = new int[3];
            for (int k = 0; k < c.Data.Length; k++)
            {
                if (c.Data[k] != 0)
                {
                    continue;
                }
                nullsIdx[nullsFound] = k;
                nullsFound++;
                if (nullsFound == 1)
                {
                    k += 2;
                }
                if (nullsFound == 3)
                {
                    break;
                }
            }
            if (nullsFound != 3)
            {
                throw new PngjException("Bad formed PngChunkITXT chunk");
            }
            key = ChunkHelper.ToString(c.Data, 0, nullsIdx[0]);
            int i = nullsIdx[0] + 1;

            compressed = c.Data[i] == 0 ? false : true;
            i++;
            if (compressed && c.Data[i] != 0)
            {
                throw new PngjException("Bad formed PngChunkITXT chunk - bad compression method ");
            }
            langTag       = ChunkHelper.ToString(c.Data, i, nullsIdx[1] - i);
            translatedTag = ChunkHelper.ToStringUTF8(c.Data, nullsIdx[1] + 1, nullsIdx[2] - nullsIdx[1] - 1);
            i             = nullsIdx[2] + 1;
            if (compressed)
            {
                byte[] bytes = ChunkHelper.compressBytes(c.Data, i, c.Data.Length - i, false);
                val = ChunkHelper.ToStringUTF8(bytes);
            }
            else
            {
                val = ChunkHelper.ToStringUTF8(c.Data, i, c.Data.Length - i);
            }
        }
コード例 #5
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            int num = 0;

            int[] array = new int[3];
            for (int i = 0; i < c.Data.Length; i++)
            {
                if (c.Data[i] == 0)
                {
                    array[num] = i;
                    num++;
                    if (num == 1)
                    {
                        i += 2;
                    }
                    if (num == 3)
                    {
                        break;
                    }
                }
            }
            if (num != 3)
            {
                throw new PngjException("Bad formed PngChunkITXT chunk");
            }
            key = ChunkHelper.ToString(c.Data, 0, array[0]);
            int num2 = array[0] + 1;

            compressed = ((c.Data[num2] != 0) ? true : false);
            num2++;
            if (compressed && c.Data[num2] != 0)
            {
                throw new PngjException("Bad formed PngChunkITXT chunk - bad compression method ");
            }
            langTag       = ChunkHelper.ToString(c.Data, num2, array[1] - num2);
            translatedTag = ChunkHelper.ToStringUTF8(c.Data, array[1] + 1, array[2] - array[1] - 1);
            num2          = array[2] + 1;
            if (compressed)
            {
                byte[] x = ChunkHelper.compressBytes(c.Data, num2, c.Data.Length - num2, compress: false);
                val = ChunkHelper.ToStringUTF8(x);
            }
            else
            {
                val = ChunkHelper.ToStringUTF8(c.Data, num2, c.Data.Length - num2);
            }
        }
コード例 #6
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);
        }
コード例 #7
0
        public override ChunkRaw CreateRawChunk()
        {
            if (key.Length == 0)
            {
                throw new PngjException("Text chunk key must be non empty");
            }
            MemoryStream memoryStream = new MemoryStream();

            ChunkHelper.WriteBytesToStream(memoryStream, ChunkHelper.ToBytes(key));
            memoryStream.WriteByte(0);
            memoryStream.WriteByte(0);
            byte[] bytes = ChunkHelper.compressBytes(ChunkHelper.ToBytes(val), compress: true);
            ChunkHelper.WriteBytesToStream(memoryStream, bytes);
            byte[]   array    = memoryStream.ToArray();
            ChunkRaw chunkRaw = createEmptyChunk(array.Length, alloc: false);

            chunkRaw.Data = array;
            return(chunkRaw);
        }
コード例 #8
0
        public override void ParseFromRaw(ChunkRaw c)
        {
            int num = -1;

            for (int i = 0; i < c.Data.Length; i++)
            {
                if (c.Data[i] == 0)
                {
                    num = i;
                    break;
                }
            }
            if (num < 0 || num > c.Data.Length - 2)
            {
                throw new PngjException("bad zTXt chunk: no separator found");
            }
            key = ChunkHelper.ToString(c.Data, 0, num);
            if (c.Data[num + 1] != 0)
            {
                throw new PngjException("bad zTXt chunk: unknown compression method");
            }
            byte[] x = ChunkHelper.compressBytes(c.Data, num + 2, c.Data.Length - num - 2, compress: false);
            val = ChunkHelper.ToString(x);
        }
コード例 #9
0
 public byte[] GetProfile()
 {
     return(ChunkHelper.compressBytes(compressedProfile, compress: false));
 }
コード例 #10
0
 public void SetProfileNameAndContent(string name, byte[] profile)
 {
     profileName       = name;
     compressedProfile = ChunkHelper.compressBytes(profile, compress: true);
 }