Skip to content

Commit

Permalink
Merge pull request ome#4148 from melissalinkert/jpeg-reset-legacy-flag
Browse files Browse the repository at this point in the history
JPEG: reset `useLegacy` flag to its original state upon close
  • Loading branch information
dgault authored Feb 7, 2024
2 parents 194a643 + 70ffd45 commit cd0beb8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/formats-bsd/src/loci/formats/in/JPEGReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public class JPEGReader extends DelegateReader {

private static final int MAX_SIZE = 8192;

/**
* setId may alter the "useLegacy" variable depending upon
* the type of JPEG encountered. Storing the state of
* the "useLegacy" variable prior to any internal changes
* allows the reader to reset "useLegacy" to its original
* state upon close.
*/
private boolean initialUseLegacy;

// -- Constructor --

/** Constructs a new JPEGReader. */
Expand All @@ -83,6 +92,10 @@ public JPEGReader() {
/* @see FormatReader#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
// capture the current state of "useLegacy"
// it may be updated later in this method and should be reset upon close
initialUseLegacy = isLegacy();

try {
super.setId(id);
}
Expand Down Expand Up @@ -176,6 +189,10 @@ public String[] getSeriesUsedFiles(boolean noPixels) {
public void close(boolean fileOnly) throws IOException {
super.close(fileOnly);
Location.mapId(currentId, null);

// reset to whatever legacy setting was originally requested
// this erases any changes made during setId
setLegacy(initialUseLegacy);
}

// -- Helper reader --
Expand Down

0 comments on commit cd0beb8

Please sign in to comment.