下面列出了java.awt.image.SampleModel#getDataType() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Returns true if the data read was originally signed in the specified
* component, false if not. This method always returns false since PPM
* data is always unsigned.
*
* @param c The index of the component, from 0 to N-1.
*
* @return always false, since PPM data is always unsigned.
* */
public boolean isOrigSigned(int c) {
if (isBinary) return true;
// Check component index
SampleModel sm = null;
if (inputIsRaster)
sm = raster.getSampleModel();
else
sm = src.getSampleModel();
if (sm.getDataType() == DataBuffer.TYPE_USHORT ||
sm.getDataType() == DataBuffer.TYPE_BYTE)
return false;
return true;
}
/**
* Returns the most efficient FormatTag that is compatible with
* the destination raster and all source rasters.
*
* @param srcs the source <code>Raster</code>; may be <code>null</code>.
* @param dst the destination <code>Raster</code>.
*/
public static int findCompatibleTag(Raster src) {
SampleModel dstSM = src.getSampleModel();
int dstDT = dstSM.getDataType();
int defaultDataType = dstSM.getDataType();
boolean allComponentSampleModel =
dstSM instanceof ComponentSampleModel;
boolean allBinary = ImageUtil.isBinary(dstSM);
if(allBinary) {
// The copy flag is not set until the mediaLibImage is
// created as knowing this information requires too much
// processing to determine here.
return DataBuffer.TYPE_BYTE | BINARY;
}
if (!allComponentSampleModel) {
if ((defaultDataType == DataBuffer.TYPE_BYTE) ||
(defaultDataType == DataBuffer.TYPE_USHORT) ||
(defaultDataType == DataBuffer.TYPE_SHORT)) {
defaultDataType = DataBuffer.TYPE_INT;
}
}
int tag = defaultDataType | COPIED;
if (!allComponentSampleModel) {
return tag;
}
if (isPixelSequential(dstSM))
return dstDT | UNCOPIED;
return tag;
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT)
throw new IllegalArgumentException(I18N.getString("J2KImageWriter5"));
if (sm.getNumBands() > 16384)
throw new IllegalArgumentException(I18N.getString("J2KImageWriter6"));
}
/** Checks if an image is binary or not.
@param image image to check
@return true if it is a binary image */
public static boolean isBinary(PlanarImage image) {
SampleModel sm = image.getSampleModel();
ColorModel cm = image.getColorModel();
return (sm instanceof MultiPixelPackedSampleModel) &&
(sm.getDataType() == DataBuffer.TYPE_BYTE) &&
(sm.getNumBands() == 1) &&
(sm.getSampleSize(1) == 1);
}
SampleConverter(SampleModel base, MathTransform1D[] toConverted, MathTransform1D[] toPacked) {
super(DataBuffer.TYPE_FLOAT, base.getWidth(), base.getHeight(), base.getNumBands());
this.base = base;
this.baseDataType = base.getDataType();
this.toConverted = toConverted;
this.toPacked = toPacked;
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private boolean isOriginalSigned(SampleModel sampleModel) {
int type = sampleModel.getDataType();
if (type == DataBuffer.TYPE_BYTE || type == DataBuffer.TYPE_USHORT)
return false;
return true;
}
/**
* Constructs a WarpNearestOpImage.
*
* @param source The source image.
* @param config RenderingHints used in calculations.
* @param layout The destination image layout.
* @param warp An object defining the warp algorithm.
* @param interp An object describing the interpolation method.
* @param roi input ROI object used.
* @param noData NoData Range object used for checking if NoData are present.
*/
public WarpNearestOpImage(
final RenderedImage source,
final Map<?, ?> config,
final ImageLayout layout,
final Warp warp,
final Interpolation interp,
final ROI sourceROI,
final Range noData,
final double[] bkg) {
super(
source,
layout,
config,
false,
null, // extender not needed in
// nearest-neighbor
// interpolation
interp,
warp,
bkg,
sourceROI,
noData);
/*
* If the source has IndexColorModel, override the default setting in OpImage. The dest shall
* have exactly the same SampleModel and ColorModel as the source. Note, in this case, the
* source should have an integral data type.
*/
final ColorModel srcColorModel = source.getColorModel();
if (srcColorModel instanceof IndexColorModel) {
sampleModel = source.getSampleModel().createCompatibleSampleModel(tileWidth, tileHeight);
colorModel = srcColorModel;
}
/*
* Selection of a destinationNoData value for each datatype
*/
final SampleModel sm = source.getSampleModel();
// Source image data Type
final int srcDataType = sm.getDataType();
// Creation of a lookuptable containing the values to use for no data
if ((srcDataType == DataBuffer.TYPE_BYTE) && hasNoData) {
final int numBands = getNumBands();
byteLookupTable = new byte[numBands][256];
for (int b = 0; b < numBands; b++) {
for (int i = 0; i < byteLookupTable[0].length; i++) {
final byte value = (byte) i;
if (noDataRange.contains(value)) {
byteLookupTable[b][i] = (byte) backgroundValues[b];
} else {
byteLookupTable[b][i] = value;
}
}
}
}
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
static public int[] getDTypeFromImage(final SampleModel sm, boolean keepBitWidth) {
int dbtype = sm.getDataType();
final int bits = sm.getSampleSize(0);
if (dbtype == DataBuffer.TYPE_INT) {
if (bits <= 8) {
dbtype = DataBuffer.TYPE_BYTE;
} else if (bits <= 16) {
dbtype = DataBuffer.TYPE_SHORT;
}
}
if (dbtype == DataBuffer.TYPE_USHORT) {
if (bits < 8) {
dbtype = DataBuffer.TYPE_BYTE;
} else if (bits < 16) {
dbtype = DataBuffer.TYPE_SHORT;
}
}
if (dbtype == DataBuffer.TYPE_SHORT) {
if (bits <= 8) {
dbtype = DataBuffer.TYPE_BYTE;
}
}
int dtype = -1;
switch (dbtype) {
case DataBuffer.TYPE_BYTE:
dtype = keepBitWidth ? Dataset.INT8 : Dataset.INT16;
break;
case DataBuffer.TYPE_SHORT:
dtype = Dataset.INT16;
break;
case DataBuffer.TYPE_USHORT:
dtype = keepBitWidth ? Dataset.INT16 : Dataset.INT32;
break;
case DataBuffer.TYPE_INT:
dtype = Dataset.INT32;
break;
case DataBuffer.TYPE_DOUBLE:
dtype = Dataset.FLOAT64;
break;
case DataBuffer.TYPE_FLOAT:
dtype = Dataset.FLOAT32;
break;
}
return new int[] {dtype, dbtype == DataBuffer.TYPE_USHORT && !keepBitWidth ? 1 : 0};
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}
private void checkSampleModel(SampleModel sm) {
int type = sm.getDataType();
if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT
|| sm.getNumBands() != 1 || sm.getSampleSize(0) != 1)
throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2"));
}