#include #include #include "read_rgb.h" inline static short read_short(FILE*F) { short hi = fgetc(F); short lo = fgetc(F); return (hi << 8) | lo; } inline static long read_long(FILE*F) { long hi = read_short(F); long lo = read_short(F); return (hi << 16) | lo; } int load_rgb(const char* filename, int& h, int& w, long **& screen) { char zeros[404] = {0}; FILE*F = fopen(filename, "r"); if(!F) return 1; /*assert*/(read_short(F) == 474); // MAGIC, 474=SGI assert(fgetc(F) == 0); // STORAGE, 0=no compression assert(fgetc(F) == 1); // BPC, 1 byte per R, G, or B value assert(read_short(F) == 2); // DIMENSION w = read_short(F); // XSIZE h = read_short(F); // YSIZE assert(read_short(F) == 3); // ZSIZE assert(read_long(F) == 0); // PINMIN assert(read_long(F) == 255); // PINMAX read_long(F); // DUMMY fread(zeros, 1, 80, F); // IMAGENAME assert(read_long(F) == 0); // COLORMAP, 0=normal fread(zeros, 1, 404, F); // DUMMY screen = new long*[w]; *screen = new long[w*h]; for(int i=1; i