- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSWtexture.h
More file actions
Latest commit
72 lines (64 loc) · 4.64 KB
/
Copy pathSWtexture.h
File metadata and controls
72 lines (64 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndefSW_TEXTURE_H
#defineSW_TEXTURE_H
#include"SWcore.h"
#include"SWpixels.h"
typedefstructSWtexture {
SWenummode, type;
SWintw, h, type_size, pp_size;
void*pixels;
void (*free)(void*);
} SWtexture;
externSWfloat_sw_ubyte_to_float_table[256];
voidswTexInit(SWtexture*t, SWenummode, SWenumtype, SWintw, SWinth,
constvoid*pixels);
voidswTexInitMove(SWtexture*t, SWenummode, SWenumtype, SWintw, SWinth, void*pixels,
void (*free)(void*));
voidswTexInitMove_malloced(SWtexture*t, SWenummode, SWenumtype, SWintw, SWinth,
void*pixels);
voidswTexDestroy(SWtexture*t);
#defineswTex_RGB888_GetColorFloat_RGBA(t, u, v, rgba) \
swPx_RGB888_GetColor_FRGBA_UV((t)->w, (t)->h, (t)->pixels, u, v, rgba)
#defineswTexGetColorFloat_RGBA(t, u, v, rgba) \
{ \
SWint x = (SWint)(u * (t)->w) & ((t)->w - 1); \
SWint y = (SWint)(v * (t)->h) & ((t)->h - 1); \
\
switch ((t)->type) { \
case SW_UNSIGNED_BYTE: { \
SWint i; \
SWubyte *p = (SWubyte *)(t)->pixels; \
if ((t)->mode == SW_RGB) { \
p += 3 * (y * (t)->w + x); \
rgba[3] = (SWfloat)1.0; \
} else if ((t)->mode == SW_RGBA) { \
p += 4 * (y * (t)->w + x); \
rgba[3] = _sw_ubyte_to_float_table[p[3]]; \
} \
\
for (i = 0; i < 3; i++) { \
rgba[i] = _sw_ubyte_to_float_table[p[i]]; \
} \
} break; \
case SW_COMPRESSED: { \
const SWubyte *table = (const SWubyte *)(t)->pixels; \
const SWubyte *pixels = (const SWubyte *)(t)->pixels + 256 * 4 * 4; \
\
SWint i = 4 * (2 * (y & 1) + (x & 1)); \
x >>= 1; \
y >>= 1; \
const SWubyte index = pixels[y * ((t)->w >> 1) + x]; \
const SWubyte *_col = &table[index * 16 + i]; \
\
for (i = 0; i < 4; i++) { \
rgba[i] = _sw_ubyte_to_float_table[_col[i]]; \
} \
} break; \
default: \
break; \
} \
}
#defineswTexGetColorUbyte_RGBA(t, u, v, rgba) \
swPxGetColorUbyte_RGBA(t->type, t->mode, t->w, t->h, t->pixels, u, v, rgba)
#defineswTexGetColorUbyte_BGRA(t, u, v, bgra) \
swPxGetColorUbyte_BGRA(t->type, t->mode, t->w, t->h, t->pixels, u, v, bgra)
#endif/* SW_TEXTURE_H */