Changeset 278 for pkpgcounter

Show
Ignore:
Timestamp:
11/02/05 20:35:58 (18 years ago)
Author:
jerome
Message:

Now much faster even without Psyco. In any case, the time will be spent
in GhostScript?, not in my routines.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/inkcoverage.py

    r277 r278  
    2424import sys 
    2525 
    26 import psyco 
    27  
    2826from PIL import Image 
    2927 
     
    4240    nbpix = sum(r) 
    4341    for histo in (r, g, b) : 
    44         value = 0 
    45         for i in range(len(histo)) : 
    46             value += histo[i] * (255 - i) 
    47         result.append((100 * (value / 255.0)) / nbpix) 
     42        result.append((100 * (reduce(lambda x,y: x + (y[1] * (255 - y[0])), enumerate(histo), 0) / 255.0)) / nbpix) 
    4843    return tuple(result)         
    4944 
    5045if __name__ == "__main__" : 
    51     psyco.bind(percent_cmy) 
    5246    print percent_cmy(sys.argv[1])