Copy image to clipboard #995

Open
opened 2025-05-24 07:51:34 +12:00 by mikedilger · 3 comments
mikedilger commented 2025-05-24 07:51:34 +12:00 (Migrated from github.com)
No description provided.
mikedilger commented 2025-05-24 09:44:05 +12:00 (Migrated from github.com)
  1. Images start as a URL.

  2. The 'Fetcher' then handles it and moves it through these states: Starting, CheckingCache, LoadingFromCache, Queued, Fetching, Ready, Taken, Failed. These states are so that subsequent calls to the Fetcher don't start over and fetch it yet-again. This consults a local file cache and then gets it from the network.

  3. Then the media handler hashes the data and compares it to any file metadata that was specified to see if the hash matches what was expected.

  4. Then it scales the image and converts SVGs into images and makes this result available for the UI as an RgbaImage.

  5. The UI then takes the image and turns it into a UI-friendly ColorImage which is loaded to the GPU, and the UI remembers just a TextureHandle.

  6. The UI can now draw it with the TextureHandle as needed. When the UI draws it, it also draws the menu that lets you copy the URL (which it remembered).

In order to add "Copy Image to Clipboard" there will need to be sigificant refactoring because you'll want the original bytes before the media handler scaled and converted the data for rendering purposes back in step 3, which the UI never sees currently (it is part of the lib media handler, which I admit is wrong) and also the UI dropped the bytes itself as soon as it got a TextureHandle (it never needed to keep the bytes so far, and keeping all the images might hog CPU-side memory unnecessarily).

0. Images start as a URL. 1. The 'Fetcher' then handles it and moves it through these states: Starting, CheckingCache, LoadingFromCache, Queued, Fetching, Ready, Taken, Failed. These states are so that subsequent calls to the Fetcher don't start over and fetch it yet-again. This consults a local file cache and then gets it from the network. 2. Then the media handler hashes the data and compares it to any file metadata that was specified to see if the hash matches what was expected. 3. Then it scales the image and converts SVGs into images and makes this result available for the UI as an RgbaImage. 4. The UI then takes the image and turns it into a UI-friendly ColorImage which is loaded to the GPU, and the UI remembers just a TextureHandle. 5. The UI can now draw it with the TextureHandle as needed. When the UI draws it, it also draws the menu that lets you copy the URL (which it remembered). In order to add "Copy Image to Clipboard" there will need to be sigificant refactoring because you'll want the original bytes before the media handler scaled and converted the data for rendering purposes back in step 3, which the UI never sees currently (it is part of the lib media handler, which I admit is wrong) and also the UI dropped the bytes itself as soon as it got a TextureHandle (it never needed to keep the bytes so far, and keeping all the images might hog CPU-side memory unnecessarily).
mikedilger commented 2025-05-24 09:46:04 +12:00 (Migrated from github.com)

Copying an image to the clipboard isn't supported in egui 0.30, but luckily it is supported in 0.31. Something like this:

 ui.output_mut(|o| o.commands.push(egui::OutputCommand::CopyImage(color_image)) 

We just have to have a color_image somewhere.

Copying an image to the clipboard isn't supported in egui 0.30, but luckily it is supported in 0.31. Something like this: ``` ui.output_mut(|o| o.commands.push(egui::OutputCommand::CopyImage(color_image)) ``` We just have to have a color_image somewhere.
mikedilger commented 2025-05-27 08:18:12 +12:00 (Migrated from github.com)

Plan:

  • Globals keeps a cut_paste_image: Option<Vec<u8>>
  • When selecting "Copy Image", set cut_paste_image to None and send a command to the overlord
  • Overlord should ask fetcher to fetch the data from the cache for cut-paste
  • Fetcher fetches it from the cache and stuff it into cut_paste_image
  • UI frame update code always checks cut_paste_image and if ever Some(bytes) it does it and sets it to None, and then adds to the status queue so the user knows it has been done.
Plan: * Globals keeps a `cut_paste_image: Option<Vec<u8>>` * When selecting "Copy Image", set cut_paste_image to None and send a command to the overlord * Overlord should ask fetcher to fetch the data from the cache for cut-paste * Fetcher fetches it from the cache and stuff it into cut_paste_image * UI frame update code always checks cut_paste_image and if ever Some(bytes) it does it and sets it to None, and then adds to the status queue so the user knows it has been done.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nostr/gossip#995
No description provided.