mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
SVG mask
This commit is contained in:
parent
b44e9c7752
commit
b8bb46042c
77
frontend/src/assets/images/mask.svg
Normal file
77
frontend/src/assets/images/mask.svg
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg width="100%" height="100%" viewBox="0 0 60 60" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
<g transform="matrix(1,0,0,1,0,5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,10)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,15)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,20)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,25)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,30)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,35)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,40)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,45)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,50)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,55)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,60)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-10)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-15)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-20)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-25)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-30)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-35)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-40)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-45)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-50)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-55)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(1,0,0,1,0,-60)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB |
@ -8,7 +8,6 @@ import {
|
|||||||
InpaintingCanvasState,
|
InpaintingCanvasState,
|
||||||
OutpaintingCanvasState,
|
OutpaintingCanvasState,
|
||||||
} from './canvasSlice';
|
} from './canvasSlice';
|
||||||
import maskPatternImage from 'assets/images/mask_pattern2.png';
|
|
||||||
|
|
||||||
import { rgbaColorToString } from './util/colorToString';
|
import { rgbaColorToString } from './util/colorToString';
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
@ -32,6 +31,86 @@ export const canvasMaskCompositerSelector = createSelector(
|
|||||||
|
|
||||||
type IAICanvasMaskCompositerProps = RectConfig;
|
type IAICanvasMaskCompositerProps = RectConfig;
|
||||||
|
|
||||||
|
const getColoredSVG = (color: string) => {
|
||||||
|
return `data:image/svg+xml;utf8,<svg width="100%" height="100%" viewBox="0 0 30 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,0)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,2.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,7.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,10)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,12.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,15)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,17.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,20)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,22.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,25)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,27.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,30)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-2.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-7.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-10)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-12.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-15)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-17.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-20)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-22.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-25)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-27.5)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
<g transform="matrix(0.5,0,0,0.5,0,-30)">
|
||||||
|
<path d="M-3.5,63.5L64,-4" style="fill:none;stroke:black;stroke-width:1px;"/>
|
||||||
|
</g>
|
||||||
|
</svg>`.replaceAll('black', color);
|
||||||
|
};
|
||||||
|
|
||||||
const IAICanvasMaskCompositer = (props: IAICanvasMaskCompositerProps) => {
|
const IAICanvasMaskCompositer = (props: IAICanvasMaskCompositerProps) => {
|
||||||
const { ...rest } = props;
|
const { ...rest } = props;
|
||||||
|
|
||||||
@ -52,8 +131,6 @@ const IAICanvasMaskCompositer = (props: IAICanvasMaskCompositerProps) => {
|
|||||||
const incrementOffset = useCallback(() => {
|
const incrementOffset = useCallback(() => {
|
||||||
setOffset(offset + 1);
|
setOffset(offset + 1);
|
||||||
setTimeout(incrementOffset, 500);
|
setTimeout(incrementOffset, 500);
|
||||||
console.log('toggle');
|
|
||||||
console.log('incrementing');
|
|
||||||
}, [offset]);
|
}, [offset]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -63,14 +140,21 @@ const IAICanvasMaskCompositer = (props: IAICanvasMaskCompositerProps) => {
|
|||||||
image.onload = () => {
|
image.onload = () => {
|
||||||
setFillPatternImage(image);
|
setFillPatternImage(image);
|
||||||
};
|
};
|
||||||
|
image.src = getColoredSVG(maskColorString);
|
||||||
image.src = maskPatternImage;
|
}, [fillPatternImage, maskColorString]);
|
||||||
}, [fillPatternImage]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setInterval(() => setOffset((i) => (i + 1) % 6), 100);
|
if (!fillPatternImage) return;
|
||||||
|
fillPatternImage.src = getColoredSVG(maskColorString);
|
||||||
|
}, [fillPatternImage, maskColorString]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setInterval(
|
||||||
|
() => setOffset((i) => (i + 2) % Number(fillPatternImage?.width)),
|
||||||
|
100
|
||||||
|
);
|
||||||
return () => clearInterval(timer);
|
return () => clearInterval(timer);
|
||||||
}, []);
|
}, [fillPatternImage?.width]);
|
||||||
|
|
||||||
if (!fillPatternImage) return null;
|
if (!fillPatternImage) return null;
|
||||||
|
|
||||||
@ -84,7 +168,7 @@ const IAICanvasMaskCompositer = (props: IAICanvasMaskCompositerProps) => {
|
|||||||
fillPatternImage={fillPatternImage}
|
fillPatternImage={fillPatternImage}
|
||||||
fillPatternOffsetY={offset}
|
fillPatternOffsetY={offset}
|
||||||
fillPatternRepeat={'repeat'}
|
fillPatternRepeat={'repeat'}
|
||||||
fillPatternScale={{ x: 1 / stageScale, y: 1 / stageScale }}
|
fillPatternScale={{ x: 0.5 / stageScale, y: 0.5 / stageScale }}
|
||||||
listening={true}
|
listening={true}
|
||||||
opacity={maskOpacity}
|
opacity={maskOpacity}
|
||||||
globalCompositeOperation={'source-in'}
|
globalCompositeOperation={'source-in'}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user