1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2017 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.library.effect;
|
21
|
|
22
|
import org.distorted.library.type.Data1D;
|
23
|
import org.distorted.library.type.Data3D;
|
24
|
import org.distorted.library.type.Data4D;
|
25
|
import org.distorted.library.type.Dynamic1D;
|
26
|
import org.distorted.library.type.Dynamic3D;
|
27
|
import org.distorted.library.type.Static1D;
|
28
|
import org.distorted.library.type.Static3D;
|
29
|
|
30
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31
|
|
32
|
public class FragmentEffectChroma extends FragmentEffect
|
33
|
{
|
34
|
private static final float[] UNITIES = new float[] {0.0f};
|
35
|
private static final int DIMENSION = 4;
|
36
|
private static final boolean SUPPORTS_CENTER = false;
|
37
|
private static final boolean SUPPORTS_REGION = true;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
public FragmentEffectChroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
|
42
|
{
|
43
|
super(smooth?SMOOTH_CHROMA:CHROMA ,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION);
|
44
|
|
45
|
if( blend instanceof Dynamic1D )
|
46
|
{
|
47
|
mDynamic0 = (Dynamic1D)blend;
|
48
|
}
|
49
|
else if ( blend instanceof Static1D )
|
50
|
{
|
51
|
mStatic0 = (Static1D)blend;
|
52
|
}
|
53
|
|
54
|
if( color instanceof Dynamic3D )
|
55
|
{
|
56
|
mDynamic1 = (Dynamic3D)color;
|
57
|
}
|
58
|
else if ( color instanceof Static3D)
|
59
|
{
|
60
|
mStatic1 = (Static3D)color;
|
61
|
}
|
62
|
|
63
|
mRegion = region;
|
64
|
}
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
public FragmentEffectChroma(Data1D blend, Data3D color)
|
69
|
{
|
70
|
super(CHROMA,UNITIES,DIMENSION,SUPPORTS_CENTER,SUPPORTS_REGION);
|
71
|
|
72
|
if( blend instanceof Dynamic1D )
|
73
|
{
|
74
|
mDynamic0 = (Dynamic1D)blend;
|
75
|
}
|
76
|
else if ( blend instanceof Static1D )
|
77
|
{
|
78
|
mStatic0 = (Static1D)blend;
|
79
|
}
|
80
|
|
81
|
if( color instanceof Dynamic3D )
|
82
|
{
|
83
|
mDynamic1 = (Dynamic3D)color;
|
84
|
}
|
85
|
else if ( color instanceof Static3D)
|
86
|
{
|
87
|
mStatic1 = (Static3D)color;
|
88
|
}
|
89
|
}
|
90
|
|
91
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92
|
|
93
|
public boolean compute(float[] uniforms, int index, long currentDuration, long step )
|
94
|
{
|
95
|
if( mDynamic1!=null )
|
96
|
{
|
97
|
mDynamic1.interpolateMain(uniforms,index+1,currentDuration,step);
|
98
|
}
|
99
|
else
|
100
|
{
|
101
|
uniforms[index+1] = ((Static3D)mStatic1).getX();
|
102
|
uniforms[index+2] = ((Static3D)mStatic1).getY();
|
103
|
uniforms[index+3] = ((Static3D)mStatic1).getZ();
|
104
|
}
|
105
|
|
106
|
if( mDynamic0!=null )
|
107
|
{
|
108
|
return mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
|
109
|
}
|
110
|
else
|
111
|
{
|
112
|
uniforms[index ] = ((Static1D)mStatic0).getX();
|
113
|
return false;
|
114
|
}
|
115
|
}
|
116
|
}
|