~neon/kgeography/master

Viewing all changes in revision 943.

  • Committer: Pino Toscano
  • Date: 2020-06-18 21:00:42 UTC
  • Revision ID: git-v1:47b207a32d554fb2472bb77b0d3e20ad61150c65
colorcheker.py: switch from QImage to PIL

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

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: