本文整理汇总了Java中java.awt.image.ComponentSampleModel.getPixelStride方法的典型用法代码示例。如果您正苦于以下问题:Java ComponentSampleModel.getPixelStride方法的具体用法?Java ComponentSampleModel.getPixelStride怎么用?Java ComponentSampleModel.getPixelStride使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.ComponentSampleModel
的用法示例。
在下文中一共展示了ComponentSampleModel.getPixelStride方法的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: isInterleaved
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/*** Analyzes a ComponentSampleModel to determine if it can function
* as a PixelInterleavedSampleModel. In order to do so, it must use
* only bank 0 of its DataBuffer, and the data offsets must span a range
* of less than pixelStride.
*
* <p> These properties are trivially true for a 1-banded SampleModel.
*/
private boolean isInterleaved(ComponentSampleModel sm) {
// Analyze ComponentSampleModel to determine if it has the
// properties of a PixelInterleavedSampleModel
int numBands = sampleModel.getNumBands();
if (numBands == 1) {
return true;
}
// Determine banks used
int[] bankIndices = sm.getBankIndices();
for (int i = 0; i < numBands; i++) {
if (bankIndices[i] != 0) {
return false;
}
}
// Determine range of band offsets
int[] bandOffsets = sm.getBandOffsets();
int minOffset = bandOffsets[0];
int maxOffset = minOffset;
for (int i = 1; i < numBands; i++) {
int offset = bandOffsets[i];
if (offset < minOffset) {
minOffset = offset;
}
if (offset > maxOffset) {
maxOffset = offset;
}
}
if (maxOffset - minOffset >= sm.getPixelStride()) {
return false;
}
return true;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例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: imageIsContiguous
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
* Returns whether the image has contiguous data across rows.
*/
public static final boolean imageIsContiguous(RenderedImage image) {
SampleModel sm;
if(image instanceof BufferedImage) {
WritableRaster ras = ((BufferedImage)image).getRaster();
sm = ras.getSampleModel();
} else {
sm = image.getSampleModel();
}
if (sm instanceof ComponentSampleModel) {
// Ensure image rows samples are stored contiguously
// in a single bank.
ComponentSampleModel csm = (ComponentSampleModel)sm;
if (csm.getPixelStride() != csm.getNumBands()) {
return false;
}
int[] bandOffsets = csm.getBandOffsets();
for (int i = 0; i < bandOffsets.length; i++) {
if (bandOffsets[i] != i) {
return false;
}
}
int[] bankIndices = csm.getBankIndices();
for (int i = 0; i < bandOffsets.length; i++) {
if (bankIndices[i] != 0) {
return false;
}
}
return true;
}
// Otherwise true if and only if it's a bilevel image with
// a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
// pixel stride.
return ImageUtil.isBinary(sm);
}
示例13: 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;
}
示例14: RasterFormatTag
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
* Constructs a RasterFormatTag given a sampleModel and a
* formatTagID. Generally, this constructor is called by
* RasterAccessor.findCompatibleTags(RenderedImage[] srcs,
* RenderedImage dst) and it takes care of setting the values
* correctly. In special cases, OpImages need to construct
* a RasterFormatTag without creating a RenderedImage. In this
* case a RasterFormatTag can be created using a formatTagID
* returned from
* RasterAccessor.findCompatibleTag(SampleModel[] srcs, SampleModel dst)
* and a sampleModel that was either passed in to the
* findCompatibleTag() call or one that was created using
* createCompatibleSampleModel() on one of the passed in
* SampleModels. Attempting to use arbitrary SampleModels
* with arbitrary formatTagIDs has undefined results.
*
* param sampleModel A <code>SampleModel</code> for the RasterFormagTag
* param formatTagID An <code>int</code> to indicate format tag id
*
*/
public RasterFormatTag(SampleModel sampleModel, int formatTagID) {
this.formatTagID = formatTagID;
if ((formatTagID & COPY_MASK) == UNCOPIED) {
ComponentSampleModel csm =
(ComponentSampleModel)sampleModel;
this.bankIndices = csm.getBankIndices();
this.numBands = csm.getNumDataElements();
this.bandOffsets = csm.getBandOffsets();
this.pixelStride = csm.getPixelStride();
if (pixelStride != bandOffsets.length) {
isPixelSequential = false;
} else {
isPixelSequential = true;
for (int i = 0; i < bandOffsets.length; i++) {
if (bandOffsets[i] >= pixelStride ||
bankIndices[i] != bankIndices[0]) {
isPixelSequential = false;
}
for (int j = i+1; j < bandOffsets.length; j++) {
if (bandOffsets[i] == bandOffsets[j]) {
isPixelSequential = false;
}
}
if (!isPixelSequential) break;
}
}
} else if ((formatTagID & COPY_MASK) == COPIED) {
numBands = sampleModel.getNumBands();
bandOffsets = new int[numBands];
pixelStride = numBands;
bankIndices = new int[numBands];
for (int i = 0; i < numBands; i++) {
bandOffsets[i] = i;
bankIndices[i] = 0;
}
isPixelSequential = true;
}
}
示例15: imageIsContiguous
import java.awt.image.ComponentSampleModel; //导入方法依赖的package包/类
/**
* Returns whether the image has contiguous data across rows.
*/
public static final boolean imageIsContiguous(RenderedImage image) {
SampleModel sm;
if(image instanceof BufferedImage) {
WritableRaster ras = ((BufferedImage)image).getRaster();
sm = ras.getSampleModel();
} else {
sm = image.getSampleModel();
}
if (sm instanceof ComponentSampleModel) {
// Ensure image rows samples are stored contiguously
// in a single bank.
ComponentSampleModel csm = (ComponentSampleModel)sm;
if (csm.getPixelStride() != csm.getNumBands()) {
return false;
}
int[] bandOffsets = csm.getBandOffsets();
for (int i = 0; i < bandOffsets.length; i++) {
if (bandOffsets[i] != i) {
return false;
}
}
int[] bankIndices = csm.getBankIndices();
for (int i = 0; i < bandOffsets.length; i++) {
if (bankIndices[i] != 0) {
return false;
}
}
return true;
}
// Otherwise true if and only if it's a bilevel image with
// a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit
// pixel stride.
return ImageUtil.isBinary(sm);
}