-
Notifications
You must be signed in to change notification settings - Fork 90
/
r_dither.h
76 lines (61 loc) · 1.77 KB
/
r_dither.h
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
73
74
75
76
#ifndef __R_DITHER__
#define __R_DITHER__
/*
Copyright (C) 2012 Szilard Biro
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
http://www.flipcode.com/archives/Texturing_As_In_Unreal.shtml
(X&1)==0 (X&1==1)
+---------------------------------
(Y&1)==0 | u+=.25,v+=.00 u+=.50,v+=.75
(Y&1)==1 | u+=.75,v+=.50 u+=.00,v+=.25
*/
#if 1
#define DitherKernel2(u, v, X, Y) \
if ((Y)&1) { \
if ((X)&1) { \
(u) = (u) + (32768); \
(v) = (v) + (49152); \
} else { \
(u) = (u) + (16384); \
} \
} else { \
if ((X)&1) { \
(v) = (v) + (32768); \
} else { \
(u) = (u) + (49152); \
(v) = (v) + (16384); \
} \
}
#else
#define DitherKernel2(u, v, X, Y) \
if ((Y)&1) { \
if ((X)&1) { \
(u) = (u) + (65536 * 0.50); /* 50 */ \
(v) = (v) + (65536 * 0.75); /* 75 */ \
} else { \
(u) = (u) + (65536 * 0.25); /* 25 */ \
(v) = (v) + (65536 * 0.0); /* 00 */ \
} \
} else { \
if ((X)&1) { \
(u) = (u) + (65536 * 0.0); /* 00 */ \
(v) = (v) + (65536 * 0.5); /* 25 */ \
} else { \
(u) = (u) + (65536 * 0.75); /* 75 */ \
(v) = (v) + (65536 * 0.25); /* 50 */ \
} \
}
#endif
#endif