From 95764ac466d1e6aeaa8c67d8c28c340513353c2d Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 22 Sep 2014 12:52:41 +1000 Subject: [PATCH] vp8l: update comments to match latest spec. The spec change is at https://gerrit.chromium.org/gerrit/#/c/71605/ LGTM=robsc R=robsc CC=golang-codereviews https://golang.org/cl/146910043 --- vp8l/decode.go | 7 ++++--- vp8l/transform.go | 16 ++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/vp8l/decode.go b/vp8l/decode.go index 13fa6d9..ee7afb0 100644 --- a/vp8l/decode.go +++ b/vp8l/decode.go @@ -130,8 +130,9 @@ func (d *decoder) decodeTransform(w int32, h int32) (t transform, newWidth int32 pix[p+2] += pix[p-2] pix[p+3] += pix[p-1] } - // The C code fills in palette entries past the nColors upper limit as - // transparent black. In Go, we re-slice up to 256 4-byte pixels. + // The spec says that "if the index is equal or larger than color_table_size, + // the argb color value should be set to 0x00000000 (transparent black)." + // We re-slice up to 256 4-byte pixels. t.pix = pix[:4*256] } return t, w, nil @@ -530,7 +531,7 @@ func decodeHeader(r io.Reader) (d *decoder, w int32, h int32, err error) { return nil, 0, 0, err } if version != 0 { - return nil, 0, 0, errors.New("vp8l: unsupported version") + return nil, 0, 0, errors.New("vp8l: invalid version") } return d, int32(width), int32(height), nil } diff --git a/vp8l/transform.go b/vp8l/transform.go index f79431c..06543da 100644 --- a/vp8l/transform.go +++ b/vp8l/transform.go @@ -142,7 +142,7 @@ func inversePredictor(t *transform, pix []byte, h int32) []byte { pix[p+2] += avg2(avg2(pix[p-2], pix[top-2]), avg2(pix[top+2], pix[top+6])) pix[p+3] += avg2(avg2(pix[p-1], pix[top-1]), avg2(pix[top+3], pix[top+7])) - case 11: // Select(T, L, TL). + case 11: // Select(L, T, TL). l0 := int32(pix[p-4]) l1 := int32(pix[p-3]) l2 := int32(pix[p-2]) @@ -155,18 +155,18 @@ func inversePredictor(t *transform, pix []byte, h int32) []byte { t1 := int32(pix[top+1]) t2 := int32(pix[top+2]) t3 := int32(pix[top+3]) - t := abs(c0-l0) + abs(c1-l1) + abs(c2-l2) + abs(c3-l3) l := abs(c0-t0) + abs(c1-t1) + abs(c2-t2) + abs(c3-t3) - if t <= l { - pix[p+0] += uint8(t0) - pix[p+1] += uint8(t1) - pix[p+2] += uint8(t2) - pix[p+3] += uint8(t3) - } else { + t := abs(c0-l0) + abs(c1-l1) + abs(c2-l2) + abs(c3-l3) + if l < t { pix[p+0] += uint8(l0) pix[p+1] += uint8(l1) pix[p+2] += uint8(l2) pix[p+3] += uint8(l3) + } else { + pix[p+0] += uint8(t0) + pix[p+1] += uint8(t1) + pix[p+2] += uint8(t2) + pix[p+3] += uint8(t3) } case 12: // ClampAddSubtractFull(L, T, TL).