mirror of
https://github.com/golang/go
synced 2024-11-22 05:14:40 -07:00
image: use built-in clear to simplify code
Change-Id: Id34936a115baaf61e4268582c6d9a2027494c385
GitHub-Last-Rev: 5fe455b7d2
GitHub-Pull-Request: golang/go#66244
Reviewed-on: https://go-review.googlesource.com/c/go/+/570555
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
This commit is contained in:
parent
e3d4491ad6
commit
ed08d01dc3
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user