Java Code Examples for java.awt.image.SinglePixelPackedSampleModel#getScanlineStride()

The following examples show how to use java.awt.image.SinglePixelPackedSampleModel#getScanlineStride() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebP.java    From webp-imageio with Apache License 2.0 5 votes vote down vote up
private static byte[] extractDirectRGBAInt( int aWidth, int aHeight, DirectColorModel aColorModel, SinglePixelPackedSampleModel aSampleModel, DataBufferInt aDataBuffer ) {
  byte[] out = new byte[ aWidth * aHeight * 4 ];

  int rMask = aColorModel.getRedMask();
  int gMask = aColorModel.getGreenMask();
  int bMask = aColorModel.getBlueMask();
  int aMask = aColorModel.getAlphaMask();
  int rShift = getShift( rMask );
  int gShift = getShift( gMask );
  int bShift = getShift( bMask );
  int aShift = getShift( aMask );
  int[] bank = aDataBuffer.getBankData()[ 0 ];
  int scanlineStride = aSampleModel.getScanlineStride();
  int scanIx = 0;
  for ( int b = 0, y = 0; y < aHeight; y++ ) {
    int pixIx = scanIx;
    for ( int x = 0; x < aWidth; x++, b += 4 ) {
      int pixel = bank[ pixIx++ ];
      out[ b ] = ( byte ) ( ( pixel & rMask ) >>> rShift );
      out[ b + 1 ] = ( byte ) ( ( pixel & gMask ) >>> gShift );
      out[ b + 2 ] = ( byte ) ( ( pixel & bMask ) >>> bShift );
      out[ b + 3 ] = ( byte ) ( ( pixel & aMask ) >>> aShift );
    }
    scanIx += scanlineStride;
  }
  return out;
}
 
Example 2
Source File: IntegerInterleavedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerInterleavedRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerInterleavedRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
 
Example 3
Source File: IntegerInterleavedRaster.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                DataBufferInt dataBuffer,
                                Rectangle aRegion,
                                Point origin,
                                IntegerInterleavedRaster parent)
{
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    this.data = stealData(dataBuffer, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dataBuffer.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
 
Example 4
Source File: PathGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if the BufferedImage argument has non-opaque
 * bits in it and therefore can not be directly rendered by
 * GDI. Return false if the image is opaque. If this function
 * can not tell for sure whether the image has transparent
 * pixels then it assumes that it does.
 */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null
        ? true
        : colorModel.getTransparency() != ColorModel.OPAQUE;

    /*
     * For the default INT ARGB check the image to see if any pixels are
     * really transparent. If there are no transparent pixels then the
     * transparency of the color model can be ignored.
     * We assume that IndexColorModel images have already been
     * checked for transparency and will be OPAQUE unless they actually
     * have transparent pixels present.
     */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
            bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt &&
                sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm =
                    (SinglePixelPackedSampleModel)sm;
                // Stealing the data array for reading only...
                int[] int_data =
                    SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y+h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x+w; i++) {
                        if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }

    return hasTransparency;
}
 
Example 5
Source File: IntegerComponentRaster.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a IntegerComponentRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerComponentRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerComponentRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerComponentRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    if (dbi.getNumBanks() != 1) {
        throw new
            RasterFormatException("DataBuffer for IntegerComponentRasters"+
                                  " must only have 1 bank.");
    }
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        int[] boffsets = sppsm.getBitOffsets();
        boolean notByteBoundary = false;
        for (int i=1; i < boffsets.length; i++) {
            if ((boffsets[i]%8) != 0) {
                notByteBoundary = true;
            }
        }
        this.type = (notByteBoundary
                     ? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES
                     : IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES);

        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerComponentRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }

    verify();
}
 
Example 6
Source File: ByteInterleavedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
        throw new RasterFormatException("ByteInterleavedRasters must have " +
                                        "byte DataBuffers");
    }

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 7
Source File: PathGraphics.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if the BufferedImage argument has non-opaque
 * bits in it and therefore can not be directly rendered by
 * GDI. Return false if the image is opaque. If this function
 * can not tell for sure whether the image has transparent
 * pixels then it assumes that it does.
 */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null
        ? true
        : colorModel.getTransparency() != ColorModel.OPAQUE;

    /*
     * For the default INT ARGB check the image to see if any pixels are
     * really transparent. If there are no transparent pixels then the
     * transparency of the color model can be ignored.
     * We assume that IndexColorModel images have already been
     * checked for transparency and will be OPAQUE unless they actually
     * have transparent pixels present.
     */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
            bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt &&
                sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm =
                    (SinglePixelPackedSampleModel)sm;
                // Stealing the data array for reading only...
                int[] int_data =
                    SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y+h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x+w; i++) {
                        if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }

    return hasTransparency;
}
 
Example 8
Source File: PathGraphics.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if the BufferedImage argument has non-opaque
 * bits in it and therefore can not be directly rendered by
 * GDI. Return false if the image is opaque. If this function
 * can not tell for sure whether the image has transparent
 * pixels then it assumes that it does.
 */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null
        ? true
        : colorModel.getTransparency() != ColorModel.OPAQUE;

    /*
     * For the default INT ARGB check the image to see if any pixels are
     * really transparent. If there are no transparent pixels then the
     * transparency of the color model can be ignored.
     * We assume that IndexColorModel images have already been
     * checked for transparency and will be OPAQUE unless they actually
     * have transparent pixels present.
     */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
            bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt &&
                sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm =
                    (SinglePixelPackedSampleModel)sm;
                // Stealing the data array for reading only...
                int[] int_data =
                    SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y+h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x+w; i++) {
                        if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }

    return hasTransparency;
}
 
Example 9
Source File: IntegerComponentRaster.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a IntegerComponentRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerComponentRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerComponentRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerComponentRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    if (dbi.getNumBanks() != 1) {
        throw new
            RasterFormatException("DataBuffer for IntegerComponentRasters"+
                                  " must only have 1 bank.");
    }
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        int[] boffsets = sppsm.getBitOffsets();
        boolean notByteBoundary = false;
        for (int i=1; i < boffsets.length; i++) {
            if ((boffsets[i]%8) != 0) {
                notByteBoundary = true;
            }
        }
        this.type = (notByteBoundary
                     ? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES
                     : IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES);

        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerComponentRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }

    verify();
}
 
Example 10
Source File: ByteInterleavedRaster.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
        throw new RasterFormatException("ByteInterleavedRasters must have " +
                                        "byte DataBuffers");
    }

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 11
Source File: PathGraphics.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if the BufferedImage argument has non-opaque
 * bits in it and therefore can not be directly rendered by
 * GDI. Return false if the image is opaque. If this function
 * can not tell for sure whether the image has transparent
 * pixels then it assumes that it does.
 */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null
        ? true
        : colorModel.getTransparency() != ColorModel.OPAQUE;

    /*
     * For the default INT ARGB check the image to see if any pixels are
     * really transparent. If there are no transparent pixels then the
     * transparency of the color model can be ignored.
     * We assume that IndexColorModel images have already been
     * checked for transparency and will be OPAQUE unless they actually
     * have transparent pixels present.
     */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
            bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt &&
                sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm =
                    (SinglePixelPackedSampleModel)sm;
                // Stealing the data array for reading only...
                int[] int_data =
                    SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y+h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x+w; i++) {
                        if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }

    return hasTransparency;
}
 
Example 12
Source File: ByteInterleavedRaster.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
        throw new RasterFormatException("ByteInterleavedRasters must have " +
                                        "byte DataBuffers");
    }

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 13
Source File: IntegerComponentRaster.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a IntegerComponentRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerComponentRaster(SampleModel sampleModel,
                              DataBufferInt dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              IntegerComponentRaster parent)
{
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (dataBuffer.getNumBanks() != 1) {
        throw new
            RasterFormatException("DataBuffer for IntegerComponentRasters"+
                                  " must only have 1 bank.");
    }
    this.data = stealData(dataBuffer, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        int[] boffsets = sppsm.getBitOffsets();
        boolean notByteBoundary = false;
        for (int i=1; i < boffsets.length; i++) {
            if ((boffsets[i]%8) != 0) {
                notByteBoundary = true;
            }
        }
        this.type = (notByteBoundary
                     ? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES
                     : IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES);

        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dataBuffer.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerComponentRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }

    verify();
}
 
Example 14
Source File: IntegerComponentRaster.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a IntegerComponentRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerComponentRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerComponentRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerComponentRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    if (dbi.getNumBanks() != 1) {
        throw new
            RasterFormatException("DataBuffer for IntegerComponentRasters"+
                                  " must only have 1 bank.");
    }
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        int[] boffsets = sppsm.getBitOffsets();
        boolean notByteBoundary = false;
        for (int i=1; i < boffsets.length; i++) {
            if ((boffsets[i]%8) != 0) {
                notByteBoundary = true;
            }
        }
        this.type = (notByteBoundary
                     ? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES
                     : IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES);

        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerComponentRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }

    verify();
}
 
Example 15
Source File: ByteInterleavedRaster.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferByte that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ByteInterleavedRaster(SampleModel sampleModel,
                             DataBufferByte dataBuffer,
                             Rectangle aRegion,
                             Point origin,
                             ByteInterleavedRaster parent)
{
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    this.data = stealData(dataBuffer, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dataBuffer.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 16
Source File: IntegerComponentRaster.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a IntegerComponentRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerComponentRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerComponentRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerComponentRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    if (dbi.getNumBanks() != 1) {
        throw new
            RasterFormatException("DataBuffer for IntegerComponentRasters"+
                                  " must only have 1 bank.");
    }
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        int[] boffsets = sppsm.getBitOffsets();
        boolean notByteBoundary = false;
        for (int i=1; i < boffsets.length; i++) {
            if ((boffsets[i]%8) != 0) {
                notByteBoundary = true;
            }
        }
        this.type = (notByteBoundary
                     ? IntegerComponentRaster.TYPE_INT_PACKED_SAMPLES
                     : IntegerComponentRaster.TYPE_INT_8BIT_SAMPLES);

        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerComponentRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }

    verify();
}
 
Example 17
Source File: ByteInterleavedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferByte that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ByteInterleavedRaster(SampleModel sampleModel,
                             DataBufferByte dataBuffer,
                             Rectangle aRegion,
                             Point origin,
                             ByteInterleavedRaster parent)
{
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    this.data = stealData(dataBuffer, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dataBuffer.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 18
Source File: PathGraphics.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if the BufferedImage argument has non-opaque
 * bits in it and therefore can not be directly rendered by
 * GDI. Return false if the image is opaque. If this function
 * can not tell for sure whether the image has transparent
 * pixels then it assumes that it does.
 */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null
        ? true
        : colorModel.getTransparency() != ColorModel.OPAQUE;

    /*
     * For the default INT ARGB check the image to see if any pixels are
     * really transparent. If there are no transparent pixels then the
     * transparency of the color model can be ignored.
     * We assume that IndexColorModel images have already been
     * checked for transparency and will be OPAQUE unless they actually
     * have transparent pixels present.
     */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
            bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt &&
                sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm =
                    (SinglePixelPackedSampleModel)sm;
                // Stealing the data array for reading only...
                int[] int_data =
                    SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y+h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x+w; i++) {
                        if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }

    return hasTransparency;
}
 
Example 19
Source File: ByteInterleavedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a ByteInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferByte and
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or InterleavedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ByteInterleavedRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Rectangle aRegion,
                              Point origin,
                              ByteInterleavedRaster parent) {
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
        throw new RasterFormatException("ByteInterleavedRasters must have " +
                                        "byte DataBuffers");
    }

    DataBufferByte dbb = (DataBufferByte)dataBuffer;
    this.data = stealData(dbb, 0);

    int xOffset = aRegion.x - origin.x;
    int yOffset = aRegion.y - origin.y;
    if (sampleModel instanceof PixelInterleavedSampleModel ||
        (sampleModel instanceof ComponentSampleModel &&
         isInterleaved((ComponentSampleModel)sampleModel))) {
        ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
        this.scanlineStride = csm.getScanlineStride();
        this.pixelStride = csm.getPixelStride();
        this.dataOffsets = csm.getBandOffsets();
        for (int i = 0; i < getNumDataElements(); i++) {
            dataOffsets[i] += xOffset*pixelStride+yOffset*scanlineStride;
        }
    } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.packed = true;
        this.bitMasks = sppsm.getBitMasks();
        this.bitOffsets = sppsm.getBitOffsets();
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbb.getOffset();
        dataOffsets[0] += xOffset*pixelStride+yOffset*scanlineStride;
    } else {
        throw new RasterFormatException("ByteInterleavedRasters must " +
          "have PixelInterleavedSampleModel, SinglePixelPackedSampleModel"+
          " or interleaved ComponentSampleModel.  Sample model is " +
          sampleModel);
    }
    this.bandOffset = this.dataOffsets[0];

    this.dbOffsetPacked = dataBuffer.getOffset() -
        sampleModelTranslateY*scanlineStride -
        sampleModelTranslateX*pixelStride;
    this.dbOffset = dbOffsetPacked -
        (xOffset*pixelStride+yOffset*scanlineStride);

    // Set inOrder to true if the data elements are in order and
    // have no gaps between them
    this.inOrder = false;
    if (numDataElements == pixelStride) {
        inOrder = true;
        for (int i = 1; i < numDataElements; i++) {
            if (dataOffsets[i] - dataOffsets[0] != i) {
                inOrder = false;
                break;
            }
        }
    }

    verify();
}
 
Example 20
Source File: PathGraphics.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return true if the BufferedImage argument has non-opaque
 * bits in it and therefore can not be directly rendered by
 * GDI. Return false if the image is opaque. If this function
 * can not tell for sure whether the image has transparent
 * pixels then it assumes that it does.
 */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null
        ? true
        : colorModel.getTransparency() != ColorModel.OPAQUE;

    /*
     * For the default INT ARGB check the image to see if any pixels are
     * really transparent. If there are no transparent pixels then the
     * transparency of the color model can be ignored.
     * We assume that IndexColorModel images have already been
     * checked for transparency and will be OPAQUE unless they actually
     * have transparent pixels present.
     */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
            bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt &&
                sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm =
                    (SinglePixelPackedSampleModel)sm;
                // Stealing the data array for reading only...
                int[] int_data =
                    SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y+h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x+w; i++) {
                        if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }

    return hasTransparency;
}