Skip to content

Commit

Permalink
Apply gamma to skins, kill sw_state structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
skullernet committed Dec 7, 2012
1 parent ee80739 commit 2b1aa07
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
29 changes: 20 additions & 9 deletions src/refresh/sw/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "sw.h"

static byte gammatable[256];

/*
================
IMG_Unload
Expand All @@ -38,9 +40,9 @@ static void R_LightScaleTexture(byte *in, int inwidth, int inheight)
c = inwidth * inheight;

for (i = 0; i < c; i++, p += TEX_BYTES) {
p[0] = sw_state.gammatable[p[0]];
p[1] = sw_state.gammatable[p[1]];
p[2] = sw_state.gammatable[p[2]];
p[0] = gammatable[p[0]];
p[1] = gammatable[p[1]];
p[2] = gammatable[p[2]];
}
}

Expand Down Expand Up @@ -70,7 +72,8 @@ void IMG_Load(image_t *image, byte *pic, int width, int height)
((uint32_t *)image->pixels[0])[i] = d_8to24table[pic[i]];
}

R_LightScaleTexture(image->pixels[0], MIPSIZE(c), 1);
if (!(r_config.flags & QVF_GAMMARAMP))
R_LightScaleTexture(image->pixels[0], MIPSIZE(c), 1);
} else {
image->pixels[0] = R_Malloc(c * TEX_BYTES);
for (i = 0; i < c; i++) {
Expand All @@ -90,9 +93,14 @@ void IMG_Load(image_t *image, byte *pic, int width, int height)
image->pixels[2] = image->pixels[1] + b * TEX_BYTES / 4;
image->pixels[3] = image->pixels[2] + b * TEX_BYTES / 16;

R_LightScaleTexture(pic, width, height);
if (!(r_config.flags & QVF_GAMMARAMP))
R_LightScaleTexture(pic, width, height);

if (width == image->width && height == image->height)
memcpy(image->pixels[0], pic, width * height * TEX_BYTES);
else
IMG_ResampleTexture(pic, width, height, image->pixels[0], image->width, image->height);

IMG_ResampleTexture(pic, width, height, image->pixels[0], image->width, image->height);
IMG_MipMap(image->pixels[1], image->pixels[0], image->width >> 0, image->height >> 0);
IMG_MipMap(image->pixels[2], image->pixels[1], image->width >> 1, image->height >> 1);
IMG_MipMap(image->pixels[3], image->pixels[2], image->width >> 2, image->height >> 2);
Expand All @@ -108,6 +116,9 @@ void IMG_Load(image_t *image, byte *pic, int width, int height)
}
}
}

if (image->type == IT_SKIN && !(r_config.flags & QVF_GAMMARAMP))
R_LightScaleTexture(image->pixels[0], width, height);
}

void R_BuildGammaTable(void)
Expand All @@ -117,13 +128,13 @@ void R_BuildGammaTable(void)

if (g == 1.0) {
for (i = 0; i < 256; i++)
sw_state.gammatable[i] = i;
gammatable[i] = i;
return;
}

for (i = 0; i < 256; i++) {
inf = 255 * pow((i + 0.5) / 255.5 , g) + 0.5;
sw_state.gammatable[i] = clamp(inf, 0, 255);
inf = 255 * pow((i + 0.5) / 255.5, g) + 0.5;
gammatable[i] = clamp(inf, 0, 255);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/refresh/sw/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ bsp_t *r_worldmodel;

byte r_warpbuffer[WARP_WIDTH * WARP_HEIGHT * VID_BYTES];

swstate_t sw_state;

float r_time1;
int r_numallocatededges;
float r_aliasuvscale = 1.0;
Expand Down Expand Up @@ -208,7 +206,7 @@ void R_Register(void)
r_lerpmodels = Cvar_Get("r_lerpmodels", "1", 0);
r_novis = Cvar_Get("r_novis", "0", 0);

vid_gamma = Cvar_Get("vid_gamma", "1.0", CVAR_ARCHIVE);
vid_gamma = Cvar_Get("vid_gamma", "1.0", CVAR_ARCHIVE | CVAR_FILES);

Cmd_AddCommand("scdump", D_SCDump_f);

Expand Down
10 changes: 0 additions & 10 deletions src/refresh/sw/sw.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,17 +697,7 @@ void R_EmitSkyBox(void);

void R_ApplySIRDAlgorithum(void);

typedef struct swstate_s {
qboolean fullscreen;
int prev_mode; // last valid SW mode

byte gammatable[256];
byte currentpalette[1024];
} swstate_t;

void R_IMFlatShadedQuad(vec3_t a, vec3_t b, vec3_t c, vec3_t d, color_t color, float alpha);

void R_InitDraw(void);

extern swstate_t sw_state;

0 comments on commit 2b1aa07

Please sign in to comment.