image.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. Image
  2. =====
  3. .. contents::
  4. :local:
  5. :depth: 2
  6. Overview
  7. --------
  8. An image is a container that owns the pixels of a given image view
  9. It allocates them in its constructor and deletes them in the destructor.
  10. It has a deep assignment operator and copy constructor. Images are used
  11. rarely, just when data ownership is important. Most STL algorithms operate on
  12. ranges, not containers. Similarly most GIL algorithms operate on image views
  13. (which images provide).
  14. In the most general form images are N-dimensional and satisfy the following
  15. concept:
  16. .. code-block:: cpp
  17. concept RandomAccessNDImageConcept<typename Img> : Regular<Img>
  18. {
  19. typename view_t; where MutableRandomAccessNDImageViewConcept<view_t>;
  20. typename const_view_t = view_t::const_t;
  21. typename point_t = view_t::point_t;
  22. typename value_type = view_t::value_type;
  23. typename allocator_type;
  24. Img::Img(point_t dims, std::size_t alignment=0);
  25. Img::Img(point_t dims, value_type fill_value, std::size_t alignment);
  26. void Img::recreate(point_t new_dims, std::size_t alignment=0);
  27. void Img::recreate(point_t new_dims, value_type fill_value, std::size_t alignment);
  28. const point_t& Img::dimensions() const;
  29. const const_view_t& const_view(const Img&);
  30. const view_t& view(Img&);
  31. };
  32. Two-dimensional images have additional requirements:
  33. .. code-block:: cpp
  34. concept RandomAccess2DImageConcept<RandomAccessNDImageConcept Img>
  35. {
  36. typename x_coord_t = const_view_t::x_coord_t;
  37. typename y_coord_t = const_view_t::y_coord_t;
  38. Img::Img(x_coord_t width, y_coord_t height, std::size_t alignment=0);
  39. Img::Img(x_coord_t width, y_coord_t height, value_type fill_value, std::size_t alignment);
  40. x_coord_t Img::width() const;
  41. y_coord_t Img::height() const;
  42. void Img::recreate(x_coord_t width, y_coord_t height, std::size_t alignment=1);
  43. void Img::recreate(x_coord_t width, y_coord_t height, value_type fill_value, std::size_t alignment);
  44. };
  45. GIL images have views that model ``ImageViewConcept`` and operate on pixels.
  46. .. code-block:: cpp
  47. concept ImageConcept<RandomAccess2DImageConcept Img>
  48. {
  49. where MutableImageViewConcept<view_t>;
  50. typename coord_t = view_t::coord_t;
  51. };
  52. Images, unlike locators and image views, don't have 'mutable' set of concepts
  53. because immutable images are not very useful.
  54. .. seealso::
  55. - `RandomAccessNDImageConcept<Image> <reference/structboost_1_1gil_1_1_random_access_n_d_image_concept.html>`_
  56. - `RandomAccess2DImageConcept<Image> <reference/structboost_1_1gil_1_1_random_access2_d_image_concept.html>`_
  57. - `ImageConcept<Image> <reference/structboost_1_1gil_1_1_image_concept.html>`_
  58. Models
  59. ------
  60. GIL provides a class, ``image``, which is templated over the value type
  61. (the pixel) and models ``ImageConcept``:
  62. .. code-block:: cpp
  63. template
  64. <
  65. typename Pixel, // Models PixelValueConcept
  66. bool IsPlanar, // planar or interleaved image
  67. typename A=std::allocator<unsigned char>
  68. >
  69. class image;
  70. The image constructor takes an alignment parameter which allows for
  71. constructing images that are word-aligned or 8-byte aligned. The alignment is
  72. specified in bytes. The default value for alignment is 0, which means there is
  73. no padding at the end of rows. Many operations are faster using such
  74. 1D-traversable images, because ``image_view::x_iterator`` can be used to
  75. traverse the pixels, instead of the more complicated ``image_view::iterator``.
  76. Note that when alignment is 0, packed images are aligned to the bit - i.e.
  77. there are no padding bits at the end of rows of packed images.