Created
September 3, 2011 12:46
-
-
Save jcayzac/1191138 to your computer and use it in GitHub Desktop.
Saving a 8bpp image to PGM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ostream> | |
#include <algorithm> | |
void save_8bpp_image_as_PGM( | |
std::ostream& out, | |
const uint8_t* image_data, | |
size_t width, | |
size_t height, | |
size_t bytes_per_row | |
) { | |
out << "P2\n" << width << " " << height << "\n255\n"; | |
for(size_t y(0); y < height; ++y, out << "\n") | |
for(size_t x(0); x < width; ++x, out << " ") | |
out << (int) image_data[y * bytes_per_row + x] << " "; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment