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 support for Booleans #8

Merged
merged 15 commits into from
Feb 2, 2023
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017 - 2021, Howard Hughes Medical Institute.
Copyright (c) 2017 - 2023, Howard Hughes Medical Institute.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,13 @@
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*-
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* 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.
* #L%
*/
package net.imglib2.converter.readwrite.longaccess;

import net.imglib2.Sampler;
import net.imglib2.converter.readwrite.SamplerConverter;
import net.imglib2.img.basictypeaccess.BooleanAccess;
import net.imglib2.img.basictypeaccess.ByteAccess;
import net.imglib2.type.logic.NativeBoolType;
import net.imglib2.type.numeric.integer.ByteLongAccessType;
import net.imglib2.type.numeric.integer.ByteType;

/**
* A {@link SamplerConverter} that converts {@link ByteLongAccessType} into
* {@link NativeBoolType}. {@link NativeBoolType}s are fundamentally 8 bits,
* which is also the size of a {@link ByteType}; even sizes make this conversion
* sensical.
*
* @author Gabriel Selzer
*/
public class ByteLongAccessTypeNativeBoolTypeConverter implements SamplerConverter< ByteLongAccessType, NativeBoolType >
{

@Override
public NativeBoolType convert( final Sampler< ? extends ByteLongAccessType > sampler )
{
return new NativeBoolType( new ConvertedAccess( sampler.get() ) );
}

public static class ConvertedAccess implements BooleanAccess
{
private static final byte ONE = ( byte ) 1;

private static final byte ZERO = ( byte ) 0;

private final ByteLongAccessType type;

public ConvertedAccess( final ByteLongAccessType type )
{
this.type = type;
}

@Override
public boolean getValue( final int index )
{
return type.get() > 0;
}

@Override
public void setValue( final int index, final boolean value )
{
type.set( value ? ONE : ZERO );
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/imglib2/img/NativeLongAccessImg.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand All @@ -29,6 +29,7 @@

package net.imglib2.img;

import net.imglib2.img.basictypelongaccess.BooleanLongAccess;
import net.imglib2.img.basictypelongaccess.ByteLongAccess;
import net.imglib2.img.basictypelongaccess.CharLongAccess;
import net.imglib2.img.basictypelongaccess.DoubleLongAccess;
Expand Down Expand Up @@ -68,6 +69,8 @@ public NativeLongAccessImgFactory( final T t )
}

/* basic type containers */
public abstract NativeLongAccessImg< T, ? extends BooleanLongAccess> createNativeBooleanInstance( long[] dimensions, Fraction entitiesPerPixel );

public abstract NativeLongAccessImg< T, ? extends ByteLongAccess > createByteInstance( long[] dimensions, Fraction entitiesPerPixel );

public abstract NativeLongAccessImg< T, ? extends CharLongAccess > createCharInstance( long[] dimensions, Fraction entitiesPerPixel );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* 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.
* #L%
*/

package net.imglib2.img.basictypelongaccess;

import net.imglib2.img.basictypeaccess.BooleanAccess;

/**
* A {@link BooleanAccess} that can also query indices representable by a
* {@code long}
*
* @author Gabriel Selzer
*/
public interface BooleanLongAccess extends BooleanAccess
{
public boolean getValue( final long index );

public void setValue( final long index, final boolean value );
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -32,7 +32,8 @@
import net.imglib2.img.basictypeaccess.ByteAccess;

/**
* TODO
* A {@link ByteAccess} that can also query indices representable by a
* {@code long}
*
* @author Stephan Preibisch
* @author Stephan Saalfeld
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -32,7 +32,8 @@
import net.imglib2.img.basictypeaccess.CharAccess;

/**
* TODO
* A {@link CharAccess} that can also query indices representable by a
* {@code long}
*
* @author Stephan Preibisch
* @author Stephan Saalfeld
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* ImgLib2 data structures using Unsafe.
* %%
* Copyright (C) 2017 - 2021 Howard Hughes Medical Institute.
* Copyright (C) 2017 - 2023 Howard Hughes Medical Institute.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -32,7 +32,8 @@
import net.imglib2.img.basictypeaccess.DoubleAccess;

/**
* TODO
* A {@link DoubleAccess} that can also query indices representable by a
* {@code long}
*
* @author Stephan Preibisch
* @author Stephan Saalfeld
Expand Down
Loading