Image GetImage()
{
ReadPng();
int pal0 = 0;
int palIdx = 0;
palShades = false;
if (trans != null) {
for (int k = 0; k < trans.Length; ++k) {
int n = trans[k] & 0xff;
if (n == 0) {
++pal0;
palIdx = k;
}
if (n != 0 && n != 255) {
palShades = true;
break;
}
}
}
if ((colorType & 4) != 0)
palShades = true;
genBWMask = (!palShades && (pal0 > 1 || transRedGray >= 0));
if (!palShades && !genBWMask && pal0 == 1) {
additional.Put(PdfName.MASK, new PdfLiteral("["+palIdx+" "+palIdx+"]"));
}
bool needDecode = (interlaceMethod == 1) || (bitDepth == 16) || ((colorType & 4) != 0) || palShades || genBWMask;
switch (colorType) {
case 0:
inputBands = 1;
break;
case 2:
inputBands = 3;
break;
case 3:
inputBands = 1;
break;
case 4:
inputBands = 2;
break;
case 6:
inputBands = 4;
break;
}
if (needDecode)
DecodeIdat();
int components = inputBands;
if ((colorType & 4) != 0)
--components;
int bpc = bitDepth;
if (bpc == 16)
bpc = 8;
Image img;
if (image != null) {
if (colorType == 3)
img = new ImgRaw(width, height, components, bpc, image);
else
img = Image.GetInstance(width, height, components, bpc, image);
}
else {
img = new ImgRaw(width, height, components, bpc, idat.ToArray());
img.Deflated = true;
PdfDictionary decodeparms = new PdfDictionary();
decodeparms.Put(PdfName.BITSPERCOMPONENT, new PdfNumber(bitDepth));
decodeparms.Put(PdfName.PREDICTOR, new PdfNumber(15));
decodeparms.Put(PdfName.COLUMNS, new PdfNumber(width));
decodeparms.Put(PdfName.COLORS, new PdfNumber((colorType == 3 || (colorType & 2) == 0) ? 1 : 3));
additional.Put(PdfName.DECODEPARMS, decodeparms);
}
if (additional.Get(PdfName.COLORSPACE) == null)
additional.Put(PdfName.COLORSPACE, GetColorspace());
if (intent != null)
additional.Put(PdfName.INTENT, intent);
if (additional.Size > 0)
img.Additional = additional;
if (icc_profile != null)
img.TagICC = icc_profile;
if (palShades) {
Image im2 = Image.GetInstance(width, height, 1, 8, smask);
im2.MakeMask();
img.ImageMask = im2;
}
if (genBWMask) {
Image im2 = Image.GetInstance(width, height, 1, 1, smask);
im2.MakeMask();
img.ImageMask = im2;
}
img.SetDpi(dpiX, dpiY);
img.XYRatio = XYRatio;
img.OriginalType = Image.ORIGINAL_PNG;
return img;
}