abr00kx commited on
Commit
10a4c3d
·
verified ·
1 Parent(s): 8d6f4b6

Defringe, wider fringe range, linear colour denoise, cleanups

Browse files
Files changed (4) hide show
  1. README.md +1 -1
  2. js/app.js +5 -4
  3. js/renderer.js +20 -3
  4. sw.js +1 -1
README.md CHANGED
@@ -14,7 +14,7 @@ A fast photo editor that runs entirely in the browser. Photos are decoded, edite
14
 
15
  - **Open** JPEG, PNG and WebP by drag-and-drop, file picker or paste. Open several at once.
16
  - **Adjust** exposure, brightness, contrast, highlights, shadows, temperature, tint, saturation, vibrance, sharpen and vignette, or use Auto enhance.
17
- - **Clean up** noise with separate luminance and colour denoise, and correct lens colour fringing (lateral chromatic aberration) on the red/cyan and blue/yellow axes.
18
  - **Crop** freely or to social shapes (1:1, 4:5, 9:16, 16:9, 1.91:1, 2:3, 3:2, 4:3), rotate, flip and straighten.
19
  - **Filters**: fourteen colour presets applied as 3D LUTs, with a strength slider.
20
  - **Undo, redo and reset** per photo. Edits are non-destructive.
 
14
 
15
  - **Open** JPEG, PNG and WebP by drag-and-drop, file picker or paste. Open several at once.
16
  - **Adjust** exposure, brightness, contrast, highlights, shadows, temperature, tint, saturation, vibrance, sharpen and vignette, or use Auto enhance.
17
+ - **Clean up** noise with separate luminance and colour denoise, and correct lens colour fringing (lateral chromatic aberration) on the red/cyan and blue/yellow axes, plus a defringe pass for purple and green edges.
18
  - **Crop** freely or to social shapes (1:1, 4:5, 9:16, 16:9, 1.91:1, 2:3, 3:2, 4:3), rotate, flip and straighten.
19
  - **Filters**: fourteen colour presets applied as 3D LUTs, with a strength slider.
20
  - **Undo, redo and reset** per photo. Edits are non-destructive.
js/app.js CHANGED
@@ -14,7 +14,7 @@ const store = {
14
 
15
  // ---------------------------------------------------------------------------------------------- state
16
 
17
- const defAdj = () => ({ exposure: 0, brightness: 0, contrast: 0, highlights: 0, shadows: 0, temperature: 0, tint: 0, saturation: 0, vibrance: 0, sharpen: 0, denoise: 0, denoiseColor: 0, fringeRed: 0, fringeBlue: 0, vignette: 0 });
18
  const defGeom = () => ({ rot: 0, flipH: false, flipV: false, straighten: 0, crop: { x: 0, y: 0, w: 1, h: 1 }, ratio: 0, ratioKey: 'free' });
19
  const defState = () => ({ adj: defAdj(), filter: { id: 'none', amt: 100 }, geom: defGeom() });
20
 
@@ -384,6 +384,7 @@ const SLIDERS = [
384
  ['Lens', [
385
  { k: 'fringeRed', label: 'Fringe, red / cyan', track: 'linear-gradient(90deg,#e0524a,#8a8a8a,#3fb8c4)' },
386
  { k: 'fringeBlue', label: 'Fringe, blue / yellow', track: 'linear-gradient(90deg,#4a6ee0,#8a8a8a,#d9c33a)' },
 
387
  { k: 'vignette', label: 'Vignette', track: 'linear-gradient(90deg,#e6e6e6,#6a6a6a,#0c0c0c)' },
388
  ]],
389
  ];
@@ -405,7 +406,7 @@ function buildSliders() {
405
  if (s.track) input.style.setProperty('--track', s.track);
406
  const paint = () => {
407
  const v = +input.value;
408
- row.querySelector('output').textContent = (s.fmt || signed)(v);
409
  row.classList.toggle('changed', v !== 0);
410
  };
411
  input.addEventListener('input', () => { if (!ready()) return; cur.state.adj[s.k] = +input.value; paint(); render(); });
@@ -1148,5 +1149,5 @@ draw();
1148
 
1149
  if ('serviceWorker' in navigator && location.protocol === 'https:') navigator.serviceWorker.register('sw.js').catch(() => {});
1150
 
1151
- // Test hook for automated checks; harmless in normal use.
1152
- window.__fettle = { addFiles, docs, state: () => cur?.state, ready, renderer: r };
 
14
 
15
  // ---------------------------------------------------------------------------------------------- state
16
 
17
+ const defAdj = () => ({ exposure: 0, brightness: 0, contrast: 0, highlights: 0, shadows: 0, temperature: 0, tint: 0, saturation: 0, vibrance: 0, sharpen: 0, denoise: 0, denoiseColor: 0, fringeRed: 0, fringeBlue: 0, defringe: 0, vignette: 0 });
18
  const defGeom = () => ({ rot: 0, flipH: false, flipV: false, straighten: 0, crop: { x: 0, y: 0, w: 1, h: 1 }, ratio: 0, ratioKey: 'free' });
19
  const defState = () => ({ adj: defAdj(), filter: { id: 'none', amt: 100 }, geom: defGeom() });
20
 
 
384
  ['Lens', [
385
  { k: 'fringeRed', label: 'Fringe, red / cyan', track: 'linear-gradient(90deg,#e0524a,#8a8a8a,#3fb8c4)' },
386
  { k: 'fringeBlue', label: 'Fringe, blue / yellow', track: 'linear-gradient(90deg,#4a6ee0,#8a8a8a,#d9c33a)' },
387
+ { k: 'defringe', label: 'Defringe', min: 0, track: 'linear-gradient(90deg,#b04fc4,#4fb45a 45%,#777 80%)' },
388
  { k: 'vignette', label: 'Vignette', track: 'linear-gradient(90deg,#e6e6e6,#6a6a6a,#0c0c0c)' },
389
  ]],
390
  ];
 
406
  if (s.track) input.style.setProperty('--track', s.track);
407
  const paint = () => {
408
  const v = +input.value;
409
+ row.querySelector('output').textContent = (s.fmt || (min < 0 ? signed : String))(v);
410
  row.classList.toggle('changed', v !== 0);
411
  };
412
  input.addEventListener('input', () => { if (!ready()) return; cur.state.adj[s.k] = +input.value; paint(); render(); });
 
1149
 
1150
  if ('serviceWorker' in navigator && location.protocol === 'https:') navigator.serviceWorker.register('sw.js').catch(() => {});
1151
 
1152
+ // Hook for the automated checks, only when served from a development machine.
1153
+ if (location.hostname === 'localhost') window.__fettle = { addFiles, docs, state: () => cur?.state, ready, renderer: r };
js/renderer.js CHANGED
@@ -27,12 +27,14 @@ uniform float uSaturation, uVibrance, uSharpen, uVignette;
27
  uniform vec3 uWB;
28
  uniform vec2 uCA; // extra magnification for red and blue
29
  uniform vec2 uDenoise; // luminance, colour (0..1)
 
30
  uniform float uLutAmt, uLutSize;
31
  uniform float uSplit; // framebuffer x below which the original shows; negative = off
32
  uniform float uBypass; // 1 = show original colours everywhere
33
  uniform float uMatte; // 1 = flatten transparency onto white
34
 
35
  const vec3 W = vec3(0.2126, 0.7152, 0.0722);
 
36
 
37
  vec3 grade(vec3 c, vec2 vp) {
38
  // Exposure and white balance act on linear light.
@@ -124,7 +126,7 @@ void main() {
124
  float w = exp(-d * d * 40.0 - float(i * i + j * j) * 0.1);
125
  csum += (s - y) * w; wsum += w;
126
  }
127
- c = mix(c, vec3(dot(c, W)) + csum / wsum, min(1.0, uDenoise.y * 2.0));
128
  }
129
 
130
  if (uSharpen > 0.0) {
@@ -132,6 +134,20 @@ void main() {
132
  + fetch(src + vec2(0.0, uTexel.y), 0.0) + fetch(src - vec2(0.0, uTexel.y), 0.0);
133
  c += (raw - n * 0.25) * uSharpen;
134
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  c = grade(clamp(c, 0.0, 1.0), (uv - uVigRect.xy) / uVigRect.zw);
136
  }
137
  float a = px.a;
@@ -290,8 +306,9 @@ export class Renderer {
290
  gl.uniform1f(u.uSharpen, a.sharpen / 100 * 1.5);
291
  gl.uniform1f(u.uVignette, a.vignette / 100);
292
  gl.uniform2f(u.uDenoise, (a.denoise || 0) / 100, (a.denoiseColor || 0) / 100);
293
- // Full slider travel is 0.4% magnification, about 8 px at the edge of a 4000 px photo.
294
- gl.uniform2f(u.uCA, (a.fringeRed || 0) / 100 * 0.004, (a.fringeBlue || 0) / 100 * 0.004);
 
295
  // Warmer = more red, less blue; tint trades green against magenta. Gains are normalised to hold brightness.
296
  const t = a.temperature / 100, n = a.tint / 100;
297
  const g = [1 + 0.3 * t + 0.08 * n, 1 - 0.2 * n, 1 - 0.3 * t + 0.08 * n];
 
27
  uniform vec3 uWB;
28
  uniform vec2 uCA; // extra magnification for red and blue
29
  uniform vec2 uDenoise; // luminance, colour (0..1)
30
+ uniform float uDefringe;
31
  uniform float uLutAmt, uLutSize;
32
  uniform float uSplit; // framebuffer x below which the original shows; negative = off
33
  uniform float uBypass; // 1 = show original colours everywhere
34
  uniform float uMatte; // 1 = flatten transparency onto white
35
 
36
  const vec3 W = vec3(0.2126, 0.7152, 0.0722);
37
+ const vec2 RING[4] = vec2[4](vec2(1.0, 0.0), vec2(0.0, 1.0), vec2(0.7071, 0.7071), vec2(0.7071, -0.7071));
38
 
39
  vec3 grade(vec3 c, vec2 vp) {
40
  // Exposure and white balance act on linear light.
 
126
  float w = exp(-d * d * 40.0 - float(i * i + j * j) * 0.1);
127
  csum += (s - y) * w; wsum += w;
128
  }
129
+ c = mix(c, vec3(dot(c, W)) + csum / wsum, uDenoise.y);
130
  }
131
 
132
  if (uSharpen > 0.0) {
 
134
  + fetch(src + vec2(0.0, uTexel.y), 0.0) + fetch(src - vec2(0.0, uTexel.y), 0.0);
135
  c += (raw - n * 0.25) * uSharpen;
136
  }
137
+ // Defringe: at strong brightness edges, pull purple/magenta and green back to neutral.
138
+ // Other hues (sky blue, sunset orange) are left alone.
139
+ if (uDefringe > 0.0) {
140
+ float lo = Y0, hi = Y0;
141
+ for (int k = 0; k < 4; k++) {
142
+ float a = dot(fetch(src + RING[k] * uTexel * 3.0, 0.0), W);
143
+ float b = dot(fetch(src - RING[k] * uTexel * 3.0, 0.0), W);
144
+ lo = min(lo, min(a, b)); hi = max(hi, max(a, b));
145
+ }
146
+ float k = uDefringe * smoothstep(0.12, 0.4, hi - lo);
147
+ float mag = max(0.0, min(c.r, c.b) - c.g);
148
+ float grn = max(0.0, c.g - max(c.r, c.b));
149
+ c.r -= mag * k; c.b -= mag * k; c.g -= grn * k;
150
+ }
151
  c = grade(clamp(c, 0.0, 1.0), (uv - uVigRect.xy) / uVigRect.zw);
152
  }
153
  float a = px.a;
 
306
  gl.uniform1f(u.uSharpen, a.sharpen / 100 * 1.5);
307
  gl.uniform1f(u.uVignette, a.vignette / 100);
308
  gl.uniform2f(u.uDenoise, (a.denoise || 0) / 100, (a.denoiseColor || 0) / 100);
309
+ // Full slider travel is 1% magnification, about 20 px at the edge of a 4000 px photo.
310
+ gl.uniform2f(u.uCA, (a.fringeRed || 0) / 100 * 0.01, (a.fringeBlue || 0) / 100 * 0.01);
311
+ gl.uniform1f(u.uDefringe, (a.defringe || 0) / 100);
312
  // Warmer = more red, less blue; tint trades green against magenta. Gains are normalised to hold brightness.
313
  const t = a.temperature / 100, n = a.tint / 100;
314
  const g = [1 + 0.3 * t + 0.08 * n, 1 - 0.2 * n, 1 - 0.3 * t + 0.08 * n];
sw.js CHANGED
@@ -1,6 +1,6 @@
1
  // Keeps Fettle usable offline. Everything is stored on the first visit; after that the network is tried first,
2
  // so a new version is picked up as soon as you are online.
3
- const CACHE = 'fettle-v3';
4
  const FILES = [
5
  './', 'index.html', 'styles.css', 'icon.svg', 'manifest.webmanifest',
6
  'fonts/schibsted-grotesk-latin-wght-normal.woff2',
 
1
  // Keeps Fettle usable offline. Everything is stored on the first visit; after that the network is tried first,
2
  // so a new version is picked up as soon as you are online.
3
+ const CACHE = 'fettle-v4';
4
  const FILES = [
5
  './', 'index.html', 'styles.css', 'icon.svg', 'manifest.webmanifest',
6
  'fonts/schibsted-grotesk-latin-wght-normal.woff2',