#include #include typedef uint16_t depth; typedef std::vector column; typedef std::vector grid; static const depth BOTTOM = 65535; static inline int xsize(grid const& g) { return g.size(); } static inline int ysize(grid const& g) { return g.empty() ? 0 : g[0].size(); } static inline int get(grid const& g, int x, int y, int def = BOTTOM) { return x >= 0 && y >= 0 && x < xsize(g) && y < ysize(g) ? g[x][y] : def; } void resize(int xsize, int ysize, grid*, depth def = BOTTOM); void read_pgm(char const* filename, grid*, depth* zsize = NULL); void write_pgm(grid const&, char const* filename, depth zsize = 0); static inline depth color(int r, int g, int b) { return r>>3<<11|g>>2<<5|b>>3; } void write_ppm(grid const&, char const* filename);