Summary description for ICC_Profile.
Esempio n. 1
0
 /**
  * @see PdfStamperImp#setOutputIntents(String, String, String, String, ICC_Profile)
  */
 override public void SetOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile) {
     base.SetOutputIntents(outputConditionIdentifier, outputCondition, registryName, info, colorProfile);
     PdfArray a = extraCatalog.GetAsArray(PdfName.OUTPUTINTENTS);
     if(a != null) {
         PdfDictionary d = a.GetAsDict(0);
         if(d != null)
             d.Put(PdfName.S, PdfName.GTS_PDFA1);
     }
 }
Esempio n. 2
0
 public static ICC_Profile GetInstance(byte[] data) {
     if (data.Length < 128 || data[36] != 0x61 || data[37] != 0x63 
         || data[38] != 0x73 || data[39] != 0x70)
         throw new ArgumentException(MessageLocalization.GetComposedMessage("invalid.icc.profile"));
     ICC_Profile icc = new ICC_Profile();
     icc.data = data;
     cstags.TryGetValue(Encoding.ASCII.GetString(data, 16, 4), out icc.numComponents);
     return icc;
 }
Esempio n. 3
0
 public static ICC_Profile GetInstance(byte[] data) {
     if (data.Length < 128 | data[36] != 0x61 || data[37] != 0x63 
         || data[38] != 0x73 || data[39] != 0x70)
         throw new ArgumentException("Invalid ICC profile");
     ICC_Profile icc = new ICC_Profile();
     icc.data = data;
     object cs = cstags[Encoding.ASCII.GetString(data, 16, 4)];
     icc.numComponents = (cs == null ? 0 : (int)cs);
     return icc;
 }
Esempio n. 4
0
        public static ICC_Profile GetInstance(byte[] data, int numComponents) {
            if (data.Length < 128 || data[36] != 0x61 || data[37] != 0x63 
                || data[38] != 0x73 || data[39] != 0x70)
                throw new ArgumentException(MessageLocalization.GetComposedMessage("invalid.icc.profile"));
            ICC_Profile icc = new ICC_Profile();
            icc.data = data;

            if (!cstags.TryGetValue(Encoding.ASCII.GetString(data, 16, 4), out icc.numComponents)) {
                icc.numComponents = 0;
            }
            // invalid ICC
            if (icc.numComponents != numComponents) {
                throw new ArgumentException("ICC profile contains " + icc.numComponents + " component(s), the image data contains " + numComponents + " component(s)");
            }
            return icc;
        }
Esempio n. 5
0
 /**
 * Creates an ICC stream.
 *
 * @param   compressionLevel    the compressionLevel
 *
 * @param   profile an ICC profile
 * @since   2.1.3   (replacing the constructor without param compressionLevel)
 */
 public PdfICCBased(ICC_Profile profile, int compressionLevel) {
     int numberOfComponents = profile.NumComponents;
     switch (numberOfComponents) {
         case 1:
             Put(PdfName.ALTERNATE, PdfName.DEVICEGRAY);
             break;
         case 3:
             Put(PdfName.ALTERNATE, PdfName.DEVICERGB);
             break;
         case 4:
             Put(PdfName.ALTERNATE, PdfName.DEVICECMYK);
             break;
         default:
             throw new PdfException(numberOfComponents + " Component(s) is not supported in iText");
     }
     Put(PdfName.N, new PdfNumber(numberOfComponents));
     bytes = profile.Data;
     FlateCompress(compressionLevel);
 }
Esempio n. 6
0
 /**
 * Creates an ICC stream.
 *
 * @param   compressionLevel    the compressionLevel
 *
 * @param   profile an ICC profile
 * @since   2.1.3   (replacing the constructor without param compressionLevel)
 */
 public PdfICCBased(ICC_Profile profile, int compressionLevel) {
     int numberOfComponents = profile.NumComponents;
     switch (numberOfComponents) {
         case 1:
             Put(PdfName.ALTERNATE, PdfName.DEVICEGRAY);
             break;
         case 3:
             Put(PdfName.ALTERNATE, PdfName.DEVICERGB);
             break;
         case 4:
             Put(PdfName.ALTERNATE, PdfName.DEVICECMYK);
             break;
         default:
             throw new PdfException(MessageLocalization.GetComposedMessage("1.component.s.is.not.supported", numberOfComponents));
     }
     Put(PdfName.N, new PdfNumber(numberOfComponents));
     bytes = profile.Data;
     Put(PdfName.LENGTH, new PdfNumber(bytes.Length));
     FlateCompress(compressionLevel);
 }
Esempio n. 7
0
    //  [C11] Output intents

        /**
        * Sets the values of the output intent dictionary. Null values are allowed to
        * suppress any key.
        * @param outputConditionIdentifier a value
        * @param outputCondition a value
        * @param registryName a value
        * @param info a value
        * @param destOutputProfile a value
        * @throws IOException on error
        */
        public virtual void SetOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile)
        {
            PdfDictionary outa = ExtraCatalog; //force the creation
            outa = new PdfDictionary(PdfName.OUTPUTINTENT);
            if (outputCondition != null)
                outa.Put(PdfName.OUTPUTCONDITION, new PdfString(outputCondition, PdfObject.TEXT_UNICODE));
            if (outputConditionIdentifier != null)
                outa.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString(outputConditionIdentifier, PdfObject.TEXT_UNICODE));
            if (registryName != null)
                outa.Put(PdfName.REGISTRYNAME, new PdfString(registryName, PdfObject.TEXT_UNICODE));
            if (info != null)
                outa.Put(PdfName.INFO, new PdfString(info, PdfObject.TEXT_UNICODE));
            if (colorProfile != null) {
                PdfStream stream = new PdfICCBased(colorProfile, compressionLevel);
                outa.Put(PdfName.DESTOUTPUTPROFILE, AddToBody(stream).IndirectReference);
            }

            outa.Put(PdfName.S, PdfName.GTS_PDFX);

            extraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(outa));
        }
Esempio n. 8
0
 /**
 * Creates an ICC stream.
 * @param   profile an ICC profile
 */
 public PdfICCBased(ICC_Profile profile) : this(profile, DEFAULT_COMPRESSION) {
     ;
 }
Esempio n. 9
0
        /// <summary>
        /// Constructs an Image object duplicate.
        /// </summary>
        /// <param name="image">another Image object.</param>
        public Image(Image image) : base(image) {
            this.type = image.type;
            this.url = image.url;
            this.rawData = image.rawData;
            this.bpc = image.bpc;
            this.template = image.template;
            this.alignment = image.alignment;
            this.alt = image.alt;
            this.absoluteX = image.absoluteX;
            this.absoluteY = image.absoluteY;
            this.plainWidth = image.plainWidth;
            this.plainHeight = image.plainHeight;
            this.scaledWidth = image.scaledWidth;
            this.scaledHeight = image.scaledHeight;
            this.mySerialId = image.mySerialId;

            this.directReference = image.directReference;

            this.rotationRadians = image.rotationRadians;
            this.initialRotation = image.initialRotation;
            this.indentationLeft = image.indentationLeft;
            this.indentationRight = image.indentationRight;
            this.spacingBefore = image.spacingBefore;
            this.spacingAfter = image.spacingAfter;

            this.widthPercentage = image.widthPercentage;
            this.scaleToFitLineWhenOverflow = image.scaleToFitLineWhenOverflow;
            this.scaleToFitHeight = image.scaleToFitHeight;
            this.annotation = image.annotation;
            this.layer = image.layer;
            this.interpolation = image.interpolation;
            this.originalType = image.originalType;
            this.originalData = image.originalData;
            this.deflated = image.deflated;
            this.dpiX = image.dpiX;
            this.dpiY = image.dpiY;
            this.XYRatio = image.XYRatio;

            this.colorspace = image.colorspace;
            this.invert = image.invert;
            this.profile = image.profile;
            this.additional = image.additional;
            this.mask = image.mask;
            this.imageMask = image.imageMask;
            this.smask = image.smask;
            this.transparency = image.transparency;
            this.role = image.role;
            if (image.accessibleAttributes != null)
                this.accessibleAttributes = new Dictionary<PdfName, PdfObject>(image.accessibleAttributes);
            ID = image.ID;
        }
 /// <summary>
 /// Constructs an Image object duplicate.
 /// </summary>
 /// <param name="image">another Image object.</param>
 public Image(Image image)
     : base(image)
 {
     this.type = image.type;
     this.url = image.url;
     this.alignment = image.alignment;
     this.alt = image.alt;
     this.absoluteX = image.absoluteX;
     this.absoluteY = image.absoluteY;
     this.plainWidth = image.plainWidth;
     this.plainHeight = image.plainHeight;
     this.scaledWidth = image.scaledWidth;
     this.scaledHeight = image.scaledHeight;
     this.rotationRadians = image.rotationRadians;
     this.indentationLeft = image.indentationLeft;
     this.indentationRight = image.indentationRight;
     this.colorspace = image.colorspace;
     this.rawData = image.rawData;
     this.template = image.template;
     this.bpc = image.bpc;
     this.transparency = image.transparency;
     this.mySerialId = image.mySerialId;
     this.invert = image.invert;
     this.dpiX = image.dpiX;
     this.dpiY = image.dpiY;
     this.mask = image.mask;
     this.imageMask = image.imageMask;
     this.interpolation = image.interpolation;
     this.annotation = image.annotation;
     this.profile = image.profile;
     this.deflated = image.deflated;
     this.additional = image.additional;
     this.smask = image.smask;
     this.XYRatio = image.XYRatio;
     this.originalData = image.originalData;
     this.originalType = image.originalType;
     this.spacingAfter = image.spacingAfter;
     this.spacingBefore = image.spacingBefore;
     this.widthPercentage = image.widthPercentage;
     this.layer = image.layer;
     this.initialRotation = image.initialRotation;
     this.directReference = image.directReference;
 }
Esempio n. 11
0
        void ReadPng()
        {
            for (int i = 0; i < PNGID.Length; i++) {
                if (PNGID[i] != isp.ReadByte())	{
                    throw new IOException(MessageLocalization.GetComposedMessage("file.is.not.a.valid.png"));
                }
            }
            byte[] buffer = new byte[TRANSFERSIZE];
            while (true) {
                int len = GetInt(isp);
                String marker = GetString(isp);
                if (len < 0 || !CheckMarker(marker))
                    throw new IOException(MessageLocalization.GetComposedMessage("corrupted.png.file"));
                if (IDAT.Equals(marker)) {
                    int size;
                    while (len != 0) {
                        size = isp.Read(buffer, 0, Math.Min(len, TRANSFERSIZE));
                        if (size <= 0)
                            return;
                        idat.Write(buffer, 0, size);
                        len -= size;
                    }
                }
                else if (tRNS.Equals(marker)) {
                    switch (colorType) {
                        case 0:
                            if (len >= 2) {
                                len -= 2;
                                int gray = GetWord(isp);
                                if (bitDepth == 16)
                                    transRedGray = gray;
                                else
                                    additional.Put(PdfName.MASK, new PdfLiteral("["+gray+" "+gray+"]"));
                            }
                            break;
                        case 2:
                            if (len >= 6) {
                                len -= 6;
                                int red = GetWord(isp);
                                int green = GetWord(isp);
                                int blue = GetWord(isp);
                                if (bitDepth == 16) {
                                    transRedGray = red;
                                    transGreen = green;
                                    transBlue = blue;
                                }
                                else
                                    additional.Put(PdfName.MASK, new PdfLiteral("["+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)isp.ReadByte();
                                len = 0;
                            }
                            break;
                    }
                    Utilities.Skip(isp, len);
                }
                else if (IHDR.Equals(marker)) {
                    width = GetInt(isp);
                    height = GetInt(isp);

                    bitDepth = isp.ReadByte();
                    colorType = isp.ReadByte();
                    compressionMethod = isp.ReadByte();
                    filterMethod = isp.ReadByte();
                    interlaceMethod = isp.ReadByte();
                }
                else if (PLTE.Equals(marker)) {
                    if (colorType == 3) {
                        PdfArray colorspace = new PdfArray();
                        colorspace.Add(PdfName.INDEXED);
                        colorspace.Add(GetColorspace());
                        colorspace.Add(new PdfNumber(len / 3 - 1));
                        ByteBuffer colortable = new ByteBuffer();
                        while ((len--) > 0) {
                            colortable.Append_i(isp.ReadByte());
                        }
                        colorspace.Add(new PdfString(colorTable = colortable.ToByteArray()));
                        additional.Put(PdfName.COLORSPACE, colorspace);
                    }
                    else {
                        Utilities.Skip(isp, len);
                    }
                }
                else if (pHYs.Equals(marker)) {
                    int dx = GetInt(isp);
                    int dy = GetInt(isp);
                    int unit = isp.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 (cHRM.Equals(marker)) {
                    xW = (float)GetInt(isp) / 100000f;
                    yW = (float)GetInt(isp) / 100000f;
                    xR = (float)GetInt(isp) / 100000f;
                    yR = (float)GetInt(isp) / 100000f;
                    xG = (float)GetInt(isp) / 100000f;
                    yG = (float)GetInt(isp) / 100000f;
                    xB = (float)GetInt(isp) / 100000f;
                    yB = (float)GetInt(isp) / 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 (sRGB.Equals(marker)) {
                    int ri = isp.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 (gAMA.Equals(marker)) {
                    int gm = GetInt(isp);
                    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 (iCCP.Equals(marker)) {
                    do {
                        --len;
                    } while (isp.ReadByte() != 0);
                    isp.ReadByte();
                    --len;
                    byte[] icccom = new byte[len];
                    int p = 0;
                    while (len > 0) {
                        int r = isp.Read(icccom, p, len);
                        if (r < 0)
                            throw new IOException(MessageLocalization.GetComposedMessage("premature.end.of.file"));
                        p += r;
                        len -= r;
                    }
                    byte[] iccp = PdfReader.FlateDecode(icccom, true);
                    icccom = null;
                    try {
                        icc_profile = ICC_Profile.GetInstance(iccp);
                    }
                    catch {
                        icc_profile = null;
                    }
                }
                else if (IEND.Equals(marker)) {
                    break;
                }
                else {
                    Utilities.Skip(isp, len);
                }
                Utilities.Skip(isp, 4);
            }
        }
Esempio n. 12
0
 /**
  * Creates an ICC stream.
  * @param   profile an ICC profile
  */
 public PdfICCBased(ICC_Profile profile) : this(profile, DEFAULT_COMPRESSION)
 {
     ;
 }
Esempio n. 13
0
        /**
         * @see PdfWriter#setOutputIntents(String, String, String, String, ICC_Profile)
         */
        public override void SetOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile)
        {
            base.SetOutputIntents(outputConditionIdentifier, outputCondition, registryName, info, colorProfile);
            PdfArray a = extraCatalog.GetAsArray(PdfName.OUTPUTINTENTS);

            if (a != null)
            {
                PdfDictionary d = a.GetAsDict(0);
                if (d != null)
                {
                    d.Put(PdfName.S, PdfName.GTS_PDFA1);
                }
            }
            this.colorProfile = colorProfile;
        }