Skip to content

Commit 86dd19f

Browse files
committed
Add default method NativeImg.getAccessType() and re-enable BufferAccess handling in PrimitiveBlocks
1 parent cc07d99 commit 86dd19f

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/main/java/net/imglib2/blocks/ViewPrimitiveBlocks.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public ViewPrimitiveBlocks( final ViewProperties< T, R > props )
6868
{
6969
this.props = props;
7070
final PrimitiveType primitiveType = props.getRootType().getNativeTypeFactory().getPrimitiveType();
71-
final MemCopy memCopy = MemCopy.forPrimitiveType( primitiveType, /*props.getRootAccessType() instanceof BufferAccess*/ false, false );
71+
final MemCopy memCopy = MemCopy.forPrimitiveType( primitiveType, props.getRoot().getAccessType() instanceof BufferAccess, false );
7272
final Extension extension = props.getExtension() != null ? props.getExtension() : Extension.border();
7373
final Object oob = extractOobValue( props.getRootType(), extension );
7474
final Ranges findRanges = Ranges.forExtension( extension );

src/main/java/net/imglib2/blocks/ViewProperties.java

-17
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import net.imglib2.RandomAccessible;
3838
import net.imglib2.converter.Converter;
3939
import net.imglib2.img.NativeImg;
40-
import net.imglib2.img.basictypeaccess.array.ArrayDataAccess;
4140
import net.imglib2.transform.integer.MixedTransform;
4241
import net.imglib2.type.NativeType;
4342
import net.imglib2.view.TransformBuilder;
@@ -146,22 +145,6 @@ public R getRootType()
146145
return rootType;
147146
}
148147

149-
public ArrayDataAccess< ? > getRootAccessType()
150-
{
151-
return ( ArrayDataAccess< ? > ) getDataAccess( root );
152-
}
153-
154-
/*
155-
* TODO: There should be a better way to get straight to a DataAccess instance.
156-
* This is similar to the getType() problem.
157-
* For now, this will work.
158-
* Make an issue about getDataAccess() ...
159-
*/
160-
private static < A > A getDataAccess( NativeImg< ?, A > img )
161-
{
162-
return img.update( img.cursor() );
163-
}
164-
165148
public Extension getExtension()
166149
{
167150
return extension;

src/main/java/net/imglib2/img/NativeImg.java

+14
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,18 @@ public interface NativeImg< T extends Type< T >, A > extends Img< T >
5757
void setLinkedType( T type );
5858

5959
T createLinkedType();
60+
61+
/**
62+
* This is used for checking whether a {@link NativeImg} is backed by
63+
* primitive arrays or {@code ByteBuffer}.
64+
* <p>
65+
* This may return the actual data backing this {@code NativeImg}, or just
66+
* some {@code A} of the same type. <em>Do not store a reference to the
67+
* returned object to avoid memory leaks!</em>
68+
*
69+
* @return an instance of the access type {@code A} backing this image.
70+
*/
71+
default A getAccessType() {
72+
return update( cursor() );
73+
}
6074
}

0 commit comments

Comments
 (0)