void ReadPng() { for (int i = 0; i < PNGID.Length; i++) { Assert(PNGID[i] == Inp.ReadByte()); } byte[] buffer = new byte[1024]; while (true) { int len = GetInt(Inp); uint chunktype = GetUInt(Inp); Assert(len >= 0); if (chunktype == IHDR) // header { Width = GetInt(Inp); Height = GetInt(Inp); BitDepth = Inp.ReadByte(); ColorType = Inp.ReadByte(); CompressionMethod = Inp.ReadByte(); FilterMethod = Inp.ReadByte(); InterlaceMethod = Inp.ReadByte(); } else if (chunktype == IDAT) // the image data { Util.Copy(Inp, Idat, len, buffer); } else if (chunktype == tRNS) // transparency information { switch (ColorType) { case 0: if (len >= 2) { len -= 2; int gray = GetWord(Inp); if (BitDepth == 16) { TransRedGray = gray; } else { Additional.Put(DictName.Mask, "[ " + gray + " " + gray + " ]"); } } break; case 2: if (len >= 6) { len -= 6; int red = GetWord(Inp); int green = GetWord(Inp); int blue = GetWord(Inp); if (BitDepth == 16) { TransRedGray = red; TransGreen = green; TransBlue = blue; } else { Additional.Put(DictName.Mask, "[ " + red + " " + red + " " + green + " " + green + " " + blue + " " + blue + " ]"); } } break; case 3: if (len > 0) { Trans = new byte[len]; for (int k = 0; k < len; ++k) { Trans[k] = ( byte )Inp.ReadByte(); } len = 0; } break; } Util.Skip(Inp, len); } else if (chunktype == PLTE) // contains the palette; list of colors. { if (ColorType == 3) { DictArray colorspace = new DictArray(); colorspace.Add(DictName.Indexed); colorspace.Add(GetColorspace()); colorspace.Add(len / 3 - 1); ColorTable = new byte[len]; int ix = 0; while ((len--) > 0) { ColorTable[ix++] = ( byte )Inp.ReadByte(); } colorspace.Add(new PdfByteStr(ColorTable)); Additional.Put(DictName.ColorSpace, colorspace); } else { Util.Skip(Inp, len); } } else if (chunktype == pHYs) // Currently nothing is done with this info. { int dx = GetInt(Inp); int dy = GetInt(Inp); int unit = Inp.ReadByte(); if (unit == 1) { DpiX = ( int )(( float )dx * 0.0254f + 0.5f); DpiY = ( int )(( float )dy * 0.0254f + 0.5f); } else { if (dy != 0) { XYRatio = ( float )dx / ( float )dy; } } } else if (chunktype == cHRM) // gives the chromaticity coordinates of the display primaries and white point. { xW = ( float )GetInt(Inp) / 100000f; yW = ( float )GetInt(Inp) / 100000f; xR = ( float )GetInt(Inp) / 100000f; yR = ( float )GetInt(Inp) / 100000f; xG = ( float )GetInt(Inp) / 100000f; yG = ( float )GetInt(Inp) / 100000f; xB = ( float )GetInt(Inp) / 100000f; yB = ( float )GetInt(Inp) / 100000f; HasCHRM = !(Math.Abs(xW) < 0.0001f || Math.Abs(yW) < 0.0001f || Math.Abs(xR) < 0.0001f || Math.Abs(yR) < 0.0001f || Math.Abs(xG) < 0.0001f || Math.Abs(yG) < 0.0001f || Math.Abs(xB) < 0.0001f || Math.Abs(yB) < 0.0001f); } else if (chunktype == sRGB) // indicates that the standard sRGB color space is used. { int ri = Inp.ReadByte(); Intent = Intents[ri]; Gamma = 2.2f; xW = 0.3127f; yW = 0.329f; xR = 0.64f; yR = 0.33f; xG = 0.3f; yG = 0.6f; xB = 0.15f; yB = 0.06f; HasCHRM = true; } else if (chunktype == gAMA) { int gm = GetInt(Inp); if (gm != 0) { Gamma = 100000f / ( float )gm; if (!HasCHRM) { xW = 0.3127f; yW = 0.329f; xR = 0.64f; yR = 0.33f; xG = 0.3f; yG = 0.6f; xB = 0.15f; yB = 0.06f; HasCHRM = true; } } } else if (chunktype == iCCP) { // Console.WriteLine( "iCCP chunk found" ); do { len -= 1; } while (Inp.ReadByte() != 0); Inp.ReadByte(); len -= 1; byte[] icc = new byte[len]; Util.ReadN(Inp, icc, 0, len); icc = Util.Inflate(icc); ICCP = ICC_Profile.GetInstance(icc); } else if (chunktype == IEND) { break; } else { Util.Skip(Inp, len); } Util.Skip(Inp, 4); } }
//public void AddZClassType(ZClassType ztype) //{ // if (ztype.SharpType.IsGenericType) // { // ImportGenericZTypes.Add(ztype.ZName, ztype); // } // else // { // ImportNormalZTypes.Add(ztype.ZName, ztype); // } //} //public void AddZEnum(ZEnumType zenum) //{ // ZEnumList.Add(zenum); //} //public void AddDim(ZDimType dimType) //{ // //ImportDimTypes.Add(dimType.ZName, dimType); // ImportDims.Add(dimType); //} public void AddNameWord(WordInfo word) { DictName.Add(word); }