Ignore:
Timestamp:
Apr 9, 2015, 9:58:36 PM (10 years ago)
Author:
chronos
Message:
  • Fixed: Use csOpaque control style also to Image, PaintBox and OpenGLControl.
  • Modified: Change size of test frame with SpinEdits as delayed using timer.
  • Updated: BRGABitmap package to version 8.1.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgraanimatedgif.pas

    r452 r472  
    3434    FTimeAccumulator: double;
    3535    FCurrentImage, FWantedImage: integer;
     36    FFullAnimationTime: double;
    3637    FPreviousDisposeMode: TDisposeMode;
    3738
     
    4142
    4243    function GetCount: integer;
     44    function GetTimeUntilNextImage: integer;
    4345    procedure Render(StretchWidth, StretchHeight: integer);
    4446    procedure UpdateSimple(Canvas: TCanvas; ARect: TRect;
     
    7072    BackgroundMode: TGifBackgroundMode;
    7173
    72     constructor Create(filename: string);
     74    constructor Create(filenameUTF8: string);
    7375    constructor Create(stream: TStream);
    7476    constructor Create; override;
     
    7880    procedure LoadFromStream(Stream: TStream); override;
    7981    procedure SaveToStream(Stream: TStream); override;
     82    procedure LoadFromFile(const AFilenameUTF8: string); override;
     83    procedure SaveToFile(const AFilenameUTF8: string); override;
    8084    class function GetFileExtensions: string; override;
    8185
     
    97101    property MemBitmap: TBGRABitmap Read GetMemBitmap;
    98102    property CurrentImage: integer Read FCurrentImage Write SetCurrentImage;
     103    property TimeUntilNextImageMs: integer read GetTimeUntilNextImage;
    99104  end;
    100105
     
    114119implementation
    115120
    116 uses BGRABlend;
     121uses BGRABlend, lazutf8classes;
    117122
    118123const
     124  {$IFDEF ENDIAN_LITTLE}
    119125  AlphaMask = $FF000000;
     126  {$ELSE}
     127  AlphaMask = $000000FF;
     128  {$ENDIF}
    120129
    121130type
     
    188197    if not FPaused then
    189198      FTimeAccumulator += (curDate - FPrevDate) * 24 * 60 * 60 * 1000;
     199    if FFullAnimationTime > 0 then FTimeAccumulator:= frac(FTimeAccumulator/FFullAnimationTime)*FFullAnimationTime;
    190200    nextImage := FCurrentImage;
    191201    while FTimeAccumulator > FImages[nextImage].Delay do
     
    279289end;
    280290
    281 constructor TBGRAAnimatedGif.Create(filename: string);
     291function TBGRAAnimatedGif.GetTimeUntilNextImage: integer;
    282292var
    283   Stream: TFileStream;
     293  acc: double;
     294begin
     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;
     307end;
     308
     309constructor TBGRAAnimatedGif.Create(filenameUTF8: string);
     310var
     311  Stream: TFileStreamUTF8;
    284312begin
    285313  inherited Create;
    286314  Init;
    287   Stream := TFileStream.Create(filename, fmOpenRead);
     315  Stream := TFileStreamUTF8.Create(filenameUTF8, fmOpenRead or fmShareDenyWrite);
    288316  LoadFromStream(Stream);
    289317  Stream.Free;
     
    355383end;
    356384
     385procedure TBGRAAnimatedGif.LoadFromFile(const AFilenameUTF8: string);
     386var stream: TFileStreamUTF8;
     387begin
     388  stream := TFileStreamUTF8.Create(AFilenameUTF8,fmOpenRead or fmShareDenyWrite);
     389  try
     390    LoadFromStream(Stream);
     391  finally
     392    Stream.Free;
     393  end;
     394end;
     395
     396procedure TBGRAAnimatedGif.SaveToFile(const AFilenameUTF8: string);
     397var
     398  Stream: TFileStreamUTF8;
     399begin
     400  Stream := TFileStreamUTF8.Create(AFilenameUTF8, fmCreate);
     401  try
     402    SaveToStream(Stream);
     403  finally
     404    Stream.Free;
     405  end;
     406end;
     407
    357408{$HINTS OFF}
    358409procedure TBGRAAnimatedGif.LoadImages(stream: TStream);
     
    458509    stridx:   longint;
    459510    bitbuf, bitsinbuf: longint;
    460     bytbuf:   array[0..255] of byte;
     511    bytbuf:   packed array[0..255] of byte;
    461512    bytinbuf, bytbufidx: byte;
    462513    endofsrc: boolean;
     
    684735  begin
    685736    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);
    686741    if (GIFImageDescriptor.flags and GIFImageDescriptor_LocalColorTableFlag =
    687742      GIFImageDescriptor_LocalColorTableFlag) then
     
    724779    Clear;
    725780    SetLength(FImages, NbImages);
     781    FFullAnimationTime:= 0;
    726782    for i := 0 to Count - 1 do
     783    begin
    727784      FImages[i] := NewImages[i];
     785      FFullAnimationTime += NewImages[i].Delay;
     786    end;
    728787  end;
    729788
     
    746805          mincount := sizeof(GIFGraphicControlExtension);
    747806          stream.Read(GIFGraphicControlExtension, mincount);
     807          GIFGraphicControlExtension.delaytime := LEtoN(GIFGraphicControlExtension.delaytime);
    748808
    749809          if GIFGraphicControlExtension.flags and
     
    781841  begin
    782842    stream.Read(GIFScreenDescriptor, sizeof(GIFScreenDescriptor));
     843    GIFScreenDescriptor.Width := LEtoN(GIFScreenDescriptor.Width);
     844    GIFScreenDescriptor.Height := LEtoN(GIFScreenDescriptor.Height);
    783845    FWidth  := GIFScreenDescriptor.Width;
    784846    FHeight := GIFScreenDescriptor.Height;
Note: See TracChangeset for help on using the changeset viewer.