RAWK
Gigapixel Raw Image Processing Toolkit
 All Classes Functions Variables Pages
image_blend.hpp
1 // RAWK Copyright (C) 2014 Robert Kooima
2 //
3 // This program is free software: you can redistribute it and/or modify it
4 // under the terms of the GNU General Public License as published by the Free
5 // Software Foundation, either version 3 of the License, or (at your option)
6 // any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but WITH-
9 // OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 // more details.
12 
13 #ifndef IMAGE_BLEND_HPP
14 #define IMAGE_BLEND_HPP
15 
16 //------------------------------------------------------------------------------
17 
19 
20 class blend : public image
21 {
22 public:
28 
29  blend(image *L, image *R) : image(L, R) { }
30 
31  virtual double get(int i, int j, int k) const
32  {
33  double a = L->get(i, j, L->get_depth() - 1);
34 
35  if (a == 1.0) return L->get(i, j, k);
36  if (a == 0.0) return R->get(i, j, k);
37 
38  return a * L->get(i, j, k) + (1.0 - a) * R->get(i, j, k);
39  }
40 
41  virtual int get_depth() const
42  {
43  return std::max(L->get_depth() - 1, R->get_depth());
44  }
45 
46  virtual void doc(std::ostream& out) const
47  {
48  out << "blend";
49  }
50 };
51 
52 //------------------------------------------------------------------------------
53 
54 #endif
virtual double get(int i, int j, int k) const =0
Return the value of the sample at row i, column j, channel k.
image * L
Left child.
Definition: image.hpp:117
Base class for all image sources, filters, and operators.
Definition: image.hpp:20
blend(image *L, image *R)
Blend image L with image R using the alpha channel of L. The alpha channel is taken to be the last ch...
Definition: image_blend.hpp:29
Blend operator.
Definition: image_blend.hpp:20
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image_blend.hpp:46
virtual int get_depth() const
Return the depth of this image.
Definition: image.hpp:66
image * R
Right child.
Definition: image.hpp:118
virtual int get_depth() const
Return the depth of this image.
Definition: image_blend.hpp:41