From 152836fe54974ddcf5f71a99bd5d5ddd229dbd84 Mon Sep 17 00:00:00 2001 From: cocool97 <34218602+cocool97@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:15:11 +0100 Subject: [PATCH] feat: add framebuffer_bytes method (#61) * feat: add `framebuffer_bytes` method --- Cargo.toml | 2 +- adb_cli/Cargo.toml | 2 +- .../src/server/device_commands/framebuffer.rs | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a75bd0b..ae93963 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/adb_cli/Cargo.toml b/adb_cli/Cargo.toml index a6cc3fc..45de282 100644 --- a/adb_cli/Cargo.toml +++ b/adb_cli/Cargo.toml @@ -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" } diff --git a/adb_client/src/server/device_commands/framebuffer.rs b/adb_client/src/server/device_commands/framebuffer.rs index 29cf663..16e9518 100644 --- a/adb_client/src/server/device_commands/framebuffer.rs +++ b/adb_client/src/server/device_commands/framebuffer.rs @@ -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::()]> 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>(&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(&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, Vec>> { let serial: String = self.identifier.clone();