public MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits, int scanlineStride, int dataBitOffset)
            : base(dataType, w, h, 1)
        {
            if (dataType != DataBuffer.TYPE_BYTE &&
                dataType != DataBuffer.TYPE_USHORT &&
                dataType != DataBuffer.TYPE_INT)
            {
                // awt.61=Unsupported data type: {0}
                throw new java.lang.IllegalArgumentException("Unsupported data type: " + dataType);
            }

            this.scanlineStride = scanlineStride;
            if (numberOfBits == 0)
            {
                // awt.20C=Number of Bits equals to zero
                throw new RasterFormatException("Number of Bits equals to zero"); //$NON-NLS-1$
            }
            this.pixelBitStride  = numberOfBits;
            this.dataElementSize = DataBuffer.getDataTypeSize(dataType);
            if (dataElementSize % pixelBitStride != 0)
            {
                // awt.20D=The number of bits per pixel is not a power of 2 or pixels span data element boundaries
                throw new RasterFormatException("The number of bits per pixel is not a power of 2 or pixels span data element boundaries"); //$NON-NLS-1$
            }

            if (dataBitOffset % numberOfBits != 0)
            {
                // awt.20E=Data Bit offset is not a multiple of pixel bit stride
                throw new RasterFormatException("Data Bit offset is not a multiple of pixel bit stride"); //$NON-NLS-1$
            }
            this.dataBitOffset = dataBitOffset;

            this.pixelsPerDataElement = dataElementSize / pixelBitStride;
            this.bitMask = (1 << numberOfBits) - 1;
        }
        public MultiPixelPackedSampleModel(int dataType, int w, int h, int numberOfBits)
            :

            this(dataType, w, h, numberOfBits, (numberOfBits * w +
                                                DataBuffer.getDataTypeSize(dataType) - 1) /
                 DataBuffer.getDataTypeSize(dataType), 0)
        {
        }
示例#3
0
        public override int[] getSampleSize()
        {
            int[] sampleSizes = new int[numBands];
            int   size        = DataBuffer.getDataTypeSize(dataType);

            for (int i = 0; i < numBands; i++)
            {
                sampleSizes[i] = size;
            }
            return(sampleSizes);
        }
示例#4
0
        public static WritableRaster createPackedRaster(int dataType, int w, int h,
                                                        int bands, int bitsPerBand, 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 (bands < 1 || bitsPerBand < 1)
            {
                // awt.27D=bitsPerBand or bands is not greater than zero
                throw new java.lang.IllegalArgumentException("bitsPerBand or bands is not greater than zero"); //$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$
            }

            if (bitsPerBand * bands > DataBuffer.getDataTypeSize(dataType))
            {
                // awt.27E=The product of bitsPerBand and bands is greater than the number of bits held by dataType
                throw new java.lang.IllegalArgumentException("The product of bitsPerBand and bands is greater than the number of bits held by dataType"); //$NON-NLS-1$
            }

            if (bands > 1)
            {
                int[] bandMasks = new int[bands];
                int   mask      = (1 << bitsPerBand) - 1;

                for (int i = 0; i < bands; i++)
                {
                    bandMasks[i] = mask << (bitsPerBand * (bands - 1 - i));
                }

                return(createPackedRaster(dataType, w, h, bandMasks, location));
            }
            DataBuffer data = null;
            int        size = ((bitsPerBand * w +
                                DataBuffer.getDataTypeSize(dataType) - 1) /
                               DataBuffer.getDataTypeSize(dataType)) * h;

            switch (dataType)
            {
            case DataBuffer.TYPE_BYTE:
                data = new DataBufferByte(size);
                break;

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

            case DataBuffer.TYPE_INT:
                data = new DataBufferInt(size);
                break;
            }
            return(createPackedRaster(data, w, h, bitsPerBand, location));
        }
示例#5
0
 public override int getSampleSize(int band)
 {
     return(DataBuffer.getDataTypeSize(dataType));
 }