示例#1
0
        public static WritableRaster createPackedRaster(DataBuffer dataBuffer,
                                                        int w, int h, int scanlineStride, int [] bandMasks, Point location)
        {
            if (dataBuffer == null)
            {
                // awt.278=dataBuffer is null
                throw new java.lang.NullPointerException("dataBuffer is null"); //$NON-NLS-1$
            }

            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 (bandMasks == null)
            {
                // awt.27C=bandMasks is null
                throw new RasterFormatException("bandMasks is null"); //$NON-NLS-1$
            }

            if (dataBuffer.getNumBanks() > 1)
            {
                // awt.27A=dataBuffer has more than one bank
                throw new RasterFormatException("dataBuffer has more than one bank"); //$NON-NLS-1$
            }

            int dataType = dataBuffer.getDataType();

            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$
            }

            SinglePixelPackedSampleModel sampleModel =
                new SinglePixelPackedSampleModel(dataType, w, h,
                                                 scanlineStride, bandMasks);

            return(new OrdinaryWritableRaster(sampleModel, dataBuffer, location));
        }
示例#2
0
        public static WritableRaster createBandedRaster(DataBuffer dataBuffer,
                                                        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 (dataBuffer == null)
            {
                // awt.278=dataBuffer is null
                throw new java.lang.NullPointerException("dataBuffer is null"); //$NON-NLS-1$
            }

            int dataType = dataBuffer.getDataType();

            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$
            }

            BandedSampleModel sampleModel = new BandedSampleModel(dataType, w, h,
                                                                  scanlineStride, bankIndices, bandOffsets);

            return(new OrdinaryWritableRaster(sampleModel, dataBuffer, location));
        }
示例#3
0
        private static void validateDataBuffer(DataBuffer dataBuffer, int w,
                                               int h, SampleModel sampleModel)
        {
            int size = 0;

            if (sampleModel is ComponentSampleModel)
            {
                ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
                int [] offsets           = csm.getBandOffsets();
                int    maxOffset         = offsets[0];
                for (int i = 1; i < offsets.Length; i++)
                {
                    if (offsets[i] > maxOffset)
                    {
                        maxOffset = offsets[i];
                    }
                }
                int scanlineStride = csm.getScanlineStride();
                int pixelStride    = csm.getPixelStride();

                size = (h - 1) * scanlineStride +
                       (w - 1) * pixelStride + maxOffset + 1;
            }
            else if (sampleModel is MultiPixelPackedSampleModel)
            {
                MultiPixelPackedSampleModel mppsm =
                    (MultiPixelPackedSampleModel)sampleModel;

                int scanlineStride = mppsm.getScanlineStride();
                int dataBitOffset  = mppsm.getDataBitOffset();
                int dataType       = dataBuffer.getDataType();

                size = scanlineStride * h;

                switch (dataType)
                {
                case DataBuffer.TYPE_BYTE:
                    size += (dataBitOffset + 7) / 8;
                    break;

                case DataBuffer.TYPE_USHORT:
                    size += (dataBitOffset + 15) / 16;
                    break;

                case DataBuffer.TYPE_INT:
                    size += (dataBitOffset + 31) / 32;
                    break;
                }
            }
            else if (sampleModel is SinglePixelPackedSampleModel)
            {
                SinglePixelPackedSampleModel sppsm =
                    (SinglePixelPackedSampleModel)sampleModel;

                int scanlineStride = sppsm.getScanlineStride();
                size = (h - 1) * scanlineStride + w;
            }
            if (dataBuffer.getSize() < size)
            {
                // awt.298=dataBuffer is too small
                throw new RasterFormatException("dataBuffer is too small"); //$NON-NLS-1$
            }
        }
示例#4
0
        public static WritableRaster createBandedRaster(DataBuffer dataBuffer,
            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 (dataBuffer == null) {
            // awt.278=dataBuffer is null
            throw new java.lang.NullPointerException("dataBuffer is null"); //$NON-NLS-1$
            }

            int dataType = dataBuffer.getDataType();

            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$
            }

            BandedSampleModel sampleModel = new BandedSampleModel(dataType, w, h,
                scanlineStride, bankIndices, bandOffsets);

            return new OrdinaryWritableRaster(sampleModel, dataBuffer, location);
        }
示例#5
0
        private static void validateDataBuffer(DataBuffer dataBuffer, int w,
            int h, SampleModel sampleModel)
        {
            int size = 0;

            if (sampleModel is ComponentSampleModel) {
            ComponentSampleModel csm = (ComponentSampleModel) sampleModel;
            int [] offsets = csm.getBandOffsets();
            int maxOffset = offsets[0];
            for (int i = 1; i < offsets.Length; i++) {
                if (offsets[i] > maxOffset) {
                    maxOffset = offsets[i];
                }
            }
            int scanlineStride = csm.getScanlineStride();
            int pixelStride = csm.getPixelStride();

            size = (h - 1) * scanlineStride +
            (w - 1) * pixelStride + maxOffset + 1;

            } else if (sampleModel is MultiPixelPackedSampleModel) {
            MultiPixelPackedSampleModel mppsm =
                (MultiPixelPackedSampleModel) sampleModel;

            int scanlineStride = mppsm.getScanlineStride();
            int dataBitOffset = mppsm.getDataBitOffset();
            int dataType = dataBuffer.getDataType();

            size = scanlineStride * h;

            switch (dataType) {
            case DataBuffer.TYPE_BYTE:
                size += (dataBitOffset + 7) / 8;
                break;
            case DataBuffer.TYPE_USHORT:
                size += (dataBitOffset + 15) / 16;
                break;
            case DataBuffer.TYPE_INT:
                size += (dataBitOffset + 31) / 32;
                break;
            }
            } else if (sampleModel is SinglePixelPackedSampleModel) {
            SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel) sampleModel;

            int scanlineStride = sppsm.getScanlineStride();
            size = (h - 1) * scanlineStride + w;
            }
            if (dataBuffer.getSize() < size) {
            // awt.298=dataBuffer is too small
            throw new RasterFormatException("dataBuffer is too small"); //$NON-NLS-1$
            }
        }
示例#6
0
        public static WritableRaster createPackedRaster(DataBuffer dataBuffer,
            int w, int h, int bitsPerPixel, 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 (dataBuffer == null) {
            // awt.278=dataBuffer is null
            throw new java.lang.NullPointerException("dataBuffer is null"); //$NON-NLS-1$
            }

            if (dataBuffer.getNumBanks() > 1) {
            // awt.27A=dataBuffer has more than one bank
            throw new RasterFormatException("dataBuffer has more than one bank"); //$NON-NLS-1$
            }

            int dataType = dataBuffer.getDataType();
            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$
            }

            MultiPixelPackedSampleModel sampleModel =
            new MultiPixelPackedSampleModel(dataType, w, h, bitsPerPixel);

            return new OrdinaryWritableRaster(sampleModel, dataBuffer, location);
        }