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

« back to all changes in this revision

Viewing changes to source/blender/nodes/composite/nodes/node_composite_colorMatte.c

  • 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:
33
33
#include "node_composite_util.h"
34
34
 
35
35
/* ******************* Color Key ********************************************************** */
36
 
static bNodeSocketTemplate cmp_node_color_in[]={
37
 
        {SOCK_RGBA,1,"Image", 1.0f, 1.0f, 1.0f, 1.0f},
38
 
        {SOCK_RGBA,1,"Key Color", 1.0f, 1.0f, 1.0f, 1.0f},
39
 
        {-1,0,""}
40
 
};
41
 
 
42
 
static bNodeSocketTemplate cmp_node_color_out[]={
43
 
        {SOCK_RGBA,0,"Image"},
44
 
        {SOCK_FLOAT,0,"Matte"},
45
 
        {-1,0,""}
46
 
};
47
 
 
48
 
static void do_color_key(bNode *node, float *out, float *in)
49
 
{
50
 
        float h_wrap;
51
 
        NodeChroma *c;
52
 
        c=node->storage;
53
 
 
54
 
 
55
 
        copy_v3_v3(out, in);
56
 
 
57
 
        if (
58
 
        /* do hue last because it needs to wrap, and does some more checks  */
59
 
 
60
 
        /* sat */       (fabsf(in[1]-c->key[1]) < c->t2) &&
61
 
        /* val */       (fabsf(in[2]-c->key[2]) < c->t3) &&
62
 
 
63
 
        /* multiply by 2 because it wraps on both sides of the hue,
64
 
         * otherwise 0.5 would key all hue's */
65
 
 
66
 
        /* hue */       ((h_wrap= 2.0f * fabsf(in[0]-c->key[0])) < c->t1 || (2.0f - h_wrap) < c->t1)
67
 
        ) {
68
 
                out[3]=0.0; /*make transparent*/
69
 
        }
70
 
 
71
 
        else { /*pixel is outside key color */
72
 
                out[3]=in[3]; /* make pixel just as transparent as it was before */
73
 
        }
74
 
}
75
 
 
76
 
static void node_composit_exec_color_matte(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
77
 
{
78
 
        CompBuf *cbuf;
79
 
        CompBuf *colorbuf;
80
 
        NodeChroma *c;
81
 
        
82
 
        if (in[0]->hasinput==0) return;
83
 
        if (in[0]->data==NULL) return;
84
 
        if (out[0]->hasoutput==0 && out[1]->hasoutput==0) return;
85
 
        
86
 
        cbuf= typecheck_compbuf(in[0]->data, CB_RGBA);
87
 
        
88
 
        colorbuf= dupalloc_compbuf(cbuf);
89
 
        
90
 
        c=node->storage;
91
 
        
92
 
        /*convert rgbbuf to hsv*/
93
 
        composit1_pixel_processor(node, colorbuf, cbuf, in[0]->vec, do_rgba_to_hsva, CB_RGBA);
94
 
        
95
 
   /*convert key to hsv*/
96
 
        do_rgba_to_hsva(node, c->key, in[1]->vec);
97
 
        
98
 
 
99
 
        /*per pixel color key*/
100
 
        composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_color_key, CB_RGBA);
101
 
        
102
 
        /*convert back*/
103
 
        composit1_pixel_processor(node, colorbuf, colorbuf, in[0]->vec, do_hsva_to_rgba, CB_RGBA);
104
 
        
105
 
        out[0]->data= colorbuf;
106
 
        if (out[1]->hasoutput)
107
 
                out[1]->data= valbuf_from_rgbabuf(colorbuf, CHAN_A);
108
 
        
109
 
        generate_preview(data, node, colorbuf);
110
 
 
111
 
        if (cbuf!=in[0]->data)
112
 
                free_compbuf(cbuf);
113
 
}
114
 
 
115
 
static void node_composit_init_color_matte(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp))
 
36
static bNodeSocketTemplate cmp_node_color_in[] = {
 
37
        {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f},
 
38
        {SOCK_RGBA, 1, N_("Key Color"), 1.0f, 1.0f, 1.0f, 1.0f},
 
39
        {-1, 0, ""}
 
40
};
 
41
 
 
42
static bNodeSocketTemplate cmp_node_color_out[] = {
 
43
        {SOCK_RGBA, 0, N_("Image")},
 
44
        {SOCK_FLOAT, 0, N_("Matte")},
 
45
        {-1, 0, ""}
 
46
};
 
47
 
 
48
static void node_composit_init_color_matte(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
116
49
{
117
50
        NodeChroma *c= MEM_callocN(sizeof(NodeChroma), "node color");
118
51
        node->storage= c;
132
65
        node_type_size(&ntype, 200, 80, 300);
133
66
        node_type_init(&ntype, node_composit_init_color_matte);
134
67
        node_type_storage(&ntype, "NodeChroma", node_free_standard_storage, node_copy_standard_storage);
135
 
        node_type_exec(&ntype, node_composit_exec_color_matte);
136
68
 
137
69
        nodeRegisterType(ttype, &ntype);
138
70
}