/Doc/library/imageop.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 107 lines · 62 code · 45 blank · 0 comment · 0 complexity · 4a980760678bfcc6c48172b37b0ce70d MD5 · raw file

  1. :mod:`imageop` --- Manipulate raw image data
  2. ============================================
  3. .. module:: imageop
  4. :synopsis: Manipulate raw image data.
  5. :deprecated:
  6. .. deprecated:: 2.6
  7. The :mod:`imageop` module has been removed in Python 3.0.
  8. The :mod:`imageop` module contains some useful operations on images. It operates
  9. on images consisting of 8 or 32 bit pixels stored in Python strings. This is
  10. the same format as used by :func:`gl.lrectwrite` and the :mod:`imgfile` module.
  11. The module defines the following variables and functions:
  12. .. exception:: error
  13. This exception is raised on all errors, such as unknown number of bits per
  14. pixel, etc.
  15. .. function:: crop(image, psize, width, height, x0, y0, x1, y1)
  16. Return the selected part of *image*, which should be *width* by *height* in size
  17. and consist of pixels of *psize* bytes. *x0*, *y0*, *x1* and *y1* are like the
  18. :func:`gl.lrectread` parameters, i.e. the boundary is included in the new image.
  19. The new boundaries need not be inside the picture. Pixels that fall outside the
  20. old image will have their value set to zero. If *x0* is bigger than *x1* the
  21. new image is mirrored. The same holds for the y coordinates.
  22. .. function:: scale(image, psize, width, height, newwidth, newheight)
  23. Return *image* scaled to size *newwidth* by *newheight*. No interpolation is
  24. done, scaling is done by simple-minded pixel duplication or removal. Therefore,
  25. computer-generated images or dithered images will not look nice after scaling.
  26. .. function:: tovideo(image, psize, width, height)
  27. Run a vertical low-pass filter over an image. It does so by computing each
  28. destination pixel as the average of two vertically-aligned source pixels. The
  29. main use of this routine is to forestall excessive flicker if the image is
  30. displayed on a video device that uses interlacing, hence the name.
  31. .. function:: grey2mono(image, width, height, threshold)
  32. Convert a 8-bit deep greyscale image to a 1-bit deep image by thresholding all
  33. the pixels. The resulting image is tightly packed and is probably only useful
  34. as an argument to :func:`mono2grey`.
  35. .. function:: dither2mono(image, width, height)
  36. Convert an 8-bit greyscale image to a 1-bit monochrome image using a
  37. (simple-minded) dithering algorithm.
  38. .. function:: mono2grey(image, width, height, p0, p1)
  39. Convert a 1-bit monochrome image to an 8 bit greyscale or color image. All
  40. pixels that are zero-valued on input get value *p0* on output and all one-value
  41. input pixels get value *p1* on output. To convert a monochrome black-and-white
  42. image to greyscale pass the values ``0`` and ``255`` respectively.
  43. .. function:: grey2grey4(image, width, height)
  44. Convert an 8-bit greyscale image to a 4-bit greyscale image without dithering.
  45. .. function:: grey2grey2(image, width, height)
  46. Convert an 8-bit greyscale image to a 2-bit greyscale image without dithering.
  47. .. function:: dither2grey2(image, width, height)
  48. Convert an 8-bit greyscale image to a 2-bit greyscale image with dithering. As
  49. for :func:`dither2mono`, the dithering algorithm is currently very simple.
  50. .. function:: grey42grey(image, width, height)
  51. Convert a 4-bit greyscale image to an 8-bit greyscale image.
  52. .. function:: grey22grey(image, width, height)
  53. Convert a 2-bit greyscale image to an 8-bit greyscale image.
  54. .. data:: backward_compatible
  55. If set to 0, the functions in this module use a non-backward compatible way
  56. of representing multi-byte pixels on little-endian systems. The SGI for
  57. which this module was originally written is a big-endian system, so setting
  58. this variable will have no effect. However, the code wasn't originally
  59. intended to run on anything else, so it made assumptions about byte order
  60. which are not universal. Setting this variable to 0 will cause the byte
  61. order to be reversed on little-endian systems, so that it then is the same as
  62. on big-endian systems.