~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2011, Blender Foundation.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * Contributor:
 
19
 *              Dalai Felinto
 
20
 */
 
21
 
 
22
#include "COM_DistanceRGBMatteOperation.h"
 
23
#include "BLI_math.h"
 
24
 
 
25
DistanceRGBMatteOperation::DistanceRGBMatteOperation() : NodeOperation()
 
26
{
 
27
        this->addInputSocket(COM_DT_COLOR);
 
28
        this->addInputSocket(COM_DT_COLOR);
 
29
        this->addOutputSocket(COM_DT_VALUE);
 
30
 
 
31
        this->m_inputImageProgram = NULL;
 
32
        this->m_inputKeyProgram = NULL;
 
33
}
 
34
 
 
35
void DistanceRGBMatteOperation::initExecution()
 
36
{
 
37
        this->m_inputImageProgram = this->getInputSocketReader(0);
 
38
        this->m_inputKeyProgram = this->getInputSocketReader(1);
 
39
}
 
40
 
 
41
void DistanceRGBMatteOperation::deinitExecution()
 
42
{
 
43
        this->m_inputImageProgram = NULL;
 
44
        this->m_inputKeyProgram = NULL;
 
45
}
 
46
 
 
47
float DistanceRGBMatteOperation::calculateDistance(float key[4], float image[4])
 
48
{
 
49
        return len_v3v3(key, image);
 
50
}
 
51
 
 
52
void DistanceRGBMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
 
53
{
 
54
        float inKey[4];
 
55
        float inImage[4];
 
56
 
 
57
        const float tolerance = this->m_settings->t1;
 
58
        const float falloff = this->m_settings->t2;
 
59
 
 
60
        float distance;
 
61
        float alpha;
 
62
 
 
63
        this->m_inputKeyProgram->read(inKey, x, y, sampler);
 
64
        this->m_inputImageProgram->read(inImage, x, y, sampler);
 
65
        
 
66
        distance = this->calculateDistance(inKey, inImage);
 
67
 
 
68
        /* store matte(alpha) value in [0] to go with
 
69
         * COM_SetAlphaOperation and the Value output
 
70
         */
 
71
 
 
72
        /*make 100% transparent */
 
73
        if (distance < tolerance) {
 
74
                output[0] = 0.f;
 
75
        }
 
76
        /*in the falloff region, make partially transparent */
 
77
        else if (distance < falloff + tolerance) {
 
78
                distance = distance - tolerance;
 
79
                alpha = distance / falloff;
 
80
                /*only change if more transparent than before */
 
81
                if (alpha < inImage[3]) {
 
82
                        output[0] = alpha;
 
83
                }
 
84
                else { /* leave as before */
 
85
                        output[0] = inImage[3];
 
86
                }
 
87
        }
 
88
        else {
 
89
                /* leave as before */
 
90
                output[0] = inImage[3];
 
91
        }
 
92
}