Skip to content

Commit

Permalink
Merge pull request #30 from BIOP/pom-scijava-39
Browse files Browse the repository at this point in the history
Update to pom scijava 39
  • Loading branch information
NicoKiaru authored Oct 28, 2024
2 parents d92e90c + 873ea92 commit 6d7feed
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>38.0.1</version>
<version>39.0.0-SNAPSHOT</version>
<relativePath />
</parent>

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/epfl/biop/bdv/img/OpenersToSpimData.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.slf4j.LoggerFactory;
import spimdata.util.Displaysettings;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -208,7 +209,7 @@ protected AbstractSpimData<?> getSpimDataInstance(List<OpenerSettings> openerSet
// create spimdata
SequenceDescription sd = new SequenceDescription(new TimePoints(timePoints), viewSetups, null, new MissingViews(missingViews));
sd.setImgLoader(new OpenersImageLoader(openerSettings, openers, sd));
return new SpimData(null, sd, new ViewRegistrations(registrations));
return new SpimData((File) null, sd, new ViewRegistrations(registrations));
}
catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,75 @@ public int getBytesPerElement() {
}
}

/**
* Class explaining how to read and load pixels of type : unsigned short (16 bits)
*/
public static class BioFormatsShortArrayLoader extends
BioformatsArrayLoader implements CacheArrayLoader<VolatileShortArray>
{

final ByteOrder byteOrder;

protected BioFormatsShortArrayLoader(ResourcePool<IFormatReader> readerPool,
int channel, int iSeries, boolean littleEndian)
{
super(readerPool, channel, iSeries);
if (littleEndian) {
byteOrder = ByteOrder.LITTLE_ENDIAN;
}
else {
byteOrder = ByteOrder.BIG_ENDIAN;
}
}

@Override
public VolatileShortArray loadArray(int timepoint, int setup, int level,
int[] dimensions, long[] min) throws InterruptedException
{
try {
// get the reader
IFormatReader reader = readerPool.acquire();
reader.setSeries(iSeries);
reader.setResolution(level);
int minX = (int) min[0];
int minY = (int) min[1];
int minZ = (int) min[2];
int maxX = Math.min(minX + dimensions[0], reader.getSizeX());
int maxY = Math.min(minY + dimensions[1], reader.getSizeY());
int maxZ = Math.min(minZ + dimensions[2], reader.getSizeZ());
int w = maxX - minX;
int h = maxY - minY;
int d = maxZ - minZ;
int nElements = (w * h * d);

// read pixels
ByteBuffer buffer = ByteBuffer.allocate(nElements * 2);
for (int z = minZ; z < maxZ; z++) {
byte[] bytes = reader.openBytes(reader.getIndex(z, channel, timepoint), minX, minY,
w, h);
buffer.put(bytes);
}

// release the reader
readerPool.recycle(reader);

// unsigned short specific transform
short[] shorts = new short[nElements];
buffer.flip();
buffer.order(byteOrder).asShortBuffer().get(shorts);
return new VolatileShortArray(shorts, true);
}
catch (Exception e) {
throw new InterruptedException(e.getMessage());
}
}

@Override
public int getBytesPerElement() {
return 2;
}
}

/**
* Class explaining how to read and load pixels of type : float (32 bits)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.numeric.integer.IntType;
import net.imglib2.type.numeric.integer.ShortType;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedIntType;
import net.imglib2.type.numeric.integer.UnsignedShortType;
Expand Down Expand Up @@ -564,6 +565,9 @@ private static Type<? extends NumericType<?>> getBioformatsBdvSourceType(int pt,
if (pt == FormatTools.UINT32) {
return new UnsignedIntType();
}
if (pt == FormatTools.INT16) {
return new ShortType();
}
}
throw new UnsupportedOperationException("Unhandled pixel type for serie " +
image_index + ": " + pt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.numeric.integer.AbstractIntegerType;
import net.imglib2.type.numeric.integer.IntType;
import net.imglib2.type.numeric.integer.ShortType;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedIntType;
import net.imglib2.type.numeric.integer.UnsignedShortType;
Expand Down Expand Up @@ -183,8 +184,18 @@ else if (t instanceof UnsignedShortType) {
(CacheArrayLoader<A>) new BioFormatsArrayLoaders.BioFormatsUnsignedShortArrayLoader(
readerPool, iChannel, iSeries, isLittleEndian);
}
}
else if (t instanceof FloatType) {
} else if (t instanceof ShortType) {
if (opener.to16bit()) {
// the data is originally 8 bits
throw new UnsupportedOperationException("Pixel type " + t.getClass()
.getName() + " conversion to 16 bits unsupported in " + BioFormatsSetupLoader.class
.getName());
} else {
loader =
(CacheArrayLoader<A>) new BioFormatsArrayLoaders.BioFormatsShortArrayLoader(
readerPool, iChannel, iSeries, isLittleEndian);
}
} else if (t instanceof FloatType) {
loader =
(CacheArrayLoader<A>) new BioFormatsArrayLoaders.BioFormatsFloatArrayLoader(
readerPool, iChannel, iSeries, isLittleEndian);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ protected AbstractSpimData<?> getSpimDataInstance(
sd.setImgLoader(new BioFormatsImageLoader(openers, sd, openers.get(
0).nFetcherThread, openers.get(0).numPriorities));

return new SpimData(null, sd, new ViewRegistrations(registrations));
return new SpimData((File) null, sd, new ViewRegistrations(registrations));
}
catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public AbstractSpimData<?> getSpimDataInstance(URI quPathProject,
sd.setImgLoader(new QuPathImageLoader(quPathProject, openerModel, sd,
openerModel.nFetcherThread, openerModel.numPriorities));

final SpimData spimData = new SpimData(null, sd, new ViewRegistrations(
final SpimData spimData = new SpimData((File) null, sd, new ViewRegistrations(
registrations));
return spimData;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/epfl/biop/bdv/img/omero/OmeroOpener.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public OmeroOpener(

List<Long> imageIDs = OmeroHelper.getImageIDs(datalocation, gateway, securityContext);

if (imageIDs.size()==0) throw new IllegalStateException("Could not found an image ID in url "+datalocation);
if (imageIDs.isEmpty()) throw new IllegalStateException("Could not found an image ID in url "+datalocation);
if (imageIDs.size()>1) throw new UnsupportedOperationException("Could not open multiple Omero IDs in a single URL, split them.");

long imageID = imageIDs.get(0);
Expand Down

0 comments on commit 6d7feed

Please sign in to comment.