5252}
5353
5454
55- def decode (arr , colourspace = 'YBR_FULL' , reshape = True ):
55+ def decode (arr , colour_transform = 0 , reshape = True ):
5656 """Return the decoded JPEG data from `arr` as a :class:`numpy.ndarray`.
5757
5858 Parameters
5959 ----------
6060 arr : numpy.ndarray or bytes
6161 A 1D array of ``np.uint8``, or a Python :class:`bytes` object
6262 containing the encoded JPEG image.
63- colourspace : str, optional
64- One of ``'MONOCHROME1'``, ``'MONOCHROME2'``, ``'RGB'``, ``'YBR_FULL'``,
65- ``'YBR_FULL_422'``.
63+ colour_transform : int, optional
64+ The colour transform used, one of:
65+ | ``0`` : No transform applied (default)
66+ | ``1`` : RGB to YCbCr
67+ | ``2`` : JPEG-LS pseudo RCT or RCT
68+ | ``3`` : Freeform
6669 reshape : bool, optional
6770 Reshape and review the output array so it matches the image data
6871 (default), otherwise return a 1D array of ``np.uint8``.
@@ -77,28 +80,10 @@ def decode(arr, colourspace='YBR_FULL', reshape=True):
7780 RuntimeError
7881 If the decoding failed.
7982 """
80- colours = {
81- 'MONOCHROME1' : 0 ,
82- 'MONOCHROME2' : 0 ,
83- 'RGB' : 1 ,
84- 'YBR_FULL' : 0 ,
85- 'YBR_FULL_422' : 0 ,
86- - 1 : - 1 , # For unit testing only
87- }
88-
89- try :
90- transform = colours [colourspace ]
91- except KeyError :
92- warnings .warn (
93- "Unsupported colour space '{}', no colour transform will "
94- "be applied" .format (colourspace )
95- )
96- transform = 0
97-
9883 if isinstance (arr , bytes ):
9984 arr = np .frombuffer (arr , 'uint8' )
10085
101- status , out , params = _libjpeg .decode (arr , transform )
86+ status , out , params = _libjpeg .decode (arr , colour_transform )
10287 status = status .decode ("utf-8" )
10388 code , msg = status .split ("::::" )
10489 code = int (code )
@@ -128,6 +113,49 @@ def decode(arr, colourspace='YBR_FULL', reshape=True):
128113 )
129114
130115
116+ def decode_pixel_data (arr , photometric_interp ):
117+ """Return the decoded JPEG data from `arr` as a :class:`numpy.ndarray`.
118+
119+ Parameters
120+ ----------
121+ arr : numpy.ndarray or bytes
122+ A 1D array of ``np.uint8``, or a Python :class:`bytes` object
123+ containing the encoded JPEG image.
124+ photometric_interp : str
125+ The (0028,0004) *Photometric Interpretation* of the pixel data, one of
126+ ``'MONOCHROME1'``, ``'MONOCHROME2'``, ``'RGB'``, ``'YBR_FULL'``,
127+ ``'YBR_FULL_422'``.
128+
129+ Returns
130+ -------
131+ numpy.ndarray
132+ A 1D array of ``numpy.uint8`` containing the decoded image data.
133+
134+ Raises
135+ ------
136+ RuntimeError
137+ If the decoding failed.
138+ """
139+ colours = {
140+ 'MONOCHROME1' : 0 ,
141+ 'MONOCHROME2' : 0 ,
142+ 'RGB' : 1 ,
143+ 'YBR_FULL' : 0 ,
144+ 'YBR_FULL_422' : 0 ,
145+ }
146+
147+ try :
148+ transform = colours [photometric_interp ]
149+ except KeyError :
150+ warnings .warn (
151+ "Unsupported (0028,0004) Photometric Interpretation '{}', no "
152+ "colour transformation will be applied" .format (photometric_interp )
153+ )
154+ transform = 0
155+
156+ return decode (arr , transform , reshape = False )
157+
158+
131159def get_parameters (arr ):
132160 """Return a :class:`dict` containing JPEG image parameters.
133161
0 commit comments