-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathIFormatReader.java
More file actions
618 lines (523 loc) · 21 KB
/
IFormatReader.java
File metadata and controls
618 lines (523 loc) · 21 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/*
* #%L
* Top-level reader and writer APIs
* %%
* Copyright (C) 2005 - 2017 Open Microscopy Environment:
* - Board of Regents of the University of Wisconsin-Madison
* - Glencoe Software, Inc.
* - University of Dundee
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package loci.formats;
import java.io.IOException;
import java.util.Hashtable;
import java.util.List;
import loci.common.RandomAccessInputStream;
import loci.formats.meta.MetadataStore;
/**
* Interface for all biological file format readers.
*/
public interface IFormatReader extends IFormatHandler {
// -- Constants --
/** File grouping options. */
int MUST_GROUP = 0;
int CAN_GROUP = 1;
int CANNOT_GROUP = 2;
// -- IFormatReader API methods --
/**
* Checks if the given file is a valid instance of this file format.
*
* @param open If true, and the file extension is insufficient to determine
* the file type, the file may be opened for further analysis, or other
* relatively expensive file system operations (such as file existence
* tests and directory listings) may be performed. If false, file system
* access is not allowed.
*/
boolean isThisType(String name, boolean open);
/** Checks if the given block is a valid header for this file format. */
boolean isThisType(byte[] block);
/** Checks if the given stream is a valid stream for this file format. */
boolean isThisType(RandomAccessInputStream stream) throws IOException;
/** Determines the number of image planes in the current file. */
int getImageCount();
/**
* Checks if the image planes in the file have more than one channel per
* {@link #openBytes} call.
* This method returns true if and only if {@link #getRGBChannelCount()}
* returns a value greater than 1.
*/
boolean isRGB();
/** Gets the size of the X dimension. */
int getSizeX();
/** Gets the size of the Y dimension. */
int getSizeY();
/** Gets the size of the Z dimension. */
int getSizeZ();
/** Gets the size of the C dimension. */
int getSizeC();
/** Gets the size of the T dimension. */
int getSizeT();
/**
* Gets the pixel type.
* @return the pixel type as an enumeration from {@link FormatTools}
* <i>static</i> pixel types such as {@link FormatTools#INT8}.
*/
int getPixelType();
/**
* Gets the number of valid bits per pixel. The number of valid bits per
* pixel is always less than or equal to the number of bits per pixel
* that correspond to {@link #getPixelType()}.
*/
int getBitsPerPixel();
/**
* Gets the effective size of the C dimension, guaranteeing that
* getEffectiveSizeC() * getSizeZ() * getSizeT() == getImageCount()
* regardless of the result of isRGB().
*/
int getEffectiveSizeC();
/**
* Gets the number of channels returned with each call to openBytes.
* The most common case where this value is greater than 1 is for interleaved
* RGB data, such as a 24-bit color image plane. However, it is possible for
* this value to be greater than 1 for non-interleaved data, such as an RGB
* TIFF with Planar rather than Chunky configuration.
*/
int getRGBChannelCount();
/**
* Gets whether the image planes are indexed color.
* This value has no impact on {@link #getSizeC()},
* {@link #getEffectiveSizeC()} or {@link #getRGBChannelCount()}.
*/
boolean isIndexed();
/**
* Returns false if {@link #isIndexed()} is false, or if {@link #isIndexed()}
* is true and the lookup table represents "real" color data. Returns true
* if {@link #isIndexed()} is true and the lookup table is only present to aid
* in visualization.
*/
boolean isFalseColor();
/**
* Gets the 8-bit color lookup table associated with
* the most recently opened image.
* If no image planes have been opened, or if {@link #isIndexed()} returns
* false, then this may return null. Also, if {@link #getPixelType()} returns
* anything other than {@link FormatTools#INT8} or {@link FormatTools#UINT8},
* this method will return null.
*/
byte[][] get8BitLookupTable() throws FormatException, IOException;
/**
* Gets the 16-bit color lookup table associated with
* the most recently opened image.
* If no image planes have been opened, or if {@link #isIndexed()} returns
* false, then this may return null. Also, if {@link #getPixelType()} returns
* anything other than {@link FormatTools#INT16} or {@link
* FormatTools#UINT16}, this method will return null.
*/
short[][] get16BitLookupTable() throws FormatException, IOException;
Modulo getModuloZ();
Modulo getModuloC();
Modulo getModuloT();
/** Get the size of the X dimension for the thumbnail. */
int getThumbSizeX();
/** Get the size of the Y dimension for the thumbnail. */
int getThumbSizeY();
/** Gets whether the data is in little-endian format. */
boolean isLittleEndian();
/**
* Gets a five-character string representing the
* dimension order in which planes will be returned. Valid orders are:<ul>
* <li>XYCTZ</li>
* <li>XYCZT</li>
* <li>XYTCZ</li>
* <li>XYTZC</li>
* <li>XYZCT</li>
* <li>XYZTC</li>
* </ul>
* In cases where the channels are interleaved (e.g., CXYTZ), C will be
* the first dimension after X and Y (e.g., XYCTZ) and the
* {@link #isInterleaved()} method will return true.
*/
String getDimensionOrder();
/**
* Gets whether the dimension order and sizes are known, or merely guesses.
*/
boolean isOrderCertain();
/**
* Gets whether the current series is a lower resolution copy of a different
* series.
*/
boolean isThumbnailSeries();
/**
* Gets whether or not the channels are interleaved. This method exists
* because X and Y must appear first in the dimension order. For
* interleaved data, {@link #getDimensionOrder()} returns XYCTZ or XYCZT,
* and this method returns true.
*
* Note that this flag returns whether or not the data returned by
* {@link #openBytes(int)} is interleaved. In most cases, this will
* match the interleaving in the original file, but for some formats (e.g.
* TIFF) channel re-ordering is done internally and the return value of
* this method will not match what is in the original file.
*/
boolean isInterleaved();
/**
* Gets whether or not the given sub-channel is interleaved. This method
* exists because some data with multiple rasterized sub-dimensions within
* C have one sub-dimension interleaved, and the other not—e.g.,
* {@link loci.formats.in.SDTReader} handles spectral-lifetime data with
* interleaved lifetime bins and non-interleaved spectral channels.
*/
boolean isInterleaved(int subC);
/**
* Obtains the specified image plane from the current file as a byte array.
* @see #openBytes(int, byte[])
*/
byte[] openBytes(int no) throws FormatException, IOException;
/**
* Obtains a sub-image of the specified image plane,
* whose upper-left corner is given by (x, y).
*/
byte[] openBytes(int no, int x, int y, int w, int h)
throws FormatException, IOException;
/**
* Obtains the specified image plane from the current file into a
* pre-allocated byte array of
* (sizeX * sizeY * bytesPerPixel * RGB channel count).
*
* @param no the image index within the file.
* @param buf a pre-allocated buffer.
* @return the pre-allocated buffer <code>buf</code> for convenience.
* @throws FormatException if there was a problem parsing the metadata of the
* file.
* @throws IOException if there was a problem reading the file.
*/
byte[] openBytes(int no, byte[] buf)
throws FormatException, IOException;
/**
* Obtains a sub-image of the specified image plane
* into a pre-allocated byte array.
*
* @param no the image index within the file.
* @param buf a pre-allocated buffer.
* @param x X coordinate of the upper-left corner of the sub-image
* @param y Y coordinate of the upper-left corner of the sub-image
* @param w width of the sub-image
* @param h height of the sub-image
* @return the pre-allocated buffer <code>buf</code> for convenience.
* @throws FormatException if there was a problem parsing the metadata of the
* file.
* @throws IOException if there was a problem reading the file.
*/
byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
throws FormatException, IOException;
/**
* Obtains the specified image plane (or sub-image thereof) in the reader's
* native data structure. For most readers this is a byte array; however,
* some readers call external APIs that work with other types such as
* {@link java.awt.image.BufferedImage}. The openPlane method exists to
* maintain generality and efficiency while avoiding pollution of the API
* with AWT-specific logic.
*
* @see loci.formats.FormatReader
* @see loci.formats.gui.BufferedImageReader
*/
Object openPlane(int no, int x, int y, int w, int h)
throws FormatException, IOException;
/**
* Obtains a thumbnail for the specified image plane from the current file,
* as a byte array.
*/
byte[] openThumbBytes(int no) throws FormatException, IOException;
/**
* Closes the currently open file. If the flag is set, this is all that
* happens; if unset, it is equivalent to calling
* {@link IFormatHandler#close()}.
*/
void close(boolean fileOnly) throws IOException;
/** Gets the number of series in this file. */
int getSeriesCount();
/** Activates the specified series. This also resets the resolution to 0. */
void setSeries(int no);
/** Gets the currently active series. */
int getSeries();
/** Specifies whether or not to normalize float data. */
void setNormalized(boolean normalize);
/** Returns true if we should normalize float data. */
boolean isNormalized();
/**
* Specifies whether or not to save proprietary metadata
* in the MetadataStore.
*/
void setOriginalMetadataPopulated(boolean populate);
/**
* Returns true if we should save proprietary metadata
* in the MetadataStore.
*/
boolean isOriginalMetadataPopulated();
/** Specifies whether or not to force grouping in multi-file formats. */
void setGroupFiles(boolean group);
/** Returns true if we should group files in multi-file formats.*/
boolean isGroupFiles();
/** Returns true if this format's metadata is completely parsed. */
boolean isMetadataComplete();
/**
* Returns an int indicating that we cannot, must, or might group the files
* in a given dataset.
*/
int fileGroupOption(String id) throws FormatException, IOException;
/**
* Returns an array of filenames needed to open this dataset.
* The first element in the array is expected to be the path passed to
* {@link #setId(String)}. The remaining elements are expected to be in a
* consistent order; if a directory listing is necessary to build the list
* then it should be sorted first.
*/
String[] getUsedFiles();
/**
* Returns an array of filenames needed to open this dataset.
* If the 'noPixels' flag is set, then only files that do not contain
* pixel data will be returned.
*
* The first element in the array is expected to be the path passed to
* {@link #setId(String)}, if appropriate based upon 'noPixels'.
* The remaining elements are expected to be in a consistent order;
* if a directory listing is necessary to build the list then it should
* be sorted first.
*/
String[] getUsedFiles(boolean noPixels);
/**
* Returns an array of filenames needed to open the current series.
*
* The first element in the array is expected to be the path passed to
* {@link #setId(String)}. The remaining elements are expected to be in a
* consistent order; if a directory listing is necessary to build the list
* then it should be sorted first.
*/
String[] getSeriesUsedFiles();
/**
* Returns an array of filenames needed to open the current series.
* If the 'noPixels' flag is set, then only files that do not contain
* pixel data will be returned.
*
* The first element in the array is expected to be the path passed to
* {@link #setId(String)}, if appropriate based upon 'noPixels'.
* The remaining elements are expected to be in a consistent order;
* if a directory listing is necessary to build the list then it should
* be sorted first.
*/
String[] getSeriesUsedFiles(boolean noPixels);
/**
* Returns an array of FileInfo objects representing the files needed
* to open this dataset.
* If the 'noPixels' flag is set, then only files that do not contain
* pixel data will be returned.
*/
FileInfo[] getAdvancedUsedFiles(boolean noPixels);
/**
* Returns an array of FileInfo objects representing the files needed to
* open the current series.
* If the 'noPixels' flag is set, then only files that do not contain
* pixel data will be returned.
*/
FileInfo[] getAdvancedSeriesUsedFiles(boolean noPixels);
/** Returns the current file. */
String getCurrentFile();
/** Returns the list of domains represented by the current file. */
String[] getDomains();
/**
* Gets the rasterized index corresponding
* to the given Z, C and T coordinates (real sizes).
*/
int getIndex(int z, int c, int t);
/**
* Gets the rasterized index corresponding to the given Z, C, T,
* moduloZ, moduloC and moduloT coordinates (effective sizes). Note
* that the Z, C and T coordinates take the modulo dimension sizes
* into account. The effective size for each of these dimensions is
* limited to the total size of the dimension divided by the modulo
* size.
*/
int getIndex(int z, int c, int t, int moduloZ, int moduloC, int moduloT);
/**
* Gets the Z, C and T coordinates (real sizes) corresponding to the
* given rasterized index value.
*/
int[] getZCTCoords(int index);
/**
* Gets the Z, C, T, moduloZ, moduloC and moduloT coordinates
* (effective sizes) corresponding to the given rasterized index
* value. Note that the Z, C and T coordinates are not the same as
* those returned by getZCTCoords(int) because the size of the
* modulo dimensions is taken into account. The effective size for
* each of these dimensions is limited to the total size of the
* dimension divided by the modulo size.
*/
int[] getZCTModuloCoords(int index);
/**
* Obtains the specified metadata field's value for the current file.
* @param field the name associated with the metadata field
* @return the value, or null if the field doesn't exist
*/
Object getMetadataValue(String field);
/**
* Obtains the specified metadata field's value for the current series
* in the current file.
* @param field the name associated with the metadata field
* @return the value, or null if the field doesn't exist
*/
Object getSeriesMetadataValue(String field);
/**
* Obtains the hashtable containing the metadata field/value pairs from
* the current file.
* @return the hashtable containing all non-series-specific metadata
* from the file
*/
Hashtable<String, Object> getGlobalMetadata();
/**
* Obtains the hashtable containing metadata field/value pairs from the
* current series in the current file.
*/
Hashtable<String, Object> getSeriesMetadata();
/** Obtains the core metadata values for the current file.
* @deprecated Reader internals should not be accessed by reader users
*/
@Deprecated
List<CoreMetadata> getCoreMetadataList();
/**
* Specifies whether ugly metadata (entries with unprintable characters,
* and extremely large entries) should be discarded from the metadata table.
*/
void setMetadataFiltered(boolean filter);
/**
* Returns true if ugly metadata (entries with unprintable characters,
* and extremely large entries) are discarded from the metadata table.
*/
boolean isMetadataFiltered();
/**
* Sets the default metadata store for this reader.
* @param store a metadata store implementation.
*/
void setMetadataStore(MetadataStore store);
/**
* Retrieves the current metadata store for this reader. You can be
* assured that this method will <b>never</b> return a <code>null</code>
* metadata store.
* @return A metadata store implementation.
*/
MetadataStore getMetadataStore();
/**
* Retrieves the current metadata store's root object. It is guaranteed that
* all file parsing has been performed by the reader prior to retrieval.
* Requests for a full populated root object should be made using this method.
* @return Current metadata store's root object fully populated.
*/
Object getMetadataStoreRoot();
/**
* Retrieves all underlying readers.
* Returns null if there are no underlying readers.
*/
IFormatReader[] getUnderlyingReaders();
/** Returns true if this is a single-file format. */
boolean isSingleFile(String id) throws FormatException, IOException;
/**
* Returns the number of parent directories that are important when
* processing the given list of files. The number of directories is relative
* to the common parent. For example, given a list with these two files:
*
* /path/to/file/foo
* /path/to/file/that/is/related
*
* A return value of 0 indicates that "/path/to/file/" is irrelevant.
* A return value of 1 indicates that "/path/to/" is irrelevant.
* Return values less than 0 are invalid.
*
* All listed files are assumed to belong to datasets of the same format.
*/
int getRequiredDirectories(String[] files) throws FormatException, IOException;
/** Returns a short description of the dataset structure. */
String getDatasetStructureDescription();
/** Returns a list of scientific domains in which this format is used. */
String[] getPossibleDomains(String id) throws FormatException, IOException;
/** Returns true if this format supports multi-file datasets. */
boolean hasCompanionFiles();
/** Returns the optimal sub-image width for use with openBytes. */
int getOptimalTileWidth();
/** Returns the optimal sub-image height for use with openBytes. */
int getOptimalTileHeight();
// -- Sub-resolution API methods --
/** Returns the first core index corresponding to the specified series.
* @deprecated This method is no longer required for sub-resolution support.
*/
@Deprecated
int seriesToCoreIndex(int series);
/** Returns the series corresponding to the specified core index.
* @deprecated This method is no longer required for sub-resolution support.
*/
@Deprecated
int coreIndexToSeries(int index);
/** Return the index into CoreMetadata of the current resolution/series.
* @deprecated This method is no longer required for sub-resolution support.
*/
@Deprecated
int getCoreIndex();
/**
* Set the current resolution/series (ignores subresolutions).
*
* Equivalent to setSeries, but with flattened resolutions always
* set to false.
*
* @deprecated This method is no longer required for sub-resolution support.
*/
@Deprecated
void setCoreIndex(int no);
/**
* Return the number of resolutions for the current series.
*
* Resolutions are stored in descending order, so the largest resolution is
* first and the smallest resolution is last.
*/
int getResolutionCount();
/**
* Set the resolution level.
*
* @see #getResolutionCount()
*/
void setResolution(int resolution);
/**
* Get the current resolution level.
*
* @see #getResolutionCount()
*/
int getResolution();
/** Return whether or not resolution flattening is enabled. */
boolean hasFlattenedResolutions();
/** Set whether or not to flatten resolutions into individual series. */
void setFlattenedResolutions(boolean flatten);
/**
* Reopen any files that were closed, and which are expected to be open
* while the reader is open. This assumes that {@link #setId} has been
* called, but close(false) has not been called.
*/
void reopenFile() throws IOException;
}