Code Monkey home page Code Monkey logo

scoobie-doobie-effector's Introduction

This project was bootstrapped with Create React App.

スクービーウービードゥービーなウェブカメラエフェクター

https://okathira.github.io/scoobie-doobie-effector/

ウェブカメラを使います。映像やカメラ情報などの外部への送信は一切してないです。

React.App.-.Google.Chrome.2021-07-13.06-55-43.mp4

使用ライブラリ

MIT License Copyright (c) 2017 Anton Lavrenov

MIT License Copyright (c) 2018 Moz Morris

他はソースコード内

scoobie-doobie-effector's People

Contributors

okathira avatar

Stargazers

 avatar  avatar

Watchers

 avatar

scoobie-doobie-effector's Issues

範囲外でクリックし始めた・し終えたときの挙動

onMouseDown={() => {
setMouseDownPos(
getRelativePointerPosition(inputAreaRef) ?? { x: 0, y: 0 }
);
setDragging(true);
}}
onMouseUp={() => {
addBoxProps();
setDragging(false);
}}

範囲外でクリックし始めて範囲内でクリックし終えたときと、
範囲外でクリックし終えて範囲内でクリックし始めたときの
挙動を直す。

グレースケールの処理を軽くする

export const makeGrayscale = (image: ImageData) => {
const l = image.data.length / 4; // RGBA
for (let i = 0; i < l; i++) {
const grayscale =
image.data[i * 4 + 0] * 0.299 +
image.data[i * 4 + 1] * 0.587 +
image.data[i * 4 + 2] * 0.114;
const s = (grayscale * grayscale) / 255 / 255;
image.data[i * 4 + 0] = (s + 0.008) * 255;
image.data[i * 4 + 1] = (s + 0.014) * 255 + 1.9;
image.data[i * 4 + 2] = (s + 0.004) * 255;
}
};

ピクセルごと毎回計算しているため遅い
grayscale を 256 段階と考えれば、そこから求められる RGB 値の組み合わせも 256 個しかないためテーブル化やメモ化でどうにかできそう?

react-konva のコンポーネントに Context を渡せない

boxesProps: BoxProps[]; // TODO: コンテキストにするとレンダリングされないのを治す

const OutputArea: React.FC<{
layoutSize: RectSize;
baseCanvas: CanvasImageSource;
}> = ({ layoutSize, baseCanvas }) => {
// TODO: 子に渡しているだけのため消したい
const boxesProps = useBoxesProps();
return (
<Stage
className="output-area"
width={layoutSize.width}
height={layoutSize.height}
>
<Layer>
<Image image={baseCanvas} />
<ClippingBoxes currentFrame={baseCanvas} boxesProps={boxesProps} />
</Layer>
</Stage>
);
};

Context が常に初期値になってた

Context<canvas> を通らない
facebook/react#13336
facebook/react#13332 (comment)
Context<Layer> 以下のような dom に属さないコンポーネントまでたどり着かない

ブリッジさせるしかないらしい
konvajs/react-konva#188 (comment)
facebook/react#17275 (comment)

選択範囲をポインターの動きにリアルタイムで追従させる

<SelectionRect
beginPos={mouseDownPos}
endPos={getRelativePointerPosition(inputAreaRef) || { x: 0, y: 0 }}
// FIXME: endPosの更新タイミングで描画されず、baseCanvasの更新により描画されている。
/>

<SelectionRect> の描画更新タイミングを、ドラッグ中のマウスポインターに動きがあったときとしたい。

リサイズ中に枠線の大きさが変わる

onTransformEnd={() => {
// FIXME: 変形中は表示倍率を変更しているため枠線にも影響が出るのに対し、
// 変形後は枠線の幅が戻るため、結果を確認しながら操作ができなくなっている。
// transformerはnodeのscaleを変更し、widthとheightはそのまま。
// しかし、データの管理を容易にするため、変形終了時にスケールをリセットする。
const node = shapeRef.current!;
const scaleX = node.scaleX();
const scaleY = node.scaleY();
// もとに戻す
node.scaleX(1);
node.scaleY(1);
onChange({
...boxProps,
x: node.x(),
y: node.y(),
// 最小値を指定する
width: Math.max(minimumBoxSize, node.width() * scaleX),
height: Math.max(minimumBoxSize, node.height() * scaleY),
});
}}

グレイスケールの処理をCSSで置き換える

// グレイスケールならCSSでもできる。その場合はcanvasごとにフィルターがかかるため構造を変える必要がありそう。
export const makeGrayscale = (image: ImageData) => {
const l = image.data.length / 4;
for (let i = 0; i < l; i++) {
const grayscale =
image.data[i * 4 + 0] * 0.299 +
image.data[i * 4 + 1] * 0.587 +
image.data[i * 4 + 2] * 0.114;
image.data[i * 4 + 0] = grayscale;
image.data[i * 4 + 1] = grayscale;
image.data[i * 4 + 2] = grayscale;
}
};

const image = ctx.getImageData(0, 0, canvasSize.width, canvasSize.height);
makeGrayscale(image);
ctx.putImageData(image, 0, 0);

グレイスケールだけなら CSS の filter で高速に処理できる。
CSS は、 <canvas> となる <Konva.Stage> ごとにしかかけられないため、構造を考える必要がありそう。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.