mIRC Home    About    Download    Register    News    Help

Print Thread
N
NrWarren
NrWarren
N
I was trying to make use of the new $pic().frames and
$pic().delay features for GIF images.

Seems that it worked properly for "some" gifs, but other
gifs, /drawpic and $pic do not seem to be working.

I am thinking that it must have to do with maybe
some gif's being encoded differently. i will have to look
into what the differences are for the files.

N
NrWarren
NrWarren
N
actually, i think this may be a false alarm...
i think my test .gif file was copied improperly from a website.

N
NrWarren
NrWarren
N
Here is the script I made to animate gifs.
Works pretty well. Thanks khaled!

(problem was websites not allowing proper saving of gifs)

Code:
; Opens window for GIF images.
;
; Usage:
; //tenor loop $qt($mircdir\tenor.gif)
; //tenor $qt($mircdir\tenor2.gif) 
; 
;  $tenor($qt($mircdir\scripts\tenor.gif)) 
;  Returns <id> <frames>
; 

alias tenor {
  ; Set Unique ID for GIF.
  ; ------------------------
  var %id $rand(1,999999)

  ; Loop in Existing Window.
  ; ---------------------------------------
  if (loop. isin $1) {
    var %id $gettok($1,2,46)
    var %loop $+(loop.,%id)
    tokenize 32 $2- 
  }

  ; Check for existing GIF.
  ; ------------------------
  if (loop == $1) { 
    ; First Loop.
    ; -------------
    tokenize 32 $2- 
    var %loop $+(loop.,%id)

  }


  ; Check for GIF.
  ; ----------------
  var %tenor.file $$1
  if ($exists($1) == $false) { 
    echo -s > No such file: %tenor.file
    return 
  }

  ; Set GIF properties.
  ; ---------------------
  var %tenor.w $calc($pic($$1-).width +155) 
  var %tenor.h $calc($pic($$1-).height +155)

  ; Rescale GIF (if too small)
  ; ---------------------------
  if (%tenor.w < 500) { 
    inc %tenor.w %tenor.w 
    inc %tenor.h %tenor.h
  }

  var %tenor.frames $calc($pic($$1-).frames -1) 
  var %tenor.win $+(@tenor,.,%id)


  ; Setup Window and Check for excessive frames.
  ; ----------------------------------------------
  window -pk0 %tenor.win $iif($window(%tenor.win).x == $null,-1,$v1) $iif($window(%tenor.win).y == $null,-1,$v1) %tenor.w %tenor.h

  if (%tenor.frames > 150) { 
    var %tenor.frames 150
  } 
  titlebar %tenor.win ( $+ %tenor.frames Frames)

  var %tenor.delay $pic($$1-).delay

  ; Draw GIF frames.
  ; ------------------

  var %i 1
  while (%i < %tenor.frames) {
    inc %i
    .timerTENOR. [ $+ [ %id ] ] [ $+ . ] [ $+ [ %i ] ] -m 1 $calc(%tenor.delay * %i) /drawpic -os %tenor.win 0 0 $calc(%tenor.w -20) $calc(%tenor.h -25) %i $$1- 
  }
  if (%loop != $null) { 
    .timerTENOR. [ $+ [ %id ] ] -m 1 $calc(%tenor.delay * (%i +1)) /tenor %loop $1-
  }
  return %id %tenor.frames
} 

on *:close:@: {
  .timerTENOR. [ $+ [ $gettok($target,2,46) ] ] [ $+ * ] off
}


Last edited by NrWarren; 14/12/18 09:41 AM.
Joined: Jul 2006
Posts: 4,062
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,062
It seems to me that $pic().delay is incomplete, it looks like $pic().delay is looking at the first frame and looking for the delay for that frame (or something like that).

However, I'm not sure, but it seems that GIF internal structure rather have a different delay per frame.

I'm testing with a gif created by the website lichess.org where the gif are successive frames of the various chess moves of a chess game, those gif have a starting delay of 0 but subsequent frames' delay are 400ms and it's impossible to get that 400 ms currently.
looks like $pic().delay should be extended to $pic(,Nth).delay, returns the delay of the next Nth frame

Short code I used to test:

alias mayo {
window -depo @test 0 0 $window(-2).w $window(-2).h
drawgif @test 0 0 0 C:\Users\Ouims\Downloads\gm1.gif
}
/drawgif ;@win x y Nth_icon path
alias drawgif var %t $ticksqpc | .timerdrawgif $+ %t $pic($5-).frames $pic($5-).delay drawpic -fo $unsafe($1-4) $!calc($pic( $unsafe($5-) ).frames - $!timer(drawgif $!+ %t ).reps - 1) $unsafe($5-)

You can grab such a gif by going to any game, for example https://lichess.org/93xDn2Tq/white -> share and export (down below) -> save as gif


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 3,907
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 3,907
It looks like you are only using the delay from the first frame in your timer.

See the following script for an example that uses the delay per frame. Type /test to start the script. The script downloads/uses the animated mIRC icon made some years ago that has multiple variable delays.

Code
test {
  %fname = $getdir $+ mircnow5.gif
  echo fname: %fname
  if ($exists(%fname)) {
    showgif
    return
  }
  var %url = https://www.mirc.com/images/mircnow5.gif
  echo urlget: $urlget(%url,gf,%fname,showgif)
}
showgif {
  if (!$exists(%fname)) return

  %icons = $pic(%fname).icons
  echo icons: %icons

  if (%icons > 0) {
    %frames = $pic(%fname).frames
    echo frames: %frames

    if (%frames > 0) {
      %w = $calc($pic(%fname).width + 20)
      %h = $calc($pic(%fname).height + 20)

      window -pf @test 10 10 %w %h
      drawrect -fr @test $rgb(255,255,255) 1 0 0 %w %h

      %i = 0
      .timergif -m 1 0 showframe
    }
  }
}
showframe {
  if (!$window(@test)) return

  drawrect -nfr @test $rgb(255,255,255) 1 0 0 %w %h
  drawpic -to @test $rgb(0,255,0) 10 10 %i %fname

  %delay = $pic(%fname,%i).delay
  echo i: %i delay: %delay
  .timergif -m 1 %delay showframe

  inc %i
  if (%i >= %frames) %i = 0
}

Joined: Jul 2006
Posts: 4,062
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,062
Ah it's already a feature, I didn't check the official help file and did not check unofficial help file carefully enough, thanks.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2006
Posts: 4,062
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,062
Also, why did you make /drawpic's Nth icon and Mth frames 0 based index ? wouldn't it have been better for scripter to have that synched with $pic()'s N and M value ?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 3,907
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 3,907
Quote
why did you make /drawpic's Nth icon and Mth frames 0 based index ?
Ah, grasshopper, you are asking a "why" question, about a feature implemented long ago. There is no way to know. To find the answer, we would need to time-travel through 30 years of development history and take note of the different times that $pic()/drawpic/etc. were added/updated/extended. I am going to take a punt and say it probably seemed like a jolly good idea at the time :-)

Joined: Jul 2006
Posts: 4,062
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,062
It was in 2018 in 7.53, I guess that seems like yesterday when it's 8 years. It would be madness to implement something that seems like a bad idea crazy so I'll guess that's because the underlying C implementation is 0 based and nobody objected.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2012
Posts: 388
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 388
Originally Posted by Khaled
To find the answer, we would need to time-travel through 30 years of development history ... :-)
     [Linked Image from i.ibb.co]
     Wow! Let's go, Back to the Future... set the timer to ~ 1995 year!


🌐 https://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Joined: Jul 2006
Posts: 4,062
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,062
After looking at $pic().delay a bit more this evening, I found some issues.

I used https://imagy.app/animated-image-analyzer/ to analyse my gif, you can try with my gif here https://www.dropbox.com/scl/fi/i1th...rlkey=e240bdtipajt34r7y1w41u62o&dl=0

This code use $pic(file,N).delay with N index being 0-based ($calc(%a -1)), more about that later. In the debug, I'll include the value from the website
//var -s %g C:\Users\Ouims\Downloads\gm1.gif,%a 1,%b $pic(%g).frames | while (%a <= %b) { echo -sg frame %a delay : $pic(%g,$calc(%a -1)).delay | inc %a }

Quote
* Set %g to C:\Users\Ouims\Downloads\gm1.gif
-
* Set %a to 1
-
* Set %b to 149
frame 1 delay : 0 vs 100
frame 2 delay : 0 vs 100
frame 3 delay : 400 vs 400
frame 4 delay : 0 vs 100
frame 5 delay : 400 vs 400
frame 6 delay : 0 vs 100
frame 7 delay : 400 vs 400
frame 8 delay : 0 vs 100
frame 9 delay : 400 vs 400
frame 10 delay : 0 vs 100
frame 11 delay : 400 vs 400
frame 12 delay : 0 vs 100
frame 13 delay : 400 vs 100
...
frame 22 delay : 320 vs 320
frame 23 delay : 0 vs 100
frame 24 delay : 450 vs 450
...
frame 149 delay : 10 vs 10

1) Using N as a 0 based index is the only way to align my result with the website, if I make it 1 based, there's an off by one shift. I'm not sure if this is a bug or if it's intended because you didn't correct me when I stated otherwise, and it's against the fact that identifiers' N value are normally all 1-based index.

2)Whenever the value should be 100, mIRC reports 0, but for any other value tested in this gif, mIRC is correct... EVEN for the last frame 149 with the delay of 10ms instead of 100ms, which mIRC gets correctly.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 3,907
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 3,907
1) I see you are still clinging desperately to the "why" :-) It certainly looks like it was implemented to use a zero index.

2) Those frames have no delay specified. For frames that have no delay specified, different applications, sites, gif analyzers, etc. will return whatever default number they want. Some use a minimum of a 100ms delay to slow down the gif animation. mIRC will return zero because... no delay has been specified 👍

Joined: Jul 2006
Posts: 4,062
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,062
Ah ok, I couldn't tell there was no delay specified internally. You might saw me coming but would it be possible to change it to return $null so that the scripter can choose the default value himself ?
I'm not clinging to anything, I'm trying to make something work 👍


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 3,907
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 3,907
Quote
would it be possible to change it to return $null
This would break all gif-related scripts that use the returned delay value. As you know, if a feature has been in place for a long time, I will very rarely change it as it could break backward compatibility, which it would in this case.

Joined: Jul 2006
Posts: 4,062
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,062
Then a .edelay prop returning $true if the delay is empty/notspecified ?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 3,907
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 3,907
The Windows GDI+ library cannot tell when a GIF frame does not have a delay specified. It returns a BYTE array for frame delays with values starting at zero. The GIF98a standard actually says that if a delay is not specified, the GIF should be animated without delay, ie. a zero delay. The treating of "no delay specified" as different delay values by different browsers, applications, websites, etc. is just down to the developer of the application, eg. every browser uses a different value for "no delay specified" or even delays that are too small. I believe it was originally a way of handling broken GIFs by inserting minimum delays between frames to avoid excess CPU usage. Basically, if a frame has no delay specified, it is correct to assume that the delay should be zero.

Aaand... I think we are done with this particular discussion. I am now off to have a nice morning walk in the park with my dog :-) Enjoy your weekend everyone.

Joined: Jan 2012
Posts: 388
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 388
Originally Posted by Khaled
I am now off to have a nice morning walk in the park with my dog :-)
Will there be a photo shoot with your dog, taken during that nice morning walk in a beautiful park? :-D
Preferably It is advisable to combine everything into one GIF file, so we can play the animation in mIRC using the code: #Post273892
     [Linked Image from i.ibb.co]


🌐 https://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples

Link Copied to Clipboard