diff options
Diffstat (limited to 'src/r_filter.h')
-rw-r--r-- | src/r_filter.h | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/src/r_filter.h b/src/r_filter.h new file mode 100644 index 0000000..8151eac --- /dev/null +++ b/src/r_filter.h | |||
@@ -0,0 +1,174 @@ | |||
1 | /* Emacs style mode select -*- C++ -*- | ||
2 | *----------------------------------------------------------------------------- | ||
3 | * | ||
4 | * | ||
5 | * PrBoom: a Doom port merged with LxDoom and LSDLDoom | ||
6 | * based on BOOM, a modified and improved DOOM engine | ||
7 | * Copyright (C) 1999 by | ||
8 | * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman | ||
9 | * Copyright (C) 1999-2000 by | ||
10 | * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze | ||
11 | * Copyright 2005, 2006 by | ||
12 | * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version 2 | ||
17 | * of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | * GNU General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
27 | * 02111-1307, USA. | ||
28 | * | ||
29 | *-----------------------------------------------------------------------------*/ | ||
30 | |||
31 | #ifndef R_FILTER_H | ||
32 | #define R_FILTER_H | ||
33 | |||
34 | #define DITHER_DIM 4 | ||
35 | |||
36 | extern byte filter_ditherMatrix[DITHER_DIM][DITHER_DIM]; | ||
37 | #define FILTER_UVBITS 6 | ||
38 | #define FILTER_UVDIM (1<<FILTER_UVBITS) | ||
39 | extern byte filter_roundedUVMap[FILTER_UVDIM*FILTER_UVDIM]; | ||
40 | extern byte filter_roundedRowMap[4*16]; | ||
41 | |||
42 | void R_FilterInit(void); | ||
43 | |||
44 | // Use the dither matrix to determine whether a pixel is on or off based | ||
45 | // on the overall intensity we're trying to simulate | ||
46 | #define filter_getDitheredPixelLevel(x, y, intensity) \ | ||
47 | ((filter_ditherMatrix[(y)&(DITHER_DIM-1)][(x)&(DITHER_DIM-1)] < (intensity)) ? 1 : 0) | ||
48 | |||
49 | // Choose current pixel or next pixel down based on dither of the fractional | ||
50 | // texture V coord. texV is not a true fractional texture coord, so it | ||
51 | // has to be converted using ((texV) - dcvars.yl) >> 8), which was empirically | ||
52 | // derived. the "-dcvars.yl" is apparently required to offset some minor | ||
53 | // shaking in coordinate y-axis and prevents dithering seams | ||
54 | #define FILTER_GETV(x,y,texV,nextRowTexV) \ | ||
55 | (filter_getDitheredPixelLevel(x, y, (((texV) - yl) >> 8)&0xff) ? ((nextRowTexV)>>FRACBITS) : ((texV)>>FRACBITS)) | ||
56 | |||
57 | // Choose current column or next column to the right based on dither of the | ||
58 | // fractional texture U coord | ||
59 | #define filter_getDitheredForColumn(x, y, texV, nextRowTexV) \ | ||
60 | dither_sources[(filter_getDitheredPixelLevel(x, y, filter_fracu))][FILTER_GETV(x,y,texV,nextRowTexV)] | ||
61 | |||
62 | #define filter_getRoundedForColumn(texV, nextRowTexV) \ | ||
63 | filter_getScale2xQuadColors( \ | ||
64 | source[ ((texV)>>FRACBITS) ], \ | ||
65 | source[ (MAX(0, ((texV)>>FRACBITS)-1)) ], \ | ||
66 | nextsource[ ((texV)>>FRACBITS) ], \ | ||
67 | source[ ((nextRowTexV)>>FRACBITS) ], \ | ||
68 | prevsource[ ((texV)>>FRACBITS) ] \ | ||
69 | ) \ | ||
70 | [ filter_roundedUVMap[ \ | ||
71 | ((filter_fracu>>(8-FILTER_UVBITS))<<FILTER_UVBITS) + \ | ||
72 | ((((texV)>>8) & 0xff)>>(8-FILTER_UVBITS)) \ | ||
73 | ] ] | ||
74 | |||
75 | #define filter_getRoundedForSpan(texU, texV) \ | ||
76 | filter_getScale2xQuadColors( \ | ||
77 | source[ (((texU)>>16)&0x3f) | (((texV)>>10)&0xfc0) ], \ | ||
78 | source[ (((texU)>>16)&0x3f) | ((((texV)-FRACUNIT)>>10)&0xfc0) ], \ | ||
79 | source[ ((((texU)+FRACUNIT)>>16)&0x3f) | (((texV)>>10)&0xfc0) ], \ | ||
80 | source[ (((texU)>>16)&0x3f) | ((((texV)+FRACUNIT)>>10)&0xfc0) ], \ | ||
81 | source[ ((((texU)-FRACUNIT)>>16)&0x3f) | (((texV)>>10)&0xfc0) ] \ | ||
82 | ) \ | ||
83 | [ filter_roundedUVMap[ \ | ||
84 | (((((texU)>>8) & 0xff)>>(8-FILTER_UVBITS))<<FILTER_UVBITS) + \ | ||
85 | ((((texV)>>8) & 0xff)>>(8-FILTER_UVBITS)) \ | ||
86 | ] ] | ||
87 | |||
88 | byte *filter_getScale2xQuadColors(byte e, byte b, byte f, byte h, byte d); | ||
89 | |||
90 | // This is the horrendous macro version of the function commented out of | ||
91 | // r_filter.c. It does a bilinear blend on the four source texels for a | ||
92 | // given u and v | ||
93 | #define filter_getFilteredForColumn32(depthmap, texV, nextRowTexV) ( \ | ||
94 | VID_PAL32( depthmap(nextsource[(nextRowTexV)>>FRACBITS]), (filter_fracu*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS) ) + \ | ||
95 | VID_PAL32( depthmap(source[(nextRowTexV)>>FRACBITS]), ((0xffff-filter_fracu)*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS) ) + \ | ||
96 | VID_PAL32( depthmap(source[(texV)>>FRACBITS]), ((0xffff-filter_fracu)*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS) ) + \ | ||
97 | VID_PAL32( depthmap(nextsource[(texV)>>FRACBITS]), (filter_fracu*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS) )) | ||
98 | |||
99 | // The 16 bit method of the filtering doesn't really maintain enough | ||
100 | // accuracy for discerning viewers, but the alternative requires converting | ||
101 | // from 32 bit, which is slow and requires both the intPalette and the | ||
102 | // shortPalette to be in memory at the same time. | ||
103 | #define filter_getFilteredForColumn16(depthmap, texV, nextRowTexV) ( \ | ||
104 | VID_PAL16( depthmap(nextsource[(nextRowTexV)>>FRACBITS]), (filter_fracu*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS) ) + \ | ||
105 | VID_PAL16( depthmap(source[(nextRowTexV)>>FRACBITS]), ((0xffff-filter_fracu)*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS) ) + \ | ||
106 | VID_PAL16( depthmap(source[(texV)>>FRACBITS]), ((0xffff-filter_fracu)*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS) ) + \ | ||
107 | VID_PAL16( depthmap(nextsource[(texV)>>FRACBITS]), (filter_fracu*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS) )) | ||
108 | |||
109 | #define filter_getFilteredForColumn15(depthmap, texV, nextRowTexV) ( \ | ||
110 | VID_PAL15( depthmap(nextsource[(nextRowTexV)>>FRACBITS]), (filter_fracu*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS) ) + \ | ||
111 | VID_PAL15( depthmap(source[(nextRowTexV)>>FRACBITS]), ((0xffff-filter_fracu)*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS) ) + \ | ||
112 | VID_PAL15( depthmap(source[(texV)>>FRACBITS]), ((0xffff-filter_fracu)*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS) ) + \ | ||
113 | VID_PAL15( depthmap(nextsource[(texV)>>FRACBITS]), (filter_fracu*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS) )) | ||
114 | |||
115 | // Same as for column but wrapping at 64 | ||
116 | #define filter_getFilteredForSpan32(depthmap, texU, texV) ( \ | ||
117 | VID_PAL32( depthmap(source[ ((((texU)+FRACUNIT)>>16)&0x3f) | ((((texV)+FRACUNIT)>>10)&0xfc0)]), (unsigned int)(((texU)&0xffff)*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS)) + \ | ||
118 | VID_PAL32( depthmap(source[ (((texU)>>16)&0x3f) | ((((texV)+FRACUNIT)>>10)&0xfc0)]), (unsigned int)((0xffff-((texU)&0xffff))*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS)) + \ | ||
119 | VID_PAL32( depthmap(source[ (((texU)>>16)&0x3f) | (((texV)>>10)&0xfc0)]), (unsigned int)((0xffff-((texU)&0xffff))*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS)) + \ | ||
120 | VID_PAL32( depthmap(source[ ((((texU)+FRACUNIT)>>16)&0x3f) | (((texV)>>10)&0xfc0)]), (unsigned int)(((texU)&0xffff)*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS))) | ||
121 | |||
122 | // Use 16 bit addition here since it's a little faster and the defects from | ||
123 | // such low-accuracy blending are less visible on spans | ||
124 | #define filter_getFilteredForSpan16(depthmap, texU, texV) ( \ | ||
125 | VID_PAL16( depthmap(source[ ((((texU)+FRACUNIT)>>16)&0x3f) | ((((texV)+FRACUNIT)>>10)&0xfc0)]), (unsigned int)(((texU)&0xffff)*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS)) + \ | ||
126 | VID_PAL16( depthmap(source[ (((texU)>>16)&0x3f) | ((((texV)+FRACUNIT)>>10)&0xfc0)]), (unsigned int)((0xffff-((texU)&0xffff))*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS)) + \ | ||
127 | VID_PAL16( depthmap(source[ (((texU)>>16)&0x3f) | (((texV)>>10)&0xfc0)]), (unsigned int)((0xffff-((texU)&0xffff))*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS)) + \ | ||
128 | VID_PAL16( depthmap(source[ ((((texU)+FRACUNIT)>>16)&0x3f) | (((texV)>>10)&0xfc0)]), (unsigned int)(((texU)&0xffff)*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS))) | ||
129 | |||
130 | #define filter_getFilteredForSpan15(depthmap, texU, texV) ( \ | ||
131 | VID_PAL15( depthmap(source[ ((((texU)+FRACUNIT)>>16)&0x3f) | ((((texV)+FRACUNIT)>>10)&0xfc0)]), (unsigned int)(((texU)&0xffff)*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS)) + \ | ||
132 | VID_PAL15( depthmap(source[ (((texU)>>16)&0x3f) | ((((texV)+FRACUNIT)>>10)&0xfc0)]), (unsigned int)((0xffff-((texU)&0xffff))*((texV)&0xffff))>>(32-VID_COLORWEIGHTBITS)) + \ | ||
133 | VID_PAL15( depthmap(source[ (((texU)>>16)&0x3f) | (((texV)>>10)&0xfc0)]), (unsigned int)((0xffff-((texU)&0xffff))*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS)) + \ | ||
134 | VID_PAL15( depthmap(source[ ((((texU)+FRACUNIT)>>16)&0x3f) | (((texV)>>10)&0xfc0)]), (unsigned int)(((texU)&0xffff)*(0xffff-((texV)&0xffff)))>>(32-VID_COLORWEIGHTBITS))) | ||
135 | |||
136 | // do red and blue at once for slight speedup | ||
137 | |||
138 | #define GETBLENDED15_5050(col1, col2) \ | ||
139 | ((((col1&0x7c1f)+(col2&0x7c1f))>>1)&0x7c1f) | \ | ||
140 | ((((col1&0x03e0)+(col2&0x03e0))>>1)&0x03e0) | ||
141 | |||
142 | #define GETBLENDED16_5050(col1, col2) \ | ||
143 | ((((col1&0xf81f)+(col2&0xf81f))>>1)&0xf81f) | \ | ||
144 | ((((col1&0x07e0)+(col2&0x07e0))>>1)&0x07e0) | ||
145 | |||
146 | #define GETBLENDED32_5050(col1, col2) \ | ||
147 | ((((col1&0xff00ff)+(col2&0xff00ff))>>1)&0xff00ff) | \ | ||
148 | ((((col1&0x00ff00)+(col2&0x00ff00))>>1)&0x00ff00) | ||
149 | |||
150 | #define GETBLENDED15_3268(col1, col2) \ | ||
151 | ((((col1&0x7c1f)*5+(col2&0x7c1f)*11)>>4)&0x7c1f) | \ | ||
152 | ((((col1&0x03e0)*5+(col2&0x03e0)*11)>>4)&0x03e0) | ||
153 | |||
154 | #define GETBLENDED16_3268(col1, col2) \ | ||
155 | ((((col1&0xf81f)*5+(col2&0xf81f)*11)>>4)&0xf81f) | \ | ||
156 | ((((col1&0x07e0)*5+(col2&0x07e0)*11)>>4)&0x07e0) | ||
157 | |||
158 | #define GETBLENDED32_3268(col1, col2) \ | ||
159 | ((((col1&0xff00ff)*5+(col2&0xff00ff)*11)>>4)&0xff00ff) | \ | ||
160 | ((((col1&0x00ff00)*5+(col2&0x00ff00)*11)>>4)&0x00ff00) | ||
161 | |||
162 | #define GETBLENDED15_9406(col1, col2) \ | ||
163 | ((((col1&0x7c1f)*15+(col2&0x7c1f))>>4)&0x7c1f) | \ | ||
164 | ((((col1&0x03e0)*15+(col2&0x03e0))>>4)&0x03e0) | ||
165 | |||
166 | #define GETBLENDED16_9406(col1, col2) \ | ||
167 | ((((col1&0xf81f)*15+(col2&0xf81f))>>4)&0xf81f) | \ | ||
168 | ((((col1&0x07e0)*15+(col2&0x07e0))>>4)&0x07e0) | ||
169 | |||
170 | #define GETBLENDED32_9406(col1, col2) \ | ||
171 | ((((col1&0xff00ff)*15+(col2&0xff00ff))>>4)&0xff00ff) | \ | ||
172 | ((((col1&0x00ff00)*15+(col2&0x00ff00))>>4)&0x00ff00) | ||
173 | |||
174 | #endif | ||