Alchemy  1.0
A framework to robustly process network messages and structured data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
bitmap.cpp
Go to the documentation of this file.
1 /// @file bitmap.cpp
2 ///
3 /// Data object to manipulate the data of a bitmap image structure.
4 ///
5 /// The MIT License(MIT)
6 /// @copyright 2014 Paul M Watt
7 // ****************************************************************************
8 // Includes ********************************************************************
9 #include "bitmap.h"
10 #include <fstream>
11 
12 
13 // ****************************************************************************
14 namespace sgraph
15 {
16 
17 // ****************************************************************************
18 bool Bitmap::Load (const std::string &name)
19 {
20  m_file_name = name;
21 
22  std::ifstream input(m_file_name, std::ios::binary);
23  if (input.bad())
24  {
25  return false;
26  }
27 
28  input >> m_file_header;
29 
30 
31  if ( m_file_header.offset != (size_t)0x36)
32  {
33  return false;
34  }
35 
36 
37  size_t s = m_info.size();
38 
39  //input >> m_info;
40 
41  return true;
42 }
43 
44 // ****************************************************************************
45 void Bitmap::process( std::string &msg,
46  pixel_ftor ftor)
47 {
48  auto t = Hg::make_view<Hg::rgba_t>(m_info.pixels.get());
49  auto iter = t.begin();
50 
51  // Calculate the number of bytes that can be encoded or extracted
52  // from the image and ensure the the message buffer is large enough.
53  size_t length = t.end() - iter;
54  msg.resize(length);
55 
56  for (size_t index = 0; iter != t.end(); ++iter, ++index)
57  {
58  ftor(*iter, (Hg::byte_t&)(msg[index]));
59  }
60 }
61 
62 // ****************************************************************************
63 bool Bitmap::Store (const std::string &name)
64 {
65  std::ofstream output(name, std::ios::binary);
66  if (output.bad())
67  {
68  return false;
69  }
70 
71  output << m_file_header;
72  output << m_info;
73 
74  return true;
75 }
76 
77 
78 } // namespace sgraph
79