import { getImageProperties , getBlob } from '../utils/canvas' ; import { Effects } from './const' ; import { isAnyEffectSet , transformValueToRange } from './mapDataManipulationUtils' ; import { runGainEffectFunction , runGammaEffectFunction , runColorEffectFunction , runCustomEffectFunction , } from './effectFunctions' ; export async function runEffectFunctions ( originalBlob , effects ) { if ( ! isAnyEffectSet ( effects ) ) { return originalBlob ; } const { rgba , width , height , format } = await getImageProperties ( originalBlob ) ; let rgbaArray = new Array ( rgba . length ) ; for ( let i = 0 ; i < rgba . length ; i ++ ) { rgbaArray [ i ] = transformValueToRange ( rgba [ i ] , 0 , 255 , 0 , 1 ) ; } rgbaArray = runGainEffectFunction ( rgbaArray , effects ) ; rgbaArray = runGammaEffectFunction ( rgbaArray , effects ) ; rgbaArray = runColorEffectFunction ( rgbaArray , effects ) ; rgbaArray = runCustomEffectFunction ( rgbaArray , effects ) ; const newImgData = new Uint8ClampedArray ( rgbaArray . length ) ; for ( let i = 0 ; i < rgbaArray . length ; i ++ ) { newImgData [ i ] = transformValueToRange ( rgbaArray [ i ] , 0 , 1 , 0 , 255 ) ; } const newBlob = await getBlob ( { rgba : newImgData , width , height , format } ) ; return newBlob ; }