@@ -97,57 +97,96 @@ fn test_new_encoder() {
97
97
Err ( Error :: InvalidImageLength { size: 12 , width: 3 , height: 3 } )
98
98
) ) ;
99
99
100
- assert ! ( matches!( qoi:: Encoder :: new( & arr3, 1 , 1 ) , Err ( Error :: InvalidChannels { channels: 12 } ) ) ) ;
100
+ assert ! ( matches!(
101
+ qoi:: Encoder :: new( & arr3, 1 , 1 ) ,
102
+ Err ( Error :: InvalidImageLength { size: 12 , width: 1 , height: 1 } )
103
+ ) ) ;
101
104
102
- let enc = qoi:: Encoder :: new_raw ( & arr3, 2 , 2 , 2 * 3 , RawChannels :: Bgr ) . unwrap ( ) ;
105
+ let enc = qoi:: EncoderBuilder :: new ( & arr3, 2 , 2 )
106
+ . stride ( 2 * 3 )
107
+ . raw_channels ( RawChannels :: Bgr )
108
+ . build ( )
109
+ . unwrap ( ) ;
103
110
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
104
111
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
105
112
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
106
113
assert_eq ! ( res, [ 2 , 1 , 0 , 5 , 4 , 3 , 8 , 7 , 6 , 11 , 10 , 9 ] ) ;
107
114
108
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Rgba ) . unwrap ( ) ;
115
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
116
+ . stride ( 2 * 4 )
117
+ . raw_channels ( RawChannels :: Rgba )
118
+ . build ( )
119
+ . unwrap ( ) ;
109
120
assert_eq ! ( enc. channels( ) , Channels :: Rgba ) ;
110
121
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
111
122
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
112
123
assert_eq ! ( res, arr4) ;
113
124
114
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Bgra ) . unwrap ( ) ;
125
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
126
+ . stride ( 2 * 4 )
127
+ . raw_channels ( RawChannels :: Bgra )
128
+ . build ( )
129
+ . unwrap ( ) ;
115
130
assert_eq ! ( enc. channels( ) , Channels :: Rgba ) ;
116
131
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
117
132
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
118
133
assert_eq ! ( res, [ 2 , 1 , 0 , 3 , 6 , 5 , 4 , 7 , 10 , 9 , 8 , 11 , 14 , 13 , 12 , 15 ] ) ;
119
134
120
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Rgbx ) . unwrap ( ) ;
135
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
136
+ . stride ( 2 * 4 )
137
+ . raw_channels ( RawChannels :: Rgbx )
138
+ . build ( )
139
+ . unwrap ( ) ;
121
140
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
122
141
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
123
142
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
124
143
assert_eq ! ( res, [ 0 , 1 , 2 , 4 , 5 , 6 , 8 , 9 , 10 , 12 , 13 , 14 ] ) ;
125
144
126
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Xrgb ) . unwrap ( ) ;
145
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
146
+ . stride ( 2 * 4 )
147
+ . raw_channels ( RawChannels :: Xrgb )
148
+ . build ( )
149
+ . unwrap ( ) ;
127
150
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
128
151
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
129
152
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
130
153
assert_eq ! ( res, [ 1 , 2 , 3 , 5 , 6 , 7 , 9 , 10 , 11 , 13 , 14 , 15 ] ) ;
131
154
132
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Bgra ) . unwrap ( ) ;
155
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
156
+ . stride ( 2 * 4 )
157
+ . raw_channels ( RawChannels :: Bgra )
158
+ . build ( )
159
+ . unwrap ( ) ;
133
160
assert_eq ! ( enc. channels( ) , Channels :: Rgba ) ;
134
161
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
135
162
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
136
163
assert_eq ! ( res, [ 2 , 1 , 0 , 3 , 6 , 5 , 4 , 7 , 10 , 9 , 8 , 11 , 14 , 13 , 12 , 15 ] ) ;
137
164
138
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Abgr ) . unwrap ( ) ;
165
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
166
+ . stride ( 2 * 4 )
167
+ . raw_channels ( RawChannels :: Abgr )
168
+ . build ( )
169
+ . unwrap ( ) ;
139
170
assert_eq ! ( enc. channels( ) , Channels :: Rgba ) ;
140
171
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
141
172
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
142
173
assert_eq ! ( res, [ 3 , 2 , 1 , 0 , 7 , 6 , 5 , 4 , 11 , 10 , 9 , 8 , 15 , 14 , 13 , 12 ] ) ;
143
174
144
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Bgrx ) . unwrap ( ) ;
175
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
176
+ . stride ( 2 * 4 )
177
+ . raw_channels ( RawChannels :: Bgrx )
178
+ . build ( )
179
+ . unwrap ( ) ;
145
180
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
146
181
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
147
182
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
148
183
assert_eq ! ( res, [ 2 , 1 , 0 , 6 , 5 , 4 , 10 , 9 , 8 , 14 , 13 , 12 ] ) ;
149
184
150
- let enc = qoi:: Encoder :: new_raw ( & arr4, 2 , 2 , 2 * 4 , RawChannels :: Xbgr ) . unwrap ( ) ;
185
+ let enc = qoi:: EncoderBuilder :: new ( & arr4, 2 , 2 )
186
+ . stride ( 2 * 4 )
187
+ . raw_channels ( RawChannels :: Xbgr )
188
+ . build ( )
189
+ . unwrap ( ) ;
151
190
assert_eq ! ( enc. channels( ) , Channels :: Rgb ) ;
152
191
let qoi = enc. encode_to_vec ( ) . unwrap ( ) ;
153
192
let ( _header, res) = decode_to_vec ( qoi) . unwrap ( ) ;
0 commit comments