Skip to content

Commit

Permalink
Merge pull request #4081 from melissalinkert/svs-fixes
Browse files Browse the repository at this point in the history
SVS: fix a variety of small issues
  • Loading branch information
dgault authored Oct 13, 2023
2 parents 09edddc + 593c819 commit 95a55e8
Showing 1 changed file with 62 additions and 9 deletions.
71 changes: 62 additions & 9 deletions components/formats-gpl/src/loci/formats/in/SVSReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,19 @@ public class SVSReader extends BaseTiffReader {
private ArrayList<String> dyeNames = new ArrayList<String>();

private transient Color displayColor = null;

// explicitly record the series and IFD indexes
// for the label and macro images
// this makes it easier to calculate IFD mappings
private int labelIndex = -1;
private int macroIndex = -1;

// total number of extra (label and macro) images
private int extraImages = 0;

private transient Double physicalDistanceFromLeftEdge;
private transient Double physicalDistanceFromTopEdge;

// -- Constructor --

/** Constructs a new SVS reader. */
Expand Down Expand Up @@ -275,7 +284,7 @@ protected void initStandardMetadata() throws FormatException, IOException {

for (int i=0; i<seriesCount; i++) {
setSeries(i);
int index = getIFDIndex(i, 0);
int index = i;
tiffParser.fillInIFD(ifds.get(index));

String comment = ifds.get(index).getComment();
Expand Down Expand Up @@ -349,6 +358,12 @@ else if (t.toLowerCase().indexOf("macro") >= 0) {
}
else {
ifds.remove(s);
if (s < labelIndex) {
labelIndex--;
}
if (s < macroIndex) {
macroIndex--;
}
}
}
if (uniqueZ.size() == 0) {
Expand Down Expand Up @@ -469,6 +484,12 @@ else if (t.toLowerCase().indexOf("macro") >= 0) {
int color = Integer.parseInt(value);
displayColor = new Color((color << 8) | 0xff);
break;
case "Left":
physicalDistanceFromLeftEdge = DataTools.parseDouble(value);
break;
case "Top":
physicalDistanceFromTopEdge = DataTools.parseDouble(value);
break;
}
}
}
Expand All @@ -486,7 +507,10 @@ protected void initMetadataStore() throws FormatException {
super.initMetadataStore();

MetadataStore store = makeFilterMetadata();
MetadataTools.populatePixels(store, this, getImageCount() > 1);
boolean populatePlaneData = getImageCount() > 1 ||
physicalDistanceFromTopEdge != null ||
physicalDistanceFromLeftEdge != null;
MetadataTools.populatePixels(store, this, populatePlaneData);

String instrument = MetadataTools.createLSID("Instrument", 0);
String objective = MetadataTools.createLSID("Objective", 0, 0);
Expand All @@ -501,17 +525,32 @@ protected void initMetadataStore() throws FormatException {
store.setImageInstrumentRef(instrument, i);
store.setObjectiveSettingsID(objective, i);

if (i == 0) {
if (physicalDistanceFromTopEdge != null) {
Length yPos = FormatTools.getStagePosition(physicalDistanceFromTopEdge, UNITS.MM);
for (int p=0; p<getImageCount(); p++) {
store.setPlanePositionY(yPos, i, p);
}
}
if (physicalDistanceFromLeftEdge != null) {
Length xPos = FormatTools.getStagePosition(physicalDistanceFromLeftEdge, UNITS.MM);
for (int p=0; p<getImageCount(); p++) {
store.setPlanePositionX(xPos, i, p);
}
}
}

if (hasFlattenedResolutions() || i > extraImages) {
store.setImageName("Series " + (i + 1), i);
}
else {
if (i == 0) {
store.setImageName("", i);
}
else if (i == labelIndex) {
else if (core.flattenedIndex(i, 0) == labelIndex) {
store.setImageName("label image", i);
}
else if (i == macroIndex) {
else if (core.flattenedIndex(i, 0) == macroIndex) {
store.setImageName("macro image", i);
}
}
Expand Down Expand Up @@ -559,7 +598,10 @@ else if (i == macroIndex) {

private int getIFDIndex(int coreIndex, int no) {
int index = coreIndex;
// coreCount is the number of pyramid resolutions (independent of flattening)
int coreCount = core.flattenedSize() - extraImages;

// this is the case where the requested IFD is within the pyramid
if (coreIndex > 0 && coreIndex < coreCount) {
if (core.get(0, 0).imageCount > 1) {
index++;
Expand All @@ -568,6 +610,7 @@ private int getIFDIndex(int coreIndex, int no) {
index = coreCount - coreIndex;
}
}

if ((coreIndex > 0 && coreIndex < coreCount) || no > 0) {
for (int i=0; i<no; i++) {
index += coreCount;
Expand All @@ -576,11 +619,21 @@ private int getIFDIndex(int coreIndex, int no) {
index++;
}
}
else if (coreIndex >= coreCount && core.get(0, 0).imageCount > 1) {
for (int i=0; i<coreCount; i++) {
index += core.get(0, i).imageCount;
else if (coreIndex >= coreCount) {
if (core.get(0, 0).imageCount > 1) {
for (int i=0; i<coreCount; i++) {
index += core.get(0, i).imageCount;
}
index -= (coreCount - 1);
}
else {
if (coreIndex == labelIndex) {
return labelIndex;
}
if (coreIndex == macroIndex) {
return macroIndex;
}
}
index -= (coreCount - 1);
}
return index;
}
Expand Down Expand Up @@ -632,7 +685,7 @@ protected Length[] getPhysicalSizes() {
}

protected double getMagnification() {
return magnification;
return magnification == null ? Double.NaN : magnification;
}

protected ArrayList<String> getDyeNames() {
Expand Down

0 comments on commit 95a55e8

Please sign in to comment.