Skip to content

Commit

Permalink
add missing data types
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Aug 12, 2024
1 parent fef3529 commit 026a407
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/main/java/net/clesperanto/imagej/ImageJConverters.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -106,10 +107,25 @@ private static ImagePlus fromBuffer(ByteBuffer byteBuffer, ImageJDataType type,
case UINT8:
fillImage(im, dimensions, byteBuffer::get);
break;
case INT8:
fillImage(im, dimensions, byteBuffer::get);
break;
case UINT16:
ShortBuffer uShortBuff = byteBuffer.asShortBuffer();
fillImage(im, dimensions, uShortBuff::get);
break;
case INT16:
ShortBuffer shortBuff = byteBuffer.asShortBuffer();
fillImage(im, dimensions, shortBuff::get);
break;
case UINT32:
IntBuffer uIntBuff = byteBuffer.asIntBuffer();
fillImage(im, dimensions, uIntBuff::get);
break;
case INT32:
IntBuffer intBuff = byteBuffer.asIntBuffer();
fillImage(im, dimensions, intBuff::get);
break;
default:
throw new IllegalArgumentException("Data type not supported.");
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/net/clesperanto/imagej/ImageJDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import net.clesperanto.core.DataType;
import net.clesperanto.core.DeviceJ;

// TODO add all types ImagePlus.GRAY8, ImagePlus.GRAY16, ImagePlus.GRAY32, ImagePlus.COLOR_256 or ImagePlus.COLOR_RGB)
public enum ImageJDataType {
FLOAT32(DataType.fromString("float"), ImagePlus.GRAY32, float[].class, 32),
INT32(DataType.fromString("int"), ImagePlus.GRAY32, int[].class, 32),
UINT32(DataType.fromString("uint"), ImagePlus.GRAY32, int[].class, 32),
UINT16(DataType.fromString("ushort"), ImagePlus.GRAY16, short[].class, 16),
UINT8(DataType.fromString("uchar"), ImagePlus.GRAY8, byte[].class, 8);
INT16(DataType.fromString("short"), ImagePlus.GRAY16, short[].class, 16),
UINT8(DataType.fromString("uchar"), ImagePlus.GRAY8, byte[].class, 8),
INT8(DataType.fromString("char"), ImagePlus.GRAY8, byte[].class, 8);

private final DataType dt;
private final int imgDtype;
Expand All @@ -25,6 +28,10 @@ public enum ImageJDataType {
this.bitDepth = bitDepth;
}

public static ImageJDataType fromImagePlus(ImagePlus imp) {
return fromImgPlusDataType(imp.getType());
}

public static ImageJDataType fromString(String dType) {
for (ImageJDataType type : values()) {
if (type.dt.getName().equals(dType)) {
Expand Down

0 comments on commit 026a407

Please sign in to comment.