Skip to content

Commit b4e9d7b

Browse files
Desktop: Fix bitmap file export not preserving alpha (#3673)
Fix Export not preserving alpha
1 parent c071243 commit b4e9d7b

4 files changed

Lines changed: 10 additions & 14 deletions

File tree

desktop/src/render/state.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22

33
use crate::window::Window;
4-
use crate::wrapper::{Color, TargetTexture, WgpuContext, WgpuExecutor};
4+
use crate::wrapper::{TargetTexture, WgpuContext, WgpuExecutor};
55

66
#[derive(derivative::Derivative)]
77
#[derivative(Debug)]
@@ -232,10 +232,7 @@ impl RenderState {
232232
return;
233233
};
234234
let size = glam::UVec2::new(viewport_texture.width(), viewport_texture.height());
235-
let result = futures::executor::block_on(
236-
self.executor
237-
.render_vello_scene_to_target_texture(&scene, size, &Default::default(), Color::TRANSPARENT, &mut self.overlays_texture),
238-
);
235+
let result = futures::executor::block_on(self.executor.render_vello_scene_to_target_texture(&scene, size, &Default::default(), None, &mut self.overlays_texture));
239236
if let Err(e) = result {
240237
tracing::error!("Error rendering overlays: {:?}", e);
241238
return;

desktop/wrapper/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use graphite_editor::application::{Editor, Environment, Host, Platform};
33
use graphite_editor::messages::prelude::{FrontendMessage, Message};
44

55
pub use graphite_editor::consts::FILE_EXTENSION;
6-
// TODO: Remove usage of this reexport in desktop create and remove this line
7-
pub use graphene_std::Color;
86

97
pub use wgpu_executor::TargetTexture;
108
pub use wgpu_executor::WgpuContext;

node-graph/libraries/wgpu-executor/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ unsafe impl StaticType for Surface {
112112
const VELLO_SURFACE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
113113

114114
impl WgpuExecutor {
115-
pub async fn render_vello_scene_to_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Color) -> Result<wgpu::Texture> {
115+
pub async fn render_vello_scene_to_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Option<Color>) -> Result<wgpu::Texture> {
116116
let mut output = None;
117117
self.render_vello_scene_to_target_texture(scene, size, context, background, &mut output).await?;
118118
Ok(output.unwrap().texture)
119119
}
120-
pub async fn render_vello_scene_to_target_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Color, output: &mut Option<TargetTexture>) -> Result<()> {
120+
pub async fn render_vello_scene_to_target_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Option<Color>, output: &mut Option<TargetTexture>) -> Result<()> {
121121
// Initialize (lazily) if this is the first call
122122
if output.is_none() {
123123
*output = Some(TargetTexture::new(&self.context.device, size));
@@ -126,7 +126,7 @@ impl WgpuExecutor {
126126
if let Some(target_texture) = output.as_mut() {
127127
target_texture.ensure_size(&self.context.device, size);
128128

129-
let [r, g, b, a] = background.to_rgba8_srgb();
129+
let [r, g, b, a] = background.unwrap_or(Color::TRANSPARENT).to_rgba8_srgb();
130130
let render_params = RenderParams {
131131
base_color: vello::peniko::Color::from_rgba8(r, g, b, a),
132132
width: size.x,

node-graph/nodes/gstd/src/render_node.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ async fn render<'a: 'n>(ctx: impl Ctx + ExtractFootprint + ExtractVarArgs, edito
189189
}
190190
}
191191

192-
let mut background = Color::from_rgb8_srgb(0x22, 0x22, 0x22);
193-
if !contains_artboard && !render_params.hide_artboards {
194-
background = Color::WHITE;
195-
}
192+
let background = if !render_params.for_export && !contains_artboard && !render_params.hide_artboards {
193+
Some(Color::WHITE)
194+
} else {
195+
None
196+
};
196197

197198
let texture = exec
198199
.render_vello_scene_to_texture(&scene, physical_resolution, context, background)

0 commit comments

Comments
 (0)