|
7 | 7 | */ |
8 | 8 | package com.glencoesoftware.bioformats2raw.test; |
9 | 9 |
|
| 10 | +import java.nio.ByteOrder; |
10 | 11 | import java.nio.file.Files; |
11 | 12 | import java.util.Arrays; |
12 | 13 | import java.util.List; |
|
18 | 19 | import dev.zarr.zarrjava.core.Attributes; |
19 | 20 | import dev.zarr.zarrjava.v3.Array; |
20 | 21 | import dev.zarr.zarrjava.v3.ArrayMetadata; |
| 22 | +import dev.zarr.zarrjava.v3.DataType; |
21 | 23 | import dev.zarr.zarrjava.v3.Group; |
22 | 24 | import dev.zarr.zarrjava.v3.codec.Codec; |
23 | 25 | import dev.zarr.zarrjava.v3.codec.core.BloscCodec; |
| 26 | +import dev.zarr.zarrjava.v3.codec.core.BytesCodec; |
24 | 27 | import dev.zarr.zarrjava.v3.codec.core.GzipCodec; |
25 | 28 | import dev.zarr.zarrjava.v3.codec.core.ShardingIndexedCodec; |
26 | 29 | import dev.zarr.zarrjava.v3.codec.core.ZstdCodec; |
27 | 30 |
|
| 31 | +import loci.formats.FormatTools; |
28 | 32 | import ome.xml.model.OME; |
29 | 33 |
|
30 | 34 | import picocli.CommandLine.ExecutionException; |
@@ -454,4 +458,49 @@ public void testBadCompressionOptions(String codec) throws Exception { |
454 | 458 | }); |
455 | 459 | } |
456 | 460 |
|
| 461 | + /** |
| 462 | + * Test pixel type preservation. |
| 463 | + * |
| 464 | + * @param type string representation of Bio-Formats pixel type |
| 465 | + * @param dataType expected corresponding Zarr data type |
| 466 | + */ |
| 467 | + @ParameterizedTest |
| 468 | + @MethodSource("getPixelTypes") |
| 469 | + public void testPixelType(String type, DataType dataType) throws Exception { |
| 470 | + input = fake("pixelType", type); |
| 471 | + assertTool("--ngff-version", getNGFFVersion()); |
| 472 | + Group z = Group.open(store.resolve("")); |
| 473 | + |
| 474 | + // Check series dimensions and special pixels |
| 475 | + Array series0 = Array.open(store.resolve("0", "0")); |
| 476 | + assertEquals(dataType, series0.metadata().dataType); |
| 477 | + for (Codec codec : series0.metadata().codecs) { |
| 478 | + if (codec instanceof BytesCodec) { |
| 479 | + assertEquals(((BytesCodec) codec).configuration.endian.getByteOrder(), |
| 480 | + ByteOrder.LITTLE_ENDIAN); |
| 481 | + } |
| 482 | + } |
| 483 | + assertArrayEquals(new long[] {1, 1, 1, 512, 512}, series0.metadata().shape); |
| 484 | + int[] shape = new int[] {1, 1, 1, 512, 512}; |
| 485 | + assertArrayEquals(shape, series0.metadata().chunkShape()); |
| 486 | + |
| 487 | + int pixelType = FormatTools.pixelTypeFromString(type); |
| 488 | + checkSpecialPixels(0, 1, 1, 1, shape, series0, pixelType); |
| 489 | + |
| 490 | + OME ome = getOMEMetadata(); |
| 491 | + assertFalse(ome.getImage(0).getPixels().getBigEndian()); |
| 492 | + } |
| 493 | + |
| 494 | + /** |
| 495 | + * @return pairs of pixel type strings and Zarr data types |
| 496 | + */ |
| 497 | + static Stream<Arguments> getPixelTypes() { |
| 498 | + return Stream.of( |
| 499 | + Arguments.of("float", DataType.FLOAT32), |
| 500 | + Arguments.of("double", DataType.FLOAT64), |
| 501 | + Arguments.of("uint32", DataType.UINT32), |
| 502 | + Arguments.of("int32", DataType.INT32) |
| 503 | + ); |
| 504 | + } |
| 505 | + |
457 | 506 | } |
0 commit comments