| 172 | } |
| 173 | |
| 174 | Image 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 | |
| 198 | size_t TotalInputBytes(fwk::iface::Model& model) |
| 199 | { |
no test coverage detected