Skip to content
Dejan edited this page Jul 14, 2017 · 5 revisions

Blank image with gray:

  typedef std::array< std::uint8_t, 3 > array3u8_t; //!< Guarantee by ISO that there be only three consecutive std::uint8_t
  typedef ::color::rgb< std::uint8_t > rgb_t; //!< Guarantee by design of this library that only array< std::uint8_t, 3 > will be in memory.
  std::vector< array3u8_t >  image( 1000 * 1000 );
  memset ( image.data(), 0x80 , 3 * image.size() );
  auo r = reinterpret_cast< rgb_t * >( image.data() );
  // now r points to field of rgb_t

By design of ::color::rgb< std::uint8_t > it is guarantee that this type store ONLY three consecutive std::uint8_t in memory so above reinterpret_cast is safe to perform.

Clone this wiki locally