Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Add screenshot export improvements and new icon
Richie McIlroy61982eb243da
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex d48ec03f9..d3381b173 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -1113,6 +1113,25 @@ async fn copy_screenshot_to_clipboard(Ok(())}+#[tauri::command]+#[specta::specta]+#[instrument(skip(clipboard, data))]+async fn copy_image_to_clipboard(+ clipboard: MutableState<'_, ClipboardContext>,+ data: Vec<u8>,+) -> Result<(), String> {+ println!("Copying image to clipboard ({} bytes)", data.len());++ let img_data = clipboard_rs::RustImageData::from_bytes(&data)+ .map_err(|e| format!("Failed to create image data from bytes: {e}"))?;+ clipboard+ .write()+ .await+ .set_image(img_data)+ .map_err(|err| format!("Failed to copy image to clipboard: {err}"))?;+ Ok(())+}+#[tauri::command]#[specta::specta]#[instrument(skip(_app))]@@ -2248,6 +2267,7 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {copy_file_to_path,copy_video_to_clipboard,copy_screenshot_to_clipboard,+ copy_image_to_clipboard,open_file_path,get_video_metadata,create_editor_instance,diff --git a/apps/desktop/src-tauri/src/screenshot_editor.rs b/apps/desktop/src-tauri/src/screenshot_editor.rsindex 2a77d4b5b..f8aa5a12d 100644--- a/apps/desktop/src-tauri/src/screenshot_editor.rs+++ b/apps/desktop/src-tauri/src/screenshot_editor.rs@@ -213,12 +213,15 @@ impl ScreenshotEditorInstances {recording_time: 0.0,};+ let (base_w, base_h) =+ ProjectUniforms::get_base_size(&constants.options, ¤t_config);+let uniforms = ProjectUniforms::new(&constants,¤t_config,0,30,- cap_project::XY::new(width, height),+ cap_project::XY::new(base_w, base_h),&cap_project::CursorEvents::default(),&segment_frames,);diff --git a/apps/desktop/src/components/Mode.tsx b/apps/desktop/src/components/Mode.tsxindex 7950c6fd3..37acdc259 100644--- a/apps/desktop/src/components/Mode.tsx+++ b/apps/desktop/src/components/Mode.tsx@@ -3,7 +3,6 @@ import { createSignal } from "solid-js";import Tooltip from "~/components/Tooltip";import { useRecordingOptions } from "~/routes/(window-chrome)/OptionsContext";import { commands } from "~/utils/tauri";-import IconCapImageFilled from "~icons/cap/image-filled";const Mode = () => {const { rawOptions, setOptions } = useRecordingOptions();@@ -81,7 +80,7 @@ const Mode = () => {: "bg-gray-3 hover:bg-gray-7"}`}>- <IconCapImageFilled class="size-3.5 invert dark:invert-0" />+ <IconCapScreenshot class="size-3.5 invert dark:invert-0" /></div></Tooltip>)}@@ -124,7 +123,7 @@ const Mode = () => {: "bg-gray-3 hover:bg-gray-7"}`}>- <IconCapImageFilled class="size-3.5 invert dark:invert-0" />+ <IconCapScreenshot class="size-3.5 invert dark:invert-0" /></div></>)}diff --git a/apps/desktop/src/components/ModeSelect.tsx b/apps/desktop/src/components/ModeSelect.tsxindex 8ca19afb1..61f1d17a6 100644--- a/apps/desktop/src/components/ModeSelect.tsx+++ b/apps/desktop/src/components/ModeSelect.tsx@@ -73,7 +73,7 @@ const ModeSelect = (props: { onClose?: () => void; standalone?: boolean }) => {title: "Screenshot Mode",description:"Capture high-quality screenshots of your screen or specific windows. Annotate and share instantly.",- icon: IconCapCamera,+ icon: IconCapScreenshot,},];@@ -81,7 +81,7 @@ const ModeSelect = (props: { onClose?: () => void; standalone?: boolean }) => {<divdata-tauri-drag-region="none"class={cx(- "grid grid-cols-2 gap-8 items-center text-center bg-gray-1",+ "grid grid-cols-1 md:grid-cols-3 gap-8 items-center text-center bg-gray-1",props.standalone? "absolute z-10 border border-gray-3 p-16 rounded-xl": "",diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/TargetMenuGrid.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/TargetMenuGrid.tsxindex 2531ba96d..565d8a345 100644--- a/apps/desktop/src/routes/(window-chrome)/new-main/TargetMenuGrid.tsx+++ b/apps/desktop/src/routes/(window-chrome)/new-main/TargetMenuGrid.tsx@@ -7,6 +7,7 @@ import type {} from "~/utils/tauri";import TargetCard, {type RecordingWithPath,+ type ScreenshotWithPath,TargetCardSkeleton,} from "./TargetCard";@@ -36,10 +37,15 @@ type RecordingGridProps = BaseProps<RecordingWithPath> & {variant: "recording";};+type ScreenshotGridProps = BaseProps<ScreenshotWithPath> & {+ variant: "screenshot";+};+type TargetMenuGridProps =| DisplayGridProps| WindowGridProps- | RecordingGridProps;+ | RecordingGridProps+ | ScreenshotGridProps;export default function TargetMenuGrid(props: TargetMenuGridProps) {const items = createMemo(() => props.targets ?? []);@@ -111,7 +117,9 @@ export default function TargetMenuGrid(props: TargetMenuGridProps) {? "No displays found": props.variant === "window"? "No windows found"- : "No recordings found";+ : props.variant === "recording"+ ? "No recordings found"+ : "No screenshots found";return (<div@@ -247,6 +255,41 @@ export default function TargetMenuGrid(props: TargetMenuGridProps) {);})()}</Match>+ <Match when={props.variant === "screenshot"}>+ {(() => {+ const screenshotProps = props as ScreenshotGridProps;+ return (+ <For each={items() as ScreenshotWithPath[]}>+ {(item, index) => (+ <Transition+ appear+ enterActiveClass="transition duration-200"+ enterClass="scale-95 opacity-0"+ enterToClass="scale-100 opacity-100"+ exitActiveClass="transition duration-200"+ exitClass="scale-100"+ exitToClass="scale-95"+ >+ <div+ style={{ "transition-delay": `${index() * 100}ms` }}+ >+ <TargetCard+ variant="screenshot"+ target={item}+ onClick={() => screenshotProps.onSelect?.(item)}+ disabled={screenshotProps.disabled}+ onKeyDown={handleKeyDown}+ class="w-full"+ data-target-menu-card="true"+ highlightQuery={screenshotProps.highlightQuery}+ />+ </div>+ </Transition>+ )}+ </For>+ );+ })()}+ </Match></Switch></Match></Switch>diff --git a/apps/desktop/src/routes/(window-chrome)/settings/screenshots.tsx b/apps/desktop/src/routes/(window-chrome)/settings/screenshots.tsxindex 998fdb22e..58689f807 100644--- a/apps/desktop/src/routes/(window-chrome)/settings/screenshots.tsx+++ b/apps/desktop/src/routes/(window-chrome)/settings/screenshots.tsx@@ -27,11 +27,8 @@ import IconLucideCopy from "~icons/lucide/copy";import IconLucideEdit from "~icons/lucide/edit";import IconLucideFolder from "~icons/lucide/folder";-type Screenshot = {- meta: RecordingMeta;- path: string; // png path- prettyName: string;- thumbnailPath: string;+type Screenshot = RecordingMeta & {+ path: string;};const Tabs: { id: string; label: string; icon?: JSX.Element }[] = [@@ -45,22 +42,7 @@ const screenshotsQuery = queryOptions({queryKey: ["screenshots"],queryFn: async () => {const result = await commands.listScreenshots().catch(() => [] as const);-- const screenshots = await Promise.all(- result.map(async (file) => {- const [path, meta] = file;- // path is the png path.- // thumbnail is the same as path for screenshots.-- return {- meta,- path,- prettyName: meta.pretty_name,- thumbnailPath: path,- };- }),- );- return screenshots;+ return result.map(([path, meta]) => ({ ...meta, path }));},reconcile: (old, n) => reconcile(n)(old),refetchInterval: 2000,@@ -193,14 +175,12 @@ function ScreenshotItem(props: {<imgclass="object-cover rounded size-12"alt="Screenshot thumbnail"- src={`${convertFileSrc(- props.screenshot.thumbnailPath,- )}?t=${Date.now()}`}+ src={`${convertFileSrc(props.screenshot.path)}?t=${Date.now()}`}onError={() => setImageExists(false)}/></Show><div class="flex flex-col gap-2">- <span>{props.screenshot.prettyName}</span>+ <span>{props.screenshot.pretty_name}</span></div></div><div class="flex gap-2 items-center">diff --git a/apps/desktop/src/routes/mode-select.tsx b/apps/desktop/src/routes/mode-select.tsxindex bbeb90846..cbd8fe8d7 100644--- a/apps/desktop/src/routes/mode-select.tsx+++ b/apps/desktop/src/routes/mode-select.tsx@@ -1,10 +1,22 @@+import type { UnlistenFn } from "@tauri-apps/api/event";import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";-import { onMount } from "solid-js";+import { type as ostype } from "@tauri-apps/plugin-os";+import { onCleanup, onMount } from "solid-js";import ModeSelect from "~/components/ModeSelect";+import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";+import { initializeTitlebar } from "~/utils/titlebar-state";const ModeSelectWindow = () => {+ let unlistenResize: UnlistenFn | undefined;+ const isWindows = ostype() === "windows";+onMount(async () => {const window = getCurrentWindow();++ if (isWindows) {+ unlistenResize = await initializeTitlebar();+ }+try {const currentSize = await window.innerSize();@@ -16,14 +28,23 @@ const ModeSelectWindow = () => {}});+ onCleanup(() => {+ unlistenResize?.();+ });+return (<divdata-tauri-drag-regionclass="flex relative justify-center items-center p-4 min-h-screen bg-gray-1">+ {isWindows && (+ <div class="absolute top-0 right-0 z-50 h-9">+ <CaptionControlsWindows11 />+ </div>+ )}<divdata-tauri-drag-region="none"- class="relative z-10 space-y-10 w-full max-w-3xl"+ class="relative z-10 space-y-10 w-full max-w-5xl"><h2 class="text-[24px] font-medium text-center text-gray-12">Recording Modesdiff --git a/apps/desktop/src/routes/screenshot-editor/ExportDialog.tsx b/apps/desktop/src/routes/screenshot-editor/ExportDialog.tsxindex e089bfbca..bc2044673 100644--- a/apps/desktop/src/routes/screenshot-editor/ExportDialog.tsx+++ b/apps/desktop/src/routes/screenshot-editor/ExportDialog.tsx@@ -1,264 +1,11 @@import { Button } from "@cap/ui-solid";-import { convertFileSrc } from "@tauri-apps/api/core";-import { save } from "@tauri-apps/plugin-dialog";-import { createSignal } from "solid-js";-import toast from "solid-toast";-import { commands } from "~/utils/tauri";import IconCapCopy from "~icons/cap/copy";import IconCapFile from "~icons/cap/file";-import { type Annotation, useScreenshotEditorContext } from "./context";-import { Dialog, DialogContent } from "./ui";+import { DialogContent } from "./ui";+import { useScreenshotExport } from "./useScreenshotExport";export function ExportDialog() {- const { dialog, setDialog, path, latestFrame, annotations } =- useScreenshotEditorContext();- const [exporting, setExporting] = createSignal(false);-- const drawAnnotations = (- ctx: CanvasRenderingContext2D,- annotations: Annotation[],- ) => {- for (const ann of annotations) {- if (ann.type === "mask") continue;- ctx.save();- ctx.globalAlpha = ann.opacity;- ctx.strokeStyle = ann.strokeColor;- ctx.lineWidth = ann.strokeWidth;- ctx.fillStyle = ann.fillColor;-- if (ann.type === "rectangle") {- if (ann.fillColor !== "transparent") {- ctx.fillRect(ann.x, ann.y, ann.width, ann.height);- }- ctx.strokeRect(ann.x, ann.y, ann.width, ann.height);- } else if (ann.type === "circle") {- ctx.beginPath();- const cx = ann.x + ann.width / 2;- const cy = ann.y + ann.height / 2;- const rx = Math.abs(ann.width / 2);- const ry = Math.abs(ann.height / 2);- ctx.ellipse(cx, cy, rx, ry, 0, 0, 2 * Math.PI);- if (ann.fillColor !== "transparent") {- ctx.fill();- }- ctx.stroke();- } else if (ann.type === "arrow") {- ctx.beginPath();- const x1 = ann.x;- const y1 = ann.y;- const x2 = ann.x + ann.width;- const y2 = ann.y + ann.height;-- // Line- ctx.moveTo(x1, y1);- ctx.lineTo(x2, y2);- ctx.stroke();-- // Arrowhead- const angle = Math.atan2(y2 - y1, x2 - x1);- const headLen = 10 + ann.strokeWidth; // scale with stroke?- ctx.beginPath();- ctx.moveTo(x2, y2);- ctx.lineTo(- x2 - headLen * Math.cos(angle - Math.PI / 6),- y2 - headLen * Math.sin(angle - Math.PI / 6),- );- ctx.lineTo(- x2 - headLen * Math.cos(angle + Math.PI / 6),- y2 - headLen * Math.sin(angle + Math.PI / 6),- );- ctx.lineTo(x2, y2);- ctx.fillStyle = ann.strokeColor;- ctx.fill();- } else if (ann.type === "text" && ann.text) {- ctx.fillStyle = ann.strokeColor; // Text uses stroke color- ctx.font = `${ann.height}px sans-serif`;- ctx.fillText(ann.text, ann.x, ann.y + ann.height); // text baseline bottomish- }-- ctx.restore();- }- };-- const blurRegion = (- ctx: CanvasRenderingContext2D,- source: HTMLCanvasElement,- startX: number,- startY: number,- regionWidth: number,- regionHeight: number,- level: number,- ) => {- const scale = Math.max(2, Math.round(level / 4));- const temp = document.createElement("canvas");- temp.width = Math.max(1, Math.floor(regionWidth / scale));- temp.height = Math.max(1, Math.floor(regionHeight / scale));- const tempCtx = temp.getContext("2d");- if (!tempCtx) return;-- tempCtx.imageSmoothingEnabled = true;- tempCtx.drawImage(- source,- startX,- startY,- regionWidth,- regionHeight,- 0,- 0,- temp.width,- temp.height,- );-- ctx.drawImage(- temp,- 0,- 0,- temp.width,- temp.height,- startX,- startY,- regionWidth,- regionHeight,- );- };-- const applyMaskAnnotations = (- ctx: CanvasRenderingContext2D,- source: HTMLCanvasElement,- annotations: Annotation[],- ) => {- for (const ann of annotations) {- if (ann.type !== "mask") continue;-- const startX = Math.max(0, Math.min(ann.x, ann.x + ann.width));- const startY = Math.max(0, Math.min(ann.y, ann.y + ann.height));- const endX = Math.min(source.width, Math.max(ann.x, ann.x + ann.width));- const endY = Math.min(source.height, Math.max(ann.y, ann.y + ann.height));-- const regionWidth = endX - startX;- const regionHeight = endY - startY;- if (regionWidth <= 0 || regionHeight <= 0) continue;-- const level = Math.max(1, ann.maskLevel ?? 16);- const type = ann.maskType ?? "blur";-- if (type === "pixelate") {- const blockSize = Math.max(2, Math.round(level));- const temp = document.createElement("canvas");- temp.width = Math.max(1, Math.floor(regionWidth / blockSize));- temp.height = Math.max(1, Math.floor(regionHeight / blockSize));- const tempCtx = temp.getContext("2d");- if (!tempCtx) continue;- tempCtx.imageSmoothingEnabled = false;- tempCtx.drawImage(- source,- startX,- startY,- regionWidth,- regionHeight,- 0,- 0,- temp.width,- temp.height,- );- const previousSmoothing = ctx.imageSmoothingEnabled;- ctx.imageSmoothingEnabled = false;- ctx.drawImage(- temp,- 0,- 0,- temp.width,- temp.height,- startX,- startY,- regionWidth,- regionHeight,- );- ctx.imageSmoothingEnabled = previousSmoothing;- continue;- }-- blurRegion(ctx, source, startX, startY, regionWidth, regionHeight, level);- }- ctx.filter = "none";- };-- const exportImage = async (destination: "file" | "clipboard") => {- setExporting(true);- try {- const canvas = document.createElement("canvas");- const ctx = canvas.getContext("2d");- if (!ctx) throw new Error("Could not get canvas context");-- const frame = latestFrame();- if (frame) {- canvas.width = frame.width;- canvas.height = frame.data.height;- ctx.putImageData(frame.data, 0, 0);- } else {- // Fallback to loading file- const img = new Image();- img.src = convertFileSrc(path);- await new Promise((resolve, reject) => {- img.onload = resolve;- img.onerror = reject;- });- canvas.width = img.width;- canvas.height = img.height;- ctx.drawImage(img, 0, 0);- }-- const sourceCanvas = document.createElement("canvas");- sourceCanvas.width = canvas.width;- sourceCanvas.height = canvas.height;- const sourceCtx = sourceCanvas.getContext("2d");- if (!sourceCtx) throw new Error("Could not get source canvas context");- sourceCtx.drawImage(canvas, 0, 0);-- applyMaskAnnotations(ctx, sourceCanvas, annotations);- drawAnnotations(ctx, annotations);-- // 3. Export- const blob = await new Promise<Blob | null>((resolve) =>- canvas.toBlob(resolve, "image/png"),- );- if (!blob) throw new Error("Failed to create blob");-- const buffer = await blob.arrayBuffer();- const uint8Array = new Uint8Array(buffer);-- if (destination === "file") {- const savePath = await save({- filters: [{ name: "PNG Image", extensions: ["png"] }],- defaultPath: "screenshot.png",- });- if (savePath) {- await commands.writeFile(savePath, Array.from(uint8Array));- toast.success("Screenshot saved!");- }- } else {- // Copy to clipboard- // We need a command for this as web API might be limited- // commands.copyImageToClipboard(uint8Array)?- // For now, let's use the existing command if it supports data- // commands.copyScreenshotToClipboard(path) copies the file at path.- // If we want to copy the *edited* image, we need to save it to a temp file first or send bytes.-- // Fallback to copying the original file for now- await commands.copyScreenshotToClipboard(path);- toast.success(- "Original screenshot copied to clipboard (editing export WIP)",- );- }-- setDialog({ ...dialog(), open: false });- } catch (err) {- console.error(err);- toast.error("Failed to export");- } finally {- setExporting(false);- }- };+ const { exportImage, isExporting } = useScreenshotExport();return (<DialogContent@@ -274,7 +21,7 @@ export function ExportDialog() {variant="gray"class="flex-1 flex gap-2 items-center justify-center h-12"onClick={() => exportImage("file")}- disabled={exporting()}+ disabled={isExporting()}><IconCapFile class="size-5" />Save to File@@ -283,7 +30,7 @@ export function ExportDialog() {variant="gray"class="flex-1 flex gap-2 items-center justify-center h-12"onClick={() => exportImage("clipboard")}- disabled={exporting()}+ disabled={isExporting()}><IconCapCopy class="size-5" />Copy to Clipboarddiff --git a/apps/desktop/src/routes/screenshot-editor/Header.tsx b/apps/desktop/src/routes/screenshot-editor/Header.tsxindex 46c75070c..4b2db39bd 100644--- a/apps/desktop/src/routes/screenshot-editor/Header.tsx+++ b/apps/desktop/src/routes/screenshot-editor/Header.tsx@@ -21,6 +21,7 @@ import IconLucideSave from "~icons/lucide/save";import { AnnotationTools } from "./AnnotationTools";import { useScreenshotEditorContext } from "./context";import PresetsSubMenu from "./PresetsDropdown";+import { useScreenshotExport } from "./useScreenshotExport";import { AspectRatioSelect } from "./popovers/AspectRatioSelect";import { BackgroundSettingsPopover } from "./popovers/BackgroundSettingsPopover";import { BorderPopover } from "./popovers/BorderPopover";@@ -40,6 +41,8 @@ export function Header() {const { path, setDialog, project, latestFrame } =useScreenshotEditorContext();+ const { exportImage, isExporting } = useScreenshotExport();+const cropDialogHandler = () => {const frame = latestFrame();setDialog({@@ -93,9 +96,10 @@ export function Header() {<EditorButtononClick={() => {- commands.copyScreenshotToClipboard(path);+ exportImage("clipboard");}}tooltipText="Copy to Clipboard"+ disabled={isExporting()}leftIcon={<IconLucideCopy class="w-4" />}/>diff --git a/apps/desktop/src/routes/screenshot-editor/useScreenshotExport.ts b/apps/desktop/src/routes/screenshot-editor/useScreenshotExport.tsnew file mode 100644index 000000000..354748b7a--- /dev/null+++ b/apps/desktop/src/routes/screenshot-editor/useScreenshotExport.ts@@ -0,0 +1,250 @@+import { convertFileSrc } from "@tauri-apps/api/core";+import { save } from "@tauri-apps/plugin-dialog";+import { createSignal } from "solid-js";+import toast from "solid-toast";+import { commands } from "~/utils/tauri";+import { type Annotation, useScreenshotEditorContext } from "./context";++export function useScreenshotExport() {+ const { path, latestFrame, annotations } = useScreenshotEditorContext();+ const [isExporting, setIsExporting] = createSignal(false);++ const drawAnnotations = (+ ctx: CanvasRenderingContext2D,+ annotations: Annotation[],+ ) => {+ for (const ann of annotations) {+ if (ann.type === "mask") continue;+ ctx.save();+ ctx.globalAlpha = ann.opacity;+ ctx.strokeStyle = ann.strokeColor;+ ctx.lineWidth = ann.strokeWidth;+ ctx.fillStyle = ann.fillColor;++ if (ann.type === "rectangle") {+ if (ann.fillColor !== "transparent") {+ ctx.fillRect(ann.x, ann.y, ann.width, ann.height);+ }+ ctx.strokeRect(ann.x, ann.y, ann.width, ann.height);+ } else if (ann.type === "circle") {+ ctx.beginPath();+ const cx = ann.x + ann.width / 2;+ const cy = ann.y + ann.height / 2;+ const rx = Math.abs(ann.width / 2);+ const ry = Math.abs(ann.height / 2);+ ctx.ellipse(cx, cy, rx, ry, 0, 0, 2 * Math.PI);+ if (ann.fillColor !== "transparent") {+ ctx.fill();+ }+ ctx.stroke();+ } else if (ann.type === "arrow") {+ ctx.beginPath();+ const x1 = ann.x;+ const y1 = ann.y;+ const x2 = ann.x + ann.width;+ const y2 = ann.y + ann.height;++ // Line+ ctx.moveTo(x1, y1);+ ctx.lineTo(x2, y2);+ ctx.stroke();++ // Arrowhead+ const angle = Math.atan2(y2 - y1, x2 - x1);+ const headLen = 10 + ann.strokeWidth; // scale with stroke?+ ctx.beginPath();+ ctx.moveTo(x2, y2);+ ctx.lineTo(+ x2 - headLen * Math.cos(angle - Math.PI / 6),+ y2 - headLen * Math.sin(angle - Math.PI / 6),+ );+ ctx.lineTo(+ x2 - headLen * Math.cos(angle + Math.PI / 6),+ y2 - headLen * Math.sin(angle + Math.PI / 6),+ );+ ctx.lineTo(x2, y2);+ ctx.fillStyle = ann.strokeColor;+ ctx.fill();+ } else if (ann.type === "text" && ann.text) {+ ctx.fillStyle = ann.strokeColor; // Text uses stroke color+ ctx.font = `${ann.height}px sans-serif`;+ ctx.fillText(ann.text, ann.x, ann.y + ann.height); // text baseline bottomish+ }++ ctx.restore();+ }+ };++ const blurRegion = (+ ctx: CanvasRenderingContext2D,+ source: HTMLCanvasElement,+ startX: number,+ startY: number,+ regionWidth: number,+ regionHeight: number,+ level: number,+ ) => {+ const scale = Math.max(2, Math.round(level / 4));+ const temp = document.createElement("canvas");+ temp.width = Math.max(1, Math.floor(regionWidth / scale));+ temp.height = Math.max(1, Math.floor(regionHeight / scale));+ const tempCtx = temp.getContext("2d");+ if (!tempCtx) return;++ tempCtx.imageSmoothingEnabled = true;+ tempCtx.drawImage(+ source,+ startX,+ startY,+ regionWidth,+ regionHeight,+ 0,+ 0,+ temp.width,+ temp.height,+ );++ ctx.drawImage(+ temp,+ 0,+ 0,+ temp.width,+ temp.height,+ startX,+ startY,+ regionWidth,+ regionHeight,+ );+ };++ const applyMaskAnnotations = (+ ctx: CanvasRenderingContext2D,+ source: HTMLCanvasElement,+ annotations: Annotation[],+ ) => {+ for (const ann of annotations) {+ if (ann.type !== "mask") continue;++ const startX = Math.max(0, Math.min(ann.x, ann.x + ann.width));+ const startY = Math.max(0, Math.min(ann.y, ann.y + ann.height));+ const endX = Math.min(source.width, Math.max(ann.x, ann.x + ann.width));+ const endY = Math.min(source.height, Math.max(ann.y, ann.y + ann.height));++ const regionWidth = endX - startX;+ const regionHeight = endY - startY;+ if (regionWidth <= 0 || regionHeight <= 0) continue;++ const level = Math.max(1, ann.maskLevel ?? 16);+ const type = ann.maskType ?? "blur";++ if (type === "pixelate") {+ const blockSize = Math.max(2, Math.round(level));+ const temp = document.createElement("canvas");+ temp.width = Math.max(1, Math.floor(regionWidth / blockSize));+ temp.height = Math.max(1, Math.floor(regionHeight / blockSize));+ const tempCtx = temp.getContext("2d");+ if (!tempCtx) continue;+ tempCtx.imageSmoothingEnabled = false;+ tempCtx.drawImage(+ source,+ startX,+ startY,+ regionWidth,+ regionHeight,+ 0,+ 0,+ temp.width,+ temp.height,+ );+ const previousSmoothing = ctx.imageSmoothingEnabled;+ ctx.imageSmoothingEnabled = false;+ ctx.drawImage(+ temp,+ 0,+ 0,+ temp.width,+ temp.height,+ startX,+ startY,+ regionWidth,+ regionHeight,+ );+ ctx.imageSmoothingEnabled = previousSmoothing;+ continue;+ }++ blurRegion(ctx, source, startX, startY, regionWidth, regionHeight, level);+ }+ ctx.filter = "none";+ };++ const exportImage = async (destination: "file" | "clipboard") => {+ setIsExporting(true);+ try {+ const canvas = document.createElement("canvas");+ const ctx = canvas.getContext("2d");+ if (!ctx) throw new Error("Could not get canvas context");++ const frame = latestFrame();+ if (frame) {+ canvas.width = frame.width;+ canvas.height = frame.data.height;+ ctx.putImageData(frame.data, 0, 0);+ } else {+ // Fallback to loading file+ const img = new Image();+ img.src = convertFileSrc(path);+ await new Promise((resolve, reject) => {+ img.onload = resolve;+ img.onerror = reject;+ });+ canvas.width = img.width;+ canvas.height = img.height;+ ctx.drawImage(img, 0, 0);+ }++ const sourceCanvas = document.createElement("canvas");+ sourceCanvas.width = canvas.width;+ sourceCanvas.height = canvas.height;+ const sourceCtx = sourceCanvas.getContext("2d");+ if (!sourceCtx) throw new Error("Could not get source canvas context");+ sourceCtx.drawImage(canvas, 0, 0);++ applyMaskAnnotations(ctx, sourceCanvas, annotations);+ drawAnnotations(ctx, annotations);++ const blob = await new Promise<Blob | null>((resolve) =>+ canvas.toBlob(resolve, "image/png"),+ );+ if (!blob) throw new Error("Failed to create blob");++ const buffer = await blob.arrayBuffer();+ const uint8Array = new Uint8Array(buffer);++ if (destination === "file") {+ const savePath = await save({+ filters: [{ name: "PNG Image", extensions: ["png"] }],+ defaultPath: "screenshot.png",+ });+ if (savePath) {+ await commands.writeFile(savePath, Array.from(uint8Array));+ toast.success("Screenshot saved!");+ setDialog({ ...dialog(), open: false });+ }+ } else {+ // Use the new copyImageToClipboard command+ // @ts-ignore - commands type might not be updated yet+ await commands.copyImageToClipboard(Array.from(uint8Array));+ toast.success("Screenshot copied to clipboard!");+ setDialog({ ...dialog(), open: false });+ }+ } catch (err) {+ console.error(err);+ toast.error("Failed to export");+ } finally {+ setIsExporting(false);+ }+ };++ return { exportImage, isExporting };+}diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex 918b3898e..e0e2b9435 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -89,6 +89,9 @@ async copyVideoToClipboard(path: string) : Promise<null> {async copyScreenshotToClipboard(path: string) : Promise<null> {return await TAURI_INVOKE("copy_screenshot_to_clipboard", { path });},+async copyImageToClipboard(data: number[]) : Promise<null> {+ return await TAURI_INVOKE("copy_image_to_clipboard", { data });+},async openFilePath(path: string) : Promise<null> {return await TAURI_INVOKE("open_file_path", { path });},diff --git a/crates/enc-mediafoundation/src/mft.rs b/crates/enc-mediafoundation/src/mft.rsindex 808a5cab6..530acccab 100644--- a/crates/enc-mediafoundation/src/mft.rs+++ b/crates/enc-mediafoundation/src/mft.rs@@ -21,10 +21,21 @@ pub struct EncoderDevice {impl EncoderDevice {pub fn enumerate(major_type: GUID, subtype: GUID) -> Result<Vec<EncoderDevice>> {- Self::enumerate_with_flags(+ let devices = Self::enumerate_with_flags(major_type,subtype,MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_TRANSCODE_ONLY | MFT_ENUM_FLAG_SORTANDFILTER,+ )?;++ if !devices.is_empty() {+ return Ok(devices);+ }++ // Fallback to software implementation if hardware encoding is not available+ Self::enumerate_with_flags(+ major_type,+ subtype,+ MFT_ENUM_FLAG_TRANSCODE_ONLY | MFT_ENUM_FLAG_SORTANDFILTER,)}diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex 4cd230eed..4f2ad9fc1 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -691,15 +691,14 @@ impl ProjectUniforms {basis as f64 * padding_factor}- pub fn get_output_size(+ pub fn get_base_size(options: &RenderOptions,project: &ProjectConfiguration,- resolution_base: XY<u32>,) -> (u32, u32) {let crop = Self::get_crop(options, project);let crop_aspect = crop.aspect_ratio();- let (base_width, base_height) = match &project.aspect_ratio {+ match &project.aspect_ratio {None => {let padding_basis = u32::max(crop.size.x, crop.size.y) as f64;let padding =@@ -744,7 +743,15 @@ impl ProjectUniforms {(crop.size.x, ((crop.size.x as f32 * 4.0 / 3.0) as u32))}}- };+ }+ }++ pub fn get_output_size(+ options: &RenderOptions,+ project: &ProjectConfiguration,+ resolution_base: XY<u32>,+ ) -> (u32, u32) {+ let (base_width, base_height) = Self::get_base_size(options, project);let width_scale = resolution_base.x as f32 / base_width as f32;let height_scale = resolution_base.y as f32 / base_height as f32;diff --git a/packages/ui-solid/icons/screenshot.svg b/packages/ui-solid/icons/screenshot.svgnew file mode 100644index 000000000..f5a9956bb--- /dev/null+++ b/packages/ui-solid/icons/screenshot.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" fill="white" width="800px" height="800px" viewBox="0 0 24 24"><path d="M21,2H3A1,1,0,0,0,2,3V21a1,1,0,0,0,1,1H21a1,1,0,0,0,1-1V3A1,1,0,0,0,21,2ZM20,14l-3-3-5,5-2-2L4,20V4H20ZM6,8.5A2.5,2.5,0,1,1,8.5,11,2.5,2.5,0,0,1,6,8.5Z"/></svg>\ No newline at end of filediff --git a/packages/ui-solid/src/auto-imports.d.ts b/packages/ui-solid/src/auto-imports.d.tsindex 6bf33b06f..930b3ac25 100644--- a/packages/ui-solid/src/auto-imports.d.ts+++ b/packages/ui-solid/src/auto-imports.d.ts@@ -30,6 +30,7 @@ declare global {const IconCapGear: typeof import('~icons/cap/gear.jsx')['default']const IconCapHotkeys: typeof import('~icons/cap/hotkeys.jsx')['default']const IconCapImage: typeof import('~icons/cap/image.jsx')['default']+ const IconCapImageFilled: typeof import('~icons/cap/image-filled.jsx')['default']const IconCapInfo: typeof import('~icons/cap/info.jsx')['default']const IconCapInstant: typeof import('~icons/cap/instant.jsx')['default']const IconCapLayout: typeof import('~icons/cap/layout.jsx')['default']@@ -52,6 +53,8 @@ declare global {const IconCapRedo: typeof import('~icons/cap/redo.jsx')['default']const IconCapRestart: typeof import('~icons/cap/restart.jsx')['default']const IconCapScissors: typeof import('~icons/cap/scissors.jsx')['default']+ const IconCapScreen: typeof import('~icons/cap/screen.jsx')['default']+ const IconCapScreenshot: typeof import('~icons/cap/screenshot.jsx')['default']const IconCapSettings: typeof import('~icons/cap/settings.jsx')['default']const IconCapShadow: typeof import('~icons/cap/shadow.jsx')['default']const IconCapSquare: typeof import('~icons/cap/square.jsx')['default']