diff options
Diffstat (limited to 'js/leibovitz/balance.js')
-rw-r--r-- | js/leibovitz/balance.js | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/js/leibovitz/balance.js b/js/leibovitz/balance.js index 6566176..73f60e8 100644 --- a/js/leibovitz/balance.js +++ b/js/leibovitz/balance.js @@ -1,11 +1,25 @@ -// BalanceManager handles white balance adjustments +/** + * White balance management module implementing temperature-based color adjustment + * Uses the Observer pattern for state management and effect application + * Implements a non-linear temperature adjustment algorithm with RGB channel scaling + * Uses a static class pattern for state management + */ + class BalanceManager { + /** + * Initializes the balance manager and sets up UI controls + * Implements the Factory pattern for UI initialization + */ static init() { this.balanceSlider = document.getElementById('balance-slider'); this.balanceValue = document.getElementById('balance-value'); this._setupEventListeners(); } + /** + * Sets up event listeners for UI controls + * Implements the Observer pattern for state changes + */ static _setupEventListeners() { this.balanceSlider.addEventListener('input', () => { const value = this.balanceSlider.value; @@ -13,10 +27,26 @@ class BalanceManager { }); } + /** + * Gets the current white balance temperature + * @returns {number} Current temperature in Kelvin (2000K-10000K) + */ static getCurrentBalance() { return parseInt(this.balanceSlider.value); } + /** + * Applies white balance adjustment to an image + * Implements temperature-based RGB channel scaling with non-linear response + * @param {ImageData} imageData - Source image data + * @returns {ImageData} White balanced image data + * + * Algorithm: + * 1. Convert temperature to ratio relative to neutral (6500K) + * 2. Apply non-linear scaling (0.2 factor) to red and blue channels + * 3. Warmer temps (<6500K) increase red, decrease blue + * 4. Cooler temps (>6500K) increase blue, decrease red + */ static applyBalance(imageData) { const balance = this.getCurrentBalance(); if (!balance || balance === 6500) return imageData; // 6500K is neutral |