Skip to content

Instantly share code, notes, and snippets.

@jcayzac
Created September 3, 2011 12:46
Show Gist options
  • Save jcayzac/1191138 to your computer and use it in GitHub Desktop.
Save jcayzac/1191138 to your computer and use it in GitHub Desktop.
Saving a 8bpp image to PGM
#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