@Override public void extend(WritableRaster raster, PlanarImage sourceImage) { int dataType = raster.getSampleModel().getDataType(); switch (dataType) { case DataBuffer.TYPE_BYTE: extendAsByte(raster, sourceImage); break; case DataBuffer.TYPE_SHORT: extendAsShort(raster, sourceImage); break; case DataBuffer.TYPE_USHORT: extendAsUShort(raster, sourceImage); break; case DataBuffer.TYPE_INT: extendAsInt(raster, sourceImage); break; case DataBuffer.TYPE_FLOAT: extendAsFloat(raster, sourceImage); break; case DataBuffer.TYPE_DOUBLE: extendAsDouble(raster, sourceImage); break; default: throw new UnsupportedOperationException("Unsupported data type"); } }
private void extendAsByte(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); int minValue = NumberOperations.intValue(minValueN); int maxValue = NumberOperations.intValue(maxValueN); int range = maxValue - minValue; for (int b = 0; b < raster.getNumBands(); b++) { for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { int value = (int) clamp(rand.nextInt(range) + minValue, 0, 255); raster.setSample(x, y, b, value); } } } } }
private void extendAsInt(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); int minValue = NumberOperations.intValue(minValueN); int maxValue = NumberOperations.intValue(maxValueN); int range = maxValue - minValue; for (int b = 0; b < raster.getNumBands(); b++) { for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { int value = (int) clamp(rand.nextInt(range) + minValue, Integer.MIN_VALUE, Integer.MAX_VALUE); raster.setSample(x, y, b, value); } } } } }
private void extendAsUShort(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); int minValue = NumberOperations.intValue(minValueN); int maxValue = NumberOperations.intValue(maxValueN); int range = maxValue - minValue; for (int b = 0; b < raster.getNumBands(); b++) { for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { int value = (int) clamp(rand.nextInt(range) + minValue, 0, 0xffff); raster.setSample(x, y, b, value); } } } } }
private void extendAsShort(WritableRaster raster, PlanarImage sourceImage) { Rectangle bounds = sourceImage.getBounds(); int minValue = NumberOperations.intValue(minValueN); int maxValue = NumberOperations.intValue(maxValueN); int range = maxValue - minValue; for (int b = 0; b < raster.getNumBands(); b++) { for (int y = raster.getMinY(), ny = 0; ny < raster.getHeight(); y++, ny++) { for (int x = raster.getMinX(), nx = 0; nx < raster.getWidth(); x++, nx++) { if (!bounds.contains(x, y)) { int value = (int) clamp(rand.nextInt(range) + minValue, Short.MIN_VALUE, Short.MAX_VALUE); raster.setSample(x, y, b, value); } } } } }