diff --git a/apps/nexus/patch.cpp b/apps/nexus/patch.cpp index 16330da3..9c89ac06 100644 --- a/apps/nexus/patch.cpp +++ b/apps/nexus/patch.cpp @@ -18,6 +18,54 @@ void pad(unsigned int &size) { while(size&0x3) size++; } +void shuffle(float *buffer, unsigned int size, unsigned int stride) { + float *tmp = new float[size]; + unsigned int count = 0; + + unsigned int nelem = size/stride; + for(unsigned int s = 0; s < stride; s++) { + float *ptr = buffer + s; + for(unsigned int i = 0; i < nelem; i++) { + tmp[count++] = *ptr; + ptr += stride; + } + } + memcpy(buffer, tmp, size * sizeof(float)); + delete []tmp; +} + +void unshuffle(float *buffer, unsigned int size, unsigned int stride) { + float *tmp = new float[size]; + + unsigned int count = 0; + unsigned int nelem = size/stride; + for(unsigned int s = 0; s < stride; s++) { + float *ptr = tmp + s; + for(unsigned int i = 0; i < nelem; i++) { + *ptr = buffer[count++]; + ptr += stride; + } + } + memcpy(buffer, tmp, size * sizeof(float)); + delete []tmp; +} + +void subtract(float *buffer, unsigned int size) { + float p = buffer[0]; + float q; + for(unsigned int i = 1; i < size; i++) { + q = buffer[i]; + buffer[i] -= p; + p = q; + } +} + +void unsubtract(float *buffer, unsigned int size) { + for(unsigned int i = 1; i < size; i++) + buffer[i] += buffer[i-1]; +} + + Patch::Patch(Signature signature, char *s, unsigned short nvert, unsigned short nface): start(s) { @@ -121,6 +169,9 @@ unsigned int Patch::ByteSize(Signature signature, char *Patch::Compress(unsigned int ram_size, unsigned int &size) { + //lets use differences + // shuffle((float *)VertBegin(), nv * 3, 3); + // subtract((float *)VertBegin(), nv * 3); //TODO use OVERLAP and test speed //TODO fill chunk padding with zeroes? @@ -164,5 +215,8 @@ void Patch::Decompress(unsigned int ram_size, void *src, unsigned int src_sz) { } assert(dst_size == ram_size); //TODO add 3 to start... so we can use asm_fast decompressor + + // unsubtract((float *)VertBegin(), nv * 3); + // unshuffle((float *)VertBegin(), nv * 3, 3); }