/// <summary>
        /// {@inheritDoc}
        /// </summary>
        public Raster GetRaster(int x, int y, int w, int h)
        {
            // If working raster is big enough, reuse it. Otherwise,
            // build a large enough new one.
            Raster raster = Saved;

            if (raster == null || raster.Width < w || raster.Height < h)
            {
                raster = GetCachedRaster(Model, w, h);
                Saved  = raster;
            }

            // Access raster internal int array. Because we use a DirectColorModel,
            // we know the DataBuffer is of type DataBufferInt and the SampleModel
            // is SinglePixelPackedSampleModel.
            // Adjust for initial offset in DataBuffer and also for the scanline
            // stride.
            // These calls make the DataBuffer non-acceleratable, but the
            // Raster is never Stable long enough to accelerate anyway...
            DataBufferInt rasterDB = (DataBufferInt)raster.DataBuffer;

            int[] pixels         = rasterDB.GetData(0);
            int   off            = rasterDB.Offset;
            int   scanlineStride = ((SinglePixelPackedSampleModel)raster.SampleModel).ScanlineStride;
            int   adjust         = scanlineStride - w;

            FillRaster(pixels, off, adjust, x, y, w, h);             // delegate to subclass

            return(raster);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an image containing pixels read from the screen.  This image does
        /// not include the mouse cursor. </summary>
        /// <param name="screenRect">      Rect to capture in screen coordinates </param>
        /// <returns>  The captured image </returns>
        /// <exception cref="IllegalArgumentException"> if <code>screenRect</code> width and height are not greater than zero </exception>
        /// <exception cref="SecurityException"> if <code>readDisplayPixels</code> permission is not granted </exception>
        /// <seealso cref=     SecurityManager#checkPermission </seealso>
        /// <seealso cref=     AWTPermission </seealso>
        public virtual BufferedImage CreateScreenCapture(Rectangle screenRect)
        {
            lock (this)
            {
                CheckScreenCaptureAllowed();

                CheckValidRect(screenRect);

                BufferedImage  image;
                DataBufferInt  buffer;
                WritableRaster raster;

                if (ScreenCapCM == null)
                {
                    /*
                     * Fix for 4285201
                     * Create a DirectColorModel equivalent to the default RGB ColorModel,
                     * except with no Alpha component.
                     */

                    ScreenCapCM = new DirectColorModel(24, 0x00FF0000, 0x0000FF00, 0x000000FF);
                    /* red mask */
                    /* green mask */
                    /* blue mask */
                }

                // need to sync the toolkit prior to grabbing the pixels since in some
                // cases rendering to the screen may be delayed
                Toolkit.DefaultToolkit.Sync();

                int[] pixels;
                int[] bandmasks = new int[3];

                pixels = Peer.GetRGBPixels(screenRect);
                buffer = new DataBufferInt(pixels, pixels.Length);

                bandmasks[0] = ScreenCapCM.RedMask;
                bandmasks[1] = ScreenCapCM.GreenMask;
                bandmasks[2] = ScreenCapCM.BlueMask;

                raster = Raster.CreatePackedRaster(buffer, screenRect.Width_Renamed, screenRect.Height_Renamed, screenRect.Width_Renamed, bandmasks, null);
                SunWritableRaster.makeTrackable(buffer);

                image = new BufferedImage(ScreenCapCM, raster, false, null);

                return(image);
            }
        }
Exemplo n.º 3
0
		public override string CalculateSHA1() {
			MessageDigest md = MessageDigest.getInstance ("SHA");
			DataBufferInt dbi = (DataBufferInt) Image.getRaster ().getDataBuffer ();
			for (int i=0; i<dbi.getNumBanks (); i++) {
				int [] curBank = dbi.getData (i);
				for (int j=0; j<curBank.Length; j++) {
					int x = curBank[j];
					md.update ((sbyte) (x & 0xFF));
					md.update ((sbyte) ((x>>8) & 0xFF));
					md.update ((sbyte) ((x>>16) & 0xFF));
					md.update ((sbyte) ((x>>24) & 0xFF));
				}
			}
			byte [] resdata = (byte[])vmw.common.TypeUtils.ToByteArray(md.digest());
			return Convert.ToBase64String (resdata);
		}
Exemplo n.º 4
0
        private WritableRaster CreateDCMraster()
        {
            WritableRaster   wr;
            DirectColorModel dcm      = (DirectColorModel)Model;
            bool             hasAlpha = Model.HasAlpha();

            int[] bandMasks = new int[3 + (hasAlpha ? 1 : 0)];
            bandMasks[0] = dcm.RedMask;
            bandMasks[1] = dcm.GreenMask;
            bandMasks[2] = dcm.BlueMask;
            if (hasAlpha)
            {
                bandMasks[3] = dcm.AlphaMask;
            }
            DataBufferInt db = new DataBufferInt(IntPixels, Width * Height);

            wr = Raster.CreatePackedRaster(db, Width, Height, Width, bandMasks, null);
            return(wr);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a <code>DataBuffer</code> that corresponds to this
        /// <code>MultiPixelPackedSampleModel</code>.  The
        /// <code>DataBuffer</code> object's data type and size
        /// is consistent with this <code>MultiPixelPackedSampleModel</code>.
        /// The <code>DataBuffer</code> has a single bank. </summary>
        /// <returns> a <code>DataBuffer</code> with the same data type and
        /// size as this <code>MultiPixelPackedSampleModel</code>. </returns>
        public override DataBuffer CreateDataBuffer()
        {
            DataBuffer dataBuffer = null;

            int size = (int)ScanlineStride_Renamed * Height_Renamed;

            switch (DataType_Renamed)
            {
            case DataBuffer.TYPE_BYTE:
                dataBuffer = new DataBufferByte(size + (DataBitOffset_Renamed + 7) / 8);
                break;

            case DataBuffer.TYPE_USHORT:
                dataBuffer = new DataBufferUShort(size + (DataBitOffset_Renamed + 15) / 16);
                break;

            case DataBuffer.TYPE_INT:
                dataBuffer = new DataBufferInt(size + (DataBitOffset_Renamed + 31) / 32);
                break;
            }
            return(dataBuffer);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a DataBuffer that corresponds to this
        /// SinglePixelPackedSampleModel.  The DataBuffer's data type and size
        /// will be consistent with this SinglePixelPackedSampleModel.  The
        /// DataBuffer will have a single bank.
        /// </summary>
        public override DataBuffer CreateDataBuffer()
        {
            DataBuffer dataBuffer = null;

            int size = (int)BufferSize;

            switch (DataType_Renamed)
            {
            case DataBuffer.TYPE_BYTE:
                dataBuffer = new DataBufferByte(size);
                break;

            case DataBuffer.TYPE_USHORT:
                dataBuffer = new DataBufferUShort(size);
                break;

            case DataBuffer.TYPE_INT:
                dataBuffer = new DataBufferInt(size);
                break;
            }
            return(dataBuffer);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a DataBuffer that corresponds to this BandedSampleModel,
        /// The DataBuffer's data type, number of banks, and size
        /// will be consistent with this BandedSampleModel. </summary>
        /// <exception cref="IllegalArgumentException"> if <code>dataType</code> is not
        ///         one of the supported types. </exception>
        public override DataBuffer CreateDataBuffer()
        {
            DataBuffer dataBuffer = null;

            int size = ScanlineStride_Renamed * Height_Renamed;

            switch (DataType_Renamed)
            {
            case DataBuffer.TYPE_BYTE:
                dataBuffer = new DataBufferByte(size, NumBanks);
                break;

            case DataBuffer.TYPE_USHORT:
                dataBuffer = new DataBufferUShort(size, NumBanks);
                break;

            case DataBuffer.TYPE_SHORT:
                dataBuffer = new DataBufferShort(size, NumBanks);
                break;

            case DataBuffer.TYPE_INT:
                dataBuffer = new DataBufferInt(size, NumBanks);
                break;

            case DataBuffer.TYPE_FLOAT:
                dataBuffer = new DataBufferFloat(size, NumBanks);
                break;

            case DataBuffer.TYPE_DOUBLE:
                dataBuffer = new DataBufferDouble(size, NumBanks);
                break;

            default:
                throw new IllegalArgumentException("dataType is not one " + "of the supported types.");
            }

            return(dataBuffer);
        }
Exemplo n.º 8
0
 public virtual int[] GetData(DataBufferInt dbi, int bank)
 {
     return(dbi.Bankdata[bank]);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Filters the information provided in the <code>imageComplete</code>
        /// method of the <code>ImageConsumer</code> interface.
        /// <para>
        /// Note: This method is intended to be called by the
        /// <code>ImageProducer</code> of the <code>Image</code> whose pixels
        /// are being filtered.  Developers using
        /// this class to retrieve pixels from an image should avoid calling
        /// this method directly since that operation could result in problems
        /// with retrieving the requested pixels.
        /// </para>
        /// </summary>
        /// <param name="status"> the status of image loading </param>
        /// <exception cref="ImagingOpException"> if there was a problem calling the filter
        /// method of the <code>BufferedImageOp</code> associated with this
        /// instance. </exception>
        /// <seealso cref= ImageConsumer#imageComplete </seealso>
        public override void ImageComplete(int status)
        {
            WritableRaster wr;

            switch (status)
            {
            case ImageConsumer_Fields.IMAGEERROR:
            case ImageConsumer_Fields.IMAGEABORTED:
                // reinitialize the params
                Model      = null;
                Width      = -1;
                Height     = -1;
                IntPixels  = null;
                BytePixels = null;
                break;

            case ImageConsumer_Fields.SINGLEFRAMEDONE:
            case ImageConsumer_Fields.STATICIMAGEDONE:
                if (Width <= 0 || Height <= 0)
                {
                    break;
                }
                if (Model is DirectColorModel)
                {
                    if (IntPixels == null)
                    {
                        break;
                    }
                    wr = CreateDCMraster();
                }
                else if (Model is IndexColorModel)
                {
                    int[] bandOffsets = new int[] { 0 };
                    if (BytePixels == null)
                    {
                        break;
                    }
                    DataBufferByte db = new DataBufferByte(BytePixels, Width * Height);
                    wr = Raster.CreateInterleavedRaster(db, Width, Height, Width, 1, bandOffsets, null);
                }
                else
                {
                    ConvertToRGB();
                    if (IntPixels == null)
                    {
                        break;
                    }
                    wr = CreateDCMraster();
                }
                BufferedImage bi = new BufferedImage(Model, wr, Model.AlphaPremultiplied, null);
                bi = BufferedImageOp_Renamed.Filter(bi, null);
                WritableRaster r  = bi.Raster;
                ColorModel     cm = bi.ColorModel;
                int            w  = r.Width;
                int            h  = r.Height;
                Consumer.SetDimensions(w, h);
                Consumer.ColorModel = cm;
                if (cm is DirectColorModel)
                {
                    DataBufferInt db = (DataBufferInt)r.DataBuffer;
                    Consumer.SetPixels(0, 0, w, h, cm, db.Data, 0, w);
                }
                else if (cm is IndexColorModel)
                {
                    DataBufferByte db = (DataBufferByte)r.DataBuffer;
                    Consumer.SetPixels(0, 0, w, h, cm, db.Data, 0, w);
                }
                else
                {
                    throw new InternalError("Unknown color model " + cm);
                }
                break;
            }
            Consumer.ImageComplete(status);
        }