pulls in the latest exif-terminator version with bugfix and performance optimizations (#3583)

This commit is contained in:
kim 2024-11-28 15:14:49 +00:00 committed by GitHub
parent 312cb8b9c7
commit 3cc50491c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 63 additions and 55 deletions

2
go.mod
View file

@ -41,7 +41,7 @@ require (
codeberg.org/gruf/go-sched v1.2.4
codeberg.org/gruf/go-storage v0.2.0
codeberg.org/gruf/go-structr v0.8.11
codeberg.org/superseriousbusiness/exif-terminator v0.9.0
codeberg.org/superseriousbusiness/exif-terminator v0.9.1
github.com/DmitriyVTitov/size v1.5.0
github.com/KimMachineGun/automemlimit v0.6.1
github.com/buckket/go-blurhash v1.1.0

4
go.sum generated
View file

@ -72,8 +72,8 @@ codeberg.org/gruf/go-storage v0.2.0 h1:mKj3Lx6AavEkuXXtxqPhdq+akW9YwrnP16yQBF7K5
codeberg.org/gruf/go-storage v0.2.0/go.mod h1:o3GzMDE5QNUaRnm/daUzFqvuAaC4utlgXDXYO79sWKU=
codeberg.org/gruf/go-structr v0.8.11 h1:I3cQCHpK3fQSXWaaUfksAJRN4+efULiuF11Oi/m8c+o=
codeberg.org/gruf/go-structr v0.8.11/go.mod h1:zkoXVrAnKosh8VFAsbP/Hhs8FmLBjbVVy5w/Ngm8ApM=
codeberg.org/superseriousbusiness/exif-terminator v0.9.0 h1:/EfyGI6HIrbkhFwgXGSjZ9o1kr/+k8v4mKdfXTH02Go=
codeberg.org/superseriousbusiness/exif-terminator v0.9.0/go.mod h1:gCWKduudUWFzsnixoMzu0FYVdxHWG+AbXnZ50DqxsUE=
codeberg.org/superseriousbusiness/exif-terminator v0.9.1 h1:8Pss29AVuvljHAYLnZUyoqJp/8IN1cD3Jz30bJbxme8=
codeberg.org/superseriousbusiness/exif-terminator v0.9.1/go.mod h1:gCWKduudUWFzsnixoMzu0FYVdxHWG+AbXnZ50DqxsUE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=

View file

@ -109,17 +109,17 @@ func (v *jpegVisitor) writeSegment(s *jpegstructure.Segment) error {
sizeLen, found := markerLen[s.MarkerId]
if !found || sizeLen == 2 {
sizeLen = 2
l := uint16(len(s.Data) + sizeLen)
if err := binary.Write(w, binary.BigEndian, &l); err != nil {
l := uint16(len(s.Data) + 2)
b := make([]byte, 2)
binary.BigEndian.PutUint16(b, l)
if _, err := w.Write(b); err != nil {
return err
}
} else if sizeLen == 4 {
l := uint32(len(s.Data) + sizeLen)
if err := binary.Write(w, binary.BigEndian, &l); err != nil {
l := uint32(len(s.Data) + 4)
b := make([]byte, 4)
binary.BigEndian.PutUint32(b, l)
if _, err := w.Write(b); err != nil {
return err
}
} else if sizeLen != 0 {

View file

@ -25,17 +25,16 @@
)
const (
riffHeaderSize = 4 * 3
riffHeader = "RIFF"
webpHeader = "WEBP"
exifFourcc = "EXIF"
xmpFourcc = "XMP "
)
var (
riffHeader = [4]byte{'R', 'I', 'F', 'F'}
webpHeader = [4]byte{'W', 'E', 'B', 'P'}
exifFourcc = [4]byte{'E', 'X', 'I', 'F'}
xmpFourcc = [4]byte{'X', 'M', 'P', ' '}
errNoRiffHeader = errors.New("no RIFF header")
errNoWebpHeader = errors.New("not a WEBP file")
errInvalidChunk = errors.New("invalid chunk")
)
type webpVisitor struct {
@ -43,59 +42,68 @@ type webpVisitor struct {
doneHeader bool
}
func fourCC(b []byte) [4]byte {
return [4]byte{b[0], b[1], b[2], b[3]}
}
func (v *webpVisitor) split(data []byte, atEOF bool) (advance int, token []byte, err error) {
// parse/write the header first
if !v.doneHeader {
if len(data) < riffHeaderSize {
// need the full header
// const rifHeaderSize = 12
if len(data) < 12 {
if atEOF {
err = errNoRiffHeader
}
return
}
if fourCC(data) != riffHeader {
if string(data[:4]) != riffHeader {
err = errNoRiffHeader
return
}
if fourCC(data[8:]) != webpHeader {
if string(data[8:12]) != webpHeader {
err = errNoWebpHeader
return
}
if _, err = v.writer.Write(data[:riffHeaderSize]); err != nil {
if _, err = v.writer.Write(data[:12]); err != nil {
return
}
advance += riffHeaderSize
data = data[riffHeaderSize:]
advance += 12
data = data[12:]
v.doneHeader = true
}
// need enough for fourcc and size
if len(data) < 8 {
return
}
size := int64(binary.LittleEndian.Uint32(data[4:]))
if (size & 1) != 0 {
// odd chunk size - extra padding byte
size++
}
// wait until there is enough
if int64(len(data)-8) < size {
return
}
fourcc := fourCC(data)
rawChunkData := data[8 : 8+size]
if fourcc == exifFourcc || fourcc == xmpFourcc {
// replace exif/xmp with blank
rawChunkData = make([]byte, size)
}
if _, err = v.writer.Write(data[:8]); err == nil {
if _, err = v.writer.Write(rawChunkData); err == nil {
advance += 8 + int(size)
for {
// need enough for
// fourcc and size
if len(data) < 8 {
return
}
}
return
size := int64(binary.LittleEndian.Uint32(data[4:]))
if (size & 1) != 0 {
// odd chunk size:
// extra padding byte
size++
}
// wait until there is enough
if int64(len(data)) < 8+size {
return
}
// replace exif/xmp with blank
switch string(data[:4]) {
case exifFourcc, xmpFourcc:
clear(data[8 : 8+size])
}
if _, err = v.writer.Write(data[:8+size]); err != nil {
return
}
advance += 8 + int(size)
data = data[8+size:]
}
}

2
vendor/modules.txt vendored
View file

@ -66,7 +66,7 @@ codeberg.org/gruf/go-storage/s3
# codeberg.org/gruf/go-structr v0.8.11
## explicit; go 1.21
codeberg.org/gruf/go-structr
# codeberg.org/superseriousbusiness/exif-terminator v0.9.0
# codeberg.org/superseriousbusiness/exif-terminator v0.9.1
## explicit; go 1.21
codeberg.org/superseriousbusiness/exif-terminator
# github.com/DmitriyVTitov/size v1.5.0