public static float[] generateHeightMap(final Image ardorImage, final float min, final float max) {
if (max <= min) {
throw new IllegalArgumentException("max must be greater than min");
}
final ImageDataFormat format = ardorImage.getDataFormat();
if (format != ImageDataFormat.RGB && format != ImageDataFormat.RGBA && format != ImageDataFormat.Luminance) {
throw new IllegalArgumentException("Unhandled format (must be Luminance, RGB or RGBA): " + format);
}
if (ardorImage.getWidth() != ardorImage.getHeight() || !MathUtils.isPowerOfTwo(ardorImage.getWidth())) {
throw new IllegalArgumentException("Only pow2, square images are supported.");
}
final int size = ardorImage.getWidth(), comps = format.getComponents();
// initialize the height data attributes
final float[] heightData = new float[ardorImage.getWidth() * ardorImage.getHeight()];
final byte[] data = new byte[heightData.length * comps];
ardorImage.getData(0).get(data);