Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default method NativeImg.getAccessType() #369

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() );
}
}
Loading