1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// Distorted is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Distorted is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.examples.aroundtheworld;
|
21
|
|
22
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
23
|
|
24
|
import org.distorted.library.DistortedEffects;
|
25
|
import org.distorted.library.type.Dynamic1D;
|
26
|
import org.distorted.library.type.Dynamic2D;
|
27
|
import org.distorted.library.type.Dynamic3D;
|
28
|
import org.distorted.library.type.Static1D;
|
29
|
import org.distorted.library.type.Static2D;
|
30
|
import org.distorted.library.type.Static3D;
|
31
|
import org.distorted.library.type.Static4D;
|
32
|
|
33
|
class AroundTheWorldEffectsManager
|
34
|
{
|
35
|
private float mWhiteness, mBlackness, mAsianness; // those always sum up to 1
|
36
|
|
37
|
// WHITENESS
|
38
|
// Vertex effects:
|
39
|
// a) make the lips smaller (SINK)
|
40
|
private Static4D wLipsRegion;
|
41
|
private Static3D wLipsCenter;
|
42
|
private Static1D wLipsFactor;
|
43
|
private Dynamic1D wLipsDyn;
|
44
|
|
45
|
// ASIANNESS
|
46
|
// Vertex Effects:
|
47
|
// a) move lips & nose higher (DISTORT)
|
48
|
private Static4D aLipsNoseRegion;
|
49
|
private Static3D aLipsNoseCenter;
|
50
|
private Static3D aLipsNoseFactor;
|
51
|
private Dynamic3D aLipsNoseDyn;
|
52
|
// b) make the nose broader (PINCH)
|
53
|
private Static4D aNoseBroaderRegion;
|
54
|
private Static3D aNoseBroaderCenter;
|
55
|
private Static2D aNoseBroaderFactor;
|
56
|
private Dynamic2D aNoseBroaderDyn;
|
57
|
// c) make the nostrils more visible (DISTORT)
|
58
|
private Static4D aNostrilsRegion;
|
59
|
private Static3D aNostrilsCenter;
|
60
|
private Static3D aNostrilsFactor;
|
61
|
private Dynamic3D aNostrilsDyn;
|
62
|
// d) rotate eyes (2 x SWIRL)
|
63
|
private Static4D aEyesRegion;
|
64
|
private Static3D aLEyeCenter, aREyeCenter;
|
65
|
private Static1D aLEyeFactor, aREyeFactor;
|
66
|
private Dynamic1D aLEyeDyn, aREyeDyn;
|
67
|
// e) move eyebrow higher (DISTORT)
|
68
|
private Static4D aEyebrowsRegion;
|
69
|
private Static3D aEyebrowsCenter;
|
70
|
private Static3D aEyebrowsFactor;
|
71
|
private Dynamic3D aEyebrowsDyn;
|
72
|
|
73
|
// Fragment effects:
|
74
|
// a) change color of the skin to more brown and less red (CHROMA)
|
75
|
private Static4D aSkinColorRegion;
|
76
|
private Static3D aChromaSkin;
|
77
|
private Static1D aChromaSkinFactor;
|
78
|
private Dynamic1D aChromaSkinDyn;
|
79
|
// b) darken both eyes (2 x SMOOTH_CHROMA)
|
80
|
private Static4D aLEyeColorRegion, aREyeColorRegion;
|
81
|
private Static3D aChromaEyes;
|
82
|
private Static1D aChromaEyesFactor;
|
83
|
private Dynamic1D aChromaEyesDyn;
|
84
|
|
85
|
// BLACKNESS
|
86
|
// Vertex Effects
|
87
|
// a) make the whole face broader (PINCH)
|
88
|
private Static4D bFaceRegion;
|
89
|
private Static3D bFaceCenter;
|
90
|
private Static2D bFaceFactor;
|
91
|
private Dynamic2D bFaceDyn;
|
92
|
// b) tip of the nose lower (DISTORT)
|
93
|
private Static4D bTipLowerRegion;
|
94
|
private Static3D bTipLowerCenter;
|
95
|
private Static3D bTipLowerFactor;
|
96
|
private Dynamic3D bTipLowerDyn;
|
97
|
// c) broaden the whole nose: (PINCH)
|
98
|
private Static4D bWholeNoseRegion;
|
99
|
private Static3D bWholeNoseCenter;
|
100
|
private Static2D bWholeNoseFactor;
|
101
|
private Dynamic2D bWholeNoseDyn;
|
102
|
// d) broaden the tip of the nose some more: (PINCH)
|
103
|
private Static4D bNoseBroaderRegion;
|
104
|
private Static3D bNoseBroaderCenter;
|
105
|
private Static2D bNoseBroaderFactor;
|
106
|
private Dynamic2D bNoseBroaderDyn;
|
107
|
// 3) make lips higher: (PINCH)
|
108
|
private Static4D bLipsRegion;
|
109
|
private Static3D bLipsCenter;
|
110
|
private Static2D bLipsFactor;
|
111
|
private Dynamic2D bLipsDyn;
|
112
|
// Fragment effects
|
113
|
// a) make the whole face darker (CHROMA)
|
114
|
private Static4D bSkinColorRegion;
|
115
|
private Static3D bChromaSkin;
|
116
|
private Static1D bChromaSkinFactor;
|
117
|
private Dynamic1D bChromaSkinDyn;
|
118
|
// b) move both eyes back to whiteness (2 x SMOOTH CHROMA)
|
119
|
private Static4D bLEyeColorRegion, bREyeColorRegion;
|
120
|
private Static3D bChromaEyes;
|
121
|
private Static1D bChromaEyesFactor;
|
122
|
private Dynamic1D bChromaEyesDyn;
|
123
|
// c) darken both pupils (2 x SMOOTH_CHROMA)
|
124
|
private Static4D bLPupilColorRegion, bRPupilColorRegion;
|
125
|
private Static3D bChromaPupil;
|
126
|
private Static1D bChromaPupilFactor;
|
127
|
private Dynamic1D bChromaPupilDyn;
|
128
|
// d) all those chroma effects have reduced contrast - bring it back
|
129
|
private Static1D bContrastFactor;
|
130
|
private Dynamic1D bContrastDyn;
|
131
|
|
132
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
133
|
|
134
|
AroundTheWorldEffectsManager()
|
135
|
{
|
136
|
mWhiteness = 1;
|
137
|
mBlackness = 0;
|
138
|
mAsianness = 0;
|
139
|
|
140
|
// WHITENESS
|
141
|
// Vertex Effects
|
142
|
wLipsRegion = new Static4D(0,0,100,100);
|
143
|
wLipsCenter = new Static3D(300,500,0);
|
144
|
wLipsFactor = new Static1D(0.7f);
|
145
|
wLipsDyn = new Dynamic1D();
|
146
|
wLipsDyn.add(wLipsFactor);
|
147
|
|
148
|
// ASIANNESS
|
149
|
// Vertex Effects
|
150
|
aLipsNoseRegion = new Static4D(0,0,267,267);
|
151
|
aLipsNoseCenter = new Static3D(300,560,0);
|
152
|
aLipsNoseDyn = new Dynamic3D();
|
153
|
aLipsNoseFactor = new Static3D(0,0,0);
|
154
|
aLipsNoseDyn.add(aLipsNoseFactor);
|
155
|
|
156
|
aNoseBroaderRegion = new Static4D(0,0,130,130);
|
157
|
aNoseBroaderCenter = new Static3D(300,307,0);
|
158
|
aNoseBroaderDyn = new Dynamic2D();
|
159
|
aNoseBroaderFactor = new Static2D(0,90);
|
160
|
aNoseBroaderDyn.add(aNoseBroaderFactor);
|
161
|
|
162
|
aNostrilsRegion = new Static4D(0,0,60,60);
|
163
|
aNostrilsCenter = new Static3D(300,336,0);
|
164
|
aNostrilsDyn = new Dynamic3D();
|
165
|
aNostrilsFactor = new Static3D(0,0,0);
|
166
|
aNostrilsDyn.add(aNostrilsFactor);
|
167
|
|
168
|
aEyesRegion = new Static4D(0,0,83,83);
|
169
|
aLEyeCenter = new Static3D(176,230,0);
|
170
|
aREyeCenter = new Static3D(420,230,0);
|
171
|
aLEyeDyn = new Dynamic1D();
|
172
|
aREyeDyn = new Dynamic1D();
|
173
|
aLEyeFactor = new Static1D(0);
|
174
|
aREyeFactor = new Static1D(0);
|
175
|
aLEyeDyn.add(aLEyeFactor);
|
176
|
aREyeDyn.add(aREyeFactor);
|
177
|
|
178
|
aEyebrowsRegion = new Static4D(0,0,142,142);
|
179
|
aEyebrowsCenter = new Static3D(300,100,0);
|
180
|
aEyebrowsDyn = new Dynamic3D();
|
181
|
aEyebrowsFactor = new Static3D(0,0,0);
|
182
|
aEyebrowsDyn.add(aEyebrowsFactor);
|
183
|
|
184
|
// Fragment Effects
|
185
|
aSkinColorRegion = new Static4D(300,300,600,600);
|
186
|
aLEyeColorRegion = new Static4D(172,230,29,25);
|
187
|
aREyeColorRegion = new Static4D(423,230,29,25);
|
188
|
|
189
|
aChromaSkin = new Static3D(0.5f, 0.5f, 0.5f);
|
190
|
aChromaEyes = new Static3D(0.5f, 0.14f, 0.14f);
|
191
|
aChromaSkinFactor = new Static1D(0.0f);
|
192
|
aChromaEyesFactor = new Static1D(0.0f);
|
193
|
|
194
|
aChromaSkinDyn = new Dynamic1D();
|
195
|
aChromaSkinDyn.add(aChromaSkinFactor);
|
196
|
aChromaEyesDyn = new Dynamic1D();
|
197
|
aChromaEyesDyn.add(aChromaEyesFactor);
|
198
|
|
199
|
// BLACKNESS
|
200
|
// Vertex Effects
|
201
|
bFaceRegion = new Static4D(0,0,600,600);
|
202
|
bFaceCenter = new Static3D(300,300,0);
|
203
|
bFaceFactor = new Static2D(1.0f,90.0f);
|
204
|
bFaceDyn = new Dynamic2D();
|
205
|
bFaceDyn.add(bFaceFactor);
|
206
|
|
207
|
bTipLowerRegion = new Static4D(0,0,41,41);
|
208
|
bTipLowerCenter = new Static3D(300,393,0);
|
209
|
bTipLowerFactor = new Static3D(0,0,0);
|
210
|
bTipLowerDyn = new Dynamic3D();
|
211
|
bTipLowerDyn.add(bTipLowerFactor);
|
212
|
|
213
|
bWholeNoseRegion = new Static4D(0,0,130,130);
|
214
|
bWholeNoseCenter = new Static3D(300,357,0);
|
215
|
bWholeNoseFactor = new Static2D(1.0f,90.0f);
|
216
|
bWholeNoseDyn = new Dynamic2D();
|
217
|
bWholeNoseDyn.add(bWholeNoseFactor);
|
218
|
|
219
|
bNoseBroaderRegion = new Static4D(0,0,95,95);
|
220
|
bNoseBroaderCenter = new Static3D(300,408,0);
|
221
|
bNoseBroaderFactor = new Static2D(1.0f,90.0f);
|
222
|
bNoseBroaderDyn = new Dynamic2D();
|
223
|
bNoseBroaderDyn.add(bNoseBroaderFactor);
|
224
|
|
225
|
bLipsRegion = new Static4D(0,96,118,118);
|
226
|
bLipsCenter = new Static3D(300,458,0);
|
227
|
bLipsFactor = new Static2D(1.0f,0.0f);
|
228
|
bLipsDyn = new Dynamic2D();
|
229
|
bLipsDyn.add(bLipsFactor);
|
230
|
|
231
|
// Fragment Effects
|
232
|
bSkinColorRegion = new Static4D(300,300,600,600);
|
233
|
bLEyeColorRegion = new Static4D(158,241,55,24);
|
234
|
bREyeColorRegion = new Static4D(436,241,55,24);
|
235
|
bLPupilColorRegion = new Static4D(166,230,28,23);
|
236
|
bRPupilColorRegion = new Static4D(431,230,28,23);
|
237
|
|
238
|
bChromaSkin = new Static3D(0.4f, 0.25f, 0.25f);
|
239
|
bChromaEyes = new Static3D(1.0f, 1.0f, 1.0f);
|
240
|
bChromaPupil = new Static3D(0.4f, 0.14f, 0.14f);
|
241
|
bChromaSkinFactor = new Static1D(0.0f);
|
242
|
bChromaPupilFactor = new Static1D(0.0f);
|
243
|
bChromaEyesFactor = new Static1D(0.0f);
|
244
|
bContrastFactor = new Static1D(0.0f);
|
245
|
|
246
|
bChromaSkinDyn = new Dynamic1D();
|
247
|
bChromaSkinDyn.add(bChromaSkinFactor);
|
248
|
bChromaEyesDyn = new Dynamic1D();
|
249
|
bChromaEyesDyn.add(bChromaEyesFactor);
|
250
|
bChromaPupilDyn = new Dynamic1D();
|
251
|
bChromaPupilDyn.add(bChromaPupilFactor);
|
252
|
bContrastDyn = new Dynamic1D();
|
253
|
bContrastDyn.add(bContrastFactor);
|
254
|
}
|
255
|
|
256
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
257
|
|
258
|
synchronized void apply(DistortedEffects effects)
|
259
|
{
|
260
|
setRace(mBlackness, mAsianness);
|
261
|
|
262
|
// WHITENESS
|
263
|
effects.sink(wLipsDyn, wLipsCenter, wLipsRegion);
|
264
|
|
265
|
// ASIANNESS
|
266
|
effects.distort(aLipsNoseDyn, aLipsNoseCenter, aLipsNoseRegion);
|
267
|
effects.pinch(aNoseBroaderDyn, aNoseBroaderCenter, aNoseBroaderRegion);
|
268
|
effects.distort(aNostrilsDyn, aNostrilsCenter, aNostrilsRegion);
|
269
|
effects.swirl(aLEyeDyn, aLEyeCenter, aEyesRegion);
|
270
|
effects.swirl(aREyeDyn, aREyeCenter, aEyesRegion);
|
271
|
effects.distort(aEyebrowsDyn, aEyebrowsCenter, aEyebrowsRegion);
|
272
|
|
273
|
effects.chroma(aChromaSkinDyn, aChromaSkin, aSkinColorRegion, false);
|
274
|
effects.chroma(aChromaEyesDyn, aChromaEyes, aLEyeColorRegion, true);
|
275
|
effects.chroma(aChromaEyesDyn, aChromaEyes, aREyeColorRegion, true);
|
276
|
|
277
|
// BLACKNESS
|
278
|
effects.pinch(bFaceDyn, bFaceCenter, bFaceRegion);
|
279
|
effects.distort(bTipLowerDyn, bTipLowerCenter, bTipLowerRegion);
|
280
|
effects.pinch(bWholeNoseDyn, bWholeNoseCenter, bWholeNoseRegion);
|
281
|
effects.pinch(bNoseBroaderDyn, bNoseBroaderCenter, bNoseBroaderRegion);
|
282
|
effects.pinch(bLipsDyn, bLipsCenter, bLipsRegion);
|
283
|
|
284
|
effects.chroma(bChromaSkinDyn, bChromaSkin, bSkinColorRegion, false);
|
285
|
effects.chroma(bChromaEyesDyn, bChromaEyes, bLEyeColorRegion, true);
|
286
|
effects.chroma(bChromaEyesDyn, bChromaEyes, bREyeColorRegion, true);
|
287
|
effects.chroma(bChromaPupilDyn, bChromaPupil, bLPupilColorRegion, true);
|
288
|
effects.chroma(bChromaPupilDyn, bChromaPupil, bRPupilColorRegion, true);
|
289
|
|
290
|
effects.contrast(bContrastDyn);
|
291
|
}
|
292
|
|
293
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
294
|
|
295
|
synchronized void setRace(float blackness, float asianness)
|
296
|
{
|
297
|
mWhiteness = 1 - blackness - asianness;
|
298
|
mAsianness = asianness;
|
299
|
mBlackness = blackness;
|
300
|
|
301
|
//android.util.Log.e("manager", "blackness="+blackness+" asianness="+asianness);
|
302
|
|
303
|
// WHITENESS
|
304
|
wLipsFactor.set(1.0f-0.3f*mWhiteness);
|
305
|
|
306
|
// ASIANNESS
|
307
|
aLipsNoseFactor.set2(-23.0f*mAsianness);
|
308
|
aNoseBroaderFactor.set1(1.0f+0.85f*mAsianness);
|
309
|
aNostrilsFactor.set2(-12.0f*mAsianness);
|
310
|
aLEyeFactor.set(+10.0f*mAsianness);
|
311
|
aREyeFactor.set(-10.0f*mAsianness);
|
312
|
aEyebrowsFactor.set2(-40.0f*mAsianness);
|
313
|
|
314
|
aChromaSkinFactor.set(0.2f*mAsianness);
|
315
|
aChromaEyesFactor.set(0.7f*mAsianness);
|
316
|
|
317
|
// BLACKNESS
|
318
|
bFaceFactor.set1(1.0f + 0.1f*mBlackness);
|
319
|
bTipLowerFactor.set2(23.0f*mBlackness);
|
320
|
bWholeNoseFactor.set1(1.0f+0.5f*mBlackness);
|
321
|
bNoseBroaderFactor.set1(1.0f+0.38f*mBlackness);
|
322
|
bLipsFactor.set1(1.0f+1.0f*mBlackness);
|
323
|
|
324
|
bChromaSkinFactor.set(0.75f*mBlackness);
|
325
|
bChromaEyesFactor.set(0.2f*mBlackness);
|
326
|
bChromaPupilFactor.set(0.6f*mBlackness);
|
327
|
|
328
|
bContrastFactor.set(1.0f+1.5f*mBlackness);
|
329
|
}
|
330
|
}
|