本文整理匯總了Java中java.awt.image.SinglePixelPackedSampleModel.getScanlineStride方法的典型用法代碼示例。如果您正苦於以下問題:Java SinglePixelPackedSampleModel.getScanlineStride方法的具體用法?Java SinglePixelPackedSampleModel.getScanlineStride怎麽用?Java SinglePixelPackedSampleModel.getScanlineStride使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.image.SinglePixelPackedSampleModel
的用法示例。
在下文中一共展示了SinglePixelPackedSampleModel.getScanlineStride方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extractDirectRGBInt
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
private static byte[] extractDirectRGBInt( int aWidth, int aHeight, DirectColorModel aColorModel, SinglePixelPackedSampleModel aSampleModel, DataBufferInt aDataBuffer ) {
byte[] out = new byte[ aWidth * aHeight * 3 ];
int rMask = aColorModel.getRedMask();
int gMask = aColorModel.getGreenMask();
int bMask = aColorModel.getBlueMask();
int rShift = getShift( rMask );
int gShift = getShift( gMask );
int bShift = getShift( bMask );
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 += 3 ) {
int pixel = bank[ pixIx++ ];
out[ b ] = ( byte ) ( ( pixel & rMask ) >>> rShift );
out[ b + 1 ] = ( byte ) ( ( pixel & gMask ) >>> gShift );
out[ b + 2 ] = ( byte ) ( ( pixel & bMask ) >>> bShift );
}
scanIx += scanlineStride;
}
return out;
}
示例2: IntegerInterleavedRaster
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* 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();
}
示例3: IntegerInterleavedRaster
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* 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();
}
示例4: forceTransparentWhite
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* Converts an image so that viewers which do not support the
* alpha channel will see a white background (and not a black
* one).
* @param img the image to convert
* @param sppsm
*/
protected void forceTransparentWhite(BufferedImage img, SinglePixelPackedSampleModel sppsm) {
//
// This is a trick so that viewers which do not support
// the alpha channel will see a white background (and not
// a black one).
//
int w = img.getWidth();
int h = img.getHeight();
DataBufferInt biDB=(DataBufferInt)img.getRaster().getDataBuffer();
int scanStride = sppsm.getScanlineStride();
int dbOffset = biDB.getOffset();
int[] pixels = biDB.getBankData()[0];
int p = dbOffset;
int adjust = scanStride - w;
int a=0, r=0, g=0, b=0, pel=0;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
pel = pixels[p];
a = (pel >> 24) & 0xff;
r = (pel >> 16) & 0xff;
g = (pel >> 8 ) & 0xff;
b = pel & 0xff;
r = (255*(255 -a) + a*r)/255;
g = (255*(255 -a) + a*g)/255;
b = (255*(255 -a) + a*b)/255;
pixels[p++] =
(a<<24 & 0xff000000) |
(r<<16 & 0xff0000) |
(g<<8 & 0xff00) |
(b & 0xff);
}
p += adjust;
}
}
示例5: applyLut_INT
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
public static WritableRaster applyLut_INT(WritableRaster wr,
final int []lut) {
SinglePixelPackedSampleModel sm =
(SinglePixelPackedSampleModel)wr.getSampleModel();
DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
final int srcBase
= (db.getOffset() +
sm.getOffset(wr.getMinX()-wr.getSampleModelTranslateX(),
wr.getMinY()-wr.getSampleModelTranslateY()));
// Access the pixel data array
final int[] pixels = db.getBankData()[0];
final int width = wr.getWidth();
final int height = wr.getHeight();
final int scanStride = sm.getScanlineStride();
int end, pix;
// For alpha premult we need to multiply all comps.
for (int y=0; y<height; y++) {
int sp = srcBase + y*scanStride;
end = sp + width;
while (sp<end) {
pix = pixels[sp];
pixels[sp] =
(( pix &0xFF000000)|
(lut[(pix>>>16)&0xFF]<<16) |
(lut[(pix>>> 8)&0xFF]<< 8) |
(lut[(pix )&0xFF] ));
sp++;
}
}
return wr;
}
示例6: convertIndexColorModelToSRGB
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* Converts pixels from an index color model to the target image.
*
* @param x the X coordinate of the source pixel rectangle
* @param y the Y coordinate of the source pixel rectangle
* @param w the width of the source pixel rectangle
* @param h the height of the source pixel rectangle
* @param model the color model of the source pixels
* @param pixels the pixel data
* @param offset the offset in the pixel array
* @param scansize the scanline size
* @param transparency the assumed transparency
*
* @return the determined transparency
*/
private int convertIndexColorModelToSRGB(int x, int y, int w, int h,
IndexColorModel model,
byte[] pixels, int offset,
int scansize, int transparency)
{
int mapSize = model.getMapSize();
int[] colorMap = new int[mapSize];
for(int i=0; i < mapSize; i++)
{
colorMap[i] = model.getRGB(i);
}
WritableRaster raster = bImage.getRaster();
SinglePixelPackedSampleModel sampleMode =
(SinglePixelPackedSampleModel) raster.getSampleModel();
DataBuffer dataBuffer = (DataBuffer) raster.getDataBuffer();
int rasterOffset = sampleMode.getOffset(x,y)+dataBuffer.getOffset();
int rasterScanline = sampleMode.getScanlineStride();
for (int yy = 0; yy < h; yy++)
{
int xoffset = offset;
for (int xx = 0; xx < w; xx++)
{
int argb = colorMap[(pixels[xoffset++] & 0xFF)];
dataBuffer.setElem(rasterOffset+xx, argb);
int alpha = (argb >>> 24);
transparency = updateTransparency(alpha, transparency);
}
offset += scansize;
rasterOffset += rasterScanline;
}
return transparency;
}
示例7: convertIndexColorModelToSRGB
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* Converts pixels from an index color model to the target image.
*
* @param x the X coordinate of the source pixel rectangle
* @param y the Y coordinate of the source pixel rectangle
* @param w the width of the source pixel rectangle
* @param h the height of the source pixel rectangle
* @param model the color model of the source pixels
* @param pixels the pixel data
* @param offset the offset in the pixel array
* @param scansize the scanline size
* @param transparency the assumed transparency
*
* @return the determined transparency
*/
private int convertIndexColorModelToSRGB(int x, int y, int w, int h,
IndexColorModel model,
byte[] pixels, int offset,
int scansize, int transparency)
{
int mapSize = model.getMapSize();
int[] colorMap = new int[mapSize];
for(int i=0; i < mapSize; i++)
{
colorMap[i] = model.getRGB(i);
}
WritableRaster raster = bImage.getRaster();
SinglePixelPackedSampleModel sampleMode =
(SinglePixelPackedSampleModel) raster.getSampleModel();
DataBuffer dataBuffer = (DataBuffer) raster.getDataBuffer();
int rasterOffset = sampleMode.getOffset(x,y)+dataBuffer.getOffset();
int rasterScanline = sampleMode.getScanlineStride();
for (int yy = 0; yy < h; yy++)
{
int xoffset = offset;
for (int xx = 0; xx < w; xx++)
{
int argb = colorMap[(pixels[xoffset++] & 0xFF)];
dataBuffer.setElem(rasterOffset+xx, argb);
int alpha = (argb >>> 24);
transparency = updateTransparency(alpha, transparency);
}
offset += scansize;
rasterOffset += rasterScanline;
}
return transparency;
}
示例8: IntegerInterleavedRaster
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* 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(false);
}
示例9: calculateScanlineStrideSPPSM
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* Calculates scanline stride in bytes
* @param sppsm - sample model
* @param r - raster
* @return scanline stride in bytes
*/
private static int calculateScanlineStrideSPPSM(SinglePixelPackedSampleModel sppsm, Raster r) {
if (sppsm.getScanlineStride() != sppsm.getWidth()) {
int dataTypeSize = DataBuffer.getDataTypeSize(r.getDataBuffer().getDataType()) / 8;
return sppsm.getScanlineStride()*dataTypeSize;
}
return -1;
}
示例10: extractDirectRGBAInt
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
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;
}
示例11: hasTransparentPixels
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* 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;
}
示例12: IntegerComponentRaster
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* 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();
}
示例13: IntegerComponentRaster
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* 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();
}
示例14: BufferedImageGraphics
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
public BufferedImageGraphics(BufferedImage bi)
{
this.image = bi;
imageWidth = bi.getWidth();
imageHeight = bi.getHeight();
if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel))
hasFastCM = false;
else if(bi.getColorModel().equals(CairoSurface.cairoCM_opaque))
{
hasFastCM = true;
hasAlpha = false;
}
else if(bi.getColorModel().equals(CairoSurface.cairoColorModel)
|| bi.getColorModel().equals(CairoSurface.cairoCM_pre))
{
hasFastCM = true;
hasAlpha = true;
}
else
hasFastCM = false;
// Cache surfaces.
if( bufferedImages.get( bi ) != null )
surface = bufferedImages.get( bi );
else
{
surface = new CairoSurface( imageWidth, imageHeight );
bufferedImages.put(bi, surface);
}
cairo_t = surface.newCairoContext();
// Get pixels out of buffered image and set in cairo surface
Raster raster = bi.getRaster();
int[] pixels;
if (hasFastCM)
{
SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
int minX = image.getRaster().getSampleModelTranslateX();
int minY = image.getRaster().getSampleModelTranslateY();
// Pull pixels directly out of data buffer
pixels = ((DataBufferInt)raster.getDataBuffer()).getData();
// Discard pixels that fall outside of the image's bounds
// (ie, this image is actually a subimage of a different image)
if (!(sm.getScanlineStride() == imageWidth && minX == 0 && minY == 0))
{
int[] pixels2 = new int[imageWidth * imageHeight];
int scanline = sm.getScanlineStride();
for (int i = 0; i < imageHeight; i++)
System.arraycopy(pixels, (i - minY) * scanline - minX, pixels2,
i * imageWidth, imageWidth);
pixels = pixels2;
}
// Fill the alpha channel as opaque if image does not have alpha
if( !hasAlpha )
for(int i = 0; i < pixels.length; i++)
pixels[i] &= 0xFFFFFFFF;
}
else
{
pixels = CairoGraphics2D.findSimpleIntegerArray(image.getColorModel(),
image.getData());
if (pixels != null)
System.arraycopy(pixels, 0, surface.getData(),
0, pixels.length);
}
setup( cairo_t );
setClip(0, 0, imageWidth, imageHeight);
}
示例15: updateBufferedImage
import java.awt.image.SinglePixelPackedSampleModel; //導入方法依賴的package包/類
/**
* Update a rectangle of the bufferedImage. This can be improved upon a lot.
*/
private void updateBufferedImage(int x, int y, int width, int height)
{
Rectangle bounds = new Rectangle(x, y, width, height);
bounds = getTransformedBounds(bounds, transform).getBounds();
x = bounds.x;
y = bounds.y;
width = bounds.width;
height = bounds.height;
int[] pixels = surface.getData();
if( x > imageWidth || y > imageHeight )
return;
// Deal with negative width/height.
if (height < 0)
{
y += height;
height = -height;
}
if (width < 0)
{
x += width;
width = -width;
}
// Clip edges.
if( x < 0 )
x = 0;
if( y < 0 )
y = 0;
if( x + width > imageWidth )
width = imageWidth - x;
if( y + height > imageHeight )
height = imageHeight - y;
if(!hasFastCM)
{
image.setRGB(x, y, width, height, pixels,
x + y * imageWidth, imageWidth);
// The setRGB method assumes (or should assume) that pixels are NOT
// alpha-premultiplied, but Cairo stores data with premultiplication
// (thus the pixels returned in getPixels are premultiplied).
// This is ignored for consistency, however, since in
// CairoGrahpics2D.drawImage we also use non-premultiplied data
}
else
{
int[] db = ((DataBufferInt)image.getRaster().getDataBuffer()).
getData();
// This should not fail, as we check the image sample model when we
// set the hasFastCM flag
SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel() ;
int minX = image.getRaster().getSampleModelTranslateX();
int minY = image.getRaster().getSampleModelTranslateY();
if (sm.getScanlineStride() == imageWidth && minX == 0)
{
System.arraycopy(pixels, y * imageWidth,
db, (y - minY) * imageWidth,
height * imageWidth);
}
else
{
int scanline = sm.getScanlineStride();
for (int i = y; i < (height + y); i++)
System.arraycopy(pixels, i * imageWidth + x, db,
(i - minY) * scanline + x - minX, width);
}
}
}