bool decrunch(RGBE *_scanline, int _len, FILE *_file) { int i, j; if (_len < MINELEN || _len > MAXELEN) return oldDecrunch(_scanline, _len, _file); i = fgetc(_file); if (i != 2) { fseek(_file, -1, SEEK_CUR); return oldDecrunch(_scanline, _len, _file); } _scanline[0][G] = fgetc(_file); _scanline[0][B] = fgetc(_file); i = fgetc(_file); if (_scanline[0][G] != 2 || _scanline[0][B] & 128) { _scanline[0][R] = 2; _scanline[0][E] = i; return oldDecrunch(_scanline + 1, _len - 1, _file); } // read each component for (i = 0; i < 4; i++) { for (j = 0; j < _len;) { unsigned char code = fgetc(_file); if (code > 128) // run { code &= 127; unsigned char val = fgetc(_file); while (code--) _scanline[j++][i] = val; } else // non-run { while (code--) _scanline[j++][i] = fgetc(_file); } } } return feof(_file) ? false : true; }
bool decrunch(RGBE *scanline, int len, FILE *file) { int i, j; if (len < MINELEN || len > MAXELEN) return oldDecrunch(scanline, len, file); i = fgetc(file); if (i != 2) { fseek(file, -1, SEEK_CUR); return oldDecrunch(scanline, len, file); } scanline[0][G] = fgetc(file); scanline[0][B] = fgetc(file); i = fgetc(file); if (scanline[0][G] != 2 || scanline[0][B] & 128) { scanline[0][R] = 2; scanline[0][E] = i; return oldDecrunch(scanline + 1, len - 1, file); } // read each component for (i = 0; i < 4; i++) { for (j = 0; j < len; ) { unsigned char code = fgetc(file); if (code > 128) { // run code &= 127; unsigned char val = fgetc(file); while (code--) scanline[j++][i] = val; } else { // non-run while(code--) scanline[j++][i] = fgetc(file); } } } return feof(file) ? false : true; }