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

first attempts at displaying 8-bits cached images #16

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@
<artifactId>imglib2-ij</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
6 changes: 5 additions & 1 deletion src/main/java/tpietzsch/blocks/ByteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public static void setBytes( final byte src, final long dst, final long csx )
UNSAFE.setMemory( dst, csx, src );
}

public interface Address
public static void copyBytes( final byte[] src, final long dst, final long sox, final long csx) {
UNSAFE.copyMemory( src, BYTE_ARRAY_OFFSET + sox, null, dst, csx );
}

public interface Address
{
long getAddress();
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/tpietzsch/blocks/CopySubArrayImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ public void copysubarray3d( final short[] src, final int sox, final int soy, fin
}
}

public static class ByteToAddress implements CopySubArray< byte[], Address >
{
@Override
public void clearsubarray3d( final Address dst, final int dox, final int doy, final int doz, final int dsx, final int dsy, final int csx, final int csy, final int csz )
{
final ArrayFill fill = ( o, l ) -> ByteUtils.setBytes( ( byte ) 0, dst.getAddress() + o, l );
fillsubarray3dn( fill, dox, doy, doz, dsx, dsy, csx, csy, csz );
}

@Override
public void copysubarray3d( final byte[] src, final int sox, final int soy, final int soz, final int ssx, final int ssy, final Address dst, final int dox, final int doy, final int doz, final int dsx, final int dsy, final int csx, final int csy, final int csz )
{
final ArrayCopy copy = ( so, o, l ) -> ByteUtils.copyBytes( src, dst.getAddress() + o, so, l );
copysubarray3dn( copy, sox, soy, soz, ssx, ssy, dox, doy, doz, dsx, dsy, csx, csy, csz );
}
}

static void copysubarray3dn(
ArrayCopy copysubarray1dn,
final int sox,
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/tpietzsch/blocks/TileAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
import tpietzsch.cache.UploadBuffer;
import tpietzsch.multires.ResolutionLevel3D;

import static net.imglib2.type.PrimitiveType.BYTE;
import static net.imglib2.type.PrimitiveType.SHORT;
import static tpietzsch.backend.Texture.InternalFormat.R16;
import static tpietzsch.backend.Texture.InternalFormat.R8;

/**
* Copy blocks from a {@link ResolutionLevel3D} source to an {@link UploadBuffer}.
Expand Down Expand Up @@ -124,6 +126,16 @@ public boolean loadTile( final int[] gridPos, final UploadBuffer buffer )
new CopySubArrayImp.ShortToAddress(),
cacheSpec
);
} else if ( cacheSpec.format() == R8 && cellimg )
{
final boolean volatil = type instanceof Volatile;
return new TileAccess<>(
volatil
? new GridDataAccessImp.VolatileCells<>( ( AbstractCellImg ) img )
: new GridDataAccessImp.Cells<>( ( AbstractCellImg ) img ),
new CopySubArrayImp.ByteToAddress(),
cacheSpec
);
}
}

Expand All @@ -137,7 +149,7 @@ public static boolean isSupportedType( final Object type )
{
final PrimitiveType primitive = ( ( NativeType ) type ).getNativeTypeFactory().getPrimitiveType();
final Fraction epp = ( ( NativeType ) type ).getEntitiesPerPixel();
if ( primitive == SHORT && epp.getNumerator() == epp.getDenominator() )
if (( primitive == SHORT && epp.getNumerator() == epp.getDenominator() )|| (primitive == BYTE && epp.getNumerator() == epp.getDenominator()))
return true;
}

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/tpietzsch/example2/VolumeRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static com.jogamp.opengl.GL.GL_SRC_ALPHA;
import static com.jogamp.opengl.GL.GL_UNPACK_ALIGNMENT;
import static tpietzsch.backend.Texture.InternalFormat.R16;
import static tpietzsch.backend.Texture.InternalFormat.R8;
import static tpietzsch.example2.VolumeRenderer.RepaintType.DITHER;
import static tpietzsch.example2.VolumeRenderer.RepaintType.FULL;
import static tpietzsch.example2.VolumeRenderer.RepaintType.LOAD;
Expand Down Expand Up @@ -160,9 +161,6 @@ void request( final RepaintType type )

private final DefaultQuad quad;




public VolumeRenderer(
final int renderWidth,
final int renderHeight,
Expand All @@ -177,7 +175,7 @@ public VolumeRenderer(

// set up gpu cache
// TODO This could be packaged into one class and potentially shared between renderers?
cacheSpec = new CacheSpec( R16, cacheBlockSize );
cacheSpec = new CacheSpec( R8, cacheBlockSize ); //new CacheSpec( R16, cacheBlockSize );
final int[] cacheGridDimensions = TextureCache.findSuitableGridSize( cacheSpec, maxCacheSizeInMB );
textureCache = new TextureCache( cacheGridDimensions, cacheSpec );
pboChain = new PboChain( 5, 100, textureCache );
Expand Down Expand Up @@ -436,7 +434,8 @@ private void updateBlocks(

try
{
ProcessFillTasks.parallel( textureCache, pboChain, context, forkJoinPool, fillTasks );
//ProcessFillTasks.parallel( textureCache, pboChain, context, forkJoinPool, fillTasks );
ProcessFillTasks.sequential( textureCache, pboChain, context, fillTasks );
}
catch ( final InterruptedException e )
{
Expand Down
Loading