From 32c9fecc09e233fb2c70cb7542b38fb6cca4444f Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 8 Apr 2024 19:36:50 -0500 Subject: [PATCH] NDPI: first version of precompressed tile reading --- .../formats/services/JPEGTurboService.java | 10 + .../services/JPEGTurboServiceImpl.java | 11 +- .../src/loci/formats/in/NDPIReader.java | 264 ++++++++++++++---- 3 files changed, 232 insertions(+), 53 deletions(-) diff --git a/components/formats-bsd/src/loci/formats/services/JPEGTurboService.java b/components/formats-bsd/src/loci/formats/services/JPEGTurboService.java index 9ecc8b9c9e9..bddf1be24bb 100644 --- a/components/formats-bsd/src/loci/formats/services/JPEGTurboService.java +++ b/components/formats-bsd/src/loci/formats/services/JPEGTurboService.java @@ -120,6 +120,16 @@ byte[] getTile(byte[] buf, int xCoordinate, int yCoordinate, int width, */ byte[] getCompressedTile(int xTile, int yTile) throws IOException; + /** + * Similar to getTile(int, int), but returns the JPEG-compressed bytes. + * + * @param data preallocated array for storing tile + * @param xTile column index of the tile + * @param yTile row index of the tile + * @return JPEG-compressed bytes + */ + byte[] getCompressedTile(byte[] data, int xTile, int yTile) throws IOException; + /** * Free resources associated with the initialized stream. */ diff --git a/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java b/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java index 2e79544413b..c2e194801a5 100644 --- a/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java +++ b/components/formats-bsd/src/loci/formats/services/JPEGTurboServiceImpl.java @@ -356,12 +356,21 @@ public byte[] getCompressedTile(int tileX, int tileY) throws IOException { } byte[] data = new byte[(int) dataLength]; + return getCompressedTile(data, tileX, tileY); + } + + @Override + public byte[] getCompressedTile(byte[] data, int tileX, int tileY) throws IOException { + if (header == null) { + header = getFixedHeader(); + } int offset = 0; System.arraycopy(header, 0, data, offset, header.length); offset += header.length; - start = tileX + (tileY * xTiles * mult); + int mult = tileHeight / mcuHeight; // was restartInterval + int start = tileX + (tileY * xTiles * mult); for (int row=0; row