本文整理汇总了Java中java.awt.image.BandedSampleModel类的典型用法代码示例。如果您正苦于以下问题:Java BandedSampleModel类的具体用法?Java BandedSampleModel怎么用?Java BandedSampleModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BandedSampleModel类属于java.awt.image包,在下文中一共展示了BandedSampleModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reportInternal
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
public Object reportInternal (Argument args[], Context context)
throws ExtensionException, LogoException {
_reference patchVar = (_reference)((org.nlogo.nvm.Argument)args[0]).getReporter();
World world = context.getAgent().world();
int width = world.worldWidth();
int height = world.worldHeight();
Envelope envelope = GISExtension.getState().getTransformation().getEnvelope(world);
GridDimensions dimensions = new GridDimensions(new Dimension(width, height), envelope);
DataBuffer data = new DataBufferDouble(width * height);
BandedSampleModel sampleModel = new BandedSampleModel(data.getDataType(),width, height, 1);
WritableRaster raster = Raster.createWritableRaster(sampleModel, data, null);
for (int px = world.minPxcor(), ix = 0; px <= world.maxPxcor(); px += 1, ix += 1) {
for (int py = world.minPycor(), iy = raster.getHeight() - 1; py <= world.maxPycor(); py += 1, iy -= 1) {
Patch p = world.fastGetPatchAt(px, py);
Object value = p.getVariable(patchVar.reference.vn());
if (value instanceof Number) {
raster.setSample(ix, iy, 0, ((Number)value).doubleValue());
} else {
raster.setSample(ix, iy, 0, Double.NaN);
}
}
}
return new RasterDataset(dimensions, raster);
}
示例2: readRasterDataset
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
/** */
private static RasterDataset readRasterDataset (BufferedReader in)
throws IOException {
Projection dstProj = GISExtension.getState().getProjection();
Projection srcProj = null;
try {
srcProj = PROJ_FORMAT.parseProjection(in.readLine());
} catch (java.text.ParseException e) {
e.printStackTrace();
}
AsciiGridFileReader asc = new AsciiGridFileReader(in);
GridDimensions dimensions = new GridDimensions(asc.getSize(), asc.getEnvelope());
DataBuffer data = asc.getData();
BandedSampleModel sampleModel = new BandedSampleModel(data.getDataType(),
dimensions.getGridWidth(),
dimensions.getGridHeight(),
1);
WritableRaster raster = Raster.createWritableRaster(sampleModel, data, null);
if ((srcProj != null) &&
(dstProj != null) &&
(!srcProj.equals(dstProj))) {
return new RasterDataset(raster, dimensions, srcProj, dstProj);
} else {
return new RasterDataset(dimensions, raster);
}
}
示例3: createSampleModel
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
private SampleModel createSampleModel() {
if (samples == 1) {
return new PixelInterleavedSampleModel(dataType, width, height, 1,
width, OFFSETS_0);
}
// samples == 3
if (banded) {
return new BandedSampleModel(dataType, width, height, width,
OFFSETS_0_1_2, OFFSETS_0_0_0);
}
if( (!compressed) && pmi.endsWith("422" ) ) {
return new PartialComponentSampleModel(width, height, 2, 1);
}
if( (!compressed) && pmi.endsWith("420") ) {
return new PartialComponentSampleModel(width,height,2,2);
}
return new PixelInterleavedSampleModel(dataType, width, height, 3,
width * 3, OFFSETS_0_1_2);
}
示例4: getBufferedImage
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
@Override
public BufferedImage getBufferedImage(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
try (RgbeInfo info = new RgbeInfo(byteSource)) {
// It is necessary to create our own BufferedImage here as the
// org.apache.commons.imaging.common.IBufferedImageFactory interface does
// not expose this complexity
final DataBuffer buffer = new DataBufferFloat(info.getPixelData(),
info.getWidth() * info.getHeight());
final BufferedImage ret = new BufferedImage(new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false,
Transparency.OPAQUE, buffer.getDataType()),
Raster.createWritableRaster(
new BandedSampleModel(buffer.getDataType(),
info.getWidth(), info.getHeight(), 3),
buffer,
new Point()), false, null);
return ret;
}
}
示例5: IntegerRaster
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
/**
* Constructs IntegerRaster with the given size.
* @param _nrow the number of rows
* @param _ncol the number of columns
*/
public IntegerRaster(int _nrow, int _ncol) {
nrow = _nrow;
ncol = _ncol;
dimension = new Dimension(ncol, nrow);
int size = nrow*ncol;
ComponentColorModel ccm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {8, 8, 8}, false, // hasAlpha
false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
BandedSampleModel csm = new BandedSampleModel(DataBuffer.TYPE_BYTE, ncol, nrow, ncol, new int[] {0, 1, 2}, new int[] {0, 0, 0});
rgbData = new byte[3][size];
DataBuffer databuffer = new DataBufferByte(rgbData, size);
WritableRaster raster = Raster.createWritableRaster(csm, databuffer, new Point(0, 0));
image = new BufferedImage(ccm, raster, false, null);
// col in x direction, row in y direction
xmin = 0;
xmax = ncol;
ymin = nrow;
ymax = 0; // zero is on top
}
示例6: convert
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
@Override
public SampleModel convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
int width = fa.getInt(instance, "width"); // NOI18N
int height = fa.getInt(instance, "height"); // NOI18N
int dataType = fa.getInt(instance, "dataType"); // NOI18N
int scanlineStride = fa.getInt(instance, "scanlineStride"); // NOI18N
int[] bankIndices = fa.getIntArray(instance, "bankIndices", false); // NOI18N
int[] bandOffsets = fa.getIntArray(instance, "bandOffsets", false); // NOI18N
return new BandedSampleModel(dataType, width, height, scanlineStride, bankIndices, bandOffsets);
}
示例7: ByteBandedRaster
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
/**
* Constructs a ByteBandedRaster with the given sampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferShort and
* SampleModel must be of type BandedSampleModel.
* 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 ByteBandedRaster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point origin,
ByteBandedRaster parent) {
super(sampleModel, dataBuffer, aRegion, origin, parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (!(dataBuffer instanceof DataBufferByte)) {
throw new RasterFormatException("ByteBandedRaster must have" +
"byte DataBuffers");
}
DataBufferByte dbb = (DataBufferByte)dataBuffer;
if (sampleModel instanceof BandedSampleModel) {
BandedSampleModel bsm = (BandedSampleModel)sampleModel;
this.scanlineStride = bsm.getScanlineStride();
int bankIndices[] = bsm.getBankIndices();
int bandOffsets[] = bsm.getBandOffsets();
int dOffsets[] = dbb.getOffsets();
dataOffsets = new int[bankIndices.length];
data = new byte[bankIndices.length][];
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
for (int i = 0; i < bankIndices.length; i++) {
data[i] = stealData(dbb, bankIndices[i]);
dataOffsets[i] = dOffsets[bankIndices[i]] +
xOffset + yOffset*scanlineStride + bandOffsets[i];
}
} else {
throw new RasterFormatException("ByteBandedRasters must have"+
"BandedSampleModels");
}
verify();
}
示例8: ShortBandedRaster
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
/**
* Constructs a ShortBandedRaster with the given SampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferUShort and
* SampleModel must be of type BandedSampleModel.
* 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 DataBufferUShort 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 ShortBandedRaster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point origin,
ShortBandedRaster parent) {
super(sampleModel, dataBuffer, aRegion, origin, parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (!(dataBuffer instanceof DataBufferUShort)) {
throw new RasterFormatException("ShortBandedRaster must have " +
"ushort DataBuffers");
}
DataBufferUShort dbus = (DataBufferUShort)dataBuffer;
if (sampleModel instanceof BandedSampleModel) {
BandedSampleModel bsm = (BandedSampleModel)sampleModel;
this.scanlineStride = bsm.getScanlineStride();
int bankIndices[] = bsm.getBankIndices();
int bandOffsets[] = bsm.getBandOffsets();
int dOffsets[] = dbus.getOffsets();
dataOffsets = new int[bankIndices.length];
data = new short[bankIndices.length][];
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
for (int i = 0; i < bankIndices.length; i++) {
data[i] = stealData(dbus, bankIndices[i]);
dataOffsets[i] = dOffsets[bankIndices[i]] +
xOffset + yOffset*scanlineStride + bandOffsets[i];
}
} else {
throw new RasterFormatException("ShortBandedRasters must have "+
"BandedSampleModels");
}
verify();
}
示例9: main
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
public static void main(String[] args) {
Vector<Class<? extends SampleModel>> classes = new Vector<Class<? extends SampleModel>>();
classes.add(ComponentSampleModel.class);
classes.add(MultiPixelPackedSampleModel.class);
classes.add(SinglePixelPackedSampleModel.class);
classes.add(BandedSampleModel.class);
classes.add(PixelInterleavedSampleModel.class);
for (Class<? extends SampleModel> c : classes) {
doTest(c);
}
}
示例10: ByteBandedRaster
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
/**
* Constructs a ByteBandedRaster with the given sampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferShort and
* SampleModel must be of type BandedSampleModel.
* 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 ByteBandedRaster(SampleModel sampleModel,
DataBufferByte dataBuffer,
Rectangle aRegion,
Point origin,
ByteBandedRaster parent)
{
super(sampleModel, dataBuffer, aRegion, origin, parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (sampleModel instanceof BandedSampleModel) {
BandedSampleModel bsm = (BandedSampleModel)sampleModel;
this.scanlineStride = bsm.getScanlineStride();
int bankIndices[] = bsm.getBankIndices();
int bandOffsets[] = bsm.getBandOffsets();
int dOffsets[] = dataBuffer.getOffsets();
dataOffsets = new int[bankIndices.length];
data = new byte[bankIndices.length][];
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
for (int i = 0; i < bankIndices.length; i++) {
data[i] = stealData(dataBuffer, bankIndices[i]);
dataOffsets[i] = dOffsets[bankIndices[i]] +
xOffset + yOffset*scanlineStride + bandOffsets[i];
}
} else {
throw new RasterFormatException("ByteBandedRasters must have"+
"BandedSampleModels");
}
verify();
}
示例11: ShortBandedRaster
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
/**
* Constructs a ShortBandedRaster with the given SampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferUShort and
* SampleModel must be of type BandedSampleModel.
* 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 DataBufferUShort 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 ShortBandedRaster(SampleModel sampleModel,
DataBufferUShort dataBuffer,
Rectangle aRegion,
Point origin,
ShortBandedRaster parent)
{
super(sampleModel, dataBuffer, aRegion, origin, parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (sampleModel instanceof BandedSampleModel) {
BandedSampleModel bsm = (BandedSampleModel)sampleModel;
this.scanlineStride = bsm.getScanlineStride();
int bankIndices[] = bsm.getBankIndices();
int bandOffsets[] = bsm.getBandOffsets();
int dOffsets[] = dataBuffer.getOffsets();
dataOffsets = new int[bankIndices.length];
data = new short[bankIndices.length][];
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
for (int i = 0; i < bankIndices.length; i++) {
data[i] = stealData(dataBuffer, bankIndices[i]);
dataOffsets[i] = dOffsets[bankIndices[i]] +
xOffset + yOffset*scanlineStride + bandOffsets[i];
}
} else {
throw new RasterFormatException("ShortBandedRasters must have "+
"BandedSampleModels");
}
verify();
}
示例12: getRemoteBufferedImage
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
@Override
public BufferedImage getRemoteBufferedImage(){
SampleModel samplemodel = new BandedSampleModel(DataBuffer.TYPE_DOUBLE, getWidth(), getHeight(), hasAlpha() ? 4:3);
DataBufferDouble databuffer = new DataBufferDouble(getData(), numValues());
WritableRaster raster = Raster.createWritableRaster(samplemodel, databuffer, null);
ColorModel colormodel = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
hasAlpha(),
false,
hasAlpha() ? ComponentColorModel.TRANSLUCENT:ComponentColorModel.OPAQUE,
DataBuffer.TYPE_DOUBLE
);
BufferedImage bimg = new BufferedImage(colormodel, raster, false, null);
return bimg;
}
示例13: ByteBandedRaster
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
/**
* Constructs a ByteBandedRaster with the given sampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferShort and
* SampleModel must be of type BandedSampleModel.
* 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 ByteBandedRaster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point origin,
ByteBandedRaster parent) {
super(sampleModel, dataBuffer, aRegion, origin, parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (!(dataBuffer instanceof DataBufferByte)) {
throw new RasterFormatException("ByteBandedRaster must have" +
"byte DataBuffers");
}
DataBufferByte dbb = (DataBufferByte)dataBuffer;
if (sampleModel instanceof BandedSampleModel) {
BandedSampleModel bsm = (BandedSampleModel)sampleModel;
this.scanlineStride = bsm.getScanlineStride();
int bankIndices[] = bsm.getBankIndices();
int bandOffsets[] = bsm.getBandOffsets();
int dOffsets[] = dbb.getOffsets();
dataOffsets = new int[bankIndices.length];
data = new byte[bankIndices.length][];
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
for (int i = 0; i < bankIndices.length; i++) {
data[i] = stealData(dbb, bankIndices[i]);
dataOffsets[i] = dOffsets[bankIndices[i]] +
xOffset + yOffset*scanlineStride + bandOffsets[i];
}
} else {
throw new RasterFormatException("ByteBandedRasters must have"+
"BandedSampleModels");
}
verify(false);
}
示例14: ShortBandedRaster
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
/**
* Constructs a ShortBandedRaster with the given SampleModel,
* DataBuffer, and parent. DataBuffer must be a DataBufferUShort and
* SampleModel must be of type BandedSampleModel.
* 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 DataBufferUShort 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 ShortBandedRaster(SampleModel sampleModel,
DataBuffer dataBuffer,
Rectangle aRegion,
Point origin,
ShortBandedRaster parent) {
super(sampleModel, dataBuffer, aRegion, origin, parent);
this.maxX = minX + width;
this.maxY = minY + height;
if (!(dataBuffer instanceof DataBufferUShort)) {
throw new RasterFormatException("ShortBandedRaster must have " +
"ushort DataBuffers");
}
DataBufferUShort dbus = (DataBufferUShort)dataBuffer;
if (sampleModel instanceof BandedSampleModel) {
BandedSampleModel bsm = (BandedSampleModel)sampleModel;
this.scanlineStride = bsm.getScanlineStride();
int bankIndices[] = bsm.getBankIndices();
int bandOffsets[] = bsm.getBandOffsets();
int dOffsets[] = dbus.getOffsets();
dataOffsets = new int[bankIndices.length];
data = new short[bankIndices.length][];
int xOffset = aRegion.x - origin.x;
int yOffset = aRegion.y - origin.y;
for (int i = 0; i < bankIndices.length; i++) {
data[i] = stealData(dbus, bankIndices[i]);
dataOffsets[i] = dOffsets[bankIndices[i]] +
xOffset + yOffset*scanlineStride + bandOffsets[i];
}
} else {
throw new RasterFormatException("ShortBandedRasters must have "+
"BandedSampleModels");
}
verify(false);
}
示例15: loadAsciiGrid
import java.awt.image.BandedSampleModel; //导入依赖的package包/类
/** */
private static RasterDataset loadAsciiGrid (String ascFilePath,
Projection srcProj,
Projection dstProj) throws ExtensionException, IOException {
AsciiGridFileReader asc = null;
try {
File ascFile = GISExtension.getState().getFile(ascFilePath);
if (ascFile == null) {
throw new ExtensionException("ascii file " + ascFilePath + " not found");
}
asc = new AsciiGridFileReader(new BufferedReader(new InputStreamReader(ascFile.getInputStream())));
GridDimensions dimensions = new GridDimensions(asc.getSize(), asc.getEnvelope());
DataBuffer data = asc.getData();
BandedSampleModel sampleModel = new BandedSampleModel(data.getDataType(),
dimensions.getGridWidth(),
dimensions.getGridHeight(),
1);
WritableRaster raster = Raster.createWritableRaster(sampleModel, data, null);
if ((srcProj != null) &&
(dstProj != null) &&
(!srcProj.equals(dstProj))) {
return new RasterDataset(raster, dimensions, srcProj, dstProj);
} else {
return new RasterDataset(dimensions, raster);
}
} finally {
if (asc != null) {
try { asc.close(); } catch (IOException e) { }
}
}
}