예제 #1
0
        /// <summary>
        /// Returns the samples for a specified band for the specified rectangle
        /// of pixels in an int array, 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 return. </param>
        /// <param name="iArray">    If non-null, returns the samples in this array. </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <returns> the samples for the specified band for the specified
        ///         region of pixels. </returns>
        /// <seealso cref= #setSamples(int, int, int, int, int, int[], DataBuffer) </seealso>
        public override int[] GetSamples(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[] samples;
            if (iArray != null)
            {
                samples = iArray;
            }
            else
            {
                samples = new int [w * h];
            }
            int lineOffset = y * ScanlineStride_Renamed + x;
            int dstOffset  = 0;

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    int value = data.GetElem(lineOffset + j);
                    samples[dstOffset++] = ((int)((uint)(value & BitMasks_Renamed[b]) >> BitOffsets_Renamed[b]));
                }
                lineOffset += ScanlineStride_Renamed;
            }
            return(samples);
        }
예제 #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;
            }
        }
예제 #3
0
        /// <summary>
        /// Returns all samples for the specified rectangle of pixels in
        /// an int array, 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">    If non-null, returns the samples in this array. </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <returns> all samples for the specified region of pixels. </returns>
        /// <seealso cref= #setPixels(int, int, int, int, int[], DataBuffer) </seealso>
        public override int[] GetPixels(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[] pixels;
            if (iArray != null)
            {
                pixels = iArray;
            }
            else
            {
                pixels = new int [w * h * NumBands_Renamed];
            }
            int lineOffset = y * ScanlineStride_Renamed + x;
            int dstOffset  = 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++)
                    {
                        pixels[dstOffset++] = ((int)((uint)(value & BitMasks_Renamed[k]) >> BitOffsets_Renamed[k]));
                    }
                }
                lineOffset += ScanlineStride_Renamed;
            }
            return(pixels);
        }
예제 #4
0
        /// <summary>
        /// Returns as int the sample in a specified band for the pixel
        /// located at (x,y).
        /// 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 return. </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <returns> the sample in a specified band for the specified
        ///         pixel. </returns>
        /// <seealso cref= #setSample(int, int, int, int, DataBuffer) </seealso>
        public override int GetSample(int x, int y, int b, 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 sample = data.GetElem(y * ScanlineStride_Renamed + x);

            return((int)((uint)(sample & BitMasks_Renamed[b]) >> BitOffsets_Renamed[b]));
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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;
            }
        }
예제 #8
0
        /// <summary>
        /// Returns all samples in for the specified pixel in an int array.
        /// 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">    If non-null, returns the samples in this array </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <returns> all samples for the specified pixel. </returns>
        /// <seealso cref= #setPixel(int, int, int[], DataBuffer) </seealso>
        public override int [] GetPixel(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[] pixels;
            if (iArray == null)
            {
                pixels = new int [NumBands_Renamed];
            }
            else
            {
                pixels = iArray;
            }

            int value = data.GetElem(y * ScanlineStride_Renamed + x);

            for (int i = 0; i < NumBands_Renamed; i++)
            {
                pixels[i] = (int)((uint)(value & BitMasks_Renamed[i]) >> BitOffsets_Renamed[i]);
            }
            return(pixels);
        }
예제 #9
0
        /// <summary>
        /// Returns data for a single pixel in a primitive array of type
        /// TransferType.  For a SinglePixelPackedSampleModel, the array will
        /// have one element, and the type will be the same as the storage
        /// data type.  Generally, obj
        /// should be passed in as null, so that the Object will be created
        /// automatically and will be of the right primitive data type.
        /// <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>
        /// If obj is non-null, it should 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 non-null and 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">       If non-null, a primitive array in which to return
        ///                  the pixel data. </param>
        /// <param name="data">      The DataBuffer containing the image data. </param>
        /// <returns> the data for the specified pixel. </returns>
        /// <seealso cref= #setDataElements(int, int, Object, DataBuffer) </seealso>
        public override Object GetDataElements(int x, int y, Object obj, 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 type = TransferType;

            switch (type)
            {
            case DataBuffer.TYPE_BYTE:

                sbyte[] bdata;

                if (obj == null)
                {
                    bdata = new sbyte[1];
                }
                else
                {
                    bdata = (sbyte[])obj;
                }

                bdata[0] = (sbyte)data.GetElem(y * ScanlineStride_Renamed + x);

                obj = (Object)bdata;
                break;

            case DataBuffer.TYPE_USHORT:

                short[] sdata;

                if (obj == null)
                {
                    sdata = new short[1];
                }
                else
                {
                    sdata = (short[])obj;
                }

                sdata[0] = (short)data.GetElem(y * ScanlineStride_Renamed + x);

                obj = (Object)sdata;
                break;

            case DataBuffer.TYPE_INT:

                int[] idata;

                if (obj == null)
                {
                    idata = new int[1];
                }
                else
                {
                    idata = (int[])obj;
                }

                idata[0] = data.GetElem(y * ScanlineStride_Renamed + x);

                obj = (Object)idata;
                break;
            }

            return(obj);
        }