#include #include "write_rgb.h" inline static void print_short(short s, FILE*F) { fputc(s>>8, F); fputc(s & 0xFF, F); } inline static void print_long(long L, FILE*F) { print_short(L >> 16, F); print_short(L & 0xFFFF, F); } int save_rgb(const char* filename, int h, int w, long ** screen) { char zeros[404] = {0}; FILE*F = fopen(filename, "w"); if(!F) return 1; print_short(474, F); // MAGIC, 474=SGI fputc(0, F); // STORAGE, 0=no compression fputc(1, F); // BPC, 1 byte per R, G, or B value print_short(2, F); // DIMENSION print_short(w, F); // XSIZE print_short(h, F); // YSIZE print_short(3, F); // ZSIZE print_long(0, F); // PINMIN print_long(255, F); // PINMAX print_long(0, F); // DUMMY fwrite(zeros, 1, 80, F); // IMAGENAME print_long(0, F); // COLORMAP, 0=normal fwrite(zeros, 1, 404, F); // DUMMY for(int j=0; j> 16, F); for(int j=0; j> 8) & 255, F); for(int j=0; j