diff --git a/codec/h264/h264dec/cavlc.go b/codec/h264/h264dec/cavlc.go index e1932548..9400ff43 100644 --- a/codec/h264/h264dec/cavlc.go +++ b/codec/h264/h264dec/cavlc.go @@ -127,3 +127,21 @@ func parseLevelInformation(br *bits.BitReader, totalCoeff, trailingOnes int) ([] } return levelVal, nil } + +// combineLevelRunInfo combines the level and run information obtained prior +// using the process defined in section 9.2.4 of the specifications and returns +// the corresponding coeffLevel list. +func combineLevelRunInfo(levelVal, runVal []int, totalCoeff int) []int { + coeffNum := -1 + i := totalCoeff - 1 + var coeffLevel []int + for j := 0; j < totalCoeff; j++ { + coeffNum += runVal[i] + 1 + if coeffNum >= len(coeffLevel) { + coeffLevel = append(coeffLevel, make([]int, (coeffNum+1)-len(coeffLevel))...) + } + coeffLevel[coeffNum] = levelVal[i] + i++ + } + return coeffLevel +}