tags.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // Copyright 2008 Christian Henning
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #ifndef BOOST_GIL_EXTENSION_IO_BMP_TAGS_HPP
  9. #define BOOST_GIL_EXTENSION_IO_BMP_TAGS_HPP
  10. #include <boost/gil/io/base.hpp>
  11. namespace boost { namespace gil {
  12. /// Defines bmp tag.
  13. struct bmp_tag : format_tag {};
  14. /// See http://en.wikipedia.org/wiki/BMP_file_format#BMP_File_Header for reference.
  15. /// Defines type for offset value.
  16. struct bmp_offset : property_base< uint32_t > {};
  17. /// Defines type for header sizes.
  18. struct bmp_header_size : property_base< uint32_t >
  19. {
  20. static const type _size = 14; /// Constant size for bmp file header size.
  21. static const type _win32_info_size = 40; /// Constant size for win32 bmp info header size.
  22. static const type _os2_info_size = 12; /// Constant size for os2 bmp info header size.
  23. };
  24. /// Defines type for image width property.
  25. struct bmp_image_width : property_base< int32_t > {};
  26. /// Defines type for image height property.
  27. struct bmp_image_height : property_base< int32_t > {};
  28. /// Defines type for bits per pixels property.
  29. struct bmp_bits_per_pixel : property_base< uint16_t > {};
  30. /// Defines type for compression property.
  31. struct bmp_compression : property_base< uint32_t >
  32. {
  33. static const type _rgb = 0; /// RGB without compression
  34. static const type _rle8 = 1; /// 8 bit index with RLE compression
  35. static const type _rle4 = 2; /// 4 bit index with RLE compression
  36. static const type _bitfield = 3; /// 16 or 32 bit fields without compression
  37. };
  38. /// Defines type for image size property.
  39. struct bmp_image_size : property_base< uint32_t > {};
  40. /// Defines type for horizontal resolution property.
  41. struct bmp_horizontal_resolution : property_base< int32_t > {};
  42. /// Defines type for vertical resolution property.
  43. struct bmp_vertical_resolution : property_base< int32_t > {};
  44. /// Defines type for number of colors property.
  45. struct bmp_num_colors : property_base< uint32_t > {};
  46. /// Defines type for important number of colors property.
  47. struct bmp_num_important_colors : property_base< uint32_t > {};
  48. /// if height is negative then image is stored top-down instead of bottom-up.
  49. struct bmp_top_down : property_base< bool > {};
  50. static const uint32_t bmp_signature = 0x4D42; /// Constant signature for bmp file format.
  51. /// Read information for bmp images.
  52. ///
  53. /// The structure is returned when using read_image_info.
  54. template<>
  55. struct image_read_info< bmp_tag >
  56. {
  57. /// Default contructor.
  58. image_read_info< bmp_tag >()
  59. : _top_down(false)
  60. , _valid( false )
  61. {}
  62. /// The offset, i.e. starting address, of the byte where the bitmap data can be found.
  63. bmp_offset::type _offset;
  64. /// The size of this header:
  65. /// - 40 bytes for Windows V3 header
  66. /// - 12 bytes for OS/2 V1 header
  67. bmp_header_size::type _header_size;
  68. /// The bitmap width in pixels ( signed integer ).
  69. bmp_image_width::type _width;
  70. /// The bitmap height in pixels ( signed integer ).
  71. bmp_image_height::type _height;
  72. /// The number of bits per pixel, which is the color depth of the image.
  73. /// Typical values are 1, 4, 8, 16, 24 and 32.
  74. bmp_bits_per_pixel::type _bits_per_pixel;
  75. /// The compression method being used. See above for a list of possible values.
  76. bmp_compression::type _compression;
  77. /// The image size. This is the size of the raw bitmap data (see below),
  78. /// and should not be confused with the file size.
  79. bmp_image_size::type _image_size;
  80. /// The horizontal resolution of the image. (pixel per meter, signed integer)
  81. bmp_horizontal_resolution::type _horizontal_resolution;
  82. /// The vertical resolution of the image. (pixel per meter, signed integer)
  83. bmp_vertical_resolution::type _vertical_resolution;
  84. /// The number of colors in the color palette, or 0 to default to 2^n - 1.
  85. bmp_num_colors::type _num_colors;
  86. /// The number of important colors used, or 0 when every color is important;
  87. /// generally ignored.
  88. bmp_num_important_colors::type _num_important_colors;
  89. bmp_top_down::type _top_down;
  90. /// Used internaly to identify is the header has been read.
  91. bool _valid;
  92. };
  93. /// Read settings for bmp images.
  94. ///
  95. /// The structure can be used for all read_xxx functions, except read_image_info.
  96. template<>
  97. struct image_read_settings< bmp_tag > : public image_read_settings_base
  98. {
  99. /// Default constructor
  100. image_read_settings()
  101. : image_read_settings_base()
  102. {}
  103. /// Constructor
  104. /// \param top_left Top left coordinate for reading partial image.
  105. /// \param dim Dimensions for reading partial image.
  106. image_read_settings( const point_t& top_left
  107. , const point_t& dim
  108. )
  109. : image_read_settings_base( top_left
  110. , dim
  111. )
  112. {}
  113. };
  114. /// Write information for bmp images.
  115. ///
  116. /// The structure can be used for write_view() function.
  117. template<>
  118. struct image_write_info< bmp_tag >
  119. {
  120. };
  121. } // namespace gil
  122. } // namespace boost
  123. #endif