Package java.awt.image

Examples of java.awt.image.ComponentSampleModel


          // 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};
View Full Code Here


    else
   
      if (bi.getColorModel() instanceof ComponentColorModel && bi.getSampleModel() instanceof ComponentSampleModel)
      {
        final ComponentColorModel componentColorModel = (ComponentColorModel) bi.getColorModel();
        final ComponentSampleModel componentSampleModel = (ComponentSampleModel) bi.getSampleModel();
        final int[] offsets = componentSampleModel.getBandOffsets();
        if (dataBuffer instanceof DataBufferInt)
        {
          // TODO: untested
          bitsPerPixel = 32
          red = 0xFF << offsets[0];
          green = 0xFF << offsets[1];
          blue = 0xFF << offsets[2];

        }
        else if (dataBuffer instanceof DataBufferByte)
        {
          bitsPerPixel = componentSampleModel.getPixelStride() * 8// TODO: should it always be 24? or are the pixel stride and the bits per pixel unrelated?
          red = 1 + offsets[0];
          green = 1 + offsets[1];
          blue = 1 + offsets[2];
        }
        else
View Full Code Here

                ColorModel cm = null;
                WritableRaster wr = null;
                if (depth() == IPL_DEPTH_8U || depth() == IPL_DEPTH_8S) {
                    cm = new ComponentColorModel(cs, alpha,
                            false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
                    wr = Raster.createWritableRaster(new ComponentSampleModel(
                            DataBuffer.TYPE_BYTE, width(), height(), nChannels(), widthStep(),
                            offsets), null);
                } else if (depth() == IPL_DEPTH_16U) {
                    cm = new ComponentColorModel(cs, alpha,
                            false, Transparency.OPAQUE, DataBuffer.TYPE_USHORT);
                    wr = Raster.createWritableRaster(new ComponentSampleModel(
                            DataBuffer.TYPE_USHORT, width(), height(), nChannels(), widthStep()/2,
                            offsets), null);
                } else if (depth() == IPL_DEPTH_16S) {
                    cm = new ComponentColorModel(cs, alpha,
                            false, Transparency.OPAQUE, DataBuffer.TYPE_SHORT);
                    wr = Raster.createWritableRaster(new ComponentSampleModel(
                            DataBuffer.TYPE_SHORT, width(), height(), nChannels(), widthStep()/2,
                            offsets), null);
                } else if (depth() == IPL_DEPTH_32S) {
                    cm = new ComponentColorModel(cs, alpha,
                            false, Transparency.OPAQUE, DataBuffer.TYPE_INT);
                    wr = Raster.createWritableRaster(new ComponentSampleModel(
                            DataBuffer.TYPE_INT, width(), height(), nChannels(), widthStep()/4,
                            offsets), null);
                } else if (depth() == IPL_DEPTH_32F) {
                    cm = new ComponentColorModel(cs, alpha,
                            false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
                    wr = Raster.createWritableRaster(new ComponentSampleModel(
                            DataBuffer.TYPE_FLOAT, width(), height(), nChannels(), widthStep()/4,
                            offsets), null);
                } else if (depth() == IPL_DEPTH_64F) {
                    cm = new ComponentColorModel(cs, alpha,
                            false, Transparency.OPAQUE, DataBuffer.TYPE_DOUBLE);
                    wr = Raster.createWritableRaster(new ComponentSampleModel(
                            DataBuffer.TYPE_DOUBLE, width(), height(), nChannels(), widthStep()/8,
                            offsets), null);
                }

                bufferedImage = new BufferedImage(cm, wr, false, null);
View Full Code Here

            }
        } else if ((variant == PGM_RAW || variant == PPM_RAW) &&
                   sampleModel instanceof ComponentSampleModel &&
                   !(colorModel instanceof IndexColorModel)) {

            ComponentSampleModel csm =
                (ComponentSampleModel)sampleModel;

            // Pixel stride must equal band count.
            if(csm.getPixelStride() == numBands) {
                writeOptimal = true;

                // Band offsets must equal band indices.
                if(variant == PPM_RAW) {
                    int[] bandOffsets = csm.getBandOffsets();
                    for(int b = 0; b < numBands; b++) {
                        if(bandOffsets[b] != b) {
                            writeOptimal = false;
                            break;
                        }
View Full Code Here

            SampleModel srcSM = getSampleModel();
            int dataType = srcSM.getDataType();
            int nbands = srcSM.getNumBands();
            boolean isBandChild = false;

            ComponentSampleModel csm = null;
            int[] bandOffs = null;

            boolean fastCobblePossible = false;
            if (srcSM instanceof ComponentSampleModel) {
                csm = (ComponentSampleModel)srcSM;
                int ps = csm.getPixelStride();
                boolean isBandInt = (ps == 1 && nbands > 1);
                isBandChild = (ps > 1 && nbands != ps);
                if ( (!isBandChild) && (!isBandInt)) {
                    bandOffs = csm.getBandOffsets();
                    int i;
                    for (i=0; i<nbands; i++) {
                        if (bandOffs[i] >= nbands) {
                            break;
                        }
View Full Code Here

                RasterAccessor d = new RasterAccessor(raster, subRegion,
                                                      dstTag, null);

                if (getSampleModel() instanceof ComponentSampleModel &&
                    raster.getSampleModel() instanceof ComponentSampleModel) {
                    ComponentSampleModel ssm = (ComponentSampleModel) getSampleModel();

                    if (ssm.getPixelStride() == ssm.getNumBands() &&
                        getSampleModel().getNumBands() == raster.getSampleModel().getNumBands())
                        fastCopyRaster(s, d);
                    else
                        ImageUtil.copyRaster(s, d);
                } else
View Full Code Here

    }

    private void cobbleByte(Rectangle bounds,
                            Raster dstRaster) {

        ComponentSampleModel dstSM =
            (ComponentSampleModel)dstRaster.getSampleModel();

        int startX = XToTileX(bounds.x);
        int startY = YToTileY(bounds.y);
        int rectXend = bounds.x + bounds.width - 1;
        int rectYend = bounds.y + bounds.height - 1;
        int endX = XToTileX(rectXend);
        int endY = YToTileY(rectYend);

        //
        //  Get parameters of destination raster
        //
        DataBufferByte dstDB = (DataBufferByte)dstRaster.getDataBuffer();
        byte[] dst           = dstDB.getData();
        int dstPS            = dstSM.getPixelStride();
        int dstSS            = dstSM.getScanlineStride();

        boolean tileParamsSet = false;
        ComponentSampleModel srcSM = null;
        int srcPS=0, srcSS=0;
        int xOrg, yOrg;
        int srcX1, srcY1, srcX2, srcY2, srcW, srcH;

        for (int y = startY; y <= endY; y++) {
            for (int x = startX; x <= endX; x++) {
                Raster tile = getTile(x, y);
                if (tile == null) {
                    //
                    // Out-of-bounds tile. Zero fill will be supplied
                    // since dstRaster is initialized to zero
                    //
                    continue;
                }

                if (! tileParamsSet) {
                    //
                    // These are constant for all tiles,
                    // so only set them once.
                    //
                    srcSM = (ComponentSampleModel)tile.getSampleModel();
                    srcPS = srcSM.getPixelStride();
                    srcSS = srcSM.getScanlineStride();
                    tileParamsSet = true;
                }

                //
                //  Intersect the tile and the rectangle
View Full Code Here

    }

    private void cobbleShort(Rectangle bounds,
                            Raster dstRaster) {

        ComponentSampleModel dstSM =
            (ComponentSampleModel)dstRaster.getSampleModel();

        int startX = XToTileX(bounds.x);
        int startY = YToTileY(bounds.y);
        int rectXend = bounds.x + bounds.width - 1;
        int rectYend = bounds.y + bounds.height - 1;
        int endX = XToTileX(rectXend);
        int endY = YToTileY(rectYend);

        //
        //  Get parameters of destination raster
        //
        DataBufferShort dstDB = (DataBufferShort)dstRaster.getDataBuffer();
        short[] dst           = dstDB.getData();
        int dstPS            = dstSM.getPixelStride();
        int dstSS            = dstSM.getScanlineStride();

        boolean tileParamsSet = false;
        ComponentSampleModel srcSM = null;
        int srcPS=0, srcSS=0;
        int xOrg, yOrg;
        int srcX1, srcY1, srcX2, srcY2, srcW, srcH;

        for (int y = startY; y <= endY; y++) {
            for (int x = startX; x <= endX; x++) {
                Raster tile = getTile(x, y);
                if (tile == null) {
                    //
                    // Out-of-bounds tile. Zero fill will be supplied
                    // since dstRaster is initialized to zero
                    //
                    continue;
                }

                if (! tileParamsSet) {
                    //
                    // These are constant for all tiles,
                    // so only set them once.
                    //
                    srcSM = (ComponentSampleModel)tile.getSampleModel();
                    srcPS = srcSM.getPixelStride();
                    srcSS = srcSM.getScanlineStride();
                    tileParamsSet = true;
                }

                //
                //  Intersect the tile and the rectangle
View Full Code Here

    }

    private void cobbleUShort(Rectangle bounds,
                            Raster dstRaster) {

        ComponentSampleModel dstSM =
            (ComponentSampleModel)dstRaster.getSampleModel();

        int startX = XToTileX(bounds.x);
        int startY = YToTileY(bounds.y);
        int rectXend = bounds.x + bounds.width - 1;
        int rectYend = bounds.y + bounds.height - 1;
        int endX = XToTileX(rectXend);
        int endY = YToTileY(rectYend);

        //
        //  Get parameters of destination raster
        //
        DataBufferUShort dstDB = (DataBufferUShort)dstRaster.getDataBuffer();
        short[] dst           = dstDB.getData();
        int dstPS            = dstSM.getPixelStride();
        int dstSS            = dstSM.getScanlineStride();

        boolean tileParamsSet = false;
        ComponentSampleModel srcSM = null;
        int srcPS=0, srcSS=0;
        int xOrg, yOrg;
        int srcX1, srcY1, srcX2, srcY2, srcW, srcH;

        for (int y = startY; y <= endY; y++) {
            for (int x = startX; x <= endX; x++) {
                Raster tile = getTile(x, y);
                if (tile == null) {
                    //
                    // Out-of-bounds tile. Zero fill will be supplied
                    // since dstRaster is initialized to zero
                    //
                    continue;
                }

                if (! tileParamsSet) {
                    //
                    // These are constant for all tiles,
                    // so only set them once.
                    //
                    srcSM = (ComponentSampleModel)tile.getSampleModel();
                    srcPS = srcSM.getPixelStride();
                    srcSS = srcSM.getScanlineStride();
                    tileParamsSet = true;
                }

                //
                //  Intersect the tile and the rectangle
View Full Code Here

    }

    private void cobbleInt(Rectangle bounds,
                            Raster dstRaster) {

        ComponentSampleModel dstSM =
            (ComponentSampleModel)dstRaster.getSampleModel();

        int startX = XToTileX(bounds.x);
        int startY = YToTileY(bounds.y);
        int rectXend = bounds.x + bounds.width - 1;
        int rectYend = bounds.y + bounds.height - 1;
        int endX = XToTileX(rectXend);
        int endY = YToTileY(rectYend);

        //
        //  Get parameters of destination raster
        //
        DataBufferInt dstDB = (DataBufferInt)dstRaster.getDataBuffer();
        int[] dst           = dstDB.getData();
        int dstPS            = dstSM.getPixelStride();
        int dstSS            = dstSM.getScanlineStride();

        boolean tileParamsSet = false;
        ComponentSampleModel srcSM = null;
        int srcPS=0, srcSS=0;
        int xOrg, yOrg;
        int srcX1, srcY1, srcX2, srcY2, srcW, srcH;

        for (int y = startY; y <= endY; y++) {
            for (int x = startX; x <= endX; x++) {
                Raster tile = getTile(x, y);
                if (tile == null) {
                    //
                    // Out-of-bounds tile. Zero fill will be supplied
                    // since dstRaster is initialized to zero
                    //
                    continue;
                }

                if (! tileParamsSet) {
                    //
                    // These are constant for all tiles,
                    // so only set them once.
                    //
                    srcSM = (ComponentSampleModel)tile.getSampleModel();
                    srcPS = srcSM.getPixelStride();
                    srcSS = srcSM.getScanlineStride();
                    tileParamsSet = true;
                }

                //
                //  Intersect the tile and the rectangle
View Full Code Here

TOP

Related Classes of java.awt.image.ComponentSampleModel

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.