From 026a40703fd8d5bc57ca2e1a8b3a1f76ef913b61 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Mon, 12 Aug 2024 19:52:41 +0200 Subject: [PATCH] add missing data types --- .../net/clesperanto/imagej/ImageJConverters.java | 16 ++++++++++++++++ .../net/clesperanto/imagej/ImageJDataType.java | 11 +++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/clesperanto/imagej/ImageJConverters.java b/src/main/java/net/clesperanto/imagej/ImageJConverters.java index c7d417b..aa066c8 100644 --- a/src/main/java/net/clesperanto/imagej/ImageJConverters.java +++ b/src/main/java/net/clesperanto/imagej/ImageJConverters.java @@ -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; @@ -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."); } diff --git a/src/main/java/net/clesperanto/imagej/ImageJDataType.java b/src/main/java/net/clesperanto/imagej/ImageJDataType.java index 0a129c8..12e53b8 100644 --- a/src/main/java/net/clesperanto/imagej/ImageJDataType.java +++ b/src/main/java/net/clesperanto/imagej/ImageJDataType.java @@ -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; @@ -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)) {