delphifiremonkey

How to combine image filters in Firemonkey?


The TFilterHueAdjust only allows modiyfying the Hue of a bitmap. How can we update it to apply Saturation and Light (HSL?)

procedure AdjustHSL(Source, Dest: TBitmap; H, S, L: Single);
var
  Filter: TFilterHueAdjust;
begin
  Filter := TFilterHueAdjust.Create(nil);
  try
    Filter.Input := Source;
    Filter.Hue := H;
    Dest.Assign(Filter.Output);
  finally
    Filter.Free;
  end;
end;

I tried applying Brightness and Contrast seperately using TFilterContrast but changing it loses the Hue (seems only one filter can be applied at a time?).

Any ideas?

Thanks.


Solution

  • Use the InputFilter property to chain multiple filters, eg:

    procedure AdjustHSL(Source, Dest: TBitmap; H, S, L: Single);
    var
      HueFilter: TFilterHueAdjust;
      ContrastFilter: TFilterContrast;
    begin
      HueFilter := TFilterHueAdjust.Create(nil);
      try
        HueFilter.Input := Source;
        HueFilter.Hue := H;
        ContrastFilter := TFilterContrast.Create(nil);
        try
          ContrastFilter.InputFilter := HueFilter; // <--
          ContrastFilter.Brightness := L;
          Dest.Assign(ContrastFilter.Output);
        finally
          ContrastFilter.Free;
        end;
      finally
        HueFilter.Free;
      end;
    end;