本文整理汇总了Java中java.awt.image.ComponentSampleModel.getScanlineStride方法的典型用法代码示例。如果您正苦于以下问题:Java ComponentSampleModel.getScanlineStride方法的具体用法?Java ComponentSampleModel.getScanlineStride怎么用?Java ComponentSampleModel.getScanlineStride使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.ComponentSampleModel
的用法示例。
在下文中一共展示了ComponentSampleModel.getScanlineStride方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBandSize
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
public static long getBandSize(SampleModel sm) {
int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());
if (sm instanceof ComponentSampleModel) {
ComponentSampleModel csm = (ComponentSampleModel)sm;
int pixelStride = csm.getPixelStride();
int scanlineStride = csm.getScanlineStride();
long size = Math.min(pixelStride, scanlineStride);
if (pixelStride > 0)
size += pixelStride * (sm.getWidth() - 1);
if (scanlineStride > 0)
size += scanlineStride * (sm.getHeight() - 1);
return size * ((elementSize + 7) / 8);
} else
return getTileSize(sm);
}
示例2: RectIterCSM
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
public RectIterCSM(RenderedImage im, Rectangle bounds) {
super(im, bounds);
ComponentSampleModel csm = (ComponentSampleModel)sampleModel;
this.scanlineStride = csm.getScanlineStride();
this.pixelStride = csm.getPixelStride();
this.bankIndices = csm.getBankIndices();
int[] bo = csm.getBandOffsets();
this.bandOffsets = new int[numBands + 1];
for (int i = 0; i < numBands; i++) {
bandOffsets[i] = bo[i];
}
bandOffsets[numBands] = 0;
this.DBOffsets = new int[numBands];
this.offset = (y - sampleModelTranslateY)*scanlineStride +
(x - sampleModelTranslateX)*pixelStride;
this.bandOffset = bandOffsets[0];
}
示例3: getBufferSizeCSM
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private static long getBufferSizeCSM(ComponentSampleModel csm) {
int[] bandOffsets = csm.getBandOffsets();
int maxBandOff=bandOffsets[0];
for (int i=1; i<bandOffsets.length; i++)
maxBandOff = Math.max(maxBandOff,bandOffsets[i]);
long size = 0;
if (maxBandOff >= 0)
size += maxBandOff+1;
int pixelStride = csm.getPixelStride();
if (pixelStride > 0)
size += pixelStride * (csm.getWidth()-1);
int scanlineStride = csm.getScanlineStride();
if (scanlineStride > 0)
size += scanlineStride*(csm.getHeight()-1);
return size;
}
示例4: createBufferedImageForDisplay
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
* Efficiently create a TYPE_3BYTE_BGR for display if possible. This is
* typically much faster than to create and display than an ARGB buffered
* image. If the input image is not in RGB format, then the ARGB form will
* be returned instead.
*
* @param img
* the image to convert
* @param ret
* the image to draw into if possible. Can be null.
* @return the converted image. Might not be the same as the ret parameter.
*/
public static BufferedImage createBufferedImageForDisplay(final MBFImage img, BufferedImage ret) {
if (img.colourSpace != ColourSpace.RGB)
return ImageUtilities.createBufferedImage(img, ret);
final int width = img.getWidth();
final int height = img.getHeight();
if (ret == null || ret.getWidth() != width || ret.getHeight() != height
|| ret.getType() != BufferedImage.TYPE_3BYTE_BGR)
ret = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
final WritableRaster raster = ret.getRaster();
final float[][] r = img.getBand(0).pixels;
final float[][] g = img.getBand(1).pixels;
final float[][] b = img.getBand(2).pixels;
final ComponentSampleModel sm = (ComponentSampleModel) raster.getSampleModel();
final DataBufferByte db = (DataBufferByte) raster.getDataBuffer();
final int scanlineStride = sm.getScanlineStride();
final int pixelStride = sm.getPixelStride();
final byte[] data = db.getData();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
data[y * scanlineStride + x * pixelStride + 2] = (byte)
Math.max(0, Math.min(255, (int) (r[y][x] * 255)));
data[y * scanlineStride + x * pixelStride + 1] = (byte)
Math.max(0, Math.min(255, (int) (g[y][x] * 255)));
data[y * scanlineStride + x * pixelStride] = (byte)
Math.max(0, Math.min(255, (int) (b[y][x] * 255)));
}
}
return ret;
}
示例5: createBufferedImage
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
* Efficiently create a TYPE_BYTE_GRAY for display. This is typically much
* faster than to create and display than an ARGB buffered image.
*
* @param img
* the image to convert
* @param ret
* BufferedImage to draw into if possible. Can be null.
* @return the converted image
*/
public static BufferedImage createBufferedImage(final FImage img, BufferedImage ret) {
final int width = img.getWidth();
final int height = img.getHeight();
if (ret == null || ret.getWidth() != width || ret.getHeight() != height
|| ret.getType() != BufferedImage.TYPE_BYTE_GRAY)
ret = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
final WritableRaster raster = ret.getRaster();
final float[][] p = img.pixels;
final ComponentSampleModel sm = (ComponentSampleModel) raster.getSampleModel();
final DataBufferByte db = (DataBufferByte) raster.getDataBuffer();
final int scanlineStride = sm.getScanlineStride();
final int pixelStride = sm.getPixelStride();
final byte[] data = db.getData();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
data[y * scanlineStride + x * pixelStride] = (byte) (Math.max(0, Math.min(255, (int) (p[y][x] * 255))));
}
}
return ret;
}
示例6: calculateScanlineStrideCSM
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
* Calculates scanline stride in bytes
* @param csm - component sample model
* @param r - raster
* @return scanline stride in bytes
*/
private static int calculateScanlineStrideCSM(ComponentSampleModel csm, Raster r) {
if (csm.getScanlineStride() != csm.getPixelStride()*csm.getWidth()) {
int dataTypeSize = DataBuffer.getDataTypeSize(r.getDataBuffer().getDataType()) / 8;
return csm.getScanlineStride()*dataTypeSize;
}
return -1;
}
示例7: extractComponentRGBInt
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private static byte[] extractComponentRGBInt( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferInt aDataBuffer ) {
byte[] out = new byte[ aWidth * aHeight * 3 ];
int[] bankIndices = aSampleModel.getBankIndices();
int[] bankOffsets = aSampleModel.getBandOffsets();
int rScanIx = bankOffsets[ 0 ];
int gScanIx = bankOffsets[ 1 ];
int bScanIx = bankOffsets[ 2 ];
int pixelStride = aSampleModel.getPixelStride();
int scanlineStride = aSampleModel.getScanlineStride();
for ( int b = 0, y = 0; y < aHeight; y++ ) {
int rPixIx = rScanIx;
int gPixIx = gScanIx;
int bPixIx = bScanIx;
for ( int x = 0; x < aWidth; x++, b += 3 ) {
out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx);
rPixIx += pixelStride;
out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx);
gPixIx += pixelStride;
out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx);
bPixIx += pixelStride;
}
rScanIx += scanlineStride;
gScanIx += scanlineStride;
bScanIx += scanlineStride;
}
return out;
}
示例8: extractComponentRGBByte
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private static byte[] extractComponentRGBByte( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferByte aDataBuffer ) {
byte[] out = new byte[ aWidth * aHeight * 3 ];
int[] bankIndices = aSampleModel.getBankIndices();
int[] bankOffsets = aSampleModel.getBandOffsets();
int rScanIx = bankOffsets[ 0 ];
int gScanIx = bankOffsets[ 1 ];
int bScanIx = bankOffsets[ 2 ];
int pixelStride = aSampleModel.getPixelStride();
int scanlineStride = aSampleModel.getScanlineStride();
for ( int b = 0, y = 0; y < aHeight; y++ ) {
int rPixIx = rScanIx;
int gPixIx = gScanIx;
int bPixIx = bScanIx;
for ( int x = 0; x < aWidth; x++, b += 3 ) {
out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx);
rPixIx += pixelStride;
out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx);
gPixIx += pixelStride;
out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx);
bPixIx += pixelStride;
}
rScanIx += scanlineStride;
gScanIx += scanlineStride;
bScanIx += scanlineStride;
}
return out;
}
示例9: extractComponentRGBAInt
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private static byte[] extractComponentRGBAInt( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferInt aDataBuffer ) {
byte[] out = new byte[ aWidth * aHeight * 4 ];
int[] bankIndices = aSampleModel.getBankIndices();
int[] bankOffsets = aSampleModel.getBandOffsets();
int rScanIx = bankOffsets[ 0 ];
int gScanIx = bankOffsets[ 1 ];
int bScanIx = bankOffsets[ 2 ];
int aScanIx = bankOffsets[ 3 ];
int pixelStride = aSampleModel.getPixelStride();
int scanlineStride = aSampleModel.getScanlineStride();
for ( int b = 0, y = 0; y < aHeight; y++ ) {
int rPixIx = rScanIx;
int gPixIx = gScanIx;
int bPixIx = bScanIx;
int aPixIx = aScanIx;
for ( int x = 0; x < aWidth; x++, b += 4 ) {
out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx);
rPixIx += pixelStride;
out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx);
gPixIx += pixelStride;
out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx);
bPixIx += pixelStride;
out[b + 3] = (byte) aDataBuffer.getElem(bankIndices[3], aPixIx);
aPixIx += pixelStride;
}
rScanIx += scanlineStride;
gScanIx += scanlineStride;
bScanIx += scanlineStride;
aScanIx += scanlineStride;
}
return out;
}
示例10: extractComponentRGBAByte
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
private static byte[] extractComponentRGBAByte( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferByte aDataBuffer ) {
byte[] out = new byte[ aWidth * aHeight * 4 ];
int[] bankIndices = aSampleModel.getBankIndices();
int[] bankOffsets = aSampleModel.getBandOffsets();
int rScanIx = bankOffsets[ 0 ];
int gScanIx = bankOffsets[ 1 ];
int bScanIx = bankOffsets[ 2 ];
int aScanIx = bankOffsets[ 3 ];
int pixelStride = aSampleModel.getPixelStride();
int scanlineStride = aSampleModel.getScanlineStride();
for ( int b = 0, y = 0; y < aHeight; y++ ) {
int rPixIx = rScanIx;
int gPixIx = gScanIx;
int bPixIx = bScanIx;
int aPixIx = aScanIx;
for ( int x = 0; x < aWidth; x++, b += 4 ) {
out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx);
rPixIx += pixelStride;
out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx);
gPixIx += pixelStride;
out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx);
bPixIx += pixelStride;
out[b + 3] = (byte) aDataBuffer.getElem(bankIndices[3], aPixIx);
aPixIx += pixelStride;
}
rScanIx += scanlineStride;
gScanIx += scanlineStride;
bScanIx += scanlineStride;
aScanIx += scanlineStride;
}
return out;
}
示例11: canUseBankDataDirectly
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
* Whether we can return the data buffer's bank data without performing any
* copy or conversion operations.
*/
private static boolean canUseBankDataDirectly(final WritableRaster r,
final int transferType, final Class<? extends DataBuffer> dataBufferClass)
{
final int tt = r.getTransferType();
if (tt != transferType) return false;
final DataBuffer buffer = r.getDataBuffer();
if (!dataBufferClass.isInstance(buffer)) return false;
final SampleModel model = r.getSampleModel();
if (!(model instanceof ComponentSampleModel)) return false;
final ComponentSampleModel csm = (ComponentSampleModel) model;
final int pixelStride = csm.getPixelStride();
if (pixelStride != 1) return false;
final int w = r.getWidth();
final int scanlineStride = csm.getScanlineStride();
if (scanlineStride != w) return false;
final int c = r.getNumBands();
final int[] bandOffsets = csm.getBandOffsets();
if (bandOffsets.length != c) return false;
for (int i = 0; i < bandOffsets.length; i++) {
if (bandOffsets[i] != 0) return false;
}
for (int i = 0; i < bandOffsets.length; i++) {
if (bandOffsets[i] != i) return false;
}
return true;
}
示例12: getScanlineStride
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
* Gets the scanline stride for the given raster
*
* @param raster
* @return
*/
int getScanlineStride(Raster raster) {
if (raster.getSampleModel() instanceof ComponentSampleModel) {
ComponentSampleModel csm = ((ComponentSampleModel) raster.getSampleModel());
return csm.getScanlineStride();
} else {
return raster.getDataBuffer().getSize() / raster.getHeight();
}
}
示例13: filter
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
public WritableRaster filter(Raster src, WritableRaster dest)
{
if (dest == null)
dest = createCompatibleDestRaster(src);
DataBuffer srcDB = src.getDataBuffer();
DataBuffer destDB = dest.getDataBuffer();
ComponentSampleModel srcSM = (ComponentSampleModel) src.getSampleModel();
ComponentSampleModel destSM = (ComponentSampleModel) dest.getSampleModel();
// Calculate offset to data in the underlying arrays:
int srcScanlineStride = srcSM.getScanlineStride();
int destScanlineStride = destSM.getScanlineStride();
int srcX = src.getMinX() - src.getSampleModelTranslateX();
int srcY = src.getMinY() - src.getSampleModelTranslateY();
int destX = dest.getMinX() - dest.getSampleModelTranslateX();
int destY = dest.getMinY() - dest.getSampleModelTranslateY();
int numBands = srcSM.getNumBands();
/* We can't use getOffset(x, y) from the sample model since we
don't want the band offset added in. */
int srcOffset =
numBands*srcX + srcScanlineStride*srcY + // from sample model
srcDB.getOffset(); // from data buffer
int destOffset =
numBands*destX + destScanlineStride*destY + // from sample model
destDB.getOffset(); // from data buffer
// Determine how much, and how many times to blit.
int rowSize = src.getWidth()*numBands;
int h = src.getHeight();
if ((rowSize == srcScanlineStride) &&
(rowSize == destScanlineStride))
{
// collapse scan line blits to one large blit.
rowSize *= h;
h = 1;
}
// Do blitting
Object srcArray = Buffers.getData(srcDB);
Object destArray = Buffers.getData(destDB);
for (int yd = 0; yd<h; yd++)
{
System.arraycopy(srcArray, srcOffset,
destArray, destOffset,
rowSize);
srcOffset += srcScanlineStride;
destOffset += destScanlineStride;
}
return dest;
}
示例14: filter
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
public WritableRaster filter(Raster src, WritableRaster dest)
{
if (dest == null)
dest = createCompatibleDestRaster(src);
DataBuffer srcDB = src.getDataBuffer();
DataBuffer destDB = dest.getDataBuffer();
ComponentSampleModel srcSM = (ComponentSampleModel) src.getSampleModel();
ComponentSampleModel destSM = (ComponentSampleModel) dest.getSampleModel();
// Calculate offset to data in the underlying arrays:
int srcScanlineStride = srcSM.getScanlineStride();
int destScanlineStride = destSM.getScanlineStride();
int srcX = src.getMinX() - src.getSampleModelTranslateX();
int srcY = src.getMinY() - src.getSampleModelTranslateY();
int destX = dest.getMinX() - dest.getSampleModelTranslateX();
int destY = dest.getMinY() - dest.getSampleModelTranslateY();
int numBands = srcSM.getNumBands();
/* We can't use getOffset(x, y) from the sample model since we
don't want the band offset added in. */
int srcOffset =
numBands*srcX + srcScanlineStride*srcY + // from sample model
srcDB.getOffset(); // from data buffer
int destOffset =
numBands*destX + destScanlineStride*destY + // from sample model
destDB.getOffset(); // from data buffer
// Determine how much, and how many times to blit.
int rowSize = src.getWidth()*numBands;
int h = src.getHeight();
if ((rowSize == srcScanlineStride) &&
(rowSize == destScanlineStride))
{
// collapse scan line blits to one large blit.
rowSize *= h;
h = 1;
}
// Do blitting
Object srcArray = Buffers.getData(srcDB);
Object destArray = Buffers.getData(destDB);
for (int yd = 0; yd<h; yd++)
{
System.arraycopy(srcArray, srcOffset,
destArray, destOffset,
rowSize);
srcOffset += srcScanlineStride;
destOffset += destScanlineStride;
}
return dest;
}
示例15: areEqualSampleModels
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
* Determines whether two SampleModels are "equal", i.e.,
* assignment-compatible. This signifies that the two SampleModels
* are either the very same object or are two different objects
* with identical characteristics.
*/
public boolean areEqualSampleModels(SampleModel sm1, SampleModel sm2) {
if(sm1 == sm2) {
// Identical objects.
return true;
} else if(sm1.getClass() == sm2.getClass() &&
sm1.getDataType() == sm2.getDataType() &&
sm1.getTransferType() == sm2.getTransferType() &&
sm1.getWidth() == sm2.getWidth() &&
sm1.getHeight() == sm2.getHeight()) {
// At this point all common attributes are equivalent. Next test
// those specific to the known direct subclasses of SampleModel.
// Subclasses which are not known will always return false.
if(sm1 instanceof ComponentSampleModel) {
ComponentSampleModel csm1 = (ComponentSampleModel)sm1;
ComponentSampleModel csm2 = (ComponentSampleModel)sm2;
return csm1.getPixelStride() == csm2.getPixelStride() &&
csm1.getScanlineStride() == csm2.getScanlineStride() &&
Arrays.equals(csm1.getBankIndices(),
csm2.getBankIndices()) &&
Arrays.equals(csm1.getBandOffsets(),
csm2.getBandOffsets());
} else if(sm1 instanceof MultiPixelPackedSampleModel) {
MultiPixelPackedSampleModel mpp1 =
(MultiPixelPackedSampleModel)sm1;
MultiPixelPackedSampleModel mpp2 =
(MultiPixelPackedSampleModel)sm2;
return mpp1.getPixelBitStride() == mpp2.getPixelBitStride() &&
mpp1.getScanlineStride() == mpp2.getScanlineStride() &&
mpp1.getDataBitOffset() == mpp2.getDataBitOffset();
} else if(sm1 instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel spp1 =
(SinglePixelPackedSampleModel)sm1;
SinglePixelPackedSampleModel spp2 =
(SinglePixelPackedSampleModel)sm2;
return spp1.getScanlineStride() == spp2.getScanlineStride() &&
Arrays.equals(spp1.getBitMasks(), spp2.getBitMasks());
}
}
return false;
}