Beispiel #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 = (int)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);
        }
Beispiel #2
0
        internal static PngChunk Factory(ChunkRaw chunk, ImageInfo info)
        {
            PngChunk c = FactoryFromId(ChunkHelper.ToString(chunk.IdBytes), info);

            c.Length = chunk.Len;
            c.ParseFromRaw(chunk);
            return(c);
        }
Beispiel #3
0
        public override void ParseFromRaw(ChunkRaw chunk)
        {
            byte[] data   = chunk.Data;
            int    length = data.Length;
            int    t      = -1;

            for (int i = 0; i < length; i++)           // look for first zero
            {
                if (data[i] == 0)
                {
                    t = i;
                    break;
                }
            }
            if (t <= 0 || t > length - 2)
            {
                throw new System.Exception("bad sPLT chunk: no separator found");
            }
            PalName     = ChunkHelper.ToString(data, 0, t);
            SampleDepth = PngHelperInternal.ReadInt1fromByte(data, t + 1);
            t          += 2;
            int nentries = (length - t) / (SampleDepth == 8 ? 6 : 10);

            Palette = new int[nentries * 5];
            int r, g, b, a, f, ne;

            ne = 0;
            for (int i = 0; i < nentries; i++)
            {
                if (SampleDepth == 8)
                {
                    r = PngHelperInternal.ReadInt1fromByte(data, t++);
                    g = PngHelperInternal.ReadInt1fromByte(data, t++);
                    b = PngHelperInternal.ReadInt1fromByte(data, t++);
                    a = PngHelperInternal.ReadInt1fromByte(data, t++);
                }
                else
                {
                    r  = PngHelperInternal.ReadInt2fromBytes(data, t);
                    t += 2;
                    g  = PngHelperInternal.ReadInt2fromBytes(data, t);
                    t += 2;
                    b  = PngHelperInternal.ReadInt2fromBytes(data, t);
                    t += 2;
                    a  = PngHelperInternal.ReadInt2fromBytes(data, t);
                    t += 2;
                }
                f             = PngHelperInternal.ReadInt2fromBytes(data, t);
                t            += 2;
                Palette[ne++] = r;
                Palette[ne++] = g;
                Palette[ne++] = b;
                Palette[ne++] = a;
                Palette[ne++] = f;
            }
        }
Beispiel #4
0
        public override void ParseFromRaw(ChunkRaw chunk)
        {
            byte[] data       = chunk.Data;
            int    length     = data.Length;
            int    nullsFound = 0;

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

            compressed = data[i] == 0 ? false : true;
            i++;
            if (compressed && data[i] != 0)
            {
                throw new System.Exception("Bad formed PngChunkITXT chunk - bad compression method ");
            }
            langTag       = ChunkHelper.ToString(data, i, nullsIdx[1] - i);
            translatedTag = ChunkHelper.ToStringUTF8(data, nullsIdx[1] + 1, nullsIdx[2] - nullsIdx[1] - 1);
            i             = nullsIdx[2] + 1;
            if (compressed)
            {
                byte[] bytes = ChunkHelper.CompressBytes(data, i, length - i, false);
                val = ChunkHelper.ToStringUTF8(bytes);
            }
            else
            {
                val = ChunkHelper.ToStringUTF8(data, i, length - i);
            }
        }
Beispiel #5
0
 internal void WriteChunk(Stream os)
 {
     if (IdBytes.Length != 4)
     {
         throw new PngjOutputException("bad chunkid [" + ChunkHelper.ToString(IdBytes) + "]");
     }
     crcval = ComputeCrc();
     PngHelperInternal.WriteInt4(os, Len);
     PngHelperInternal.WriteBytes(os, IdBytes);
     if (Len > 0)
     {
         PngHelperInternal.WriteBytes(os, Data, 0, Len);
     }
     //Console.WriteLine("writing chunk " + this.ToString() + "crc=" + crcval);
     PngHelperInternal.WriteInt4(os, crcval);
 }
Beispiel #6
0
 internal ChunkRaw(int length, byte[] idbytes, bool alloc) : this(length, ChunkHelper.ToString(idbytes), alloc)
 {
 }
Beispiel #7
0
 /// <summary>
 /// Just id and length
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("chunkid=" + ChunkHelper.ToString(IdBytes) + " len=" + Len);
 }
Beispiel #8
0
 public String GetProfileAsString()
 {
     return(ChunkHelper.ToString(GetProfile()));
 }