prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Use pillow to replace opencv in reference evaluator
  Caveat: https://github.com/python-pillow/Pillow/issues/6047#issuecomment-1038150443
  
  cc @jcwchen 
  
  </issue>
  <code>
  [start of onnx/reference/ops/op_image_decoder.py]
  1 # Copyright (c) ONNX Project Contributors
  2 
  3 # SPDX-License-Identifier: Apache-2.0
  4 # pylint: disable=C0123,C3001,R0912,R0913,R0914,R1730,W0221,W0613
  5 
  6 import numpy as np
  7 
  8 from onnx.reference.op_run import OpRun
  9 
  10 
  11 class ImageDecoder(OpRun):
  12     def _run(  # type: ignore
  13         self,
  14         encoded,
  15         pixel_format="RGB",
  16     ):
  17         try:
  18             # pylint: disable=import-outside-toplevel`
  19             import cv2
  20         except ImportError as e:
  21             raise ImportError(
  22                 "opencv-python must be installed to use the reference implementation of the ImageDecoder operator"
  23             ) from e
  24         decoded = None
  25         if pixel_format == "BGR":
  26             decoded = cv2.imdecode(encoded, cv2.IMREAD_COLOR)
  27         elif pixel_format == "RGB":
  28             decoded = cv2.imdecode(encoded, cv2.IMREAD_COLOR)
  29             decoded = cv2.cvtColor(decoded, cv2.COLOR_BGR2RGB)
  30         elif pixel_format == "Grayscale":
  31             decoded = cv2.imdecode(encoded, cv2.IMREAD_GRAYSCALE)
  32             decoded = np.expand_dims(decoded, axis=2)  # (H, W) to (H, W, 1)
  33         else:
  34             raise RuntimeError(f"pixel_format={pixel_format!r} is not supported.")
  35         return (decoded,)
  36
  [end of onnx/reference/ops/op_image_decoder.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/onnx/reference/ops/op_image_decoder.py b/onnx/reference/ops/op_image_decoder.py
  --- a/onnx/reference/ops/op_image_decoder.py
  +++ b/onnx/reference/ops/op_image_decoder.py
  @@ -1,7 +1,10 @@
   # Copyright (c) ONNX Project Contributors
   
   # SPDX-License-Identifier: Apache-2.0
  -# pylint: disable=C0123,C3001,R0912,R0913,R0914,R1730,W0221,W0613
  +
  +from __future__ import annotations
  +
  +import io
   
   import numpy as np
   
  @@ -9,27 +12,22 @@
   
   
   class ImageDecoder(OpRun):
  -    def _run(  # type: ignore
  -        self,
  -        encoded,
  -        pixel_format="RGB",
  -    ):
  +    def _run(self, encoded: np.ndarray, pixel_format="RGB") -> tuple[np.ndarray]:  # type: ignore
           try:
  -            # pylint: disable=import-outside-toplevel`
  -            import cv2
  +            import PIL.Image  # pylint: disable=import-outside-toplevel
           except ImportError as e:
               raise ImportError(
  -                "opencv-python must be installed to use the reference implementation of the ImageDecoder operator"
  +                "Pillow must be installed to use the reference implementation of the ImageDecoder operator"
               ) from e
  -        decoded = None
  +        img = PIL.Image.open(io.BytesIO(encoded.tobytes()))
           if pixel_format == "BGR":
  -            decoded = cv2.imdecode(encoded, cv2.IMREAD_COLOR)
  +            decoded = np.array(img)[:, :, ::-1]
           elif pixel_format == "RGB":
  -            decoded = cv2.imdecode(encoded, cv2.IMREAD_COLOR)
  -            decoded = cv2.cvtColor(decoded, cv2.COLOR_BGR2RGB)
  +            decoded = np.array(img)
           elif pixel_format == "Grayscale":
  -            decoded = cv2.imdecode(encoded, cv2.IMREAD_GRAYSCALE)
  +            img = img.convert("L")
  +            decoded = np.array(img)
               decoded = np.expand_dims(decoded, axis=2)  # (H, W) to (H, W, 1)
           else:
  -            raise RuntimeError(f"pixel_format={pixel_format!r} is not supported.")
  +            raise ValueError(f"pixel_format={pixel_format!r} is not supported.")
           return (decoded,)
  
verification_info: {"golden_diff": "diff --git a/onnx/reference/ops/op_image_decoder.py b/onnx/reference/ops/op_image_decoder.py\n--- a/onnx/reference/ops/op_image_decoder.py\n+++ b/onnx/reference/ops/op_image_decoder.py\n@@ -1,7 +1,10 @@\n # Copyright (c) ONNX Project Contributors\n \n # SPDX-License-Identifier: Apache-2.0\n-# pylint: disable=C0123,C3001,R0912,R0913,R0914,R1730,W0221,W0613\n+\n+from __future__ import annotations\n+\n+import io\n \n import numpy as np\n \n@@ -9,27 +12,22 @@\n \n \n class ImageDecoder(OpRun):\n-    def _run(  # type: ignore\n-        self,\n-        encoded,\n-        pixel_format=\"RGB\",\n-    ):\n+    def _run(self, encoded: np.ndarray, pixel_format=\"RGB\") -> tuple[np.ndarray]:  # type: ignore\n         try:\n-            # pylint: disable=import-outside-toplevel`\n-            import cv2\n+            import PIL.Image  # pylint: disable=import-outside-toplevel\n         except ImportError as e:\n             raise ImportError(\n-                \"opencv-python must be installed to use the reference implementation of the ImageDecoder operator\"\n+                \"Pillow must be installed to use the reference implementation of the ImageDecoder operator\"\n             ) from e\n-        decoded = None\n+        img = PIL.Image.open(io.BytesIO(encoded.tobytes()))\n         if pixel_format == \"BGR\":\n-            decoded = cv2.imdecode(encoded, cv2.IMREAD_COLOR)\n+            decoded = np.array(img)[:, :, ::-1]\n         elif pixel_format == \"RGB\":\n-            decoded = cv2.imdecode(encoded, cv2.IMREAD_COLOR)\n-            decoded = cv2.cvtColor(decoded, cv2.COLOR_BGR2RGB)\n+            decoded = np.array(img)\n         elif pixel_format == \"Grayscale\":\n-            decoded = cv2.imdecode(encoded, cv2.IMREAD_GRAYSCALE)\n+            img = img.convert(\"L\")\n+            decoded = np.array(img)\n             decoded = np.expand_dims(decoded, axis=2)  # (H, W) to (H, W, 1)\n         else:\n-            raise RuntimeError(f\"pixel_format={pixel_format!r} is not supported.\")\n+            raise ValueError(f\"pixel_format={pixel_format!r} is not supported.\")\n         return (decoded,)\n", "issue": "Use pillow to replace opencv in reference evaluator\nCaveat: https://github.com/python-pillow/Pillow/issues/6047#issuecomment-1038150443\r\n\r\ncc @jcwchen \n", "before_files": [{"content": "# Copyright (c) ONNX Project Contributors\n\n# SPDX-License-Identifier: Apache-2.0\n# pylint: disable=C0123,C3001,R0912,R0913,R0914,R1730,W0221,W0613\n\nimport numpy as np\n\nfrom onnx.reference.op_run import OpRun\n\n\nclass ImageDecoder(OpRun):\n    def _run(  # type: ignore\n        self,\n        encoded,\n        pixel_format=\"RGB\",\n    ):\n        try:\n            # pylint: disable=import-outside-toplevel`\n            import cv2\n        except ImportError as e:\n            raise ImportError(\n                \"opencv-python must be installed to use the reference implementation of the ImageDecoder operator\"\n            ) from e\n        decoded = None\n        if pixel_format == \"BGR\":\n            decoded = cv2.imdecode(encoded, cv2.IMREAD_COLOR)\n        elif pixel_format == \"RGB\":\n            decoded = cv2.imdecode(encoded, cv2.IMREAD_COLOR)\n            decoded = cv2.cvtColor(decoded, cv2.COLOR_BGR2RGB)\n        elif pixel_format == \"Grayscale\":\n            decoded = cv2.imdecode(encoded, cv2.IMREAD_GRAYSCALE)\n            decoded = np.expand_dims(decoded, axis=2)  # (H, W) to (H, W, 1)\n        else:\n            raise RuntimeError(f\"pixel_format={pixel_format!r} is not supported.\")\n        return (decoded,)\n", "path": "onnx/reference/ops/op_image_decoder.py"}]}