Ignore:
Timestamp:
Apr 17, 2019, 10:42:18 AM (5 years ago)
Author:
chronos
Message:
  • Modified: Updated Graphics32 library.
Location:
GraphicTest/Packages/Graphics32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/Graphics32

    • Property svn:ignore set to
      lib
  • GraphicTest/Packages/Graphics32/GR32_Resamplers.pas

    r450 r522  
    5050{$ENDIF}
    5151  Classes, SysUtils, GR32, GR32_Transforms, GR32_Containers,
    52   GR32_OrdinalMaps, GR32_Blend, GR32_System, GR32_Bindings;
     52  GR32_OrdinalMaps, GR32_Blend;
    5353
    5454procedure BlockTransfer(
     
    343343    procedure SetKernel(const Value: TCustomKernel);
    344344    function GetKernelClassName: string;
    345     procedure SetKernelClassName(Value: string);
     345    procedure SetKernelClassName(const Value: string);
    346346    procedure SetKernelMode(const Value: TKernelMode);
    347347    procedure SetTableSize(Value: Integer);
     
    578578procedure IncBuffer(var Buffer: TBufferEntry; Color: TColor32); {$IFDEF USEINLINING} inline; {$ENDIF}
    579579procedure MultiplyBuffer(var Buffer: TBufferEntry; W: Integer); {$IFDEF USEINLINING} inline; {$ENDIF}
    580 function BufferToColor32(Buffer: TBufferEntry; Shift: Integer): TColor32; {$IFDEF USEINLINING} inline; {$ENDIF}
     580function BufferToColor32(const Buffer: TBufferEntry; Shift: Integer): TColor32; {$IFDEF USEINLINING} inline; {$ENDIF}
    581581procedure ShrBuffer(var Buffer: TBufferEntry; Shift: Integer); {$IFDEF USEINLINING} inline; {$ENDIF}
     582
     583{ Downsample byte map }
     584procedure DownsampleByteMap2x(Source, Dest: TByteMap);
     585procedure DownsampleByteMap3x(Source, Dest: TByteMap);
     586procedure DownsampleByteMap4x(Source, Dest: TByteMap);
    582587
    583588{ Registration routines }
     
    605610
    606611uses
    607   GR32_LowLevel, GR32_Rasterizers, GR32_Math, Math;
     612  GR32_System, GR32_Bindings, GR32_LowLevel, GR32_Rasterizers, GR32_Math,
     613  GR32_Gamma, Math;
    608614
    609615resourcestring
     
    611617
    612618const
    613   CAlbrecht2    : array [0..1] of Double = (5.383553946707251E-1, 4.616446053292749E-1);
    614   CAlbrecht3    : array [0..2] of Double = (3.46100822018625E-1,  4.97340635096738E-1,
    615                                             1.56558542884637E-1);
    616   CAlbrecht4    : array [0..3] of Double = (2.26982412792069E-1,  4.57254070828427E-1,
    617                                             2.73199027957384E-1,  4.25644884221201E-2);
    618   CAlbrecht5    : array [0..4] of Double = (1.48942606015830E-1,  3.86001173639176E-1,
    619                                             3.40977403214053E-1,  1.139879604246E-1,
    620                                             1.00908567063414E-2);
    621   CAlbrecht6    : array [0..5] of Double = (9.71676200107429E-2,  3.08845222524055E-1,
    622                                             3.62623371437917E-1,  1.88953325525116E-1,
    623                                             4.02095714148751E-2,  2.20088908729420E-3);
    624   CAlbrecht7    : array [0..6] of Double = (6.39644241143904E-2,  2.39938645993528E-1,
    625                                             3.50159563238205E-1,  2.47741118970808E-1,
    626                                             8.54382560558580E-2,  1.23202033692932E-2,
    627                                             4.37788257917735E-4);
    628   CAlbrecht8    : array [0..7] of Double = (4.21072107042137E-2,  1.82076226633776E-1,
    629                                             3.17713781059942E-1,  2.84438001373442E-1,
    630                                             1.36762237777383E-1,  3.34038053504025E-2,
    631                                             3.41677216705768E-3,  8.19649337831348E-5);
    632   CAlbrecht9    : array [0..8] of Double = (2.76143731612611E-2,  1.35382228758844E-1,
    633                                             2.75287234472237E-1,  2.98843335317801E-1,
    634                                             1.85319330279284E-1,  6.48884482549063E-2,
    635                                             1.17641910285655E-2,  8.85987580106899E-4,
    636                                             1.48711469943406E-5);
    637   CAlbrecht10   : array [0..9] of Double = (1.79908225352538E-2,  9.87959586065210E-2,
    638                                             2.29883817001211E-1,  2.94113019095183E-1,
    639                                             2.24338977814325E-1,  1.03248806248099E-1,
    640                                             2.75674109448523E-2,  3.83958622947123E-3,
    641                                             2.18971708430106E-4,  2.62981665347889E-6);
    642   CAlbrecht11  : array [0..10] of Double = (1.18717127796602E-2,  7.19533651951142E-2,
    643                                             1.87887160922585E-1,  2.75808174097291E-1,
    644                                             2.48904243244464E-1,  1.41729867200712E-1,
    645                                             5.02002976228256E-2,  1.04589649084984E-2,
    646                                             1.13615112741660E-3,  4.96285981703436E-5,
    647                                             4.34303262685720E-7);
     619  CAlbrecht2 : array [0..1] of Double = (5.383553946707251E-1,
     620    4.616446053292749E-1);
     621  CAlbrecht3 : array [0..2] of Double = (3.46100822018625E-1,
     622    4.97340635096738E-1, 1.56558542884637E-1);
     623  CAlbrecht4 : array [0..3] of Double = (2.26982412792069E-1,
     624    4.57254070828427E-1, 2.73199027957384E-1, 4.25644884221201E-2);
     625  CAlbrecht5 : array [0..4] of Double = (1.48942606015830E-1,
     626    3.86001173639176E-1, 3.40977403214053E-1, 1.139879604246E-1,
     627    1.00908567063414E-2);
     628  CAlbrecht6 : array [0..5] of Double = (9.71676200107429E-2,
     629    3.08845222524055E-1, 3.62623371437917E-1, 1.88953325525116E-1,
     630    4.02095714148751E-2, 2.20088908729420E-3);
     631  CAlbrecht7 : array [0..6] of Double = (6.39644241143904E-2,
     632    2.39938645993528E-1, 3.50159563238205E-1, 2.47741118970808E-1,
     633    8.54382560558580E-2, 1.23202033692932E-2, 4.37788257917735E-4);
     634  CAlbrecht8 : array [0..7] of Double = (4.21072107042137E-2,
     635    1.82076226633776E-1, 3.17713781059942E-1, 2.84438001373442E-1,
     636    1.36762237777383E-1, 3.34038053504025E-2, 3.41677216705768E-3,
     637    8.19649337831348E-5);
     638  CAlbrecht9 : array [0..8] of Double = (2.76143731612611E-2,
     639    1.35382228758844E-1, 2.75287234472237E-1, 2.98843335317801E-1,
     640    1.85319330279284E-1, 6.48884482549063E-2, 1.17641910285655E-2,
     641    8.85987580106899E-4, 1.48711469943406E-5);
     642  CAlbrecht10: array [0..9] of Double = (1.79908225352538E-2,
     643    9.87959586065210E-2, 2.29883817001211E-1, 2.94113019095183E-1,
     644    2.24338977814325E-1, 1.03248806248099E-1, 2.75674109448523E-2,
     645    3.83958622947123E-3, 2.18971708430106E-4, 2.62981665347889E-6);
     646  CAlbrecht11: array [0..10] of Double = (1.18717127796602E-2,
     647    7.19533651951142E-2, 1.87887160922585E-1, 2.75808174097291E-1,
     648    2.48904243244464E-1, 1.41729867200712E-1, 5.02002976228256E-2,
     649    1.04589649084984E-2, 1.13615112741660E-3, 4.96285981703436E-5,
     650    4.34303262685720E-7);
     651
    648652type
    649653  TTransformationAccess = class(TTransformation);
     
    660664  TMappingTable = array of TCluster;
    661665
    662 
    663 type
    664666  TKernelSamplerClass = class of TKernelSampler;
    665667
     
    741743end;
    742744
    743 function BufferToColor32(Buffer: TBufferEntry; Shift: Integer): TColor32;
     745function BufferToColor32(const Buffer: TBufferEntry; Shift: Integer): TColor32;
    744746begin
    745747  with TColor32Entry(Result) do
     
    17191721          C := Src.Bits[X + ClusterY[Y].Pos * Src.Width];
    17201722          ClustYW := ClusterY[Y].Weight;
    1721           Inc(Ca, C shr 24 * ClustYW);
    1722           Inc(Cr, (C and $00FF0000) shr 16 * ClustYW);
    1723           Inc(Cg, (C and $0000FF00) shr 8 * ClustYW);
    1724           Inc(Cb, (C and $000000FF) * ClustYW);
     1723          Inc(Ca, Integer(C shr 24) * ClustYW);
     1724          Inc(Cr, Integer(C and $00FF0000) shr 16 * ClustYW);
     1725          Inc(Cg, Integer(C and $0000FF00) shr 8 * ClustYW);
     1726          Inc(Cb, Integer(C and $000000FF) * ClustYW);
    17251727        end;
    17261728        with HorzBuffer[X - MapXLoPos] do
     
    18121814    Inc(NativeUInt(RowSrc), OffSrc);
    18131815    {$ELSE}
    1814     Inc(Cardinal(RowSrc), OffSrc);
     1816    Inc(PByte(RowSrc), OffSrc);
    18151817    {$ENDIF}
    18161818  end;
     
    22942296        Inc(NativeUInt(RowSrc), OffSrc * dy);
    22952297        {$ELSE}
    2296         Inc(Cardinal(RowSrc), OffSrc * dy);
     2298        Inc(PByte(RowSrc), OffSrc * dy);
    22972299        {$ENDIF}
    22982300      end;
     
    24912493
    24922494
     2495{ TByteMap downsample functions }
     2496
     2497procedure DownsampleByteMap2x(Source, Dest: TByteMap);
     2498var
     2499  X, Y: Integer;
     2500  ScnLn: array [0 .. 2] of PByteArray;
     2501begin
     2502  for Y := 0 to (Source.Height div 2) - 1 do
     2503  begin
     2504    ScnLn[0] := Dest.ScanLine[Y];
     2505    ScnLn[1] := Source.ScanLine[Y * 2];
     2506    ScnLn[2] := Source.ScanLine[Y * 2 + 1];
     2507    for X := 0 to (Source.Width div 2) - 1 do
     2508      ScnLn[0, X] := (
     2509        ScnLn[1, 2 * X] + ScnLn[1, 2 * X + 1] +
     2510        ScnLn[2, 2 * X] + ScnLn[2, 2 * X + 1]) div 4;
     2511  end;
     2512end;
     2513
     2514procedure DownsampleByteMap3x(Source, Dest: TByteMap);
     2515var
     2516  X, Y: Integer;
     2517  x3: Integer;
     2518  ScnLn: array [0 .. 3] of PByteArray;
     2519begin
     2520  for Y := 0 to (Source.Height div 3) - 1 do
     2521  begin
     2522    ScnLn[0] := Dest.ScanLine[Y];
     2523    ScnLn[1] := Source.ScanLine[3 * Y];
     2524    ScnLn[2] := Source.ScanLine[3 * Y + 1];
     2525    ScnLn[3] := Source.ScanLine[3 * Y + 2];
     2526    for X := 0 to (Source.Width div 3) - 1 do
     2527    begin
     2528      x3 := 3 * X;
     2529      ScnLn[0, X] := (
     2530        ScnLn[1, x3] + ScnLn[1, x3 + 1] + ScnLn[1, x3 + 2] +
     2531        ScnLn[2, x3] + ScnLn[2, x3 + 1] + ScnLn[2, x3 + 2] +
     2532        ScnLn[3, x3] + ScnLn[3, x3 + 1] + ScnLn[3, x3 + 2]) div 9;
     2533    end;
     2534  end;
     2535end;
     2536
     2537procedure DownsampleByteMap4x(Source, Dest: TByteMap);
     2538var
     2539  X, Y: Integer;
     2540  x4: Integer;
     2541  ScnLn: array [0 .. 4] of PByteArray;
     2542begin
     2543  for Y := 0 to (Source.Height div 4) - 1 do
     2544  begin
     2545    ScnLn[0] := Dest.ScanLine[Y];
     2546    ScnLn[1] := Source.ScanLine[Y * 4];
     2547    ScnLn[2] := Source.ScanLine[Y * 4 + 1];
     2548    ScnLn[3] := Source.ScanLine[Y * 4 + 2];
     2549    ScnLn[4] := Source.ScanLine[Y * 4 + 3];
     2550    for X := 0 to (Source.Width div 4) - 1 do
     2551    begin
     2552      x4 := 4 * X;
     2553      ScnLn[0, X] := (
     2554        ScnLn[1, x4] + ScnLn[1, x4 + 1] + ScnLn[1, x4 + 2] + ScnLn[1, x4 + 3] +
     2555        ScnLn[2, x4] + ScnLn[2, x4 + 1] + ScnLn[2, x4 + 2] + ScnLn[2, x4 + 3] +
     2556        ScnLn[3, x4] + ScnLn[3, x4 + 1] + ScnLn[3, x4 + 2] + ScnLn[3, x4 + 3] +
     2557        ScnLn[4, x4] + ScnLn[4, x4 + 1] + ScnLn[4, x4 + 2] + ScnLn[4, x4 + 3]) div 16;
     2558    end;
     2559  end;
     2560end;
     2561
    24932562
    24942563{ TCustomKernel }
     
    29353004end;
    29363005
    2937 procedure TKernelResampler.SetKernelClassName(Value: string);
     3006procedure TKernelResampler.SetKernelClassName(const Value: string);
    29383007var
    29393008  KernelClass: TCustomKernelClass;
     
    31733242                end else
    31743243                begin
    3175                   Inc(HorzEntry.R, Div255(Alpha * SrcP.R) * W);
    3176                   Inc(HorzEntry.G, Div255(Alpha * SrcP.G) * W);
    3177                   Inc(HorzEntry.B, Div255(Alpha * SrcP.B) * W);
     3244                  Inc(HorzEntry.R, Integer(Div255(Alpha * SrcP.R)) * W);
     3245                  Inc(HorzEntry.G, Integer(Div255(Alpha * SrcP.G)) * W);
     3246                  Inc(HorzEntry.B, Integer(Div255(Alpha * SrcP.B)) * W);
    31783247                end;
    31793248              end;
     
    31963265          begin
    31973266            // Sample premultiplied values
    3198             OuterPremultColorR := Div255(Alpha * TColor32Entry(FOuterColor).R);
    3199             OuterPremultColorG := Div255(Alpha * TColor32Entry(FOuterColor).G);
    3200             OuterPremultColorB := Div255(Alpha * TColor32Entry(FOuterColor).B);
     3267            OuterPremultColorR := Integer(Div255(Alpha * TColor32Entry(FOuterColor).R));
     3268            OuterPremultColorG := Integer(Div255(Alpha * TColor32Entry(FOuterColor).G));
     3269            OuterPremultColorB := Integer(Div255(Alpha * TColor32Entry(FOuterColor).B));
    32013270
    32023271            for I := -KWidth to KWidth do
     
    33643433  if FKernelMode in [kmTableNearest, kmTableLinear] then
    33653434  begin
    3366     FWeightTable := TIntegerMap.Create;
    3367     FWeightTable.SetSize(W * 2 + 1, FTableSize + 1);
     3435    FWeightTable := TIntegerMap.Create(W * 2 + 1, FTableSize + 1);
    33683436    for I := 0 to FTableSize do
    33693437    begin
     
    33823450end;
    33833451
     3452
    33843453{ TCustomBitmap32NearestResampler }
    33853454
     
    35183587      end;
    35193588
    3520       WX := GAMMA_TABLE[((X shr 8) and $FF) xor $FF];
     3589      WX := GAMMA_ENCODING_TABLE[((X shr 8) and $FF) xor $FF];
    35213590      Result := CombineReg(CombineReg(C1, C2, WX),
    35223591                           CombineReg(C3, C4, WX),
    3523                            GAMMA_TABLE[((Y shr 8) and $FF) xor $FF]);
     3592                           GAMMA_ENCODING_TABLE[((Y shr 8) and $FF) xor $FF]);
    35243593      EMMS; 
    35253594    end 
     
    35583627  DstH := DstRect.Bottom - DstRect.Top;
    35593628  if (DstW > SrcW) and (DstH > SrcH) and (SrcW > 1) and (SrcH > 1) then
    3560     StretchHorzStretchVertLinear(Dst, DstRect, DstClip, Src, SrcRect, CombineOp, CombineCallBack)
     3629    StretchHorzStretchVertLinear(Dst, DstRect, DstClip, Src, SrcRect, CombineOp,
     3630      CombineCallBack)
    35613631  else
    3562     GR32_Resamplers.Resample(Dst, DstRect, DstClip, Src, SrcRect, FLinearKernel, CombineOp, CombineCallBack);
     3632    GR32_Resamplers.Resample(Dst, DstRect, DstClip, Src, SrcRect, FLinearKernel,
     3633      CombineOp, CombineCallBack);
    35633634end;
    35643635
     
    35683639  CombineOp: TDrawMode; CombineCallBack: TPixelCombineEvent);
    35693640begin
    3570   DraftResample(Dst, DstRect, DstClip, Src, SrcRect, FLinearKernel, CombineOp, CombineCallBack)
     3641  DraftResample(Dst, DstRect, DstClip, Src, SrcRect, FLinearKernel, CombineOp,
     3642    CombineCallBack)
    35713643end;
    35723644
     
    35773649  U, V: TFixed;
    35783650begin
    3579   FTransformationReverseTransformFixed(X * FixedOne + FixedHalf, Y * FixedOne + FixedHalf, U, V);
     3651  FTransformationReverseTransformFixed(X * FixedOne + FixedHalf,
     3652    Y * FixedOne + FixedHalf, U, V);
    35803653  Result := FGetSampleFixed(U - FixedHalf, V - FixedHalf);
    35813654end;
     
    41394212end;
    41404213
    4141 {CPU target and feature Function templates}
     4214{CPU target and feature function templates}
    41424215
    41434216const
Note: See TracChangeset for help on using the changeset viewer.