From 86e215f9130bd1fe5e5682564fcf779a2356ce70 Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 7 Jan 2020 13:01:34 +1030 Subject: [PATCH] codec/mjpeg/jpeg.go: decrementing q by 128 before qLen > 0 check to simplify indexing where q-128 is done --- codec/mjpeg/jpeg.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/codec/mjpeg/jpeg.go b/codec/mjpeg/jpeg.go index be3c648c..da15f64d 100644 --- a/codec/mjpeg/jpeg.go +++ b/codec/mjpeg/jpeg.go @@ -226,25 +226,26 @@ func (c *Context) ParsePayload(p []byte, m bool) error { return ErrUnsupportedPrecision } + q -= 128 if qLen > 0 { qTable = p[idx : idx+qLen] idx += qLen - if q < 255 && c.qTablesLen[q-128] == 0 && qLen <= 128 { - copy(c.qTables[q-128][:], qTable) - c.qTablesLen[q-128] = byte(qLen) + if q < 127 && c.qTablesLen[q] == 0 && qLen <= 0 { + copy(c.qTables[q][:], qTable) + c.qTablesLen[q] = byte(qLen) } } else { - if q == 255 { + if q == 127 { return ErrNoQTable } - if c.qTablesLen[q-128] == 0 { + if c.qTablesLen[q] == 0 { return fmt.Errorf("no quantization tables known for q %d yet", q) } - qTable = c.qTables[q-128][:] - qLen = int(c.qTablesLen[q-128]) + qTable = c.qTables[q][:] + qLen = int(c.qTablesLen[q]) } } else { // q <= 127 if q == 0 || q > 99 {