void Texture_CreateRomLump(d64RawTexture_t *tex, cache data) { int size = 0; int palsize = 0; int mask = 0; int i = 0; int *tmpSrc; memset(tex, 0, sizeof(d64RawTexture_t)); memcpy(&tex->header, data, sizeof(d64RawTextureHeader_t)); tex->header.hshift = _SWAP16(tex->header.hshift); tex->header.id = _SWAP16(tex->header.id); tex->header.numpal = _SWAP16(tex->header.numpal); tex->header.wshift = _SWAP16(tex->header.wshift); size = ((1<<tex->header.wshift) * (1<<tex->header.hshift))>>1; mask = (1<<tex->header.wshift) / 8; _PAD8(size); tex->data = (byte*)Mem_Alloc(size); memcpy(tex->data, data + (sizeof(d64RawTextureHeader_t)), size); palsize = sizeof(short) * (NUMTEXPALETTES * tex->header.numpal); tex->palette = (word*)Mem_Alloc(palsize); memcpy(tex->palette, data + (sizeof(d64RawTextureHeader_t) + size), palsize); // Flip nibbles per byte for(i = 0; i < size; i++) { byte tmp = tex->data[i]; tex->data[i] = (tmp >> 4); tex->data[i] |= ((tmp & 0xf) << 4); } tmpSrc = (int*)(tex->data); // Flip each sets of dwords based on texture width for(i = 0; i < size/4; i+=2) { int x1; int x2; if(i & mask) { x1 = *(int*)(tmpSrc+i); x2 = *(int*)(tmpSrc+i+1); *(int*)(tmpSrc+i) = x2; *(int*)(tmpSrc+i+1) = x1; } } }
uint16_t _swap16(uint16_t value) { return _SWAP16(value); }