2 Copyright (C) 2012 fmaj7b5.info
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef FM7b5_IMAGE_IO_H
19 #define FM7b5_IMAGE_IO_H
29 Image<std::uint8_t> loadPGM(const std::string& filename);
32 void savePGM(const Image<T>& image, const std::string& filename);
37 void savePNM(const Image<T>& image, const std::string& filename)
41 if (fopen_s(&fp, filename.c_str(), "wb") != 0) {
42 throw std::runtime_error(__FUNCTION__ ": could not open a file.");
57 throw std::runtime_error(__FUNCTION__ ": unknown format.");
61 /* width, height, depth */
62 fprintf(fp, "%d %d\n%d\n", image.width(), image.height(), 255);
65 for (size_t h = 0; h < image.height(); ++h) {
66 const size_t width(image.width());
68 size_t ret = fwrite(image.data() + image.stride() * h, image.bpp(), width, fp);
71 throw std::runtime_error(__FUNCTION__ ": could not write correctly.");
77 #endif /* FM7b5_IMAGE_IO_H */