Project

General

Profile

Download (4.82 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / effect / FragmentEffectContrast.java @ 7625e47e

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.Data4D;
24
import org.distorted.library.type.Dynamic1D;
25
import org.distorted.library.type.Dynamic4D;
26
import org.distorted.library.type.Static1D;
27
import org.distorted.library.type.Static4D;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class FragmentEffectContrast extends FragmentEffect
32
  {
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
/**
35
 * Makes a certain sub-region of the Object smoothly change its contrast level.
36
 *
37
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
38
 *                 at any given moment. Valid range: <0,infinity)
39
 * @param region   Region this Effect is limited to.
40
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
41
 */
42
  public FragmentEffectContrast(Data1D contrast, Data4D region, boolean smooth)
43
    {
44
    super(smooth?EffectName.SMOOTH_CONTRAST:EffectName.CONTRAST);
45

    
46
    if( contrast instanceof Dynamic1D )
47
      {
48
      mDynamic0 = (Dynamic1D)contrast;
49
      }
50
    else if ( contrast instanceof Static1D )
51
      {
52
      mStatic0 = (Static1D)contrast;
53
      }
54

    
55
    if( region == null )
56
      {
57
      mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
58
      }
59
    else
60
      {
61
      if (region instanceof Static4D)
62
        {
63
        mStaticRegion = (Static4D) region;
64
        }
65
      else if (region instanceof Dynamic4D)
66
        {
67
        mDynamicRegion = (Dynamic4D) region;
68
        }
69
      }
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
/**
74
 * Makes the whole Object smoothly change its contrast level.
75
 *
76
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
77
 *                 at any given moment. Valid range: <0,infinity)
78
 */
79
  public FragmentEffectContrast(Data1D contrast)
80
    {
81
    super(EffectName.CONTRAST);
82

    
83
    if( contrast instanceof Dynamic1D )
84
      {
85
      mDynamic0 = (Dynamic1D)contrast;
86
      }
87
    else if ( contrast instanceof Static1D )
88
      {
89
      mStatic0 = (Static1D)contrast;
90
      }
91

    
92
    mStaticRegion = new Static4D(0,0,Float.MAX_VALUE, Float.MAX_VALUE);
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  public boolean compute(float[] uniforms, int index, long currentDuration, long step )
98
    {
99
    if( mDynamicRegion!=null )
100
      {
101
      mDynamicRegion.interpolateMain(uniforms,index+4,currentDuration,step);
102
      }
103
    else
104
      {
105
      uniforms[index+4] = mStaticRegion.getX();
106
      uniforms[index+5] = mStaticRegion.getY();
107
      uniforms[index+6] = mStaticRegion.getZ();
108
      uniforms[index+7] = mStaticRegion.getW();
109
      }
110

    
111
    if( mDynamic0!=null )
112
      {
113
      return mDynamic0.interpolateMain(uniforms,index,currentDuration,step);
114
      }
115
    else
116
      {
117
      uniforms[index] = ((Static1D)mStatic0).getX();
118
      return false;
119
      }
120
    }
121
  }
(8-8/25)