Geometry and colors
===================

Geometry
--------

Transformations
~~~~~~~~~~~~~~~

.. currentmodule:: djvu.decode
.. class:: AffineTransform((x0, y0, w0, h0), (x1, y1, w1, h1))

   The object represents an affine coordinate transformation that maps points
   from rectangle (`x0`, `y0`, `w0`, `h0`) to rectangle (`x1`, `y1`, `w1`, `h1`).

   .. method:: rotate(n)

      Rotate the output rectangle counter-clockwise by `n` degrees. 

   .. method:: apply((x, y))
               apply((x, y, w, h))

      Apply the coordinate transform to a point or a rectangle.

   .. method:: inverse((x, y))
               inverse((x, y, w, h))

      Apply the inverse coordinate transform to a point or a rectangle.

   .. method:: mirror_x()

      Reverse the X coordinates of the output rectangle.

   .. method:: mirror_y()

      Reverse the Y coordinates of the output rectangle.

Pixel formats
-------------

.. currentmodule:: djvu.decode
.. class:: PixelFormat

   Abstract base for all pixel formats.

   Inheritance diagram:

      .. inheritance-diagram:: 
         PixelFormatRgb
         PixelFormatRgbMask
         PixelFormatGrey
         PixelFormatPalette
         PixelFormatPackedBits
         :parts: 1

.. currentmodule:: djvu.decode
.. class:: PixelFormatRgb([byteorder='RGB'])

   24-bit pixel format, with:

   - RGB (`byteorder` = ``'RGB'``) or
   - BGR (`byteorder` = ``'BGR'``)

   byte order.

.. currentmodule:: djvu.decode
.. class::
   PixelFormatRgbMask(red_mask, green_mask, blue_mask[, xor_value], bpp=16)
   PixelFormatRgbMask(red_mask, green_mask, blue_mask[, xor_value], bpp=32)

   `red_mask`, `green_mask` and :keyword:`blue_mask` are
   bit masks for color components for each pixel. The resulting color is then
   xored with the `xor_value`.

   For example, ``PixelFormatRgbMask(0xf800, 0x07e0, 0x001f, bpp=16)`` is a
   highcolor format with:

   - 5 (most significant) bits for red,
   - 6 bits for green,
   - 5 (least significant) bits for blue.

.. currentmodule:: djvu.decode
.. class:: PixelFormatGrey()

   8-bit, grey pixel format.

.. currentmodule:: djvu.decode
.. class:: PixelFormatPalette(palette)

   Palette pixel format.

   `palette` must be a dictionary which contains 216 (6 x 6 x 6)
   entries of a web color cube, such that:

   - for each key ``(r, g, b)``: ``r in range(0, 6)``, ``g in range(0, 6)`` etc.;
   - for each value ``v``: ``v in range(0, 0x100)``.

.. currentmodule:: djvu.decode
.. class:: PixelFormatPackedBits(endianness)

   Bitonal, 1 bit per pixel format with:

   - most significant bits on the left (*endianness* = ``'>'``) or
   - least significant bits on the left (*endianness* = ``'<'``).

Render modes
------------

.. currentmodule:: djvu.decode
.. data:: djvu.decode.RENDER_COLOR

   Render color page or stencil.

.. currentmodule:: djvu.decode
.. data:: djvu.decode.RENDER_BLACK

   Render stencil or color page.

.. currentmodule:: djvu.decode
.. data:: djvu.decode.RENDER_COLOR_ONLY

   Render color page or fail.

.. currentmodule:: djvu.decode
.. data:: djvu.decode.RENDER_MASK_ONLY

   Render stencil or fail.

.. currentmodule:: djvu.decode
.. data:: djvu.decode.RENDER_BACKGROUND

   Render color background layer.

.. currentmodule:: djvu.decode
.. data:: djvu.decode.RENDER_FOREGROUND

   Render foreground background layer

.. vim:ts=3 sw=3 et

.. vim:ts=3 sw=3 et ft=rst
