Add graphicControl disposal to make-artificial
diff --git a/script/make-artificial.go b/script/make-artificial.go
index 4b9c5f6..930bf0c 100644
--- a/script/make-artificial.go
+++ b/script/make-artificial.go
@@ -527,10 +527,10 @@
func stateGif(line string) (stateFunc, error) {
const (
- cmdB = "bytes "
- cmdGCD = "graphicControlDuration "
- cmdL = "lzw "
- cmdLC = "loopCount "
+ cmdB = "bytes "
+ cmdGC = "graphicControl "
+ cmdL = "lzw "
+ cmdLC = "loopCount "
)
outer:
switch {
@@ -562,8 +562,26 @@
}
return stateGif, nil
- case strings.HasPrefix(line, cmdGCD):
- s := line[len(cmdGCD):]
+ case strings.HasPrefix(line, cmdGC):
+ s := line[len(cmdGC):]
+
+ flags := uint8(0)
+ if i := strings.IndexByte(s, ' '); i < 0 {
+ break
+ } else {
+ switch s[:i] {
+ case "animationDisposalNone":
+ flags |= 0x00
+ case "animationDisposalRestoreBackground":
+ flags |= 0x08
+ case "animationDisposalRestorePrevious":
+ flags |= 0x0C
+ default:
+ break outer
+ }
+ s = s[i+1:]
+ }
+
if !strings.HasSuffix(s, "ms") {
break
}
@@ -573,11 +591,16 @@
break
}
duration /= 10 // GIF's unit of time is 10ms.
+
+ transparentIndex := uint8(0)
+
out = append(out,
- 0x21, 0xF9, 0x04, 0x00,
+ 0x21, 0xF9, 0x04,
+ flags,
uint8(duration>>0),
uint8(duration>>8),
- 0x00, 0x00,
+ transparentIndex,
+ 0x00,
)
return stateGif, nil
diff --git a/test/data/artificial/gif-background-color.gif.make-artificial.txt b/test/data/artificial/gif-background-color.gif.make-artificial.txt
index 390cf63..10c4c38 100644
--- a/test/data/artificial/gif-background-color.gif.make-artificial.txt
+++ b/test/data/artificial/gif-background-color.gif.make-artificial.txt
@@ -17,16 +17,14 @@
loopCount 1
-# TODO: graphicControl animationDisposalRestoreBackground 100ms
-bytes 0x21 0xF9 0x04 0x08 0x0A 0x00 0x00 0x00
+graphicControl animationDisposalRestoreBackground 100ms
frame {
frameLeftTopWidthHeight 0 0 2 1
}
lzw 2 0x00 0x01
-# TODO: graphicControl animationDisposalRestoreBackground 200ms
-bytes 0x21 0xF9 0x04 0x08 0x14 0x00 0x00 0x00
+graphicControl animationDisposalRestoreBackground 200ms
frame {
frameLeftTopWidthHeight 2 0 1 1
diff --git a/test/data/artificial/gif-multiple-graphic-controls.gif.make-artificial.txt b/test/data/artificial/gif-multiple-graphic-controls.gif.make-artificial.txt
index c2ec26a..cd36eed 100644
--- a/test/data/artificial/gif-multiple-graphic-controls.gif.make-artificial.txt
+++ b/test/data/artificial/gif-multiple-graphic-controls.gif.make-artificial.txt
@@ -20,8 +20,8 @@
}
}
-graphicControlDuration 200ms
-graphicControlDuration 300ms
+graphicControl animationDisposalNone 200ms
+graphicControl animationDisposalNone 300ms
frame {
frameLeftTopWidthHeight 0 0 1 1