Ejemplo n.º 1
0
        /// <summary>
        /// ColorConverts the source BufferedImage.
        /// If the destination image is null,
        /// a BufferedImage will be created with an appropriate ColorModel. </summary>
        /// <param name="src"> the source <code>BufferedImage</code> to be converted </param>
        /// <param name="dest"> the destination <code>BufferedImage</code>,
        ///        or <code>null</code> </param>
        /// <returns> <code>dest</code> color converted from <code>src</code>
        ///         or a new, converted <code>BufferedImage</code>
        ///         if <code>dest</code> is <code>null</code> </returns>
        /// <exception cref="IllegalArgumentException"> if dest is null and this op was
        ///             constructed using the constructor which takes only a
        ///             RenderingHints argument, since the operation is ill defined. </exception>
        public BufferedImage Filter(BufferedImage src, BufferedImage dest)
        {
            ColorSpace    srcColorSpace, destColorSpace;
            BufferedImage savdest = null;

            if (src.ColorModel is IndexColorModel)
            {
                IndexColorModel icm = (IndexColorModel)src.ColorModel;
                src = icm.ConvertToIntDiscrete(src.Raster, true);
            }
            srcColorSpace = src.ColorModel.ColorSpace;
            if (dest != null)
            {
                if (dest.ColorModel is IndexColorModel)
                {
                    savdest        = dest;
                    dest           = null;
                    destColorSpace = null;
                }
                else
                {
                    destColorSpace = dest.ColorModel.ColorSpace;
                }
            }
            else
            {
                destColorSpace = null;
            }

            if ((CSList != null) || (!(srcColorSpace is ICC_ColorSpace)) || ((dest != null) && (!(destColorSpace is ICC_ColorSpace))))
            {
                /* non-ICC case */
                dest = NonICCBIFilter(src, srcColorSpace, dest, destColorSpace);
            }
            else
            {
                dest = ICCBIFilter(src, srcColorSpace, dest, destColorSpace);
            }

            if (savdest != null)
            {
                Graphics2D big = savdest.CreateGraphics();
                try
                {
                    big.DrawImage(dest, 0, 0, null);
                }
                finally
                {
                    big.Dispose();
                }
                return(savdest);
            }
            else
            {
                return(dest);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a convolution on BufferedImages.  Each component of the
        /// source image will be convolved (including the alpha component, if
        /// present).
        /// If the color model in the source image is not the same as that
        /// in the destination image, the pixels will be converted
        /// in the destination.  If the destination image is null,
        /// a BufferedImage will be created with the source ColorModel.
        /// The IllegalArgumentException may be thrown if the source is the
        /// same as the destination. </summary>
        /// <param name="src"> the source <code>BufferedImage</code> to filter </param>
        /// <param name="dst"> the destination <code>BufferedImage</code> for the
        ///        filtered <code>src</code> </param>
        /// <returns> the filtered <code>BufferedImage</code> </returns>
        /// <exception cref="NullPointerException"> if <code>src</code> is <code>null</code> </exception>
        /// <exception cref="IllegalArgumentException"> if <code>src</code> equals
        ///         <code>dst</code> </exception>
        /// <exception cref="ImagingOpException"> if <code>src</code> cannot be filtered </exception>
        public BufferedImage Filter(BufferedImage src, BufferedImage dst)
        {
            if (src == null)
            {
                throw new NullPointerException("src image is null");
            }
            if (src == dst)
            {
                throw new IllegalArgumentException("src image cannot be the " + "same as the dst image");
            }

            bool          needToConvert = false;
            ColorModel    srcCM         = src.ColorModel;
            ColorModel    dstCM;
            BufferedImage origDst = dst;

            // Can't convolve an IndexColorModel.  Need to expand it
            if (srcCM is IndexColorModel)
            {
                IndexColorModel icm = (IndexColorModel)srcCM;
                src   = icm.ConvertToIntDiscrete(src.Raster, false);
                srcCM = src.ColorModel;
            }

            if (dst == null)
            {
                dst     = CreateCompatibleDestImage(src, null);
                dstCM   = srcCM;
                origDst = dst;
            }
            else
            {
                dstCM = dst.ColorModel;
                if (srcCM.ColorSpace.Type != dstCM.ColorSpace.Type)
                {
                    needToConvert = true;
                    dst           = CreateCompatibleDestImage(src, null);
                    dstCM         = dst.ColorModel;
                }
                else if (dstCM is IndexColorModel)
                {
                    dst   = CreateCompatibleDestImage(src, null);
                    dstCM = dst.ColorModel;
                }
            }

            if (ImagingLib.filter(this, src, dst) == null)
            {
                throw new ImagingOpException("Unable to convolve src image");
            }

            if (needToConvert)
            {
                ColorConvertOp ccop = new ColorConvertOp(Hints);
                ccop.Filter(dst, origDst);
            }
            else if (origDst != dst)
            {
                java.awt.Graphics2D g = origDst.CreateGraphics();
                try
                {
                    g.DrawImage(dst, 0, 0, null);
                }
                finally
                {
                    g.Dispose();
                }
            }

            return(origDst);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructs a <code>BufferedImage</code> of one of the predefined
 /// image types:
 /// TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.
 /// </summary>
 public BufferedImage(int @width, int @height, int @imageType, IndexColorModel @cm)
 {
 }