Exemplo n.º 1
0
        public static WritableRaster createBandedRaster(int dataType, int w, int h,
                                                        int scanlineStride, int[] bankIndices, int [] bandOffsets,
                                                        Point location)
        {
            if (w <= 0 || h <= 0)
            {
                // awt.22E=w or h is less than or equal to zero
                throw new RasterFormatException("w or h is less than or equal to zero"); //$NON-NLS-1$
            }

            if (location == null)
            {
                location = new Point(0, 0);
            }

            if ((long)location.x + w > java.lang.Integer.MAX_VALUE ||
                (long)location.y + h > java.lang.Integer.MAX_VALUE)
            {
                // awt.276=location.x + w or location.y + h results in integer overflow
                throw new RasterFormatException("location.x + w or location.y + h results in integer overflow"); //$NON-NLS-1$
            }

            if (bankIndices == null || bandOffsets == null)
            {
                // awt.277=bankIndices or bandOffsets is null
                throw new java.lang.ArrayIndexOutOfBoundsException("bankIndices or bandOffsets is null"); //$NON-NLS-1$
            }

            if (dataType != DataBuffer.TYPE_BYTE &&
                dataType != DataBuffer.TYPE_USHORT &&
                dataType != DataBuffer.TYPE_INT)
            {
                // awt.230=dataType is not one of the supported data types
                throw new java.lang.IllegalArgumentException("dataType is not one of the supported data types"); //$NON-NLS-1$
            }

            int maxOffset = bandOffsets[0];
            int maxBank   = bankIndices[0];

            for (int i = 0; i < bankIndices.Length; i++)
            {
                if (bandOffsets[i] > maxOffset)
                {
                    maxOffset = bandOffsets[i];
                }
                if (bankIndices[i] > maxBank)
                {
                    maxBank = bankIndices[i];
                }
            }

            int numBanks = maxBank + 1;
            int dataSize = scanlineStride * (h - 1) + w + maxOffset;

            DataBuffer data = null;

            switch (dataType)
            {
            case DataBuffer.TYPE_BYTE:
                data = new java.awt.image.DataBufferByte(dataSize, numBanks);
                break;

            case DataBuffer.TYPE_USHORT:
                data = new java.awt.image.DataBufferUShort(dataSize, numBanks);
                break;

            case DataBuffer.TYPE_INT:
                data = new DataBufferInt(dataSize, numBanks);
                break;
            }
            return(createBandedRaster(data, w, h, scanlineStride, bankIndices,
                                      bandOffsets, location));
        }
Exemplo n.º 2
0
        public static WritableRaster createBandedRaster(int dataType, int w, int h,
            int scanlineStride, int[] bankIndices, int []bandOffsets,
            Point location)
        {
            if (w <= 0 || h <= 0) {
            // awt.22E=w or h is less than or equal to zero
            throw new RasterFormatException("w or h is less than or equal to zero"); //$NON-NLS-1$
            }

            if (location == null) {
            location = new Point(0, 0);
            }

            if ((long) location.x + w > java.lang.Integer.MAX_VALUE
                || (long) location.y + h > java.lang.Integer.MAX_VALUE) {
            // awt.276=location.x + w or location.y + h results in integer overflow
            throw new RasterFormatException("location.x + w or location.y + h results in integer overflow"); //$NON-NLS-1$
            }

            if (bankIndices == null || bandOffsets == null) {
            // awt.277=bankIndices or bandOffsets is null
            throw new java.lang.ArrayIndexOutOfBoundsException("bankIndices or bandOffsets is null"); //$NON-NLS-1$
            }

            if (dataType != DataBuffer.TYPE_BYTE
                && dataType != DataBuffer.TYPE_USHORT
                && dataType != DataBuffer.TYPE_INT) {
            // awt.230=dataType is not one of the supported data types
            throw new java.lang.IllegalArgumentException("dataType is not one of the supported data types"); //$NON-NLS-1$
            }

            int maxOffset = bandOffsets[0];
            int maxBank = bankIndices[0];

            for (int i = 0; i < bankIndices.Length; i++) {
            if (bandOffsets[i] > maxOffset) {
                maxOffset = bandOffsets[i];
            }
            if (bankIndices[i] > maxBank) {
                maxBank = bankIndices[i];
            }
            }

            int numBanks = maxBank + 1;
            int dataSize = scanlineStride * (h - 1) + w + maxOffset;

            DataBuffer data = null;

            switch (dataType) {
            case DataBuffer.TYPE_BYTE:
            data = new java.awt.image.DataBufferByte(dataSize, numBanks);
            break;
            case DataBuffer.TYPE_USHORT:
            data = new java.awt.image.DataBufferUShort(dataSize, numBanks);
            break;
            case DataBuffer.TYPE_INT:
            data = new DataBufferInt(dataSize, numBanks);
            break;
            }
            return createBandedRaster(data, w, h, scanlineStride, bankIndices,
                bandOffsets, location);
        }