alpha perfomance fix
This commit is contained in:
@@ -9,6 +9,7 @@ type V210AGenerator struct {
|
||||
width int
|
||||
height int
|
||||
fillSize int
|
||||
fillBase []byte
|
||||
alphaBase []byte
|
||||
}
|
||||
|
||||
@@ -17,6 +18,7 @@ var _ FrameGenerator = (*V210AGenerator)(nil)
|
||||
func NewV210AGenerator(
|
||||
fill FrameGenerator,
|
||||
width, height uint,
|
||||
fillDynamic bool,
|
||||
) (*V210AGenerator, error) {
|
||||
if fill == nil {
|
||||
return nil, fmt.Errorf("v210a: fill generator is nil")
|
||||
@@ -38,6 +40,12 @@ func NewV210AGenerator(
|
||||
if err := fillAlphaPlane(g.alphaBase, g.width, g.height, alphaOpaque); err != nil {
|
||||
return nil, fmt.Errorf("v210a: initialize alpha plane: %w", err)
|
||||
}
|
||||
if !fillDynamic {
|
||||
g.fillBase = make([]byte, g.fillSize)
|
||||
if err := fill.GenerateFrame(g.fillBase, 0); err != nil {
|
||||
return nil, fmt.Errorf("v210a: initialize static fill: %w", err)
|
||||
}
|
||||
}
|
||||
return g, nil
|
||||
}
|
||||
|
||||
@@ -47,8 +55,10 @@ func (g *V210AGenerator) GenerateFrame(dst []byte, frameIndex int) error {
|
||||
return fmt.Errorf("v210a: destination is too small: got %d bytes, need %d", len(dst), need)
|
||||
}
|
||||
|
||||
if err := g.fill.GenerateFrame(dst[:g.fillSize], frameIndex); err != nil {
|
||||
return fmt.Errorf("v210a: generate fill frame %d: %w", frameIndex, err)
|
||||
if g.fillBase != nil {
|
||||
copy(dst[:g.fillSize], g.fillBase)
|
||||
} else if err := g.fill.GenerateFrame(dst[:g.fillSize], frameIndex); err != nil {
|
||||
return fmt.Errorf("v210a: generate dynamic fill frame %d: %w", frameIndex, err)
|
||||
}
|
||||
alpha := dst[g.fillSize:need]
|
||||
copy(alpha, g.alphaBase)
|
||||
|
||||
Reference in New Issue
Block a user