Exemplo n.º 1
0
        /// <summary>
        /// Sets the data for a single pixel in the specified DataBuffer from a
        /// primitive array of type TransferType.  For a
        /// SinglePixelPackedSampleModel, only the first element of the array
        /// will hold valid data, and the type of the array must be the same as
        /// the storage data type of the SinglePixelPackedSampleModel.
        /// <para>
        /// The following code illustrates transferring data for one pixel from
        /// DataBuffer <code>db1</code>, whose storage layout is described by
        /// SinglePixelPackedSampleModel <code>sppsm1</code>,
        /// to DataBuffer <code>db2</code>, whose storage layout is described by
        /// SinglePixelPackedSampleModel <code>sppsm2</code>.
        /// The transfer will generally be more efficient than using
        /// getPixel/setPixel.
        /// <pre>
        ///       SinglePixelPackedSampleModel sppsm1, sppsm2;
        ///       DataBufferInt db1, db2;
        ///       sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null,
        ///                              db1), db2);
        /// </pre>
        /// Using getDataElements/setDataElements to transfer between two
        /// DataBuffer/SampleModel pairs is legitimate if the SampleModels have
        /// the same number of bands, corresponding bands have the same number of
        /// bits per sample, and the TransferTypes are the same.
        /// </para>
        /// <para>
        /// obj must be a primitive array of type TransferType.  Otherwise,
        /// a ClassCastException is thrown.  An
        /// ArrayIndexOutOfBoundsException may be thrown if the coordinates are
        /// not in bounds, or if obj is not large enough to hold the pixel data.
        /// </para>
        /// </summary>
        /// <param name="x">         The X coordinate of the pixel location. </param>
        /// <param name="y">         The Y coordinate of the pixel location. </param>
        /// <param name="obj">       A primitive array containing pixel data. </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <seealso cref= #getDataElements(int, int, Object, DataBuffer) </seealso>
        public override void SetDataElements(int x, int y, Object obj, DataBuffer data)
        {
            if ((x < 0) || (y < 0) || (x >= Width_Renamed) || (y >= Height_Renamed))
            {
                throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!");
            }

            int type = TransferType;

            switch (type)
            {
            case DataBuffer.TYPE_BYTE:

                sbyte[] barray = (sbyte[])obj;
                data.SetElem(y * ScanlineStride_Renamed + x, ((int)barray[0]) & 0xff);
                break;

            case DataBuffer.TYPE_USHORT:

                short[] sarray = (short[])obj;
                data.SetElem(y * ScanlineStride_Renamed + x, ((int)sarray[0]) & 0xffff);
                break;

            case DataBuffer.TYPE_INT:

                int[] iarray = (int[])obj;
                data.SetElem(y * ScanlineStride_Renamed + x, iarray[0]);
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets all samples for a rectangle of pixels from an int array containing
        /// one sample per array element.
        /// ArrayIndexOutOfBoundsException may be thrown if the coordinates are
        /// not in bounds. </summary>
        /// <param name="x">         The X coordinate of the upper left pixel location. </param>
        /// <param name="y">         The Y coordinate of the upper left pixel location. </param>
        /// <param name="w">         The width of the pixel rectangle. </param>
        /// <param name="h">         The height of the pixel rectangle. </param>
        /// <param name="iArray">    The input samples in an int array. </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <seealso cref= #getPixels(int, int, int, int, int[], DataBuffer) </seealso>
        public override void SetPixels(int x, int y, int w, int h, int[] iArray, DataBuffer data)
        {
            int x1 = x + w;
            int y1 = y + h;

            if (x < 0 || x >= Width_Renamed || w > Width_Renamed || x1 < 0 || x1 > Width_Renamed || y < 0 || y >= Height_Renamed || h > Height_Renamed || y1 < 0 || y1 > Height_Renamed)
            {
                throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!");
            }

            int lineOffset = y * ScanlineStride_Renamed + x;
            int srcOffset  = 0;

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    int value = data.GetElem(lineOffset + j);
                    for (int k = 0; k < NumBands_Renamed; k++)
                    {
                        value &= ~BitMasks_Renamed[k];
                        int srcValue = iArray[srcOffset++];
                        value |= ((srcValue << BitOffsets_Renamed[k]) & BitMasks_Renamed[k]);
                    }
                    data.SetElem(lineOffset + j, value);
                }
                lineOffset += ScanlineStride_Renamed;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets a sample in the specified band for the pixel located at (x,y)
        /// in the DataBuffer using an int for input.
        /// ArrayIndexOutOfBoundsException may be thrown if the coordinates are
        /// not in bounds. </summary>
        /// <param name="x">         The X coordinate of the pixel location. </param>
        /// <param name="y">         The Y coordinate of the pixel location. </param>
        /// <param name="b">         The band to set. </param>
        /// <param name="s">         The input sample as an int. </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <seealso cref= #getSample(int, int, int, DataBuffer) </seealso>
        public override void SetSample(int x, int y, int b, int s, DataBuffer data)
        {
            // Bounds check for 'b' will be performed automatically
            if ((x < 0) || (y < 0) || (x >= Width_Renamed) || (y >= Height_Renamed))
            {
                throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!");
            }
            int value = data.GetElem(y * ScanlineStride_Renamed + x);

            value &= ~BitMasks_Renamed[b];
            value |= (s << BitOffsets_Renamed[b]) & BitMasks_Renamed[b];
            data.SetElem(y * ScanlineStride_Renamed + x, value);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets a pixel in the DataBuffer using an int array of samples for input.
        /// ArrayIndexOutOfBoundsException may be thrown if the coordinates are
        /// not in bounds. </summary>
        /// <param name="x">         The X coordinate of the pixel location. </param>
        /// <param name="y">         The Y coordinate of the pixel location. </param>
        /// <param name="iArray">    The input samples in an int array. </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <seealso cref= #getPixel(int, int, int[], DataBuffer) </seealso>
        public override void SetPixel(int x, int y, int[] iArray, DataBuffer data)
        {
            if ((x < 0) || (y < 0) || (x >= Width_Renamed) || (y >= Height_Renamed))
            {
                throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!");
            }
            int lineOffset = y * ScanlineStride_Renamed + x;
            int value      = data.GetElem(lineOffset);

            for (int i = 0; i < NumBands_Renamed; i++)
            {
                value &= ~BitMasks_Renamed[i];
                value |= ((iArray[i] << BitOffsets_Renamed[i]) & BitMasks_Renamed[i]);
            }
            data.SetElem(lineOffset, value);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets the samples in the specified band for the specified rectangle
        /// of pixels from an int array containing one sample per array element.
        /// ArrayIndexOutOfBoundsException may be thrown if the coordinates are
        /// not in bounds. </summary>
        /// <param name="x">         The X coordinate of the upper left pixel location. </param>
        /// <param name="y">         The Y coordinate of the upper left pixel location. </param>
        /// <param name="w">         The width of the pixel rectangle. </param>
        /// <param name="h">         The height of the pixel rectangle. </param>
        /// <param name="b">         The band to set. </param>
        /// <param name="iArray">    The input samples in an int array. </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <seealso cref= #getSamples(int, int, int, int, int, int[], DataBuffer) </seealso>
        public override void SetSamples(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)
        {
            // Bounds check for 'b' will be performed automatically
            if ((x < 0) || (y < 0) || (x + w > Width_Renamed) || (y + h > Height_Renamed))
            {
                throw new ArrayIndexOutOfBoundsException("Coordinate out of bounds!");
            }
            int lineOffset = y * ScanlineStride_Renamed + x;
            int srcOffset  = 0;

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    int value = data.GetElem(lineOffset + j);
                    value &= ~BitMasks_Renamed[b];
                    int sample = iArray[srcOffset++];
                    value |= ((int)sample << BitOffsets_Renamed[b]) & BitMasks_Renamed[b];
                    data.SetElem(lineOffset + j, value);
                }
                lineOffset += ScanlineStride_Renamed;
            }
        }