Skip to content
  • Pino Toscano's avatar
    colorcheker.py: switch from QImage to PIL · 47b207a3
    Pino Toscano authored
    QImage is simply too slow, and it does not have optimized ways to get
    the color statistics of an image; because of this, the only way to get
    the information needed is to iterate pixel by pixel, which is super
    slow.
    
    As solution, switch to a different Python library, PIL, which is
    designed for image manipulation: it has fast color statistics which
    avoid the need to iterate by pixel just to know which colors the image
    has. This also switches away from QRgba in favour of a simple (R,G,B,A)
    tuple. The iteration by pixel is done only in case the image has some
    color not referenced by the map, and we want to print to the user the
    coordinate of the first pixel of it.
    
    This speeds up dramatically the validation of all the maps at once, i.e
      $ time python3 tools/colorchecker.py data/*.kgm
    on my local machine, the results were
    - before this patch: ~5m 15s (~135s)
    - after this patch: < 5s
    47b207a3