Files
MajoorWaldi-ComfyUI-Majoor-…/js/preview/shared/canvas-pool.js
T
Ewald 068792c764 feat(color-correct): add zone-based color adjustment and soft brush drawing
- Implement global, shadows, midtones, and highlights zones for color correction
- Add brightness, contrast, saturation, vibrance, and gamma controls per zone
- Include temperature and tint adjustments with improved hue adjustment range
- Introduce soft brush drawing feature with adjustable softness
- Enhance draw tool with improved cursor feedback and eraser functionality
- Optimize performance with requestAnimationFrame for certain interactions
- Refactor color correction widget synchronization and reset logic
2026-04-24 23:52:41 +02:00

46 lines
1008 B
JavaScript

const POOL_MAX = 24;
const pool = [];
function clampDim(value) {
return Math.max(1, Math.round(value || 1));
}
function acquireCanvas(width, height) {
const w = clampDim(width);
const h = clampDim(height);
for (let i = pool.length - 1; i >= 0; i--) {
const c = pool[i];
if (c.width === w && c.height === h) {
pool.splice(i, 1);
return c;
}
}
const reused = pool.pop();
if (reused) {
if (reused.width !== w) reused.width = w;
if (reused.height !== h) reused.height = h;
return reused;
}
const fresh = document.createElement("canvas");
fresh.width = w;
fresh.height = h;
return fresh;
}
function releaseCanvas(canvas) {
if (!canvas) return;
if (pool.length >= POOL_MAX) return;
try {
const ctx = canvas.getContext("2d");
if (ctx) ctx.clearRect(0, 0, canvas.width, canvas.height);
} catch {
return;
}
pool.push(canvas);
}
function _poolSize() {
return pool.length;
}
export {
_poolSize,
acquireCanvas,
releaseCanvas
};