OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
PortableBitmapReader.h
Go to the documentation of this file.
1 #ifndef PORTABLEBITMAPRREADER_H
2 #define PORTABLEBITMAPRREADER_H
3 
5 
6 #include <string>
7 #include <vector>
8 #include <istream>
9 
11 public:
12  PortableBitmapReader(const std::string & input);
13 
14  unsigned int getWidth() const;
15  unsigned int getHeight() const;
16 
17  bool isBlack(unsigned int i, unsigned int j) const;
18  std::vector<bool> getPixels() const;
19  void print(std::ostream &out) const;
20 
21 private:
22  void readHeader(std::istream &in);
23  void readImageAscii(std::istream &in);
24  void readImageBinary(std::istream &in);
25  std::string getNextPart(std::istream &in);
26 
27  unsigned int getIdx(unsigned int h, unsigned int w) const;
28 
29  unsigned int width_m;
30  unsigned int height_m;
31 
32  enum FileType {
35  };
36 
38 
39  std::vector<bool> pixels_m;
40 };
41 
42 inline
43 unsigned int PortableBitmapReader::getWidth() const {
44  return width_m;
45 }
46 
47 inline
48 unsigned int PortableBitmapReader::getHeight() const {
49  return height_m;
50 }
51 
52 inline
53 bool PortableBitmapReader::isBlack(unsigned int i, unsigned int j) const {
54  return pixels_m[getIdx(i, j)];
55 }
56 
57 inline
58 std::vector<bool> PortableBitmapReader::getPixels() const {
59  return pixels_m;
60 }
61 
62 inline
63 unsigned int PortableBitmapReader::getIdx(unsigned int h, unsigned int w) const {
64  if (h >= height_m || w >= width_m) throw OpalException("PortableBitmapReader::getIdx",
65  "Pixel number out of bounds");
66  return h * width_m + w;
67 }
68 
69 #endif
PortableBitmapReader(const std::string &input)
std::vector< bool > pixels_m
std::vector< bool > getPixels() const
std::string getNextPart(std::istream &in)
The base class for all OPAL exceptions.
Definition: OpalException.h:28
void readImageAscii(std::istream &in)
bool isBlack(unsigned int i, unsigned int j) const
unsigned int getHeight() const
unsigned int getWidth() const
void readImageBinary(std::istream &in)
void readHeader(std::istream &in)
unsigned int getIdx(unsigned int h, unsigned int w) const
void print(std::ostream &out) const