supported_types.hpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. //
  2. // Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
  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_PNG_DETAIL_SUPPORTED_TYPES_HPP
  9. #define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_SUPPORTED_TYPES_HPP
  10. #include <boost/gil/extension/io/png/tags.hpp>
  11. #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  12. #include <boost/gil/extension/toolbox/color_spaces/gray_alpha.hpp>
  13. #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  14. #include <cstddef>
  15. #include <type_traits>
  16. namespace boost { namespace gil { namespace detail {
  17. static const size_t PNG_BYTES_TO_CHECK = 4;
  18. // Read support
  19. template< png_bitdepth::type BitDepth
  20. , png_color_type::type ColorType
  21. >
  22. struct png_rw_support_base
  23. {
  24. static const png_bitdepth::type _bit_depth = BitDepth;
  25. static const png_color_type::type _color_type = ColorType;
  26. };
  27. template< typename Channel
  28. , typename ColorSpace
  29. >
  30. struct png_read_support : read_support_false
  31. , png_rw_support_base< 1
  32. , PNG_COLOR_TYPE_GRAY
  33. > {};
  34. template< typename BitField
  35. , bool Mutable
  36. >
  37. struct png_read_support< packed_dynamic_channel_reference< BitField
  38. , 1
  39. , Mutable
  40. >
  41. , gray_t
  42. > : read_support_true
  43. , png_rw_support_base< 1
  44. , PNG_COLOR_TYPE_GRAY
  45. > {};
  46. template< typename BitField
  47. , bool Mutable
  48. >
  49. struct png_read_support< packed_dynamic_channel_reference< BitField
  50. , 2
  51. , Mutable
  52. >
  53. , gray_t
  54. > : read_support_true
  55. , png_rw_support_base< 2
  56. , PNG_COLOR_TYPE_GRAY
  57. > {};
  58. template< typename BitField
  59. , bool Mutable
  60. >
  61. struct png_read_support< packed_dynamic_channel_reference< BitField
  62. , 4
  63. , Mutable
  64. >
  65. , gray_t
  66. > : read_support_true
  67. , png_rw_support_base< 4
  68. , PNG_COLOR_TYPE_GRAY
  69. > {};
  70. template<>
  71. struct png_read_support<uint8_t
  72. , gray_t
  73. > : read_support_true
  74. , png_rw_support_base< 8
  75. , PNG_COLOR_TYPE_GRAY
  76. > {};
  77. #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  78. template<>
  79. struct png_read_support<uint8_t
  80. , gray_alpha_t
  81. > : read_support_true
  82. , png_rw_support_base< 8
  83. , PNG_COLOR_TYPE_GA
  84. > {};
  85. #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  86. template<>
  87. struct png_read_support<uint8_t
  88. , rgb_t
  89. > : read_support_true
  90. , png_rw_support_base< 8
  91. , PNG_COLOR_TYPE_RGB
  92. > {};
  93. template<>
  94. struct png_read_support<uint8_t
  95. , rgba_t
  96. > : read_support_true
  97. , png_rw_support_base< 8
  98. , PNG_COLOR_TYPE_RGBA
  99. > {};
  100. template<>
  101. struct png_read_support<uint16_t
  102. , gray_t
  103. > : read_support_true
  104. , png_rw_support_base< 16
  105. , PNG_COLOR_TYPE_GRAY
  106. > {};
  107. template<>
  108. struct png_read_support<uint16_t
  109. , rgb_t
  110. > : read_support_true
  111. , png_rw_support_base< 16
  112. , PNG_COLOR_TYPE_RGB
  113. > {};
  114. template<>
  115. struct png_read_support<uint16_t
  116. , rgba_t
  117. > : read_support_true
  118. , png_rw_support_base< 16
  119. , PNG_COLOR_TYPE_RGBA
  120. > {};
  121. #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  122. template<>
  123. struct png_read_support<uint16_t
  124. , gray_alpha_t
  125. > : read_support_true
  126. , png_rw_support_base< 16
  127. , PNG_COLOR_TYPE_GA
  128. > {};
  129. #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  130. // Write support
  131. template< typename Channel
  132. , typename ColorSpace
  133. >
  134. struct png_write_support : write_support_false
  135. , png_rw_support_base< 1
  136. , PNG_COLOR_TYPE_GRAY
  137. > {};
  138. template< typename BitField
  139. , bool Mutable
  140. >
  141. struct png_write_support< packed_dynamic_channel_reference< BitField
  142. , 1
  143. , Mutable
  144. >
  145. , gray_t
  146. > : write_support_true
  147. , png_rw_support_base< 1
  148. , PNG_COLOR_TYPE_GRAY
  149. >
  150. {};
  151. template< typename BitField
  152. , bool Mutable
  153. >
  154. struct png_write_support< packed_dynamic_channel_reference< BitField
  155. , 1
  156. , Mutable
  157. > const
  158. , gray_t
  159. > : write_support_true
  160. , png_rw_support_base< 1
  161. , PNG_COLOR_TYPE_GRAY
  162. >
  163. {};
  164. template< typename BitField
  165. , bool Mutable
  166. >
  167. struct png_write_support< packed_dynamic_channel_reference< BitField
  168. , 2
  169. , Mutable
  170. >
  171. , gray_t
  172. > : write_support_true
  173. , png_rw_support_base< 2
  174. , PNG_COLOR_TYPE_GRAY
  175. >
  176. {};
  177. template< typename BitField
  178. , bool Mutable
  179. >
  180. struct png_write_support< packed_dynamic_channel_reference< BitField
  181. , 2
  182. , Mutable
  183. > const
  184. , gray_t
  185. > : write_support_true
  186. , png_rw_support_base< 2
  187. , PNG_COLOR_TYPE_GRAY
  188. >
  189. {};
  190. template< typename BitField
  191. , bool Mutable
  192. >
  193. struct png_write_support< packed_dynamic_channel_reference< BitField
  194. , 4
  195. , Mutable
  196. >
  197. , gray_t
  198. > : write_support_true
  199. , png_rw_support_base< 4
  200. , PNG_COLOR_TYPE_GRAY
  201. >
  202. {};
  203. template< typename BitField
  204. , bool Mutable
  205. >
  206. struct png_write_support< packed_dynamic_channel_reference< BitField
  207. , 4
  208. , Mutable
  209. > const
  210. , gray_t
  211. > : write_support_true
  212. , png_rw_support_base< 4
  213. , PNG_COLOR_TYPE_GRAY
  214. >
  215. {};
  216. template<>
  217. struct png_write_support<uint8_t
  218. , gray_t
  219. > : write_support_true
  220. , png_rw_support_base< 8
  221. , PNG_COLOR_TYPE_GRAY
  222. >
  223. {};
  224. #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  225. template<>
  226. struct png_write_support<uint8_t
  227. , gray_alpha_t
  228. > : write_support_true
  229. , png_rw_support_base< 8
  230. , PNG_COLOR_TYPE_GA
  231. >
  232. {};
  233. #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  234. template<>
  235. struct png_write_support<uint8_t
  236. , rgb_t
  237. > : write_support_true
  238. , png_rw_support_base< 8
  239. , PNG_COLOR_TYPE_RGB
  240. >
  241. {};
  242. template<>
  243. struct png_write_support<uint8_t
  244. , rgba_t
  245. > : write_support_true
  246. , png_rw_support_base< 8
  247. , PNG_COLOR_TYPE_RGBA
  248. >
  249. {};
  250. template<>
  251. struct png_write_support<uint16_t
  252. , gray_t
  253. > : write_support_true
  254. , png_rw_support_base< 16
  255. , PNG_COLOR_TYPE_GRAY
  256. >
  257. {};
  258. template<>
  259. struct png_write_support<uint16_t
  260. , rgb_t
  261. > : write_support_true
  262. , png_rw_support_base< 16
  263. , PNG_COLOR_TYPE_RGB
  264. >
  265. {};
  266. template<>
  267. struct png_write_support<uint16_t
  268. , rgba_t
  269. > : write_support_true
  270. , png_rw_support_base< 16
  271. , PNG_COLOR_TYPE_RGBA
  272. >
  273. {};
  274. #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  275. template<>
  276. struct png_write_support<uint16_t
  277. , gray_alpha_t
  278. > : write_support_true
  279. , png_rw_support_base< 16
  280. , PNG_COLOR_TYPE_GA
  281. >
  282. {};
  283. #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  284. } // namespace detail
  285. template<typename Pixel>
  286. struct is_read_supported<Pixel, png_tag>
  287. : std::integral_constant
  288. <
  289. bool,
  290. detail::png_read_support
  291. <
  292. typename channel_type<Pixel>::type,
  293. typename color_space_type<Pixel>::type
  294. >::is_supported
  295. >
  296. {
  297. using parent_t = detail::png_read_support
  298. <
  299. typename channel_type<Pixel>::type,
  300. typename color_space_type<Pixel>::type
  301. >;
  302. static const png_bitdepth::type _bit_depth = parent_t::_bit_depth;
  303. static const png_color_type::type _color_type = parent_t::_color_type;
  304. };
  305. template<typename Pixel>
  306. struct is_write_supported<Pixel, png_tag>
  307. : std::integral_constant
  308. <
  309. bool,
  310. detail::png_write_support
  311. <
  312. typename channel_type<Pixel>::type,
  313. typename color_space_type<Pixel>::type
  314. >::is_supported
  315. >
  316. {
  317. using parent_t = detail::png_write_support
  318. <
  319. typename channel_type<Pixel>::type,
  320. typename color_space_type<Pixel>::type
  321. >;
  322. static const png_bitdepth::type _bit_depth = parent_t::_bit_depth;
  323. static const png_color_type::type _color_type = parent_t::_color_type;
  324. };
  325. } // namespace gil
  326. } // namespace boost
  327. #endif