Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -208,125 +208,134 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 208 |
}
|
| 209 |
|
| 210 |
// カーブのインタラクションを設定
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
isDragging = true;
|
| 227 |
-
draggedPoint = point;
|
| 228 |
-
return;
|
| 229 |
-
}
|
| 230 |
-
}
|
| 231 |
|
| 232 |
-
|
| 233 |
-
if (x > 0 && x < 255 && y > 0 && y < 255) {
|
| 234 |
-
points.push({x, y});
|
| 235 |
-
points.sort((a, b) => a.x - b.x);
|
| 236 |
isDragging = true;
|
| 237 |
-
draggedPoint =
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
drawCurve(canvas, points, color);
|
| 241 |
-
if (canvas !== luminanceCurveCanvas) {
|
| 242 |
-
applyBtn.click();
|
| 243 |
}
|
| 244 |
-
}
|
| 245 |
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
// 境界チェック
|
| 254 |
-
x = Math.max(0, Math.min(255, x));
|
| 255 |
-
y = Math.max(0, Math.min(255, y));
|
| 256 |
-
|
| 257 |
-
// 最初と最後の点はx座標を固定
|
| 258 |
-
if (points.indexOf(draggedPoint) === 0) {
|
| 259 |
-
x = 0;
|
| 260 |
-
} else if (points.indexOf(draggedPoint) === points.length - 1) {
|
| 261 |
-
x = 255;
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
draggedPoint.x = x;
|
| 265 |
-
draggedPoint.y = y;
|
| 266 |
-
|
| 267 |
-
drawCurve(canvas, points, color);
|
| 268 |
-
if (canvas !== luminanceCurveCanvas) {
|
| 269 |
-
applyBtn.click();
|
| 270 |
-
}
|
| 271 |
-
});
|
| 272 |
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
if (
|
| 285 |
-
|
|
|
|
| 286 |
}
|
| 287 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
const
|
| 295 |
-
const
|
| 296 |
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
points.splice(i, 1);
|
| 303 |
-
drawCurve(canvas, points, color);
|
| 304 |
-
if (canvas !== luminanceCurveCanvas) {
|
| 305 |
-
applyBtn.click();
|
| 306 |
-
}
|
| 307 |
-
return;
|
| 308 |
-
}
|
| 309 |
}
|
| 310 |
-
}
|
| 311 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
// RGBカーブを適用
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
// カーブを適用
|
| 323 |
-
camanInstance.process("rgbCurve", function(rgba) {
|
| 324 |
-
rgba.r = redCurve[rgba.r];
|
| 325 |
-
rgba.g = greenCurve[rgba.g];
|
| 326 |
-
rgba.b = blueCurve[rgba.b];
|
| 327 |
-
return rgba;
|
| 328 |
-
});
|
| 329 |
-
}
|
| 330 |
|
| 331 |
// 輝度カーブを適用(連続的なシャドウ/ハイライト調整)
|
| 332 |
function applyLuminanceCurve() {
|
|
|
|
| 208 |
}
|
| 209 |
|
| 210 |
// カーブのインタラクションを設定
|
| 211 |
+
function setupCurveInteraction(canvas, points, color) {
|
| 212 |
+
let isDragging = false;
|
| 213 |
+
let draggedPoint = null;
|
| 214 |
+
let needsUpdate = false;
|
| 215 |
+
let updateTimeout = null;
|
| 216 |
+
|
| 217 |
+
canvas.addEventListener('mousedown', function(e) {
|
| 218 |
+
const rect = canvas.getBoundingClientRect();
|
| 219 |
+
const x = (e.clientX - rect.left) / rect.width * 255;
|
| 220 |
+
const y = 255 - (e.clientY - rect.top) / rect.height * 255;
|
| 221 |
+
|
| 222 |
+
// 既存の点をチェック
|
| 223 |
+
for (let i = 0; i < points.length; i++) {
|
| 224 |
+
const point = points[i];
|
| 225 |
+
const distance = Math.sqrt(Math.pow(point.x - x, 2) + Math.pow(point.y - y, 2));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
+
if (distance < 15) {
|
|
|
|
|
|
|
|
|
|
| 228 |
isDragging = true;
|
| 229 |
+
draggedPoint = point;
|
| 230 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
}
|
| 232 |
+
}
|
| 233 |
|
| 234 |
+
// 新しい点を追加
|
| 235 |
+
if (x > 0 && x < 255 && y > 0 && y < 255) {
|
| 236 |
+
points.push({x, y});
|
| 237 |
+
points.sort((a, b) => a.x - b.x);
|
| 238 |
+
isDragging = true;
|
| 239 |
+
draggedPoint = {x, y};
|
| 240 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
+
drawCurve(canvas, points, color);
|
| 243 |
+
needsUpdate = true;
|
| 244 |
+
});
|
| 245 |
+
|
| 246 |
+
canvas.addEventListener('mousemove', function(e) {
|
| 247 |
+
if (!isDragging || !draggedPoint) return;
|
| 248 |
+
|
| 249 |
+
const rect = canvas.getBoundingClientRect();
|
| 250 |
+
let x = (e.clientX - rect.left) / rect.width * 255;
|
| 251 |
+
let y = 255 - (e.clientY - rect.top) / rect.height * 255;
|
| 252 |
+
|
| 253 |
+
// 境界チェック
|
| 254 |
+
x = Math.max(0, Math.min(255, x));
|
| 255 |
+
y = Math.max(0, Math.min(255, y));
|
| 256 |
+
|
| 257 |
+
// 最初と最後の点はx座標を固定
|
| 258 |
+
if (points.indexOf(draggedPoint) === 0) {
|
| 259 |
+
x = 0;
|
| 260 |
+
} else if (points.indexOf(draggedPoint) === points.length - 1) {
|
| 261 |
+
x = 255;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
draggedPoint.x = x;
|
| 265 |
+
draggedPoint.y = y;
|
| 266 |
+
|
| 267 |
+
drawCurve(canvas, points, color);
|
| 268 |
+
needsUpdate = true;
|
| 269 |
|
| 270 |
+
// リアルタイムプレビュー更新(デバウンス付き)
|
| 271 |
+
if (updateTimeout) clearTimeout(updateTimeout);
|
| 272 |
+
updateTimeout = setTimeout(() => {
|
| 273 |
+
if (needsUpdate) {
|
| 274 |
+
applyFilters();
|
| 275 |
+
needsUpdate = false;
|
| 276 |
}
|
| 277 |
+
}, 200);
|
| 278 |
+
});
|
| 279 |
+
|
| 280 |
+
canvas.addEventListener('mouseup', function() {
|
| 281 |
+
isDragging = false;
|
| 282 |
+
draggedPoint = null;
|
| 283 |
+
if (needsUpdate) {
|
| 284 |
+
applyFilters();
|
| 285 |
+
needsUpdate = false;
|
| 286 |
+
}
|
| 287 |
+
});
|
| 288 |
+
|
| 289 |
+
canvas.addEventListener('mouseleave', function() {
|
| 290 |
+
isDragging = false;
|
| 291 |
+
draggedPoint = null;
|
| 292 |
+
if (needsUpdate) {
|
| 293 |
+
applyFilters();
|
| 294 |
+
needsUpdate = false;
|
| 295 |
+
}
|
| 296 |
+
});
|
| 297 |
+
|
| 298 |
+
// ポイントを削除するダブルクリック
|
| 299 |
+
canvas.addEventListener('dblclick', function(e) {
|
| 300 |
+
if (points.length <= 2) return;
|
| 301 |
|
| 302 |
+
const rect = canvas.getBoundingClientRect();
|
| 303 |
+
const x = (e.clientX - rect.left) / rect.width * 255;
|
| 304 |
+
const y = 255 - (e.clientY - rect.top) / rect.height * 255;
|
| 305 |
+
|
| 306 |
+
for (let i = 1; i < points.length - 1; i++) {
|
| 307 |
+
const point = points[i];
|
| 308 |
+
const distance = Math.sqrt(Math.pow(point.x - x, 2) + Math.pow(point.y - y, 2));
|
| 309 |
|
| 310 |
+
if (distance < 15) {
|
| 311 |
+
points.splice(i, 1);
|
| 312 |
+
drawCurve(canvas, points, color);
|
| 313 |
+
applyFilters();
|
| 314 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
}
|
| 316 |
+
}
|
| 317 |
+
});
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
function applyFilters() {
|
| 321 |
+
if (!camanInstance) return;
|
| 322 |
+
|
| 323 |
+
// ローディング表示なしで直接適用
|
| 324 |
+
camanInstance.revert(false);
|
| 325 |
+
|
| 326 |
+
// 基本調整
|
| 327 |
+
camanInstance.brightness(parseInt(brightnessSlider.value));
|
| 328 |
+
camanInstance.contrast(parseInt(contrastSlider.value) * 1.5);
|
| 329 |
+
camanInstance.saturation(parseInt(saturationSlider.value));
|
| 330 |
|
| 331 |
// RGBカーブを適用
|
| 332 |
+
applyRgbCurves();
|
| 333 |
+
|
| 334 |
+
// 輝度カーブを適用
|
| 335 |
+
applyLuminanceCurve();
|
| 336 |
+
|
| 337 |
+
camanInstance.render();
|
| 338 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
// 輝度カーブを適用(連続的なシャドウ/ハイライト調整)
|
| 341 |
function applyLuminanceCurve() {
|