Skip to content

Commit

Permalink
refactor(image_composition): image::imageops::{overlay -> replace}
Browse files Browse the repository at this point in the history
* Overlay takes into account the underlying pixel and the overlayed
  pixel to interpolate the final pixel data.

  Eg: This takes effect for transparent regions in PNG images.

* Replace performs the same operation for us but instead it does not
  perform the pixel interpolation and instead just replaces the pixel.

* Test performed on 8-core i5 machine with only 1 `wl_output`:
---
Benchmark 1: ./wayshot-overlay --stdout > /dev/null
  Time (mean ± σ):      81.6 ms ±  14.1 ms    [User: 25.1 ms, System: 17.1 ms]
  Range (min … max):    59.0 ms … 109.8 ms    41 runs

Benchmark 2: ./wayshot-replace --stdout > /dev/null
  Time (mean ± σ):      75.8 ms ±  14.6 ms    [User: 24.7 ms, System: 15.0 ms]
  Range (min … max):    58.2 ms … 105.3 ms    30 runs

Summary
  './wayshot-replace --stdout > /dev/null' ran
    1.08 ± 0.28 times faster than './wayshot-overlay --stdout > /dev/null'
---

Signed-off-by: Shinyzenith <[email protected]>
  • Loading branch information
Shinyzenith committed Oct 12, 2023
1 parent 6d3da9a commit 5984f6b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libwayshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{
thread,
};

use image::{imageops::overlay, RgbaImage};
use image::{imageops::replace, RgbaImage};
use memmap2::MmapMut;
use wayland_client::{
globals::{registry_queue_init, GlobalList},
Expand Down Expand Up @@ -474,7 +474,7 @@ impl WayshotConnection {
if let Some(overlayed_image_or_error) = possible_overlayed_image_or_error {
if let Ok(mut overlayed_image) = overlayed_image_or_error {
if let Ok(image) = image {
overlay(&mut overlayed_image, &image, 0, 0);
replace(&mut overlayed_image, &image, 0, 0);
Some(Ok(overlayed_image))
} else {
Some(image)
Expand Down

0 comments on commit 5984f6b

Please sign in to comment.