OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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
11public:
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
21private:
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 {
34 BINARY
35 };
36
38
39 std::vector<bool> pixels_m;
40};
41
42inline
43unsigned int PortableBitmapReader::getWidth() const {
44 return width_m;
45}
46
47inline
48unsigned int PortableBitmapReader::getHeight() const {
49 return height_m;
50}
51
52inline
53bool PortableBitmapReader::isBlack(unsigned int i, unsigned int j) const {
54 return pixels_m[getIdx(i, j)];
55}
56
57inline
58std::vector<bool> PortableBitmapReader::getPixels() const {
59 return pixels_m;
60}
61
62inline
63unsigned 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
std::vector< bool > pixels_m
void readImageAscii(std::istream &in)
unsigned int getIdx(unsigned int h, unsigned int w) const
std::vector< bool > getPixels() const
bool isBlack(unsigned int i, unsigned int j) const
PortableBitmapReader(const std::string &input)
void print(std::ostream &out) const
void readImageBinary(std::istream &in)
std::string getNextPart(std::istream &in)
void readHeader(std::istream &in)
unsigned int getWidth() const
unsigned int getHeight() const
The base class for all OPAL exceptions.
Definition: OpalException.h:28