type TImageChange = - 100..100; // (saves having to write valide the values) // based on ApplyLUT in G32_Filters unit { I've also had Hue and Luminance working, but cannot find any use for changing Hue, and Luminance just seems a very slow way of changing Brightness} procedure ApplyLUTs(Dst, Src: TBitmap32; const RedLUT, GreenLUT, BlueLUT: TLUT8; const Saturation: TImageChange); var i, ColorAv, ColorMax, ColorMin: Integer; DstPColor, SrcPColor: PColor32; RedVal, GreenVal, BlueVal: Cardinal; SrcColor: TColor32; sSaturation: Single; function ApplySaturation(ColorValue: Integer): Integer; begin Result := ColorAv + Round((ColorValue - ColorAv) * sSaturation); if Result < 0 then Result := 0 else if Result > 255 then Result := 255; end; begin if (Dst.Width <> Src.Width) or (Dst.Height <> Src.Height) then Exit; sSaturation := 1 + Saturation / 100; // apply LUTs, saturation DstPColor := @Dst.Bits[0]; SrcPColor := @Src.Bits[0]; if Saturation <> 0 then begin sSaturation := 1 + Saturation / 100; for i := 0 to Src.Width * Src.Height - 1 do begin SrcColor := SrcPColor^; // seperate the RGB values RedVal := SrcColor and $00FF0000; RedVal := RedVal shr 16; RedVal := RedLUT[RedVal]; GreenVal := SrcColor and $0000FF00; GreenVal := GreenVal shr 8; GreenVal := GreenLUT[GreenVal]; BlueVal := SrcColor and $000000FF; BlueVal := BlueLUT[BlueVal]; // Saturation ColorMax := Max(RedVal, Max(GreenVal, BlueVal)); ColorMin := Min(RedVal, Min(GreenVal, BlueVal)); if ColorMax <> ColorMin then begin ColorAv := (ColorMax + ColorMin) div 2; RedVal := ApplySaturation(RedVal); GreenVal := ApplySaturation(GreenVal); BlueVal := ApplySaturation(BlueVal); end; // build new color DstPColor^ := $FF000000 + RedVal shl 16 + GreenVal shl 8 + BlueVal; Inc(DstPColor); Inc(SrcPColor); end; end else // no need to apply saturation, which is slow for i := 0 to Src.Width * Src.Height - 1 do begin SrcColor := SrcPColor^; // seperate the RGB values RedVal := SrcColor and $00FF0000; RedVal := RedVal shr 16; RedVal := RedLUT[RedVal]; GreenVal := SrcColor and $0000FF00; GreenVal := GreenVal shr 8; GreenVal := GreenLUT[GreenVal]; BlueVal := SrcColor and $000000FF; BlueVal := BlueLUT[BlueVal]; // build new color DstPColor^ := $FF000000 + RedVal shl 16 + GreenVal shl 8 + BlueVal; Inc(DstPColor); Inc(SrcPColor); end; end;