@@ -273,38 +273,28 @@ impl QoiHandler {
273273
274274#[ cfg( feature = "qoi" ) ]
275275impl BitmapUpdateHandler for QoiHandler {
276- fn handle < ' a > ( & mut self , mut bitmap : BitmapUpdate , encoder : & ' a mut PduEncoder ) -> Result < UpdateFragmenter < ' a > > {
276+ fn handle < ' a > ( & mut self , bitmap : BitmapUpdate , encoder : & ' a mut PduEncoder ) -> Result < UpdateFragmenter < ' a > > {
277277 use ironrdp_graphics:: image_processing:: PixelFormat :: * ;
278278
279- if usize:: from ( bitmap. width . get ( ) * 4 ) != bitmap. stride {
280- anyhow:: bail!( "unsupported bitmap with stride" ) ;
281- }
282- let mut pixels = bitmap. data . as_mut_slice ( ) ;
283- let n = pixels. len ( ) / 4 ;
284- match bitmap. format {
285- ARgb32 => ( ) ,
286- XRgb32 => {
287- ( 0 ..n) . for_each ( |i| pixels. copy_within ( 4 * i + 1 ..4 * i + 4 , 3 * i) ) ;
288- pixels = & mut pixels[ ..n * 3 ] ;
289- }
290- ABgr32 => todo ! ( ) ,
291- XBgr32 => todo ! ( ) ,
292- BgrA32 => pixels. chunks_exact_mut ( 4 ) . for_each ( |chunk| chunk. reverse ( ) ) ,
293- BgrX32 => {
294- dbg ! ( ) ;
295- ( 0 ..n) . for_each ( |i| {
296- pixels[ 4 * i..4 * i + 3 ] . reverse ( ) ;
297- pixels. copy_within ( 4 * i..4 * i + 3 , 3 * i) ;
298- } ) ;
299- pixels = & mut pixels[ ..n * 3 ] ;
300- }
301- RgbA32 => todo ! ( ) ,
302- RgbX32 => {
303- ( 0 ..n) . for_each ( |i| pixels. copy_within ( 4 * i..4 * i + 3 , 3 * i) ) ;
304- pixels = & mut pixels[ ..n * 3 ] ;
305- }
306- }
307- let data = qoi:: encode_to_vec ( pixels, bitmap. width . get ( ) . into ( ) , bitmap. height . get ( ) . into ( ) ) . unwrap ( ) ;
279+ let channels = match bitmap. format {
280+ ARgb32 => qoi:: RawChannels :: Argb ,
281+ XRgb32 => qoi:: RawChannels :: Xrgb ,
282+ ABgr32 => qoi:: RawChannels :: Abgr ,
283+ XBgr32 => qoi:: RawChannels :: Xbgr ,
284+ BgrA32 => qoi:: RawChannels :: Bgra ,
285+ BgrX32 => qoi:: RawChannels :: Bgrx ,
286+ RgbA32 => qoi:: RawChannels :: Rgba ,
287+ RgbX32 => qoi:: RawChannels :: Rgbx ,
288+ } ;
289+
290+ let enc = qoi:: Encoder :: new_raw (
291+ & bitmap. data ,
292+ bitmap. width . get ( ) . into ( ) ,
293+ bitmap. height . get ( ) . into ( ) ,
294+ bitmap. stride ,
295+ channels,
296+ ) ?;
297+ let data = enc. encode_to_vec ( ) ?;
308298 encoder. set_surface ( bitmap, self . codec_id , data)
309299 }
310300}
0 commit comments