Package java.awt.image

Examples of java.awt.image.DataBufferByte


        {
          // this is much faster than iterating through the pixels.
          // if we create a writable raster and then construct a buffered image,
          // no new array is created and no data is copied.
          // TODO: optimize other cases.
          final DataBufferByte db = new DataBufferByte(new byte[][] {bytes}, bytes.length);
          final ComponentSampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, pixelStride, lineStride, new int[] {redMask - 1, greenMask -1, blueMask -1});
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
          // construction borrowed from BufferedImage constructor, for BufferedImage.TYPE_3BYTE_BGR
                  final ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
                  int[] nBits = {8, 8, 8};
                  //int[] bOffs = {2, 1, 0};
                  final ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false,
                                                       Transparency.OPAQUE,
                                                       DataBuffer.TYPE_BYTE);
                  final BufferedImage bi = new BufferedImage(colorModel, r, false, null);
          return bi;
        }
        else if (bitsPerPixel == 32)
        {
          final DataBufferByte db = new DataBufferByte(new byte[][] {bytes}, bytes.length);
          final ComponentSampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, pixelStride, lineStride, new int[] {redMask - 1, greenMask -1, blueMask -1, 3})// TODO: what to do with alpha?
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
          // construction borrowed from BufferedImage constructor, for BufferedImage.TYPE_4BYTE_ABGR
                  final ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
                  int[] nBits = {8, 8, 8, 8};
                  //int[] bOffs = {3, 2, 1, 0};
                  final ColorModel colorModel = new ComponentColorModel(cs, nBits, true, false,
                                                       Transparency.TRANSLUCENT,
                                                       DataBuffer.TYPE_BYTE);
                  final BufferedImage bi = new BufferedImage(colorModel, r, false, null);
          return bi;
        }
        else if (bitsPerPixel == 8)
        {
          final DataBufferByte db = new DataBufferByte(new byte[][] {bytes}, bytes.length);
          final SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, w, h, lineStride, new int[] {redMask, greenMask, blueMask});
          final WritableRaster r = Raster.createWritableRaster(sm, db, new Point(0, 0));
                  final ColorModel colorModel = new DirectColorModel(bitsPerPixel, redMask, greenMask, blueMask);
                  final BufferedImage bi = new BufferedImage(colorModel, r, false, null);
          return bi;
View Full Code Here


        }

        int[] palette = {0xffffff, 0x000000};
        ColorModel colorModel = new IndexColorModel(1, 2,
                palette, 0, false, -1, DataBuffer.TYPE_BYTE);
        DataBufferByte dataBuffer = new DataBufferByte(imageData, imageData.length);
        WritableRaster raster = WritableRaster.createPackedRaster(dataBuffer,
                xbmHeader.width, xbmHeader.height, 1, null);
        BufferedImage image = new BufferedImage(colorModel, raster,
                colorModel.isAlphaPremultiplied(), new Properties());
        return image;
View Full Code Here

            for (int y = 0; y < ySize; y++)
            {
                readScanLine(pcxHeader, is, scanline);
                System.arraycopy(scanline, 0, image, y*bytesPerImageRow, bytesPerImageRow);
            }
            DataBufferByte dataBuffer = new DataBufferByte(image, image.length);
            int[] palette;
            if (pcxHeader.bitsPerPixel == 1)
                palette = new int[] { 0x000000, 0xffffff };
            else if (pcxHeader.bitsPerPixel == 8)
            {
                // Normally the palette is read 769 bytes from the end of the file.
                // However DCX files have multiple PCX images in one file, so
                // there could be extra data before the end! So try look for the palette
                // immediately after the image data first.
                palette = read256ColorPalette(is);
                if (palette == null)
                    palette = read256ColorPaletteFromEndOfFile(byteSource);
                if (palette == null)
                    throw new ImageReadException(
                            "No 256 color palette found in image that needs it");
            }
            else
                palette = pcxHeader.colormap;
            WritableRaster raster;
            if (pcxHeader.bitsPerPixel == 8)
            {
                raster = WritableRaster.createInterleavedRaster(dataBuffer,
                        xSize, ySize, bytesPerImageRow, 1, new int[]{0}, null);
            }
            else
            {
                raster =  WritableRaster.createPackedRaster(dataBuffer,
                        xSize, ySize, pcxHeader.bitsPerPixel, null);
            }
            IndexColorModel colorModel = new IndexColorModel(pcxHeader.bitsPerPixel,
                    1 << pcxHeader.bitsPerPixel, palette, 0, false, -1, DataBuffer.TYPE_BYTE);
            return new BufferedImage(colorModel, raster,
                    colorModel.isAlphaPremultiplied(), new Properties());
        }
        else if (pcxHeader.bitsPerPixel == 1 && 2 <= pcxHeader.nPlanes
                && pcxHeader.nPlanes <= 4)
        {
            IndexColorModel colorModel = new IndexColorModel(pcxHeader.nPlanes,
                    1 << pcxHeader.nPlanes, pcxHeader.colormap, 0, false, -1, DataBuffer.TYPE_BYTE);
            BufferedImage image = new BufferedImage(xSize, ySize, BufferedImage.TYPE_BYTE_BINARY, colorModel);
            byte[] unpacked = new byte[xSize];
            for (int y = 0; y < ySize; y++)
            {
                readScanLine(pcxHeader, is, scanline);
                int nextByte = 0;
                Arrays.fill(unpacked, (byte) 0);
                for (int plane = 0; plane < pcxHeader.nPlanes; plane++)
                {
                    for (int i = 0; i < pcxHeader.bytesPerLine; i++)
                    {
                        int b = 0xff & scanline[nextByte++];
                        for (int j = 0; j < 8 && 8*i + j < unpacked.length; j++)
                            unpacked[8*i + j] |= (byte) (((b >> (7 - j)) & 0x1) << plane);
                    }
                }
                image.getRaster().setDataElements(0, y, xSize, 1, unpacked);
            }
            return image;
        }
        else if (pcxHeader.bitsPerPixel == 8 && pcxHeader.nPlanes == 3)
        {
            byte[][] image = new byte[3][];
            image[0] = new byte[xSize*ySize];
            image[1] = new byte[xSize*ySize];
            image[2] = new byte[xSize*ySize];
            for (int y = 0; y < ySize; y++)
            {
                readScanLine(pcxHeader, is, scanline);
                System.arraycopy(scanline, 0, image[0], y*xSize, xSize);
                System.arraycopy(scanline, pcxHeader.bytesPerLine,
                        image[1], y*xSize, xSize);
                System.arraycopy(scanline, 2*pcxHeader.bytesPerLine,
                        image[2], y*xSize, xSize);
            }
            DataBufferByte dataBuffer = new DataBufferByte(image, image[0].length);
            WritableRaster raster = WritableRaster.createBandedRaster(dataBuffer,
                    xSize, ySize, xSize, new int[]{0,1,2},
                    new int[]{0,0,0}, null);
            ColorModel colorModel = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
                    Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
            return new BufferedImage(colorModel, raster,
                    colorModel.isAlphaPremultiplied(), new Properties());
        }
        else if ((pcxHeader.bitsPerPixel == 24 && pcxHeader.nPlanes == 1) ||
                (pcxHeader.bitsPerPixel == 32 && pcxHeader.nPlanes == 1))
        {
            int rowLength = 3 * xSize;
            byte[] image = new byte[rowLength * ySize];
            for (int y = 0; y < ySize; y++)
            {
                readScanLine(pcxHeader, is, scanline);
                if (pcxHeader.bitsPerPixel == 24)
                    System.arraycopy(scanline, 0, image, y*rowLength, rowLength);
                else
                {
                    for (int x = 0; x < xSize; x++)
                    {
                        image[y*rowLength + 3*x] = scanline[4*x];
                        image[y*rowLength + 3*x + 1] = scanline[4*x + 1];
                        image[y*rowLength + 3*x + 2] = scanline[4*x + 2];
                    }
                }
            }
            DataBufferByte dataBuffer = new DataBufferByte(image, image.length);
            WritableRaster raster = WritableRaster.createInterleavedRaster(
                    dataBuffer, xSize, ySize, rowLength, 3,
                    new int[]{2,1,0}, null);
            ColorModel colorModel = new ComponentColorModel(
                    ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
View Full Code Here

            throws ImageReadException, IOException
    {
        int rowLength = (wbmpHeader.width + 7) / 8;
        byte[] image = readByteArray("Pixels", rowLength * wbmpHeader.height, is,
                "Error reading image pixels");
        DataBufferByte dataBuffer = new DataBufferByte(image, image.length);
        WritableRaster raster = WritableRaster.createPackedRaster(dataBuffer,
                wbmpHeader.width, wbmpHeader.height, 1, null);
        int[] palette = {0x000000, 0xffffff};
        IndexColorModel colorModel = new IndexColorModel(1, 2, palette, 0,
                false, -1, DataBuffer.TYPE_BYTE);
View Full Code Here

//      Get the ColorModel right
        PDColorSpace colorspace = getColorSpace();
        ColorModel cm = colorspace.createColorModel( bpc );
        WritableRaster raster = cm.createCompatibleWritableRaster( width, height );
        //DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
        DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
        byte[] bufferData = buffer.getData();
        //System.arraycopy( array, 0, bufferData, 0, array.length );
        int predictor = getPredictor();

        PredictorAlgorithm filter = PredictorAlgorithm.getFilter(predictor);
        filter.setWidth(width);
View Full Code Here

                new Point(0,0) );
                */
        DataBuffer rasterBuffer = raster.getDataBuffer();
        if( rasterBuffer instanceof DataBufferByte )
        {
            DataBufferByte byteBuffer = (DataBufferByte)rasterBuffer;
            byte[] data = byteBuffer.getData();
            System.arraycopy( finalData, 0, data, 0, data.length );
        }
        else if( rasterBuffer instanceof DataBufferInt )
        {
            DataBufferInt byteBuffer = (DataBufferInt)rasterBuffer;
            int[] data = byteBuffer.getData();
            for( int i=0; i<finalData.length; i++ )
            {
                data[i] = (finalData[i]+256)%256;
            }
        }
View Full Code Here

        // Restore the transient DataBuffer.
        switch (dataType) {
        case DataBuffer.TYPE_BYTE:
            dataBuffer =
                new DataBufferByte((byte[][])dataArray, size, offsets);
            break;
        case DataBuffer.TYPE_SHORT:
            dataBuffer =
                new DataBufferShort((short[][])dataArray, size, offsets);
            break;
View Full Code Here

        }
        int size = (int)lsize;

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

        case DataBuffer.TYPE_USHORT:
            d = new DataBufferUShort(size);
            break;
View Full Code Here

        }
        int size = (int)lsize;

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

        case DataBuffer.TYPE_USHORT:
            d = new DataBufferUShort(size, banks);
            break;
View Full Code Here

        // Restore the transient DataBuffer.
        switch (dataType) {
        case DataBuffer.TYPE_BYTE:
            dataBuffer =
                new DataBufferByte((byte[][])dataArray, size, offsets);
            break;
        case DataBuffer.TYPE_SHORT:
            dataBuffer =
                new DataBufferShort((short[][])dataArray, size, offsets);
            break;
View Full Code Here

TOP

Related Classes of java.awt.image.DataBufferByte

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.