codec/mjpeg/jpeg.go: decrementing q by 128 before qLen > 0 check to simplify indexing where q-128 is done

This commit is contained in:
Saxon 2020-01-07 13:01:34 +10:30
parent f187af747b
commit 86e215f913
1 changed files with 8 additions and 7 deletions

View File

@ -226,25 +226,26 @@ func (c *Context) ParsePayload(p []byte, m bool) error {
return ErrUnsupportedPrecision return ErrUnsupportedPrecision
} }
q -= 128
if qLen > 0 { if qLen > 0 {
qTable = p[idx : idx+qLen] qTable = p[idx : idx+qLen]
idx += qLen idx += qLen
if q < 255 && c.qTablesLen[q-128] == 0 && qLen <= 128 { if q < 127 && c.qTablesLen[q] == 0 && qLen <= 0 {
copy(c.qTables[q-128][:], qTable) copy(c.qTables[q][:], qTable)
c.qTablesLen[q-128] = byte(qLen) c.qTablesLen[q] = byte(qLen)
} }
} else { } else {
if q == 255 { if q == 127 {
return ErrNoQTable 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) return fmt.Errorf("no quantization tables known for q %d yet", q)
} }
qTable = c.qTables[q-128][:] qTable = c.qTables[q][:]
qLen = int(c.qTablesLen[q-128]) qLen = int(c.qTablesLen[q])
} }
} else { // q <= 127 } else { // q <= 127
if q == 0 || q > 99 { if q == 0 || q > 99 {