/** * Reuses an existing image. * @param ref the reference to the image dictionary * @throws BadElementException on error * @return the image */ public static Image GetInstance(PRIndirectReference iref) { PdfDictionary dic = (PdfDictionary)PdfReader.GetPdfObjectRelease(iref); int width = ((PdfNumber)PdfReader.GetPdfObjectRelease(dic.Get(PdfName.WIDTH))).IntValue; int height = ((PdfNumber)PdfReader.GetPdfObjectRelease(dic.Get(PdfName.HEIGHT))).IntValue; Image imask = null; PdfObject obj = dic.Get(PdfName.SMASK); if (obj != null && obj.IsIndirect()) { imask = GetInstance((PRIndirectReference)obj); } else { obj = dic.Get(PdfName.MASK); if (obj != null && obj.IsIndirect()) { PdfObject obj2 = PdfReader.GetPdfObjectRelease(obj); if (obj2 is PdfDictionary) imask = GetInstance((PRIndirectReference)obj); } } Image img = new ImgRaw(width, height, 1, 1, null); img.imageMask = imask; img.directReference = iref; return img; }
/// <summary> /// Gets an instance of an Image in raw mode. /// </summary> /// <param name="width">the width of the image in pixels</param> /// <param name="height">the height of the image in pixels</param> /// <param name="components">1,3 or 4 for GrayScale, RGB and CMYK</param> /// <param name="bpc">bits per component</param> /// <param name="data">the image data</param> /// <param name="transparency"> /// transparency information in the Mask format of the /// image dictionary /// </param> /// <returns>an object of type ImgRaw</returns> public static Image GetInstance(int width, int height, int components, int bpc, byte[] data, int[] transparency) { if (transparency != null && transparency.Length != components * 2) throw new BadElementException("Transparency length must be equal to (componentes * 2)"); if (components == 1 && bpc == 1) { byte[] g4 = CCITTG4Encoder.Compress(data, width, height); return Image.GetInstance(width, height, false, Element.CCITTG4, Element.CCITT_BLACKIS1, g4, transparency); } Image img = new ImgRaw(width, height, components, bpc, data); img.transparency = transparency; return img; }
/** * Reads next frame image */ protected void ReadImage() { ix = ReadShort(); // (sub)image position & size iy = ReadShort(); iw = ReadShort(); ih = ReadShort(); int packed = inp.ReadByte(); lctFlag = (packed & 0x80) != 0; // 1 - local color table flag interlace = (packed & 0x40) != 0; // 2 - interlace flag // 3 - sort flag // 4-5 - reserved lctSize = 2 << (packed & 7); // 6-8 - local color table size m_bpc = NewBpc(m_gbpc); if (lctFlag) { m_curr_table = ReadColorTable((packed & 7) + 1); // read table m_bpc = NewBpc((packed & 7) + 1); } else { m_curr_table = m_global_table; } if (transparency && transIndex >= m_curr_table.Length / 3) transparency = false; if (transparency && m_bpc == 1) { // Acrobat 5.05 doesn't like this combination byte[] tp = new byte[12]; Array.Copy(m_curr_table, 0, tp, 0, 6); m_curr_table = tp; m_bpc = 2; } bool skipZero = DecodeImageData(); // decode pixel data if (!skipZero) Skip(); Image img = null; img = new ImgRaw(iw, ih, 1, m_bpc, m_out); PdfArray colorspace = new PdfArray(); colorspace.Add(PdfName.INDEXED); colorspace.Add(PdfName.DEVICERGB); int len = m_curr_table.Length; colorspace.Add(new PdfNumber(len / 3 - 1)); colorspace.Add(new PdfString(m_curr_table)); PdfDictionary ad = new PdfDictionary(); ad.Put(PdfName.COLORSPACE, colorspace); img.Additional = ad; if (transparency) { img.Transparency = new int[]{transIndex, transIndex}; } img.OriginalType = Image.ORIGINAL_GIF; img.OriginalData = fromData; img.Url = fromUrl; GifFrame gf = new GifFrame(); gf.image = img; gf.ix = ix; gf.iy = iy; frames.Add(gf); // add image to frame list //ResetFrame(); }