1
1
mirror of https://github.com/wader/fq.git synced 2024-11-10 10:11:39 +03:00

gif: Support GIF87a

This commit is contained in:
Mattias Wadman 2021-10-19 01:53:37 +02:00
parent b643e22877
commit 6ff5acae03
2 changed files with 16 additions and 9 deletions

View File

@ -53,7 +53,8 @@ func fieldColorMap(d *decode.D, name string, bitDepth int) {
func gifDecode(d *decode.D, in interface{}) interface{} {
d.Endian = decode.LittleEndian
d.FieldValidateUTF8("header", "GIF89a")
d.FieldValidateUTF8Any("header", 6, []string{"GIF87a", "GIF89a"})
d.FieldU16("width")
d.FieldU16("height")
gcpFollows := d.FieldBool("gcp_follows")

View File

@ -727,25 +727,31 @@ func (d *D) FieldValidateUTF8Fn(name string, v string, fn func() string) {
}
}
func (d *D) FieldValidateUTF8(name string, v string) {
func (d *D) FieldValidateUTF8Any(name string, nBytes int, vs []string) {
pos := d.Pos()
found := false
s := d.FieldStrFn(name, func() (string, string) {
nBytes := len(v)
str, err := d.TryUTF8(nBytes)
if err != nil {
panic(IOError{Err: err, Name: name, Op: "FieldValidateUTF8", Size: int64(nBytes) * 8, Pos: d.Pos()})
}
s := "Correct"
if str != v {
s = "Incorrect"
for _, v := range vs {
if v == str {
found = true
return str, "Correct"
}
}
return str, s
return str, "Incorrect"
})
if s != v {
panic(ValidateError{Reason: fmt.Sprintf("expected %s found %s", v, s), Pos: pos})
if !found {
panic(ValidateError{Reason: fmt.Sprintf("expected any of %v found %s", vs, s), Pos: pos})
}
}
func (d *D) FieldValidateUTF8(name string, v string) {
d.FieldValidateUTF8Any(name, len(v), []string{v})
}
func (d *D) ValidateAtLeastBitsLeft(nBits int64) {
bl := d.BitsLeft()
if bl < nBits {