mirror of
https://github.com/ful1e5/Bibata_Cursor.git
synced 2025-06-01 23:58:30 -04:00
✨ Auto match image pixel
This commit is contained in:
parent
f57f1b2974
commit
e0a4276a5a
2 changed files with 16 additions and 19 deletions
|
@ -7,20 +7,11 @@ import ColoredSvgGenerator, {
|
||||||
Cursors,
|
Cursors,
|
||||||
ThemeConfig
|
ThemeConfig
|
||||||
} from "./SvgHandler/ColoredSvgGenerator";
|
} from "./SvgHandler/ColoredSvgGenerator";
|
||||||
import { Frames, PixelDiffRate } from "./types";
|
import { Frames } from "./types";
|
||||||
import { getFrameName } from "./utils/getFrameName";
|
import { getFrameName } from "./utils/getFrameName";
|
||||||
import { generateRenderTemplate } from "./utils/htmlTemplate";
|
import { generateRenderTemplate } from "./utils/htmlTemplate";
|
||||||
import { matchImages } from "./utils/matchImages";
|
import { matchImages } from "./utils/matchImages";
|
||||||
|
|
||||||
const pixelDiffRate: PixelDiffRate = {
|
|
||||||
left_ptr_watch: {
|
|
||||||
rate: 100
|
|
||||||
},
|
|
||||||
wait: {
|
|
||||||
rate: 990
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export class BitmapsGenerator {
|
export class BitmapsGenerator {
|
||||||
private readonly staticCurs: Cursors;
|
private readonly staticCurs: Cursors;
|
||||||
private readonly animatedCurs: Cursors;
|
private readonly animatedCurs: Cursors;
|
||||||
|
@ -159,19 +150,18 @@ export class BitmapsGenerator {
|
||||||
omitBackground: true,
|
omitBackground: true,
|
||||||
encoding: "binary"
|
encoding: "binary"
|
||||||
});
|
});
|
||||||
|
const matched = matchImages({
|
||||||
const diff = matchImages({
|
|
||||||
img1Buff: frames[firstFrame].buffer,
|
img1Buff: frames[firstFrame].buffer,
|
||||||
img2Buff: newFrame
|
img2Buff: newFrame
|
||||||
});
|
});
|
||||||
|
|
||||||
const { rate } = pixelDiffRate[cursor];
|
if (matched) {
|
||||||
if (!(diff < rate)) {
|
|
||||||
frames[key] = { buffer: newFrame };
|
|
||||||
} else {
|
|
||||||
breakRendering = true;
|
breakRendering = true;
|
||||||
|
} else {
|
||||||
|
frames[key] = { buffer: newFrame };
|
||||||
|
setTimeout(() => {}, 1);
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,21 @@ interface MatchImagesArgs {
|
||||||
img2Buff: Buffer;
|
img2Buff: Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const matchImages = ({ img1Buff, img2Buff }: MatchImagesArgs) => {
|
export const matchImages = ({
|
||||||
|
img1Buff,
|
||||||
|
img2Buff
|
||||||
|
}: MatchImagesArgs): boolean => {
|
||||||
const img1 = PNG.sync.read(img1Buff);
|
const img1 = PNG.sync.read(img1Buff);
|
||||||
const img2 = PNG.sync.read(img2Buff);
|
const img2 = PNG.sync.read(img2Buff);
|
||||||
const { width, height } = img1;
|
const { width, height } = img1;
|
||||||
|
|
||||||
const diff = new PNG({ width, height });
|
const diff = new PNG({ width, height });
|
||||||
|
|
||||||
return pixelmatch(img1.data, img2.data, diff.data, width, height, {
|
const value = pixelmatch(img1.data, img2.data, diff.data, width, height, {
|
||||||
threshold: 0.25
|
threshold: 0.25
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(value);
|
||||||
|
if (value <= 400) return true;
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue