A
download filterAdjust.pas
Language: Delphi
Copyright: (C) 2004 Durand Emmanuel (C) 2004 Burgel Eric
LOC: 75
Project Info
Filters
Server: SourceForge
Type: cvs
...ilters\Filters1\Src\Delphi\
   ...ractfilterNeighbor3.pas
   Chronometer.pas
   divers.pas
   filter.pas
   filterAdjust.pas
   filterArithmeticAdd.pas
   ...ithmeticConstantAdd.pas
   ...ArithmeticSubstract.pas
   filterBlobBalance.pas
   filterBlobExplorer.pas
   filterBlobGrouping.pas
   ...erBlobRepositioning.pas
   ...rBlobRepositioning2.pas
   filterBlur.pas
   filterCanny.pas
   filterContour.pas
   filterContrastExplorer.pas
   filterConvolution.pas
   filterCoocurenceMatrix.pas
   filterCopy.pas
   filterCorrelation.pas
   filterCutter.pas
   filterDistancesMap.pas
   filterExplorer.pas
   ...nisotropicDiffusion.pas
   ...GranularityExplorer.pas
   filterHistogram.pas
   ...erHistogramContrast.pas
   filterImageCreator.pas
   filterImageLoader.pas
   filterImageSaver.pas
   filterIntegration.pas
   filterInvert.pas
   filterLocalDeviation.pas
   filterLogPolar.pas
   filterMedian.pas
   filterMorphology.pas
   ...onMaximaSuppression.pas
   filterNormalize.pas
   filterOnOffCell.pas
   filterProjectionLine.pas
   filterPyramid.pas
   filterRescaleIntensity.pas
   filterResize.pas
   filterRotation.pas
   filterSigmoid.pas
   filterSmoothBilateral.pas
   filterSobel.pas
   filterSPV.pas
   filterStackProcessor.pas
   filterStackSmasher.pas
   ...erStandardDeviation.pas
   filterSUSAN.pas
   filterThresholdBinary.pas
   filterVectorHistogram.pas
   filterWavelets.pas
   filterWaves.pas
   fmask.pas
   fparameters.pas
   image.pas
   imageIO.pas
   imageIOVideo.pas
   lacModel.pas
   polygonalyzation.pas
   wrapper_itk.pas
   wrapper_opencv.pas

unit filterAdjust;
(* ***** BEGIN LICENSE BLOCK *****
 * Copyright (C) 2004 Durand Emmanuel
 * Copyright (C) 2004 Burgel Eric
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact :
 *   filters@edurand.com
 *   filters@burgel.com
 *
 * ***** END LICENSE BLOCK ***** *)

{
 edurand (filters@edurand.com)
 eburgel (filters@burgel.com)
}

interface
uses
  filter, fparameters, image;

type
  TFilterAdjust = class(TFilter)
  public
    constructor Create; override;
    procedure Run(); override;
  private
    parameterImageIn, parameterImageOut : TParameterImage;
    parameterBrightness : TParameterInteger ;
    parameterContrast : TParameterInteger ;
    parameterAutoAdjust : TParameterBoolean ;
    imgIn, imgOut : PBitmap32 ;
    procedure _run();
  end;

implementation
uses
  imageIO;

constructor TFilterAdjust.Create;
begin
  inherited;
  parameterImageIn:= addParameterImage('inImage', 'input image to invert');
  parameterImageOut:= addParameterImage('outImage', 'result image of invertion');
  parameterBrightness := addParameterInteger('Brightness', 'Brightness', -10000, 10000, 0) ;
  parameterContrast := addParameterInteger('Contrast', 'Contrast', 0, 20000, 10000) ;
  parameterAutoAdjust := addParameterBoolean('AutoAdjust', 'Automatic bright and contrast', false) ;
end;

procedure TFilterAdjust.Run();
begin
  imgIn  := parameterImageIn.Image ;
  imgOut := parameterImageOut.Image ;
  if (imgIn<>nil) and (imgOut<>nil) then begin
    _run();
  end;
end;

procedure TFilterAdjust._run();
var
  pSrc, PDest : PColor32Array;
  x, y, maxX, maxY : Integer ;
  color : integer ;
  red, green, blue : integer ;
  newRed, newGreen, newBlue, newColor : Integer ;
  a, b : integer ;
begin
  maxX := scanWidth(imgIn)-1 ;
  maxY := scanHeight(imgIn)-1 ;
  eraseImage(imgOut);
  a := parameterContrast.Value ;
  b := parameterBrightness.Value ;
  for y:=0 to maxY do begin
    pSrc := scanLine(imgIn, y) ;
    pDest := scanLine(imgOut, y) ;
    for x:=0 to maxX do begin
      color := pSrc^[0] and $00FFFFFF ;
      red := color shr 16 ;
      green := (color shr 8) and $FF ;
      blue := color and $FF ;
      // Red
      newRed := ((red-$80)*a) div $80 + $80 + b ;
      if newRed>255 then newRed := 255 else if newRed<0 then newRed := 0 ;
      // Green
      newGreen := ((green-$80)*a) div $80 + $80 + b ;
      if newGreen>255 then newGreen := 255 else if newGreen<0 then newGreen := 0 ;
      // Blue
      newBlue := ((blue-$80)*a) div $80 + $80 + b ;
      if newBlue>255 then newBlue := 255 else if newBlue<0 then newBlue := 0 ;
      
      newColor := (newRed shl 16) or (newGreen shl 8) or newBlue ;
      pDest^[0] :=
        (pSrc^[0] and $FF000000) +
        (newColor and $00FFFFFF);
      inc(pDest) ;
      inc(pSrc) ;
    end ;
  end ;
end;

end.

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us