Rename Raster to Bitmap

This commit is contained in:
Keavon Chambers 2023-12-08 16:18:56 -08:00
parent c5ed54cbd2
commit 5a6815dd91
9 changed files with 26 additions and 28 deletions

View file

@ -56,7 +56,7 @@ pub enum FrontendMessage {
#[serde(rename = "blobUrl")] #[serde(rename = "blobUrl")]
blob_url: String, blob_url: String,
}, },
TriggerDownloadRaster { TriggerDownloadImage {
svg: String, svg: String,
name: String, name: String,
mime: String, mime: String,

View file

@ -388,7 +388,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
} else { } else {
let mime = file_type.to_mime().to_string(); let mime = file_type.to_mime().to_string();
let size = (size * scale_factor).into(); let size = (size * scale_factor).into();
responses.add(FrontendMessage::TriggerDownloadRaster { svg: document, name, mime, size }); responses.add(FrontendMessage::TriggerDownloadImage { svg: document, name, mime, size });
} }
} }
FlipSelectedLayers { flip_axis } => { FlipSelectedLayers { flip_axis } => {

View file

@ -742,9 +742,8 @@ pub fn load_image_properties(document_node: &DocumentNode, node_id: NodeId, _con
pub fn output_properties(_document_node: &DocumentNode, _node_id: NodeId, context: &mut NodePropertiesContext) -> Vec<LayoutGroup> { pub fn output_properties(_document_node: &DocumentNode, _node_id: NodeId, context: &mut NodePropertiesContext) -> Vec<LayoutGroup> {
let output_type = context.executor.previous_output_type(context.layer_path); let output_type = context.executor.previous_output_type(context.layer_path);
let raster_output_type = concrete!(ImageFrame<Color>);
let disabled = match output_type { let disabled = match output_type {
Some(output_type) => output_type != raster_output_type, Some(output_type) => output_type != concrete!(ImageFrame<Color>),
None => true, None => true,
}; };

View file

@ -11,7 +11,7 @@ import {
TriggerCopyToClipboardBlobUrl, TriggerCopyToClipboardBlobUrl,
TriggerFetchAndOpenDocument, TriggerFetchAndOpenDocument,
TriggerDownloadBlobUrl, TriggerDownloadBlobUrl,
TriggerDownloadRaster, TriggerDownloadImage,
TriggerDownloadTextFile, TriggerDownloadTextFile,
TriggerImport, TriggerImport,
TriggerOpenDocument, TriggerOpenDocument,
@ -83,8 +83,8 @@ export function createPortfolioState(editor: Editor) {
editor.subscriptions.subscribeJsMessage(TriggerCopyToClipboardBlobUrl, (triggerDownloadBlobUrl) => { editor.subscriptions.subscribeJsMessage(TriggerCopyToClipboardBlobUrl, (triggerDownloadBlobUrl) => {
copyToClipboardFileURL(triggerDownloadBlobUrl.blobUrl); copyToClipboardFileURL(triggerDownloadBlobUrl.blobUrl);
}); });
editor.subscriptions.subscribeJsMessage(TriggerDownloadRaster, async (triggerRasterDownload) => { editor.subscriptions.subscribeJsMessage(TriggerDownloadImage, async (triggerDownloadImage) => {
const { svg, name, mime, size } = triggerRasterDownload; const { svg, name, mime, size } = triggerDownloadImage;
// Fill the canvas with white if it'll be a JPEG (which does not support transparency and defaults to black) // Fill the canvas with white if it'll be a JPEG (which does not support transparency and defaults to black)
const backgroundColor = mime.endsWith("jpeg") ? "white" : undefined; const backgroundColor = mime.endsWith("jpeg") ? "white" : undefined;

View file

@ -541,7 +541,7 @@ export class TriggerDownloadBlobUrl extends JsMessage {
readonly blobUrl!: string; readonly blobUrl!: string;
} }
export class TriggerDownloadRaster extends JsMessage { export class TriggerDownloadImage extends JsMessage {
readonly svg!: string; readonly svg!: string;
readonly name!: string; readonly name!: string;
@ -1402,7 +1402,7 @@ export const messageMakers: Record<string, MessageMaker> = {
TriggerCopyToClipboardBlobUrl, TriggerCopyToClipboardBlobUrl,
TriggerFetchAndOpenDocument, TriggerFetchAndOpenDocument,
TriggerDownloadBlobUrl, TriggerDownloadBlobUrl,
TriggerDownloadRaster, TriggerDownloadImage,
TriggerDownloadTextFile, TriggerDownloadTextFile,
TriggerFontLoad, TriggerFontLoad,
TriggerGraphViewOverlay, TriggerGraphViewOverlay,

View file

@ -222,15 +222,14 @@ impl<'i, T: Sample> Sample for &'i T {
} }
} }
// TODO: We might rename this to Bitmap at some point pub trait Bitmap {
pub trait Raster {
type Pixel: Pixel; type Pixel: Pixel;
fn width(&self) -> u32; fn width(&self) -> u32;
fn height(&self) -> u32; fn height(&self) -> u32;
fn get_pixel(&self, x: u32, y: u32) -> Option<Self::Pixel>; fn get_pixel(&self, x: u32, y: u32) -> Option<Self::Pixel>;
} }
impl<'i, T: Raster> Raster for &'i T { impl<'i, T: Bitmap> Bitmap for &'i T {
type Pixel = T::Pixel; type Pixel = T::Pixel;
fn width(&self) -> u32 { fn width(&self) -> u32 {
@ -246,7 +245,7 @@ impl<'i, T: Raster> Raster for &'i T {
} }
} }
impl<'i, T: Raster> Raster for &'i mut T { impl<'i, T: Bitmap> Bitmap for &'i mut T {
type Pixel = T::Pixel; type Pixel = T::Pixel;
fn width(&self) -> u32 { fn width(&self) -> u32 {
@ -262,7 +261,7 @@ impl<'i, T: Raster> Raster for &'i mut T {
} }
} }
pub trait RasterMut: Raster { pub trait BitmapMut: Bitmap {
fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel>; fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel>;
fn set_pixel(&mut self, x: u32, y: u32, pixel: Self::Pixel) { fn set_pixel(&mut self, x: u32, y: u32, pixel: Self::Pixel) {
*self.get_pixel_mut(x, y).unwrap() = pixel; *self.get_pixel_mut(x, y).unwrap() = pixel;
@ -277,7 +276,7 @@ pub trait RasterMut: Raster {
} }
} }
impl<'i, T: RasterMut + Raster> RasterMut for &'i mut T { impl<'i, T: BitmapMut + Bitmap> BitmapMut for &'i mut T {
fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel> { fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel> {
(*self).get_pixel_mut(x, y) (*self).get_pixel_mut(x, y)
} }
@ -567,7 +566,7 @@ impl<'a, P> Default for ImageSlice<'a, P> {
} }
#[cfg(not(target_arch = "spirv"))] #[cfg(not(target_arch = "spirv"))]
impl<P: Copy + Debug + Pixel> Raster for ImageSlice<'_, P> { impl<P: Copy + Debug + Pixel> Bitmap for ImageSlice<'_, P> {
type Pixel = P; type Pixel = P;
fn get_pixel(&self, x: u32, y: u32) -> Option<P> { fn get_pixel(&self, x: u32, y: u32) -> Option<P> {
self.data.get((x + y * self.width) as usize).copied() self.data.get((x + y * self.width) as usize).copied()

View file

@ -66,7 +66,7 @@ where
type Static = Image<P::Static>; type Static = Image<P::Static>;
} }
impl<P: Copy + Pixel> Raster for Image<P> { impl<P: Copy + Pixel> Bitmap for Image<P> {
type Pixel = P; type Pixel = P;
#[inline(always)] #[inline(always)]
fn get_pixel(&self, x: u32, y: u32) -> Option<P> { fn get_pixel(&self, x: u32, y: u32) -> Option<P> {
@ -82,7 +82,7 @@ impl<P: Copy + Pixel> Raster for Image<P> {
} }
} }
impl<P: Copy + Pixel> RasterMut for Image<P> { impl<P: Copy + Pixel> BitmapMut for Image<P> {
fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut P> { fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut P> {
self.data.get_mut((x + y * self.width) as usize) self.data.get_mut((x + y * self.width) as usize)
} }
@ -278,7 +278,7 @@ impl<P: Debug + Copy + Pixel> Sample for ImageFrame<P> {
} }
} }
impl<P: Copy + Pixel> Raster for ImageFrame<P> { impl<P: Copy + Pixel> Bitmap for ImageFrame<P> {
type Pixel = P; type Pixel = P;
fn width(&self) -> u32 { fn width(&self) -> u32 {
@ -294,7 +294,7 @@ impl<P: Copy + Pixel> Raster for ImageFrame<P> {
} }
} }
impl<P: Copy + Pixel> RasterMut for ImageFrame<P> { impl<P: Copy + Pixel> BitmapMut for ImageFrame<P> {
fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel> { fn get_pixel_mut(&mut self, x: u32, y: u32) -> Option<&mut Self::Pixel> {
self.image.get_pixel_mut(x, y) self.image.get_pixel_mut(x, y)
} }

View file

@ -352,5 +352,5 @@ impl UpcastNode {
pub enum RenderOutput { pub enum RenderOutput {
CanvasFrame(graphene_core::SurfaceFrame), CanvasFrame(graphene_core::SurfaceFrame),
Svg(String), Svg(String),
Raster(Vec<u8>), Image(Vec<u8>),
} }

View file

@ -2,7 +2,7 @@ use dyn_any::{DynAny, StaticType};
use glam::{DAffine2, DVec2, Vec2}; use glam::{DAffine2, DVec2, Vec2};
use graph_craft::imaginate_input::{ImaginateController, ImaginateMaskStartingFill, ImaginateSamplingMethod}; use graph_craft::imaginate_input::{ImaginateController, ImaginateMaskStartingFill, ImaginateSamplingMethod};
use graph_craft::proto::DynFuture; use graph_craft::proto::DynFuture;
use graphene_core::raster::{Alpha, BlendMode, BlendNode, Image, ImageFrame, Linear, LinearChannel, Luminance, NoiseType, Pixel, RGBMut, Raster, RasterMut, RedGreenBlue, Sample}; use graphene_core::raster::{Alpha, Bitmap, BitmapMut, BlendMode, BlendNode, Image, ImageFrame, Linear, LinearChannel, Luminance, NoiseType, Pixel, RGBMut, RedGreenBlue, Sample};
use graphene_core::transform::{Footprint, Transform}; use graphene_core::transform::{Footprint, Transform};
use crate::wasm_application_io::WasmEditorApi; use crate::wasm_application_io::WasmEditorApi;
@ -126,7 +126,7 @@ pub struct MapImageNode<P, MapFn> {
} }
#[node_macro::node_fn(MapImageNode<_P>)] #[node_macro::node_fn(MapImageNode<_P>)]
fn map_image<MapFn, _P, Img: RasterMut<Pixel = _P>>(image: Img, map_fn: &'input MapFn) -> Img fn map_image<MapFn, _P, Img: BitmapMut<Pixel = _P>>(image: Img, map_fn: &'input MapFn) -> Img
where where
MapFn: for<'any_input> Node<'any_input, _P, Output = _P> + 'input, MapFn: for<'any_input> Node<'any_input, _P, Output = _P> + 'input,
{ {
@ -150,8 +150,8 @@ fn insert_channel_node<
_P: RGBMut, _P: RGBMut,
_S: Pixel + Luminance, _S: Pixel + Luminance,
// Input image // Input image
Input: RasterMut<Pixel = _P>, Input: BitmapMut<Pixel = _P>,
Insertion: Raster<Pixel = _S>, Insertion: Bitmap<Pixel = _S>,
>( >(
mut image: Input, mut image: Input,
insertion: Insertion, insertion: Insertion,
@ -200,7 +200,7 @@ fn mask_imge<
// mask the input image // mask the input image
_S: Luminance, _S: Luminance,
// Input image // Input image
Input: Transform + RasterMut<Pixel = _P>, Input: Transform + BitmapMut<Pixel = _P>,
// Stencil // Stencil
Stencil: Transform + Sample<Pixel = _S>, Stencil: Transform + Sample<Pixel = _S>,
>( >(
@ -316,7 +316,7 @@ where
blend_image(foreground, new_background, map_fn) blend_image(foreground, new_background, map_fn)
} }
fn blend_image<'input, _P: Alpha + Pixel + Debug, MapFn, Frame: Sample<Pixel = _P> + Transform, Background: RasterMut<Pixel = _P> + Transform + Sample<Pixel = _P>>( fn blend_image<'input, _P: Alpha + Pixel + Debug, MapFn, Frame: Sample<Pixel = _P> + Transform, Background: BitmapMut<Pixel = _P> + Transform + Sample<Pixel = _P>>(
foreground: Frame, foreground: Frame,
background: Background, background: Background,
map_fn: &'input MapFn, map_fn: &'input MapFn,
@ -327,7 +327,7 @@ where
blend_image_closure(foreground, background, |a, b| map_fn.eval((a, b))) blend_image_closure(foreground, background, |a, b| map_fn.eval((a, b)))
} }
pub fn blend_image_closure<_P: Alpha + Pixel + Debug, MapFn, Frame: Sample<Pixel = _P> + Transform, Background: RasterMut<Pixel = _P> + Transform + Sample<Pixel = _P>>( pub fn blend_image_closure<_P: Alpha + Pixel + Debug, MapFn, Frame: Sample<Pixel = _P> + Transform, Background: BitmapMut<Pixel = _P> + Transform + Sample<Pixel = _P>>(
foreground: Frame, foreground: Frame,
mut background: Background, mut background: Background,
map_fn: MapFn, map_fn: MapFn,