Changeset 521 for GraphicTest/Packages/bgrabitmap/bgrareadpng.pas
- Timestamp:
- Apr 17, 2019, 12:58:41 AM (5 years ago)
- Location:
- GraphicTest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest
- Property svn:ignore
-
old new 8 8 GraphicTest.lps 9 9 GraphicTest.dbg 10 heaptrclog.trc
-
- Property svn:ignore
-
GraphicTest/Packages/bgrabitmap/bgrareadpng.pas
r494 r521 40 40 { TBGRAReaderPNG } 41 41 42 TBGRAReaderPNG = class (T FPCustomImageReader)42 TBGRAReaderPNG = class (TBGRAImageReader) 43 43 private 44 44 … … 133 133 property OriginalWidth: integer read GetOriginalWidth; 134 134 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; 135 137 end; 136 138 137 139 implementation 138 140 139 141 uses math; 140 142 141 143 const StartPoints : array[0..7, 0..1] of word = … … 163 165 end; 164 166 167 function TBGRAReaderPNG.GetQuickInfo(AStream: TStream): TQuickImageInfo; 168 const headerChunkSize = 13; 169 var 170 {%H-}FileHeader : packed array[0..7] of byte; 171 {%H-}ChunkHeader : TChunkHeader; 172 {%H-}HeaderChunk : THeaderChunk; 173 begin 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; 196 end; 197 198 function TBGRAReaderPNG.GetBitmapDraft(AStream: TStream; AMaxWidth, 199 AMaxHeight: integer; out AOriginalWidth, AOriginalHeight: integer): TBGRACustomBitmap; 200 var 201 png: TBGRAReaderPNG; 202 begin 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; 213 end; 214 165 215 procedure TBGRAReaderPNG.ReadChunk; 166 167 216 var {%H-}ChunkHeader : TChunkHeader; 168 217 readCRC : longword; … … 520 569 UsingBitGroup := 0; 521 570 DataIndex := 0; 571 {$PUSH}{$RANGECHECKS OFF} //because PByteArray is limited to 32767 522 572 if (UsingBitGroup = 0) and (Header.BitDepth <> 16) then 523 573 case ByteWidth of … … 583 633 end; 584 634 end; 635 {$POP} 585 636 586 637 X := StartX; … … 694 745 end; 695 746 696 function TBGRAReaderPNG.ColorGray1 (const CD:TColorDAta): TFPColor;747 function TBGRAReaderPNG.ColorGray1(const CD: TColorData): TFPColor; 697 748 begin 698 749 if CD = 0 then … … 702 753 end; 703 754 704 function TBGRAReaderPNG.ColorGray2 (const CD:TColorDAta): TFPColor;755 function TBGRAReaderPNG.ColorGray2(const CD: TColorData): TFPColor; 705 756 var c : NativeUint; 706 757 begin … … 718 769 end; 719 770 720 function TBGRAReaderPNG.ColorGray4 (const CD:TColorDAta): TFPColor;771 function TBGRAReaderPNG.ColorGray4(const CD: TColorData): TFPColor; 721 772 var c : NativeUint; 722 773 begin … … 733 784 end; 734 785 735 function TBGRAReaderPNG.ColorGray8 (const CD:TColorDAta): TFPColor;786 function TBGRAReaderPNG.ColorGray8(const CD: TColorData): TFPColor; 736 787 var c : NativeUint; 737 788 begin … … 747 798 end; 748 799 749 function TBGRAReaderPNG.ColorGray16 (const CD:TColorDAta): TFPColor;800 function TBGRAReaderPNG.ColorGray16(const CD: TColorData): TFPColor; 750 801 var c : NativeUint; 751 802 begin … … 1065 1116 while Count4 > 0 do 1066 1117 begin 1067 {$push}{$r-} 1118 {$push}{$r-}{$q-} 1068 1119 PDWord(p)^ := (((PDWord(pPrev)^ and $00FF00FF) + (PDWord(p)^ and $00FF00FF)) and $00FF00FF) 1069 1120 or (((PDWord(pPrev)^ and $FF00FF00) + (PDWord(p)^ and $FF00FF00)) and $FF00FF00); … … 1307 1358 // Check IHDR 1308 1359 ReadChunk; 1309 move (chunk.data^, FHeader, sizeof(Header)); 1360 fillchar(FHeader, sizeof(FHeader), 0); 1361 move (chunk.data^, FHeader, min(sizeof(Header), chunk.alength)); 1310 1362 with header do 1311 1363 begin
Note:
See TracChangeset
for help on using the changeset viewer.