RAWK
Gigapixel Raw Image Processing Toolkit
 All Classes Functions Variables Pages
image_output.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_OUTPUT_HPP
14 #define IMAGE_OUTPUT_HPP
15 
16 //------------------------------------------------------------------------------
17 
19 
20 class output : public image
21 {
22 public:
28 
29  output(std::string name, char type, image *L)
30  : image(L), cache(false), file(0), chars(0)
31  {
32  const int height = L->get_height();
33  const int width = L->get_width ();
34  const int depth = L->get_depth ();
35 
36  switch (type)
37  {
38  case 'b': file = new rawb(name, 0, height, width, depth, true); break;
39  case 'c': file = new rawc(name, 0, height, width, depth, true); break;
40  case 'u': file = new rawu(name, 0, height, width, depth, true); break;
41  case 'U': file = new rawU(name, 0, height, width, depth, true); break;
42  case 's': file = new raws(name, 0, height, width, depth, true); break;
43  case 'S': file = new rawS(name, 0, height, width, depth, true); break;
44  case 'l': file = new rawl(name, 0, height, width, depth, true); break;
45  case 'L': file = new rawL(name, 0, height, width, depth, true); break;
46  case 'i': file = new rawi(name, 0, height, width, depth, true); break;
47  case 'I': file = new rawI(name, 0, height, width, depth, true); break;
48  case 'f': file = new rawf(name, 0, height, width, depth, true); break;
49  case 'F': file = new rawF(name, 0, height, width, depth, true); break;
50  case 'd': file = new rawd(name, 0, height, width, depth, true); break;
51  case 'D': file = new rawD(name, 0, height, width, depth, true); break;
52  }
53  }
54 
55  ~output()
56  {
57  delete file;
58  }
59 
60  virtual double get(int i, int j, int k) const
61  {
62  if (0 <= i && i < file->get_height() &&
63  0 <= j && j < file->get_width () &&
64  0 <= k && k < file->get_depth ())
65  {
66  if (cache)
67  return file->get(i, j, k);
68  else
69  return L->get(i, j, k);
70  }
71  return 0.0;
72  }
73 
74  virtual void doc(std::ostream& out) const
75  {
76  out << "output " << file->get_name ()
77  << " " << file->get_height()
78  << " " << file->get_width ()
79  << " " << file->get_depth ();
80  }
81 
87 
88  virtual void process()
89  {
90  int f, g = 8, c = 0;
91  int i, h = get_height();
92  int j, w = get_width ();
93  int k, d = get_depth ();
94 
96 
97  // Divide the set of all scanlines into groups of size g.
98 
99  #pragma omp parallel for private(i, j, k) schedule(dynamic)
100  for (f = 0; f < h; f += g)
101  {
102  // Process each group in parallel.
103 
104  int l = std::min(f + g, h);
105 
106  for (i = f; i < l; ++i)
107  for (j = 0; j < w; ++j)
108  for (k = 0; k < d; ++k)
109  file->put(i, j, k, L->get(i, j, k));
110 
111  // Report a running total of completed scan lines.
112 
113  #pragma omp critical
114  c += g;
115 
116  if (omp_get_thread_num() == 0)
117  report(c, h);
118  }
119 
120  // Finish the report and enable the cache.
121 
122  report(h, h);
123  cache = true;
124  }
125 
126 private:
127  bool cache;
128  raw *file;
129  int chars;
130 
131  void report(int i, int n)
132  {
133  std::ostringstream stream;
134 
135  stream << "Wrote " << i
136  << " of " << n
137  << " to " << file->get_name();
138 
139  if (i < n)
140  std::cout << std::string(chars, '\b') << stream.str() << std::flush;
141  else
142  std::cout << std::string(chars, '\b') << stream.str() << std::endl;
143 
144  chars = stream.str().size();
145  }
146 };
147 
148 //------------------------------------------------------------------------------
149 
150 #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.
virtual void process()
Process all samples of this image, storing them in the file. Then, switch into cached mode...
Definition: image_output.hpp:88
output(std::string name, char type, image *L)
Write a raw-formatted data file named name. Type is a character giving the output sample type...
Definition: image_output.hpp:29
image * L
Left child.
Definition: image.hpp:117
RAW image file.
Definition: raw.hpp:68
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image_output.hpp:74
Signed 32-bit RAW adapter.
Definition: raw.hpp:331
Byte-swapped single precision floating point RAW adapter.
Definition: raw.hpp:463
Single precision floating point RAW adapter.
Definition: raw.hpp:445
Unigned 32-bit RAW adapter.
Definition: raw.hpp:369
Base class for all image sources, filters, and operators.
Definition: image.hpp:20
Unsigned 16-bit RAW adapter.
Definition: raw.hpp:293
Byte-swapped unsigned 16-bit RAW adapter.
Definition: raw.hpp:311
virtual int get_height() const
Return the height of this image.
Definition: image.hpp:46
Unsigned 8-bit RAW adapter.
Definition: raw.hpp:235
Signed 8-bit RAW adapter.
Definition: raw.hpp:217
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
Byte-swapped single precision floating point RAW adapter.
Definition: raw.hpp:425
Single precision floating point RAW adapter.
Definition: raw.hpp:407
Signed 16-bit RAW adapter.
Definition: raw.hpp:255
Byte-swapped signed 16-bit RAW adapter.
Definition: raw.hpp:273
Byte-swapped signed 32-bit RAW adapter.
Definition: raw.hpp:349
Image file writer.
Definition: image_output.hpp:20
Byte-swapped unsigned 32-bit RAW adapter.
Definition: raw.hpp:387
virtual void process()
Process all samples of both children.
Definition: image.hpp:103