/// Decompress a bitmap which has been encoded by the RLE algorithm
///
/// # Example
/// ```no_run
/// use std::net::{SocketAddr, TcpStream};
/// use rdp::core::client::Connector;
/// use rdp::core::event::RdpEvent;
/// let addr = "127.0.0.1:3389".parse::<SocketAddr>().unwrap();
/// let tcp = TcpStream::connect(&addr).unwrap();
/// let mut connector = Connector::new()
///     .screen(800, 600)
///     .credentials("domain".to_string(), "username".to_string(), "password".to_string());
/// let mut client = connector.connect(tcp).unwrap();
/// client.read(|rdp_event| {
///     match rdp_event {
///         RdpEvent::Bitmap(bitmap) => {
///             let data = if bitmap.is_compress {
///                 bitmap.decompress().unwrap()
///             }
///             else {
///                 bitmap.data
///             };
///         }
///          _ => println!("Unhandled event")
///     }
/// }).unwrap()
/// ```
Decompress a bitmap which has been encoded by the RLE algorithm
Decompress a bitmap which has been encoded by the RLE algorithm
pub fn decompress(self) -> RdpResult<Vec<u8>> {
        // actually only handle 32 bpp
        match self.bpp {
            32 => {
                // 32 bpp is straight forward
                Ok(
                    if self.is_compress {
                        let mut result = vec![0 as u8; self.width as usize * self.height as usize * 4];
                        rle_32_decompress(&self.data, self.width as u32, self.height as u32, &mut result)?;
                        result
                    } else {
                        self.data
                    }
                )
            },
            16 => {
                // 16 bpp is more consumer
                let result_16bpp = if self.is_compress {
                    let mut result = vec![0 as u16; self.width as usize * self.height as usize * 2];
                    rle_16_decompress(&self.data, self.width as usize, self.height as usize, &mut result)?;
                    result
                } else {
                    let mut result = vec![0 as u16; self.width as usize * self.height as usize];
                    for i in 0..self.height {
                        for j in 0..self.width {
                            let src = (((self.height - i - 1) * self.width + j) * 2) as usize;
                            result[(i * self.width + j) as usize] = (self.data[src + 1] as u16) << 8 | self.data[src] as u16;
                        }
                    }
                    result
                };
                Ok(rgb565torgb32(&result_16bpp, self.width as usize, self.height as usize))
            },
            _ => Err(Error::RdpError(RdpError::new(RdpErrorKind::NotImplemented)))
        }
    }
pub fn decompress ( self ) -> RdpResult < Vec < u8 > > { // actually only handle 32 bpp match self . bpp { 32 => { // 32 bpp is straight forward Ok ( if self . is_compress { let mut result = vec ! [ 0 as u8 self width as usize self height as usize 4 ] ; rle_32_decompress ( & self . data , self . width as u32 , self . height as u32 , & mut result ) ? ; result } else { self . data } ) } , 16 => { // 16 bpp is more consumer let result_16bpp = if self . is_compress { let mut result = vec ! [ 0 as u16 self width as usize self height as usize 2 ] ; rle_16_decompress ( & self . data , self . width as usize , self . height as usize , & mut result ) ? ; result } else { let mut result = vec ! [ 0 as u16 self width as usize self height as usize ] ; for i in 0 .. self . height { for j in 0 .. self . width { let src = ( ( ( self . height - i - 1 ) * self . width + j ) * 2 ) as usize ; result [ ( i * self . width + j ) as usize ] = ( self . data [ src + 1 ] as u16 ) << 8 | self . data [ src ] as u16 ; } } result } ; Ok ( rgb565torgb32 ( & result_16bpp , self . width as usize , self . height as usize ) ) } , _ => Err ( Error :: RdpError ( RdpError :: new ( RdpErrorKind :: NotImplemented ) ) ) } }
Decompress a bitmap which has been encoded by the RLE algorithm
Decompress a bitmap which has been encoded by the RLE algorithm
self
example
```no_run
use std::net::{SocketAddr, TcpStream};
use rdp::core::client::Connector;
use rdp::core::event::RdpEvent;
let addr = "127.0.0.1:3389".parse::().unwrap();
let tcp = TcpStream::connect(&addr).unwrap();
let mut connector = Connector::new()
.screen(800, 600)
.credentials("domain".to_string(), "username".to_string(), "password".to_string());
let mut client = connector.connect(tcp).unwrap();
client.read(|rdp_event| {
match rdp_event {
RdpEvent::Bitmap(bitmap) => {
let data = if bitmap.is_compress {
bitmap.decompress().unwrap()
}
else {
bitmap.data
};
}
_ => println!("Unhandled event")
}
}).unwrap()
```
` ` ` no_run use std :: net :: { SocketAddr TcpStream } ; use rdp :: core :: client :: Connector ; use rdp :: core :: event :: RdpEvent ; let addr = " 127 . 0 . 0 . 1 : 3389 " . parse :: () . unwrap () ; let tcp = TcpStream :: connect ( &addr ) . unwrap () ; let mut connector = Connector :: new () . screen ( 800 600 ) . credentials ( " domain " . to_string () " username " . to_string () " password " . to_string () ) ; let mut client = connector . connect ( tcp ) . unwrap () ; client . read ( |rdp_event| { match rdp_event { RdpEvent :: Bitmap ( bitmap ) = > { let data = if bitmap . is_compress { bitmap . decompress () . unwrap () } else { bitmap . data } ; } _ = > println! ( " Unhandled event " ) } } ) . unwrap () ` ` `