Quote:Original post by MaulingMonkey
Quote:Original post by iMalc
Also the maths for the array size [1024 * 1024 * 392] may be done with shorts since they are all less than 32767, so the result would be, uh... zero? Try [1024L * 1024L * 392L].
Nope, they'll all be ints. Unless he's working on a 16 bit system, because, well, then he's got 16 bit ints. In that case, his array would turn out to be 0 indeed. But that'd cause a compile error, wouldn't it?
Ah yes I remember now, I was using a 16-bit compiler when I had that problem.
corrington_j: It is easy to store the floats from zero to one as 1 byte instead of four. First make a small lookup table like this (for speed):
float lookupTable[256];void initLookupTable() //called once from your initialisation code{ for (int i=0; i<256; ++i) lookupTable = i / 255.0f;}// then replace your array accesses...val = slices[j][k];//with...val = GetVal(i, j, k);//Where GetVal is defined as...float GetVal(int i, int j, int k){ return lookupTable[ slices[j][k] ];}//and the corresponding SetVal...void SetVal(int i, int j, int k, float newVal){ slices[j][k] = static_cast<unsigned char>(newVal*255.0);}//instead of...slices[j][k] = val;//use...SetVal(i, j, k, val);