From 132059d26ece95c3bfbf5cc1270687b678eb3ce4 Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 20 Aug 2019 16:18:39 +0930 Subject: [PATCH] codec/h264/h264dec/cabac.go: added binarization process for coded block pattern --- codec/h264/h264dec/cabacenc.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/codec/h264/h264dec/cabacenc.go b/codec/h264/h264dec/cabacenc.go index 224fc529..f9b0cca5 100644 --- a/codec/h264/h264dec/cabacenc.go +++ b/codec/h264/h264dec/cabacenc.go @@ -28,6 +28,7 @@ package h264dec import ( "errors" + "fmt" "math" ) @@ -220,3 +221,23 @@ func subMbTypeBinString(v, slice int) ([]int, error) { return nil, errBadSubMbSliceType } } + +// codedBlockPatternBinString returns the binarization for the syntax element +// coded_block_pattern as defined by section 9.3.2.6 in specifications. +func codedBlockPatternBinString(luma, chroma, arrayType int) ([]int, error) { + p, err := fixedLenBinString(luma, 15) + if err != nil { + return nil, fmt.Errorf("fixed length binarization failed with error: %v", err) + } + + if arrayType == 0 || arrayType == 3 { + return p, nil + } + + s, err := truncUnaryBinString(chroma, 2) + if err != nil { + return nil, fmt.Errorf("truncated unary binarization failed with error: %v", err) + } + + return append(p, s...), nil +}