summaryrefslogtreecommitdiff
path: root/src/player/ChromaKeyFXNode.cpp
blob: 4e704542cdc81e14f008260d863f76c2a739a171 (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
154
//
//  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 "ChromaKeyFXNode.h"

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

#include <string>

using namespace std;

namespace avg {

ChromaKeyFXNode::ChromaKeyFXNode() 
    : FXNode(false),
      m_sColorName("00FF00"),
      m_Color(0, 255, 0),
      m_HTolerance(0.0),
      m_STolerance(0.0),
      m_LTolerance(0.0),
      m_Softness(0.0),
      m_Erosion(0),
      m_SpillThreshold(0.0)
{
    ObjectCounter::get()->incRef(&typeid(*this));
}

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

void ChromaKeyFXNode::disconnect()
{
    m_pFilter = GPUChromaKeyFilterPtr();
    FXNode::disconnect();
}
    

void ChromaKeyFXNode::setColor(const std::string& sColorName)
{
    m_sColorName = sColorName;
    m_Color = colorStringToColor(m_sColorName);
    updateFilter();
}

const std::string& ChromaKeyFXNode::getColor() const
{
    return m_sColorName;
}

void ChromaKeyFXNode::setHTolerance(float tolerance)
{
    m_HTolerance = tolerance;
    updateFilter();
}

float ChromaKeyFXNode::getHTolerance() const
{
    return m_HTolerance;
}

void ChromaKeyFXNode::setSTolerance(float tolerance)
{
    m_STolerance = tolerance;
    updateFilter();
}

float ChromaKeyFXNode::getSTolerance() const
{
    return m_STolerance;
}

void ChromaKeyFXNode::setLTolerance(float tolerance)
{
    m_LTolerance = tolerance;
    updateFilter();
}

float ChromaKeyFXNode::getLTolerance() const
{
    return m_LTolerance;
}

void ChromaKeyFXNode::setSoftness(float softness)
{
    m_Softness = softness;
    updateFilter();
}

float ChromaKeyFXNode::getSoftness() const
{
    return m_Softness;
}

void ChromaKeyFXNode::setErosion(int erosion)
{
    m_Erosion = erosion;
    updateFilter();
}

int ChromaKeyFXNode::getErosion() const
{
    return m_Erosion;
}

void ChromaKeyFXNode::setSpillThreshold(float spillThreshold)
{
    m_SpillThreshold = spillThreshold;
    updateFilter();
}

float ChromaKeyFXNode::getSpillThreshold() const
{
    return m_SpillThreshold;
}

GPUFilterPtr ChromaKeyFXNode::createFilter(const IntPoint& size)
{
    m_pFilter = GPUChromaKeyFilterPtr(new GPUChromaKeyFilter(size, false));
    m_pFilter->setParams(m_Color, m_HTolerance, m_STolerance, m_LTolerance, m_Softness,
            m_Erosion, m_SpillThreshold);
    setDirty();
    return m_pFilter;
}

void ChromaKeyFXNode::updateFilter()
{
    if (m_pFilter) {
        m_pFilter->setParams(m_Color, m_HTolerance, m_STolerance, m_LTolerance, 
                m_Softness, m_Erosion, m_SpillThreshold);
        setDirty();
    }
}

}