1- from __future__ import absolute_import
1+ from __future__ import absolute_import , annotations
2+
3+ from typing import Union , TYPE_CHECKING
4+
5+ if TYPE_CHECKING :
6+ from typing import BinaryIO
7+ from rawpy ._rawpy import (
8+ # Module-level attributes
9+ flags ,
10+ libraw_version ,
11+ # Main classes
12+ RawPy ,
13+ Params ,
14+ # Named tuples
15+ ImageSizes ,
16+ Thumbnail ,
17+ # Enums
18+ RawType ,
19+ ThumbFormat ,
20+ DemosaicAlgorithm ,
21+ FBDDNoiseReductionMode ,
22+ ColorSpace ,
23+ HighlightMode ,
24+ # Exceptions
25+ LibRawError ,
26+ LibRawFatalError ,
27+ LibRawNonFatalError ,
28+ LibRawUnspecifiedError ,
29+ LibRawFileUnsupportedError ,
30+ LibRawRequestForNonexistentImageError ,
31+ LibRawOutOfOrderCallError ,
32+ LibRawNoThumbnailError ,
33+ LibRawUnsupportedThumbnailError ,
34+ LibRawInputClosedError ,
35+ LibRawNotImplementedError ,
36+ LibRawUnsufficientMemoryError ,
37+ LibRawDataError ,
38+ LibRawIOError ,
39+ LibRawCancelledByCallbackError ,
40+ LibRawBadCropError ,
41+ LibRawTooBigError ,
42+ LibRawMemPoolOverflowError ,
43+ NotSupportedError ,
44+ )
245
346from ._version import __version__
447
@@ -59,21 +102,26 @@ def _check_multiprocessing_fork():
59102 # multiprocessing not available
60103 pass
61104
62- def imread (pathOrFile , shot_select = 0 ) :
105+ def imread (pathOrFile : Union [ str , BinaryIO ], shot_select : int = 0 ) -> RawPy :
63106 """
64107 Convenience function that creates a :class:`rawpy.RawPy` instance, opens the given file,
65108 and returns the :class:`rawpy.RawPy` instance for further processing.
66109
67- :param str|file pathOrFile: path or file object of RAW image that will be read
68- :param int shot_select: select which image to extract from RAW files that contain multiple images
69- (e.g., Dual Pixel RAW). Default is 0 for the first/main image.
70- :rtype: :class:`rawpy.RawPy`
110+ :param pathOrFile: path or file object of RAW image that will be read
111+ :type pathOrFile: str or file-like object
112+ :param shot_select: select which image to extract from RAW files that contain multiple images
113+ (e.g., Dual Pixel RAW). Default is 0 for the first/main image.
114+ :type shot_select: int
115+ :return: RawPy instance with the opened RAW image
116+ :rtype: rawpy.RawPy
71117 """
72118 _check_multiprocessing_fork ()
73119 d = RawPy ()
74- if hasattr (pathOrFile , 'read' ):
75- d .open_buffer (pathOrFile )
76- else :
120+ if isinstance (pathOrFile , str ):
121+ # pathOrFile is a string file path
77122 d .open_file (pathOrFile )
123+ else :
124+ # pathOrFile is a file-like object with read() method
125+ d .open_buffer (pathOrFile )
78126 d .set_unpack_params (shot_select = shot_select )
79127 return d
0 commit comments