1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:14:40 -07:00

image: use built-in clear to simplify code

This commit is contained in:
apocelipes 2024-03-11 20:57:41 +09:00
parent 78755f6b8c
commit 5fe455b7d2
5 changed files with 6 additions and 21 deletions

View File

@ -1078,9 +1078,7 @@ func drawPaletted(dst Image, r image.Rectangle, src image.Image, sp image.Point,
// Recycle the quantization error buffers.
if floydSteinberg {
quantErrorCurr, quantErrorNext = quantErrorNext, quantErrorCurr
for i := range quantErrorNext {
quantErrorNext[i] = [4]int32{}
}
clear(quantErrorNext)
}
}
}

View File

@ -406,10 +406,8 @@ func (d *decoder) readImageDescriptor(keepAllFrames bool) error {
// seem OK with this, so we enlarge the palette with
// transparent colors. See golang.org/issue/15059.
p := make(color.Palette, ti+1)
copy(p, m.Palette)
for i := len(m.Palette); i < len(p); i++ {
p[i] = color.RGBA{}
}
i := copy(p, m.Palette)
clear(p[i:])
m.Palette = p
}
}

View File

@ -220,10 +220,7 @@ func encodeColorTable(dst []byte, p color.Palette, size int) (int, error) {
n := log2Lookup[size]
if n > len(p) {
// Pad with black.
fill := dst[3*len(p) : 3*n]
for i := range fill {
fill[i] = 0
}
clear(dst[3*len(p) : 3*n])
}
return 3 * n, nil
}

View File

@ -131,9 +131,7 @@ func (d *decoder) processDHT(n int) error {
}
// Derive the look-up table.
for i := range h.lut {
h.lut[i] = 0
}
clear(h.lut[:])
var x, code uint32
for i := uint32(0); i < lutSize; i++ {
code <<= 1

View File

@ -295,12 +295,6 @@ func filter(cr *[nFilter][]byte, pr []byte, bpp int) int {
return filter
}
func zeroMemory(v []uint8) {
for i := range v {
v[i] = 0
}
}
func (e *encoder) writeImage(w io.Writer, m image.Image, cb int, level int) error {
if e.zw == nil || e.zwLevel != level {
zw, err := zlib.NewWriterLevel(w, level)
@ -359,7 +353,7 @@ func (e *encoder) writeImage(w io.Writer, m image.Image, cb int, level int) erro
e.pr = make([]uint8, sz)
} else {
e.pr = e.pr[:sz]
zeroMemory(e.pr)
clear(e.pr)
}
pr := e.pr