diff --git a/src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java b/src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java index e305f4119..1a42af41f 100644 --- a/src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java +++ b/src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java @@ -68,7 +68,7 @@ public ViewPrimitiveBlocks( final ViewProperties< T, R > props ) { this.props = props; final PrimitiveType primitiveType = props.getRootType().getNativeTypeFactory().getPrimitiveType(); - final MemCopy memCopy = MemCopy.forPrimitiveType( primitiveType, /*props.getRootAccessType() instanceof BufferAccess*/ false, false ); + final MemCopy memCopy = MemCopy.forPrimitiveType( primitiveType, props.getRoot().getAccessType() instanceof BufferAccess, false ); final Extension extension = props.getExtension() != null ? props.getExtension() : Extension.border(); final Object oob = extractOobValue( props.getRootType(), extension ); final Ranges findRanges = Ranges.forExtension( extension ); diff --git a/src/main/java/net/imglib2/blocks/ViewProperties.java b/src/main/java/net/imglib2/blocks/ViewProperties.java index b44941b11..eeb97a9f5 100644 --- a/src/main/java/net/imglib2/blocks/ViewProperties.java +++ b/src/main/java/net/imglib2/blocks/ViewProperties.java @@ -37,7 +37,6 @@ import net.imglib2.RandomAccessible; import net.imglib2.converter.Converter; import net.imglib2.img.NativeImg; -import net.imglib2.img.basictypeaccess.array.ArrayDataAccess; import net.imglib2.transform.integer.MixedTransform; import net.imglib2.type.NativeType; import net.imglib2.view.TransformBuilder; @@ -146,22 +145,6 @@ public R getRootType() return rootType; } - public ArrayDataAccess< ? > getRootAccessType() - { - return ( ArrayDataAccess< ? > ) getDataAccess( root ); - } - - /* - * TODO: There should be a better way to get straight to a DataAccess instance. - * This is similar to the getType() problem. - * For now, this will work. - * Make an issue about getDataAccess() ... - */ - private static < A > A getDataAccess( NativeImg< ?, A > img ) - { - return img.update( img.cursor() ); - } - public Extension getExtension() { return extension; diff --git a/src/main/java/net/imglib2/img/NativeImg.java b/src/main/java/net/imglib2/img/NativeImg.java index 83af3cd30..5fe13d32e 100644 --- a/src/main/java/net/imglib2/img/NativeImg.java +++ b/src/main/java/net/imglib2/img/NativeImg.java @@ -57,4 +57,18 @@ public interface NativeImg< T extends Type< T >, A > extends Img< T > void setLinkedType( T type ); T createLinkedType(); + + /** + * This is used for checking whether a {@link NativeImg} is backed by + * primitive arrays or {@code ByteBuffer}. + *

+ * This may return the actual data backing this {@code NativeImg}, or just + * some {@code A} of the same type. Do not store a reference to the + * returned object to avoid memory leaks! + * + * @return an instance of the access type {@code A} backing this image. + */ + default A getAccessType() { + return update( cursor() ); + } }