1 module rip.dsp.transforms.haar;
2 
3 private
4 {
5 	import std.math;
6 
7 	import rip.processing.filters.linear;
8 
9 	static float SQ2 = cast(float) SQRT2;
10 }
11 
12 
13 class Haar2 : LinearFilter
14 {
15 	this()
16 	{
17 		apertureWidth = 2;
18 		apertureHeight = 2;
19 		apertureDivider =  1.0 / SQ2;
20 		apertureOffset = 0.0f;
21 		flattenKernel = flatten(
22 			[
23 				[ 1.0f,   1.0f ],
24 				[ 1.0f,  -1.0f ],
25 			]
26 			);
27 	}
28 }
29 
30 
31 class Haar4 : LinearFilter
32 {
33 	this()
34 	{
35 		apertureWidth = 4;
36 		apertureHeight = 4;
37 		apertureDivider =  0.5f;
38 		apertureOffset = 0.0f;
39 		flattenKernel = flatten(
40 			[
41 				[ 1.0f,   1.0f,    1.0f,  1.0f ],
42 				[ 1.0f,   1.0f,   -1.0f  -1.0f ],
43 				[ SQ2,   -SQ2,     0.0f,  0.0f ],
44 				[ 0.0f,   0.0f,    SQ2,   -SQ2 ],
45 			]
46 			);
47 	}
48 }
49 
50 
51 class Haar8 : LinearFilter
52 {
53 	this()
54 	{
55 		apertureWidth = 8;
56 		apertureHeight = 8;
57 		apertureDivider = 1.0f / sqrt(8.0f);
58 		apertureOffset = 0.0f;
59 		flattenKernel = flatten(
60 			[
61 				[ 1.0f,   1.0f,   1.0f,   1.0f,   1.0f,   1.0f,   1.0f,   1.0f ],
62 				[ 1.0f,   1.0f,   1.0f,   1.0f,  -1.0f,  -1.0f,  -1.0f,  -1.0f ],
63 				[ SQ2,    SQ2,   -SQ2,   -SQ2,    0.0f,   0.0f,   0.0f,   0.0f ],
64 				[ 0.0f,   0.0f,   0.0f,   0.0f,   SQ2,    SQ2,   -SQ2,   -SQ2  ],
65 				[ 2.0f,  -2.0f,   0.0f,   0.0f,   0.0f,   0.0f,   0.0f,   0.0f ],
66 				[ 0.0f,   0.0f,   2.0f,  -2.0f,   0.0f,   0.0f,   0.0f,   0.0f ],
67 				[ 0.0f,   0.0f,   0.0f,   0.0f,   2.0f,  -2.0f,   0.0f,   0.0f ],
68 				[ 0.0f,   0.0f ,  0.0f,   0.0f,   0.0f,   0.0f,   2.0f,  -2.0f ],
69 			]
70 			);
71 	}
72 }