예제 #1
0
 /// <summary>Update original image with Raw Image parameters.</summary>
 /// <param name="image">to update its parameters with Raw Image parameters.</param>
 /// <param name="width">the exact width of the image</param>
 /// <param name="height">the exact height of the image</param>
 /// <param name="components">1,3 or 4 for GrayScale, RGB and CMYK</param>
 /// <param name="bpc">bits per component. Must be 1,2,4 or 8</param>
 /// <param name="data">the image data</param>
 protected internal static void UpdateRawImageParameters(RawImageData image, int width, int height, int components
                                                         , int bpc, byte[] data)
 {
     image.SetHeight(height);
     image.SetWidth(width);
     if (components != 1 && components != 3 && components != 4)
     {
         throw new iText.IO.IOException(iText.IO.IOException.ComponentsMustBe1_3Or4);
     }
     if (bpc != 1 && bpc != 2 && bpc != 4 && bpc != 8)
     {
         throw new iText.IO.IOException(iText.IO.IOException.BitsPerComponentMustBe1_2_4or8);
     }
     image.SetColorSpace(components);
     image.SetBpc(bpc);
     image.data = data;
 }
예제 #2
0
 protected internal static void UpdateCcittImageParameters(RawImageData image, int width, int height, bool
                                                           reverseBits, int typeCcitt, int parameters, byte[] data)
 {
     if (typeCcitt != RawImageData.CCITTG4 && typeCcitt != RawImageData.CCITTG3_1D && typeCcitt != RawImageData
         .CCITTG3_2D)
     {
         throw new iText.IO.IOException(iText.IO.IOException.CcittCompressionTypeMustBeCcittg4Ccittg3_1dOrCcittg3_2d
                                        );
     }
     if (reverseBits)
     {
         TIFFFaxDecoder.ReverseBits(data);
     }
     image.SetHeight(height);
     image.SetWidth(width);
     image.SetColorSpace(parameters);
     image.SetTypeCcitt(typeCcitt);
     image.data = data;
 }
예제 #3
0
        public static void UpdateImageAttributes(RawImageData image, IDictionary <String, Object> additional)
        {
            if (!image.IsRawImage())
            {
                throw new ArgumentException("Raw image expected.");
            }
            // will also have the CCITT parameters
            int colorSpace = image.GetColorSpace();
            int typeCCITT  = image.GetTypeCcitt();

            if (typeCCITT > 0xff)
            {
                if (!image.IsMask())
                {
                    image.SetColorSpace(1);
                }
                image.SetBpc(1);
                image.SetFilter("CCITTFaxDecode");
                int k = typeCCITT - RawImageData.CCITTG3_1D;
                IDictionary <String, Object> decodeparms = new Dictionary <String, Object>();
                if (k != 0)
                {
                    decodeparms.Put("K", k);
                }
                if ((colorSpace & RawImageData.CCITT_BLACKIS1) != 0)
                {
                    decodeparms.Put("BlackIs1", true);
                }
                if ((colorSpace & RawImageData.CCITT_ENCODEDBYTEALIGN) != 0)
                {
                    decodeparms.Put("EncodedByteAlign", true);
                }
                if ((colorSpace & RawImageData.CCITT_ENDOFLINE) != 0)
                {
                    decodeparms.Put("EndOfLine", true);
                }
                if ((colorSpace & RawImageData.CCITT_ENDOFBLOCK) != 0)
                {
                    decodeparms.Put("EndOfBlock", false);
                }
                decodeparms.Put("Columns", image.GetWidth());
                decodeparms.Put("Rows", image.GetHeight());
                image.decodeParms = decodeparms;
            }
            else
            {
                switch (colorSpace)
                {
                case 1: {
                    if (image.IsInverted())
                    {
                        image.decode = new float[] { 1, 0 };
                    }
                    break;
                }

                case 3: {
                    if (image.IsInverted())
                    {
                        image.decode = new float[] { 1, 0, 1, 0, 1, 0 };
                    }
                    break;
                }

                case 4:
                default: {
                    if (image.IsInverted())
                    {
                        image.decode = new float[] { 1, 0, 1, 0, 1, 0, 1, 0 };
                    }
                    break;
                }
                }
                if (additional != null)
                {
                    image.SetImageAttributes(additional);
                }
                if (image.IsMask() && (image.GetBpc() == 1 || image.GetBpc() > 8))
                {
                    image.SetColorSpace(-1);
                }
                if (image.IsDeflated())
                {
                    image.SetFilter("FlateDecode");
                }
            }
        }