aboutsummaryrefslogtreecommitdiff
path: root/libraries/agg/patches/0006-Implement-grain-merge-blending-mode-GIMP.patch
blob: f1e465b4d3a85a57bb2a2b939a3e7fce5a0fd34b (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
From 9422570f4e099a834fc43619f7b2a7eb6b442e25 Mon Sep 17 00:00:00 2001
From: Tom Hughes <tom@compton.nu>
Date: Sun, 19 May 2013 15:31:01 +0100
Subject: [PATCH 06/15] Implement grain-merge blending mode (GIMP)

---
 include/agg_pixfmt_rgba.h | 42 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/include/agg_pixfmt_rgba.h b/include/agg_pixfmt_rgba.h
index 79d10dc..f576ce4 100644
--- a/include/agg_pixfmt_rgba.h
+++ b/include/agg_pixfmt_rgba.h
@@ -1401,9 +1401,46 @@ namespace agg
         }
     };
 
+    //================================================comp_op_rgba_grain_merge
+    template <typename ColorT, typename Order> struct comp_op_rgba_grain_merge
+    {
+        typedef ColorT color_type;
+        typedef Order order_type;
+        typedef typename color_type::value_type value_type;
+        typedef typename color_type::calc_type calc_type;
+        typedef typename color_type::long_type long_type;
+        enum base_scale_e
+        {
+            base_shift = color_type::base_shift,
+            base_mask  = color_type::base_mask
+        };
 
+        // E = I + M - 128
+        static AGG_INLINE void blend_pix(value_type* p,
+                                         unsigned sr, unsigned sg, unsigned sb,
+                                         unsigned sa, unsigned cover)
+        {
 
-
+            if(cover < 255)
+            {
+                sr = (sr * cover + 255) >> 8;
+                sg = (sg * cover + 255) >> 8;
+                sb = (sb * cover + 255) >> 8;
+                sa = (sa * cover + 255) >> 8;
+            }
+            if(sa)
+            {
+                calc_type da = p[Order::A];
+                int dr = sr + p[Order::R] - 128;
+                int dg = sg + p[Order::G] - 128;
+                int db = sb + p[Order::B] - 128;
+                p[Order::R] = (value_type)(dr < 0 ? 0 : (dr > 255 ? 255 : dr));
+                p[Order::G] = (value_type)(dg < 0 ? 0 : (dg > 255 ? 255 : dg));
+                p[Order::B] = (value_type)(db < 0 ? 0 : (db > 255 ? 255 : db));
+                p[Order::A] = (value_type)(sa + da - ((sa * da + base_mask) >> base_shift));
+            }
+        }
+    };
 
     //======================================================comp_op_table_rgba
     template<class ColorT, class Order> struct comp_op_table_rgba
@@ -1451,6 +1488,7 @@ namespace agg
         comp_op_rgba_contrast   <ColorT,Order>::blend_pix,
         comp_op_rgba_invert     <ColorT,Order>::blend_pix,
         comp_op_rgba_invert_rgb <ColorT,Order>::blend_pix,
+        comp_op_rgba_grain_merge<ColorT,Order>::blend_pix,
         0
     };
 
@@ -1486,6 +1524,7 @@ namespace agg
         comp_op_contrast,      //----comp_op_contrast
         comp_op_invert,        //----comp_op_invert
         comp_op_invert_rgb,    //----comp_op_invert_rgb
+        comp_op_grain_merge,   //----comp_op_grain_merge
 
         end_of_comp_op_e
     };
@@ -2908,4 +2947,3 @@ namespace agg
 }
 
 #endif
-
-- 
1.8.1.4