java.awt.image.DataBufferDouble Java Examples

The following examples show how to use java.awt.image.DataBufferDouble. 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: GraphicsUtils.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public static Object getData(final DataBuffer db) {
	if (db instanceof DataBufferByte) {
		return ((DataBufferByte) db).getData();
	} else if (db instanceof DataBufferUShort) {
		return ((DataBufferUShort) db).getData();
	} else if (db instanceof DataBufferShort) {
		return ((DataBufferShort) db).getData();
	} else if (db instanceof DataBufferInt) {
		return ((DataBufferInt) db).getData();
	} else if (db instanceof DataBufferFloat) {
		return ((DataBufferFloat) db).getData();
	} else if (db instanceof DataBufferDouble) {
		return ((DataBufferDouble) db).getData();
	} else {
		throw new RuntimeException("Not found DataBuffer class !");
	}
}
 
Example #2
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Extracts pixel data as arrays of doubles, one per channel. */
public static double[][] getDoubles(final WritableRaster r, final int x,
	final int y, final int w, final int h)
{
	if (canUseBankDataDirectly(r, DataBuffer.TYPE_DOUBLE,
		DataBufferDouble.class) && x == 0 && y == 0 && w == r.getWidth() && h == r
			.getHeight())
	{
		return ((DataBufferDouble) r.getDataBuffer()).getBankData();
	}
	// NB: an order of magnitude faster than the naive makeType solution
	final int c = r.getNumBands();
	final double[][] samples = new double[c][w * h];
	for (int i = 0; i < c; i++)
		r.getSamples(x, y, w, h, i, samples[i]);
	return samples;
}
 
Example #3
Source File: ObjectUtils.java    From WorldPainter with GNU General Public License v3.0 6 votes vote down vote up
public static DataBuffer clone(DataBuffer dataBuffer) {
    if (dataBuffer instanceof DataBufferByte) {
        return clone((DataBufferByte) dataBuffer);
    } else if (dataBuffer instanceof DataBufferDouble) {
        return clone((DataBufferDouble) dataBuffer);
    } else if (dataBuffer instanceof DataBufferFloat) {
        return clone((DataBufferFloat) dataBuffer);
    } else if (dataBuffer instanceof DataBufferInt) {
        return clone((DataBufferInt) dataBuffer);
    } else if (dataBuffer instanceof DataBufferShort) {
        return clone((DataBufferShort) dataBuffer);
    } else if (dataBuffer instanceof DataBufferUShort) {
        return clone((DataBufferUShort) dataBuffer);
    } else {
        throw new UnsupportedOperationException("Don't know how to clone " + dataBuffer.getClass().getName());
    }
}
 
Example #4
Source File: GraphicsUtils.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
public static double[] getDataDouble(final DataBuffer db) {
	return ((DataBufferDouble) db).getData();
}
 
Example #5
Source File: DataBufferPersistenceUtils.java    From geowave with Apache License 2.0 4 votes vote down vote up
public static byte[] getDataBufferBinary(final DataBuffer dataBuffer) {
  final DataBufferProtos.DataBuffer.Builder bldr = DataBufferProtos.DataBuffer.newBuilder();
  bldr.setType(dataBuffer.getDataType());
  bldr.addAllOffsets(Ints.asList(dataBuffer.getOffsets()));
  bldr.setSize(dataBuffer.getSize());
  switch (dataBuffer.getDataType()) {
    case DataBuffer.TYPE_BYTE:
      final ByteDataBuffer.Builder byteBldr = ByteDataBuffer.newBuilder();
      final byte[][] byteBank = ((DataBufferByte) dataBuffer).getBankData();
      final Iterable<ByteString> byteIt = () -> new Iterator<ByteString>() {
        private int index = 0;

        @Override
        public boolean hasNext() {
          return byteBank.length > index;
        }

        @Override
        public ByteString next() {
          if (!hasNext()) {
            throw new NoSuchElementException();
          }
          return ByteString.copyFrom(byteBank[index++]);
        }
      };
      byteBldr.addAllBanks(byteIt);
      bldr.setByteDb(byteBldr.build());
      break;
    case DataBuffer.TYPE_SHORT:
      setBuilder(shortToInt(((DataBufferShort) dataBuffer).getBankData()), bldr);
      break;
    case DataBuffer.TYPE_USHORT:
      setBuilder(shortToInt(((DataBufferUShort) dataBuffer).getBankData()), bldr);
      break;
    case DataBuffer.TYPE_INT:
      setBuilder(((DataBufferInt) dataBuffer).getBankData(), bldr);
      break;
    case DataBuffer.TYPE_FLOAT:
      final FloatDataBuffer.Builder fltBldr = FloatDataBuffer.newBuilder();
      final float[][] fltBank = ((DataBufferFloat) dataBuffer).getBankData();
      final Iterable<FloatArray> floatIt = () -> new Iterator<FloatArray>() {
        private int index = 0;

        @Override
        public boolean hasNext() {
          return fltBank.length > index;
        }

        @Override
        public FloatArray next() {
          return FloatArray.newBuilder().addAllSamples(Floats.asList(fltBank[index++])).build();
        }
      };
      fltBldr.addAllBanks(floatIt);
      bldr.setFlt(fltBldr);
      break;
    case DataBuffer.TYPE_DOUBLE:
      final DoubleDataBuffer.Builder dblBldr = DoubleDataBuffer.newBuilder();
      final double[][] dblBank = ((DataBufferDouble) dataBuffer).getBankData();
      final Iterable<DoubleArray> dblIt = () -> new Iterator<DoubleArray>() {
        private int index = 0;

        @Override
        public boolean hasNext() {
          return dblBank.length > index;
        }

        @Override
        public DoubleArray next() {
          return DoubleArray.newBuilder().addAllSamples(Doubles.asList(dblBank[index++])).build();
        }
      };
      dblBldr.addAllBanks(dblIt);
      bldr.setDbl(dblBldr);
      break;
    default:
      throw new RuntimeException(
          "Unsupported DataBuffer type for serialization " + dataBuffer.getDataType());
  }
  return bldr.build().toByteArray();
}
 
Example #6
Source File: DataBufferPersistenceUtils.java    From geowave with Apache License 2.0 4 votes vote down vote up
public static DataBuffer getDataBuffer(final byte[] binary)
    throws IOException, ClassNotFoundException {
  // // Read serialized form from the stream.
  final DataBufferProtos.DataBuffer buffer = DataBufferProtos.DataBuffer.parseFrom(binary);

  final int[] offsets = ArrayUtils.toPrimitive(buffer.getOffsetsList().toArray(new Integer[] {}));
  // Restore the transient DataBuffer.
  switch (buffer.getType()) {
    case DataBuffer.TYPE_BYTE:
      return new DataBufferByte(
          listToByte(buffer.getByteDb().getBanksList()),
          buffer.getSize(),
          offsets);
    case DataBuffer.TYPE_SHORT:
      return new DataBufferShort(
          intToShort(listToInt(buffer.getSint().getBanksList())),
          buffer.getSize(),
          offsets);
    case DataBuffer.TYPE_USHORT:
      return new DataBufferUShort(
          intToShort(listToInt(buffer.getSint().getBanksList())),
          buffer.getSize(),
          offsets);
    case DataBuffer.TYPE_INT:
      return new DataBufferInt(
          listToInt(buffer.getSint().getBanksList()),
          buffer.getSize(),
          offsets);
    case DataBuffer.TYPE_FLOAT:
      return new DataBufferFloat(
          listToFloat(buffer.getFlt().getBanksList()),
          buffer.getSize(),
          offsets);
    case DataBuffer.TYPE_DOUBLE:
      return new DataBufferDouble(
          listToDouble(buffer.getDbl().getBanksList()),
          buffer.getSize(),
          offsets);
    default:
      throw new RuntimeException(
          "Unsupported data buffer type for deserialization" + buffer.getType());
  }
}
 
Example #7
Source File: ObjectUtils.java    From WorldPainter with GNU General Public License v3.0 4 votes vote down vote up
public static DataBufferDouble clone(DataBufferDouble dataBuffer) {
    return new DataBufferDouble(clone(dataBuffer.getBankData()), dataBuffer.getSize(), dataBuffer.getOffsets());
}
 
Example #8
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Creates an image from the given double data.
 *
 * @param data Array containing image data.
 * @param w Width of image plane.
 * @param h Height of image plane.
 * @param c Number of channels.
 * @param interleaved If set, the channels are assumed to be interleaved;
 *          otherwise they are assumed to be sequential. For example, for RGB
 *          data, the pattern "RGBRGBRGB..." is interleaved, while
 *          "RRR...GGG...BBB..." is sequential.
 */
public static BufferedImage makeImage(final double[] data, final int w,
	final int h, final int c, final boolean interleaved)
{
	if (c == 1) return makeImage(data, w, h);
	final int dataType = DataBuffer.TYPE_DOUBLE;
	final DataBuffer buffer = new DataBufferDouble(data, c * w * h);
	return constructImage(c, dataType, w, h, interleaved, false, buffer);
}
 
Example #9
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Creates an image from the given double-precision floating point data.
 *
 * @param data Array containing image data. It is assumed that each channel
 *          corresponds to one element of the array. For example, for RGB
 *          data, data[0] is R, data[1] is G, and data[2] is B.
 * @param w Width of image plane.
 * @param h Height of image plane.
 */
public static BufferedImage makeImage(final double[][] data, final int w,
	final int h)
{
	final int dataType = DataBuffer.TYPE_DOUBLE;
	final DataBuffer buffer = new DataBufferDouble(data, data[0].length);
	return constructImage(data.length, dataType, w, h, false, true, buffer);
}