Skip to content
Commit 47b207a3 authored by Pino Toscano's avatar Pino Toscano
Browse files

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
parent cde28d76
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment