001/**
002 * 
003 */
004package icy.image;
005
006import java.awt.Rectangle;
007import java.io.IOException;
008
009import icy.common.exception.UnsupportedFormatException;
010import icy.sequence.MetaDataUtil;
011import loci.formats.ome.OMEXMLMetadataImpl;
012import ome.xml.meta.OMEXMLMetadata;
013
014/**
015 * Image provider interface.<br>
016 * This interface is designed to any class capable of delivering image data at different level
017 * access.<br>
018 * Takes an uniquely identified resource as input and returns image data at different level access.<br>
019 * <br>
020 * Example of possible class implementing this interface:
021 * <ul>
022 * <li>LOCI (Bio-Formats) image reader class.</li>
023 * <li>image database interface.</li>
024 * </ul>
025 * 
026 * @author Stephane
027 */
028public interface ImageProvider
029{
030    /**
031     * Returns the image metadata in OME format (metadata provides many informations about the image).<br>
032     * <br>
033     * Number of series (mandatory field) :<br>
034     * {@link MetaDataUtil#getNumSeries(OMEXMLMetadata)}<br>
035     * Dimension (mandatory fields) :<br>
036     * {@link MetaDataUtil#getSizeX(OMEXMLMetadata, int)}<br>
037     * {@link MetaDataUtil#getSizeY(OMEXMLMetadata, int)}<br>
038     * {@link MetaDataUtil#getSizeZ(OMEXMLMetadata, int)}<br>
039     * {@link MetaDataUtil#getSizeT(OMEXMLMetadata, int)}<br>
040     * {@link MetaDataUtil#getSizeC(OMEXMLMetadata, int)}<br>
041     * Internal data type (mandatory field) :<br>
042     * {@link MetaDataUtil#getDataType(OMEXMLMetadata, int)}<br>
043     * Physical and time position (mandatory fields) :<br>
044     * {@link MetaDataUtil#getPositionX(OMEXMLMetadata, int, int, int, int, double)}<br>
045     * {@link MetaDataUtil#getPositionY(OMEXMLMetadata, int, int, int, int, double)}<br>
046     * {@link MetaDataUtil#getPositionZ(OMEXMLMetadata, int, int, int, int, double)}<br>
047     * {@link MetaDataUtil#getPositionT(OMEXMLMetadata, int, long)}<br>
048     * {@link MetaDataUtil#getPositionTOffset(OMEXMLMetadata, int, int, int, int, double)}<br>
049     * <br>
050     * and many others informations depending the available metadata in the image format.
051     */
052    public OMEXMLMetadata getOMEXMLMetaData() throws UnsupportedFormatException, IOException;
053
054    /**
055     * @deprecated Use {@link #getOMEXMLMetaData()} instead.
056     */
057    @Deprecated
058    public OMEXMLMetadataImpl getMetaData() throws UnsupportedFormatException, IOException;
059
060    /**
061     * Returns the (optimal) tile width for the specified series of the image.<br>
062     * This method allow to know the best tile size to use when using the sub region image loading
063     * operations.<br>
064     * This method should returns <code>0</code> if tile loading is not supported and <code>-1</code> if any tile size
065     * can be used.
066     * 
067     * @param series
068     *        Series index for multi series image (use 0 if unsure).
069     * @return optimal tile width
070     */
071    public int getTileWidth(int series) throws UnsupportedFormatException, IOException;
072
073    /**
074     * Returns the (optimal) tile height for the specified series of the image.<br>
075     * This method allow to know the best tile size to use when using the sub region image loading
076     * operations.<br>
077     * This method should returns <code>0</code> if tile loading is not supported and <code>-1</code> if any tile size
078     * can be used.
079     * 
080     * @param series
081     *        Series index for multi series image (use 0 if unsure).
082     * @return optimal tile height
083     */
084    public int getTileHeight(int series) throws UnsupportedFormatException, IOException;
085
086    /**
087     * Returns <code>true</code> if the given sub resolution is available from this series.<br>
088     * Note that even if a sub resolution isn't available, the ImageProvider should provide it by generating it manually
089     * (using the {@link IcyBufferedImageUtil#downscaleBy2(IcyBufferedImage, boolean, int)} method.<br>
090     * <br>
091     * Final image resolution can be calculated with: <code>image.originalResolution / (2^resolution)</code><br>
092     * So <i>resolution 0</i> is the original resolution and it's always available (should always returns
093     * <code>true</code>).<br>
094     * <i>Resolution 1</i> is half of the original resolution<br>
095     * <i>Resolution 2</i> is quarter of the original resolution<br>
096     * <i>...</i>
097     * 
098     * @param series
099     *        Series index for multi series image (use 0 if unsure).
100     * @param resolution
101     *        Resolution level
102     */
103    public boolean isResolutionAvailable(int series, int resolution) throws UnsupportedFormatException, IOException;
104
105    /**
106     * Returns the image thumbnail for the specified series of the image.<br>
107     * 
108     * @param series
109     *        Series index for multi series image (use 0 if unsure).
110     * @return thumbnail image.
111     */
112    public IcyBufferedImage getThumbnail(int series)
113            throws UnsupportedFormatException, IOException;
114
115    /**
116     * Returns the pixel data located for specified position of the image.<br>
117     * Data is returned in form of a single dimension array, the type of this array depends from the image data type<br>
118     * which can be retrieve from the metadata (see {@link OMEXMLMetadataImpl#getPixelsType(int)}
119     * 
120     * @param series
121     *        Series index for multi series image (use 0 if unsure).
122     * @param resolution
123     *        Wanted resolution level for the image (use 0 if unsure).<br>
124     *        The retrieved image resolution is equal to <code>image.originalResolution / (2^resolution)</code><br>
125     *        So for instance level 0 is the default image resolution while level 1 is base image
126     *        resolution / 2 and so on...
127     * @param region
128     *        The 2D region we want to retrieve (considering the original image resolution).<br>
129     *        If set to <code>null</code> then the whole image is returned.
130     * @param z
131     *        Z position of the image (slice) we want retrieve data from
132     * @param t
133     *        T position of the image (frame) we want retrieve data from
134     * @param c
135     *        C position of the image (channel) we want retrieve (-1 is not accepted here).
136     * @return native type array containing image pixel data.<br>
137     * @see #isResolutionAvailable(int, int)
138     */
139    public Object getPixels(int series, int resolution, Rectangle region, int z, int t, int c)
140            throws UnsupportedFormatException, IOException;
141
142    /**
143     * Returns the image located at specified position.
144     * 
145     * @param series
146     *        Series index for multi series image (use 0 if unsure).
147     * @param resolution
148     *        Wanted resolution level for the image (use 0 if unsure).<br>
149     *        The retrieved image resolution is equal to <code>image.originalResolution / (2^resolution)</code><br>
150     *        So for instance level 0 is the default image resolution while level 1 is base image
151     *        resolution / 2 and so on...
152     * @param region
153     *        The 2D region we want to retrieve (considering the original image resolution).<br>
154     *        If set to <code>null</code> then the whole image is returned.
155     * @param z
156     *        Z position of the image (slice) we want retrieve
157     * @param t
158     *        T position of the image (frame) we want retrieve
159     * @param c
160     *        C position of the image (channel) we want retrieve (-1 means all channel).
161     * @return image
162     * @see #isResolutionAvailable(int, int)
163     */
164    public IcyBufferedImage getImage(int series, int resolution, Rectangle region, int z, int t, int c)
165            throws UnsupportedFormatException, IOException;
166
167    /**
168     * Returns the image located at specified position.
169     * 
170     * @param series
171     *        Series index for multi series image (use 0 if unsure).
172     * @param resolution
173     *        Wanted resolution level for the image (use 0 if unsure).<br>
174     *        The retrieved image resolution is equal to <code>image.originalResolution / (2^resolution)</code><br>
175     *        So for instance level 0 is the default image resolution while level 1 is base image
176     *        resolution / 2 and so on...
177     * @param region
178     *        The 2D region we want to retrieve (considering the original image resolution).<br>
179     *        If set to <code>null</code> then the whole image is returned.
180     * @param z
181     *        Z position of the image (slice) we want retrieve
182     * @param t
183     *        T position of the image (frame) we want retrieve
184     * @return image
185     * @see #isResolutionAvailable(int, int)
186     */
187    public IcyBufferedImage getImage(int series, int resolution, Rectangle region, int z, int t)
188            throws UnsupportedFormatException, IOException;
189
190    /**
191     * Returns the image located at specified position.
192     * 
193     * @param series
194     *        Series index for multi series image (use 0 if unsure).
195     * @param resolution
196     *        Wanted resolution level for the image (use 0 if unsure).<br>
197     *        The retrieved image resolution is equal to <code>image.originalResolution / (2^resolution)</code><br>
198     *        So for instance level 0 is the default image resolution while level 1 is base image
199     *        resolution / 2 and so on...
200     * @param z
201     *        Z position of the image (slice) we want retrieve
202     * @param t
203     *        T position of the image (frame) we want retrieve
204     * @param c
205     *        C position of the image (channel) we want retrieve (-1 means all channel).
206     * @return image
207     * @see #isResolutionAvailable(int, int)
208     */
209    public IcyBufferedImage getImage(int series, int resolution, int z, int t, int c)
210            throws UnsupportedFormatException, IOException;
211
212    /**
213     * Returns the image located at specified position.
214     * 
215     * @param series
216     *        Series index for multi series image (use 0 if unsure).
217     * @param resolution
218     *        Wanted resolution level for the image (use 0 if unsure).<br>
219     *        The retrieved image resolution is equal to <code>image.originalResolution / (2^resolution)</code><br>
220     *        So for instance level 0 is the default image resolution while level 1 is base image
221     *        resolution / 2 and so on...
222     * @param z
223     *        Z position of the image (slice) we want retrieve
224     * @param t
225     *        T position of the image (frame) we want retrieve
226     * @return image
227     * @see #isResolutionAvailable(int, int)
228     */
229    public IcyBufferedImage getImage(int series, int resolution, int z, int t)
230            throws UnsupportedFormatException, IOException;
231
232    /**
233     * Returns the image located at specified position.
234     * 
235     * @param series
236     *        Series index for multi series image (use 0 if unsure).
237     * @param z
238     *        Z position of the image (slice) we want retrieve
239     * @param t
240     *        T position of the image (frame) we want retrieve
241     * @return image
242     */
243    public IcyBufferedImage getImage(int series, int z, int t)
244            throws UnsupportedFormatException, IOException;
245
246    /**
247     * Returns the image located at specified position.
248     * 
249     * @param z
250     *        Z position of the image (slice) we want retrieve
251     * @param t
252     *        T position of the image (frame) we want retrieve
253     * @return image
254     */
255    public IcyBufferedImage getImage(int z, int t) throws UnsupportedFormatException, IOException;
256}