Skip to content

Commit

Permalink
Add default method NativeImg.getAccessType() and re-enable BufferAcce…
Browse files Browse the repository at this point in the history
…ss handling in PrimitiveBlocks
  • Loading branch information
tpietzsch committed Sep 23, 2024
1 parent cc07d99 commit 86dd19f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/net/imglib2/blocks/ViewProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/imglib2/img/NativeImg.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
* <p>
* This may return the actual data backing this {@code NativeImg}, or just
* some {@code A} of the same type. <em>Do not store a reference to the
* returned object to avoid memory leaks!</em>
*
* @return an instance of the access type {@code A} backing this image.
*/
default A getAccessType() {
return update( cursor() );
}
}

0 comments on commit 86dd19f

Please sign in to comment.