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 {