本文整理汇总了Java中java.awt.image.MultiPixelPackedSampleModel.getScanlineStride方法的典型用法代码示例。如果您正苦于以下问题:Java MultiPixelPackedSampleModel.getScanlineStride方法的具体用法?Java MultiPixelPackedSampleModel.getScanlineStride怎么用?Java MultiPixelPackedSampleModel.getScanlineStride使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.MultiPixelPackedSampleModel
的用法示例。
在下文中一共展示了MultiPixelPackedSampleModel.getScanlineStride方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DirectRasterAccessor
import java.awt.image.MultiPixelPackedSampleModel; //导入方法依赖的package包/类
/** Constructs a DirectRasterAccessor object */
public DirectRasterAccessor(Raster raster, ColorModel cm) {
DataBuffer db = raster.getDataBuffer();
offsetX = raster.getMinX()-raster.getSampleModelTranslateX();
offsetY = raster.getMinY()-raster.getSampleModelTranslateY();
if (!(db instanceof DataBufferByte)) {
throw new RuntimeException("DataBuffer of Raster not of correct type " +
"(expected DataBufferByte, got " +
db.getClass().getName() + ")");
}
DataBufferByte dbb = (DataBufferByte) db;
SampleModel sm = raster.getSampleModel();
if (!(sm instanceof MultiPixelPackedSampleModel)) {
throw new RuntimeException("SampleModel of Raster not of correct type " +
"(expected MultiPixelPackedSampleModel, got " +
sm.getClass().getName() + ")");
}
MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel) sm;
data = dbb.getData();
scanlineStride = mppsm.getScanlineStride();
if (cm.getRGB(0) == Color.white.getRGB()) {
white = 0;
black = 1;
} else {
white = 1;
black = 0;
}
}
示例2: byteLoop
import java.awt.image.MultiPixelPackedSampleModel; //导入方法依赖的package包/类
/** Bytewise OR of the black pixels */
private void byteLoop(Raster src0, Raster src1,
WritableRaster dst, Rectangle dstRect) {
int w = dst.getWidth();
int h = dst.getHeight();
DataBufferByte src0db = (DataBufferByte) src0.getDataBuffer();
DataBufferByte src1db = (DataBufferByte) src1.getDataBuffer();
DataBufferByte dstdb = (DataBufferByte) dst.getDataBuffer();
byte src0Data[] = src0db.getData();
byte src1Data[] = src1db.getData();
byte dstData[] = dstdb.getData();
MultiPixelPackedSampleModel src0sm =
(MultiPixelPackedSampleModel) src0.getSampleModel();
MultiPixelPackedSampleModel src1sm =
(MultiPixelPackedSampleModel) src1.getSampleModel();
MultiPixelPackedSampleModel dstsm =
(MultiPixelPackedSampleModel) dst.getSampleModel();
int src0ScanlineStride = src0sm.getScanlineStride();
int src1ScanlineStride = src1sm.getScanlineStride();
int dstScanlineStride = dstsm.getScanlineStride();
int white = getWhite();
if (white == 0) {
for (int offset = 0; offset < h*dstScanlineStride; offset++) {
dstData[offset] = (byte) (src0Data[offset] | src1Data[offset]);
}
} else {
for (int offset = 0; offset < h*dstScanlineStride; offset++) {
dstData[offset] = (byte) (src0Data[offset] & src1Data[offset]);
}
}
}
示例3: BytePackedRaster
import java.awt.image.MultiPixelPackedSampleModel; //导入方法依赖的package包/类
/**
* Constructs a BytePackedRaster with the given SampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferByte and
* SampleModel must be of type MultiPixelPackedSampleModel.
* 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.
*
* @exception RasterFormatException if the parameters do not conform
* to requirements of this Raster type.
*/
public BytePackedRaster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point origin,
BytePackedRaster parent){
super(sampleModel,dataBuffer,aRegion,origin, parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (!(dataBuffer instanceof DataBufferByte)) {
throw new RasterFormatException("BytePackedRasters must have" +
"byte DataBuffers");
}
DataBufferByte dbb = (DataBufferByte)dataBuffer;
this.data = stealData(dbb, 0);
if (dbb.getNumBanks() != 1) {
throw new
RasterFormatException("DataBuffer for BytePackedRasters"+
" must only have 1 bank.");
}
int dbOffset = dbb.getOffset();
if (sampleModel instanceof MultiPixelPackedSampleModel) {
MultiPixelPackedSampleModel mppsm =
(MultiPixelPackedSampleModel)sampleModel;
this.type = IntegerComponentRaster.TYPE_BYTE_BINARY_SAMPLES;
pixelBitStride = mppsm.getPixelBitStride();
if (pixelBitStride != 1 &&
pixelBitStride != 2 &&
pixelBitStride != 4) {
throw new RasterFormatException
("BytePackedRasters must have a bit depth of 1, 2, or 4");
}
scanlineStride = mppsm.getScanlineStride();
dataBitOffset = mppsm.getDataBitOffset() + dbOffset*8;
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
dataBitOffset += xOffset*pixelBitStride + yOffset*scanlineStride*8;
bitMask = (1 << pixelBitStride) -1;
shiftOffset = 8 - pixelBitStride;
} else {
throw new RasterFormatException("BytePackedRasters must have"+
"MultiPixelPackedSampleModel");
}
verify(false);
}
示例4: BytePackedRaster
import java.awt.image.MultiPixelPackedSampleModel; //导入方法依赖的package包/类
/**
* Constructs a BytePackedRaster with the given SampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferByte and
* SampleModel must be of type MultiPixelPackedSampleModel.
* 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.
*
* @exception RasterFormatException if the parameters do not conform
* to requirements of this Raster type.
*/
public BytePackedRaster(SampleModel sampleModel,
DataBufferByte dataBuffer,
Rectangle aRegion,
Point origin,
BytePackedRaster parent)
{
super(sampleModel,dataBuffer,aRegion,origin, parent);
this.maxX = minX + width;
this.maxY = minY + height;
this.data = stealData(dataBuffer, 0);
if (dataBuffer.getNumBanks() != 1) {
throw new
RasterFormatException("DataBuffer for BytePackedRasters"+
" must only have 1 bank.");
}
int dbOffset = dataBuffer.getOffset();
if (sampleModel instanceof MultiPixelPackedSampleModel) {
MultiPixelPackedSampleModel mppsm =
(MultiPixelPackedSampleModel)sampleModel;
this.type = IntegerComponentRaster.TYPE_BYTE_BINARY_SAMPLES;
pixelBitStride = mppsm.getPixelBitStride();
if (pixelBitStride != 1 &&
pixelBitStride != 2 &&
pixelBitStride != 4) {
throw new RasterFormatException
("BytePackedRasters must have a bit depth of 1, 2, or 4");
}
scanlineStride = mppsm.getScanlineStride();
dataBitOffset = mppsm.getDataBitOffset() + dbOffset*8;
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
dataBitOffset += xOffset*pixelBitStride + yOffset*scanlineStride*8;
bitMask = (1 << pixelBitStride) -1;
shiftOffset = 8 - pixelBitStride;
} else {
throw new RasterFormatException("BytePackedRasters must have"+
"MultiPixelPackedSampleModel");
}
verify(false);
}
示例5: areEqualSampleModels
import java.awt.image.MultiPixelPackedSampleModel; //导入方法依赖的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;
}
示例6: paintMonochromeBitmap
import java.awt.image.MultiPixelPackedSampleModel; //导入方法依赖的package包/类
/**
* Paint a bitmap at the current cursor position. The bitmap must be a monochrome
* (1-bit) bitmap image.
* @param img the bitmap image (must be 1-bit b/w)
* @param resolution the resolution of the image (must be a PCL resolution)
* @throws IOException In case of an I/O error
*/
public void paintMonochromeBitmap(RenderedImage img, int resolution) throws IOException {
if (!isValidPCLResolution(resolution)) {
throw new IllegalArgumentException("Invalid PCL resolution: " + resolution);
}
boolean monochrome = isMonochromeImage(img);
if (!monochrome) {
throw new IllegalArgumentException("img must be a monochrome image");
}
setRasterGraphicsResolution(resolution);
writeCommand("*r0f" + img.getHeight() + "t" + img.getWidth() + "s1A");
Raster raster = img.getData();
Encoder encoder = new Encoder(img);
// Transfer graphics data
int imgw = img.getWidth();
IndexColorModel cm = (IndexColorModel)img.getColorModel();
if (cm.getTransferType() == DataBuffer.TYPE_BYTE) {
DataBufferByte dataBuffer = (DataBufferByte)raster.getDataBuffer();
MultiPixelPackedSampleModel packedSampleModel = new MultiPixelPackedSampleModel(
DataBuffer.TYPE_BYTE, img.getWidth(), img.getHeight(), 1);
if (img.getSampleModel().equals(packedSampleModel)
&& dataBuffer.getNumBanks() == 1) {
//Optimized packed encoding
byte[] buf = dataBuffer.getData();
int scanlineStride = packedSampleModel.getScanlineStride();
int idx = 0;
int c0 = toGray(cm.getRGB(0));
int c1 = toGray(cm.getRGB(1));
boolean zeroIsWhite = c0 > c1;
for (int y = 0, maxy = img.getHeight(); y < maxy; y++) {
for (int x = 0, maxx = scanlineStride; x < maxx; x++) {
if (zeroIsWhite) {
encoder.add8Bits(buf[idx]);
} else {
encoder.add8Bits((byte)~buf[idx]);
}
idx++;
}
encoder.endLine();
}
} else {
//Optimized non-packed encoding
for (int y = 0, maxy = img.getHeight(); y < maxy; y++) {
byte[] line = (byte[])raster.getDataElements(0, y, imgw, 1, null);
for (int x = 0, maxx = imgw; x < maxx; x++) {
encoder.addBit(line[x] == 0);
}
encoder.endLine();
}
}
} else {
//Safe but slow fallback
for (int y = 0, maxy = img.getHeight(); y < maxy; y++) {
for (int x = 0, maxx = imgw; x < maxx; x++) {
int sample = raster.getSample(x, y, 0);
encoder.addBit(sample == 0);
}
encoder.endLine();
}
}
// End raster graphics
writeCommand("*rB");
}
示例7: byteLoop_v
import java.awt.image.MultiPixelPackedSampleModel; //导入方法依赖的package包/类
/** Does vertical RLSA */
private void byteLoop_v(Raster src, WritableRaster dst) {
int minX = getMinX();
int maxX = getMaxX();
int minY = getMinY();
int maxY = getMaxY();
DataBufferByte srcdb = (DataBufferByte) src.getDataBuffer();
DataBufferByte dstdb = (DataBufferByte) dst.getDataBuffer();
byte srcData[] = srcdb.getData();
byte dstData[] = dstdb.getData();
MultiPixelPackedSampleModel srcsm = (MultiPixelPackedSampleModel) src.getSampleModel();
MultiPixelPackedSampleModel dstsm = (MultiPixelPackedSampleModel) dst.getSampleModel();
int srcScanlineStride = srcsm.getScanlineStride();
int dstScanlineStride = dstsm.getScanlineStride();
int srcScanlineOffset = minY*srcScanlineStride;
int dstScanlineOffset = 0;
int[] column = new int[maxY];
int white = getWhite();
for (int x = minX, dstx = 0; x < maxX; x++, dstx++) {
int srcxOffset = x / 8;
int srcxBit = x % 8;
int dstxOffset = dstx / 8;
int dstxBit = dstx % 8;
int srcLineOffset = srcScanlineOffset;
int dstLineOffset = dstScanlineOffset;
int lasty = minY-(threshold+2);
if (white == 0) {
for (int y = minY; y < maxY; y++) {
if ((srcData[srcLineOffset+srcxOffset] & bitAccess[srcxBit]) != 0) {
column[y] = 1;
if (y < lasty+threshold+2) {
for (int i = lasty; i<y; i++) {
column[i] = 1;
}
}
lasty = y;
} else {
column[y] = 0;
}
srcLineOffset += srcScanlineStride;
}
} else {
for (int y = minY; y < maxY; y++) {
if ((srcData[srcLineOffset+srcxOffset] & bitAccess[srcxBit]) == 0) {
column[y] = 0;
if (y < lasty+threshold+2) {
for (int i = lasty; i<y; i++) {
column[i] = 0;
}
}
lasty = y;
} else {
column[y] = 1;
}
srcLineOffset += srcScanlineStride;
}
}
// Copy resulting column onto image
for (int srcy = minY, lineOffset = 0; srcy < maxY; srcy++, lineOffset += dstScanlineStride) {
if (column[srcy] == 1) {
dstData[lineOffset+dstxOffset] |= bitAccess[dstxBit];
} else {
dstData[lineOffset+dstxOffset] &= ~bitAccess[dstxBit];
}
}
}
}