Skip to content

Commit

Permalink
Merge pull request #257 from melissalinkert/fill-color
Browse files Browse the repository at this point in the history
Fix `--fill-value` to use setFillColor(...) API
  • Loading branch information
sbesson authored Oct 7, 2024
2 parents 4229a4e + e3dd7ca commit 16c59b1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
{
FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);

Arrays.fill(buf, (byte) 0);
Arrays.fill(buf, getFillColor());

BioTekWell well = wells.get(getWellIndex(getSeries()));
String file = well.getFile(getFieldIndex(getSeries()), getZCTCoords(no));
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/com/glencoesoftware/bioformats2raw/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,7 @@ public void setOverwrite(boolean canOverwrite) {
*/
@Option(
names = "--fill-value",
description = "Default value to fill in for missing tiles (0-255)" +
" (currently .mrxs only)",
description = "Default value to fill in for missing tiles (0-255)",
defaultValue = Option.NULL_VALUE
)
public void setFillValue(Short tileFill) {
Expand Down Expand Up @@ -1252,11 +1251,6 @@ public void convert()
// First find which reader class we need
Class<?> readerClass = getBaseReaderClass();

if (!readerClass.equals(MiraxReader.class) && fillValue != null) {
throw new IllegalArgumentException(
"--fill-value not yet supported for " + readerClass);
}

// Now with our found type instantiate our queue of readers for use
// during conversion
boolean savedMemoFile = false;
Expand All @@ -1265,8 +1259,8 @@ public void convert()
Memoizer memoizer;
try {
reader = (IFormatReader) readerClass.getConstructor().newInstance();
if (fillValue != null && reader instanceof MiraxReader) {
((MiraxReader) reader).setFillValue(fillValue.byteValue());
if (fillValue != null) {
reader.setFillColor(fillValue.byteValue());
}
memoizer = createMemoizer(reader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
planeReader.openBytes(0, buf, x, y, w, h);
}
catch (IOException e) {
Arrays.fill(buf, (byte) 0);
Arrays.fill(buf, getFillColor());
}
s.stop("openBytes(0) on " + file);
}
else {
Arrays.fill(buf, (byte) 0);
Arrays.fill(buf, getFillColor());
}

return buf;
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public class MiraxReader extends FormatReader {
JPEG2000CodecOptions.getDefaultOptions();

private boolean fluorescence = false;
private Byte fillValue = null;

private transient JPEGXRCodec jpegxrCodec = new JPEGXRCodec();

Expand Down Expand Up @@ -217,7 +216,7 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)

// set background color to black instead of the stored fill color
// this is to match the default behavior of Pannoramic Viewer
Arrays.fill(buf, getFillValue());
Arrays.fill(buf, getFillColor());

if (tileCache == null) {
tileCache = CacheBuilder.newBuilder()
Expand Down Expand Up @@ -1057,9 +1056,10 @@ else if (name.equals("VIMSLIDE_POSITION_BUFFER")) {
* Set the fill value for missing tiles.
*
* @param fill the fill value, or null to use the reader's default value
* @deprecated used setFillColor(Byte)
*/
public void setFillValue(Byte fill) {
fillValue = fill;
setFillColor(fill);
}

/**
Expand All @@ -1069,10 +1069,17 @@ public void setFillValue(Byte fill) {
* for brightfield.
*
* @return fill value for missing tiles
* @deprecated use getFillColor()
*/
public byte getFillValue() {
if (fillValue != null) {
return fillValue;
return getFillColor();
}

@Override
public Byte getFillColor() {
Byte color = super.getFillColor();
if (color != null) {
return color;
}
return fluorescence ? (byte) 0 : (byte) 255;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public String[] getSeriesUsedFiles(boolean noPixels) {
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
throws FormatException, IOException
{
Arrays.fill(buf, (byte) 0);
Arrays.fill(buf, getFillColor());

int fileIndex = getFileIndex(getSeries());
if (fileIndex >= 0 && fileIndex < files.length) {
Expand Down

0 comments on commit 16c59b1

Please sign in to comment.