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

« back to all changes in this revision

Viewing changes to source/blender/compositor/operations/COM_LuminanceMatteOperation.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_LuminanceMatteOperation.h"
 
23
#include "BLI_math.h"
 
24
 
 
25
LuminanceMatteOperation::LuminanceMatteOperation() : NodeOperation()
 
26
{
 
27
        addInputSocket(COM_DT_COLOR);
 
28
        addOutputSocket(COM_DT_VALUE);
 
29
 
 
30
        this->m_inputImageProgram = NULL;
 
31
}
 
32
 
 
33
void LuminanceMatteOperation::initExecution()
 
34
{
 
35
        this->m_inputImageProgram = this->getInputSocketReader(0);
 
36
}
 
37
 
 
38
void LuminanceMatteOperation::deinitExecution()
 
39
{
 
40
        this->m_inputImageProgram = NULL;
 
41
}
 
42
 
 
43
void LuminanceMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
 
44
{
 
45
        float inColor[4];
 
46
 
 
47
        const float high = this->m_settings->t1;
 
48
        const float low = this->m_settings->t2;
 
49
 
 
50
        float alpha;
 
51
 
 
52
        this->m_inputImageProgram->read(inColor, x, y, sampler);
 
53
        
 
54
        /* one line thread-friend algorithm:
 
55
         * output[0] = max(inputValue[3], min(high, max(low, ((inColor[0]-low)/(high-low))))
 
56
         */
 
57
                
 
58
        /* test range */
 
59
        if (inColor[0] > high) {
 
60
                alpha = 1.f;
 
61
        }
 
62
        else if (inColor[0] < low) {
 
63
                alpha = 0.f;
 
64
        }
 
65
        else { /*blend */
 
66
                alpha = (inColor[0] - low) / (high - low);
 
67
        }
 
68
 
 
69
 
 
70
        /* store matte(alpha) value in [0] to go with
 
71
         * COM_SetAlphaOperation and the Value output
 
72
         */
 
73
 
 
74
        /* don't make something that was more transparent less transparent */
 
75
        if (alpha < inColor[3]) {
 
76
                output[0] = alpha;
 
77
        }
 
78
        else {
 
79
                /* leave now it was before */
 
80
                output[0] = inColor[3];
 
81
        }
 
82
}
 
83