@@ -45,57 +45,96 @@ fn test_new_encoder() {
45
45
Err ( Error :: InvalidImageLength { size: 12 , width: 3 , height: 3 } )
46
46
) ) ;
47
47
48
- assert ! ( matches!( qoi:: Encoder :: new( & arr3, 1 , 1 ) , Err ( Error :: InvalidChannels { channels: 12 } ) ) ) ;
48
+ assert ! ( matches!(
49
+ qoi:: Encoder :: new( & arr3, 1 , 1 ) ,
50
+ Err ( Error :: InvalidImageLength { size: 12 , width: 1 , height: 1 } )
51
+ ) ) ;
49
52
50
- let enc = qoi:: Encoder :: new_raw ( & arr3, 2 , 2 , 2 * 3 , RawChannels :: Bgr ) . unwrap ( ) ;
53
+ let enc = qoi:: EncoderBuilder :: new ( & arr3, 2 , 2 )
54
+ . stride ( 2 * 3 )
55
+ . raw_channels ( RawChannels :: Bgr )
56
+ . build ( )
57
+ . unwrap ( ) ;
51
58
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
52
59
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
53
60
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
54
61
assert_eq ! ( res, [ 2 , 1 , 0 , 5 , 4 , 3 , 8 , 7 , 6 , 11 , 10 , 9 ] ) ;
55
62
56
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Rgba ) . unwrap ( ) ;
63
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
64
+ . stride ( 2 * 4 )
65
+ . raw_channels ( RawChannels :: Rgba )
66
+ . build ( )
67
+ . unwrap ( ) ;
57
68
assert_eq ! ( enc. channels( ) , Channels :: Rgba ) ;
58
69
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
59
70
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
60
71
assert_eq ! ( res, arr4) ;
61
72
62
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Bgra ) . unwrap ( ) ;
73
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
74
+ . stride ( 2 * 4 )
75
+ . raw_channels ( RawChannels :: Bgra )
76
+ . build ( )
77
+ . unwrap ( ) ;
63
78
assert_eq ! ( enc. channels( ) , Channels :: Rgba ) ;
64
79
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
65
80
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
66
81
assert_eq ! ( res, [ 2 , 1 , 0 , 3 , 6 , 5 , 4 , 7 , 10 , 9 , 8 , 11 , 14 , 13 , 12 , 15 ] ) ;
67
82
68
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Rgbx ) . unwrap ( ) ;
83
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
84
+ . stride ( 2 * 4 )
85
+ . raw_channels ( RawChannels :: Rgbx )
86
+ . build ( )
87
+ . unwrap ( ) ;
69
88
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
70
89
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
71
90
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
72
91
assert_eq ! ( res, [ 0 , 1 , 2 , 4 , 5 , 6 , 8 , 9 , 10 , 12 , 13 , 14 ] ) ;
73
92
74
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Xrgb ) . unwrap ( ) ;
93
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
94
+ . stride ( 2 * 4 )
95
+ . raw_channels ( RawChannels :: Xrgb )
96
+ . build ( )
97
+ . unwrap ( ) ;
75
98
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
76
99
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
77
100
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
78
101
assert_eq ! ( res, [ 1 , 2 , 3 , 5 , 6 , 7 , 9 , 10 , 11 , 13 , 14 , 15 ] ) ;
79
102
80
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Bgra ) . unwrap ( ) ;
103
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
104
+ . stride ( 2 * 4 )
105
+ . raw_channels ( RawChannels :: Bgra )
106
+ . build ( )
107
+ . unwrap ( ) ;
81
108
assert_eq ! ( enc. channels( ) , Channels :: Rgba ) ;
82
109
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
83
110
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
84
111
assert_eq ! ( res, [ 2 , 1 , 0 , 3 , 6 , 5 , 4 , 7 , 10 , 9 , 8 , 11 , 14 , 13 , 12 , 15 ] ) ;
85
112
86
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Abgr ) . unwrap ( ) ;
113
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
114
+ . stride ( 2 * 4 )
115
+ . raw_channels ( RawChannels :: Abgr )
116
+ . build ( )
117
+ . unwrap ( ) ;
87
118
assert_eq ! ( enc. channels( ) , Channels :: Rgba ) ;
88
119
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
89
120
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
90
121
assert_eq ! ( res, [ 3 , 2 , 1 , 0 , 7 , 6 , 5 , 4 , 11 , 10 , 9 , 8 , 15 , 14 , 13 , 12 ] ) ;
91
122
92
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Bgrx ) . unwrap ( ) ;
123
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
124
+ . stride ( 2 * 4 )
125
+ . raw_channels ( RawChannels :: Bgrx )
126
+ . build ( )
127
+ . unwrap ( ) ;
93
128
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
94
129
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
95
130
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
96
131
assert_eq ! ( res, [ 2 , 1 , 0 , 6 , 5 , 4 , 10 , 9 , 8 , 14 , 13 , 12 ] ) ;
97
132
98
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Xbgr ) . unwrap ( ) ;
133
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
134
+ . stride ( 2 * 4 )
135
+ . raw_channels ( RawChannels :: Xbgr )
136
+ . build ( )
137
+ . unwrap ( ) ;
99
138
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
100
139
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
101
140
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
0 commit comments