RAWK
Gigapixel Raw Image Processing Toolkit
 All Classes Functions Variables Pages
image_arithmetic.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_ARITHMETIC_HPP
14 #define IMAGE_ARITHMETIC_HPP
15 
16 //------------------------------------------------------------------------------
17 
19 
20 class sum : public image
21 {
22 public:
26 
27  sum(image *L, image *R) : image(L, R) { }
28 
29  virtual double get(int i, int j, int k) const
30  {
31  return L->get(i, j, k)
32  + R->get(i, j, k);
33  }
34 
35  virtual void doc(std::ostream& out) const
36  {
37  out << "sum";
38  }
39 };
40 
41 //------------------------------------------------------------------------------
42 
44 
45 class difference : public image
46 {
47 public:
51 
52  difference(image *L, image *R) : image(L, R) { }
53 
54  virtual double get(int i, int j, int k) const
55  {
56  return L->get(i, j, k)
57  - R->get(i, j, k);
58  }
59 
60  virtual void doc(std::ostream& out) const
61  {
62  out << "difference";
63  }
64 };
65 
66 //------------------------------------------------------------------------------
67 
69 
70 class multiply : public image
71 {
72 public:
77 
78  multiply(image *L, image *R) : image(L, R) { }
79 
80  virtual double get(int i, int j, int k) const
81  {
82  if (double v = L->get(i, j, k))
83  return v * R->get(i, j, k);
84  else
85  return 0.0;
86  }
87 
88  virtual void doc(std::ostream& out) const
89  {
90  out << "multiply";
91  }
92 };
93 
94 //------------------------------------------------------------------------------
95 
96 #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.
Difference operator.
Definition: image_arithmetic.hpp:45
image * L
Left child.
Definition: image.hpp:117
Sum operator.
Definition: image_arithmetic.hpp:20
Base class for all image sources, filters, and operators.
Definition: image.hpp:20
multiply(image *L, image *R)
Multiply all samples of image L and image R. This operator is short- circuited and will only evaluate...
Definition: image_arithmetic.hpp:78
sum(image *L, image *R)
Add all samples of image L and image R. The width, height, and depth of the result are the larger of ...
Definition: image_arithmetic.hpp:27
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image_arithmetic.hpp:60
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image_arithmetic.hpp:88
difference(image *L, image *R)
Subtract all samples of image R from image L. The width, height, and depth of the result are the larg...
Definition: image_arithmetic.hpp:52
image * R
Right child.
Definition: image.hpp:118
Multiplication operator.
Definition: image_arithmetic.hpp:70
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image_arithmetic.hpp:35