MCPcopy Create free account
hub / github.com/Arm-Examples/ML-examples / ReadImage

Function ReadImage

ethos-u-corstone-1000/app/src/common/InputUtils.cpp:174–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174Image ReadImage(const std::string& imagePath)
175{
176 std::ifstream imageStream(imagePath, std::ios::binary);
177 if (!imageStream.is_open()) {
178 throw std::runtime_error("failed to open image file: " + imagePath);
179 }
180
181 std::array<char, 2> magic{};
182 imageStream.read(magic.data(), static_cast<std::streamsize>(magic.size()));
183 if (imageStream.gcount() != static_cast<std::streamsize>(magic.size())) {
184 throw std::runtime_error("failed to read image header: " + imagePath);
185 }
186
187 if (magic[0] == 'P' && magic[1] == '6') {
188 return ReadPpmP6(imagePath);
189 }
190
191 if (magic[0] == 'B' && magic[1] == 'M') {
192 return ReadBmp24(imagePath);
193 }
194
195 throw std::runtime_error("unsupported image format: " + imagePath);
196}
197
198size_t TotalInputBytes(fwk::iface::Model& model)
199{

Callers 1

ReadImageFileFunction · 0.85

Calls 2

ReadPpmP6Function · 0.85
ReadBmp24Function · 0.85

Tested by

no test coverage detected