1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00

Process animated images singlethreaded

This commit is contained in:
DarthSim 2020-07-01 19:26:20 +06:00
parent 616ec996b3
commit 73a5d794f3
2 changed files with 4 additions and 52 deletions

View File

@ -1,39 +0,0 @@
package main
import "sync"
type panicGroup struct {
wg sync.WaitGroup
errOnce sync.Once
err error
}
func (g *panicGroup) Wait() error {
g.wg.Wait()
return g.err
}
func (g *panicGroup) Go(f func() error) {
g.wg.Add(1)
go func() {
defer g.wg.Done()
defer func() {
if r := recover(); r != nil {
if err, ok := r.(error); ok {
g.errOnce.Do(func() {
g.err = err
})
} else {
panic(r)
}
}
}()
if err := f(); err != nil {
g.errOnce.Do(func() {
g.err = err
})
}
}()
}

View File

@ -542,13 +542,8 @@ func transformAnimated(ctx context.Context, img *vipsImage, data []byte, po *pro
po.Watermark.Enabled = false
defer func() { po.Watermark.Enabled = watermarkEnabled }()
var errg panicGroup
frames := make([]*vipsImage, framesCount)
defer func() {
// Ensure all frames are processed before freeing
errg.Wait()
for _, frame := range frames {
if frame != nil {
frame.Clear()
@ -563,17 +558,13 @@ func transformAnimated(ctx context.Context, img *vipsImage, data []byte, po *pro
return err
}
frame.CopyMemory()
frames[i] = frame
errg.Go(func() error {
return transformImage(ctx, frame, nil, po, imgtype)
})
}
if err = transformImage(ctx, frame, nil, po, imgtype); err != nil {
return err
}
if err = errg.Wait(); err != nil {
return err
frame.CopyMemory()
}
checkTimeout(ctx)