Decode multiple graphic controls in a GIF

This commit is contained in:
Nigel Tao committed 2019-05-12 22:02:39 +10:00
1 parent 5bea867f72
commit b1ff27fded
6 files changed
+89 -16

No files matched your search

+23 -3
View File
@@ -513,9 +513,10 @@ var gifGlobals struct {
func stateGif(line string) (stateFunc, error) {
const (
cmdB = "bytes "
cmdL = "lzw "
cmdLC = "loopCount "
cmdB = "bytes "
cmdGCD = "graphicControlDuration "
cmdL = "lzw "
cmdLC = "loopCount "
)
outer:
switch {
@@ -547,6 +548,25 @@ outer:
}
return stateGif, nil
case strings.HasPrefix(line, cmdGCD):
s := line[len(cmdGCD):]
if !strings.HasSuffix(s, "ms") {
break
}
s = s[:len(s)-2]
duration, s, ok := parseNum(s)
if !ok || s != "" {
break
}
duration /= 10 // GIF's unit of time is 10ms.
out = append(out,
0x21, 0xF9, 0x04, 0x00,
uint8(duration>>0),
uint8(duration>>8),
0x00, 0x00,
)
return stateGif, nil
case strings.HasPrefix(line, cmdL):
s := line[len(cmdL):]
litWidth, s, ok := parseNum(s)