Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues 4150 + 4110: Consider ZSTD with pyramid levels and fix integer arithmetic scale problem #4138

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ protected void initFile(String id) throws FormatException, IOException {
convertPixelType(planes.get(0).directoryEntry.pixelType);

// remove any invalid SubBlocks

int bpp = FormatTools.getBytesPerPixel(getPixelType());
if (isRGB()) {
bpp *= (getSizeC() / originalC);
Expand All @@ -743,16 +742,18 @@ protected void initFile(String id) throws FormatException, IOException {
for (int i=0; i<planes.size(); i++) {
long planeSize = (long) planes.get(i).x * planes.get(i).y * bpp;
int compression = planes.get(i).directoryEntry.compression;
if (compression == UNCOMPRESSED || compression == JPEGXR) {
boolean isCompressed = compression == JPEGXR || compression == ZSTD_0 || compression == ZSTD_1;
if (compression == UNCOMPRESSED || isCompressed) {
long size = planes.get(i).dataSize;
if (size < planeSize || planeSize >= Integer.MAX_VALUE || size < 0) {
// check for reduced resolution in the pyramid
DimensionEntry[] entries = planes.get(i).directoryEntry.dimensionEntries;
int pyramidType = planes.get(i).directoryEntry.pyramidType;
if ((pyramidType == 1 || pyramidType == 2 || compression == JPEGXR) &&
(compression == JPEGXR || size == entries[0].storedSize * entries[1].storedSize * bpp))
if (isCompressed ||
((pyramidType == 1 || pyramidType == 2 ) && (size == entries[0].storedSize * entries[1].storedSize * bpp)))
{
int scale = planes.get(i).x / entries[0].storedSize;
// circumvent integer arithmetic rounding issue by using floating point precision calculation (see issue #4102)
int scale = (int)((double)planes.get(i).x / (double)entries[0].storedSize + 0.5);
if (scale == 1 || (((scale % 2) == 0 || (scale % 3) == 0) && allowAutostitching())) {
if (scale > 1 && scaleFactor == 0) {
scaleFactor = scale % 2 == 0 ? 2 : 3;
Expand Down Expand Up @@ -4186,7 +4187,7 @@ public byte[] readPixelData(RandomAccessInputStream s, Region tile, byte[] buf)
}
}
else {
LOGGER.warn("ZSTD-1 compression used, but no high/low byte unpacking");
LOGGER.debug("ZSTD-1 compression used, but no high/low byte unpacking");
data = decoded;
}

Expand Down
Loading