soiz1 commited on
Commit
775036b
·
verified ·
1 Parent(s): 291c76b

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +116 -107
script.js CHANGED
@@ -208,125 +208,134 @@ document.addEventListener('DOMContentLoaded', function() {
208
  }
209
 
210
  // カーブのインタラクションを設定
211
- function setupCurveInteraction(canvas, points, color) {
212
- let isDragging = false;
213
- let draggedPoint = null;
214
-
215
- canvas.addEventListener('mousedown', function(e) {
216
- const rect = canvas.getBoundingClientRect();
217
- const x = (e.clientX - rect.left) / rect.width * 255;
218
- const y = 255 - (e.clientY - rect.top) / rect.height * 255;
219
-
220
- // 既存の点をチェック
221
- for (let i = 0; i < points.length; i++) {
222
- const point = points[i];
223
- const distance = Math.sqrt(Math.pow(point.x - x, 2) + Math.pow(point.y - y, 2));
224
-
225
- if (distance < 15) {
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 = {x, y};
238
- }
239
-
240
- drawCurve(canvas, points, color);
241
- if (canvas !== luminanceCurveCanvas) {
242
- applyBtn.click();
243
  }
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
- if (canvas !== luminanceCurveCanvas) {
269
- applyBtn.click();
270
- }
271
- });
272
 
273
- canvas.addEventListener('mouseup', function() {
274
- isDragging = false;
275
- draggedPoint = null;
276
- if (canvas === luminanceCurveCanvas) {
277
- applyBtn.click();
278
- }
279
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
 
281
- canvas.addEventListener('mouseleave', function() {
282
- isDragging = false;
283
- draggedPoint = null;
284
- if (canvas === luminanceCurveCanvas && isDragging) {
285
- applyBtn.click();
 
286
  }
287
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
 
289
- // ポイントを削除するダブルクリック
290
- canvas.addEventListener('dblclick', function(e) {
291
- if (points.length <= 2) return;
292
-
293
- const rect = canvas.getBoundingClientRect();
294
- const x = (e.clientX - rect.left) / rect.width * 255;
295
- const y = 255 - (e.clientY - rect.top) / rect.height * 255;
296
 
297
- for (let i = 1; i < points.length - 1; i++) {
298
- const point = points[i];
299
- const distance = Math.sqrt(Math.pow(point.x - x, 2) + Math.pow(point.y - y, 2));
300
-
301
- if (distance < 15) {
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
- function applyRgbCurves() {
315
- if (!camanInstance) return;
316
-
317
- // カーブデータを準備
318
- const redCurve = createCurveData(redCurvePoints);
319
- const greenCurve = createCurveData(greenCurvePoints);
320
- const blueCurve = createCurveData(blueCurvePoints);
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() {