1 #ifndef STDDOMAINS_HEADER_
2 #define STDDOMAINS_HEADER_
4 #include "../headers.h"
7 /** Standard domain-pool generator. Available settings:
8 * - the decrease of max. number of domains per level
9 * - how many of more-downscaled domains to use
10 * - how big portions of standard, horizontal, vertical and diamond domains to use
12 class MStdDomains
: public ISquareDomains
{
15 DECLARE_TypeInfo( MStdDomains
, "Standard domains generator"
16 , "Creates domain blocks of many types (standard, horizontal, vertical, diamond)"
18 label
: "Per-level max-domain-count divisor",
19 desc
: "How many times will the maximum domain count\n"
20 "decrease with every level\n"
21 "(dimensions are equal to 2^level)",
22 type
: settingInt(0,0,4,IntLog2
)
24 label
: "More-downscaled domain count",
25 desc
: "The development of count of domains\n"
26 "made from more downscaled images",
27 type
: settingCombo("none\nno decrease\nhalf per scale",0)
29 label
: "Standard domains portion",
30 desc
: "How big portion from all domains\n"
31 "will be of standard type",
32 type
: settingInt(0,1,8)
34 label
: "Diamond domains portion",
35 desc
: "How big portion from all domains\n"
36 "will be of diamond type",
37 type
: settingInt(0,0,8)
39 label
: "Horizontal domains portion",
40 desc
: "How big portion from all domains\n"
41 "will be of horizontal type",
42 type
: settingInt(0,0,8)
44 label
: "Vertical domains portion",
45 desc
: "How big portion from all domains\n"
46 "will be of vertical type",
47 type
: settingInt(0,0,8)
51 /** Indices for settings */
52 enum Settings
{ MaxDomCountLevelDivisor
, MultiDownScaling
53 , DomPortion_Standard
, DomPortion_Diamond
, DomPortion_Horiz
, DomPortion_Vert
};
56 /// The list of domain pools, pool IDs are the indices, the Pool::pixels are owned
58 int width
/// Width of the original image (not zoomed)
59 , height
/// Height of the original image (not zoomed)
62 // Construction and destruction
64 MStdDomains(): width(-1), height(-1), zoom(-1) {}
66 /** Only frees the #pools */
68 for (PoolList::iterator it
=pools
.begin(); it
!=pools
.end(); ++it
)
73 /** \name ISquareDomains interface
75 void initPools(const PlaneBlock
&planeBlock
);
76 void fillPixelsInPools(PlaneBlock
&planeBlock
);
78 const PoolList
& getPools() const
80 std::vector
<short> getLevelDensities(int level
,int stdDomCountLog2
);
82 void writeSettings(std::ostream
&file
);
83 void readSettings(std::istream
&file
);
84 /* We have no data that need to be preserved */
85 void writeData(std::ostream
&) {}
86 void readData(std::istream
&) {}
92 namespace MatrixWalkers
{
93 /** A simple assigning operator - assigns its second argument into the first one */
94 struct ReverseAssigner
: public OperatorBase
{
95 template<class R1
,class R2
> void operator()(R1
&dest
,R2 src
) const { dest
= src
; }
97 /** Matrix iterator performing a 2x2 to 1 shrink */
98 template<class T
,class I
=PtrInt
>
99 struct HalfShrinker
: public Rotation_0
<T
,I
> { ROTBASE_INHERIT
100 typedef Rotation_0
<T
,I
> Base
;
102 HalfShrinker( TMatrix matrix
, I x0
=0, I y0
=0 )
103 : Base(matrix
,x0
,y0
) {}
108 return ldexp( cs
[0] + cs
[1] + cs
[c
.colSkip
] + cs
[c
.colSkip
+1], -2 );
110 void outerStep() { Base::outerStep(); Base::outerStep(); }
111 void innerStep() { Base::innerStep(); Base::innerStep(); }
113 /** Matrix iterator performing a 3x3 to 1x2 shrink */
114 template<class T
,class I
=PtrInt
>
115 struct HorizShrinker
: public Rotation_0
<T
,I
> { ROTBASE_INHERIT
116 typedef Rotation_0
<T
,I
> Base
;
118 bool addHalf
; ///< Adds half a pixel to the current position
120 HorizShrinker(TMatrix matrix
)
121 : Base(matrix
), addHalf(false) {}
124 Real groups
[2]; // groups[0]= sum of a full line, groups[1]= sum of a half line
125 T
*cs
= current
.start
;
126 groups
[addHalf
]= cs
[0] + cs
[current
.colSkip
] + cs
[current
.colSkip
*2];
128 groups
[!addHalf
]= cs
[0] + cs
[current
.colSkip
] + cs
[current
.colSkip
*2];
129 return (ldexp(groups
[0],1)+groups
[1]) * Real(1.0/9.0);
132 // do a 1.5-pixel step
139 for (int i
=0; i
<3; ++i
)
143 /** Matrix iterator performing a 3x3 to 2x1 shrink */
144 template<class T
,class I
=PtrInt
>
145 struct VertShrinker
: public Rotation_0
<T
,I
> { ROTBASE_INHERIT
146 typedef Rotation_0
<T
,I
> Base
;
148 bool addHalf
; ///< Adds half a pixel to the current position
150 VertShrinker(TMatrix matrix
)
151 : Base(matrix
), addHalf(false) {}
154 Real groups
[2]; // groups[0]= sum of a full line, groups[1]= sum of a half line
155 T
*cs
= current
.start
;
156 groups
[addHalf
]= cs
[0] + cs
[1] + cs
[2];
157 cs
+= current
.colSkip
;
158 groups
[!addHalf
]= cs
[0] + cs
[1] + cs
[2];
159 return (ldexp(groups
[0],1)+groups
[1]) * Real(1.0/9.0);
162 for (int i
=0; i
<3; ++i
)
166 // do a 1.5-pixel step
173 /** Matrix iterator performing a shrink of a diamond (rotated sub-square)
174 * into a square, decreasing the area of used pixels to 50% */
175 template<class T
,class I
=PtrInt
>
176 struct DiamShrinker
: public Rotation_0
<T
,I
> { ROTBASE_INHERIT
177 typedef Rotation_0
<T
,I
> Base
;
179 DiamShrinker(TMatrix matrix
,I side
)
180 : Base( matrix
, side
-1, 0 ) {} // the diamond begins on top-middle
185 return ldexp( cs
[0] + cs
[1] + cs
[c
.colSkip
] + cs
[c
.colSkip
+1], -2 );
187 void outerStep() { lastStart
+= current
.colSkip
+1; }
188 void innerStep() { current
.start
+= 1-current
.colSkip
; }
190 }// MatrixWalkers namespace
193 #endif // STDDOMAINS_HEADER_