title: How to invert colors of an image in pygame?
body: <p>I have a pygame Surface and would like to invert the colors.  Is there any way quicker &amp; more pythonic than this?  It's rather slow.</p>
  
  <p>I'm aware that subtracting the value from 255 isn't the only definition of an "inverted color," but it's what I want for now.</p>
  
  <p>I'm surprised that pygame doesn't have something like this built in!</p>
  
  <p>Thanks for your help!</p>
  
  <pre><code>import pygame
  
  def invertImg(img):
      """Inverts the colors of a pygame Screen"""
  
      img.lock()
  
      for x in range(img.get_width()):
          for y in range(img.get_height()):
              RGBA = img.get_at((x,y))
              for i in range(3):
                  # Invert RGB, but not Alpha
                  RGBA[i] = 255 - RGBA[i]
              img.set_at((x,y),RGBA)
  
      img.unlock()
  </code></pre>