NAP
psblendmodes.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
13 #include <algorithm>
14 
15 namespace nap
16 {
17  namespace math
18  {
28  template <typename T>
29  T darken(T target, T blend);
30 
40  template <typename T>
41  T multiply(T target, T blend);
42 
52  template <typename T>
53  T colorBurn(T target, T blend);
54 
64  template <typename T>
65  T linearBurn(T target, T blend);
66 
76  template <typename T>
77  T lighten(T target, T blend);
78 
88  template <typename T>
89  T screen(T target, T blend);
90 
100  template <typename T>
101  T colorDodge(T target, T blend);
102 
112  template <typename T>
113  T linearDodge(T target, T blend);
114 
124  template <typename T>
125  T overlay(T target, T blend);
126 
136  template <typename T>
137  T softLight(T target, T blend);
138 
148  template <typename T>
149  T hardLight(T target, T blend);
150 
160  template <typename T>
161  T vividLight(T target, T blend);
162 
172  template <typename T>
173  T linearLight(T target, T blend);
174 
184  template <typename T>
185  T pinLight(T target, T blend);
186 
196  template <typename T>
197  T difference(T target, T blend);
198 
208  template <typename T>
209  T exclusion(T target, T blend);
210  }
211 }
212 
213 template <typename T>
214 T nap::math::darken(T target, T blend)
215 {
216  return std::min(target, blend);
217 }
218 
219 template <typename T>
220 T nap::math::multiply(T target, T blend)
221 {
222  return target * blend;
223 }
224 
225 template <typename T>
226 T nap::math::colorBurn(T target, T blend)
227 {
228  return 1 - (1 - target) / blend;
229 }
230 
231 template <typename T>
232 T nap::math::linearBurn(T target, T blend)
233 {
234  return target + blend - 1;
235 }
236 
237 template <typename T>
238 T nap::math::lighten(T target, T blend)
239 {
240  return std::max(target, blend);
241 }
242 
243 template <typename T>
244 T nap::math::screen(T target, T blend)
245 {
246  return 1 - (1 - target) * (1 - blend);
247 }
248 
249 template <typename T>
250 T nap::math::colorDodge(T target, T blend)
251 {
252  return target / (1 - blend);
253 }
254 
255 template <typename T>
256 T nap::math::linearDodge(T target, T blend)
257 {
258  return target + blend;
259 }
260 
261 template <typename T>
262 T nap::math::overlay(T target, T blend)
263 {
264  if (target > 0.5)
265  return (1 - (1 - 2 * (target - 0.5)) * (1 - blend));
266  return ((2 * target) * blend);
267 }
268 
269 template <typename T>
270 T nap::math::softLight(T target, T blend)
271 {
272  if (blend > 0.5)
273  return (1 - (1 - target) * (1 - (blend - 0.5)));
274  return (blend <= 0.5) * (target * (blend + 0.5));
275 }
276 
277 template <typename T>
278 T nap::math::hardLight(T target, T blend)
279 {
280  if (blend > 0.5)
281  return (1 - (1 - target) * (1 - 2 * (blend - 0.5)));
282  return (blend <= 0.5) * (target * (2 * blend));
283 }
284 
285 template <typename T>
286 T nap::math::vividLight(T target, T blend)
287 {
288  if (blend > 0.5)
289  return (1 - (1 - target) / (2 * (blend - 0.5)));
290  return (target / (1 - 2 * blend));
291 }
292 
293 template <typename T>
294 T nap::math::linearLight(T target, T blend)
295 {
296  if (blend > 0.5)
297  return (target + 2 * (blend - 0.5));
298  return (blend <= 0.5) * (target + 2 * blend - 1);
299 }
300 
301 template <typename T>
302 T nap::math::pinLight(T target, T blend)
303 {
304  if (blend > 0.5)
305  return (max(target, 2 * (blend - 0.5)));
306  return (blend <= 0.5) * (min(target, 2 * blend));
307 }
308 
309 template <typename T>
310 T nap::math::difference(T target, T blend)
311 {
312  return target - blend;
313 }
314 
315 template <typename T>
316 T nap::math::exclusion(T target, T blend)
317 {
318  return 0.5 - 2 * (target - 0.5) * (blend - 0.5);
319 }
nap::math::multiply
T multiply(T target, T blend)
Definition: psblendmodes.h:220
nap::math::linearLight
T linearLight(T target, T blend)
Definition: psblendmodes.h:294
nap::math::hardLight
T hardLight(T target, T blend)
Definition: psblendmodes.h:278
nap::math::difference
T difference(T target, T blend)
Definition: psblendmodes.h:310
nap::math::max
T max(T left, T right)
Definition: mathutils.h:337
nap::math::linearBurn
T linearBurn(T target, T blend)
Definition: psblendmodes.h:232
nap::math::vividLight
T vividLight(T target, T blend)
Definition: psblendmodes.h:286
nap::math::min
T min(T left, T right)
Definition: mathutils.h:331
nap::math::lighten
T lighten(T target, T blend)
Definition: psblendmodes.h:238
nap::math::linearDodge
T linearDodge(T target, T blend)
Definition: psblendmodes.h:256
nap::math::screen
T screen(T target, T blend)
Definition: psblendmodes.h:244
nap::math::exclusion
T exclusion(T target, T blend)
Definition: psblendmodes.h:316
nap::math::colorBurn
T colorBurn(T target, T blend)
Definition: psblendmodes.h:226
nap
Definition: templateapp.h:17
nap::math::overlay
T overlay(T target, T blend)
Definition: psblendmodes.h:262
nap::math::pinLight
T pinLight(T target, T blend)
Definition: psblendmodes.h:302
nap::math::colorDodge
T colorDodge(T target, T blend)
Definition: psblendmodes.h:250
nap::math::softLight
T softLight(T target, T blend)
Definition: psblendmodes.h:270
nap::math::darken
T darken(T target, T blend)
Definition: psblendmodes.h:214