prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  [documents] Add basic document reader
  For documents to be analyzed, we first need to add a utility for document reading (PDF mostly). The following specs would be nice to have:
  - inherit for a shared reader class ("DocumentReader" for instance)
  - to be located in the `doctr.documents.reader`  module
  
  The following formats should be handled:
  - [x] PDF (#8, #25): this resource would be nice to check: https://github.com/pymupdf/PyMuPDF
  - [x] PNG (#30)
  - [x] JPG (#30)
  
  
  cc @charlesmindee 
  
  </issue>
  <code>
  [start of doctr/documents/reader.py]
  1 # Copyright (C) 2021, Mindee.
  2 
  3 # This program is licensed under the Apache License version 2.
  4 # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.
  5 
  6 import fitz
  7 import numpy as np
  8 import cv2
  9 from typing import List, Tuple, Optional, Any
  10 
  11 __all__ = ['read_pdf']
  12 
  13 
  14 def read_pdf(file_path: str, **kwargs: Any) -> List[np.ndarray]:
  15     """Read a PDF file and convert it into an image in numpy format
  16 
  17     Example::
  18         >>> from doctr.documents import read_pdf
  19         >>> doc = read_pdf("path/to/your/doc.pdf")
  20 
  21     Args:
  22         file_path: the path to the PDF file
  23     Returns:
  24         the list of pages decoded as numpy ndarray of shape H x W x 3
  25     """
  26 
  27     # Read pages with fitz and convert them to numpy ndarrays
  28     return [convert_page_to_numpy(page, **kwargs) for page in fitz.open(file_path)]
  29 
  30 
  31 def convert_page_to_numpy(
  32     page: fitz.fitz.Page,
  33     output_size: Optional[Tuple[int, int]] = None,
  34     rgb_output: bool = True,
  35 ) -> np.ndarray:
  36     """Convert a fitz page to a numpy-formatted image
  37 
  38     Args:
  39         page: the page of a file read with PyMuPDF
  40         output_size: the expected output size of each page in format H x W
  41         rgb_output: whether the output ndarray channel order should be RGB instead of BGR.
  42 
  43     Returns:
  44         the rendered image in numpy format
  45     """
  46 
  47     transform_matrix = None
  48 
  49     # If no output size is specified, keep the origin one
  50     if output_size is not None:
  51         scales = (output_size[1] / page.MediaBox[2], output_size[0] / page.MediaBox[3])
  52         transform_matrix = fitz.Matrix(*scales)
  53 
  54     # Generate the pixel map using the transformation matrix
  55     stream = page.getPixmap(matrix=transform_matrix).getImageData()
  56     # Decode it into a numpy
  57     img = cv2.imdecode(np.frombuffer(stream, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
  58 
  59     # Switch the channel order
  60     if rgb_output:
  61         img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  62 
  63     return img
  64
  [end of doctr/documents/reader.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/doctr/documents/reader.py b/doctr/documents/reader.py
  --- a/doctr/documents/reader.py
  +++ b/doctr/documents/reader.py
  @@ -8,7 +8,36 @@
   import cv2
   from typing import List, Tuple, Optional, Any
   
  -__all__ = ['read_pdf']
  +__all__ = ['read_pdf', 'read_img']
  +
  +
  +def read_img(
  +    file_path: str,
  +    output_size: Optional[Tuple[int, int]] = None,
  +    rgb_output: bool = True,
  +) -> np.ndarray:
  +    """Read an image file into numpy format
  +
  +    Example::
  +        >>> from doctr.documents import read_img
  +        >>> page = read_img("path/to/your/doc.jpg")
  +
  +    Args:
  +        file_path: the path to the image file
  +        output_size: the expected output size of each page in format H x W
  +        rgb_output: whether the output ndarray channel order should be RGB instead of BGR.
  +    Returns:
  +        the page decoded as numpy ndarray of shape H x W x 3
  +    """
  +
  +    img = cv2.imread(file_path, cv2.IMREAD_COLOR)
  +    # Resizing
  +    if isinstance(output_size, tuple):
  +        img = cv2.resize(img, output_size[::-1], interpolation=cv2.INTER_LINEAR)
  +    # Switch the channel order
  +    if rgb_output:
  +        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  +    return img
   
   
   def read_pdf(file_path: str, **kwargs: Any) -> List[np.ndarray]:
  
verification_info: {"golden_diff": "diff --git a/doctr/documents/reader.py b/doctr/documents/reader.py\n--- a/doctr/documents/reader.py\n+++ b/doctr/documents/reader.py\n@@ -8,7 +8,36 @@\n import cv2\n from typing import List, Tuple, Optional, Any\n \n-__all__ = ['read_pdf']\n+__all__ = ['read_pdf', 'read_img']\n+\n+\n+def read_img(\n+    file_path: str,\n+    output_size: Optional[Tuple[int, int]] = None,\n+    rgb_output: bool = True,\n+) -> np.ndarray:\n+    \"\"\"Read an image file into numpy format\n+\n+    Example::\n+        >>> from doctr.documents import read_img\n+        >>> page = read_img(\"path/to/your/doc.jpg\")\n+\n+    Args:\n+        file_path: the path to the image file\n+        output_size: the expected output size of each page in format H x W\n+        rgb_output: whether the output ndarray channel order should be RGB instead of BGR.\n+    Returns:\n+        the page decoded as numpy ndarray of shape H x W x 3\n+    \"\"\"\n+\n+    img = cv2.imread(file_path, cv2.IMREAD_COLOR)\n+    # Resizing\n+    if isinstance(output_size, tuple):\n+        img = cv2.resize(img, output_size[::-1], interpolation=cv2.INTER_LINEAR)\n+    # Switch the channel order\n+    if rgb_output:\n+        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n+    return img\n \n \n def read_pdf(file_path: str, **kwargs: Any) -> List[np.ndarray]:\n", "issue": "[documents] Add basic document reader\nFor documents to be analyzed, we first need to add a utility for document reading (PDF mostly). The following specs would be nice to have:\r\n- inherit for a shared reader class (\"DocumentReader\" for instance)\r\n- to be located in the `doctr.documents.reader`  module\r\n\r\nThe following formats should be handled:\r\n- [x] PDF (#8, #25): this resource would be nice to check: https://github.com/pymupdf/PyMuPDF\r\n- [x] PNG (#30)\r\n- [x] JPG (#30)\r\n\r\n\r\ncc @charlesmindee \n", "before_files": [{"content": "# Copyright (C) 2021, Mindee.\n\n# This program is licensed under the Apache License version 2.\n# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.\n\nimport fitz\nimport numpy as np\nimport cv2\nfrom typing import List, Tuple, Optional, Any\n\n__all__ = ['read_pdf']\n\n\ndef read_pdf(file_path: str, **kwargs: Any) -> List[np.ndarray]:\n    \"\"\"Read a PDF file and convert it into an image in numpy format\n\n    Example::\n        >>> from doctr.documents import read_pdf\n        >>> doc = read_pdf(\"path/to/your/doc.pdf\")\n\n    Args:\n        file_path: the path to the PDF file\n    Returns:\n        the list of pages decoded as numpy ndarray of shape H x W x 3\n    \"\"\"\n\n    # Read pages with fitz and convert them to numpy ndarrays\n    return [convert_page_to_numpy(page, **kwargs) for page in fitz.open(file_path)]\n\n\ndef convert_page_to_numpy(\n    page: fitz.fitz.Page,\n    output_size: Optional[Tuple[int, int]] = None,\n    rgb_output: bool = True,\n) -> np.ndarray:\n    \"\"\"Convert a fitz page to a numpy-formatted image\n\n    Args:\n        page: the page of a file read with PyMuPDF\n        output_size: the expected output size of each page in format H x W\n        rgb_output: whether the output ndarray channel order should be RGB instead of BGR.\n\n    Returns:\n        the rendered image in numpy format\n    \"\"\"\n\n    transform_matrix = None\n\n    # If no output size is specified, keep the origin one\n    if output_size is not None:\n        scales = (output_size[1] / page.MediaBox[2], output_size[0] / page.MediaBox[3])\n        transform_matrix = fitz.Matrix(*scales)\n\n    # Generate the pixel map using the transformation matrix\n    stream = page.getPixmap(matrix=transform_matrix).getImageData()\n    # Decode it into a numpy\n    img = cv2.imdecode(np.frombuffer(stream, dtype=np.uint8), cv2.IMREAD_UNCHANGED)\n\n    # Switch the channel order\n    if rgb_output:\n        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n\n    return img\n", "path": "doctr/documents/reader.py"}]}