Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| isp:brightness [2023/09/10 19:16] – [In RGB color space] Igor Yefmov | isp:brightness [2023/09/10 21:49] (current) – [Calculation reference] Igor Yefmov | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| ==== Algorithm ==== | ==== Algorithm ==== | ||
| - | Here's the algorithm to follow, assuming \(R, G, B \in [0..4095] and br \in [-1024..+1023]\): | + | Here's the algorithm to follow, assuming \(R, G, B \in [0..4095]\) and \(br \in [-1024..+1023]\): |
| - calculate luminosity | - calculate luminosity | ||
| - | - figure out the slope for each components based on whether luma is below or above 50% | + | |
| - | - figure out if the new luma is going to cross the 50% boundary | + | |
| - | - if luma does cross the 50% boundary figure out the knee point' | + | - figure out if the new luma is going to cross the 50% boundary |
| - | | + | |
| - | - just adjust the brightness additively and clamp the value to range \([0..4095]\) | + | |
| - recalculate RGB components | - recalculate RGB components | ||
| Line 22: | Line 20: | ||
| To calculate luminosity we just find the max and min of the triplet and get a simple average: | To calculate luminosity we just find the max and min of the triplet and get a simple average: | ||
| \[L = \frac{min(R, | \[L = \frac{min(R, | ||
| + | |||
| + | Brightness adjustment is a trivial addition, clamping the value to its proper limits: | ||
| + | |||
| + | \[ | ||
| + | L` = L + br \\ | ||
| + | L` \in [0..4095] | ||
| + | \] | ||
| The slope \(k_R\) for the red component calculation depends on whether \(L\) is above or below the middle: | The slope \(k_R\) for the red component calculation depends on whether \(L\) is above or below the middle: | ||
| Line 28: | Line 33: | ||
| \begin{cases} | \begin{cases} | ||
| R / L & \text{if} \; L \leq 2047 \\ | R / L & \text{if} \; L \leq 2047 \\ | ||
| - | \frac{R - 2047}{L - 2047} & \text{if} \; L > 2047 | + | \frac{R - 4095}{L - 4095} & \text{if} \; L > 2047 |
| \end{cases} | \end{cases} | ||
| \] | \] | ||
| - | Brightness adjustment is a trivial addition, clamping | + | Finding |
| + | \[ | ||
| + | R = | ||
| + | \begin{cases} | ||
| + | k_R * 2047 & \text{if} \; L \leq 2047 \\ | ||
| + | 4095 - k_R * 2047 & \text{if} \; L > 2047 | ||
| + | \end{cases} | ||
| + | \] | ||
| + | If we are crossing the middle luma boundary as the result of this adjustment - flip the slope: | ||
| \[ | \[ | ||
| - | L` = L + br \\ | + | k_R = 2 - k_R |
| - | L` \in [0..4095] | + | |
| \] | \] | ||