]> git.sesse.net Git - movit/blob - unsharp_mask_effect.cpp
Don't dither alpha.
[movit] / unsharp_mask_effect.cpp
1 #include <assert.h>
2 #include <vector>
3
4 #include "blur_effect.h"
5 #include "effect_chain.h"
6 #include "mix_effect.h"
7 #include "unsharp_mask_effect.h"
8 #include "util.h"
9
10 using namespace std;
11
12 UnsharpMaskEffect::UnsharpMaskEffect()
13         : blur(new BlurEffect),
14           mix(new MixEffect)
15 {
16         CHECK(mix->set_float("strength_first", 1.0f));
17         CHECK(mix->set_float("strength_second", -0.3f));
18 }
19
20 void UnsharpMaskEffect::rewrite_graph(EffectChain *graph, Node *self)
21 {
22         assert(self->incoming_links.size() == 1);
23         Node *input = self->incoming_links[0];
24
25         Node *blur_node = graph->add_node(blur);
26         Node *mix_node = graph->add_node(mix);
27         graph->replace_receiver(self, mix_node);
28         graph->connect_nodes(input, blur_node);
29         graph->connect_nodes(blur_node, mix_node);
30         graph->replace_sender(self, mix_node);
31
32         self->disabled = true;
33 }
34
35 bool UnsharpMaskEffect::set_float(const string &key, float value) {
36         if (key == "amount") {
37                 bool ok = mix->set_float("strength_first", 1.0f + value);
38                 return ok && mix->set_float("strength_second", -value);
39         }
40         return blur->set_float(key, value);
41 }