title: Pillow: image.getcolors(maxcolors) returns None unless maxcolors ≥ 148279
body: <p>I'm using <a href="https://pillow.readthedocs.io/en/3.1.x/handbook/index.html" rel="nofollow noreferrer">Pillow</a> to read an image, and get all its colours with <code>Image.getcolors()</code>. From the <a href="https://pillow.readthedocs.io/en/3.1.x/reference/Image.html#PIL.Image.Image.getcolors" rel="nofollow noreferrer"><code>getcolors()</code> reference page</a>:</p>
  
  <blockquote>
    <p><code>Image.getcolors(maxcolors=256)</code></p>
    
    <p>Returns a list of colors used in this image.<br>
    Parameters:    maxcolors – Maximum number of colors. If this number is exceeded, this method returns None. The default limit is 256
    colors.<br>
    Returns:   An unsorted list of (count, pixel) values.</p>
  </blockquote>
  
  <p>I am using the following code snippet to load an image, <a href="https://i.stack.imgur.com/JkyCi.png" rel="nofollow noreferrer">lena.png</a>.</p>
  
  <pre><code>from PIL import Image
  
  def main(filename):
      with Image.open(filename) as image:
          colors = image.getcolors(maxcolors) #where maxcolors is some value, as explained below
          print(colors)
  
  if __name__ == "__main__":
      main("lena.png")
  </code></pre>
  
  <p>This will print <code>None</code> if <code>image.getcolors()</code> recieves no argument or <code>maxcolors &lt; 148279</code>. If <code>maxcolors &gt;= 148279</code>, the values are printed as expected. The output is along the lines of <code>[(1, (233, 130, 132)), (1, (243, 205, 168)),</code>...<code>(1, (223, 140, 118))]</code>, a list of tuples containing the occurence of the colour first, and a tuple of the RGB values second. I checked the output, and there is not one single value greater than <code>255</code>.</p>
  
  <p>When using another image, <a href="https://i.stack.imgur.com/6Rpq6.jpg" rel="nofollow noreferrer">test.jpg</a>, the same occurs. There seems to be no correlation to filetype or dimension. Adding <code>image.load()</code> above <code>colors = ...</code> does not change this either. <code>148279</code> is a <em>prime</em>, which makes this seem even weirder to me.</p>
  
  <h1>Why does <code>getcolors()</code> not work as intended with the default value, and why does it work with <code>148279</code>?</h1>