summaryrefslogtreecommitdiff
path: root/src/player/HueSatFXNode.cpp
blob: b15f3338dfc9e576710b8603ee1faa040b4ac1cd (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
//  libavg - Media Playback Engine. 
//  Copyright (C) 2003-2014 Ulrich von Zadow
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library 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
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  Current versions can be found at www.libavg.de
//


#include "HueSatFXNode.h"

#include "../base/ObjectCounter.h"
#include "../base/Logger.h"

#include "../graphics/BitmapLoader.h"

#include<sstream>

using namespace std;

namespace avg {

HueSatFXNode::HueSatFXNode(int hue, int saturation, int lightness, bool bColorize)
    : FXNode(),
      m_fHue(hue),
      m_fLightnessOffset(lightness),
      m_fSaturation(saturation),
      m_bColorize(bColorize)
{
    ObjectCounter::get()->incRef(&typeid(*this));
}

HueSatFXNode::~HueSatFXNode()
{
    ObjectCounter::get()->decRef(&typeid(*this));
}

void HueSatFXNode::disconnect()
{
    filterPtr = GPUHueSatFilterPtr();
    FXNode::disconnect();
}

int HueSatFXNode::getHue()
{
    if (m_bColorize) {
        if (m_fHue < 0) {
            return 360 + m_fHue;
        }
        return m_fHue;
    }

    if (m_fHue/180.0 > 1.0) {
        return -360+m_fHue;
    } else if (m_fHue/180.0 < -1.0) {
        return 360+m_fHue;
    }
    return m_fHue;
}

int HueSatFXNode::getSaturation()
{
    return m_fSaturation;
}

int HueSatFXNode::getLightnessOffset()
{
    return m_fLightnessOffset;
}

bool HueSatFXNode::isColorizing()
{
    return m_bColorize;
}

void HueSatFXNode::setHue(int hue)
{
    m_fHue = hue % 360;
    setFilterParams();
}

void HueSatFXNode::setSaturation(int saturation)
{
    if (m_bColorize) {
        m_fSaturation = clamp(saturation, 0, 100);
    } else {
        m_fSaturation = clamp(saturation, -100, 100); 
    }
    setFilterParams();
}

void HueSatFXNode::setLightnessOffset(int lightnessOffset)
{
    m_fLightnessOffset = clamp(lightnessOffset, -100, 100);
    setFilterParams();
}

void HueSatFXNode::setColorizing(bool colorize)
{
    m_bColorize = colorize;
    setFilterParams();
}

GPUFilterPtr HueSatFXNode::createFilter(const IntPoint& size)
{
    filterPtr = GPUHueSatFilterPtr(new GPUHueSatFilter(size, true, false));
    setFilterParams();
    return filterPtr;
}

void HueSatFXNode::setFilterParams()
{
    if (filterPtr) {
        filterPtr->setParams(m_fHue, m_fSaturation, m_fLightnessOffset, m_bColorize);
        setDirty();
    }
}

std::string HueSatFXNode::toString()
{
    stringstream s;
    s << "HueSatFXNode( Hue: " << m_fHue << ", Saturation: " << m_fSaturation << 
            ", Lightness: " << m_fLightnessOffset << ", Colorize: " << m_bColorize <<
            " )";
    return s.str();
}

int HueSatFXNode::clamp(int val, int min, int max)
{
    int result = val;
    if (val < min) {
        result = min;
    } else if (val > max) {
        result = max;
    }
    return result;
}

}