@@ -186,14 +186,20 @@ def _Image_fromarray(
186186 https://pillow.readthedocs.io/en/stable/releasenotes/11.3.0.html#image-fromarray-mode-parameter
187187 """
188188 if PILLOW_VERSION >= (11 , 3 ):
189- # We actually rely on the old behavior of Image.fromarray():
189+ # The actual PR that implements the deprecation has more context for why
190+ # it was done, and also points out some problems:
190191 #
191- # new behavior: PIL will infer the image mode from the data passed in.
192- # That is, the type and shape determines the mode.
192+ # https://github.com/python-pillow/Pillow/pull/9018
193193 #
194- # old behiavor: The mode will change how PIL reads the image,
195- # regardless of the data. That is, it will make the data
196- # work with the mode.
194+ # Our use case falls into those problems. We actually rely on the old
195+ # behavior of Image.fromarray():
196+ #
197+ # new behavior: PIL will infer the image mode from the data passed
198+ # in. That is, the type and shape determines the mode.
199+ #
200+ # old behiavor: The mode will change how PIL reads the image,
201+ # regardless of the data. That is, it will make the
202+ # data work with the mode.
197203 #
198204 # Our uses of Image.fromarray() are effectively a "turn into PIL image
199205 # AND convert the kind" operation. In particular, in
@@ -211,6 +217,13 @@ def _Image_fromarray(
211217 # img = img.convert(mode)
212218 #
213219 # The resulting image has very different actual pixel values than before.
220+ #
221+ # TODO: Issue #9151. Pillow has an open PR to restore the functionality
222+ # we rely on:
223+ #
224+ # https://github.com/python-pillow/Pillow/pull/9063
225+ #
226+ # When that is part of a release, we can revisit this hack below.
214227 arr = obj .__array_interface__
215228 shape = arr ["shape" ]
216229 ndim = len (shape )
0 commit comments