优化缩略图

This commit is contained in:
Yeomai committed 2026-09-20 02:15:46 +08:00
1 parent 081520dbd9
commit fe4997f913
21 files changed
+128 -21

No files matched your search

+30 -6
View File
@@ -32,19 +32,35 @@ const ANIMATED_PRIORITIES = {
const DEFAULT_PRIORITY = 'resolution';
/**
* 可选的输出画布边长(正方形),界面上的下拉就是这两项。
*
* Eagle 缩略图网格里每格实际只显示 100–240px 左右,200 与 400 在这个尺寸下几乎看不出差别,
* 但像素数只有四分之一,体积能降约 4 倍。配置里写的细节分辨率超过所选边长时会被压下来,
* 所以同一份档位表在两种尺寸下都能用。
*/
const ANIMATED_OUTPUT_SIZES = [200, 400];
const DEFAULT_OUTPUT_SIZE = 200;
// 相邻锚点之间插多少个采样点。数值越大,越容易压在目标体积附近,但粗估阶段耗时略增。
const PATH_STEPS_PER_SEGMENT = 6;
function animatedProfiles(priority) {
function animatedProfiles(priority, outputSize) {
const limit = outputSize || DEFAULT_OUTPUT_SIZE;
const plan = ANIMATED_PRIORITIES[priority] || ANIMATED_PRIORITIES[DEFAULT_PRIORITY];
return plan.map(([size, fps, quality]) => ({ size, fps, quality }));
return plan.map(([size, fps, quality]) => ({
size: Math.min(size, limit),
fps,
quality,
}));
}
/**
* 把锚点路径插值成更密的采样路径,供按目标体积二分定位使用。
* 分辨率取整、帧率至少 1、质量保留两位小数;首尾锚点原样保留。
*/
function expandAnimatedPath(priority) {
function expandAnimatedPath(priority, outputSize) {
const limit = outputSize || DEFAULT_OUTPUT_SIZE;
const anchors = ANIMATED_PRIORITIES[priority] || ANIMATED_PRIORITIES[DEFAULT_PRIORITY];
const lerp = (from, to, t) => from + (to - from) * t;
const path = [];
@@ -54,15 +70,23 @@ function expandAnimatedPath(priority) {
for (let step = 0; step < PATH_STEPS_PER_SEGMENT; step++) {
const t = step / PATH_STEPS_PER_SEGMENT;
path.push({
size: Math.round(lerp(fromSize, toSize, t)),
size: Math.min(limit, Math.round(lerp(fromSize, toSize, t))),
fps: Math.max(1, Math.round(lerp(fromFps, toFps, t))),
quality: Math.round(lerp(fromQuality, toQuality, t) * 100) / 100,
});
}
}
const [size, fps, quality] = anchors[anchors.length - 1];
path.push({ size, fps, quality });
path.push({ size: Math.min(size, limit), fps, quality });
return path;
}
module.exports = { ANIMATED_PRIORITIES, DEFAULT_PRIORITY, PATH_STEPS_PER_SEGMENT, animatedProfiles, expandAnimatedPath };
module.exports = {
ANIMATED_PRIORITIES,
DEFAULT_PRIORITY,
ANIMATED_OUTPUT_SIZES,
DEFAULT_OUTPUT_SIZE,
PATH_STEPS_PER_SEGMENT,
animatedProfiles,
expandAnimatedPath,
};