1
1
use ironrdp_pdu:: utils:: SplitTo as _;
2
2
3
3
pub fn encode ( buffer : & mut [ i16 ] , temp_buffer : & mut [ i16 ] ) {
4
- encode_block ( & mut * buffer, temp_buffer, 32 ) ;
5
- encode_block ( & mut buffer[ 3072 ..] , temp_buffer, 16 ) ;
6
- encode_block ( & mut buffer[ 3840 ..] , temp_buffer, 8 ) ;
4
+ encode_block :: < 32 > ( & mut * buffer, temp_buffer) ;
5
+ encode_block :: < 16 > ( & mut buffer[ 3072 ..] , temp_buffer) ;
6
+ encode_block :: < 8 > ( & mut buffer[ 3840 ..] , temp_buffer) ;
7
7
}
8
8
9
- fn encode_block ( buffer : & mut [ i16 ] , temp_buffer : & mut [ i16 ] , subband_width : usize ) {
10
- dwt_vertical ( buffer, temp_buffer, subband_width ) ;
11
- dwt_horizontal ( buffer, temp_buffer, subband_width ) ;
9
+ fn encode_block < const SUBBAND_WIDTH : usize > ( buffer : & mut [ i16 ] , temp_buffer : & mut [ i16 ] ) {
10
+ dwt_vertical :: < SUBBAND_WIDTH > ( buffer, temp_buffer) ;
11
+ dwt_horizontal :: < SUBBAND_WIDTH > ( buffer, temp_buffer) ;
12
12
}
13
13
14
14
// DWT in vertical direction, results in 2 sub-bands in L, H order in tmp buffer dwt.
15
- fn dwt_vertical ( buffer : & [ i16 ] , dwt : & mut [ i16 ] , subband_width : usize ) {
16
- let total_width = subband_width * 2 ;
15
+ fn dwt_vertical < const SUBBAND_WIDTH : usize > ( buffer : & [ i16 ] , dwt : & mut [ i16 ] ) {
16
+ let total_width = SUBBAND_WIDTH * 2 ;
17
17
18
18
for x in 0 ..total_width {
19
- for n in 0 ..subband_width {
19
+ for n in 0 ..SUBBAND_WIDTH {
20
20
let y = n * 2 ;
21
21
let l_index = n * total_width + x;
22
- let h_index = l_index + subband_width * total_width;
22
+ let h_index = l_index + SUBBAND_WIDTH * total_width;
23
23
let src_index = y * total_width + x;
24
24
25
25
dwt[ h_index] = ( ( i32:: from ( buffer[ src_index + total_width] )
26
26
- ( ( i32:: from ( buffer[ src_index] )
27
- + i32:: from ( buffer[ src_index + if n < subband_width - 1 { 2 * total_width } else { 0 } ] ) )
27
+ + i32:: from ( buffer[ src_index + if n < SUBBAND_WIDTH - 1 { 2 * total_width } else { 0 } ] ) )
28
28
>> 1 ) )
29
29
>> 1 ) as i16 ;
30
30
dwt[ l_index] = ( i32:: from ( buffer[ src_index] )
@@ -41,24 +41,24 @@ fn dwt_vertical(buffer: &[i16], dwt: &mut [i16], subband_width: usize) {
41
41
// LL(3) order, stored in original buffer.
42
42
// The lower part L generates LL(3) and HL(0).
43
43
// The higher part H generates LH(1) and HH(2).
44
- fn dwt_horizontal ( mut buffer : & mut [ i16 ] , dwt : & [ i16 ] , subband_width : usize ) {
45
- let total_width = subband_width * 2 ;
46
- let squared_subband_width = subband_width . pow ( 2 ) ;
44
+ fn dwt_horizontal < const SUBBAND_WIDTH : usize > ( mut buffer : & mut [ i16 ] , dwt : & [ i16 ] ) {
45
+ let total_width = SUBBAND_WIDTH * 2 ;
46
+ let squared_subband_width = SUBBAND_WIDTH . pow ( 2 ) ;
47
47
48
48
let mut hl = buffer. split_to ( squared_subband_width) ;
49
49
let mut lh = buffer. split_to ( squared_subband_width) ;
50
50
let mut hh = buffer. split_to ( squared_subband_width) ;
51
51
let mut ll = buffer;
52
52
let ( mut l_src, mut h_src) = dwt. split_at ( squared_subband_width * 2 ) ;
53
53
54
- for _ in 0 ..subband_width {
54
+ for _ in 0 ..SUBBAND_WIDTH {
55
55
// L
56
- for n in 0 ..subband_width {
56
+ for n in 0 ..SUBBAND_WIDTH {
57
57
let x = n * 2 ;
58
58
59
59
// HL
60
60
hl[ n] = ( ( i32:: from ( l_src[ x + 1 ] )
61
- - ( ( i32:: from ( l_src[ x] ) + i32:: from ( l_src[ if n < subband_width - 1 { x + 2 } else { x } ] ) ) >> 1 ) )
61
+ - ( ( i32:: from ( l_src[ x] ) + i32:: from ( l_src[ if n < SUBBAND_WIDTH - 1 { x + 2 } else { x } ] ) ) >> 1 ) )
62
62
>> 1 ) as i16 ;
63
63
// LL
64
64
ll[ n] = ( i32:: from ( l_src[ x] )
@@ -70,12 +70,12 @@ fn dwt_horizontal(mut buffer: &mut [i16], dwt: &[i16], subband_width: usize) {
70
70
}
71
71
72
72
// H
73
- for n in 0 ..subband_width {
73
+ for n in 0 ..SUBBAND_WIDTH {
74
74
let x = n * 2 ;
75
75
76
76
// HH
77
77
hh[ n] = ( ( i32:: from ( h_src[ x + 1 ] )
78
- - ( ( i32:: from ( h_src[ x] ) + i32:: from ( h_src[ if n < subband_width - 1 { x + 2 } else { x } ] ) ) >> 1 ) )
78
+ - ( ( i32:: from ( h_src[ x] ) + i32:: from ( h_src[ if n < SUBBAND_WIDTH - 1 { x + 2 } else { x } ] ) ) >> 1 ) )
79
79
>> 1 ) as i16 ;
80
80
// LH
81
81
lh[ n] = ( i32:: from ( h_src[ x] )
@@ -86,10 +86,10 @@ fn dwt_horizontal(mut buffer: &mut [i16], dwt: &[i16], subband_width: usize) {
86
86
} ) as i16 ;
87
87
}
88
88
89
- hl = & mut hl[ subband_width ..] ;
90
- lh = & mut lh[ subband_width ..] ;
91
- hh = & mut hh[ subband_width ..] ;
92
- ll = & mut ll[ subband_width ..] ;
89
+ hl = & mut hl[ SUBBAND_WIDTH ..] ;
90
+ lh = & mut lh[ SUBBAND_WIDTH ..] ;
91
+ hh = & mut hh[ SUBBAND_WIDTH ..] ;
92
+ ll = & mut ll[ SUBBAND_WIDTH ..] ;
93
93
94
94
l_src = & l_src[ total_width..] ;
95
95
h_src = & h_src[ total_width..] ;
0 commit comments