Re: UQE Ultimate Quake Engine ?
Posted: Wed Jul 18, 2012 9:13 pm
I would have alook at the source if i could but it seems the site has a captcha which none of my browsers will show
so i cannot download it.
Code: Select all
/*
=============
DDS LOADING
=============
*/
typedef struct
{
unsigned int dwColorSpaceLowValue;
unsigned int dwColorSpaceHighValue;
} dds_colorkey;
typedef struct
{
unsigned int magic;
unsigned int dwSize;
unsigned int dwFlags;
unsigned int dwHeight;
unsigned int dwWidth;
long lPitch;
unsigned int dwDepth;
unsigned int dwMipMapCount;
unsigned int dwAlphaBitDepth;
unsigned int dwReserved;
void *lpSurface;
dds_colorkey ddckCKDestOverlay;
dds_colorkey ddckCKDestBlt;
dds_colorkey ddckCKSrcOverlay;
dds_colorkey ddckCKSrcBlt;
unsigned int dwPFSize;
unsigned int dwPFFlags;
unsigned int dwFourCC;
unsigned int dwRGBBitCount;
unsigned int dwRBitMask;
unsigned int dwGBitMask;
unsigned int dwBBitMask;
unsigned int dwRGBAlphaBitMask;
unsigned int dwCaps;
unsigned int dwCaps2;
unsigned int dwCaps3;
unsigned int dwVolumeDepth;
unsigned int dwTextureStage;
} dds_header;
typedef struct
{
unsigned char r;
unsigned char g;
unsigned char b;
} dds_color;
enum
{
DDS_ERROR = -1,
DDS_RGB,
DDS_RGBA,
DDS_DXT1,
DDS_DXT2,
DDS_DXT3,
DDS_DXT4,
DDS_DXT5
};
enum
{
DDPF_ALPHAPIXELS = 0x01,
DDPF_FOURCC = 0x04,
DDPF_RGB = 0x40,
DDPF_RGBA = 0x41
};
byte *LoadDDS(char *name, FILE *fin)
{
int format, image_size, x, y, w, h, i, j;
unsigned char *image_rgba, *buf, *src, *dest;
unsigned int c0, c1;
dds_header header;
dds_color color[4];
/* load file */
if (!fin && FS_OpenFile(name, &fin, NULL) == -1)
{
return NULL;
}
fread(&header, sizeof(dds_header), 1, fin);
if(header.magic != ('D' | 'D' << 8 | 'S' << 16 | ' ' << 24))
{
Con_Printf ("%s : Malformed dds image\n", name);
goto BadDDS;
}
if (header.dwPFFlags & DDPF_FOURCC)
{
if (header.dwFourCC == ('D' | ('X' << 8) | ('T' << 16) | ('1' << 24))) format = DDS_DXT1;
else if (header.dwFourCC == ('D' | ('X' << 8) | ('T' << 16) | ('2' << 24))) format = DDS_DXT2;
else if (header.dwFourCC == ('D' | ('X' << 8) | ('T' << 16) | ('3' << 24))) format = DDS_DXT3;
else if (header.dwFourCC == ('D' | ('X' << 8) | ('T' << 16) | ('4' << 24))) format = DDS_DXT4;
else if (header.dwFourCC == ('D' | ('X' << 8) | ('T' << 16) | ('5' << 24))) format = DDS_DXT5;
else format = DDS_ERROR;
}
else if (header.dwPFFlags == DDPF_RGB && header.dwRGBBitCount == 24)
{
format = DDS_RGB;
}
else if (header.dwPFFlags == DDPF_RGBA && header.dwRGBBitCount == 32)
{
format = DDS_RGBA;
}
if (format == DDS_ERROR)
{
goto BadDDS;
}
if(format == DDS_DXT2 || format == DDS_DXT4)
{
goto BadDDS;
}
image_width = w = header.dwWidth;
image_height = h = header.dwHeight;
image_size = (w * h * 4);
image_rgba = (byte *) calloc(image_size, 1);
if(format == DDS_RGB)
{
buf = (byte *) malloc(w * h * 3);
fread(buf, w * h * 3, 1, fin);
src = buf;
dest = image_rgba;
for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
*dest++ = *src++;
*dest++ = *src++;
*dest++ = *src++;
*dest++ = 255;
}
}
free(buf);
}
else if(format == DDS_RGBA)
{
buf = (byte *) malloc(w * h * 4);
fread(buf, w * h * 4, 1, fin);
src = buf;
dest = image_rgba;
for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
*dest++ = *src++;
*dest++ = *src++;
*dest++ = *src++;
*dest++ = *src++;
}
}
free(buf);
}
else
{
buf = (byte *) malloc(w * h);
src = buf;
fread(buf, w * h, 1, fin);
for(y = 0; y < h; y += 4)
{
for(x = 0; x < w; x += 4)
{
unsigned long alpha = 0;
unsigned int a0 = 0;
unsigned int a1 = 0;
if(format == DDS_DXT3)
{
alpha = *(unsigned long*)src;
src += 8;
}
else if(format == DDS_DXT5)
{
alpha = (*(unsigned long *)src) >> 16;
a0 = src[0];
a1 = src[1];
src += 8;
}
c0 = *(unsigned short *)(src + 0);
c1 = *(unsigned short *)(src + 2);
src += 4;
color[0].r = ((c0 >> 11) & 0x1f) << 3;
color[0].g = ((c0 >> 5) & 0x3f) << 2;
color[0].b = (c0 & 0x1f) << 3;
color[1].r = ((c1 >> 11) & 0x1f) << 3;
color[1].g = ((c1 >> 5) & 0x3f) << 2;
color[1].b = (c1 & 0x1f) << 3;
if(c0 > c1)
{
color[2].r = (color[0].r * 2 + color[1].r) / 3;
color[2].g = (color[0].g * 2 + color[1].g) / 3;
color[2].b = (color[0].b * 2 + color[1].b) / 3;
color[3].r = (color[0].r + color[1].r * 2) / 3;
color[3].g = (color[0].g + color[1].g * 2) / 3;
color[3].b = (color[0].b + color[1].b * 2) / 3;
}
else
{
color[2].r = (color[0].r + color[1].r) / 2;
color[2].g = (color[0].g + color[1].g) / 2;
color[2].b = (color[0].b + color[1].b) / 2;
color[3].r = 0;
color[3].g = 0;
color[3].b = 0;
}
for(i = 0; i < 4; i++)
{
unsigned int index = *src++;
unsigned char *dest = image_rgba + (w * (y + i) + x) * 4;
for(j = 0; j < 4; j++)
{
*dest++ = color[index & 0x03].r;
*dest++ = color[index & 0x03].g;
*dest++ = color[index & 0x03].b;
if(format == DDS_DXT1)
{
*dest++ = ((index & 0x03) == 3 && c0 <= c1) ? 0 : 255;
}
else if(format == DDS_DXT3)
{
*dest++ = (unsigned char)((alpha & 0x0f) << 4);
alpha >>= 4;
}
else if(format == DDS_DXT5)
{
unsigned int a = (unsigned int)(alpha & 0x07);
if(a == 0)
{
*dest++ = a0;
}
else if(a == 1)
{
*dest++ = a1;
}
else if(a0 > a1)
{
*dest++ = ((8 - a) * a0 + (a - 1) * a1) / 7;
}
else if(a > 5)
{
*dest++ = (a == 6) ? 0 : 255;
}
else
{
*dest++ = ((6 - a) * a0 + (a - 1) * a1) / 5;
}
alpha >>= 3;
}
else
{
*dest++ = 255;
}
index >>= 2;
}
}
}
}
free(buf);
}
fclose(fin);
return image_rgba;
BadDDS:;
fclose (fin);
return NULL;
}Its not been tried in court yet so probably better to do it your way untill we know for sure.In September 2011, Intel employee Ian Romanick mentioned that the S3TC patent had been marked as invalid in patent litigation between Apple and HTC