Skip to content
Snippets Groups Projects
Commit 28fd1e92 authored by Stephan Saalfeld's avatar Stephan Saalfeld
Browse files

added VolatileARGBType and abstract base class similar to the existing

implementation for RealTypes
parent dc1b2caf
No related branches found
No related tags found
No related merge requests found
/*
* #%L
* ImgLib2: a general-purpose, multidimensional image processing library.
* %%
* Copyright (C) 2009 - 2012 Stephan Preibisch, Stephan Saalfeld, Tobias
* Pietzsch, Albert Cardona, Barry DeZonia, Curtis Rueden, Lee Kamentsky, Larry
* Lindsey, Johannes Schindelin, Christian Dietz, Grant Harris, Jean-Yves
* Tinevez, Steffen Jaensch, Mark Longair, Nick Perry, and Jan Funke.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of any organization.
* #L%
*/
package net.imglib2.type.volatiles;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.NumericType;
/**
* Abstract base class for {@link VolatileNumericType}s that wrap
* {@link NativeType native} {@link NumericType}s.
*
* @param <N>
* wrapped {@link NativeType native} {@link NumericsType}.
* @param <T>
* type of derived concrete class.
*
* @author Tobias Pietzsch <tobias.pietzsch@gmail.com>
* @author Stephan Saalfeld <saalfelds@janelia.hhmi.org>
*/
public abstract class AbstractVolatileNativeNumericType< N extends NumericType< N > & NativeType< N >, T extends AbstractVolatileNativeNumericType< N, T > >
extends AbstractVolatileNumericType< N, T >
implements NativeType< T >
{
public AbstractVolatileNativeNumericType( final N t, final boolean valid )
{
super( t, valid );
}
@Override
public int getEntitiesPerPixel()
{
return t.getEntitiesPerPixel();
}
@Override
public void updateIndex( final int i )
{
t.updateIndex( i );
}
@Override
public int getIndex()
{
return t.getIndex();
}
@Override
public void incIndex()
{
t.incIndex();
}
@Override
public void incIndex( final int increment )
{
t.incIndex( increment );
}
@Override
public void decIndex()
{
t.decIndex();
}
@Override
public void decIndex( final int decrement )
{
t.decIndex( decrement );
}
}
package net.imglib2.type.volatiles;
import net.imglib2.Volatile;
import net.imglib2.img.NativeImg;
import net.imglib2.img.NativeImgFactory;
import net.imglib2.img.basictypeaccess.IntAccess;
import net.imglib2.img.basictypeaccess.volatiles.VolatileIntAccess;
import net.imglib2.img.basictypeaccess.volatiles.VolatileShortAccess;
import net.imglib2.img.basictypeaccess.volatiles.array.VolatileIntArray;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.integer.UnsignedShortType;
/**
* A {@link Volatile} variant of {@link UnsignedShortType}. It uses an
* underlying {@link UnsignedShortType} that maps into a
* {@link VolatileShortAccess}.
*
* @author Stephan Saalfeld <saalfelds@janelia.hhmi.org>
* @author Tobias Pietzsch <tobias.pietzsch@gmail.com>
*/
public class VolatileARGBType extends AbstractVolatileNativeNumericType< ARGBType, VolatileARGBType >
{
final protected NativeImg< ?, ? extends VolatileIntAccess > img;
private static class WrappedARGBType extends ARGBType
{
public WrappedARGBType( final NativeImg< ?, ? extends IntAccess > img )
{
super( img );
}
public WrappedARGBType( final IntAccess access )
{
super( access );
}
public void setAccess( final IntAccess access )
{
dataAccess = access;
}
}
// this is the constructor if you want it to read from an array
public VolatileARGBType( final NativeImg< ?, ? extends VolatileIntAccess > img )
{
super( new WrappedARGBType( img ), false );
this.img = img;
}
// this is the constructor if you want to specify the dataAccess
public VolatileARGBType( final VolatileIntAccess access )
{
super( new WrappedARGBType( access ), access.isValid() );
this.img = null;
}
// this is the constructor if you want it to be a variable
public VolatileARGBType( final int value )
{
this( new VolatileIntArray( 1, true ) );
set( value );
}
// this is the constructor if you want it to be a variable
public VolatileARGBType()
{
this( 0 );
}
public void set( final int value )
{
get().set( value );
}
@Override
public void updateContainer( final Object c )
{
final VolatileIntAccess a = img.update( c );
( ( WrappedARGBType ) t ).setAccess( a );
setValid( a.isValid() );
}
@Override
public NativeImg< VolatileARGBType, ? extends VolatileIntAccess > createSuitableNativeImg( final NativeImgFactory< VolatileARGBType > storageFactory, final long[] dim )
{
throw new UnsupportedOperationException();
}
@Override
public VolatileARGBType duplicateTypeOnSameNativeImg()
{
return new VolatileARGBType( img );
}
@Override
public VolatileARGBType createVariable()
{
return new VolatileARGBType();
}
@Override
public VolatileARGBType copy()
{
final VolatileARGBType v = createVariable();
v.set( this );
return v;
}
}
......@@ -25,6 +25,7 @@ public class VolatileUnsignedShortType extends AbstractVolatileNativeRealType< U
{
super( img );
}
public WrappedUnsignedShortType( final ShortAccess access )
{
super( access );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment