Java Code Examples for java.awt.image.SampleModel#getDataType()

The following examples show how to use java.awt.image.SampleModel#getDataType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenderedImageSrc.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: MediaLibAccessor.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
/**
 *  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;
}
 
Example 3
Source File: ConvertedGridCoverage.java    From sis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: J2KImageWriter.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
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"));
}
 
Example 5
Source File: Util.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
/** 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);
  }
 
Example 6
Source File: WBMPImageWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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"));
}
 
Example 7
Source File: WBMPImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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"));
}
 
Example 8
Source File: WBMPImageWriter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
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"));
}
 
Example 9
Source File: AWTImageUtils.java    From dawnsci with Eclipse Public License 1.0 4 votes vote down vote up
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};
}
 
Example 10
Source File: WBMPImageWriter.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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"));
}
 
Example 11
Source File: WBMPImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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"));
}
 
Example 12
Source File: WBMPImageWriter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
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"));
}
 
Example 13
Source File: WBMPImageWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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"));
}
 
Example 14
Source File: WBMPImageWriter.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
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"));
}
 
Example 15
Source File: WBMPImageWriter.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
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"));
}
 
Example 16
Source File: WBMPImageWriter.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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"));
}
 
Example 17
Source File: WBMPImageWriter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
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"));
}
 
Example 18
Source File: WarpNearestOpImage.java    From geowave with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
        }
      }
    }
  }
}
 
Example 19
Source File: J2KMetadata.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 4 votes vote down vote up
private boolean isOriginalSigned(SampleModel sampleModel) {
    int type = sampleModel.getDataType();
    if (type == DataBuffer.TYPE_BYTE || type == DataBuffer.TYPE_USHORT)
        return false;
    return true;
}
 
Example 20
Source File: WBMPImageWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
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"));
}