Beatmup
processing.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "../exception.h"
21 #include "abstract_bitmap.h"
22 #include "bitmap_access.h"
23 #include "mask_bitmap_access.h"
24 
25 namespace Beatmup {
26  /**
27  Contains templates calling elementary image processing routines depending on pixel formats of their arguments.
28  An elementary routine is a class template having a public function process() performing a specific processing action.
29  The template arguments of this class are readers of / writers to bitmaps specialized for given pixel formats.
30  */
31  namespace BitmapProcessing {
32  /**
33  Exception thrown in a situation when a processing action is not implemented for pixel formats of specific arguments.
34  */
36  public:
38  Exception("Processing action is not implemented for given pixel format: '%s'", AbstractBitmap::PIXEL_FORMAT_NAMES[fmt])
39  {}
40  };
41 
42 
43  /**
44  Calls a Func< ReaderClass >::process(access, params), where
45  - access is an instance of a proper ReaderClass to read `bitmap` starting from pixel (x0, y0),
46  - params are additional arguments.
47  */
48  template<template<class> class Func, class Bitmap, typename... Args>
49  inline void read(Bitmap& bitmap, Args&&... args) {
50  switch (bitmap.getPixelFormat()) {
51  case SingleByte:
52  Func<SingleByteBitmapReader>::process(bitmap, args...);
53  break;
54  case TripleByte:
55  Func<TripleByteBitmapReader>::process(bitmap, args...);
56  break;
57  case QuadByte:
58  Func<QuadByteBitmapReader>::process(bitmap, args...);
59  break;
60  case SingleFloat:
61  Func<SingleFloatBitmapReader>::process(bitmap, args...);
62  break;
63  case TripleFloat:
64  Func<TripleFloatBitmapReader>::process(bitmap, args...);
65  break;
66  case QuadFloat:
67  Func<QuadFloatBitmapReader>::process(bitmap, args...);
68  break;
69  case BinaryMask:
70  Func<BinaryMaskReader>::process(bitmap, args...);
71  break;
72  case QuaternaryMask:
73  Func<QuaternaryMaskReader>::process(bitmap, args...);
74  break;
75  case HexMask:
76  Func<HexMaskReader>::process(bitmap, args...);
77  break;
78  default:
80  }
81  }
82 
83 
84  /**
85  Calls a Func< WriterClass >::process(access, params) that writes to a bitmap of any kind, where
86  - access is an instance of a proper WriterClass to write to `bitmap` starting from pixel (x0, y0),
87  - params are additional arguments.
88  */
89  template<template<class> class Func, class Bitmap, typename... Args>
90  inline void write(Bitmap& bitmap, Args&&... args) {
91  switch (bitmap.getPixelFormat()) {
92  case SingleByte:
93  Func<SingleByteBitmapWriter>::process(bitmap, args...);
94  break;
95  case TripleByte:
96  Func<TripleByteBitmapWriter>::process(bitmap, args...);
97  break;
98  case QuadByte:
99  Func<QuadByteBitmapWriter>::process(bitmap, args...);
100  break;
101  case SingleFloat:
102  Func<SingleFloatBitmapWriter>::process(bitmap, args...);
103  break;
104  case TripleFloat:
105  Func<TripleFloatBitmapWriter>::process(bitmap, args...);
106  break;
107  case QuadFloat:
108  Func<QuadFloatBitmapWriter>::process(bitmap, args...);
109  break;
110  case BinaryMask:
111  Func<BinaryMaskWriter>::process(bitmap, args...);
112  break;
113  case QuaternaryMask:
114  Func<QuaternaryMaskWriter>::process(bitmap, args...);
115  break;
116  case HexMask:
117  Func<HexMaskWriter>::process(bitmap, args...);
118  break;
119  default:
121  }
122  }
123 
124 
125  /**
126  Calls a Func< WriterClass >::process(access, params) that writes to a mask bitmap where
127  - access is an instance of a proper WriterClass to write to `mask` starting from pixel (x0, y0),
128  - params are additional arguments.
129  */
130  template<template<class> class Func, class Bitmap, typename... Args>
131  inline void writeToMask(Bitmap& bitmap, Args&&... args) {
132  switch (bitmap.getPixelFormat()) {
133  case BinaryMask:
134  Func<BinaryMaskWriter>::process(bitmap, args...);
135  break;
136  case QuaternaryMask:
137  Func<QuaternaryMaskWriter>::process(bitmap, args...);
138  break;
139  case HexMask:
140  Func<HexMaskWriter>::process(bitmap, args...);
141  break;
142  case SingleByte:
143  Func<SingleByteMaskWriter>::process(bitmap, args...);
144  break;
145  default:
147  }
148  }
149 
150 
151  template<template<class, class> class Func, class InputBitmap, class OutputBitmap, typename... Args>
152  inline void pipeline(InputBitmap& in, OutputBitmap& out, Args&&... args) {
153 
154 #define WRITING(IN_R) \
155  switch (out.getPixelFormat()) { \
156  case SingleByte: \
157  Func<IN_R, SingleByteBitmapWriter>::process(in, out, args...); \
158  break; \
159  case TripleByte: \
160  Func<IN_R, TripleByteBitmapWriter>::process(in, out, args...); \
161  break; \
162  case QuadByte: \
163  Func<IN_R, QuadByteBitmapWriter>::process(in, out, args...); \
164  break; \
165  case SingleFloat: \
166  Func<IN_R, SingleFloatBitmapWriter>::process(in, out, args...); \
167  break; \
168  case TripleFloat: \
169  Func<IN_R, TripleFloatBitmapWriter>::process(in, out, args...); \
170  break; \
171  case QuadFloat: \
172  Func<IN_R, QuadFloatBitmapWriter>::process(in, out, args...); \
173  break; \
174  case BinaryMask: \
175  Func<IN_R, BinaryMaskWriter>::process(in, out, args...); \
176  break; \
177  case QuaternaryMask: \
178  Func<IN_R, QuaternaryMaskWriter>::process(in, out, args...); \
179  break; \
180  case HexMask: \
181  Func<IN_R, HexMaskWriter>::process(in, out, args...); \
182  break; \
183  default: throw ProcessingActionNotImplemented(out.getPixelFormat()); \
184  }
185 
186  switch (in.getPixelFormat()) {
187  case SingleByte:
189  break;
190  case TripleByte:
192  break;
193  case QuadByte:
195  break;
196  case SingleFloat:
198  break;
199  case TripleFloat:
201  break;
202  case QuadFloat:
204  break;
205  case BinaryMask:
207  break;
208  case QuaternaryMask:
210  break;
211  case HexMask:
213  break;
214  default:
215  throw ProcessingActionNotImplemented(in.getPixelFormat());
216  }
217 #undef WRITING
218  }
219 
220 
221  template<template<class, class> class Func, class InputBitmap, class OutputBitmap, typename... Args>
222  inline void pipelineWithMaskOutput(InputBitmap& in, OutputBitmap& out, Args&&... args) {
223 
224 #define WRITING(IN_R) \
225  switch (out.getPixelFormat()) { \
226  case BinaryMask: \
227  Func<IN_R, BinaryMaskWriter>::process(in, out, args...); \
228  break; \
229  case QuaternaryMask: \
230  Func<IN_R, QuaternaryMaskWriter>::process(in, out, args...); \
231  break; \
232  case HexMask: \
233  Func<IN_R, HexMaskWriter>::process(in, out, args...); \
234  break; \
235  case SingleByte: \
236  Func<IN_R, SingleByteMaskWriter>::process(in, out, args...); \
237  break; \
238  default: throw ProcessingActionNotImplemented(out.getPixelFormat()); \
239  }
240 
241  switch (in.getPixelFormat()) {
242  case SingleByte:
244  break;
245  case TripleByte:
247  break;
248  case QuadByte:
250  break;
251  case SingleFloat:
253  break;
254  case TripleFloat:
256  break;
257  case QuadFloat:
259  break;
260  case BinaryMask:
262  break;
263  case QuaternaryMask:
265  break;
266  case HexMask:
268  break;
269  default:
270  throw ProcessingActionNotImplemented(in.getPixelFormat());
271  }
272 #undef WRITING
273  }
274  }
275 }
#define WRITING(IN_R)
A very basic class for any image.
Exception thrown in a situation when a processing action is not implemented for pixel formats of spec...
Definition: processing.h:35
Base class for all exceptions.
Definition: exception.h:37
const PixelFormat getPixelFormat() const
Pixel format of the bitmap.
A generic to access sub-byte mask bitmap data.
Quad byte bitmap reader.
Quad float bitmap reader.
Single byte bitmap reader.
Single float bitmap reader.
Triple byte bitmap reader.
Triple float bitmap reader.
void pipelineWithMaskOutput(InputBitmap &in, OutputBitmap &out, Args &&... args)
Definition: processing.h:222
void pipeline(InputBitmap &in, OutputBitmap &out, Args &&... args)
Definition: processing.h:152
void writeToMask(Bitmap &bitmap, Args &&... args)
Calls a Func< WriterClass >::process(access, params) that writes to a mask bitmap where.
Definition: processing.h:131
void write(Bitmap &bitmap, Args &&... args)
Calls a Func< WriterClass >::process(access, params) that writes to a bitmap of any kind,...
Definition: processing.h:90
void read(Bitmap &bitmap, Args &&... args)
Calls a Func< ReaderClass >::process(access, params), where.
Definition: processing.h:49
@ SingleByte
single channel of 8 bits per pixel (like grayscale), unsigned integer values
@ SingleFloat
single channel of 32 bits per pixel (like grayscale), single precision floating point values
@ QuaternaryMask
2 bits per pixel
@ QuadFloat
4 channels of 32 bits per pixel, single precision floating point values,
@ TripleFloat
3 channels of 32 bits per pixel, single precision floating point values
@ QuadByte
4 channels of 8 bits per pixel (like RGBA), unsigned integer values
@ TripleByte
3 channels of 8 bits per pixel (like RGB), unsigned integer values
@ BinaryMask
1 bit per pixel
@ HexMask
4 bits per pixel
JNIEnv jlong jint out
Beatmup::InternalBitmap * bitmap