soiz1 commited on
Commit
f189ea4
·
verified ·
1 Parent(s): c02d10d

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +63 -21
script.js CHANGED
@@ -101,32 +101,74 @@ document.addEventListener('DOMContentLoaded', function() {
101
  };
102
 
103
  // フィルターを適用する関数
104
- const applyFilters = function() {
105
- if (!camanInstance || isApplyingFilters) return;
 
 
 
 
 
106
 
107
- isApplyingFilters = true;
 
 
 
108
 
109
- try {
110
- camanInstance.revert(false);
111
-
112
- // 基本調整を直接適用
113
- camanInstance.brightness(parseInt(brightnessSlider.value));
114
- camanInstance.contrast(parseInt(contrastSlider.value) * 1.5);
115
- camanInstance.saturation(parseInt(saturationSlider.value));
116
 
117
- // カーブ調整のみレイヤー処理
118
- camanInstance.newLayer(function() {
119
- applyRgbCurves.call(camanInstance);
120
- applyLuminanceCurve.call(camanInstance);
 
121
  });
 
 
 
 
 
 
 
122
 
123
- camanInstance.render();
124
- } catch (e) {
125
- console.error("Error applying filters:", e);
126
- } finally {
127
- isApplyingFilters = false;
128
- }
129
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  // カーブを描画する関数
132
  const drawCurve = function(canvas, points, color) {
 
101
  };
102
 
103
  // フィルターを適用する関数
104
+ const applyFilters = function() {
105
+ if (!camanInstance || isApplyingFilters) return;
106
+
107
+ isApplyingFilters = true;
108
+
109
+ try {
110
+ camanInstance.revert(false);
111
 
112
+ // 基本調整を適用
113
+ camanInstance.brightness(parseInt(brightnessSlider.value));
114
+ camanInstance.contrast(parseInt(contrastSlider.value) * 1.5);
115
+ camanInstance.saturation(parseInt(saturationSlider.value));
116
 
117
+ // RGBカーブ調整を適用
118
+ const applyRgbCurves = function() {
119
+ const redCurve = createCurveData(redCurvePoints);
120
+ const greenCurve = createCurveData(greenCurvePoints);
121
+ const blueCurve = createCurveData(blueCurvePoints);
 
 
122
 
123
+ this.process("rgbCurve", function(rgba) {
124
+ rgba.r = redCurve[rgba.r];
125
+ rgba.g = greenCurve[rgba.g];
126
+ rgba.b = blueCurve[rgba.b];
127
+ return rgba;
128
  });
129
+ };
130
+
131
+ // 輝度カーブ調整を適用
132
+ const applyLuminanceCurve = function() {
133
+ const luminanceCurve = createCurveData(luminanceCurvePoints);
134
+ const shadowAmount = parseInt(shadowsSlider.value);
135
+ const highlightAmount = parseInt(highlightsSlider.value);
136
 
137
+ this.process("luminanceAdjustment", function(rgba) {
138
+ const luminance = 0.299 * rgba.r + 0.587 * rgba.g + 0.114 * rgba.b;
139
+ const normalizedLum = luminance / 255;
140
+
141
+ // カーブ調整
142
+ const curveAdjustment = (luminanceCurve[luminance] - luminance);
143
+
144
+ // シャドウ調整(低輝度ほど強く適用)
145
+ const shadowAdjust = shadowAmount * (1 - normalizedLum);
146
+
147
+ // ハイライト調整(高輝度ほど強く適用)
148
+ const highlightAdjust = highlightAmount * normalizedLum;
149
+
150
+ // 合計調整量
151
+ const totalAdjust = curveAdjustment + shadowAdjust + highlightAdjust;
152
+
153
+ rgba.r = Math.min(255, Math.max(0, rgba.r + totalAdjust));
154
+ rgba.g = Math.min(255, Math.max(0, rgba.g + totalAdjust));
155
+ rgba.b = Math.min(255, Math.max(0, rgba.b + totalAdjust));
156
+
157
+ return rgba;
158
+ });
159
+ };
160
+
161
+ // カーブ調整を適用
162
+ applyRgbCurves.call(camanInstance);
163
+ applyLuminanceCurve.call(camanInstance);
164
+
165
+ camanInstance.render();
166
+ } catch (e) {
167
+ console.error("Error applying filters:", e);
168
+ } finally {
169
+ isApplyingFilters = false;
170
+ }
171
+ };
172
 
173
  // カーブを描画する関数
174
  const drawCurve = function(canvas, points, color) {