public long getSizeInBytes()
        {
            long size = 0L;

            java.awt.image.Raster raster = this.bufferedImage.getRaster();
            if (raster != null)
            {
                java.awt.image.DataBuffer db = raster.getDataBuffer();
                if (db != null)
                {
                    size = sizeOfDataBuffer(db);
                }
            }
            return(size);
        }
Example #2
0
        /// <summary>
        /// Returns the bounding box of the transformed destination.  The
        /// rectangle returned will be the actual bounding box of the
        /// transformed points.  The coordinates of the upper-left corner
        /// of the returned rectangle might not be (0,&nbsp;0).
        /// </summary>
        /// <param name="src"> The <CODE>Raster</CODE> to be transformed.
        /// </param>
        /// <returns> The <CODE>Rectangle2D</CODE> representing the destination's
        /// bounding box. </returns>
        public Rectangle2D GetBounds2D(Raster src)
        {
            int w = src.Width;
            int h = src.Height;

            // Get the bounding box of the src and transform the corners
            float[] pts = new float[] { 0, 0, w, 0, w, h, 0, h };
            Xform.Transform(pts, 0, pts, 0, 4);

            // Get the min, max of the dst
            float fmaxX = pts[0];
            float fmaxY = pts[1];
            float fminX = pts[0];
            float fminY = pts[1];

            for (int i = 2; i < 8; i += 2)
            {
                if (pts[i] > fmaxX)
                {
                    fmaxX = pts[i];
                }
                else if (pts[i] < fminX)
                {
                    fminX = pts[i];
                }
                if (pts[i + 1] > fmaxY)
                {
                    fmaxY = pts[i + 1];
                }
                else if (pts[i + 1] < fminY)
                {
                    fminY = pts[i + 1];
                }
            }

            return(new Rectangle2D.Float(fminX, fminY, fmaxX - fminX, fmaxY - fminY));
        }
		/// <summary>
		/// Returns <code>true</code> if <code>raster</code> is compatible
		/// with this <code>ColorModel</code> and <code>false</code> if it is
		/// not.
		/// </summary>
		public bool isCompatibleRaster(Raster @raster)
		{
			return default(bool);
		}
Example #4
0
        /// <summary>
        /// ColorConverts the image data in the source Raster.
        /// If the destination Raster is null, a new Raster will be created.
        /// The number of bands in the source and destination Rasters must
        /// meet the requirements explained above.  The constructor used to
        /// create this ColorConvertOp must have provided enough information
        /// to define both source and destination color spaces.  See above.
        /// Otherwise, an exception is thrown. </summary>
        /// <param name="src"> the source <code>Raster</code> to be converted </param>
        /// <param name="dest"> the destination <code>WritableRaster</code>,
        ///        or <code>null</code> </param>
        /// <returns> <code>dest</code> color converted from <code>src</code>
        ///         or a new, converted <code>WritableRaster</code>
        ///         if <code>dest</code> is <code>null</code> </returns>
        /// <exception cref="IllegalArgumentException"> if the number of source or
        ///             destination bands is incorrect, the source or destination
        ///             color spaces are undefined, or this op was constructed
        ///             with one of the constructors that applies only to
        ///             operations on BufferedImages. </exception>
        public WritableRaster Filter(Raster src, WritableRaster dest)
        {
            if (CSList != null)
            {
                /* non-ICC case */
                return(NonICCRasterFilter(src, dest));
            }
            int nProfiles = ProfileList.Length;

            if (nProfiles < 2)
            {
                throw new IllegalArgumentException("Source or Destination ColorSpace is undefined");
            }
            if (src.NumBands != ProfileList[0].NumComponents)
            {
                throw new IllegalArgumentException("Numbers of source Raster bands and source color space " + "components do not match");
            }
            if (dest == null)
            {
                dest = CreateCompatibleDestRaster(src);
            }
            else
            {
                if (src.Height != dest.Height || src.Width != dest.Width)
                {
                    throw new IllegalArgumentException("Width or height of Rasters do not match");
                }
                if (dest.NumBands != ProfileList[nProfiles - 1].NumComponents)
                {
                    throw new IllegalArgumentException("Numbers of destination Raster bands and destination " + "color space components do not match");
                }
            }

            /* make a new transform if needed */
            if (ThisRasterTransform == null)
            {
                int i1, whichTrans, renderState;
                ColorTransform[] theTransforms;

                /* make the transform list */
                theTransforms = new ColorTransform [nProfiles];

                /* initialize transform get loop */
                if (ProfileList[0].ProfileClass == ICC_Profile.CLASS_OUTPUT)
                {
                    /* if first profile is a printer
                     * render as colorimetric */
                    renderState = ICC_Profile.IcRelativeColorimetric;
                }
                else
                {
                    renderState = ICC_Profile.IcPerceptual;                     /* render any other
                                                                                 * class perceptually */
                }

                whichTrans = ColorTransform.In;

                PCMM mdl = CMSManager.Module;

                /* get the transforms from each profile */
                for (i1 = 0; i1 < nProfiles; i1++)
                {
                    if (i1 == nProfiles - 1)             // last profile?
                    {
                        whichTrans = ColorTransform.Out; // get output transform
                    }
                    else                                 // check for abstract profile
                    {
                        if ((whichTrans == ColorTransform.Simulation) && (ProfileList[i1].ProfileClass == ICC_Profile.CLASS_ABSTRACT))
                        {
                            renderState = ICC_Profile.IcPerceptual;
                            whichTrans  = ColorTransform.In;
                        }
                    }

                    theTransforms[i1] = mdl.createTransform(ProfileList[i1], renderState, whichTrans);

                    /* get this profile's rendering intent to select transform
                     * from next profile */
                    renderState = GetRenderingIntent(ProfileList[i1]);

                    /* "middle" profiles use simulation transform */
                    whichTrans = ColorTransform.Simulation;
                }

                /* make the net transform */
                ThisRasterTransform = mdl.createTransform(theTransforms);
            }

            int srcTransferType = src.TransferType;
            int dstTransferType = dest.TransferType;

            if ((srcTransferType == DataBuffer.TYPE_FLOAT) || (srcTransferType == DataBuffer.TYPE_DOUBLE) || (dstTransferType == DataBuffer.TYPE_FLOAT) || (dstTransferType == DataBuffer.TYPE_DOUBLE))
            {
                if (SrcMinVals == null)
                {
                    GetMinMaxValsFromProfiles(ProfileList[0], ProfileList[nProfiles - 1]);
                }
                /* color convert the raster */
                ThisRasterTransform.colorConvert(src, dest, SrcMinVals, SrcMaxVals, DstMinVals, DstMaxVals);
            }
            else
            {
                /* color convert the raster */
                ThisRasterTransform.colorConvert(src, dest);
            }


            return(dest);
        }
Example #5
0
 /// <summary>
 /// Returns the bounding box of the filtered destination Raster.  Since
 /// this is not a geometric operation, the bounding box does not
 /// change.
 /// </summary>
 public Rectangle2D GetBounds2D(Raster src)
 {
     return(src.Bounds);
 }
Example #6
0
        /// <summary>
        /// Rescales the pixel data in the source Raster.
        /// If the destination Raster is null, a new Raster will be created.
        /// The source and destination must have the same number of bands.
        /// Otherwise, an IllegalArgumentException is thrown.
        /// Note that the number of scaling factors/offsets in this object must
        /// meet the restrictions stated in the class comments above.
        /// Otherwise, an IllegalArgumentException is thrown. </summary>
        /// <param name="src"> the <code>Raster</code> to be filtered </param>
        /// <param name="dst"> the destination for the filtering operation
        ///            or <code>null</code> </param>
        /// <returns> the filtered <code>WritableRaster</code>. </returns>
        /// <exception cref="IllegalArgumentException"> if <code>src</code> and
        ///         <code>dst</code> do not have the same number of bands,
        ///         or if the number of scaling factors and offsets in this
        ///         <code>RescaleOp</code> do not meet the requirements
        ///         stated in the class comments. </exception>
        public WritableRaster Filter(Raster src, WritableRaster dst)
        {
            int numBands = src.NumBands;
            int width    = src.Width;
            int height   = src.Height;

            int[] srcPix = null;
            int   step   = 0;
            int   tidx   = 0;

            // Create a new destination Raster, if needed
            if (dst == null)
            {
                dst = CreateCompatibleDestRaster(src);
            }
            else if (height != dst.Height || width != dst.Width)
            {
                throw new IllegalArgumentException("Width or height of Rasters do not " + "match");
            }
            else if (numBands != dst.NumBands)
            {
                // Make sure that the number of bands are equal
                throw new IllegalArgumentException("Number of bands in src " + numBands + " does not equal number of bands in dest " + dst.NumBands);
            }
            // Make sure that the arrays match
            // Make sure that the low/high/constant arrays match
            if (Length != 1 && Length != src.NumBands)
            {
                throw new IllegalArgumentException("Number of scaling constants " + "does not equal the number of" + " of bands in the src raster");
            }


            //
            // Try for a native raster rescale first
            //
            if (ImagingLib.filter(this, src, dst) != null)
            {
                return(dst);
            }

            //
            // Native raster rescale failed.
            // Try to see if a lookup operation can be used
            //
            if (CanUseLookup(src, dst))
            {
                int srcNgray = (1 << SrcNbits);
                int dstNgray = (1 << DstNbits);

                if (dstNgray == 256)
                {
                    ByteLookupTable lut = CreateByteLut(ScaleFactors, Offsets, numBands, srcNgray);
                    LookupOp        op  = new LookupOp(lut, Hints);
                    op.Filter(src, dst);
                }
                else
                {
                    ShortLookupTable lut = CreateShortLut(ScaleFactors, Offsets, numBands, srcNgray);
                    LookupOp         op  = new LookupOp(lut, Hints);
                    op.Filter(src, dst);
                }
            }
            else
            {
                //
                // Fall back to the slow code
                //
                if (Length > 1)
                {
                    step = 1;
                }

                int sminX = src.MinX;
                int sY    = src.MinY;
                int dminX = dst.MinX;
                int dY    = dst.MinY;
                int sX;
                int dX;

                //
                //  Determine bits per band to determine maxval for clamps.
                //  The min is assumed to be zero.
                //  REMIND: This must change if we ever support signed data types.
                //
                int         nbits;
                int[]       dstMax  = new int[numBands];
                int[]       dstMask = new int[numBands];
                SampleModel dstSM   = dst.SampleModel;
                for (int z = 0; z < numBands; z++)
                {
                    nbits      = dstSM.GetSampleSize(z);
                    dstMax[z]  = (1 << nbits) - 1;
                    dstMask[z] = ~(dstMax[z]);
                }

                int val;
                for (int y = 0; y < height; y++, sY++, dY++)
                {
                    dX = dminX;
                    sX = sminX;
                    for (int x = 0; x < width; x++, sX++, dX++)
                    {
                        // Get data for all bands at this x,y position
                        srcPix = src.GetPixel(sX, sY, srcPix);
                        tidx   = 0;
                        for (int z = 0; z < numBands; z++, tidx += step)
                        {
                            val = (int)(srcPix[z] * ScaleFactors[tidx] + Offsets[tidx]);
                            // Clamp
                            if ((val & dstMask[z]) != 0)
                            {
                                if (val < 0)
                                {
                                    val = 0;
                                }
                                else
                                {
                                    val = dstMax[z];
                                }
                            }
                            srcPix[z] = val;
                        }

                        // Put it back for all bands
                        dst.SetPixel(dX, dY, srcPix);
                    }
                }
            }
            return(dst);
        }
Example #7
0
 /// <summary>
 /// Constructs a Raster with the given SampleModel, DataBuffer, and
 /// parent.
 /// </summary>
 public Raster(SampleModel @sampleModel, DataBuffer @dataBuffer, Rectangle @aRegion, Point @sampleModelTranslate, Raster @parent)
 {
 }
Example #8
0
        /// <summary>
        /// Creates a zeroed destination image with the correct size and number of
        /// bands.  If destCM is <code>null</code>, an appropriate
        /// <code>ColorModel</code> will be used. </summary>
        /// <param name="src">       Source image for the filter operation. </param>
        /// <param name="destCM">    the destination's <code>ColorModel</code>, which
        ///                  can be <code>null</code>. </param>
        /// <returns> a filtered destination <code>BufferedImage</code>. </returns>
        public virtual BufferedImage CreateCompatibleDestImage(BufferedImage src, ColorModel destCM)
        {
            BufferedImage image;
            int           w            = src.Width;
            int           h            = src.Height;
            int           transferType = DataBuffer.TYPE_BYTE;

            if (destCM == null)
            {
                ColorModel cm     = src.ColorModel;
                Raster     raster = src.Raster;
                if (cm is ComponentColorModel)
                {
                    DataBuffer db       = raster.DataBuffer;
                    bool       hasAlpha = cm.HasAlpha();
                    bool       isPre    = cm.AlphaPremultiplied;
                    int        trans    = cm.Transparency;
                    int[]      nbits    = null;
                    if (Ltable is ByteLookupTable)
                    {
                        if (db.DataType == db.TYPE_USHORT)
                        {
                            // Dst raster should be of type byte
                            if (hasAlpha)
                            {
                                nbits = new int[2];
                                if (trans == cm.BITMASK)
                                {
                                    nbits[1] = 1;
                                }
                                else
                                {
                                    nbits[1] = 8;
                                }
                            }
                            else
                            {
                                nbits = new int[1];
                            }
                            nbits[0] = 8;
                        }
                        // For byte, no need to change the cm
                    }
                    else if (Ltable is ShortLookupTable)
                    {
                        transferType = DataBuffer.TYPE_USHORT;
                        if (db.DataType == db.TYPE_BYTE)
                        {
                            if (hasAlpha)
                            {
                                nbits = new int[2];
                                if (trans == cm.BITMASK)
                                {
                                    nbits[1] = 1;
                                }
                                else
                                {
                                    nbits[1] = 16;
                                }
                            }
                            else
                            {
                                nbits = new int[1];
                            }
                            nbits[0] = 16;
                        }
                    }
                    if (nbits != null)
                    {
                        cm = new ComponentColorModel(cm.ColorSpace, nbits, hasAlpha, isPre, trans, transferType);
                    }
                }
                image = new BufferedImage(cm, cm.CreateCompatibleWritableRaster(w, h), cm.AlphaPremultiplied, null);
            }
            else
            {
                image = new BufferedImage(destCM, destCM.CreateCompatibleWritableRaster(w, h), destCM.AlphaPremultiplied, null);
            }

            return(image);
        }
        /// <summary>
        /// Encodes and writes raster data as a 24-bit bitmap.
        /// </summary>
        /// <param name="raster">
        ///            the source raster data </param>
        private void Write24(Raster raster)
        {
            int width = raster.getWidth();
            int height = raster.getHeight();

            // calculate bytes per line
            int bytesPerLine = GetBytesPerLine24(width);

            // write lines
            for (int y = height - 1; y >= 0; y--)
            {

                // write pixel data for each line
                for (int x = 0; x < width; x++)
                {

                    // get RGB values for pixel
                    byte r = (byte)raster.getSample(x, y, 0);
                    byte g = (byte)raster.getSample(x, y, 1);
                    byte b = (byte)raster.getSample(x, y, 2);

                    // write RGB values
                    writer.Write(b);
                    writer.Write(g);
                    writer.Write(r);
                }

                // write padding bytes at end of line
                for (int i = width * 3; i < bytesPerLine; i++)
                {
                    writer.Write((byte)0);
                }
            }
        }
		/// <summary>
		/// Copies pixels from Raster srcRaster to this WritableRaster.
		/// </summary>
		public void setRect(Raster @srcRaster)
		{
		}
        /// <summary>
        /// Encodes and writes raster data as a 4-bit bitmap.
        /// </summary>
        /// <param name="raster">
        ///            the source raster data </param>
        private void Write4(Raster raster)
        {
            int width = raster.getWidth();
            int height = raster.getHeight();

            // calculate bytes per line
            int bytesPerLine = GetBytesPerLine4(width);

            // line buffer
            byte[] line = new byte[bytesPerLine];

            // encode and write lines
            for (int y = height - 1; y >= 0; y--)
            {

                // clear line buffer
                for (int i = 0; i < bytesPerLine; i++)
                {
                    line[i] = 0;
                }

                // encode raster data for line
                for (int x = 0; x < width; x++)
                {

                    // calculate buffer index
                    int bi = x / 2;

                    // calculate nibble index (high order or low order)
                    int i = x % 2;

                    // get color index
                    int index = raster.getSample(x, y, 0);
                    // set color index in buffer
                    line[bi] = SetNibble(line[bi], i, index);
                }

                // write line data (padding bytes included)
                writer.Write(line);
            }
        }
        /// <summary>
        /// Encodes and writes raster data as an 8-bit bitmap.
        /// </summary>
        /// <param name="raster">
        ///            the source raster data </param>
        private void Write8(Raster raster)
        {
            int width = raster.getWidth();
            int height = raster.getHeight();

            // calculate bytes per line
            int bytesPerLine = GetBytesPerLine8(width);

            // write lines
            for (int y = height - 1; y >= 0; y--)
            {

                // write raster data for each line
                for (int x = 0; x < width; x++)
                {

                    // get color index for pixel
                    byte index = (byte)raster.getSample(x, y, 0);

                    // write color index
                    writer.Write(index);
                }

                // write padding bytes at end of line
                for (int i = width; i < bytesPerLine; i++)
                {
                    writer.Write((byte)0);
                }

            }
        }
        /// <summary>
        /// Encodes and writes raster data as a 1-bit bitmap.
        /// </summary>
        /// <param name="raster">
        ///            the source raster data </param>
        private void Write1(Raster raster)
        {
            int bytesPerLine = GetBytesPerLine1(raster.getWidth());

            byte[] line = new byte[bytesPerLine];

            for (int y = raster.getHeight() - 1; y >= 0; y--)
            {
                for (int i = 0; i < bytesPerLine; i++)
                {
                    line[i] = 0;
                }

                for (int x = 0; x < raster.getWidth(); x++)
                {
                    int bi = x / 8;
                    int i = x % 8;
                    int index = raster.getSample(x, y, 0);
                    line[bi] = SetBit(line[bi], i, index);
                }

                writer.Write(line);
            }
        }
		/// <summary>
		/// Sets a rectangular region of the image to the contents of the
		/// specified <code>Raster</code> <code>r</code>, which is
		/// assumed to be in the same coordinate space as the
		/// <code>BufferedImage</code>.
		/// </summary>
		public void setData(Raster @r)
		{
		}
Example #15
0
 /// <summary>
 /// Creates a zeroed-destination <code>Raster</code> with the correct
 /// size and number of bands, given this source. </summary>
 /// <param name="src">       the source <code>Raster</code> </param>
 /// <returns> the zeroed-destination <code>Raster</code>. </returns>
 public virtual WritableRaster CreateCompatibleDestRaster(Raster src)
 {
     return(src.CreateCompatibleWritableRaster(src.Width, src.Height));
 }
Example #16
0
        private BufferedImage NonICCBIFilter(BufferedImage src, ColorSpace srcColorSpace, BufferedImage dst, ColorSpace dstColorSpace)
        {
            int            w        = src.Width;
            int            h        = src.Height;
            ICC_ColorSpace ciespace = (ICC_ColorSpace)ColorSpace.GetInstance(ColorSpace.CS_CIEXYZ);

            if (dst == null)
            {
                dst           = CreateCompatibleDestImage(src, null);
                dstColorSpace = dst.ColorModel.ColorSpace;
            }
            else
            {
                if ((h != dst.Height) || (w != dst.Width))
                {
                    throw new IllegalArgumentException("Width or height of BufferedImages do not match");
                }
            }
            Raster         srcRas       = src.Raster;
            WritableRaster dstRas       = dst.Raster;
            ColorModel     srcCM        = src.ColorModel;
            ColorModel     dstCM        = dst.ColorModel;
            int            srcNumComp   = srcCM.NumColorComponents;
            int            dstNumComp   = dstCM.NumColorComponents;
            bool           dstHasAlpha  = dstCM.HasAlpha();
            bool           needSrcAlpha = srcCM.HasAlpha() && dstHasAlpha;

            ColorSpace[] list;
            if ((CSList == null) && (ProfileList.Length != 0))
            {
                /* possible non-ICC src, some profiles, possible non-ICC dst */
                bool        nonICCSrc, nonICCDst;
                ICC_Profile srcProfile, dstProfile;
                if (!(srcColorSpace is ICC_ColorSpace))
                {
                    nonICCSrc  = true;
                    srcProfile = ciespace.Profile;
                }
                else
                {
                    nonICCSrc  = false;
                    srcProfile = ((ICC_ColorSpace)srcColorSpace).Profile;
                }
                if (!(dstColorSpace is ICC_ColorSpace))
                {
                    nonICCDst  = true;
                    dstProfile = ciespace.Profile;
                }
                else
                {
                    nonICCDst  = false;
                    dstProfile = ((ICC_ColorSpace)dstColorSpace).Profile;
                }
                /* make a new transform if needed */
                if ((ThisTransform == null) || (ThisSrcProfile != srcProfile) || (ThisDestProfile != dstProfile))
                {
                    UpdateBITransform(srcProfile, dstProfile);
                }
                // process per scanline
                float      maxNum = 65535.0f;            // use 16-bit precision in CMM
                ColorSpace cs;
                int        iccSrcNumComp;
                if (nonICCSrc)
                {
                    cs            = ciespace;
                    iccSrcNumComp = 3;
                }
                else
                {
                    cs            = srcColorSpace;
                    iccSrcNumComp = srcNumComp;
                }
                float[] srcMinVal        = new float[iccSrcNumComp];
                float[] srcInvDiffMinMax = new float[iccSrcNumComp];
                for (int i = 0; i < srcNumComp; i++)
                {
                    srcMinVal[i]        = cs.GetMinValue(i);
                    srcInvDiffMinMax[i] = maxNum / (cs.GetMaxValue(i) - srcMinVal[i]);
                }
                int iccDstNumComp;
                if (nonICCDst)
                {
                    cs            = ciespace;
                    iccDstNumComp = 3;
                }
                else
                {
                    cs            = dstColorSpace;
                    iccDstNumComp = dstNumComp;
                }
                float[] dstMinVal     = new float[iccDstNumComp];
                float[] dstDiffMinMax = new float[iccDstNumComp];
                for (int i = 0; i < dstNumComp; i++)
                {
                    dstMinVal[i]     = cs.GetMinValue(i);
                    dstDiffMinMax[i] = (cs.GetMaxValue(i) - dstMinVal[i]) / maxNum;
                }
                float[] dstColor;
                if (dstHasAlpha)
                {
                    int size = ((dstNumComp + 1) > 3) ? (dstNumComp + 1) : 3;
                    dstColor = new float[size];
                }
                else
                {
                    int size = (dstNumComp > 3) ? dstNumComp : 3;
                    dstColor = new float[size];
                }
                short[] srcLine = new short[w * iccSrcNumComp];
                short[] dstLine = new short[w * iccDstNumComp];
                Object  pixel;
                float[] color;
                float[] alpha = null;
                if (needSrcAlpha)
                {
                    alpha = new float[w];
                }
                int idx;
                // process each scanline
                for (int y = 0; y < h; y++)
                {
                    // convert src scanline
                    pixel = null;
                    color = null;
                    idx   = 0;
                    for (int x = 0; x < w; x++)
                    {
                        pixel = srcRas.GetDataElements(x, y, pixel);
                        color = srcCM.GetNormalizedComponents(pixel, color, 0);
                        if (needSrcAlpha)
                        {
                            alpha[x] = color[srcNumComp];
                        }
                        if (nonICCSrc)
                        {
                            color = srcColorSpace.ToCIEXYZ(color);
                        }
                        for (int i = 0; i < iccSrcNumComp; i++)
                        {
                            srcLine[idx++] = (short)((color[i] - srcMinVal[i]) * srcInvDiffMinMax[i] + 0.5f);
                        }
                    }
                    // color convert srcLine to dstLine
                    ThisTransform.colorConvert(srcLine, dstLine);
                    // convert dst scanline
                    pixel = null;
                    idx   = 0;
                    for (int x = 0; x < w; x++)
                    {
                        for (int i = 0; i < iccDstNumComp; i++)
                        {
                            dstColor[i] = ((float)(dstLine[idx++] & 0xffff)) * dstDiffMinMax[i] + dstMinVal[i];
                        }
                        if (nonICCDst)
                        {
                            color = srcColorSpace.FromCIEXYZ(dstColor);
                            for (int i = 0; i < dstNumComp; i++)
                            {
                                dstColor[i] = color[i];
                            }
                        }
                        if (needSrcAlpha)
                        {
                            dstColor[dstNumComp] = alpha[x];
                        }
                        else if (dstHasAlpha)
                        {
                            dstColor[dstNumComp] = 1.0f;
                        }
                        pixel = dstCM.GetDataElements(dstColor, 0, pixel);
                        dstRas.SetDataElements(x, y, pixel);
                    }
                }
            }
            else
            {
                /* possible non-ICC src, possible CSList, possible non-ICC dst */
                // process per pixel
                int numCS;
                if (CSList == null)
                {
                    numCS = 0;
                }
                else
                {
                    numCS = CSList.Length;
                }
                float[] dstColor;
                if (dstHasAlpha)
                {
                    dstColor = new float[dstNumComp + 1];
                }
                else
                {
                    dstColor = new float[dstNumComp];
                }
                Object  spixel = null;
                Object  dpixel = null;
                float[] color  = null;
                float[] tmpColor;
                // process each pixel
                for (int y = 0; y < h; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        spixel   = srcRas.GetDataElements(x, y, spixel);
                        color    = srcCM.GetNormalizedComponents(spixel, color, 0);
                        tmpColor = srcColorSpace.ToCIEXYZ(color);
                        for (int i = 0; i < numCS; i++)
                        {
                            tmpColor = CSList[i].FromCIEXYZ(tmpColor);
                            tmpColor = CSList[i].ToCIEXYZ(tmpColor);
                        }
                        tmpColor = dstColorSpace.FromCIEXYZ(tmpColor);
                        for (int i = 0; i < dstNumComp; i++)
                        {
                            dstColor[i] = tmpColor[i];
                        }
                        if (needSrcAlpha)
                        {
                            dstColor[dstNumComp] = color[srcNumComp];
                        }
                        else if (dstHasAlpha)
                        {
                            dstColor[dstNumComp] = 1.0f;
                        }
                        dpixel = dstCM.GetDataElements(dstColor, 0, dpixel);
                        dstRas.SetDataElements(x, y, dpixel);
                    }
                }
            }

            return(dst);
        }
        /// <summary>
        /// Encodes and writes raster data, together with alpha (transparency) data,
        /// as a 32-bit bitmap.
        /// </summary>
        /// <param name="raster">
        ///            the source raster data </param>
        /// <param name="alpha">
        ///            the source alpha data </param>
        private void Write32(Raster raster, Raster alpha)
        {
            int width = raster.getWidth();
            int height = raster.getHeight();

            // write lines
            for (int y = height - 1; y >= 0; y--)
            {

                // write pixel data for each line
                for (int x = 0; x < width; x++)
                {

                    // get RGBA values
                    byte r = (byte)raster.getSample(x, y, 0);
                    byte g = (byte)raster.getSample(x, y, 1);
                    byte b = (byte)raster.getSample(x, y, 2);
                    byte a = (byte)alpha.getSample(x, y, 0);

                    // write RGBA values
                    writer.Write(b);
                    writer.Write(g);
                    writer.Write(r);
                    writer.Write(a);
                }
            }
        }
		/// <summary>
		/// Copies pixels from Raster srcRaster to this WritableRaster.
		/// </summary>
		public void setRect(int @dx, int @dy, Raster @srcRaster)
		{
		}
Example #19
0
        /// <summary>
        /// Transforms the <CODE>Raster</CODE> using the matrix specified in the
        /// constructor. An <CODE>IllegalArgumentException</CODE> may be thrown if
        /// the number of bands in the source or destination is incompatible with
        /// the matrix.  See the class comments for more details.
        /// <para>
        /// If the destination is null, it will be created with a number of bands
        /// equalling the number of rows in the matrix. No exception is thrown
        /// if the operation causes a data overflow.
        ///
        /// </para>
        /// </summary>
        /// <param name="src"> The <CODE>Raster</CODE> to be filtered. </param>
        /// <param name="dst"> The <CODE>Raster</CODE> in which to store the results
        /// of the filter operation.
        /// </param>
        /// <returns> The filtered <CODE>Raster</CODE>.
        /// </returns>
        /// <exception cref="IllegalArgumentException"> If the number of bands in the
        /// source or destination is incompatible with the matrix. </exception>
        public virtual WritableRaster Filter(Raster src, WritableRaster dst)
        {
            int nBands = src.NumBands;

            if (Ncols != nBands && Ncols != (nBands + 1))
            {
                throw new IllegalArgumentException("Number of columns in the " + "matrix (" + Ncols + ") must be equal to the number" + " of bands ([+1]) in src (" + nBands + ").");
            }
            if (dst == null)
            {
                dst = CreateCompatibleDestRaster(src);
            }
            else if (Nrows != dst.NumBands)
            {
                throw new IllegalArgumentException("Number of rows in the " + "matrix (" + Nrows + ") must be equal to the number" + " of bands ([+1]) in dst (" + nBands + ").");
            }

            if (ImagingLib.filter(this, src, dst) != null)
            {
                return(dst);
            }

            int[] pixel    = null;
            int[] dstPixel = new int[dst.NumBands];
            float accum;
            int   sminX = src.MinX;
            int   sY    = src.MinY;
            int   dminX = dst.MinX;
            int   dY    = dst.MinY;
            int   sX;
            int   dX;

            if (Ncols == nBands)
            {
                for (int y = 0; y < src.Height; y++, sY++, dY++)
                {
                    dX = dminX;
                    sX = sminX;
                    for (int x = 0; x < src.Width; x++, sX++, dX++)
                    {
                        pixel = src.GetPixel(sX, sY, pixel);
                        for (int r = 0; r < Nrows; r++)
                        {
                            accum = 0.0f;
                            for (int c = 0; c < Ncols; c++)
                            {
                                accum += Matrix_Renamed[r][c] * pixel[c];
                            }
                            dstPixel[r] = (int)accum;
                        }
                        dst.SetPixel(dX, dY, dstPixel);
                    }
                }
            }
            else
            {
                // Need to add constant
                for (int y = 0; y < src.Height; y++, sY++, dY++)
                {
                    dX = dminX;
                    sX = sminX;
                    for (int x = 0; x < src.Width; x++, sX++, dX++)
                    {
                        pixel = src.GetPixel(sX, sY, pixel);
                        for (int r = 0; r < Nrows; r++)
                        {
                            accum = 0.0f;
                            for (int c = 0; c < nBands; c++)
                            {
                                accum += Matrix_Renamed[r][c] * pixel[c];
                            }
                            dstPixel[r] = (int)(accum + Matrix_Renamed[r][nBands]);
                        }
                        dst.SetPixel(dX, dY, dstPixel);
                    }
                }
            }

            return(dst);
        }
		/// <summary>
		/// Sets the data for a rectangle of pixels from an input Raster.
		/// </summary>
		public void setDataElements(int @x, int @y, Raster @inRaster)
		{
		}
 /// <summary>
 /// Sets a rectangular region of the image to the contents of the
 /// specified <code>Raster</code> <code>r</code>, which is
 /// assumed to be in the same coordinate space as the
 /// <code>BufferedImage</code>.
 /// </summary>
 public void setData(Raster @r)
 {
 }
Example #22
0
        /// <summary>
        /// Performs a lookup operation on a <code>Raster</code>.
        /// If the destination <code>Raster</code> is <code>null</code>,
        /// a new <code>Raster</code> will be created.
        /// The <code>IllegalArgumentException</code> might be thrown
        /// if the source <code>Raster</code> and the destination
        /// <code>Raster</code> do not have the same
        /// number of bands or if the number of arrays in the
        /// <code>LookupTable</code> does not meet the
        /// restrictions stated in the class comment above. </summary>
        /// <param name="src"> the source <code>Raster</code> to filter </param>
        /// <param name="dst"> the destination <code>WritableRaster</code> for the
        ///            filtered <code>src</code> </param>
        /// <returns> the filtered <code>WritableRaster</code>. </returns>
        /// <exception cref="IllegalArgumentException"> if the source and destinations
        ///         rasters do not have the same number of bands, or the
        ///         number of arrays in the <code>LookupTable</code> does
        ///         not meet the restrictions described in the class comments.
        ///  </exception>
        public WritableRaster Filter(Raster src, WritableRaster dst)
        {
            int numBands  = src.NumBands;
            int dstLength = dst.NumBands;
            int height    = src.Height;
            int width     = src.Width;

            int[] srcPix = new int[numBands];

            // Create a new destination Raster, if needed

            if (dst == null)
            {
                dst = CreateCompatibleDestRaster(src);
            }
            else if (height != dst.Height || width != dst.Width)
            {
                throw new IllegalArgumentException("Width or height of Rasters do not " + "match");
            }
            dstLength = dst.NumBands;

            if (numBands != dstLength)
            {
                throw new IllegalArgumentException("Number of channels in the src (" + numBands + ") does not match number of channels" + " in the destination (" + dstLength + ")");
            }
            int numComponents = Ltable.NumComponents;

            if (numComponents != 1 && numComponents != src.NumBands)
            {
                throw new IllegalArgumentException("Number of arrays in the " + " lookup table (" + numComponents + " is not compatible with the " + " src Raster: " + src);
            }


            if (ImagingLib.filter(this, src, dst) != null)
            {
                return(dst);
            }

            // Optimize for cases we know about
            if (Ltable is ByteLookupTable)
            {
                ByteFilter((ByteLookupTable)Ltable, src, dst, width, height, numBands);
            }
            else if (Ltable is ShortLookupTable)
            {
                ShortFilter((ShortLookupTable)Ltable, src, dst, width, height, numBands);
            }
            else
            {
                // Not one we recognize so do it slowly
                int sminX = src.MinX;
                int sY    = src.MinY;
                int dminX = dst.MinX;
                int dY    = dst.MinY;
                for (int y = 0; y < height; y++, sY++, dY++)
                {
                    int sX = sminX;
                    int dX = dminX;
                    for (int x = 0; x < width; x++, sX++, dX++)
                    {
                        // Find data for all bands at this x,y position
                        src.GetPixel(sX, sY, srcPix);

                        // Lookup the data for all bands at this x,y position
                        Ltable.LookupPixel(srcPix, srcPix);

                        // Put it back for all bands
                        dst.SetPixel(dX, dY, srcPix);
                    }
                }
            }

            return(dst);
        }
 /// <summary>
 /// Returns a new <code>BufferedImage</code> of TYPE_INT_ARGB or
 /// TYPE_INT_RGB that has a <code>Raster</code> with pixel data
 /// computed by expanding the indices in the source <code>Raster</code>
 /// using the color/alpha component arrays of this <code>ColorModel</code>.
 /// </summary>
 public BufferedImage convertToIntDiscrete(Raster @raster, bool @forceARGB)
 {
     return(default(BufferedImage));
 }
Example #24
0
 /// <summary>
 /// Creates a zeroed destination Raster with the correct size and number
 /// of bands, given this source.
 /// </summary>
 public virtual WritableRaster CreateCompatibleDestRaster(Raster src)
 {
     return(src.CreateCompatibleWritableRaster());
 }
 /// <summary>
 /// Copies pixels from Raster srcRaster to this WritableRaster.
 /// </summary>
 public void setRect(Raster @srcRaster)
 {
 }
 /// <summary>
 /// Returns <code>true</code> if <code>raster</code> is compatible
 /// with this <code>ColorModel</code> or <code>false</code> if it
 /// is not compatible with this <code>ColorModel</code>.
 /// </summary>
 public bool isCompatibleRaster(Raster @raster)
 {
     return(default(bool));
 }
Example #27
0
		/// <summary>
		/// Constructs a Raster with the given SampleModel, DataBuffer, and
		/// parent.
		/// </summary>
		public Raster(SampleModel @sampleModel, DataBuffer @dataBuffer, Rectangle @aRegion, Point @sampleModelTranslate, Raster @parent)
		{
		}
 /// <summary>
 /// Copies pixels from Raster srcRaster to this WritableRaster.
 /// </summary>
 public void setRect(int @dx, int @dy, Raster @srcRaster)
 {
 }
Example #29
0
        /// <summary>
        /// Creates a zeroed destination <CODE>Raster</CODE> with the correct size
        /// and number of bands.  A <CODE>RasterFormatException</CODE> may be thrown
        /// if the transformed width or height is equal to 0.
        /// </summary>
        /// <param name="src"> The <CODE>Raster</CODE> to be transformed.
        /// </param>
        /// <returns> The zeroed destination <CODE>Raster</CODE>. </returns>
        public virtual WritableRaster CreateCompatibleDestRaster(Raster src)
        {
            Rectangle2D r = GetBounds2D(src);

            return(src.CreateCompatibleWritableRaster((int)r.X, (int)r.Y, (int)r.Width, (int)r.Height));
        }
 /// <summary>
 /// Sets the data for a rectangle of pixels from an input Raster.
 /// </summary>
 public void setDataElements(int @x, int @y, Raster @inRaster)
 {
 }
Example #31
0
        /* color convert a Raster - handles byte, ushort, int, short, float,
         * or double transferTypes */
        private WritableRaster NonICCRasterFilter(Raster src, WritableRaster dst)
        {
            if (CSList.Length != 2)
            {
                throw new IllegalArgumentException("Destination ColorSpace is undefined");
            }
            if (src.NumBands != CSList[0].NumComponents)
            {
                throw new IllegalArgumentException("Numbers of source Raster bands and source color space " + "components do not match");
            }
            if (dst == null)
            {
                dst = CreateCompatibleDestRaster(src);
            }
            else
            {
                if (src.Height != dst.Height || src.Width != dst.Width)
                {
                    throw new IllegalArgumentException("Width or height of Rasters do not match");
                }
                if (dst.NumBands != CSList[1].NumComponents)
                {
                    throw new IllegalArgumentException("Numbers of destination Raster bands and destination " + "color space components do not match");
                }
            }

            if (SrcMinVals == null)
            {
                GetMinMaxValsFromColorSpaces(CSList[0], CSList[1]);
            }

            SampleModel srcSM = src.SampleModel;
            SampleModel dstSM = dst.SampleModel;
            bool        srcIsFloat, dstIsFloat;
            int         srcTransferType = src.TransferType;
            int         dstTransferType = dst.TransferType;

            if ((srcTransferType == DataBuffer.TYPE_FLOAT) || (srcTransferType == DataBuffer.TYPE_DOUBLE))
            {
                srcIsFloat = true;
            }
            else
            {
                srcIsFloat = false;
            }
            if ((dstTransferType == DataBuffer.TYPE_FLOAT) || (dstTransferType == DataBuffer.TYPE_DOUBLE))
            {
                dstIsFloat = true;
            }
            else
            {
                dstIsFloat = false;
            }
            int w           = src.Width;
            int h           = src.Height;
            int srcNumBands = src.NumBands;
            int dstNumBands = dst.NumBands;

            float[] srcScaleFactor = null;
            float[] dstScaleFactor = null;
            if (!srcIsFloat)
            {
                srcScaleFactor = new float[srcNumBands];
                for (int i = 0; i < srcNumBands; i++)
                {
                    if (srcTransferType == DataBuffer.TYPE_SHORT)
                    {
                        srcScaleFactor[i] = (SrcMaxVals[i] - SrcMinVals[i]) / 32767.0f;
                    }
                    else
                    {
                        srcScaleFactor[i] = (SrcMaxVals[i] - SrcMinVals[i]) / ((float)((1 << srcSM.GetSampleSize(i)) - 1));
                    }
                }
            }
            if (!dstIsFloat)
            {
                dstScaleFactor = new float[dstNumBands];
                for (int i = 0; i < dstNumBands; i++)
                {
                    if (dstTransferType == DataBuffer.TYPE_SHORT)
                    {
                        dstScaleFactor[i] = 32767.0f / (DstMaxVals[i] - DstMinVals[i]);
                    }
                    else
                    {
                        dstScaleFactor[i] = ((float)((1 << dstSM.GetSampleSize(i)) - 1)) / (DstMaxVals[i] - DstMinVals[i]);
                    }
                }
            }
            int   ys = src.MinY;
            int   yd = dst.MinY;
            int   xs, xd;
            float sample;

            float[]    color = new float[srcNumBands];
            float[]    tmpColor;
            ColorSpace srcColorSpace = CSList[0];
            ColorSpace dstColorSpace = CSList[1];

            // process each pixel
            for (int y = 0; y < h; y++, ys++, yd++)
            {
                // get src scanline
                xs = src.MinX;
                xd = dst.MinX;
                for (int x = 0; x < w; x++, xs++, xd++)
                {
                    for (int i = 0; i < srcNumBands; i++)
                    {
                        sample = src.GetSampleFloat(xs, ys, i);
                        if (!srcIsFloat)
                        {
                            sample = sample * srcScaleFactor[i] + SrcMinVals[i];
                        }
                        color[i] = sample;
                    }
                    tmpColor = srcColorSpace.ToCIEXYZ(color);
                    tmpColor = dstColorSpace.FromCIEXYZ(tmpColor);
                    for (int i = 0; i < dstNumBands; i++)
                    {
                        sample = tmpColor[i];
                        if (!dstIsFloat)
                        {
                            sample = (sample - DstMinVals[i]) * dstScaleFactor[i];
                        }
                        dst.SetSample(xd, yd, i, sample);
                    }
                }
            }
            return(dst);
        }