2016年2月24日水曜日

GIMP AnimStack 紹介 (1) 手始めに

GIMP 2.8 系の特徴は、新たに取り入れられた レイヤーグループ 機能ですね。
使っていますか?、 皆さん?。
そう、この機能をフルに活用したスクリプト Script-Fu AnimStack を紹介します。
GIMP で GIF Animation を作成・編集する時に活躍しそうな 奴 です。  version 2.8 以上限定。


アニメーションを作成して行くと、どうしても、コマ(レイヤー Frame)数が多く成り勝ちです。
何十レイヤーのものは ざら で、数百にも及ぶ 大作 すら あります。
これを編集して行く作業は 大変 です。
冷静に作業しなければ、とんでもない失敗 に遭遇します。
特に、眠い目を擦りながらの時は要注意!です。  私にもその経験があります ... 。 ふぅ。

この部分を、レイヤー名に指定した語句から編集操作を行うのが AnimStack です。  あっ、Script-Fu ですよ。.

そう、このスクリプトは、 ちょっと、変わっています。
他の多くのもの (Script-Fu) が、 
画像やレイヤーを加工する際の 変数(パラメータ 選択指定可能な値)を ポップアップするダイアログ から指定するのですが、
AnimStack は、レイヤー名に書き加えられた 語句 を元に、画像操作 します。
謂わば、ユーザーインターフェイス部分が、 対話式でなく、 コマンドライン処理的 になっているのです。
最初のポイントとして、この事 (操作方法) は 十分に 理解して置いて下さい。


では、一番最初に、出来上がっている GIF Animation のコマの経過時間を操作する事から始めて見ましょう。
         AnimStack は Animtion 作成の全体をカバーするものです。 これから書く事は、ほんの一部の機能の紹介になります。

通常、GIMP では、100ms (1秒に 10 コマ 10fps)のコマ間隔になっているのは、皆さん、ご存知と思います。
これを、一律に、200ms とかに変更するのも、GIMP の GIF エクスポート機能で賄えます。
しかし、GIF 最適化 を行うと、同じ(変化のない)コマが纏められ、各 Frame (コマ)の時間が異なる場合もあります。
また、特有の Frame のみ、表示時間を長く取りたい場合もあります。
そんな時には、これ迄、一々、レイヤー名を変更していました。 例: frame#nn (100ms)(combine) > frame#nn (220ms)(combine)
この作業は、作成の終盤でもあり、ボケ掛けた頭で作業していると、ケアレスミスを誘発し易いのです。


仮に、全ての Frame が 100ms で統一されている GIF ファイルを対象に説明します。
最初に既定の画像があり、それに combine で Frame の変遷 が乗るもの とします。

尚、 このスクリプトは2バイト文字(日本語 漢字) を理解しません。  レイヤー名にそれが含まれているとエラーを吐きます。
最新版の version 0.62 以降は この問題は解消されていますので、この留意点は不要です。 *3.
       詳しくは後述しますので、 文章を読みながら実行は とりあえず しないで!。
       どうしても、試して見たい! と言う方は、レイヤー名の 全角を 全て 半角 に書き換えてから にして下さい。.



1.画像モードの変更
GIF ファイルは インデックスモードになっている事と思います。  256 色の世界。
このままでは、AnimStack でハンドリング出来ないので、 画像モードを RGB に切り替え ます。


2.コマンドを追加
GIF Animation のファイルを開き、 一番下のレイヤーの更に下に 透明背景のレイヤーを追加します。
そして、 レイヤー名を 以下の様に 変更します。
xxx [noop] [-delay:200]     注: xxx に日本語は含めないで下さい。
 [ ] で囲まれた部分がコマンドに相当します。  tag と呼ばれていますね。
複数の記述が可能で、 半角スペースを先頭に区切ります。
noop は、きっと、 No Operation no-op の略でしょう。  更に no と短縮しての記述も可能です。
-delay:200 は 200ms の表示時間に設定し直す と言う意味で、 大事なのは、最初の1レイヤー(Frame)は除外されると言う事。
xxx [noop] [-0-5;delay:300]
最初の - に続けて 数字と ; を入れると範囲指定が可能です。  ; を忘れずに!
数字は 0 基準 なので、1枚目は 0 、6枚目は 5 となります。  0-5 は1枚目から6枚目まで と言う意味です。

同様に、 /2 は 0 から始まる偶数(奇数枚目の Frame)、 1/2 は 1 から始まる奇数(偶数枚目の Frame)。
/n は n Frame 毎。  m/n は n Frame 毎の m 番目 (m<n)。
1,5 は 2枚目と6枚目の Frame 。  , が複数の範囲を連結して指定する 印 です。
6- は 7枚目から後の全て。


3.コマンドを実行
こうして、指定したコマンドは、
フィルター(F) > アニメーション(A) のメニュー項目に登録された Process AnimStack tags を押す事で、
実行されます。  この場合、レイヤー名のコマ間隔(経過時間)が変更されます。.

アンドゥ機能を活用して、 コマンドを変更しながら、 何回も試す事が可能です。

いざ、OK となれば、 変更された結果を、 別名で保存 (エクスポート)すれば良いのです。



さて、説明本題の冒頭に書いたのですが、 日本語がレイヤー名に入っているとエラーを吐いてまともに動きません。
半角英数の世界が出発点だった GIMP の難しい処ですね。
AnimStack 0.61 を使いたければ、レイヤー名に日本語を含めてはいけません。  語句によっては大丈夫な場合もありますが ... 。.
最新版の version 0.62 以降は この問題は解消されていますので、以下のスクリプトは不要です。 日本語 OK。 *3.
  コマンドを解釈する為に、レイヤー名の語句を分解するのですが、この時、日本語が災いして、間違った解釈をしてしまいます。
  GIMP ではフォルダ名に日本語が使えない点を思い出して下さい。  それと同じです。
  一々、レイヤー名を訂正するのも大変なので、 語句置換を目的に 別のスクリプトを書いています。  只今難航中。.
                               出来上がったら、公開します。  公開!。  
                               公開ページ : GIMP Script-Fu Shiro-AnimStack-GIF-Rename-Layers-Ascii
                                         リンクの無断転載 禁止!。.
                               具体的な置き換え対象の語句については そちらを参照下さい。。
  全ての日本語を半角英数に置き換えるのは徒労なので、アニメーション機能が提供する部分の標準名称に限定しています。

  今回の説明(アニメの表示時間変更)以外でも、同じと思いますので、AnimStack では レイヤー名に日本語は 禁物 です。
  最新版の version 0.62 以降は この問題は解消されていますので、この留意点は不要です。 *3.




AnimStack の Script-Fu の入手は、 最初のページにある DownLoad Link から行えます。
是非、 version が 0.62 以降 であるのを確認してから 入手して下さい。  詳しくは、以下のコメント欄を参照下さい。
 *3.
また、 上記の説明は AnimStack のページにあるリンク先の 動画 で 解説されています。 (英語) 19分52秒近辺から。

   http://registry.gimp.org/node/26501   AnimStack on registry.gimp.org (Download & Tutorials Link) ver 0.61

   

   http://tshatrov.github.io/animstack#_=_  AnimStack on github.io (Download & Tutorials Link) ver 0.62  *4.

   https://www.youtube.com/watch?v=lHKx0g8xEl4&index=2&list=PLiASt6bCYQNCRlWbGrwyPnmJlwIzMziEq
        AnimStack Official Tutorial on YouTube (Chap.5 'Ranges'  from 0h19m52s)



[2016/02/24] 文章一部推敲
[2016/02/25] 語句置換用の Script-Fu 公開
[2016/04/14] AnimStack v.0.62 で日本語完全対応になり、上記問題が解消されたのを反映。 *3.
[2016/08/13] リンクを追加 AnimStack v.0.62 用 *4.   リンク修正が遅くなりました。.

15 件のコメント:

  1. 懸案の日本語英語置換のスクリプトを公開しました。
    本文の説明を試す前に、このスクリプトを稼動させて、レイヤー名を変更して下さい。
    全ての語句を直す訳ではないので、ご確認を!。

    返信削除
  2. 僕はAnimstackの作者です

    Google Searchに見つけた

    日本語文字Animstackが出来ないとひどいバグですわね

    確認しますとフィックス作るかもしれない

    日本語がヘタすみません

    返信削除
    返信
    1. Timofei Shatrov さま コメントありがとうございます。

      わぁ、凄いです。 感激です。 AnimStack の作者さんからコメント戴けるなんて!。
      先ずは、AnimStack と言う 素晴しい Script-Fu を公開なさっている Timofei Shatrov さまに、
      お礼を述べさせて下さい。 ありがとう ございます。

      わざわざ、日本語で翻訳の上、コメント戴けた その お礼 も、併せて 述べさせて戴きます。
      お上手な日本語です。 十分、理解出来ます。

      Script-Fu に限らず、 TinyScheme や 従前の Scheme は 2バイト文字が苦手ですね。
      難問かも知れませんが、解決なさるのを お待ちしたいと思います。
      恐らく、特定の文字のみが、語句分解時に誤判別されているのだと思います。

      削除
    2. To Dear Timofei Shatrov. Thanks to your comment.

      (Trying my comment in Poor English...)

      First. I tell you a special thanks about the great script 'AnimStack'.
      It's so great!!! Useful!!! Powerful!!!
      And I am deeply moved by getting a comment from you, the author of The script.

      GIMP in Japanese language has a trouble on Japanese folder name, caused by 2 byte code.
      Perhaps same trouble, I think.
      The special terms have a error by split characters (?).

      Two Error dialogs were shown.
      GIMP Executing Error Message is "Error: ( : 1) substring: end out of bounds: 31"
      And one more is "Plug-In 'Process AnimStack tags' left image undo in inconsistent state, closing open undo groups."

      If same file changed from 2 byte code to ascii code, the script works correctly.

      Please continue to look after us in the future on the great script.
      Thanks a lot.

      削除
    3. Apologies for not contacting you sooner. I wasn't able to reproduce this bug on my PC. I found a message you sent me on Tumblr but there was no link to a ZIP. It could have been cut off by a spam filter? Can you post this link here?

      削除
    4. To Dear Timofei Shatrov. Thanks to your comment.

      Yes, I can.
      Link URL Is Here.

      https://drive.google.com/open?id=0B2GanJNrLNVxUUltSEZLZFZQa0k

      More Information in ZIP
      400 x 200 px / 5-12 Layers / Layer name in Japanese (GIMP Default)
      Please see ReadMe.txt in ZIP.

      I hope these files can help your work.

      PS; Your Site can not write Link URL in my comment... Sorry.
      (If include link, can not post a comment.)

      削除
    5. To Dear Timofei Shatrov. Thanks to your comment.

      Please hear my poor idea...

      Do 'strbreakup' by key "[", we get "Original layer name","'tag']" and "'tag']" ...
      Then, If each item end with "]", the item is AnimStack Command Strings.
      Do trim last character "]" by using substring function or by retry 'strbreakup'.

      On console, Like this.

      > (define str "レイヤー[noop] [-0-5;delay:300]")
      str
      > str
      "レイヤー[noop] [-0-5;delay:300]"
      > (strbreakup str "[")
      ("レイヤー" "noop] " "-0-5;delay:300]")
      > (cadr (strbreakup str "["))
      "noop] "
      > (car (strbreakup (cadr (strbreakup str "[") ) "]" ))
      "noop"
      > (caddr (strbreakup str "["))
      "-0-5;delay:300]"
      > (car (strbreakup (caddr (strbreakup str "[") ) "]" ))
      "-0-5;delay:300"

      Additional:
      Why 'substring' causes error in Japanese, I don't understand !!!

      削除
    6. I believe I have located the bug. It happens when the following code is executed:

      (animstack-get-disposal-mode "フレーム 2 (100ms) (combine)")

      This function uses Regular Expressions extension of Script-Fu to find where "(combine)" is. Unfortunately the boundaries returned by re-match function are in bytes not the characters, but substring function counts in characters. I think the cause of the bug is the lack of Unicode support in Regular Expressions extension. I'll try to rewrite this function without using this extension.

      The error only happens when using [delay] tag as it is the only tag that calls this function.


      削除
    7. To Dear Timofei Shatrov. Thanks to your comment.

      I read your comment.
      Your comment is very important!!!
      So you teach us that regular expression was due.
      Now, I know that Only "delay" tag causes a trouble in 2 byte code (the Japanese).
      Another tags are correct!!!
      And more more thanks for you to rewrite code in order to resolve a trouble for a rare language like the Japanese.
      Thanks a lot.

      削除
    8. Hello again. I have implemented a fix for this bug. Please try Animstack 0.62 from here:

      https://raw.githubusercontent.com/tshatrov/scriptfu/master/animstack.scm

      Unfortunately registry.gimp.org can't be updated anymore. But my Github https://github.com/tshatrov/scriptfu will always have the latest versions of my scripts.

      削除
    9. To Dear Timofei Shatrov. Thanks to your comment.

      Ohhh, Glad to receive your good comment!!!
      I am very happy.
      I want to try soon, but now I have some trouble that upgrade os from windows7 to windows10.
      Please give me a little time to try the new version.
      I will write an impression about your new version here, surely.

      削除
    10. To Dear Timofei Shatrov. I try now.

      Tagging Layers (ex; Last 3 Layers - RGB Mode)
      フレーム 2 (100ms) (combine)
      背景 (100ms)
      レイヤー [noop] [-delay:200]]

      Then, Execute on AnimStack 0.62
      フレーム 3 (200ms) (combine)
      フレーム 2 (200ms) (combine)
      背景 (100ms)

      Perfect!!! Great!!!
      Thanks a lot.

      削除
  3. To Dear Timofei Shatrov.
    Can I ask you a question in this place? .

    Please teach me how do this.
    Flat three layers (BackGround, MoveObjectLeftToRight and MoveObjectRightToLeft) I have.
    MoveObjectLeftToRight and MoveObjectRightToLeft are out of frame, and appear by time.
    I want to 21 frames in GIF.
    LeftToRight move on frame#2-9, and RightToLeft move on on frame#12-19.
    How write tag on layers with layer name.

    I tried tagging first like this.
    "Frame [*21]"
    "MoveObjectLeftToRight [y=osc:2:10] [copy:2:9] [-move:20:y]" (Layer exists out of left)
    "MoveObjectRightToLeft [y=osc:2:10] [copy:12:19] [-move:-20:y]" (Layer exists out of right)
    "BackGround [bg]"
    But position not reflect on frames...

    I tried a question on your site, no link include, but, cannot send mine.

    返信削除
    返信
    1. I think the error here is that [copy:2:9] doesn't mean the tag works on layers #2-9. The syntax to copy is [copy:limit:position]. This tag always starts working on the layer after it for "limit" layers. So if you need the tag to affect only 8 layers, you use [copy:8] but place it under the first layer that needs to be affected.

      So you should have:

      Frame [*10]
      MoveObjectRightToLeft [y=osc:2:10] [copy:8] [-move:-20:y]
      Frame [*10]
      MoveObjectLeftToRight [y=osc:2:10] [copy:8] [-move:20:y]
      Frame
      "BackGround [bg]"

      The position argument determines where to put the object *within* the animation frame (for example, [copy:8:0] puts it on top like [fg]). In your case it's not necessary. However without position argument [copy] is identical to [bg], so [copy:8] is equivalent to [bg:8].

      Hope that helps.

      削除
    2. To Dear Timofei Shatrov. Thanks to your comment.

      I am happy to receive your answer.
      I did not notice that two separate layers with tag "Frame [*10]".
      The answer is very helpful.
      The correctly tagging result is that just I wanted to.

      Thanks to understand my poor English.

      削除