Ignore:
Timestamp:
Apr 17, 2019, 12:58:41 AM (5 years ago)
Author:
chronos
Message:
  • Modified: Propagate project build mode options to used packages.
  • Added: Check memory leaks using heaptrc.
  • Modified: Update BGRABitmap package.
Location:
GraphicTest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest

    • Property svn:ignore
      •  

        old new  
        88GraphicTest.lps
        99GraphicTest.dbg
         10heaptrclog.trc
  • GraphicTest/Packages/bgrabitmap/bgrablend.pas

    r494 r521  
    698698procedure DrawPixelInlineWithAlphaCheck(dest: PBGRAPixel; const c: TBGRAPixel);
    699699begin
    700   if c.alpha = 0 then
    701     exit;
    702   if c.alpha = 255 then
    703   begin
    704     dest^ := c;
    705     exit;
    706   end;
    707   DrawPixelInlineNoAlphaCheck(dest,c);
     700  case c.alpha of
     701  0: ;
     702  255: dest^ := c;
     703  else
     704    DrawPixelInlineNoAlphaCheck(dest,c);
     705  end;
    708706end;
    709707
     
    711709begin
    712710  c.alpha := ApplyOpacity(c.alpha,appliedOpacity);
    713   if c.alpha = 0 then
    714     exit;
    715   if c.alpha = 255 then
    716   begin
    717     dest^ := c;
    718     exit;
    719   end;
    720   DrawPixelInlineNoAlphaCheck(dest,c);
     711  DrawPixelInlineWithAlphaCheck(dest, c);
    721712end;
    722713
     
    748739begin
    749740  calpha := ec.alpha shr 8;
    750   if calpha = 0 then
    751     exit;
    752   if calpha = 255 then
    753   begin
    754     dest^ := GammaCompression(ec);
    755     exit;
    756   end;
    757   DrawExpandedPixelInlineNoAlphaCheck(dest,ec,calpha);
     741  case calpha of
     742  0: ;
     743  255: dest^ := GammaCompression(ec);
     744  else
     745    DrawExpandedPixelInlineNoAlphaCheck(dest,ec,calpha);
     746  end;
    758747end;
    759748
    760749procedure DrawPixelInlineExpandedOrNotWithAlphaCheck(dest: PBGRAPixel; const ec: TExpandedPixel; c: TBGRAPixel);
    761750begin
    762   if c.alpha = 0 then
    763     exit;
    764   if c.alpha = 255 then
    765   begin
    766     dest^ := c;
    767     exit;
    768   end;
    769   DrawExpandedPixelInlineNoAlphaCheck(dest,ec,c.alpha);
     751  case c.alpha of
     752  0: ;
     753  255: dest^ := c;
     754  else
     755    DrawExpandedPixelInlineNoAlphaCheck(dest,ec,c.alpha);
     756  end;
    770757end;
    771758
    772759procedure DrawPixelInlineNoAlphaCheck(dest: PBGRAPixel; const c: TBGRAPixel);
    773760var
    774   a1f, a2f, a12, a12m: cardinal;
    775 begin
    776   {$HINTS OFF}
    777   a12  := 65025 - (not dest^.alpha) * (not c.alpha);
    778   {$HINTS ON}
    779   a12m := a12 shr 1;
    780 
    781   a1f := dest^.alpha * (not c.alpha);
    782   a2f := (c.alpha shl 8) - c.alpha;
    783 
    784   PDWord(dest)^ := ((GammaCompressionTab[(GammaExpansionTab[dest^.red] * a1f +
    785                      GammaExpansionTab[c.red] * a2f + a12m) div a12]) shl TBGRAPixel_RedShift) or
    786                    ((GammaCompressionTab[(GammaExpansionTab[dest^.green] * a1f +
    787                      GammaExpansionTab[c.green] * a2f + a12m) div a12]) shl TBGRAPixel_GreenShift) or
    788                    ((GammaCompressionTab[(GammaExpansionTab[dest^.blue] * a1f +
    789                      GammaExpansionTab[c.blue] * a2f + a12m) div a12]) shl TBGRAPixel_BlueShift) or
    790                    (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift);
     761  a1f, a2f, a12, a12m, alphaCorr: NativeUInt;
     762begin
     763  case dest^.alpha of
     764    0: dest^ := c;
     765    255:
     766      begin
     767        alphaCorr := c.alpha;
     768        if alphaCorr >= 128 then alphaCorr += 1;
     769        dest^.red := GammaCompressionTab[(GammaExpansionTab[dest^.red] * NativeUInt(256-alphaCorr) + GammaExpansionTab[c.red]*alphaCorr) shr 8];
     770        dest^.green := GammaCompressionTab[(GammaExpansionTab[dest^.green] * NativeUInt(256-alphaCorr) + GammaExpansionTab[c.green]*alphaCorr) shr 8];
     771        dest^.blue := GammaCompressionTab[(GammaExpansionTab[dest^.blue] * NativeUInt(256-alphaCorr) + GammaExpansionTab[c.blue]*alphaCorr) shr 8];
     772      end;
     773    else
     774    begin
     775      {$HINTS OFF}
     776      a12  := 65025 - (not dest^.alpha) * (not c.alpha);
     777      {$HINTS ON}
     778      a12m := a12 shr 1;
     779
     780      a1f := dest^.alpha * (not c.alpha);
     781      a2f := (c.alpha shl 8) - c.alpha;
     782
     783      PDWord(dest)^ := ((GammaCompressionTab[(GammaExpansionTab[dest^.red] * a1f +
     784                         GammaExpansionTab[c.red] * a2f + a12m) div a12]) shl TBGRAPixel_RedShift) or
     785                       ((GammaCompressionTab[(GammaExpansionTab[dest^.green] * a1f +
     786                         GammaExpansionTab[c.green] * a2f + a12m) div a12]) shl TBGRAPixel_GreenShift) or
     787                       ((GammaCompressionTab[(GammaExpansionTab[dest^.blue] * a1f +
     788                         GammaExpansionTab[c.blue] * a2f + a12m) div a12]) shl TBGRAPixel_BlueShift) or
     789                       (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift);
     790    end;
     791  end;
    791792end;
    792793
     
    794795  const ec: TExpandedPixel; calpha: byte);
    795796var
    796   a1f, a2f, a12, a12m: cardinal;
    797 begin
    798   {$HINTS OFF}
    799   a12  := 65025 - (not dest^.alpha) * (not calpha);
    800   {$HINTS ON}
    801   a12m := a12 shr 1;
    802 
    803   a1f := dest^.alpha * (not calpha);
    804   a2f := (calpha shl 8) - calpha;
    805 
    806   PDWord(dest)^ := ((GammaCompressionTab[(GammaExpansionTab[dest^.red] * a1f +
    807                      ec.red * a2f + a12m) div a12]) shl TBGRAPixel_RedShift) or
    808                    ((GammaCompressionTab[(GammaExpansionTab[dest^.green] * a1f +
    809                      ec.green * a2f + a12m) div a12]) shl TBGRAPixel_GreenShift) or
    810                    ((GammaCompressionTab[(GammaExpansionTab[dest^.blue] * a1f +
    811                      ec.blue * a2f + a12m) div a12]) shl TBGRAPixel_BlueShift) or
    812                    (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift);
     797  a1f, a2f, a12, a12m, alphaCorr: NativeUInt;
     798begin
     799  case dest^.alpha of
     800    0: begin
     801         dest^.red := GammaCompressionTab[ec.red];
     802         dest^.green := GammaCompressionTab[ec.green];
     803         dest^.blue := GammaCompressionTab[ec.blue];
     804         dest^.alpha := calpha;
     805      end;
     806    255:
     807      begin
     808        alphaCorr := calpha;
     809        if alphaCorr >= 128 then alphaCorr += 1;
     810        dest^.red := GammaCompressionTab[(GammaExpansionTab[dest^.red] * NativeUInt(256-alphaCorr) + ec.red*alphaCorr) shr 8];
     811        dest^.green := GammaCompressionTab[(GammaExpansionTab[dest^.green] * NativeUInt(256-alphaCorr) + ec.green*alphaCorr) shr 8];
     812        dest^.blue := GammaCompressionTab[(GammaExpansionTab[dest^.blue] * NativeUInt(256-alphaCorr) + ec.blue*alphaCorr) shr 8];
     813      end;
     814    else
     815    begin
     816      {$HINTS OFF}
     817      a12  := 65025 - (not dest^.alpha) * (not calpha);
     818      {$HINTS ON}
     819      a12m := a12 shr 1;
     820
     821      a1f := dest^.alpha * (not calpha);
     822      a2f := (calpha shl 8) - calpha;
     823
     824      PDWord(dest)^ := ((GammaCompressionTab[(GammaExpansionTab[dest^.red] * a1f +
     825                         ec.red * a2f + a12m) div a12]) shl TBGRAPixel_RedShift) or
     826                       ((GammaCompressionTab[(GammaExpansionTab[dest^.green] * a1f +
     827                         ec.green * a2f + a12m) div a12]) shl TBGRAPixel_GreenShift) or
     828                       ((GammaCompressionTab[(GammaExpansionTab[dest^.blue] * a1f +
     829                         ec.blue * a2f + a12m) div a12]) shl TBGRAPixel_BlueShift) or
     830                       (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift);
     831    end;
     832  end;
    813833end;
    814834
    815835procedure FastBlendPixelInline(dest: PBGRAPixel; const c: TBGRAPixel);
    816836var
    817   a1f, a2f, a12, a12m: cardinal;
    818 begin
    819   if c.alpha = 0 then
    820     exit;
    821   if c.alpha = 255 then
    822   begin
    823     dest^ := c;
    824     exit;
    825   end;
    826 
    827   {$HINTS OFF}
    828   a12  := 65025 - (not dest^.alpha) * (not c.alpha);
    829   {$HINTS ON}
    830   a12m := a12 shr 1;
    831 
    832   a1f := dest^.alpha * (not c.alpha);
    833   a2f := (c.alpha shl 8) - c.alpha;
    834 
    835   PDWord(dest)^ := (((dest^.red * a1f + c.red * a2f + a12m) div a12) shl TBGRAPixel_RedShift) or
    836                    (((dest^.green * a1f + c.green * a2f + a12m) div a12) shl TBGRAPixel_GreenShift) or
    837                    (((dest^.blue * a1f + c.blue * a2f + a12m) div a12) shl TBGRAPixel_BlueShift) or
    838                    (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift);
     837  a1f, a2f, a12, a12m, alphaCorr: NativeUInt;
     838begin
     839  case c.alpha of
     840    0: ;
     841    255: dest^ := c;
     842    else
     843    begin
     844      case dest^.alpha of
     845        0: dest^ := c;
     846        255:
     847        begin
     848          alphaCorr := c.alpha;
     849          if alphaCorr >= 128 then alphaCorr += 1;
     850          dest^.red := (dest^.red * NativeUInt(256-alphaCorr) + c.red*(alphaCorr+1)) shr 8;
     851          dest^.green := (dest^.green * NativeUInt(256-alphaCorr) + c.green*(alphaCorr+1)) shr 8;
     852          dest^.blue := (dest^.blue * NativeUInt(256-alphaCorr) + c.blue*(alphaCorr+1)) shr 8;
     853        end;
     854        else
     855        begin
     856          {$HINTS OFF}
     857          a12  := 65025 - (not dest^.alpha) * (not c.alpha);
     858          {$HINTS ON}
     859          a12m := a12 shr 1;
     860
     861          a1f := dest^.alpha * (not c.alpha);
     862          a2f := (c.alpha shl 8) - c.alpha;
     863
     864          PDWord(dest)^ := (((dest^.red * a1f + c.red * a2f + a12m) div a12) shl TBGRAPixel_RedShift) or
     865                           (((dest^.green * a1f + c.green * a2f + a12m) div a12) shl TBGRAPixel_GreenShift) or
     866                           (((dest^.blue * a1f + c.blue * a2f + a12m) div a12) shl TBGRAPixel_BlueShift) or
     867                           (((a12 + a12 shr 7) shr 8) shl TBGRAPixel_AlphaShift);
     868        end;
     869      end;
     870    end;
     871  end;
    839872end;
    840873
Note: See TracChangeset for help on using the changeset viewer.