Class ConvertTo<T>

Object
ConvertTo<T>
Type Parameters:
T - destination buffer-type
Direct Known Subclasses:
ToFloat, ToUnsignedByte, ToUnsignedInt, ToUnsignedShort

public abstract class ConvertTo<T> extends Object
Converts a subset of raw voxel bytes in a buffer to a possibly a buffer with different data-type.
  • Field Details

    • extent

      protected Extent extent
      The size of the source and destination buffers.
    • sourceIncrement

      protected int sourceIncrement
      The number of elements (bytes) to increment by, when iterating through the source buffer.
    • sourceSize

      protected int sourceSize
      The total number of elements (always bytes) in the source buffer.
    • destinationSize

      protected int destinationSize
      The total number of elements (whatever the destination type is) in the destination buffer.
  • Constructor Details

    • ConvertTo

      public ConvertTo(Function<VoxelsUntyped,Voxels<T>> functionCast, IntFunction<T> allocateBuffer, Function<T,VoxelBuffer<T>> wrapBuffer)
      Creates a new ConvertTo instance.
      Parameters:
      functionCast - How to convert a VoxelsUntyped to the specific destination-type.
      allocateBuffer - A function that creates a new buffer of type T of a given size.
      wrapBuffer - A function to wrap a buffer of type T into a VoxelBuffer.
  • Method Details

    • copyAllChannels

      public void copyAllChannels(Dimensions dimensions, ByteBuffer source, DestinationChannelForIndex destination, int z, ImageFileEncoding sourceImageEncoding, OrientationChange orientationCorrection) throws IOException
      Copies the channels in the source buffer into a particular DestinationChannelForIndex.
      Parameters:
      dimensions - scene-dimension.
      source - the buffer we copy all channels from.
      destination - finds an appropriate destination channel for a particular relative-channel-index.
      z - the current slice we are working on.
      sourceImageEncoding - how voxels are stored in the source-image.
      orientationCorrection - any correction of orientation to be applied as bytes are converted.
      Throws:
      IOException - if any error occurs when copying channels.
    • setupBefore

      protected void setupBefore(Dimensions dimensions, ImageFileEncoding sourceImageEncoding) throws IOException
      Parameters:
      dimensions - the final dimensions of the image.
      sourceImageEncoding - how voxels are stored in the source-image.
      Throws:
      IOException - if a particular combination of parameters is unsupported.
    • convertSliceOfSingleChannel

      protected VoxelBuffer<T> convertSliceOfSingleChannel(ByteBuffer source, int channelIndexRelative, OrientationChange orientationCorrection) throws IOException
      Converts a slice of single-channel into a newly created VoxelBuffer.
      Parameters:
      source - source buffer containing the bytes we copy from.
      channelIndexRelative - 0 if the buffer is non interleaved, or otherwise the index of the channel among the interleaved channels.
      orientationCorrection - any correction of orientation to be applied as bytes are converted.
      Returns:
      the converted buffer.
      Throws:
      IOException - when operation is unsupported, given particular parameterization.
    • convert

      protected T convert(ByteBuffer source, int channelIndexRelative, OrientationChange orientationCorrection, boolean littleEndian) throws IOException
      Converts a slice of single-channel into a newly created buffer of type T T.
      Parameters:
      source - source buffer containing the bytes we copy from.
      channelIndexRelative - 0 if the buffer is non interleaved, or otherwise the index of the channel among the interleaved channels.
      orientationCorrection - any correction of orientation to be applied as bytes are converted.
      littleEndian - true iff the bytes in source are in little-endian order.
      Returns:
      the converted buffer.
      Throws:
      IOException - when operation is unsupported, given particular parameterization.
    • copyKeepOrientation

      protected abstract void copyKeepOrientation(ByteBuffer source, boolean littleEndian, int channelIndexRelative, T destination) throws IOException
      Copy the bytes, without changing orientation.

      This is kept separate to copyChangeOrientation(java.nio.ByteBuffer, boolean, int, T, org.anchoranalysis.image.core.dimensions.OrientationChange) as it can be done slightly more efficiently.

      Parameters:
      source - the buffer we copy all channels from.
      littleEndian - true iff the bytes in source are in little-endian order.
      channelIndexRelative - 0 if the buffer is non interleaved, or otherwise the index of the channel among the interleaved channels.
      destination - finds an appropriate destination channel for a particular relative-channel-index.
      Throws:
      IOException - when the operation fails due to read or write IO problems.
    • copyChangeOrientation

      protected abstract void copyChangeOrientation(ByteBuffer source, boolean littleEndian, int channelIndexRelative, T destination, OrientationChange orientationCorrection) throws IOException
      Copy the bytes, changing orientation.
      Parameters:
      source - the buffer we copy all channels from.
      littleEndian - true iff the bytes in source are in little-endian order.
      channelIndexRelative - 0 if the buffer is non interleaved, or otherwise the index of the channel among the interleaved channels.
      destination - finds an appropriate destination channel for a particular relative-channel-index.
      orientationCorrection - any correction of orientation to be applied as bytes are converted.
      Throws:
      IOException - when the operation fails due to read or write IO problems.
    • supportsMultipleChannelsPerSourceBuffer

      protected abstract boolean supportsMultipleChannelsPerSourceBuffer()
      Whether the source buffer can encode more than one channel?
      Returns:
      true if this possible (either with interleaving or with RGB-encoded voxels), false if a buffer will always describe one channel only.
    • bytesPerVoxel

      protected abstract int bytesPerVoxel()
      The number bytes to describe each source-voxel.
      Returns:
      the number of bytes.