feat: add framebuffer_bytes method (#61)
* feat: add `framebuffer_bytes` method
This commit is contained in:
@@ -9,7 +9,7 @@ homepage = "https://github.com/cocool97/adb_client"
|
||||
keywords = ["adb", "android", "tcp", "usb"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/cocool97/adb_client"
|
||||
version = "2.0.4"
|
||||
version = "2.0.5"
|
||||
|
||||
# To build locally when working on a new release
|
||||
[patch.crates-io]
|
||||
|
||||
@@ -10,7 +10,7 @@ repository.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
adb_client = { version = "2.0.1" }
|
||||
adb_client = { version = "2.0.5" }
|
||||
anyhow = { version = "1.0.89" }
|
||||
clap = { version = "4.5.18", features = ["derive"] }
|
||||
env_logger = { version = "0.11.5" }
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
use std::{io::Read, iter::Map, path::Path, slice::ChunksExact};
|
||||
use std::{
|
||||
io::{Read, Seek, Write},
|
||||
iter::Map,
|
||||
path::Path,
|
||||
slice::ChunksExact,
|
||||
};
|
||||
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use image::{ImageBuffer, Rgba};
|
||||
use image::{ImageBuffer, ImageFormat, Rgba};
|
||||
|
||||
use crate::{models::AdbServerCommand, utils, ADBServerDevice, Result, RustADBError};
|
||||
|
||||
@@ -98,13 +103,21 @@ impl TryFrom<[u8; std::mem::size_of::<Self>()]> for FrameBufferInfoV2 {
|
||||
}
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Dump framebuffer of this device
|
||||
/// Dump framebuffer of this device into given ['path']
|
||||
/// Big help from source code (https://android.googlesource.com/platform/system/adb/+/refs/heads/main/framebuffer_service.cpp)
|
||||
pub fn framebuffer<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
|
||||
let img = self.framebuffer_inner()?;
|
||||
Ok(img.save(path.as_ref())?)
|
||||
}
|
||||
|
||||
/// Dump framebuffer of this device and return corresponding bytes.
|
||||
///
|
||||
/// Output data format is currently only `PNG`.
|
||||
pub fn framebuffer_bytes<W: Write + Seek>(&mut self, mut writer: W) -> Result<()> {
|
||||
let img = self.framebuffer_inner()?;
|
||||
Ok(img.write_to(&mut writer, ImageFormat::Png)?)
|
||||
}
|
||||
|
||||
/// Inner method requesting framebuffer from Android device
|
||||
fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>> {
|
||||
let serial: String = self.identifier.clone();
|
||||
|
||||
Reference in New Issue
Block a user