/Doc/library/jpeg.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 95 lines · 65 code · 30 blank · 0 comment · 0 complexity · 4a5daad9958c14f8bdac9690ced6363e MD5 · raw file

  1. :mod:`jpeg` --- Read and write JPEG files
  2. =========================================
  3. .. module:: jpeg
  4. :platform: IRIX
  5. :synopsis: Read and write image files in compressed JPEG format.
  6. :deprecated:
  7. .. deprecated:: 2.6
  8. The :mod:`jpeg` module has been deprecated for removal in Python 3.0.
  9. .. index:: single: Independent JPEG Group
  10. The module :mod:`jpeg` provides access to the jpeg compressor and decompressor
  11. written by the Independent JPEG Group (IJG). JPEG is a standard for compressing
  12. pictures; it is defined in ISO 10918. For details on JPEG or the Independent
  13. JPEG Group software refer to the JPEG standard or the documentation provided
  14. with the software.
  15. .. index::
  16. single: Python Imaging Library
  17. single: PIL (the Python Imaging Library)
  18. single: Lundh, Fredrik
  19. A portable interface to JPEG image files is available with the Python Imaging
  20. Library (PIL) by Fredrik Lundh. Information on PIL is available at
  21. http://www.pythonware.com/products/pil/.
  22. The :mod:`jpeg` module defines an exception and some functions.
  23. .. exception:: error
  24. Exception raised by :func:`compress` and :func:`decompress` in case of errors.
  25. .. function:: compress(data, w, h, b)
  26. .. index:: single: JFIF
  27. Treat data as a pixmap of width *w* and height *h*, with *b* bytes per pixel.
  28. The data is in SGI GL order, so the first pixel is in the lower-left corner.
  29. This means that :func:`gl.lrectread` return data can immediately be passed to
  30. :func:`compress`. Currently only 1 byte and 4 byte pixels are allowed, the
  31. former being treated as greyscale and the latter as RGB color. :func:`compress`
  32. returns a string that contains the compressed picture, in JFIF format.
  33. .. function:: decompress(data)
  34. .. index:: single: JFIF
  35. Data is a string containing a picture in JFIF format. It returns a tuple
  36. ``(data, width, height, bytesperpixel)``. Again, the data is suitable to pass
  37. to :func:`gl.lrectwrite`.
  38. .. function:: setoption(name, value)
  39. Set various options. Subsequent :func:`compress` and :func:`decompress` calls
  40. will use these options. The following options are available:
  41. +-----------------+---------------------------------------------+
  42. | Option | Effect |
  43. +=================+=============================================+
  44. | ``'forcegray'`` | Force output to be grayscale, even if input |
  45. | | is RGB. |
  46. +-----------------+---------------------------------------------+
  47. | ``'quality'`` | Set the quality of the compressed image to |
  48. | | a value between ``0`` and ``100`` (default |
  49. | | is ``75``). This only affects compression. |
  50. +-----------------+---------------------------------------------+
  51. | ``'optimize'`` | Perform Huffman table optimization. Takes |
  52. | | longer, but results in smaller compressed |
  53. | | image. This only affects compression. |
  54. +-----------------+---------------------------------------------+
  55. | ``'smooth'`` | Perform inter-block smoothing on |
  56. | | uncompressed image. Only useful for low- |
  57. | | quality images. This only affects |
  58. | | decompression. |
  59. +-----------------+---------------------------------------------+
  60. .. seealso::
  61. JPEG Still Image Data Compression Standard
  62. The canonical reference for the JPEG image format, by Pennebaker and Mitchell.
  63. `Information Technology - Digital Compression and Coding of Continuous-tone Still Images - Requirements and Guidelines <http://www.w3.org/Graphics/JPEG/itu-t81.pdf>`_
  64. The ISO standard for JPEG is also published as ITU T.81. This is available
  65. online in PDF form.