Changeset 472 for GraphicTest/Packages/bgrabitmap/bgraanimatedgif.pas
- Timestamp:
- Apr 9, 2015, 9:58:36 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgraanimatedgif.pas
r452 r472 34 34 FTimeAccumulator: double; 35 35 FCurrentImage, FWantedImage: integer; 36 FFullAnimationTime: double; 36 37 FPreviousDisposeMode: TDisposeMode; 37 38 … … 41 42 42 43 function GetCount: integer; 44 function GetTimeUntilNextImage: integer; 43 45 procedure Render(StretchWidth, StretchHeight: integer); 44 46 procedure UpdateSimple(Canvas: TCanvas; ARect: TRect; … … 70 72 BackgroundMode: TGifBackgroundMode; 71 73 72 constructor Create(filename : string);74 constructor Create(filenameUTF8: string); 73 75 constructor Create(stream: TStream); 74 76 constructor Create; override; … … 78 80 procedure LoadFromStream(Stream: TStream); override; 79 81 procedure SaveToStream(Stream: TStream); override; 82 procedure LoadFromFile(const AFilenameUTF8: string); override; 83 procedure SaveToFile(const AFilenameUTF8: string); override; 80 84 class function GetFileExtensions: string; override; 81 85 … … 97 101 property MemBitmap: TBGRABitmap Read GetMemBitmap; 98 102 property CurrentImage: integer Read FCurrentImage Write SetCurrentImage; 103 property TimeUntilNextImageMs: integer read GetTimeUntilNextImage; 99 104 end; 100 105 … … 114 119 implementation 115 120 116 uses BGRABlend ;121 uses BGRABlend, lazutf8classes; 117 122 118 123 const 124 {$IFDEF ENDIAN_LITTLE} 119 125 AlphaMask = $FF000000; 126 {$ELSE} 127 AlphaMask = $000000FF; 128 {$ENDIF} 120 129 121 130 type … … 188 197 if not FPaused then 189 198 FTimeAccumulator += (curDate - FPrevDate) * 24 * 60 * 60 * 1000; 199 if FFullAnimationTime > 0 then FTimeAccumulator:= frac(FTimeAccumulator/FFullAnimationTime)*FFullAnimationTime; 190 200 nextImage := FCurrentImage; 191 201 while FTimeAccumulator > FImages[nextImage].Delay do … … 279 289 end; 280 290 281 constructor TBGRAAnimatedGif.Create(filename: string);291 function TBGRAAnimatedGif.GetTimeUntilNextImage: integer; 282 292 var 283 Stream: TFileStream; 293 acc: double; 294 begin 295 if Count <= 1 then result := 60*1000 else 296 if (FWantedImage <> -1) or (FCurrentImage = -1) then 297 result := 0 298 else 299 begin 300 acc := FTimeAccumulator; 301 if not FPaused then acc += (Now- FPrevDate) * 24 * 60 * 60 * 1000; 302 if acc >= FImages[FCurrentImage].Delay then 303 result := 0 304 else 305 result := round(FImages[FCurrentImage].Delay-FTimeAccumulator); 306 end; 307 end; 308 309 constructor TBGRAAnimatedGif.Create(filenameUTF8: string); 310 var 311 Stream: TFileStreamUTF8; 284 312 begin 285 313 inherited Create; 286 314 Init; 287 Stream := TFileStream .Create(filename, fmOpenRead);315 Stream := TFileStreamUTF8.Create(filenameUTF8, fmOpenRead or fmShareDenyWrite); 288 316 LoadFromStream(Stream); 289 317 Stream.Free; … … 355 383 end; 356 384 385 procedure TBGRAAnimatedGif.LoadFromFile(const AFilenameUTF8: string); 386 var stream: TFileStreamUTF8; 387 begin 388 stream := TFileStreamUTF8.Create(AFilenameUTF8,fmOpenRead or fmShareDenyWrite); 389 try 390 LoadFromStream(Stream); 391 finally 392 Stream.Free; 393 end; 394 end; 395 396 procedure TBGRAAnimatedGif.SaveToFile(const AFilenameUTF8: string); 397 var 398 Stream: TFileStreamUTF8; 399 begin 400 Stream := TFileStreamUTF8.Create(AFilenameUTF8, fmCreate); 401 try 402 SaveToStream(Stream); 403 finally 404 Stream.Free; 405 end; 406 end; 407 357 408 {$HINTS OFF} 358 409 procedure TBGRAAnimatedGif.LoadImages(stream: TStream); … … 458 509 stridx: longint; 459 510 bitbuf, bitsinbuf: longint; 460 bytbuf: array[0..255] of byte;511 bytbuf: packed array[0..255] of byte; 461 512 bytinbuf, bytbufidx: byte; 462 513 endofsrc: boolean; … … 684 735 begin 685 736 stream.Read(GIFImageDescriptor, sizeof(GIFImageDescriptor)); 737 GIFImageDescriptor.Width := LEtoN(GIFImageDescriptor.Width); 738 GIFImageDescriptor.Height := LEtoN(GIFImageDescriptor.Height); 739 GIFImageDescriptor.x := LEtoN(GIFImageDescriptor.x); 740 GIFImageDescriptor.y := LEtoN(GIFImageDescriptor.y); 686 741 if (GIFImageDescriptor.flags and GIFImageDescriptor_LocalColorTableFlag = 687 742 GIFImageDescriptor_LocalColorTableFlag) then … … 724 779 Clear; 725 780 SetLength(FImages, NbImages); 781 FFullAnimationTime:= 0; 726 782 for i := 0 to Count - 1 do 783 begin 727 784 FImages[i] := NewImages[i]; 785 FFullAnimationTime += NewImages[i].Delay; 786 end; 728 787 end; 729 788 … … 746 805 mincount := sizeof(GIFGraphicControlExtension); 747 806 stream.Read(GIFGraphicControlExtension, mincount); 807 GIFGraphicControlExtension.delaytime := LEtoN(GIFGraphicControlExtension.delaytime); 748 808 749 809 if GIFGraphicControlExtension.flags and … … 781 841 begin 782 842 stream.Read(GIFScreenDescriptor, sizeof(GIFScreenDescriptor)); 843 GIFScreenDescriptor.Width := LEtoN(GIFScreenDescriptor.Width); 844 GIFScreenDescriptor.Height := LEtoN(GIFScreenDescriptor.Height); 783 845 FWidth := GIFScreenDescriptor.Width; 784 846 FHeight := GIFScreenDescriptor.Height;
Note:
See TracChangeset
for help on using the changeset viewer.