From 344123b1795401b4f9574df174fb4864ce18c76f Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 25 Sep 2020 23:00:01 +1000 Subject: [PATCH] Add test/data/artificial/gif-transparent-index.gif --- script/make-artificial.go | 53 +++++++++++------- .../data/artificial/gif-transparent-index.gif | Bin 0 -> 89 bytes ...-transparent-index.gif.make-artificial.txt | 36 ++++++++++++ 3 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 test/data/artificial/gif-transparent-index.gif create mode 100644 test/data/artificial/gif-transparent-index.gif.make-artificial.txt diff --git a/script/make-artificial.go b/script/make-artificial.go index 61468e86..9de99abb 100644 --- a/script/make-artificial.go +++ b/script/make-artificial.go @@ -958,40 +958,51 @@ outer: s := line[len(cmdGC):] flags := uint8(0) - if i := strings.IndexByte(s, ' '); i < 0 { - break - } else { - switch s[:i] { - case "animationDisposalNone": + duration := uint32(0) + transparentIndex := uint32(0) + for s != "" { + term := "" + if i := strings.IndexByte(s, ' '); i >= 0 { + term, s = s[:i], s[i+1:] + } else { + term, s = s, "" + } + + const ( + ms = "ms" + trans = "transparentIndex=" + ) + switch { + case term == "animationDisposalNone": flags |= 0x00 - case "animationDisposalRestoreBackground": + case term == "animationDisposalRestoreBackground": flags |= 0x08 - case "animationDisposalRestorePrevious": + case term == "animationDisposalRestorePrevious": flags |= 0x0C + case strings.HasPrefix(term, trans): + num, remaining, ok := parseNum(term[len(trans):]) + if !ok || remaining != "" { + break outer + } + flags |= 0x01 + transparentIndex = num + case strings.HasSuffix(term, ms): + num, remaining, ok := parseNum(term[:len(term)-len(ms)]) + if !ok || remaining != "" { + break outer + } + duration = num / 10 // GIF's unit of time is 10ms. default: break outer } - s = s[i+1:] } - 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. - - transparentIndex := uint8(0) - out = append(out, 0x21, 0xF9, 0x04, flags, uint8(duration>>0), uint8(duration>>8), - transparentIndex, + uint8(transparentIndex), 0x00, ) return stateGif, nil diff --git a/test/data/artificial/gif-transparent-index.gif b/test/data/artificial/gif-transparent-index.gif new file mode 100644 index 0000000000000000000000000000000000000000..a9f0e09a8771bc0b61584a8265c58a58164bf2e0 GIT binary patch literal 89 zcmZ?wbhEHbWMN=rXkuV!U|^WQz_5UUVFLpL!vO|{3l|s|9(?%lLGdRG0~Z4WgAM}& n0|Q7c13N1NBNKBYgW^vXMiB;9hzv6WBLf3F3kxe-BZD;nGM^60 literal 0 HcmV?d00001 diff --git a/test/data/artificial/gif-transparent-index.gif.make-artificial.txt b/test/data/artificial/gif-transparent-index.gif.make-artificial.txt new file mode 100644 index 00000000..96f05c0c --- /dev/null +++ b/test/data/artificial/gif-transparent-index.gif.make-artificial.txt @@ -0,0 +1,36 @@ +# Feed this file to script/make-artificial.go + +make gif + +header + +image { + imageWidthHeight 4 1 + # Four shades of red and then green, cyan, blue, white. + palette { + 0x80 0x00 0x00 + 0x90 0x00 0x00 + 0xA0 0x00 0x00 + 0xB0 0x00 0x00 + 0x00 0xC0 0x00 + 0x00 0xD0 0xD0 + 0x00 0x00 0xE0 + 0xF0 0xF0 0xF0 + } +} + +graphicControl animationDisposalNone 100ms + +frame { + frameLeftTopWidthHeight 0 0 4 1 +} +lzw 7 0x00 0x01 0x02 0x03 + +graphicControl animationDisposalNone 200ms transparentIndex=5 + +frame { + frameLeftTopWidthHeight 0 0 3 1 +} +lzw 7 0x04 0x05 0x06 + +trailer