forked from ome/bioformats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LociPrefs.java
224 lines (191 loc) · 7.67 KB
/
LociPrefs.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* #%L
* Bio-Formats Plugins for ImageJ: a collection of ImageJ plugins including the
* Bio-Formats Importer, Bio-Formats Exporter, Bio-Formats Macro Extensions,
* Data Browser and Stack Slicer.
* %%
* Copyright (C) 2006 - 2017 Open Microscopy Environment:
* - Board of Regents of the University of Wisconsin-Madison
* - Glencoe Software, Inc.
* - University of Dundee
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
package loci.plugins.util;
import ij.Prefs;
import loci.formats.ClassList;
import loci.formats.FormatTools;
import loci.formats.IFormatReader;
import loci.formats.ImageReader;
import loci.formats.in.CellSensReader;
import loci.formats.in.DynamicMetadataOptions;
import loci.formats.in.LIFReader;
import loci.formats.in.MetadataOptions;
import loci.formats.in.NativeND2Reader;
import loci.formats.in.ND2Reader;
import loci.formats.in.PictReader;
import loci.formats.in.QTReader;
import loci.formats.in.SDTReader;
import loci.formats.in.TiffDelegateReader;
import loci.formats.in.ZeissCZIReader;
/**
* Utility methods for ImageJ preferences for Bio-Formats plugins.
*/
public final class LociPrefs {
// -- Constants --
public static final String PREF_READER_ENABLED = "bioformats.enabled";
public static final String PREF_READER_WINDOWLESS = "bioformats.windowless";
public static final String PREF_ND2_NIKON = "bioformats.nd2.nikon";
public static final String PREF_PICT_QTJAVA = "bioformats.pict.qtjava";
public static final String PREF_QT_QTJAVA = "bioformats.qt.qtjava";
public static final String PREF_SDT_INTENSITY = "bioformats.sdt.intensity";
public static final String PREF_TIFF_IMAGEIO = "bioformats.tiff.imageio";
public static final String PREF_CZI_AUTOSTITCH =
"bioformats.zeissczi.allow.autostitch";
public static final String PREF_CZI_ATTACHMENT =
"bioformats.zeissczi.include.attachments";
public static final String PREF_ND2_CHUNKMAP =
"bioformats.nativend2.chunkmap";
public static final String PREF_LEICA_LIF_PHYSICAL_SIZE =
"bioformats.leicalif.physicalsize.compatibility";
public static final String PREF_SLICE_LABEL_PATTERN = "bioformats.sliceLabelPattern";
public static final String PREF_SLICE_LABEL_BASE_INDEX = "bioformats.sliceLabelBaseIndex";
public static final String PREF_CELLSENS_FAIL =
"bioformats.cellsens.fail_on_missing_ets";
// -- Constructor --
private LociPrefs() { }
// -- Utility methods --
/**
* Creates an image reader according to the current configuration settings,
* including which format readers are currently enabled, as well as
* format-specific configuration settings.
*/
public static ImageReader makeImageReader() {
ClassList<IFormatReader> defaultClasses =
ImageReader.getDefaultReaderClasses();
Class<? extends IFormatReader>[] c = defaultClasses.getClasses();
// include only enabled classes
ClassList<IFormatReader> enabledClasses =
new ClassList<IFormatReader>(IFormatReader.class);
for (int i=0; i<c.length; i++) {
boolean on = LociPrefs.isReaderEnabled(c[i]);
if (on) enabledClasses.addClass(c[i]);
}
ImageReader reader = new ImageReader(enabledClasses);
MetadataOptions options = reader.getMetadataOptions();
if (options instanceof DynamicMetadataOptions) {
((DynamicMetadataOptions) options).setBoolean(
ZeissCZIReader.ALLOW_AUTOSTITCHING_KEY, allowCZIAutostitch());
((DynamicMetadataOptions) options).setBoolean(
ZeissCZIReader.INCLUDE_ATTACHMENTS_KEY, includeCZIAttachments());
((DynamicMetadataOptions) options).setBoolean(
NativeND2Reader.USE_CHUNKMAP_KEY, useND2Chunkmap());
((DynamicMetadataOptions) options).setBoolean(
LIFReader.OLD_PHYSICAL_SIZE_KEY, isLeicaLIFPhysicalSizeBackwardsCompatible());
((DynamicMetadataOptions) options).setBoolean(
CellSensReader.FAIL_ON_MISSING_KEY, isCellsensFailOnMissing());
reader.setMetadataOptions(options);
}
// toggle reader-specific options
boolean nd2Nikon = LociPrefs.isND2Nikon();
boolean pictQTJava = LociPrefs.isPictQTJava();
boolean qtQTJava = LociPrefs.isQTQTJava();
boolean sdtIntensity = LociPrefs.isSDTIntensity();
boolean tiffImageIO = LociPrefs.isTiffImageIO();
IFormatReader[] r = reader.getReaders();
for (int i=0; i<r.length; i++) {
if (r[i] instanceof ND2Reader) {
ND2Reader nd2 = (ND2Reader) r[i];
nd2.setLegacy(nd2Nikon);
}
else if (r[i] instanceof PictReader) {
PictReader pict = (PictReader) r[i];
pict.setLegacy(pictQTJava);
}
else if (r[i] instanceof QTReader) {
QTReader qt = (QTReader) r[i];
qt.setLegacy(qtQTJava);
}
else if (r[i] instanceof SDTReader) {
SDTReader sdt = (SDTReader) r[i];
sdt.setIntensity(sdtIntensity);
}
else if (r[i] instanceof TiffDelegateReader) {
TiffDelegateReader tiff = (TiffDelegateReader) r[i];
tiff.setLegacy(tiffImageIO);
}
}
return reader;
}
/**
* Gets whether windowless mode should be used when
* opening this reader's currently initialized dataset.
*/
public static boolean isWindowless(IFormatReader r) {
return getPref(PREF_READER_WINDOWLESS, r.getClass(), false);
}
public static boolean isReaderEnabled(Class<? extends IFormatReader> c) {
return getPref(PREF_READER_ENABLED, c, true);
}
public static boolean isND2Nikon() {
return Prefs.get(PREF_ND2_NIKON, false);
}
public static boolean isPictQTJava() {
return Prefs.get(PREF_PICT_QTJAVA, false);
}
public static boolean isQTQTJava() {
return Prefs.get(PREF_QT_QTJAVA, false);
}
public static boolean isSDTIntensity() {
return Prefs.get(PREF_SDT_INTENSITY, false);
}
public static boolean isTiffImageIO() {
return Prefs.get(PREF_TIFF_IMAGEIO, false);
}
public static boolean allowCZIAutostitch() {
return Prefs.get(PREF_CZI_AUTOSTITCH,
ZeissCZIReader.ALLOW_AUTOSTITCHING_DEFAULT);
}
public static boolean includeCZIAttachments() {
return Prefs.get(PREF_CZI_ATTACHMENT,
ZeissCZIReader.INCLUDE_ATTACHMENTS_DEFAULT);
}
public static boolean useND2Chunkmap() {
return Prefs.get(PREF_ND2_CHUNKMAP, NativeND2Reader.USE_CHUNKMAP_DEFAULT);
}
public static boolean isLeicaLIFPhysicalSizeBackwardsCompatible() {
return Prefs.get(PREF_LEICA_LIF_PHYSICAL_SIZE,
LIFReader.OLD_PHYSICAL_SIZE_DEFAULT);
}
public static String getSliceLabelPattern() {
return Prefs.get(PREF_SLICE_LABEL_PATTERN, "%c%z%t- %n");
}
public static int getSliceLabelBaseIndex() {
return Prefs.getInt(PREF_SLICE_LABEL_BASE_INDEX, 1);
}
public static boolean isCellsensFailOnMissing() {
return Prefs.get(PREF_CELLSENS_FAIL, CellSensReader.FAIL_ON_MISSING_DEFAULT);
}
// -- Helper methods --
private static boolean getPref(String pref,
Class<? extends IFormatReader> c, boolean defaultValue)
{
String n = c.getName();
String readerName = n.substring(n.lastIndexOf(".") + 1, n.length() - 6);
String key = pref + "." + readerName;
return Prefs.get(key, defaultValue);
}
}