MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / parse_netpbm_format_header

Function parse_netpbm_format_header

tests/AssetsLibrary.cpp:131–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131std::tuple<unsigned int, unsigned int, int> parse_netpbm_format_header(std::ifstream &fs, char number)
132{
133 // check file type magic number is valid
134 std::array<char, 2> magic_number{{0}};
135 fs >> magic_number[0] >> magic_number[1];
136
137 if (magic_number[0] != 'P' || magic_number[1] != number)
138 {
139 throw std::runtime_error("File type magic number not supported");
140 }
141
142 discard_comments_and_spaces(fs);
143
144 unsigned int width = 0;
145 fs >> width;
146
147 discard_comments_and_spaces(fs);
148
149 unsigned int height = 0;
150 fs >> height;
151
152 discard_comments_and_spaces(fs);
153
154 int max_value = 0;
155 fs >> max_value;
156
157 if (!fs.good())
158 {
159 throw std::runtime_error("Cannot read image dimensions");
160 }
161
162 if (max_value != 255)
163 {
164 throw std::runtime_error("RawTensor doesn't have 8-bit values");
165 }
166
167 discard_comments(fs);
168
169 if (isspace(fs.peek()) == 0)
170 {
171 throw std::runtime_error("Invalid image header");
172 }
173
174 fs.ignore(1);
175
176 return std::make_tuple(width, height, max_value);
177}
178
179std::tuple<unsigned int, unsigned int, int> parse_ppm_header(std::ifstream &fs)
180{

Callers 2

parse_ppm_headerFunction · 0.85
parse_pgm_headerFunction · 0.85

Calls 3

peekMethod · 0.80
discard_commentsFunction · 0.70

Tested by

no test coverage detected