RAWK
Gigapixel Raw Image Processing Toolkit
 All Classes Functions Variables Pages
image_swizzle.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_SWIZZLE_HPP
14 #define IMAGE_SWIZZLE_HPP
15 
16 //------------------------------------------------------------------------------
17 
19 
20 class swizzle : public image
21 {
22 public:
35 
36  swizzle(std::string element, image *L) : image(L), element(element)
37  {
38  for (int i = 0; i < int(element.size()); i++)
39  {
40  char c = element[i];
41  int k = 0;
42 
43  if ('0' <= c && c <= '9') k = c - '0';
44  if ('A' <= c && c <= 'Z') k = c - 'A' + 10;
45 
46  if (0 <= k && k < L->get_depth())
47  index.push_back(k);
48  else
49  throw std::runtime_error("Swizzle index out of range");
50  }
51  }
52 
53  virtual double get(int i, int j, int k) const
54  {
55  return L->get(i, j, index[k]);
56  }
57 
58  virtual int get_depth() const
59  {
60  return index.size();
61  }
62 
63  virtual void doc(std::ostream& out) const
64  {
65  out << "swizzle " << element;
66  }
67 
68 private:
69  std::string element;
70  std::vector<int> index;
71 };
72 
73 //------------------------------------------------------------------------------
74 
75 #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.
swizzle(std::string element, image *L)
Reorder, replicate, or remove channels of L. Element is a string of digits used as channel indices...
Definition: image_swizzle.hpp:36
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_swizzle.hpp:63
virtual int get_depth() const
Return the depth of this image.
Definition: image_swizzle.hpp:58
Base class for all image sources, filters, and operators.
Definition: image.hpp:20
Swizzle filter.
Definition: image_swizzle.hpp:20