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

Fix --fill-value to use setFillColor(...) API #257

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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 @@ -708,8 +708,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 @@ -1251,11 +1250,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 @@ -1264,8 +1258,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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is planned for 0.10.0, is there a value in going through a deprecation rather than dropping these in favor of the new API defined upstream?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't totally sure what the best approach would be here, so went with deprecating to be on the safer side. If we're all OK with just removing getFillValue() and setFillValue(), I'm fine with that - it would only impact anyone using MiraxReader directly, either by extending the reader or by calling those methods directly.

*/
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