// BalanceManager handles white balance adjustments class BalanceManager { static init() { this.balanceSlider = document.getElementById('balance-slider'); this.balanceValue = document.getElementById('balance-value'); this._setupEventListeners(); } static _setupEventListeners() { this.balanceSlider.addEventListener('input', () => { const value = this.balanceSlider.value; this.balanceValue.textContent = `${value}K`; }); } static getCurrentBalance() { return parseInt(this.balanceSlider.value); } static applyBalance(imageData) { const balance = this.getCurrentBalance(); if (!balance || balance === 6500) return imageData; // 6500K is neutral const data = imageData.data; const temperature = balance / 6500; // Convert to temperature ratio for (let i = 0; i < data.length; i += 4) { // Adjust red and blue channels based on temperature // Warmer (lower K) increases red, decreases blue // Cooler (higher K) increases blue, decreases red data[i] = Math.min(255, data[i] * (1 + (temperature - 1) * 0.2)); // Red data[i + 2] = Math.min(255, data[i + 2] * (1 + (1 - temperature) * 0.2)); // Blue } return imageData; } }