Skip to content

Commit

Permalink
feat: add framebuffer_bytes method (#61)
Browse files Browse the repository at this point in the history
* feat: add `framebuffer_bytes` method
  • Loading branch information
cocool97 authored Nov 18, 2024
1 parent 5077968 commit 152836f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion adb_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
19 changes: 16 additions & 3 deletions adb_client/src/server/device_commands/framebuffer.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 152836f

Please sign in to comment.