mkiccp.py 992 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. # $URL: http://pypng.googlecode.com/svn/trunk/code/mkiccp.py $
  3. # $Rev: 182 $
  4. # Make ICC Profile
  5. # References
  6. #
  7. # [ICC 2001] ICC Specification ICC.1:2001-04 (Profile version 2.4.0)
  8. # [ICC 2004] ICC Specification ICC.1:2004-10 (Profile version 4.2.0.0)
  9. import struct
  10. # Local module.
  11. import iccp
  12. def black(m):
  13. """Return a function that maps all values from [0.0,m] to 0, and maps
  14. the range [m,1.0] into [0.0, 1.0] linearly.
  15. """
  16. m = float(m)
  17. def f(x):
  18. if x <= m:
  19. return 0.0
  20. return (x-m)/(1.0-m)
  21. return f
  22. # For monochrome input the required tags are (See [ICC 2001] 6.3.1.1):
  23. # profileDescription [ICC 2001] 6.4.32
  24. # grayTRC [ICC 2001] 6.4.19
  25. # mediaWhitePoint [ICC 2001] 6.4.25
  26. # copyright [ICC 2001] 6.4.13
  27. def agreyprofile(out):
  28. it = iccp.Profile().greyInput()
  29. it.addTags(kTRC=black(0.07))
  30. it.write(out)
  31. def main():
  32. import sys
  33. agreyprofile(sys.stdout)
  34. if __name__ == '__main__':
  35. main()