Quake II RTX doxygen  1.0 dev
image.c File Reference
#include "sw.h"

Go to the source code of this file.

Macros

#define NTX   256
 

Functions

void IMG_Unload (image_t *image)
 
static void R_LightScaleTexture (byte *in, int inwidth, int inheight)
 
void IMG_Load (image_t *image, byte *pic)
 
void R_BuildGammaTable (void)
 
static void R_CreateNotexture (void)
 
void R_InitImages (void)
 
void R_ShutdownImages (void)
 

Variables

static byte gammatable [256]
 

Macro Definition Documentation

◆ NTX

#define NTX   256

Definition at line 126 of file image.c.

Function Documentation

◆ IMG_Load()

void IMG_Load ( image_t image,
byte *  pic 
)

Definition at line 54 of file image.c.

55 {
56  int i, c, b;
57  int width, height;
58 
59  width = image->upload_width;
60  height = image->upload_height;
61 
62  if (image->flags & IF_TURBULENT) {
63  image->width = TURB_SIZE;
64  image->height = TURB_SIZE;
65  }
66 
67  b = image->width * image->height;
68  c = width * height;
69 
70  if (image->type == IT_WALL) {
71  image->pixels[0] = R_Malloc(MIPSIZE(b) * TEX_BYTES);
72  image->pixels[1] = image->pixels[0] + b * TEX_BYTES;
73  image->pixels[2] = image->pixels[1] + b * TEX_BYTES / 4;
74  image->pixels[3] = image->pixels[2] + b * TEX_BYTES / 16;
75 
76  if (!(r_config.flags & QVF_GAMMARAMP))
78 
79  if (width == image->width && height == image->height) {
80  memcpy(image->pixels[0], pic, width * height * TEX_BYTES);
81  } else {
82  IMG_ResampleTexture(pic, width, height, image->pixels[0], image->width, image->height);
83  image->upload_width = image->width;
84  image->upload_height = image->height;
85  }
86 
87  IMG_MipMap(image->pixels[1], image->pixels[0], image->width >> 0, image->height >> 0);
88  IMG_MipMap(image->pixels[2], image->pixels[1], image->width >> 1, image->height >> 1);
89  IMG_MipMap(image->pixels[3], image->pixels[2], image->width >> 2, image->height >> 2);
90 
91  Z_Free(pic);
92  } else {
93  image->pixels[0] = pic;
94 
95  if (!(image->flags & IF_OPAQUE)) {
96  for (i = 0; i < c; i++) {
97  b = pic[i * TEX_BYTES + 3];
98  if (b != 255) {
99  image->flags |= IF_TRANSPARENT;
100  }
101  }
102  }
103  }
104 
105  if (image->type == IT_SKIN && !(r_config.flags & QVF_GAMMARAMP))
106  R_LightScaleTexture(image->pixels[0], width, height);
107 }

◆ IMG_Unload()

void IMG_Unload ( image_t image)

Definition at line 28 of file image.c.

29 {
30  Z_Free(image->pixels[0]);
31  image->pixels[0] = NULL;
32 }

◆ R_BuildGammaTable()

void R_BuildGammaTable ( void  )

Definition at line 109 of file image.c.

110 {
111  int i, inf;
112  float g = vid_gamma->value;
113 
114  if (g == 1.0) {
115  for (i = 0; i < 256; i++)
116  gammatable[i] = i;
117  return;
118  }
119 
120  for (i = 0; i < 256; i++) {
121  inf = 255 * pow((i + 0.5) / 255.5, g) + 0.5;
122  gammatable[i] = clamp(inf, 0, 255);
123  }
124 }

Referenced by R_InitImages().

◆ R_CreateNotexture()

static void R_CreateNotexture ( void  )
static

Definition at line 128 of file image.c.

129 {
130  static byte buffer[MIPSIZE(NTX * NTX) * TEX_BYTES];
131  int x, y, m;
132  uint32_t *p;
133  image_t *ntx;
134 
135 // create a simple checkerboard texture for the default
136  ntx = R_NOTEXTURE;
137  ntx->type = IT_WALL;
138  ntx->flags = 0;
139  ntx->width = ntx->height = NTX;
140  ntx->upload_width = ntx->upload_height = NTX;
141  ntx->pixels[0] = buffer;
142  ntx->pixels[1] = ntx->pixels[0] + NTX * NTX * TEX_BYTES;
143  ntx->pixels[2] = ntx->pixels[1] + NTX * NTX * TEX_BYTES / 4;
144  ntx->pixels[3] = ntx->pixels[2] + NTX * NTX * TEX_BYTES / 16;
145 
146  for (m = 0; m < 4; m++) {
147  p = (uint32_t *)ntx->pixels[m];
148  for (y = 0; y < (NTX >> m); y++) {
149  for (x = 0; x < (NTX >> m); x++) {
150  if ((x ^ y) & (1 << (3 - m)))
151  *p++ = U32_BLACK;
152  else
153  *p++ = U32_WHITE;
154  }
155  }
156  }
157 }

Referenced by R_InitImages().

◆ R_InitImages()

void R_InitImages ( void  )

Definition at line 164 of file image.c.

165 {
167 
168  IMG_GetPalette();
169 
171 
173 }

Referenced by R_Init().

◆ R_LightScaleTexture()

static void R_LightScaleTexture ( byte *  in,
int  inwidth,
int  inheight 
)
static

Definition at line 34 of file image.c.

35 {
36  int i, c;
37  byte *p;
38 
39  p = in;
40  c = inwidth * inheight;
41 
42  for (i = 0; i < c; i++, p += TEX_BYTES) {
43  p[0] = gammatable[p[0]];
44  p[1] = gammatable[p[1]];
45  p[2] = gammatable[p[2]];
46  }
47 }

Referenced by IMG_Load().

◆ R_ShutdownImages()

void R_ShutdownImages ( void  )

Definition at line 180 of file image.c.

181 {
182  IMG_FreeAll();
183 }

Referenced by R_Shutdown().

Variable Documentation

◆ gammatable

byte gammatable[256]
static

Definition at line 21 of file image.c.

Referenced by R_BuildGammaTable(), and R_LightScaleTexture().

IMG_GetPalette
void IMG_GetPalette(void)
Definition: images.c:1376
IMG_FreeAll
void IMG_FreeAll(void)
Definition: images.c:1343
height
static int height
Definition: physical_sky.c:39
image_t
struct image_s image_t
Definition: material.h:27
TEX_BYTES
#define TEX_BYTES
Definition: sw.h:50
IMG_MipMap
void IMG_MipMap(byte *out, byte *in, int width, int height)
Definition: images.c:623
IMG_ResampleTexture
void IMG_ResampleTexture(const byte *in, int inwidth, int inheight, byte *out, int outwidth, int outheight)
Definition: images.c:577
width
static int width
Definition: physical_sky.c:38
gammatable
static byte gammatable[256]
Definition: image.c:21
R_BuildGammaTable
void R_BuildGammaTable(void)
Definition: image.c:109
Z_Free
void Z_Free(void *ptr)
Definition: zone.c:147
m
static struct mdfour * m
Definition: mdfour.c:32
NTX
#define NTX
Definition: image.c:126
TURB_SIZE
#define TURB_SIZE
Definition: sw.h:71
R_CreateNotexture
static void R_CreateNotexture(void)
Definition: image.c:128
c
statCounters_t c
Definition: main.c:30
registration_sequence
int registration_sequence
Definition: main.c:34
vid_gamma
cvar_t * vid_gamma
Definition: main.c:104
R_LightScaleTexture
static void R_LightScaleTexture(byte *in, int inwidth, int inheight)
Definition: image.c:34
r_config
refcfg_t r_config
Definition: refresh.c:401