Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef RW_PGM_HPP
- #define RW_PGM_HPP
- #include <cstdint>
- #include <fstream>
- #include <iostream>
- #include <sstream>
- #include <string>
- using namespace std;
- uint8_t *read_pgm_image(int &width, int &height, std::string filename)
- {
- string line;
- ifstream in(filename);
- getline(in, line);
- getline(in, line);
- stringstream width_height_ss(line);
- width_height_ss >> width >> height;
- getline(in, line);
- uint8_t *img = new uint8_t[width * height];
- in.read((char *)img, width * height);
- in.close();
- return img;
- }
- void write_pgm_image(const uint8_t *img, int width, int height, std::string filename)
- {
- std::ofstream out(filename);
- out << "P5" << std::endl
- << width << " " << height << std::endl
- << 255 << std::endl;
- out.write((const char *)img, width * height);
- out.close();
- }
- #endif //RW_PGM_HPP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement