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/bgrareadpng.pas

    r494 r521  
    4040  { TBGRAReaderPNG }
    4141
    42   TBGRAReaderPNG = class (TFPCustomImageReader)
     42  TBGRAReaderPNG = class (TBGRAImageReader)
    4343    private
    4444
     
    133133      property OriginalWidth: integer read GetOriginalWidth;
    134134      property OriginalHeight: integer read GetOriginalHeight;
     135      function GetQuickInfo(AStream: TStream): TQuickImageInfo; override;
     136      function GetBitmapDraft(AStream: TStream; {%H-}AMaxWidth, AMaxHeight: integer; out AOriginalWidth,AOriginalHeight: integer): TBGRACustomBitmap; override;
    135137  end;
    136138
    137139implementation
    138140
    139 
     141uses math;
    140142
    141143const StartPoints : array[0..7, 0..1] of word =
     
    163165end;
    164166
     167function TBGRAReaderPNG.GetQuickInfo(AStream: TStream): TQuickImageInfo;
     168const headerChunkSize = 13;
     169var
     170  {%H-}FileHeader : packed array[0..7] of byte;
     171  {%H-}ChunkHeader : TChunkHeader;
     172  {%H-}HeaderChunk : THeaderChunk;
     173begin
     174  fillchar({%H-}result, sizeof(result), 0);
     175  if AStream.Read({%H-}FileHeader, sizeof(FileHeader))<> sizeof(FileHeader) then exit;
     176  if QWord(FileHeader) <> QWord(PNGComn.Signature) then exit;
     177  if AStream.Read({%H-}ChunkHeader, sizeof(ChunkHeader))<> sizeof(ChunkHeader) then exit;
     178  if ChunkHeader.CType <> ChunkTypes[ctIHDR] then exit;
     179  if BEtoN(ChunkHeader.CLength) < headerChunkSize then exit;
     180  if AStream.Read({%H-}HeaderChunk, headerChunkSize) <> headerChunkSize then exit;
     181  result.width:= BEtoN(HeaderChunk.Width);
     182  result.height:= BEtoN(HeaderChunk.height);
     183  case HeaderChunk.ColorType and 3 of
     184    0,3: {grayscale, palette}
     185      if HeaderChunk.BitDepth > 8 then
     186        result.colorDepth := 8
     187      else
     188        result.colorDepth := HeaderChunk.BitDepth;
     189
     190    2: {color} result.colorDepth := HeaderChunk.BitDepth*3;
     191  end;
     192  if (HeaderChunk.ColorType and 4) = 4 then
     193    result.alphaDepth := HeaderChunk.BitDepth
     194  else
     195    result.alphaDepth := 0;
     196end;
     197
     198function TBGRAReaderPNG.GetBitmapDraft(AStream: TStream; AMaxWidth,
     199  AMaxHeight: integer; out AOriginalWidth, AOriginalHeight: integer): TBGRACustomBitmap;
     200var
     201  png: TBGRAReaderPNG;
     202begin
     203  png:= TBGRAReaderPNG.Create;
     204  result := BGRABitmapFactory.Create;
     205  try
     206    png.MinifyHeight := AMaxHeight;
     207    result.LoadFromStream(AStream, png);
     208    AOriginalWidth:= result.Width;
     209    AOriginalHeight:= png.OriginalHeight;
     210  finally
     211    png.Free;
     212  end;
     213end;
     214
    165215procedure TBGRAReaderPNG.ReadChunk;
    166 
    167216var {%H-}ChunkHeader : TChunkHeader;
    168217    readCRC : longword;
     
    520569  UsingBitGroup := 0;
    521570  DataIndex := 0;
     571  {$PUSH}{$RANGECHECKS OFF} //because PByteArray is limited to 32767
    522572  if (UsingBitGroup = 0) and (Header.BitDepth <> 16) then
    523573    case ByteWidth of
     
    583633         end;
    584634    end;
     635  {$POP}
    585636
    586637  X := StartX;
     
    694745end;
    695746
    696 function TBGRAReaderPNG.ColorGray1 (const CD:TColorDAta) : TFPColor;
     747function TBGRAReaderPNG.ColorGray1(const CD: TColorData): TFPColor;
    697748begin
    698749  if CD = 0 then
     
    702753end;
    703754
    704 function TBGRAReaderPNG.ColorGray2 (const CD:TColorDAta) : TFPColor;
     755function TBGRAReaderPNG.ColorGray2(const CD: TColorData): TFPColor;
    705756var c : NativeUint;
    706757begin
     
    718769end;
    719770
    720 function TBGRAReaderPNG.ColorGray4 (const CD:TColorDAta) : TFPColor;
     771function TBGRAReaderPNG.ColorGray4(const CD: TColorData): TFPColor;
    721772var c : NativeUint;
    722773begin
     
    733784end;
    734785
    735 function TBGRAReaderPNG.ColorGray8 (const CD:TColorDAta) : TFPColor;
     786function TBGRAReaderPNG.ColorGray8(const CD: TColorData): TFPColor;
    736787var c : NativeUint;
    737788begin
     
    747798end;
    748799
    749 function TBGRAReaderPNG.ColorGray16 (const CD:TColorDAta) : TFPColor;
     800function TBGRAReaderPNG.ColorGray16(const CD: TColorData): TFPColor;
    750801var c : NativeUint;
    751802begin
     
    10651116    while Count4 > 0 do
    10661117    begin
    1067       {$push}{$r-}
     1118      {$push}{$r-}{$q-}
    10681119      PDWord(p)^ := (((PDWord(pPrev)^ and $00FF00FF) + (PDWord(p)^ and $00FF00FF)) and $00FF00FF)
    10691120        or (((PDWord(pPrev)^ and $FF00FF00) + (PDWord(p)^ and $FF00FF00)) and $FF00FF00);
     
    13071358    // Check IHDR
    13081359    ReadChunk;
    1309     move (chunk.data^, FHeader, sizeof(Header));
     1360    fillchar(FHeader, sizeof(FHeader), 0);
     1361    move (chunk.data^, FHeader, min(sizeof(Header), chunk.alength));
    13101362    with header do
    13111363      begin
Note: See TracChangeset for help on using the changeset viewer.