Changeset 522 for GraphicTest/Packages/Graphics32/GR32_Resamplers.pas
- Timestamp:
- Apr 17, 2019, 10:42:18 AM (5 years ago)
- Location:
- GraphicTest/Packages/Graphics32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/Graphics32
-
Property svn:ignore
set to
lib
-
Property svn:ignore
set to
-
GraphicTest/Packages/Graphics32/GR32_Resamplers.pas
r450 r522 50 50 {$ENDIF} 51 51 Classes, SysUtils, GR32, GR32_Transforms, GR32_Containers, 52 GR32_OrdinalMaps, GR32_Blend , GR32_System, GR32_Bindings;52 GR32_OrdinalMaps, GR32_Blend; 53 53 54 54 procedure BlockTransfer( … … 343 343 procedure SetKernel(const Value: TCustomKernel); 344 344 function GetKernelClassName: string; 345 procedure SetKernelClassName( Value: string);345 procedure SetKernelClassName(const Value: string); 346 346 procedure SetKernelMode(const Value: TKernelMode); 347 347 procedure SetTableSize(Value: Integer); … … 578 578 procedure IncBuffer(var Buffer: TBufferEntry; Color: TColor32); {$IFDEF USEINLINING} inline; {$ENDIF} 579 579 procedure MultiplyBuffer(var Buffer: TBufferEntry; W: Integer); {$IFDEF USEINLINING} inline; {$ENDIF} 580 function BufferToColor32( Buffer: TBufferEntry; Shift: Integer): TColor32; {$IFDEF USEINLINING} inline; {$ENDIF}580 function BufferToColor32(const Buffer: TBufferEntry; Shift: Integer): TColor32; {$IFDEF USEINLINING} inline; {$ENDIF} 581 581 procedure ShrBuffer(var Buffer: TBufferEntry; Shift: Integer); {$IFDEF USEINLINING} inline; {$ENDIF} 582 583 { Downsample byte map } 584 procedure DownsampleByteMap2x(Source, Dest: TByteMap); 585 procedure DownsampleByteMap3x(Source, Dest: TByteMap); 586 procedure DownsampleByteMap4x(Source, Dest: TByteMap); 582 587 583 588 { Registration routines } … … 605 610 606 611 uses 607 GR32_LowLevel, GR32_Rasterizers, GR32_Math, Math; 612 GR32_System, GR32_Bindings, GR32_LowLevel, GR32_Rasterizers, GR32_Math, 613 GR32_Gamma, Math; 608 614 609 615 resourcestring … … 611 617 612 618 const 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 648 652 type 649 653 TTransformationAccess = class(TTransformation); … … 660 664 TMappingTable = array of TCluster; 661 665 662 663 type664 666 TKernelSamplerClass = class of TKernelSampler; 665 667 … … 741 743 end; 742 744 743 function BufferToColor32( Buffer: TBufferEntry; Shift: Integer): TColor32;745 function BufferToColor32(const Buffer: TBufferEntry; Shift: Integer): TColor32; 744 746 begin 745 747 with TColor32Entry(Result) do … … 1719 1721 C := Src.Bits[X + ClusterY[Y].Pos * Src.Width]; 1720 1722 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); 1725 1727 end; 1726 1728 with HorzBuffer[X - MapXLoPos] do … … 1812 1814 Inc(NativeUInt(RowSrc), OffSrc); 1813 1815 {$ELSE} 1814 Inc( Cardinal(RowSrc), OffSrc);1816 Inc(PByte(RowSrc), OffSrc); 1815 1817 {$ENDIF} 1816 1818 end; … … 2294 2296 Inc(NativeUInt(RowSrc), OffSrc * dy); 2295 2297 {$ELSE} 2296 Inc( Cardinal(RowSrc), OffSrc * dy);2298 Inc(PByte(RowSrc), OffSrc * dy); 2297 2299 {$ENDIF} 2298 2300 end; … … 2491 2493 2492 2494 2495 { TByteMap downsample functions } 2496 2497 procedure DownsampleByteMap2x(Source, Dest: TByteMap); 2498 var 2499 X, Y: Integer; 2500 ScnLn: array [0 .. 2] of PByteArray; 2501 begin 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; 2512 end; 2513 2514 procedure DownsampleByteMap3x(Source, Dest: TByteMap); 2515 var 2516 X, Y: Integer; 2517 x3: Integer; 2518 ScnLn: array [0 .. 3] of PByteArray; 2519 begin 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; 2535 end; 2536 2537 procedure DownsampleByteMap4x(Source, Dest: TByteMap); 2538 var 2539 X, Y: Integer; 2540 x4: Integer; 2541 ScnLn: array [0 .. 4] of PByteArray; 2542 begin 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; 2560 end; 2561 2493 2562 2494 2563 { TCustomKernel } … … 2935 3004 end; 2936 3005 2937 procedure TKernelResampler.SetKernelClassName( Value: string);3006 procedure TKernelResampler.SetKernelClassName(const Value: string); 2938 3007 var 2939 3008 KernelClass: TCustomKernelClass; … … 3173 3242 end else 3174 3243 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); 3178 3247 end; 3179 3248 end; … … 3196 3265 begin 3197 3266 // 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)); 3201 3270 3202 3271 for I := -KWidth to KWidth do … … 3364 3433 if FKernelMode in [kmTableNearest, kmTableLinear] then 3365 3434 begin 3366 FWeightTable := TIntegerMap.Create; 3367 FWeightTable.SetSize(W * 2 + 1, FTableSize + 1); 3435 FWeightTable := TIntegerMap.Create(W * 2 + 1, FTableSize + 1); 3368 3436 for I := 0 to FTableSize do 3369 3437 begin … … 3382 3450 end; 3383 3451 3452 3384 3453 { TCustomBitmap32NearestResampler } 3385 3454 … … 3518 3587 end; 3519 3588 3520 WX := GAMMA_ TABLE[((X shr 8) and $FF) xor $FF];3589 WX := GAMMA_ENCODING_TABLE[((X shr 8) and $FF) xor $FF]; 3521 3590 Result := CombineReg(CombineReg(C1, C2, WX), 3522 3591 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]); 3524 3593 EMMS; 3525 3594 end … … 3558 3627 DstH := DstRect.Bottom - DstRect.Top; 3559 3628 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) 3561 3631 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); 3563 3634 end; 3564 3635 … … 3568 3639 CombineOp: TDrawMode; CombineCallBack: TPixelCombineEvent); 3569 3640 begin 3570 DraftResample(Dst, DstRect, DstClip, Src, SrcRect, FLinearKernel, CombineOp, CombineCallBack) 3641 DraftResample(Dst, DstRect, DstClip, Src, SrcRect, FLinearKernel, CombineOp, 3642 CombineCallBack) 3571 3643 end; 3572 3644 … … 3577 3649 U, V: TFixed; 3578 3650 begin 3579 FTransformationReverseTransformFixed(X * FixedOne + FixedHalf, Y * FixedOne + FixedHalf, U, V); 3651 FTransformationReverseTransformFixed(X * FixedOne + FixedHalf, 3652 Y * FixedOne + FixedHalf, U, V); 3580 3653 Result := FGetSampleFixed(U - FixedHalf, V - FixedHalf); 3581 3654 end; … … 4139 4212 end; 4140 4213 4141 {CPU target and feature Function templates}4214 {CPU target and feature function templates} 4142 4215 4143 4216 const
Note:
See TracChangeset
for help on using the changeset viewer.