File: xyswappedmask2d.h

package info (click to toggle)
aoflagger 2.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,232 kB
  • sloc: cpp: 61,805; python: 60; sh: 23; makefile: 8
file content (96 lines) | stat: -rw-r--r-- 2,041 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef XYSWAPPEDMASK2D_H
#define XYSWAPPEDMASK2D_H

#include "mask2d.h"
#include "image2d.h"

/**
 * This class wraps a mask and swappes the x and y axes. It provides only the
 * trivial @ref Mask2D functions, and swappes x and y in there, such that the original
 * width becomes the new height, etc. It is useful to convert an algorithm
 * that works originally only in one direction to work in the other direction
 * without rewriting it. If a template parameter is used, the overhead should
 * be negligable.
 * 
 * Note that this method uses references to the original mask. However, masks
 * are normally wrapped in a smart pointer. The caller should make sure the
 * mask exists as long as the XYSwappedMask2D exists.
 * 
 * @author Andre Offringa
 */
template<typename MaskLike>
class XYSwappedMask2D
{
	public:
		explicit XYSwappedMask2D(MaskLike &mask) : _mask(mask)
		{
		}
		
		XYSwappedMask2D<MaskLike>& operator=(const XYSwappedMask2D<MaskLike>& source)
		{
			_mask = source._mask;
			return *this;
		}
		
		bool Value(unsigned x, unsigned y) const
		{
			return _mask.Value(y, x);
		}
		
		void SetValue(unsigned x, unsigned y, bool newValue)
		{
			_mask.SetValue(y, x, newValue);
		}
		
		void SetHorizontalValues(unsigned x, unsigned y, bool value, unsigned count)
		{
			_mask.SetVerticalValues(y, x, value, count);
		}
		
		unsigned Width() const
		{
			return _mask.Height();
		}
		
		unsigned Height() const
		{
			return _mask.Width();
		}
		
	private:
		MaskLike &_mask;
};

template<typename ImageLike>
class XYSwappedImage2D
{
	public:
		explicit XYSwappedImage2D(ImageLike &image) : _image(image)
		{
		}
		
		inline num_t Value(unsigned x, unsigned y) const
		{
			return _image.Value(y, x);
		}
		
		inline void SetValue(unsigned x, unsigned y, num_t newValue)
		{
			_image.SetValue(y, x, newValue);
		}
		
		inline unsigned Width() const
		{
			return _image.Height();
		}
		
		inline unsigned Height() const
		{
			return _image.Width();
		}
		
	private:
		ImageLike &_image;
};

#endif // XYSWAPPEDMASK2D_H