Advertisement
WarPie90

Stupidly simple image series viewer

Oct 1st, 2023
2,369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.60 KB | None | 0 0
  1. program ImageVideoSeries;
  2. (*
  3.   Views an image series at specified FPS.
  4.   Pauses with space.
  5.   When paused you can rewind or skip forward using arrow-keys.
  6. *)
  7.  
  8. const
  9.   DISK_LOCATION = 'C:\Simba\Images\';
  10.   PAUSE_BUTTON  = VK_SPACE;
  11.   REWIND_FRAME  = VK_LEFT;
  12.   FORWARD_FRAME = VK_RIGHT;
  13.   FPS           = 5;
  14.  
  15. var
  16.   bmp: TMufasaBitmap;
  17.   i: Int32;
  18.   frames: TStringArray;
  19.  
  20. procedure ShowFrame(i: Int32);
  21. begin
  22.   bmp.Init();
  23.   bmp.LoadFromFile(DISK_LOCATION+frames[i]);
  24.   ShowBitmap(bmp);
  25.   bmp.Free();
  26. end;
  27.  
  28. procedure HandleAll();
  29. var
  30.   t: Double;
  31.   isPaused: Boolean;
  32. begin
  33.   t := GetTimeRunning() + 1000 div FPS;
  34.   while GetTimeRunning() < t do
  35.   begin
  36.     isPaused := isKeyDown(PAUSE_BUTTON);
  37.     while isKeyDown(PAUSE_BUTTON) do Sleep(1);
  38.  
  39.     if isPaused then
  40.     begin
  41.       while not isKeyDown(PAUSE_BUTTON) do
  42.       begin
  43.         //check for rewinding
  44.         if isKeyDown(REWIND_FRAME) then
  45.         begin
  46.           WriteLn('<< [frame='+ToStr(i-1)+']');
  47.           while isKeyDown(REWIND_FRAME) do Sleep(1);
  48.           i := Max(0,i-1);
  49.           ShowFrame(i);
  50.         end;
  51.  
  52.         if isKeyDown(FORWARD_FRAME) then
  53.         begin
  54.           WriteLn('>> [frame='+ToStr(i+1)+']');
  55.           while isKeyDown(FORWARD_FRAME) do Sleep(1);
  56.           i := Min(i+1, High(frames));
  57.           ShowFrame(i);
  58.         end;
  59.         Sleep(1);
  60.       end;
  61.       while isKeyDown(PAUSE_BUTTON) do Sleep(1);
  62.     end;
  63.     Sleep(1);
  64.   end;
  65. end;
  66.  
  67.  
  68. begin
  69.   frames := GetFiles(DISK_LOCATION,'png');
  70.  
  71.   for i:=0 to High(frames) do
  72.   begin
  73.     ShowFrame(i);
  74.     HandleAll();
  75.   end;
  76. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement