RAWK
Gigapixel Raw Image Processing Toolkit
 All Classes Functions Variables Pages
image.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_HPP
14 #define IMAGE_HPP
15 
16 //------------------------------------------------------------------------------
17 
19 
20 class image
21 {
22 public:
25 
26  image(image *L=0, image *R=0) : L(L), R(R), P(0)
27  {
28  if (L) L->setP(this);
29  if (R) R->setP(this);
30  }
31 
33 
34  virtual ~image()
35  {
36  if (R) delete R;
37  if (L) delete L;
38  }
39 
41 
42  virtual double get(int i, int j, int k) const = 0;
43 
45 
46  virtual int get_height() const
47  {
48  if (L && R) return std::max(L->get_height(), R->get_height());
49  else if (L) return L->get_height();
50  else if (R) return L->get_height();
51  else return 0;
52  }
53 
55 
56  virtual int get_width() const
57  {
58  if (L && R) return std::max(L->get_width(), R->get_width());
59  else if (L) return L->get_width();
60  else if (R) return L->get_width();
61  else return 0;
62  }
63 
65 
66  virtual int get_depth() const
67  {
68  if (L && R) return std::max(L->get_depth(), R->get_depth());
69  else if (L) return L->get_depth();
70  else if (R) return L->get_depth();
71  else return 0;
72  }
73 
75 
77  {
78  return L;
79  }
80 
82 
84  {
85  return R;
86  }
87 
89 
91  {
92  return P;
93  }
94 
96 
97  virtual void tweak(int a, int v)
98  {
99  }
100 
102 
103  virtual void process()
104  {
105  if (L) L->process();
106  if (R) R->process();
107  }
108 
110 
111  virtual void doc(std::ostream& out) const
112  {
113  out << "undocumented";
114  }
115 
116 protected:
117  image *L;
118  image *R;
119  image *P;
120 
121 private:
122  void setP(image *p) { P = p; }
123 };
124 
125 //------------------------------------------------------------------------------
126 
127 static inline int mod(int a, int n)
128 {
129  return (a % n < 0) ? (a % n + n) : (a % n);
130 }
131 
132 static inline int wrap(int i, int n, bool w)
133 {
134  if (i < 0) return w ? mod(i, n) : 0;
135  else if (i > n - 1) return w ? mod(i, n) : n - 1;
136  else return i;
137 }
138 
139 //------------------------------------------------------------------------------
140 
141 #endif
virtual void tweak(int a, int v)
Tweak image parameter a, changing the value by a factor of v.
Definition: image.hpp:97
image * L
Left child.
Definition: image.hpp:117
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image.hpp:111
image(image *L=0, image *R=0)
Create a new image object with left child L and right child R. The parents of L and R are set to this...
Definition: image.hpp:26
virtual ~image()
Finalize this image object by deleting any children.
Definition: image.hpp:34
Base class for all image sources, filters, and operators.
Definition: image.hpp:20
image * P
Parent.
Definition: image.hpp:119
virtual int get_height() const
Return the height of this image.
Definition: image.hpp:46
virtual int get_depth() const
Return the depth of this image.
Definition: image.hpp:66
virtual int get_width() const
Return the height of this image.
Definition: image.hpp:56
image * getP()
Return the parent.
Definition: image.hpp:90
image * getR()
Return the right child.
Definition: image.hpp:83
image * getL()
Return the left child.
Definition: image.hpp:76
image * R
Right child.
Definition: image.hpp:118
virtual void process()
Process all samples of both children.
Definition: image.hpp:103