19 int Pixmap::get_width() const
24 int Pixmap::get_height() const
29 Rect Pixmap::get_rect() const
31 Rect rect = {0, 0, width, height};
35 bool Pixmap::set_image(int x, int y, unsigned char *pix)
39 pixels = new unsigned char[x * y * 4];
44 memcpy(pixels, pix, x * y * 4);
49 const unsigned char *Pixmap::get_image() const
54 unsigned char *Pixmap::get_image()
59 bool Pixmap::load(const char *fname)
64 bool Pixmap::save(const char *fname) const
70 FILE *fp = fopen(fname, "wb");
72 fprintf(stderr, "failed to save pixmap: %s: %s\n", fname, strerror(errno));
76 fprintf(fp, "P6\n%d %d\n255\n", width, height);
78 for(int i=0; i<width * height; i++) {
79 fputc(pixels[i * 4], fp);
80 fputc(pixels[i * 4 + 1], fp);
81 fputc(pixels[i * 4 + 2], fp);