Handling image color transforms directly in the browser saves round-trip latency and lets users preview adjustments instantly before committing to server-side AI passes.
Two common pixel-level operations—film negative inversion and brand logo recoloring—look simple on paper but have subtle edge cases in practice.
1. Film Negative Inversion Without Clipping Highlights
A naive 255 - channel inversion works for grayscale scans, but 35mm color negatives carry an orange mask base that shifts skin tones toward cyan if you invert each channel uniformly.
function invertNegativeBuffer ( imageData , orangeMask = { r : 245 , g : 195 , b : 155 } ) { const d = imageData . data ; for ( let i = 0 ; i < d . length ; i += 4 ) { d [ i ] = Math . min ( 255 , Math . max ( 0 , 255 - ( d [ i ] * 255 ) / orangeMask . r ) ) ; d [ i + 1 ] = Math . min ( 255 , Math . max ( 0 , 255 - ( d [ i + 1 ] * 255 ) / orangeMask . g ) ) ; d [ i + 2 ] = Math . min ( 255 , Math . max ( 0 , 255 - ( d [ i + 2 ] * 255 ) / orangeMask .…