Independent Submission                                       J. Bankoski
Request for Comments: 6386                                   J. Koleszar
Category: Informational                                       L. Quillio
ISSN: 2070-1721                                               J. Salonen
                                                              P. Wilkins
                                                                   Y. Xu
                                                             Google Inc.
                                                           November 2011
        
Independent Submission                                       J. Bankoski
Request for Comments: 6386                                   J. Koleszar
Category: Informational                                       L. Quillio
ISSN: 2070-1721                                               J. Salonen
                                                              P. Wilkins
                                                                   Y. Xu
                                                             Google Inc.
                                                           November 2011
        

VP8 Data Format and Decoding Guide

VP8数据格式和解码指南

Abstract

摘要

This document describes the VP8 compressed video data format, together with a discussion of the decoding procedure for the format.

本文档介绍了VP8压缩视频数据格式,并讨论了该格式的解码过程。

Status of This Memo

关于下段备忘

This document is not an Internet Standards Track specification; it is published for informational purposes.

本文件不是互联网标准跟踪规范;它是为了提供信息而发布的。

This is a contribution to the RFC Series, independently of any other RFC stream. The RFC Editor has chosen to publish this document at its discretion and makes no statement about its value for implementation or deployment. Documents approved for publication by the RFC Editor are not a candidate for any level of Internet Standard; see Section 2 of RFC 5741.

这是对RFC系列的贡献,独立于任何其他RFC流。RFC编辑器已选择自行发布此文档,并且未声明其对实现或部署的价值。RFC编辑批准发布的文件不适用于任何级别的互联网标准;见RFC 5741第2节。

Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at http://www.rfc-editor.org/info/rfc6386.

有关本文件当前状态、任何勘误表以及如何提供反馈的信息,请访问http://www.rfc-editor.org/info/rfc6386.

Copyright Notice

版权公告

Copyright (c) 2011 IETF Trust and the persons identified as the document authors. All rights reserved.

版权所有(c)2011 IETF信托基金和确定为文件作者的人员。版权所有。

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document.

本文件受BCP 78和IETF信托有关IETF文件的法律规定的约束(http://trustee.ietf.org/license-info)自本文件出版之日起生效。请仔细阅读这些文件,因为它们描述了您对本文件的权利和限制。

Table of Contents

目录

   1. Introduction ....................................................4
   2. Format Overview .................................................5
   3. Compressed Frame Types ..........................................7
   4. Overview of Compressed Data Format ..............................8
   5. Overview of the Decoding Process ................................9
   6. Description of Algorithms ......................................14
   7. Boolean Entropy Decoder ........................................16
      7.1. Underlying Theory of Coding ...............................17
      7.2. Practical Algorithm Description ...........................18
      7.3. Actual Implementation .....................................20
   8. Compressed Data Components .....................................25
      8.1. Tree Coding Implementation ................................27
      8.2. Tree Coding Example .......................................28
   9. Frame Header ...................................................30
      9.1. Uncompressed Data Chunk ...................................30
      9.2. Color Space and Pixel Type (Key Frames Only) ..............33
      9.3. Segment-Based Adjustments .................................34
      9.4. Loop Filter Type and Levels ...............................35
      9.5. Token Partition and Partition Data Offsets ................36
      9.6. Dequantization Indices ....................................37
      9.7. Refresh Golden Frame and Altref Frame .....................38
      9.8. Refresh Last Frame Buffer .................................39
      9.9. DCT Coefficient Probability Update ........................39
      9.10. Remaining Frame Header Data (Non-Key Frame) ..............40
      9.11. Remaining Frame Header Data (Key Frame) ..................41
   10. Segment-Based Feature Adjustments .............................41
   11. Key Frame Macroblock Prediction Records .......................42
      11.1. mb_skip_coeff ............................................42
      11.2. Luma Modes ...............................................42
      11.3. Subblock Mode Contexts ...................................45
      11.4. Chroma Modes .............................................46
      11.5. Subblock Mode Probability Table ..........................47
   12. Intraframe Prediction .........................................50
      12.1. mb_skip_coeff ............................................51
      12.2. Chroma Prediction ........................................51
      12.3. Luma Prediction ..........................................54
   13. DCT Coefficient Decoding ......................................60
      13.1. Macroblock without Non-Zero Coefficient Values ...........61
      13.2. Coding of Individual Coefficient Values ..................61
      13.3. Token Probabilities ......................................63
      13.4. Token Probability Updates ................................68
      13.5. Default Token Probability Table ..........................73
        
   1. Introduction ....................................................4
   2. Format Overview .................................................5
   3. Compressed Frame Types ..........................................7
   4. Overview of Compressed Data Format ..............................8
   5. Overview of the Decoding Process ................................9
   6. Description of Algorithms ......................................14
   7. Boolean Entropy Decoder ........................................16
      7.1. Underlying Theory of Coding ...............................17
      7.2. Practical Algorithm Description ...........................18
      7.3. Actual Implementation .....................................20
   8. Compressed Data Components .....................................25
      8.1. Tree Coding Implementation ................................27
      8.2. Tree Coding Example .......................................28
   9. Frame Header ...................................................30
      9.1. Uncompressed Data Chunk ...................................30
      9.2. Color Space and Pixel Type (Key Frames Only) ..............33
      9.3. Segment-Based Adjustments .................................34
      9.4. Loop Filter Type and Levels ...............................35
      9.5. Token Partition and Partition Data Offsets ................36
      9.6. Dequantization Indices ....................................37
      9.7. Refresh Golden Frame and Altref Frame .....................38
      9.8. Refresh Last Frame Buffer .................................39
      9.9. DCT Coefficient Probability Update ........................39
      9.10. Remaining Frame Header Data (Non-Key Frame) ..............40
      9.11. Remaining Frame Header Data (Key Frame) ..................41
   10. Segment-Based Feature Adjustments .............................41
   11. Key Frame Macroblock Prediction Records .......................42
      11.1. mb_skip_coeff ............................................42
      11.2. Luma Modes ...............................................42
      11.3. Subblock Mode Contexts ...................................45
      11.4. Chroma Modes .............................................46
      11.5. Subblock Mode Probability Table ..........................47
   12. Intraframe Prediction .........................................50
      12.1. mb_skip_coeff ............................................51
      12.2. Chroma Prediction ........................................51
      12.3. Luma Prediction ..........................................54
   13. DCT Coefficient Decoding ......................................60
      13.1. Macroblock without Non-Zero Coefficient Values ...........61
      13.2. Coding of Individual Coefficient Values ..................61
      13.3. Token Probabilities ......................................63
      13.4. Token Probability Updates ................................68
      13.5. Default Token Probability Table ..........................73
        
   14. DCT and WHT Inversion and Macroblock Reconstruction ...........76
      14.1. Dequantization ...........................................76
      14.2. Inverse Transforms .......................................78
      14.3. Implementation of the WHT Inversion ......................78
      14.4. Implementation of the DCT Inversion ......................81
      14.5. Summation of Predictor and Residue .......................83
   15. Loop Filter ...................................................84
      15.1. Filter Geometry and Overall Procedure ....................85
      15.2. Simple Filter ............................................87
      15.3. Normal Filter ............................................91
      15.4. Calculation of Control Parameters ........................95
   16. Interframe Macroblock Prediction Records ......................97
      16.1. Intra-Predicted Macroblocks ..............................97
      16.2. Inter-Predicted Macroblocks ..............................98
      16.3. Mode and Motion Vector Contexts ..........................99
      16.4. Split Prediction ........................................105
   17. Motion Vector Decoding .......................................108
      17.1. Coding of Each Component ................................108
      17.2. Probability Updates .....................................110
   18. Interframe Prediction ........................................113
      18.1. Bounds on, and Adjustment of, Motion Vectors ............113
      18.2. Prediction Subblocks ....................................115
      18.3. Sub-Pixel Interpolation .................................115
      18.4. Filter Properties .......................................118
   19. Annex A: Bitstream Syntax ....................................120
      19.1. Uncompressed Data Chunk .................................121
      19.2. Frame Header ............................................122
      19.3. Macroblock Data .........................................130
   20. Attachment One: Reference Decoder Source Code ................133
      20.1. bit_ops.h ...............................................133
      20.2. bool_decoder.h ..........................................133
      20.3. dequant_data.h ..........................................137
      20.4. dixie.c .................................................138
      20.5. dixie.h .................................................151
      20.6. dixie_loopfilter.c ......................................158
      20.7. dixie_loopfilter.h ......................................170
      20.8. idct_add.c ..............................................171
      20.9. idct_add.h ..............................................174
      20.10. mem.h ..................................................175
      20.11. modemv.c ...............................................176
      20.12. modemv.h ...............................................192
      20.13. modemv_data.h ..........................................193
      20.14. predict.c ..............................................198
      20.15. predict.h ..............................................231
      20.16. tokens.c ...............................................232
      20.17. tokens.h ...............................................242
      20.18. vp8_prob_data.h ........................................243
      20.19. vpx_codec_internal.h ...................................252
        
   14. DCT and WHT Inversion and Macroblock Reconstruction ...........76
      14.1. Dequantization ...........................................76
      14.2. Inverse Transforms .......................................78
      14.3. Implementation of the WHT Inversion ......................78
      14.4. Implementation of the DCT Inversion ......................81
      14.5. Summation of Predictor and Residue .......................83
   15. Loop Filter ...................................................84
      15.1. Filter Geometry and Overall Procedure ....................85
      15.2. Simple Filter ............................................87
      15.3. Normal Filter ............................................91
      15.4. Calculation of Control Parameters ........................95
   16. Interframe Macroblock Prediction Records ......................97
      16.1. Intra-Predicted Macroblocks ..............................97
      16.2. Inter-Predicted Macroblocks ..............................98
      16.3. Mode and Motion Vector Contexts ..........................99
      16.4. Split Prediction ........................................105
   17. Motion Vector Decoding .......................................108
      17.1. Coding of Each Component ................................108
      17.2. Probability Updates .....................................110
   18. Interframe Prediction ........................................113
      18.1. Bounds on, and Adjustment of, Motion Vectors ............113
      18.2. Prediction Subblocks ....................................115
      18.3. Sub-Pixel Interpolation .................................115
      18.4. Filter Properties .......................................118
   19. Annex A: Bitstream Syntax ....................................120
      19.1. Uncompressed Data Chunk .................................121
      19.2. Frame Header ............................................122
      19.3. Macroblock Data .........................................130
   20. Attachment One: Reference Decoder Source Code ................133
      20.1. bit_ops.h ...............................................133
      20.2. bool_decoder.h ..........................................133
      20.3. dequant_data.h ..........................................137
      20.4. dixie.c .................................................138
      20.5. dixie.h .................................................151
      20.6. dixie_loopfilter.c ......................................158
      20.7. dixie_loopfilter.h ......................................170
      20.8. idct_add.c ..............................................171
      20.9. idct_add.h ..............................................174
      20.10. mem.h ..................................................175
      20.11. modemv.c ...............................................176
      20.12. modemv.h ...............................................192
      20.13. modemv_data.h ..........................................193
      20.14. predict.c ..............................................198
      20.15. predict.h ..............................................231
      20.16. tokens.c ...............................................232
      20.17. tokens.h ...............................................242
      20.18. vp8_prob_data.h ........................................243
      20.19. vpx_codec_internal.h ...................................252
        
      20.20. vpx_decoder.h ..........................................263
      20.21. vpx_decoder_compat.h ...................................271
      20.22. vpx_image.c ............................................285
      20.23. vpx_image.h ............................................291
      20.24. vpx_integer.h ..........................................298
      20.25. AUTHORS File ...........................................299
      20.26. LICENSE ................................................301
      20.27. PATENTS ................................................302
   21. Security Considerations ......................................302
   22. References ...................................................303
      22.1. Normative Reference .....................................303
      22.2. Informative References ..................................303
        
      20.20. vpx_decoder.h ..........................................263
      20.21. vpx_decoder_compat.h ...................................271
      20.22. vpx_image.c ............................................285
      20.23. vpx_image.h ............................................291
      20.24. vpx_integer.h ..........................................298
      20.25. AUTHORS File ...........................................299
      20.26. LICENSE ................................................301
      20.27. PATENTS ................................................302
   21. Security Considerations ......................................302
   22. References ...................................................303
      22.1. Normative Reference .....................................303
      22.2. Informative References ..................................303
        
1. Introduction
1. 介绍

This document describes the VP8 compressed video data format, together with a discussion of the decoding procedure for the format. It is intended to be used in conjunction with, and as a guide to, the reference decoder source code provided in Attachment One (Section 20). If there are any conflicts between this narrative and the reference source code, the reference source code should be considered correct. The bitstream is defined by the reference source code and not this narrative.

本文档介绍了VP8压缩视频数据格式,并讨论了该格式的解码过程。其旨在与附件1(第20节)中提供的参考解码器源代码结合使用,并作为指南。如果此叙述与参考源代码之间存在任何冲突,则应认为参考源代码是正确的。比特流由参考源代码定义,而不是此叙述。

Like many modern video compression schemes, VP8 is based on decomposition of frames into square subblocks of pixels, prediction of such subblocks using previously constructed blocks, and adjustment of such predictions (as well as synthesis of unpredicted blocks) using a discrete cosine transform (hereafter abbreviated as DCT). In one special case, however, VP8 uses a Walsh-Hadamard transform (hereafter abbreviated as WHT) instead of a DCT.

与许多现代视频压缩方案一样,VP8基于将帧分解为像素的方形子块、使用先前构造的块预测此类子块以及使用离散余弦变换(以下简称为DCT)调整此类预测(以及合成不可预测的块)。然而,在一种特殊情况下,VP8使用沃尔什-阿达玛变换(以下简称WHT)代替DCT。

Roughly speaking, such systems reduce datarate by exploiting the temporal and spatial coherence of most video signals. It is more efficient to specify the location of a visually similar portion of a prior frame than it is to specify pixel values. The frequency segregation provided by the DCT and WHT facilitates the exploitation of both spatial coherence in the original signal and the tolerance of the human visual system to moderate losses of fidelity in the reconstituted signal.

粗略地说,这样的系统通过利用大多数视频信号的时间和空间一致性来降低数据速率。指定前一帧的视觉相似部分的位置比指定像素值更有效。DCT和WHT提供的频率分离有助于利用原始信号中的空间相干性和人类视觉系统的容忍度,以缓和重建信号中的保真度损失。

VP8 augments these basic concepts with, among other things, sophisticated usage of contextual probabilities. The result is a significant reduction in datarate at a given quality.

VP8增加了这些基本概念,其中包括对上下文概率的复杂使用。结果是在给定质量下,数据速率显著降低。

Unlike some similar schemes (the older MPEG formats, for example), VP8 specifies exact values for reconstructed pixels. Specifically, the specification for the DCT and WHT portions of the reconstruction does not allow for any "drift" caused by truncation of fractions. Rather, the algorithm is specified using fixed-precision integer operations exclusively. This greatly facilitates the verification of the correctness of a decoder implementation and also avoids difficult-to-predict visual incongruities between such implementations.

与一些类似的方案(例如,较旧的MPEG格式)不同,VP8为重建像素指定精确的值。具体而言,重构的DCT和WHT部分的规范不允许由分数截断引起的任何“漂移”。相反,该算法是专门使用固定精度整数运算指定的。这大大有助于验证解码器实现的正确性,还避免了此类实现之间难以预测的视觉不一致。

It should be remarked that, in a complete video playback system, the displayed frames may or may not be identical to the reconstructed frames. Many systems apply a final level of filtering (commonly referred to as postprocessing) to the reconstructed frames prior to viewing. Such postprocessing has no effect on the decoding and reconstruction of subsequent frames (which are predicted using the completely specified reconstructed frames) and is beyond the scope of this document. In practice, the nature and extent of this sort of postprocessing is dependent on both the taste of the user and on the computational facilities of the playback environment.

应当注意,在完整的视频回放系统中,显示的帧可能与重构的帧相同,也可能与重构的帧不同。许多系统在观看之前对重建的帧应用最终级别的过滤(通常称为后处理)。这种后处理对后续帧(使用完全指定的重构帧预测)的解码和重构没有影响,并且超出了本文档的范围。实际上,这种后处理的性质和程度取决于用户的喜好和回放环境的计算设施。

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].

本文件中的关键词“必须”、“不得”、“要求”、“应”、“不应”、“应”、“不应”、“建议”、“可”和“可选”应按照RFC 2119[RFC2119]中所述进行解释。

2. Format Overview
2. 格式概述

VP8 works exclusively with an 8-bit YUV 4:2:0 image format. In this format, each 8-bit pixel in the two chroma planes (U and V) corresponds positionally to a 2x2 block of 8-bit luma pixels in the Y plane; coordinates of the upper left corner of the Y block are of course exactly twice the coordinates of the corresponding chroma pixels. When we refer to pixels or pixel distances without specifying a plane, we are implicitly referring to the Y plane or to the complete image, both of which have the same (full) resolution.

VP8专用于8位YUV 4:2:0图像格式。在该格式中,两个色度平面(U和V)中的每个8位像素在位置上对应于Y平面中的8位luma像素的2x2块;Y块左上角的坐标当然是相应色度像素坐标的两倍。当我们在不指定平面的情况下引用像素或像素距离时,我们暗指的是Y平面或完整图像,两者具有相同的(完整)分辨率。

As is usually the case, the pixels are simply a large array of bytes stored in rows from top to bottom, each row being stored from left to right. This "left to right" then "top to bottom" raster-scan order is reflected in the layout of the compressed data as well.

通常情况下,像素只是从上到下按行存储的一个大字节数组,每行从左到右存储。这种“从左到右”然后“从上到下”的光栅扫描顺序也反映在压缩数据的布局中。

Provision has been made in the VP8 bitstream header for the support of a secondary YUV color format, in the form of a reserved bit.

VP8比特流报头中已规定以保留位的形式支持辅助YUV颜色格式。

Occasionally, at very low datarates, a compression system may decide to reduce the resolution of the input signal to facilitate efficient compression. The VP8 data format supports this via optional upscaling of its internal reconstruction buffer prior to output (this

有时,在非常低的数据速率下,压缩系统可能会决定降低输入信号的分辨率,以促进高效压缩。VP8数据格式通过在输出之前可选地放大其内部重建缓冲区(此

is completely distinct from the optional postprocessing discussed earlier, which has nothing to do with decoding per se). This upsampling restores the video frames to their original resolution. In other words, the compression/decompression system can be viewed as a "black box", where the input and output are always at a given resolution. The compressor might decide to "cheat" and process the signal at a lower resolution. In that case, the decompressor needs the ability to restore the signal to its original resolution.

与前面讨论的可选后处理完全不同,后者与解码本身无关)。此上采样将视频帧恢复为其原始分辨率。换句话说,压缩/解压缩系统可以被视为一个“黑匣子”,其中输入和输出总是以给定的分辨率。压缩机可能决定“欺骗”并以较低的分辨率处理信号。在这种情况下,解压器需要能够将信号恢复到其原始分辨率。

Internally, VP8 decomposes each output frame into an array of macroblocks. A macroblock is a square array of pixels whose Y dimensions are 16x16 and whose U and V dimensions are 8x8. Macroblock-level data in a compressed frame occurs (and must be processed) in a raster order similar to that of the pixels comprising the frame.

在内部,VP8将每个输出帧分解为宏块数组。宏块是Y尺寸为16x16、U和V尺寸为8x8的正方形像素阵列。压缩帧中的宏块级数据以与构成帧的像素的光栅顺序相似的光栅顺序出现(并且必须进行处理)。

Macroblocks are further decomposed into 4x4 subblocks. Every macroblock has 16 Y subblocks, 4 U subblocks, and 4 V subblocks. Any subblock-level data (and processing of such data) again occurs in raster order, this time in raster order within the containing macroblock.

宏块进一步分解为4x4子块。每个宏块有16个Y子块、4个U子块和4个V子块。任何子块级数据(以及对此类数据的处理)再次以光栅顺序出现,这一次是在包含宏块内以光栅顺序出现。

As discussed in further detail below, data can be specified at the levels of both macroblocks and their subblocks.

如下文进一步详细讨论的,可以在宏块及其子块的级别指定数据。

Pixels are always treated, at a minimum, at the level of subblocks, which may be thought of as the "atoms" of the VP8 algorithm. In particular, the 2x2 chroma blocks corresponding to 4x4 Y subblocks are never treated explicitly in the data format or in the algorithm specification.

像素总是至少在子块级别上处理,这可能被认为是VP8算法的“原子”。特别是,与4x4 Y子块相对应的2x2色度块从未在数据格式或算法规范中明确处理。

The DCT and WHT always operate at a 4x4 resolution. The DCT is used for the 16Y, 4U, and 4V subblocks. The WHT is used (with some but not all prediction modes) to encode a 4x4 array comprising the average intensities of the 16 Y subblocks of a macroblock. These average intensities are, up to a constant normalization factor, nothing more than the 0th DCT coefficients of the Y subblocks. This "higher-level" WHT is a substitute for the explicit specification of those coefficients, in exactly the same way as the DCT of a subblock substitutes for the specification of the pixel values comprising the subblock. We consider this 4x4 array as a second-order subblock called Y2, and think of a macroblock as containing 24 "real" subblocks and, sometimes, a 25th "virtual" subblock. This is dealt with further in Section 13.

DCT和WHT始终以4x4分辨率运行。DCT用于16Y、4U和4V子块。WHT(与一些但不是所有预测模式一起)用于编码4x4阵列,该4x4阵列包括宏块的16个Y子块的平均强度。这些平均强度,直到一个恒定的归一化因子,只不过是Y子块的第0个DCT系数。该“更高级别”WHT是这些系数的显式规范的替代,其方式与子块的DCT替代包含子块的像素值的规范的方式完全相同。我们认为这个4x4数组是一个称为Y2的二阶子块,并认为宏块包含24个“真实”子块,有时也有第二十五个“虚拟”子块。这将在第13节中进一步讨论。

The frame layout used by the reference decoder may be found in the file vpx_image.h (Section 20.23).

参考解码器使用的帧布局可在文件vpx_image.h(第20.23节)中找到。

3. Compressed Frame Types
3. 压缩帧类型

There are only two types of frames in VP8.

VP8中只有两种类型的帧。

Intraframes (also called key frames and, in MPEG terminology, I-frames) are decoded without reference to any other frame in a sequence; that is, the decompressor reconstructs such frames beginning from its "default" state. Key frames provide random access (or seeking) points in a video stream.

帧内帧(也称为关键帧,在MPEG术语中称为I帧)在不参考序列中的任何其他帧的情况下被解码;也就是说,解压器从其“默认”状态开始重构这样的帧。关键帧提供视频流中的随机访问(或搜索)点。

Interframes (also called prediction frames and, in MPEG terminology, P-frames) are encoded with reference to prior frames, specifically all prior frames up to and including the most recent key frame. Generally speaking, the correct decoding of an interframe depends on the correct decoding of the most recent key frame and all ensuing frames. Consequently, the decoding algorithm is not tolerant of dropped frames: In an environment in which frames may be dropped or corrupted, correct decoding will not be possible until a key frame is correctly received.

帧间(也称为预测帧,在MPEG术语中称为P帧)参照先前帧进行编码,具体地说,参照直到并包括最近关键帧的所有先前帧。一般来说,帧间的正确解码取决于最近的关键帧和所有后续帧的正确解码。因此,解码算法不能容忍丢弃的帧:在帧可能被丢弃或损坏的环境中,在正确接收到关键帧之前,不可能进行正确解码。

In contrast to MPEG, there is no use of bidirectional prediction. No frame is predicted using frames temporally subsequent to it; there is no analog to an MPEG B-frame.

与MPEG相比,不使用双向预测。没有帧是使用在其之后的帧来预测的;不存在与MPEG B帧的模拟。

Secondly, VP8 augments these notions with that of alternate prediction frames, called golden frames and altref frames (alternative reference frames). Blocks in an interframe may be predicted using blocks in the immediately previous frame as well as the most recent golden frame or altref frame. Every key frame is automatically golden and altref, and any interframe may optionally replace the most recent golden or altref frame.

第二,VP8用交替预测帧(称为golden帧和altref帧(交替参考帧))来增强这些概念。可以使用前一帧中的块以及最近的黄金帧或altref帧中的块来预测帧间中的块。每个关键帧自动为golden和altref,任何帧间帧都可以选择替换最近的golden或altref帧。

Golden frames and altref frames may also be used to partially overcome the intolerance to dropped frames discussed above: If a compressor is configured to code golden frames only with reference to the prior golden frame (and key frame), then the "substream" of key and golden frames may be decoded regardless of loss of other interframes. Roughly speaking, the implementation requires (on the compressor side) that golden frames subsume and recode any context updates effected by the intervening interframes. A typical application of this approach is video conferencing, in which retransmission of a prior golden frame and/or a delay in playback until receipt of the next golden frame is preferable to a larger retransmit and/or delay until the next key frame.

黄金帧和altref帧也可用于部分克服对上述丢弃帧的不容忍:如果压缩器被配置为仅参考先前的黄金帧(和关键帧)对黄金帧进行编码,则可以解码关键帧和黄金帧的“子流”,而不考虑其他帧间的丢失。粗略地说,实现要求(在压缩器端)黄金帧包含并重新编码由中间帧影响的任何上下文更新。该方法的典型应用是视频会议,其中,与更大的重发和/或直到下一关键帧的延迟相比,优选先前黄金帧的重发和/或直到接收到下一黄金帧的回放延迟。

4. Overview of Compressed Data Format
4. 压缩数据格式概述

The input to a VP8 decoder is a sequence of compressed frames whose order matches their order in time. Issues such as the duration of frames, the corresponding audio, and synchronization are generally provided by the playback environment and are irrelevant to the decoding process itself; however, to aid in fast seeking, a start code is included in the header of each key frame.

VP8解码器的输入是一个压缩帧序列,其顺序与其时间顺序相匹配。帧的持续时间、相应的音频和同步等问题通常由回放环境提供,与解码过程本身无关;但是,为了帮助快速查找,每个关键帧的标头中都包含一个开始代码。

The decoder is simply presented with a sequence of compressed frames and produces a sequence of decompressed (reconstructed) YUV frames corresponding to the input sequence. As stated in the Introduction, the exact pixel values in the reconstructed frame are part of VP8's specification. This document specifies the layout of the compressed frames and gives unambiguous algorithms for the correct production of reconstructed frames.

解码器简单地呈现压缩帧序列,并产生与输入序列对应的解压缩(重构)YUV帧序列。如引言中所述,重建帧中的精确像素值是VP8规范的一部分。本文件规定了压缩帧的布局,并给出了正确生成重建帧的明确算法。

The first frame presented to the decompressor is of course a key frame. This may be followed by any number of interframes; the correct reconstruction of each frame depends on all prior frames up to the key frame. The next key frame restarts this process: The decompressor resets to its default initial condition upon reception of a key frame, and the decoding of a key frame (and its ensuing interframes) is completely independent of any prior decoding.

呈现给解压器的第一帧当然是关键帧。这之后可以是任意数量的帧;每个帧的正确重建取决于关键帧之前的所有帧。下一个关键帧重新启动该过程:解压器在接收到关键帧时重置为其默认初始条件,并且关键帧(及其随后的帧间)的解码完全独立于任何先前的解码。

At the highest level, every compressed frame has three or more pieces. It begins with an uncompressed data chunk comprising 10 bytes in the case of key frames and 3 bytes for interframes. This is followed by two or more blocks of compressed data (called partitions). These compressed data partitions begin and end on byte boundaries.

在最高级别,每个压缩帧都有三个或更多的片段。它从一个未压缩的数据块开始,对于关键帧,它包含10个字节,对于帧间帧,它包含3个字节。然后是两个或多个压缩数据块(称为分区)。这些压缩数据分区在字节边界上开始和结束。

The first compressed partition has two subsections:

第一个压缩分区有两个子部分:

1. Header information that applies to the frame as a whole.

1. 应用于整个帧的标题信息。

2. Per-macroblock information specifying how each macroblock is predicted from the already-reconstructed data that is available to the decompressor.

2. 每个宏块信息,指定如何从解压缩器可用的已重构数据预测每个宏块。

As stated above, the macroblock-level information occurs in raster-scan order.

如上所述,宏块级信息以光栅扫描顺序出现。

The rest of the partitions contain, for each block, the DCT/WHT coefficients (quantized and logically compressed) of the residue signal to be added to the predicted block values. It typically accounts for roughly 70% of the overall datarate. VP8 supports packing the compressed DCT/WHT coefficients' data from macroblock

对于每个块,其余分区包含要添加到预测块值的剩余信号的DCT/WHT系数(量化和逻辑压缩)。它通常约占总数据速率的70%。VP8支持从宏块打包压缩的DCT/WHT系数数据

rows into separate partitions. If there is more than one partition for these coefficients, the sizes of the partitions -- except the last partition -- in bytes are also present in the bitstream right after the above first partition. Each of the sizes is a 3-byte data item written in little endian format. These sizes provide the decoder direct access to all DCT/WHT coefficient partitions, which enables parallel processing of the coefficients in a decoder.

将行划分为单独的分区。如果这些系数有多个分区,则分区的大小(最后一个分区除外)以字节为单位也会出现在上述第一个分区之后的比特流中。每个大小都是一个以little endian格式编写的3字节数据项。这些大小为解码器提供了对所有DCT/WHT系数分区的直接访问,从而实现了解码器中系数的并行处理。

The separate partitioning of the prediction data and coefficient data also allows flexibility in the implementation of a decompressor: An implementation may decode and store the prediction information for the whole frame and then decode, transform, and add the residue signal to the entire frame, or it may simultaneously decode both partitions, calculating prediction information and adding in the residue signal for each block in order. The length field in the frame tag, which allows decoding of the second partition to begin before the first partition has been completely decoded, is necessary for the second "block-at-a-time" decoder implementation.

预测数据和系数数据的单独分区还允许在解压器的实现中具有灵活性:实现可以解码和存储整个帧的预测信息,然后解码、变换并将剩余信号添加到整个帧,或者可以同时解码两个分区,计算预测信息并按顺序加入每个块的剩余信号。帧标签中的长度字段允许在第一分区被完全解码之前开始第二分区的解码,对于第二“一次分块”解码器实现是必需的。

All partitions are decoded using separate instances of the boolean entropy decoder described in Section 7. Although some of the data represented within the partitions is conceptually "flat" (a bit is just a bit with no probabilistic expectation one way or the other), because of the way such coders work, there is never a direct correspondence between a "conceptual bit" and an actual physical bit in the compressed data partitions. Only in the 3- or 10-byte uncompressed chunk described above is there such a physical correspondence.

使用第7节中描述的布尔熵解码器的单独实例对所有分区进行解码。尽管分区中表示的一些数据在概念上是“平坦的”(一个位只是一个没有概率期望的位),但由于这种编码器的工作方式,“概念位”和压缩数据分区中的实际物理位之间从来没有直接对应关系。只有在上面描述的3字节或10字节未压缩块中才存在这样的物理对应。

A related matter is that seeking within a partition is not supported. The data must be decompressed and processed (or at least stored) in the order in which it occurs in the partition.

一个相关的问题是不支持在分区内进行查找。数据必须按照其在分区中出现的顺序进行解压缩和处理(或至少存储)。

While this document specifies the ordering of the partition data correctly, the details and semantics of this data are discussed in a more logical fashion to facilitate comprehension. For example, the frame header contains updates to many probability tables used in decoding per-macroblock data. The per-macroblock data is often described before the layouts of the probabilities and their updates, even though this is the opposite of their order in the bitstream.

虽然本文档正确地指定了分区数据的顺序,但以更符合逻辑的方式讨论了该数据的细节和语义,以便于理解。例如,帧报头包含对解码每个宏块数据时使用的许多概率表的更新。每宏块数据通常在概率及其更新的布局之前描述,即使这与它们在比特流中的顺序相反。

5. Overview of the Decoding Process
5. 解码过程概述

A VP8 decoder needs to maintain four YUV frame buffers whose resolutions are at least equal to that of the encoded image. These buffers hold the current frame being reconstructed, the immediately previous reconstructed frame, the most recent golden frame, and the most recent altref frame.

VP8解码器需要保持四个YUV帧缓冲区,其分辨率至少等于编码图像的分辨率。这些缓冲区保存正在重建的当前帧、上一个重建帧、最近的黄金帧和最近的altref帧。

Most implementations will wish to "pad" these buffers with "invisible" pixels that extend a moderate number of pixels beyond all four edges of the visible image. This simplifies interframe prediction by allowing all (or most) prediction blocks -- which are not guaranteed to lie within the visible area of a prior frame -- to address usable image data.

大多数实现都希望用“不可见”像素“填充”这些缓冲区,这些像素将适度数量的像素扩展到可见图像的所有四个边缘之外。这通过允许所有(或大部分)预测块(不保证位于前一帧的可见区域内)寻址可用图像数据来简化帧间预测。

Regardless of the amount of padding chosen, the invisible rows above (or below) the image are filled with copies of the top (or bottom) row of the image; the invisible columns to the left (or right) of the image are filled with copies of the leftmost (or rightmost) visible row; and the four invisible corners are filled with copies of the corresponding visible corner pixels. The use of these prediction buffers (and suggested sizes for the halo) will be elaborated on in the discussion of motion vectors, interframe prediction, and sub-pixel interpolation later in this document.

无论选择了多少填充,图像上方(或下方)的不可见行都会填充图像顶部(或底部)行的副本;图像左侧(或右侧)的不可见列由最左侧(或最右侧)可见行的副本填充;四个不可见角被相应可见角像素的副本填充。这些预测缓冲区(以及光晕的建议大小)的使用将在本文后面的运动矢量、帧间预测和亚像素插值讨论中详细说明。

As will be seen in the description of the frame header, the image dimensions are specified (and can change) with every key frame. These buffers (and any other data structures whose size depends on the size of the image) should be allocated (or re-allocated) immediately after the dimensions are decoded.

从帧标题的描述中可以看出,图像尺寸随每个关键帧而指定(并且可以更改)。这些缓冲区(以及大小取决于图像大小的任何其他数据结构)应在尺寸解码后立即分配(或重新分配)。

Leaving most of the details for later elaboration, the following is an outline of the decoding process.

下面是解码过程的概要,将大部分细节留给以后的详细阐述。

First, the frame header (the beginning of the first data partition) is decoded. Altering or augmenting the maintained state of the decoder, this provides the context in which the per-macroblock data can be interpreted.

首先,对帧头(第一数据分区的开始)进行解码。改变或增加解码器的保持状态,这提供了可以解释每宏块数据的上下文。

The macroblock data occurs (and must be processed) in raster-scan order. This data comes in two or more parts. The first (prediction or mode) part comes in the remainder of the first data partition. The other parts comprise the data partition(s) for the DCT/WHT coefficients of the residue signal. For each macroblock, the prediction data must be processed before the residue.

宏块数据以光栅扫描顺序出现(并且必须进行处理)。这些数据分为两部分或更多部分。第一部分(预测或模式)位于第一个数据分区的剩余部分。其他部分包括剩余信号的DCT/WHT系数的数据分区。对于每个宏块,预测数据必须在剩余之前进行处理。

Each macroblock is predicted using one (and only one) of four possible frames. All macroblocks in a key frame, and all intra-coded macroblocks in an interframe, are predicted using the already-decoded macroblocks in the current frame. Macroblocks in an interframe may also be predicted using the previous frame, the golden frame, or the altref frame. Such macroblocks are said to be inter-coded.

使用四个可能帧中的一个(且仅一个)预测每个宏块。使用当前帧中已解码的宏块预测关键帧中的所有宏块以及帧间中的所有帧内编码宏块。帧间宏块也可以使用前一帧、黄金帧或altref帧来预测。这种宏块被称为是帧间编码的。

The purpose of prediction is to use already-constructed image data to approximate the portion of the original image being reconstructed. The effect of any of the prediction modes is then to write a macroblock-sized prediction buffer containing this approximation.

预测的目的是使用已经构造的图像数据来近似原始图像的被重建部分。然后,任何预测模式的效果都是写入包含该近似值的宏块大小的预测缓冲区。

Regardless of the prediction method, the residue DCT signal is decoded, dequantized, reverse-transformed, and added to the prediction buffer to produce the (almost final) reconstruction value of the macroblock, which is stored in the correct position of the current frame buffer.

无论采用何种预测方法,残余DCT信号都将被解码、去量化、反向变换并添加到预测缓冲器中,以产生宏块的(几乎最终)重建值,该重建值存储在当前帧缓冲器的正确位置。

The residue signal consists of 24 (sixteen Y, four U, and four V) 4x4 quantized and losslessly compressed DCT transforms approximating the difference between the original macroblock in the uncompressed source and the prediction buffer. For most prediction modes, the 0th coefficients of the sixteen Y subblocks are expressed via a 25th WHT of the second-order virtual Y2 subblock discussed above.

残余信号由24(16个Y、4个U和4个V)4x4量化和无损压缩DCT变换组成,近似于未压缩源和预测缓冲器中原始宏块之间的差值。对于大多数预测模式,十六个Y子块的第0个系数通过上面讨论的二阶虚拟Y2子块的第25个WHT表示。

Intra-prediction exploits the spatial coherence of frames. The 16x16 luma (Y) and 8x8 chroma (UV) components are predicted independently of each other using one of four simple means of pixel propagation, starting from the already-reconstructed (16-pixel-long luma, 8-pixel-long chroma) row above, and column to the left of, the current macroblock. The four methods are:

帧内预测利用帧的空间相干性。16x16亮度(Y)和8x8色度(UV)分量通过四种简单的像素传播方式中的一种相互独立地进行预测,从当前宏块上方已重建的(16像素长亮度,8像素长色度)行和左侧的列开始。这四种方法是:

1. Copying the row from above throughout the prediction buffer.

1. 在整个预测缓冲区中从上面复制行。

2. Copying the column from the left throughout the prediction buffer.

2. 在整个预测缓冲区中从左侧复制列。

3. Copying the average value of the row and column throughout the prediction buffer.

3. 在整个预测缓冲区中复制行和列的平均值。

4. Extrapolation from the row and column using the (fixed) second difference (horizontal and vertical) from the upper left corner.

4. 使用左上角的(固定)第二个差(水平和垂直)从行和列进行外推。

Additionally, the sixteen Y subblocks may be predicted independently of each other using one of ten different modes, four of which are 4x4 analogs of those described above, augmented with six "diagonal" prediction methods. There are two types of predictions, one intra and one prediction (among all the modes), for which the residue signal does not use the Y2 block to encode the DC portion of the sixteen 4x4 Y subblock DCTs. This "independent Y subblock" mode has no effect on the 8x8 chroma prediction.

此外,可以使用十种不同模式中的一种彼此独立地预测十六个Y子块,其中四种是用六种“对角”预测方法增强的上述模式的4x4类似物。存在两种类型的预测,一种是帧内预测,另一种是预测(在所有模式中),对于这两种预测,剩余信号不使用Y2块来编码16个4x4y子块dct的DC部分。此“独立Y子块”模式对8x8色度预测没有影响。

Inter-prediction exploits the temporal coherence between nearby frames. Except for the choice of the prediction frame itself, there is no difference between inter-prediction based on the previous frame and that based on the golden frame or altref frame.

帧间预测利用相邻帧之间的时间相关性。除了选择预测帧本身之外,基于前一帧的帧间预测与基于黄金帧或altref帧的帧间预测之间没有区别。

Inter-prediction is conceptually very simple. While, for reasons of efficiency, there are several methods of encoding the relationship between the current macroblock and corresponding sections of the prediction frame, ultimately each of the sixteen Y subblocks is related to a 4x4 subblock of the prediction frame, whose position in that frame differs from the current subblock position by a (usually small) displacement. These two-dimensional displacements are called motion vectors.

帧间预测在概念上非常简单。然而,出于效率的原因,存在几种编码当前宏块和预测帧的对应部分之间的关系的方法,最终十六个Y子块中的每一个与预测帧的4x4子块相关,其在该帧中的位置与当前子块位置相差一倍(通常很小)位移。这些二维位移称为运动矢量。

The motion vectors used by VP8 have quarter-pixel precision. Prediction of a subblock using a motion vector that happens to have integer (whole number) components is very easy: The 4x4 block of pixels from the displaced block in the previous, golden, or altref frame is simply copied into the correct position of the current macroblock's prediction buffer.

VP8使用的运动矢量具有四分之一像素精度。使用恰好具有整数(整数)分量的运动向量预测子块非常容易:将前一帧、golden帧或altref帧中位移块的4x4像素块复制到当前宏块预测缓冲区的正确位置。

Fractional displacements are conceptually and implementationally more complex. They require the inference (or synthesis) of sample values that, strictly speaking, do not exist. This is one of the most basic problems in signal processing, and readers conversant with that subject will see that the approach taken by VP8 provides a good balance of robustness, accuracy, and efficiency.

分数位移在概念上和实施上更为复杂。它们需要推断(或合成)严格来说不存在的样本值。这是信号处理中最基本的问题之一,熟悉该主题的读者将看到VP8所采用的方法在稳健性、准确性和效率之间提供了良好的平衡。

Leaving the details for the implementation discussion below, the pixel interpolation is calculated by applying a kernel filter (using reasonable-precision integer math) three pixels on either side, both horizontally and vertically, of the pixel to be synthesized. The resulting 4x4 block of synthetic pixels is then copied into position exactly as in the case of integer displacements.

将细节留给下面的实现讨论,通过在要合成的像素的任意一侧(水平和垂直)应用内核滤波器(使用合理精度的整数数学)三个像素来计算像素插值。然后,生成的4x4合成像素块被复制到与整数位移完全相同的位置。

Each of the eight chroma subblocks is handled similarly. Their motion vectors are never specified explicitly; instead, the motion vector for each chroma subblock is calculated by averaging the vectors of the four Y subblocks that occupy the same area of the frame. Since chroma pixels have twice the diameter (and four times the area) of luma pixels, the calculated chroma motion vectors have 1/8-pixel resolution, but the procedure for copying or generating pixels for each subblock is essentially identical to that done in the luma plane.

八个色度子块中的每一个都以类似方式处理。它们的运动矢量从未明确指定;相反,通过平均占据帧的相同区域的四个Y子块的向量来计算每个色度子块的运动向量。由于色度像素的直径是亮度像素的两倍(面积的四倍),因此计算出的色度运动矢量具有1/8像素的分辨率,但用于复制或生成每个子块的像素的过程基本上与在亮度平面中完成的过程相同。

After all the macroblocks have been generated (predicted and corrected with the DCT/WHT residue), a filtering step (the loop filter) is applied to the entire frame. The purpose of the loop filter is to reduce blocking artifacts at the boundaries between macroblocks and between subblocks of the macroblocks. The term "loop filter" is used because this filter is part of the "coding loop"; that is, it affects the reconstructed frame buffers that are used to predict ensuing frames. This is distinguished from the postprocessing filters discussed earlier, which affect only the viewed video and do not "feed into" subsequent frames.

在生成所有宏块(使用DCT/WHT残差预测和校正)之后,对整个帧应用滤波步骤(循环滤波器)。循环滤波器的目的是减少宏块之间和宏块的子块之间的边界处的块伪影。使用术语“环路滤波器”是因为该滤波器是“编码环路”的一部分;也就是说,它影响用于预测后续帧的重构帧缓冲区。这与前面讨论的后处理过滤器不同,后者只影响观看的视频,不会“馈送”到后续帧。

Next, if signaled in the data, the current frame may replace the golden frame prediction buffer and/or the altref frame buffer.

接下来,如果在数据中发信号,则当前帧可以替换黄金帧预测缓冲器和/或altref帧缓冲器。

The halos of the frame buffers are next filled as specified above. Finally, at least as far as decoding is concerned, the (references to) the "current" and "last" frame buffers should be exchanged in preparation for the next frame.

帧缓冲区的光晕将按上述规定填充。最后,至少就解码而言,(对)“当前”和“最后”帧缓冲器的引用)应交换以准备下一帧。

Various processes may be required (or desired) before viewing the generated frame. As discussed in the frame dimension information below, truncation and/or upscaling of the frame may be required. Some playback systems may require a different frame format (RGB, YUY2, etc.). Finally, as mentioned in the Introduction, further postprocessing or filtering of the image prior to viewing may be desired. Since the primary purpose of this document is a decoding specification, the postprocessing is not specified in this document.

在查看生成的帧之前,可能需要(或期望)各种过程。如下文框架尺寸信息中所述,可能需要对框架进行截断和/或放大。某些播放系统可能需要不同的帧格式(RGB、YUY2等)。最后,如引言中所述,可能需要在观看之前对图像进行进一步的后处理或滤波。由于本文件的主要目的是解码规范,因此本文件未规定后处理。

While the basic ideas of prediction and correction used by VP8 are straightforward, many of the details are quite complex. The management of probabilities is particularly elaborate. Not only do the various modes of intra-prediction and motion vector specification have associated probabilities, but they, together with the coding of DCT coefficients and motion vectors, often base these probabilities on a variety of contextual information (calculated from what has been decoded so far), as well as on explicit modification via the frame header.

虽然VP8使用的预测和校正的基本思想很简单,但许多细节相当复杂。概率的管理尤其复杂。帧内预测和运动向量规范的各种模式不仅具有相关的概率,而且它们与DCT系数和运动向量的编码一起,通常将这些概率基于各种上下文信息(根据迄今为止解码的内容计算),以及通过帧头进行显式修改。

The "top-level" of decoding and frame reconstruction is implemented in the reference decoder file dixie.c (Section 20.4).

解码和帧重建的“顶层”在参考解码器文件dixie.c(第20.4节)中实现。

This concludes our summary of decoding and reconstruction; we continue by discussing the individual aspects in more depth.

这是我们对解码和重构的总结;我们继续更深入地讨论各个方面。

A reasonable "divide and conquer" approach to implementation of a decoder is to begin by decoding streams composed exclusively of key frames. After that works reliably, interframe handling can be added more easily than if complete functionality were attempted

实现解码器的一种合理的“分而治之”方法是首先对仅由关键帧组成的流进行解码。在这项工作可靠之后,与尝试完整功能相比,可以更轻松地添加帧间处理

immediately. In accordance with this, we first discuss components needed to decode key frames (most of which are also used in the decoding of interframes) and conclude with topics exclusive to interframes.

立即根据这一点,我们首先讨论解码关键帧所需的组件(其中大部分也用于帧间解码),并以帧间专有的主题结束。

6. Description of Algorithms
6. 算法描述

As the intent of this document, together with the reference decoder source code, is to specify a platform-independent procedure for the decoding and reconstruction of a VP8 video stream, many (small) algorithms must be described exactly.

由于本文件以及参考解码器源代码的目的是为VP8视频流的解码和重建指定独立于平台的过程,因此必须准确描述许多(小型)算法。

Due to its near-universality, terseness, ability to easily describe calculation at specific precisions, and the fact that On2's reference VP8 decoder is written in C, these algorithm fragments are written using the C programming language, augmented with a few simple definitions below.

由于其接近通用性、简洁性、能够在特定精度下轻松描述计算,以及On2的参考VP8解码器是用C编写的事实,这些算法片段使用C编程语言编写,并在下面添加了一些简单的定义。

The standard (and best) reference for C is [Kernighan].

C的标准(也是最好的)参考是[Kernighan]。

Many code fragments will be presented in this document. Some will be nearly identical to corresponding sections of the reference decoder; others will differ. Roughly speaking, there are three reasons for such differences:

本文将介绍许多代码片段。有些将与参考解码器的相应部分几乎相同;其他人则会有所不同。大致来说,造成这种差异的原因有三个:

1. For reasons of efficiency, the reference decoder version may be less obvious.

1. 出于效率原因,参考解码器版本可能不太明显。

2. The reference decoder often uses large data structures to maintain context that need not be described or used here.

2. 参考解码器通常使用大型数据结构来维护此处不需要描述或使用的上下文。

3. The authors of this document felt that a different expression of the same algorithm might facilitate exposition.

3. 本文作者认为,同一算法的不同表达式可能有助于阐述。

Regardless of the chosen presentation, the calculation effected by any of the algorithms described here is identical to that effected by the corresponding portion of the reference decoder.

不管所选择的呈现方式如何,由本文描述的任何算法影响的计算与由参考解码器的相应部分影响的计算相同。

All VP8 decoding algorithms use integer math. To facilitate specification of arithmetic precision, we define the following types.

所有VP8解码算法都使用整数数学。为了便于指定算术精度,我们定义了以下类型。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef   signed char  int8; /* signed int exactly 8 bits wide */
   typedef unsigned char uint8; /* unsigned "" */
        
   typedef   signed char  int8; /* signed int exactly 8 bits wide */
   typedef unsigned char uint8; /* unsigned "" */
        
   typedef short int16;         /* signed int exactly 16 bits wide */
   typedef unsigned int16 uint16; /* unsigned "" */
        
   typedef short int16;         /* signed int exactly 16 bits wide */
   typedef unsigned int16 uint16; /* unsigned "" */
        
   /* int32 is a signed integer type at least 32 bits wide */
        
   /* int32 is a signed integer type at least 32 bits wide */
        
   typedef long int32; /* guaranteed to work on all systems */
   typedef int  int32; /* will be more efficient on some systems */
        
   typedef long int32; /* guaranteed to work on all systems */
   typedef int  int32; /* will be more efficient on some systems */
        

typedef unsigned int32 uint32;

typedef无符号int32 uint32;

   /* unsigned integer type, at least 16 bits wide, whose exact size
      is most convenient to whatever processor we are using */
        
   /* unsigned integer type, at least 16 bits wide, whose exact size
      is most convenient to whatever processor we are using */
        

typedef unsigned int uint;

typedef无符号整数单元;

   /* While pixels themselves are 8-bit unsigned integers,
      pixel arithmetic often occurs at 16- or 32-bit precision and
      the results need to be "saturated" or clamped to an 8-bit
      range. */
        
   /* While pixels themselves are 8-bit unsigned integers,
      pixel arithmetic often occurs at 16- or 32-bit precision and
      the results need to be "saturated" or clamped to an 8-bit
      range. */
        

typedef uint8 Pixel;

typedef uint8像素;

   Pixel clamp255(int32 v) { return v < 0? 0 : (v < 255? v : 255);}
        
   Pixel clamp255(int32 v) { return v < 0? 0 : (v < 255? v : 255);}
        
   /*  As is elaborated in the discussion of the bool_decoder below,
       VP8 represents probabilities as unsigned 8-bit numbers. */
        
   /*  As is elaborated in the discussion of the bool_decoder below,
       VP8 represents probabilities as unsigned 8-bit numbers. */
        

typedef uint8 Prob;

typedef uint8 Prob;

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

We occasionally need to discuss mathematical functions involving honest-to-goodness "infinite precision" real numbers. The DCT is first described via the cosine function cos; the ratio of the lengths of the circumference and diameter of a circle is denoted pi; at one point, we take a (base 1/2) logarithm, denoted log; and pow(x, y) denotes x raised to the power y. If x = 2 and y is a small non-negative integer, pow(2, y) may be expressed in C as 1 << y.

我们偶尔需要讨论涉及诚实到善良的“无限精度”实数的数学函数。首先通过余弦函数cos描述DCT;圆周长度与圆直径之比表示为pi;在某一点上,我们取(以1/2为底)对数,表示为log;pow(x,y)表示x升到y的幂。如果x=2且y是一个小的非负整数,则pow(2,y)可以用C表示为1<<y。

Finally, we sometimes need to divide signed integers by powers of two; that is, we occasionally right-shift signed numbers. The behavior of such shifts (i.e., the propagation of the sign bit) is, perhaps surprisingly, not defined by the C language itself and is left up to individual compilers. Because of the utility of this frequently needed operation, it is at least arguable that it should be defined by the language (to naturally propagate the sign bit) and, at a minimum, should be correctly implemented by any reasonable compiler. In the interest of strict portability, we attempt to call attention to these shifts when they arise.

最后,我们有时需要将有符号整数除以二的幂;也就是说,我们偶尔会右移有符号的数字。这种移位的行为(即符号位的传播)可能令人惊讶地不是由C语言本身定义的,而是由单个编译器决定的。由于这种经常需要的操作的实用性,它至少应该由语言定义(自然传播符号位),并且至少应该由任何合理的编译器正确实现。为了严格的可移植性,我们试图在出现这些变化时提请注意。

7. Boolean Entropy Decoder
7. 布尔熵译码器

As discussed in the overview above, essentially the entire VP8 data stream is encoded using a boolean entropy coder.

正如上面概述中所讨论的,整个VP8数据流基本上是使用布尔熵编码器编码的。

An understanding of the bool_decoder is critical to the implementation of a VP8 decompressor, so we discuss the bool_decoder in detail. It is easier to comprehend the bool_decoder in conjunction with the bool_encoder used by the compressor to write the compressed data partitions.

了解bool_解码器对于VP8解压器的实现至关重要,因此我们将详细讨论bool_解码器。更容易理解bool_解码器与压缩机用来写入压缩数据分区的bool_编码器。

The bool_encoder encodes (and the bool_decoder decodes) one bool (zero-or-one boolean value) at a time. Its purpose is to losslessly compress a sequence of bools for which the probability of their being zero or one can be well-estimated (via constant or previously coded information) at the time they are written, using identical corresponding probabilities at the time they are read.

bool_编码器一次编码(bool_解码器解码)一个bool(零或一个布尔值)。其目的是无损压缩bool序列,在写入bool时,使用读取bool时相同的相应概率(通过常量或先前编码的信息),可以很好地估计bool序列为零或一的概率。

As the reader is probably aware, if a bool is much more likely to be zero than one (for instance), it can, on average, be faithfully encoded using much less than one bit per value. The bool_encoder exploits this.

读者可能知道,如果bool很可能是零而不是一(例如),那么平均而言,它可以使用每个值不到一位的数据进行忠实的编码。布尔鲁编码器利用了这一点。

In the 1940s, [Shannon] proved that there is a lower bound for the average datarate of a faithful encoding of a sequence of bools (whose probability distributions are known and are independent of each other) and also that there are encoding algorithms that approximate this lower bound as closely as one wishes.

在20世纪40年代,[Shannon]证明了布尔序列(其概率分布已知且相互独立)的忠实编码的平均数据率有一个下界,并且有一些编码算法可以尽可能接近这个下界。

If we encode a sequence of bools whose probability of being zero is p (and whose probability of being 1 is 1-p), the lowest possible datarate per value is

如果我们对概率为零的布尔序列进行编码(概率为1的布尔序列为1-p),则每个值的最低可能数据速率为

   plog(p) + (1-p)log(1-p);
        
   plog(p) + (1-p)log(1-p);
        

taking the logarithms to the base 1/2 expresses the datarate in bits/ value.

将对数以1/2为基数表示数据速率,单位为位/值。

We give two simple examples. At one extreme, if p = 1/2, then log(p) = log(1-p) = 1, and the lowest possible datarate per bool is 1/2 + 1/2 = 1; that is, we cannot do any better than simply literally writing out bits. At another extreme, if p is very small, say p = 1/1024, then log(p)=10, log(1-p) is roughly .0014, and the lowest possible datarate is approximately 10/1024 + .0014, roughly 1/100 of a bit per bool.

我们给出两个简单的例子。在一个极端,如果p=1/2,那么log(p)=log(1-p)=1,每个bool的最低可能数据速率为1/2+1/2=1;也就是说,我们不能做得比简单地写出比特更好。在另一个极端,如果p非常小,比如p=1/1024,那么log(p)=10,log(1-p)大约为.0014,最低可能的数据速率大约为10/1024+.0014,大约为每bool 1/100位。

Because most of the bools in the VP8 datastream have zero-probabilities nowhere near 1/2, the compression provided by the bool_encoder is critical to the performance of VP8.

由于VP8数据流中的大多数布尔值的概率为零,不接近1/2,因此布尔_编码器提供的压缩对VP8的性能至关重要。

The boolean coder used by VP8 is a variant of an arithmetic coder. An excellent discussion of arithmetic coding (and other lossless compression techniques) can be found in [Bell].

VP8使用的布尔编码器是算术编码器的变体。在[Bell]中可以找到关于算术编码(和其他无损压缩技术)的精彩讨论。

7.1. Underlying Theory of Coding
7.1. 编码的基本理论

The basic idea used by the boolean coder is to consider the entire data stream (either of the partitions in our case) as the binary expansion of a single number x with 0 <= x < 1. The bits (or bytes) in x are of course written from high to low order, and if b[j] (B[j]) is the j^(th) bit (byte) in the partition, the value x is simply the sum (starting with j = 1) of pow(2, -j) * b[j] or pow(256, -j) * B[j].

布尔编码器使用的基本思想是将整个数据流(我们的分区中的任一个)考虑为单个数字x的二进制扩展,具有0 <= x<1。x中的位(或字节)当然是从高到低的顺序写入的,如果b[j](b[j])是分区中的第j^(th)位(字节),那么值x只是pow(2,-j)*b[j]或pow(256,-j)*b[j]的和(从j=1开始)。

Before the first bool is coded, all values of x are possible.

在编码第一个布尔之前,x的所有值都是可能的。

The coding of each bool restricts the possible values of x in proportion to the probability of what is coded. If p1 is the probability of the first bool being zero and a zero is coded, the range of possible values of x is restricted to 0 <= x < p1. If a one is coded, the range becomes p1 <= x < 1.

每个布尔的编码限制x的可能值,该值与编码的概率成比例。如果p1是第一个bool为零的概率,并且编码了零,则x的可能值范围限制为0<=x<p1。如果对1进行编码,则范围变为p1<=x<1。

The coding continues by repeating the same idea. At every stage, there is an interval a <= x < b of possible values of x. If p is the probability of a zero being coded at this stage and a zero is coded, the interval becomes a <= x < a + (p(b-a)). If a one is coded, the possible values of x are restricted to a + (p(b-a)) <= x < b.

编码继续重复相同的想法。在每个阶段,都有一个区间a<=x<b的x的可能值。如果p是在该阶段对零进行编码的概率,并且对零进行了编码,则区间变为a<=x<a+(p(b-a))。如果对一进行编码,则x的可能值限制为a+(p(b-a))<=x<b。

Assuming that only finitely many values are to be coded, after the encoder has received the last bool, it can write as its output any value x that lies in the final interval. VP8 simply writes the left endpoint of the final interval. Consequently, the output it would make if encoding were to stop at any time either increases or stays the same as each bool is encoded.

假设只对有限多个值进行编码,在编码器接收到最后一个bool后,它可以将最终间隔中的任何值x写入其输出。VP8只写最后一个间隔的左端点。因此,如果编码在任何时候停止,它将产生的输出会随着每个bool的编码而增加或保持不变。

Decoding parallels encoding. The decoder is presented with the number x, which has only the initial restriction 0 <= x < 1. To decode the first bool, the decoder is given the first probability p1. If x < p1, a zero is decoded; if x >= p1, a one is decoded. In either case, the new restriction on x -- that is, the interval of possible values of x -- is remembered.

解码与编码并行。解码器以数字x呈现,其仅具有初始限制0<=x<1。为了解码第一bool,解码器被赋予第一概率p1。如果x<p1,则解码零;如果x>=p1,则解码一个。在任何一种情况下,都会记住对x的新限制,即x的可能值的间隔。

Decoding continues in exactly the same way: If a <= x < b is the current interval and we are to decode a bool with zero-probability p, we return a zero if a <= x < a + (p(b-a)) and a one if a + (p(b-a)) <= x < b. In either case, the new restriction is remembered in preparation for decoding the next bool.

解码以完全相同的方式继续:如果a<=x<b是当前间隔,并且我们要以零概率p解码bool,那么如果a<=x<a+(p(b-a)),我们将返回零,如果a+(p(b-a))<=x<b,则返回一。在任何一种情况下,新的限制都会被记住,以准备解码下一个bool。

The process outlined above uses real numbers of infinite precision to express the probabilities and ranges. It is true that, if one could actualize this process and coded a large number of bools whose supplied probabilities matched their value distributions, the datarate achieved would approach the theoretical minimum as the number of bools encoded increased.

上述过程使用无限精度的实数来表示概率和范围。的确,如果一个人能够实现这一过程并编码大量布尔值,其提供的概率与其值分布相匹配,那么随着编码布尔值数量的增加,所获得的数据速率将接近理论最小值。

Unfortunately, computers operate at finite precision, and an approximation to the theoretically perfect process described above is necessary. Such approximation increases the datarate but, at quite moderate precision and for a wide variety of data sets, this increase is negligible.

不幸的是,计算机在有限的精度下运行,必须近似于上述理论上完美的过程。这种近似增加了数据速率,但在相当中等的精度下,对于各种各样的数据集,这种增加可以忽略不计。

The only conceptual limitations are, first, that coder probabilities must be expressed at finite precision and, second, that the decoder be able to detect each individual modification to the value interval via examination of a fixed amount of input. As a practical matter, many of the implementation details stem from the fact that the coder can function using only a small "window" to incrementally read or write the arbitrarily precise number x.

唯一的概念限制是,首先,编码器概率必须以有限精度表示,其次,解码器能够通过检查固定数量的输入来检测对值间隔的每个单独修改。实际上,许多实现细节源于这样一个事实,即编码器可以只使用一个小“窗口”来递增地读取或写入任意精确的数字x。

7.2. Practical Algorithm Description
7.2. 实用算法描述

VP8's boolean coder works with 8-bit probabilities p. The range of such p is 0 <= p <= 255; the actual probability represented by p is p/256. Also, the coder is designed so that decoding of a bool requires no more than an 8-bit comparison, and so that the state of both the encoder and decoder can be easily represented using a small number of unsigned 16-bit integers.

VP8的布尔编码器使用8位概率p。该p的范围为0<=p<=255;p表示的实际概率为p/256。此外,编码器的设计使得bool的解码只需要8位比较,并且使得编码器和解码器的状态可以使用少量无符号16位整数轻松表示。

The details are most easily understood if we first describe the algorithm using bit-at-a-time input and output. Aside from the ability to maintain a position in this bitstream and write/read bits, the encoder also needs the ability to add 1 to the bits already output; after writing n bits, adding 1 to the existing output is the same thing as adding pow(2, -n) to x.

如果我们首先使用一次一位的输入和输出来描述算法,那么细节最容易理解。除了能够保持在该比特流中的位置和写入/读取比特外,编码器还需要能够向已经输出的比特添加1;写入n位后,将1添加到现有输出与将pow(2,-n)添加到x是相同的。

Together with the bit position, the encoder must maintain two unsigned 8-bit numbers, which we call "bottom" and "range". Writing w for the n bits already written and S = pow(2, - n - 8) for the scale of the current bit position one byte out, we have the following constraint on all future values v of w (including the final value v = x):

连同位位置,编码器必须保持两个无符号8位数字,我们称之为“底部”和“范围”。对于已经写入的n个位写入w,对于当前位位置的比例为1字节,写入S=pow(2,-n-8),我们对w的所有未来值v(包括最终值v=x)有以下约束:

   w + ( S * bottom ) <= v < w + ( S * ( bottom + range ) )
        
   w + ( S * bottom ) <= v < w + ( S * ( bottom + range ) )
        

Thus, appending bottom to the already-written bits w gives the left endpoint of the interval of possible values, appending bottom + range gives the right endpoint, and range itself (scaled to the current output position) is the length of the interval.

因此,将bottom附加到已经写入的位w上,给出可能值间隔的左端点,将bottom+range附加到右端点,range本身(缩放到当前输出位置)是间隔的长度。

So that our probabilistic encodings are reasonably accurate, we do not let range vary by more than a factor of two: It stays within the bounds 128 <= range <= 255.

因此,我们的概率编码是相当准确的,我们不让范围变化超过两个因素:它保持在128<=范围<=255的范围内。

The process for encoding a boolean value val whose probability of being zero is prob / 256 -- and whose probability of being one is ( 256 - prob ) / 256 -- with 1 <= prob <= 255 is as follows.

对布尔值val进行编码的过程如下:其概率为零的概率为prob/256,其概率为(256-prob)/256,其中1<=prob<=255。

Using an unsigned 16-bit multiply followed by an unsigned right shift, we calculate an unsigned 8-bit split value:

使用无符号16位乘法和无符号右移,我们计算无符号8位分割值:

   split = 1 + (((range - 1) * probability)]] >> 8)
        
   split = 1 + (((range - 1) * probability)]] >> 8)
        

split is approximately ( prob / 256 ) * range and lies within the bounds 1 <= split <= range - 1. These bounds ensure the correctness of the decoding procedure described below.

split大约在(prob/256)*范围内,位于范围1<=split<=范围-1内。这些界限确保了下面描述的解码过程的正确性。

If the incoming boolean val to be encoded is false, we leave the left interval endpoint bottom alone and reduce range, replacing it by split. If the incoming val is true, we move up the left endpoint to bottom + split, propagating any carry to the already-written value w (this is where we need the ability to add 1 to w), and reduce range to range - split.

如果要编码的传入布尔值为false,我们将保留左区间端点底部,并缩小范围,用split替换它。如果传入的val为true,我们将左端点向上移动到bottom+split,将任何进位传播到已经写入的值w(这是我们需要将1添加到w的地方),并减少范围到范围-split。

Regardless of the value encoded, range has been reduced and now has the bounds 1 <= range <= 254. If range < 128, the encoder doubles it and shifts the high-order bit out of bottom to the output as it also doubles bottom, repeating this process one bit at a time until 128 <= range <= 255. Once this is completed, the encoder is ready to accept another bool, maintaining the constraints described above.

无论编码的值是多少,范围都已缩小,现在的边界为1<=范围<=254。如果范围<128,编码器将其加倍,并将高阶位从底部移到输出,因为它也将底部加倍,每次重复此过程一位,直到128<=范围<=255。一旦完成,编码器准备接受另一个bool,保持上述约束。

After encoding the last bool, the partition may be completed by appending bottom to the bitstream.

在编码最后一个bool之后,可以通过向比特流追加bottom来完成分区。

The decoder mimics the state of the encoder. It maintains, together with an input bit position, two unsigned 8-bit numbers, a range identical to that maintained by the encoder and a value. Decoding one bool at a time, the decoder (in effect) tracks the same left interval endpoint as does the encoder and subtracts it from the remaining input. Appending the unread portion of the bitstream to the 8-bit value gives the difference between the actual value encoded and the known left endpoint.

解码器模拟编码器的状态。它与输入位位置一起保持两个无符号8位数字,一个与编码器保持的范围相同的范围和一个值。每次解码一个布尔,解码器(实际上)跟踪与编码器相同的左间隔端点,并从剩余输入中减去它。将比特流的未读部分附加到8位值会给出编码的实际值和已知左端点之间的差异。

The decoder is initialized by setting range = 255 and reading the first 16 input bits into value. The decoder maintains range and calculates split in exactly the same way as does the encoder.

解码器通过设置range=255并将前16个输入位读入值来初始化。解码器保持范围并以与编码器完全相同的方式计算分割。

To decode a bool, it compares value to split; if value < split, the bool is zero, and range is replaced with split. If value >= split, the bool is one, range is replaced with range - split, and value is replaced with value - split.

要解码布尔值,它将值与拆分值进行比较;如果值<拆分,则bool为零,范围替换为拆分。如果值>=split,则布尔值为1,范围替换为范围-split,值替换为值-split。

Again, range is doubled one bit at a time until it is at least 128. The value is doubled in parallel, shifting a new input bit into the bottom each time.

同样,范围一次增加一位,直到至少达到128位。该值并行加倍,每次将一个新的输入位移到底部。

Writing Value for value together with the unread input bits and Range for range extended indefinitely on the right by zeros, the condition Value < Range is maintained at all times by the decoder. In particular, the bits shifted out of value as it is doubled are always zero.

将Value for Value与未读输入位一起写入,并将右侧的Range for Range无限扩展0,解码器始终保持条件Value<Range。特别是,当值翻倍时移位的位始终为零。

7.3. Actual Implementation
7.3. 实际执行

The C code below gives complete implementations of the encoder and decoder described above. While they are logically identical to the "bit-at-a-time" versions, they internally buffer a couple of extra bytes of the bitstream. This allows I/O to be done (more practically) a byte at a time and drastically reduces the number of carries the encoder has to propagate into the already-written data.

下面的C代码给出了上述编码器和解码器的完整实现。虽然它们在逻辑上与“一次比特”版本相同,但它们在内部缓冲比特流的两个额外字节。这允许I/O一次完成一个字节(更实际),并大幅减少编码器必须传播到已写入数据中的载波数。

Another (logically equivalent) implementation may be found in the reference decoder file bool_decoder.h (Section 20.2).

参考解码器文件bool_decoder.h(第20.2节)中可以找到另一个(逻辑等效)实现。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* Encoder first */
        
   /* Encoder first */
        
   typedef struct {
     uint8 *output;  /* ptr to next byte to be written */
     uint32 range;   /* 128 <= range <= 255 */
     uint32 bottom;  /* minimum value of remaining output */
     int bit_count;  /* # of shifts before an output byte
                        is available */
   } bool_encoder;
        
   typedef struct {
     uint8 *output;  /* ptr to next byte to be written */
     uint32 range;   /* 128 <= range <= 255 */
     uint32 bottom;  /* minimum value of remaining output */
     int bit_count;  /* # of shifts before an output byte
                        is available */
   } bool_encoder;
        
   /* Must set initial state of encoder before writing any bools. */
        
   /* Must set initial state of encoder before writing any bools. */
        
   void init_bool_encoder(bool_encoder *e, uint8 *start_partition)
   {
     e->output = start_partition;
     e->range = 255;
     e->bottom = 0;
     e->bit_count = 24;
   }
        
   void init_bool_encoder(bool_encoder *e, uint8 *start_partition)
   {
     e->output = start_partition;
     e->range = 255;
     e->bottom = 0;
     e->bit_count = 24;
   }
        
   /* Encoding very rarely produces a carry that must be propagated
      to the already-written output.  The arithmetic guarantees that
      the propagation will never go beyond the beginning of the
      output.  Put another way, the encoded value x is always less
      than one. */
        
   /* Encoding very rarely produces a carry that must be propagated
      to the already-written output.  The arithmetic guarantees that
      the propagation will never go beyond the beginning of the
      output.  Put another way, the encoded value x is always less
      than one. */
        
   void add_one_to_output(uint8 *q)
   {
     while (*--q == 255)
       *q = 0;
     ++*q;
   }
        
   void add_one_to_output(uint8 *q)
   {
     while (*--q == 255)
       *q = 0;
     ++*q;
   }
        
   /* Main function writes a bool_value whose probability of being
      zero is (expected to be) prob/256. */
        
   /* Main function writes a bool_value whose probability of being
      zero is (expected to be) prob/256. */
        
   void write_bool(bool_encoder *e, Prob prob, int bool_value)
   {
     /* split is approximately (range * prob) / 256 and,
        crucially, is strictly bigger than zero and strictly
        smaller than range */
        
   void write_bool(bool_encoder *e, Prob prob, int bool_value)
   {
     /* split is approximately (range * prob) / 256 and,
        crucially, is strictly bigger than zero and strictly
        smaller than range */
        
     uint32 split = 1 + (((e->range - 1) * prob) >> 8);
        
     uint32 split = 1 + (((e->range - 1) * prob) >> 8);
        
     if (bool_value) {
       e->bottom += split; /* move up bottom of interval */
       e->range -= split;  /* with corresponding decrease in range */
     } else
       e->range = split;   /* decrease range, leaving bottom alone */
        
     if (bool_value) {
       e->bottom += split; /* move up bottom of interval */
       e->range -= split;  /* with corresponding decrease in range */
     } else
       e->range = split;   /* decrease range, leaving bottom alone */
        
     while (e->range < 128)
     {
       e->range <<= 1;
        
     while (e->range < 128)
     {
       e->range <<= 1;
        
       if (e->bottom & (1 << 31))  /* detect carry */
         add_one_to_output(e->output);
        
       if (e->bottom & (1 << 31))  /* detect carry */
         add_one_to_output(e->output);
        
       e->bottom <<= 1;        /* before shifting bottom */
        
       e->bottom <<= 1;        /* before shifting bottom */
        
       if (!--e->bit_count) {  /* write out high byte of bottom ... */
        
       if (!--e->bit_count) {  /* write out high byte of bottom ... */
        
         *e->output++ = (uint8) (e->bottom >> 24);
        
         *e->output++ = (uint8) (e->bottom >> 24);
        
         e->bottom &= (1 << 24) - 1;  /* ... keeping low 3 bytes */
        
         e->bottom &= (1 << 24) - 1;  /* ... keeping low 3 bytes */
        
         e->bit_count = 8;            /* 8 shifts until next output */
       }
     }
   }
        
         e->bit_count = 8;            /* 8 shifts until next output */
       }
     }
   }
        
   /* Call this function (exactly once) after encoding the last
      bool value for the partition being written */
        
   /* Call this function (exactly once) after encoding the last
      bool value for the partition being written */
        
   void flush_bool_encoder(bool_encoder *e)
   {
     int c = e->bit_count;
     uint32 v = e->bottom;
        
   void flush_bool_encoder(bool_encoder *e)
   {
     int c = e->bit_count;
     uint32 v = e->bottom;
        
     if (v & (1 << (32 - c)))   /* propagate (unlikely) carry */
       add_one_to_output(e->output);
     v <<= c & 7;               /* before shifting remaining output */
     c >>= 3;                   /* to top of internal buffer */
     while (--c >= 0)
       v <<= 8;
     c = 4;
     while (--c >= 0) {    /* write remaining data, possibly padded */
       *e->output++ = (uint8) (v >> 24);
       v <<= 8;
     }
   }
        
     if (v & (1 << (32 - c)))   /* propagate (unlikely) carry */
       add_one_to_output(e->output);
     v <<= c & 7;               /* before shifting remaining output */
     c >>= 3;                   /* to top of internal buffer */
     while (--c >= 0)
       v <<= 8;
     c = 4;
     while (--c >= 0) {    /* write remaining data, possibly padded */
       *e->output++ = (uint8) (v >> 24);
       v <<= 8;
     }
   }
        
   /* Decoder state exactly parallels that of the encoder.
      "value", together with the remaining input, equals the
      complete encoded number x less the left endpoint of the
      current coding interval. */
        
   /* Decoder state exactly parallels that of the encoder.
      "value", together with the remaining input, equals the
      complete encoded number x less the left endpoint of the
      current coding interval. */
        
   typedef struct {
     uint8   *input;     /* pointer to next compressed data byte */
     uint32  range;      /* always identical to encoder's range */
     uint32  value;      /* contains at least 8 significant bits */
     int     bit_count;  /* # of bits shifted out of
                            value, at most 7 */
   } bool_decoder;
        
   typedef struct {
     uint8   *input;     /* pointer to next compressed data byte */
     uint32  range;      /* always identical to encoder's range */
     uint32  value;      /* contains at least 8 significant bits */
     int     bit_count;  /* # of bits shifted out of
                            value, at most 7 */
   } bool_decoder;
        
   /* Call this function before reading any bools from the
      partition. */
        
   /* Call this function before reading any bools from the
      partition. */
        
   void init_bool_decoder(bool_decoder *d, uint8 *start_partition)
   {
     {
       int i = 0;
       d->value = 0;           /* value = first 2 input bytes */
       while (++i <= 2)
        
   void init_bool_decoder(bool_decoder *d, uint8 *start_partition)
   {
     {
       int i = 0;
       d->value = 0;           /* value = first 2 input bytes */
       while (++i <= 2)
        
         d->value = (d->value << 8)  |  *start_partition++;
     }
        
         d->value = (d->value << 8)  |  *start_partition++;
     }
        
     d->input = start_partition;  /* ptr to next byte to be read */
     d->range = 255;           /* initial range is full */
     d->bit_count = 0;         /* have not yet shifted out any bits */
   }
        
     d->input = start_partition;  /* ptr to next byte to be read */
     d->range = 255;           /* initial range is full */
     d->bit_count = 0;         /* have not yet shifted out any bits */
   }
        
   /* Main function reads a bool encoded at probability prob/256,
      which of course must agree with the probability used when the
      bool was written. */
        
   /* Main function reads a bool encoded at probability prob/256,
      which of course must agree with the probability used when the
      bool was written. */
        
   int read_bool(bool_decoder *d, Prob prob)
   {
     /* range and split are identical to the corresponding values
        used by the encoder when this bool was written */
        
   int read_bool(bool_decoder *d, Prob prob)
   {
     /* range and split are identical to the corresponding values
        used by the encoder when this bool was written */
        
     uint32  split = 1 + (((d->range - 1) * prob) >> 8);
     uint32  SPLIT = split << 8;
     int     retval;           /* will be 0 or 1 */
        
     uint32  split = 1 + (((d->range - 1) * prob) >> 8);
     uint32  SPLIT = split << 8;
     int     retval;           /* will be 0 or 1 */
        
     if (d->value >= SPLIT) {  /* encoded a one */
       retval = 1;
       d->range -= split;  /* reduce range */
       d->value -= SPLIT;  /* subtract off left endpoint of interval */
     } else {              /* encoded a zero */
       retval = 0;
       d->range = split;  /* reduce range, no change in left endpoint */
     }
        
     if (d->value >= SPLIT) {  /* encoded a one */
       retval = 1;
       d->range -= split;  /* reduce range */
       d->value -= SPLIT;  /* subtract off left endpoint of interval */
     } else {              /* encoded a zero */
       retval = 0;
       d->range = split;  /* reduce range, no change in left endpoint */
     }
        
     while (d->range < 128) {  /* shift out irrelevant value bits */
       d->value <<= 1;
       d->range <<= 1;
       if (++d->bit_count == 8) {  /* shift in new bits 8 at a time */
         d->bit_count = 0;
         d->value |= *d->input++;
       }
     }
     return retval;
   }
        
     while (d->range < 128) {  /* shift out irrelevant value bits */
       d->value <<= 1;
       d->range <<= 1;
       if (++d->bit_count == 8) {  /* shift in new bits 8 at a time */
         d->bit_count = 0;
         d->value |= *d->input++;
       }
     }
     return retval;
   }
        
   /* Convenience function reads a "literal", that is, a "num_bits"-
      wide unsigned value whose bits come high- to low-order, with
      each bit encoded at probability 128 (i.e., 1/2). */
        
   /* Convenience function reads a "literal", that is, a "num_bits"-
      wide unsigned value whose bits come high- to low-order, with
      each bit encoded at probability 128 (i.e., 1/2). */
        
   uint32 read_literal(bool_decoder *d, int num_bits)
   {
     uint32 v = 0;
        
   uint32 read_literal(bool_decoder *d, int num_bits)
   {
     uint32 v = 0;
        
     while (num_bits--)
       v = (v << 1) + read_bool(d, 128);
     return v;
   }
        
     while (num_bits--)
       v = (v << 1) + read_bool(d, 128);
     return v;
   }
        
   /* Variant reads a signed number */
        
   /* Variant reads a signed number */
        
   int32 read_signed_literal(bool_decoder *d, int num_bits)
   {
     int32 v = 0;
     if (!num_bits)
       return 0;
     if (read_bool(d, 128))
       v = -1;
     while (--num_bits)
       v = (v << 1) + read_bool(d, 128);
     return v;
   }
        
   int32 read_signed_literal(bool_decoder *d, int num_bits)
   {
     int32 v = 0;
     if (!num_bits)
       return 0;
     if (read_bool(d, 128))
       v = -1;
     while (--num_bits)
       v = (v << 1) + read_bool(d, 128);
     return v;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
8. Compressed Data Components
8. 压缩数据组件

At the lowest level, VP8's compressed data is simply a sequence of probabilistically encoded bools. Most of this data is composed of (slightly) larger semantic units fashioned from bools, which we describe here.

在最底层,VP8的压缩数据只是一个概率编码布尔序列。这些数据中的大多数是由(稍大一点的)bools语义单元组成的,我们在这里描述。

We sometimes use these descriptions in C expressions within data format specifications. In this context, they refer to the return value of a call to an appropriate bool_decoder d, reading (as always) from its current reference point.

我们有时在数据格式规范的C表达式中使用这些描述。在这种情况下,它们指的是调用相应bool_解码器d的返回值,从其当前参考点读取(一如既往)。

   +--------------+-------+--------------------------------------------+
   | Call         | Alt.  | Return                                     |
   +--------------+-------+--------------------------------------------+
   | Bool(p)      | B(p)  | Bool with probability p/256 of being 0.    |
   |              |       | Return value of read_bool(d, p).           |
   |              |       |                                            |
   | Flag         | F     | A one-bit flag (same thing as a B(128) or  |
   |              |       | an L(1)).  Abbreviated F.  Return value of |
   |              |       | read_bool(d, 128).                         |
   |              |       |                                            |
   | Lit(n)       | L(n)  | Unsigned n-bit number encoded as n flags   |
   |              |       | (a "literal").  Abbreviated L(n).  The     |
   |              |       | bits are read from high to low order.      |
   |              |       | Return value of read_literal(d, n).        |
   |              |       |                                            |
   | SignedLit(n) |       | Signed n-bit number encoded similarly to   |
   |              |       | an L(n).  Return value of                  |
   |              |       | read_signed_literal(d, n).  These are      |
   |              |       | rare.                                      |
   |              |       |                                            |
   | P(8)         |       | An 8-bit probability.  No different from   |
   |              |       | an L(8), but we sometimes use this         |
   |              |       | notation to emphasize that a probability   |
   |              |       | is being coded.                            |
   |              |       |                                            |
   | P(7)         |       | A 7-bit specification of an 8-bit          |
   |              |       | probability.  Coded as an L(7) number x;   |
   |              |       | the resulting 8-bit probability is x ? x   |
   |              |       | << 1 : 1.                                  |
   |              |       |                                            |
   | F?  X        |       | A flag that, if true, is followed by a     |
   |              |       | piece of data X.                           |
   |              |       |                                            |
        
   +--------------+-------+--------------------------------------------+
   | Call         | Alt.  | Return                                     |
   +--------------+-------+--------------------------------------------+
   | Bool(p)      | B(p)  | Bool with probability p/256 of being 0.    |
   |              |       | Return value of read_bool(d, p).           |
   |              |       |                                            |
   | Flag         | F     | A one-bit flag (same thing as a B(128) or  |
   |              |       | an L(1)).  Abbreviated F.  Return value of |
   |              |       | read_bool(d, 128).                         |
   |              |       |                                            |
   | Lit(n)       | L(n)  | Unsigned n-bit number encoded as n flags   |
   |              |       | (a "literal").  Abbreviated L(n).  The     |
   |              |       | bits are read from high to low order.      |
   |              |       | Return value of read_literal(d, n).        |
   |              |       |                                            |
   | SignedLit(n) |       | Signed n-bit number encoded similarly to   |
   |              |       | an L(n).  Return value of                  |
   |              |       | read_signed_literal(d, n).  These are      |
   |              |       | rare.                                      |
   |              |       |                                            |
   | P(8)         |       | An 8-bit probability.  No different from   |
   |              |       | an L(8), but we sometimes use this         |
   |              |       | notation to emphasize that a probability   |
   |              |       | is being coded.                            |
   |              |       |                                            |
   | P(7)         |       | A 7-bit specification of an 8-bit          |
   |              |       | probability.  Coded as an L(7) number x;   |
   |              |       | the resulting 8-bit probability is x ? x   |
   |              |       | << 1 : 1.                                  |
   |              |       |                                            |
   | F?  X        |       | A flag that, if true, is followed by a     |
   |              |       | piece of data X.                           |
   |              |       |                                            |
        
   | F?  X:Y      |       | A flag that, if true, is followed by X     |
   |              |       | and, if false, is followed by Y.  Also     |
   |              |       | used to express a value where Y is an      |
   |              |       | implicit default (not encoded in the data  |
   |              |       | stream), as in F?  P(8):255, which         |
   |              |       | expresses an optional probability: If the  |
   |              |       | flag is true, the probability is specified |
   |              |       | as an 8-bit literal, while if the flag is  |
   |              |       | false, the probability defaults to 255.    |
   |              |       |                                            |
   | B(p)?  X     | B(p)? | Variants of the above using a boolean      |
   |              | X:Y   | indicator whose probability is not         |
   |              |       | necessarily 128.                           |
   |              |       |                                            |
   | T            |       | Tree-encoded value from small alphabet.    |
   +--------------+-------+--------------------------------------------+
        
   | F?  X:Y      |       | A flag that, if true, is followed by X     |
   |              |       | and, if false, is followed by Y.  Also     |
   |              |       | used to express a value where Y is an      |
   |              |       | implicit default (not encoded in the data  |
   |              |       | stream), as in F?  P(8):255, which         |
   |              |       | expresses an optional probability: If the  |
   |              |       | flag is true, the probability is specified |
   |              |       | as an 8-bit literal, while if the flag is  |
   |              |       | false, the probability defaults to 255.    |
   |              |       |                                            |
   | B(p)?  X     | B(p)? | Variants of the above using a boolean      |
   |              | X:Y   | indicator whose probability is not         |
   |              |       | necessarily 128.                           |
   |              |       |                                            |
   | T            |       | Tree-encoded value from small alphabet.    |
   +--------------+-------+--------------------------------------------+
        

The last type requires elaboration. We often wish to encode something whose value is restricted to a small number of possibilities (the alphabet).

最后一种类型需要细化。我们经常希望编码的东西,其价值被限制在少数可能性(字母表)。

This is done by representing the alphabet as the leaves of a small binary tree. The (non-leaf) nodes of the tree have associated probabilities p and correspond to calls to read_bool(d, p). We think of a zero as choosing the left branch below the node and a one as choosing the right branch.

这是通过将字母表表示为小二叉树的叶子来实现的。树的(非叶)节点具有相关概率p,并对应于对read_bool(d,p)的调用。我们认为零表示选择节点下方的左分支,一表示选择右分支。

Thus, every value (leaf) whose tree depth is x is decoded after exactly x calls to read_bool.

因此,树深度为x的每个值(叶)在x调用read_bool之后被解码。

A tree representing an encoding of an alphabet of n possible values always contains n-1 non-leaf nodes, regardless of its shape (this is easily seen by induction on n).

表示n个可能值的字母表编码的树始终包含n-1个非叶节点,而不管其形状如何(这很容易通过对n的归纳来看出)。

There are many ways that a given alphabet can be so represented. The choice of tree has little impact on datarate but does affect decoder performance. The trees used by VP8 are chosen to (on average) minimize the number of calls to read_bool. This amounts to shaping the tree so that values that are more probable have smaller tree depth than do values that are less probable.

一个给定的字母表有很多种表达方式。树的选择对数据速率几乎没有影响,但会影响解码器的性能。VP8使用的树的选择(平均)是为了最小化读取布尔的调用次数。这相当于对树进行整形,以便更可能的值比不太可能的值具有更小的树深度。

Readers familiar with Huffman coding will notice that, given an alphabet together with probabilities for each value, the associated Huffman tree minimizes the expected number of calls to read_bool.

熟悉哈夫曼编码的读者会注意到,给定一个字母表以及每个值的概率,关联的哈夫曼树会最小化读取布尔的预期调用数。

Such readers will also realize that the coding method described here never results in higher datarates than does the Huffman method and, indeed, often results in much lower datarates. Huffman coding is, in fact, nothing more than a special case of this method in which each node probability is fixed at 128 (i.e., 1/2).

这些读者还将认识到,这里描述的编码方法永远不会产生比哈夫曼方法更高的数据速率,事实上,通常会产生更低的数据速率。事实上,哈夫曼编码不过是这种方法的一种特例,其中每个节点的概率固定在128(即1/2)。

8.1. Tree Coding Implementation
8.1. 树编码实现

We give a suggested implementation of a tree data structure followed by a couple of actual examples of its usage by VP8.

我们给出了一个树数据结构的建议实现,然后给出了VP8使用它的两个实际示例。

It is most convenient to represent the values using small positive integers, typically an enum counting up from zero. The largest alphabet (used to code DCT coefficients, described in Section 13) that is tree-coded by VP8 has only 12 values. The tree for this alphabet adds 11 interior nodes and so has a total of 23 positions. Thus, an 8-bit number easily accommodates both a tree position and a return value.

使用小的正整数表示值是最方便的,通常是从零开始计数的枚举。VP8树编码的最大字母表(用于编码DCT系数,如第13节所述)只有12个值。此字母表的树添加了11个内部节点,因此总共有23个位置。因此,8位数字容易容纳树位置和返回值。

A tree may then be compactly represented as an array of (pairs of) 8-bit integers. Each (even) array index corresponds to an interior node of the tree; the 0th index of course corresponds to the root of the tree. The array entries come in pairs corresponding to the left (0) and right (1) branches of the subtree below the interior node. We use the convention that a positive (even) branch entry is the index of a deeper interior node, while a nonpositive entry v corresponds to a leaf whose value is -v.

然后,树可以紧凑地表示为8位整数(对)的数组。每个(偶数)数组索引对应于树的内部节点;当然,第0个索引对应于树的根。数组项成对出现,对应于内部节点下方子树的左(0)和右(1)分支。我们使用的约定是,正(偶数)分支条目是较深内部节点的索引,而非正条目v对应于值为-v的叶。

The node probabilities associated to a tree-coded value are stored in an array whose indices are half the indices of the corresponding tree positions. The length of the probability array is one less than the size of the alphabet.

与树编码值相关联的节点概率存储在一个数组中,该数组的索引是相应树位置索引的一半。概率数组的长度比字母表的大小小一个。

Here is C code implementing the foregoing. The advantages of our data structure should be noted. Aside from the smallness of the structure itself, the tree-directed reading algorithm is essentially a single line of code.

下面是实现上述功能的C代码。应该注意我们的数据结构的优点。除了结构本身很小之外,树定向读取算法本质上是一行代码。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* A tree specification is simply an array of 8-bit integers. */
        
   /* A tree specification is simply an array of 8-bit integers. */
        
   typedef int8 tree_index;
   typedef const tree_index Tree[];
        
   typedef int8 tree_index;
   typedef const tree_index Tree[];
        
   /* Read and return a tree-coded value at the current decoder
      position. */
        
   /* Read and return a tree-coded value at the current decoder
      position. */
        
   int treed_read(
     bool_decoder * const d, /* bool_decoder always returns a 0 or 1 */
     Tree t,                 /* tree specification */
     const Prob p[]     /* corresponding interior node probabilities */
   ) {
     register tree_index i = 0;   /* begin at root */
        
   int treed_read(
     bool_decoder * const d, /* bool_decoder always returns a 0 or 1 */
     Tree t,                 /* tree specification */
     const Prob p[]     /* corresponding interior node probabilities */
   ) {
     register tree_index i = 0;   /* begin at root */
        
     /* Descend tree until leaf is reached */
        
     /* Descend tree until leaf is reached */
        
     while ((i = t[ i + read_bool(d, p[i>>1])]) > 0) {}
        
     while ((i = t[ i + read_bool(d, p[i>>1])]) > 0) {}
        
     return -i;     /* return value is negation of nonpositive index */
   }
        
     return -i;     /* return value is negation of nonpositive index */
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Tree-based decoding is implemented in the reference decoder file bool_decoder.h (Section 20.2).

基于树的解码在参考解码器文件bool_decoder.h(第20.2节)中实现。

8.2. Tree Coding Example
8.2. 树编码示例

As a multi-part example, without getting too far into the semantics of macroblock decoding (which is of course taken up below), we look at the "mode" coding for intra-predicted macroblocks.

作为一个多部分示例,在不深入宏块解码语义的情况下(这当然在下面讨论),我们来看看帧内预测宏块的“模式”编码。

It so happens that, because of a difference in statistics, the Y (or luma) mode encoding uses two different trees: one for key frames and another for interframes. This is the only instance in VP8 of the same dataset being coded by different trees under different circumstances. The UV (or chroma) modes are a proper subset of the Y modes and, as such, have their own decoding tree.

由于统计数据的差异,Y(或luma)模式编码使用两种不同的树:一种用于关键帧,另一种用于帧间。这是VP8中同一数据集在不同情况下由不同树编码的唯一实例。UV(或色度)模式是Y模式的适当子集,因此具有其自己的解码树。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef enum
   {
       DC_PRED, /* predict DC using row above and column to the left */
       V_PRED,  /* predict rows using row above */
       H_PRED,  /* predict columns using column to the left */
       TM_PRED, /* propagate second differences a la "True Motion" */
        
   typedef enum
   {
       DC_PRED, /* predict DC using row above and column to the left */
       V_PRED,  /* predict rows using row above */
       H_PRED,  /* predict columns using column to the left */
       TM_PRED, /* propagate second differences a la "True Motion" */
        
       B_PRED,  /* each Y subblock is independently predicted */
        
       B_PRED,  /* each Y subblock is independently predicted */
        
       num_uv_modes = B_PRED,  /* first four modes apply to chroma */
       num_ymodes   /* all modes apply to luma */
   }
   intra_mbmode;
        
       num_uv_modes = B_PRED,  /* first four modes apply to chroma */
       num_ymodes   /* all modes apply to luma */
   }
   intra_mbmode;
        
   /* The aforementioned trees together with the implied codings as
      comments.
      Actual (i.e., positive) indices are always even.
      Value (i.e., nonpositive) indices are arbitrary. */
        
   /* The aforementioned trees together with the implied codings as
      comments.
      Actual (i.e., positive) indices are always even.
      Value (i.e., nonpositive) indices are arbitrary. */
        
   const tree_index ymode_tree [2 * (num_ymodes - 1)] =
   {
    -DC_PRED, 2,        /* root: DC_PRED = "0", "1" subtree */
     4, 6,              /* "1" subtree has 2 descendant subtrees */
      -V_PRED, -H_PRED, /* "10" subtree: V_PRED = "100",
                           H_PRED = "101" */
      -TM_PRED, -B_PRED /* "11" subtree: TM_PRED = "110",
                           B_PRED = "111" */
   };
        
   const tree_index ymode_tree [2 * (num_ymodes - 1)] =
   {
    -DC_PRED, 2,        /* root: DC_PRED = "0", "1" subtree */
     4, 6,              /* "1" subtree has 2 descendant subtrees */
      -V_PRED, -H_PRED, /* "10" subtree: V_PRED = "100",
                           H_PRED = "101" */
      -TM_PRED, -B_PRED /* "11" subtree: TM_PRED = "110",
                           B_PRED = "111" */
   };
        
   const tree_index kf_ymode_tree [2 * (num_ymodes - 1)] =
   {
    -B_PRED, 2,            /* root: B_PRED = "0", "1" subtree */
     4, 6,                 /* "1" subtree has 2 descendant subtrees */
      -DC_PRED, -V_PRED,   /* "10" subtree: DC_PRED = "100",
                              V_PRED = "101" */
      -H_PRED, -TM_PRED    /* "11" subtree: H_PRED = "110",
                              TM_PRED = "111" */
   };
        
   const tree_index kf_ymode_tree [2 * (num_ymodes - 1)] =
   {
    -B_PRED, 2,            /* root: B_PRED = "0", "1" subtree */
     4, 6,                 /* "1" subtree has 2 descendant subtrees */
      -DC_PRED, -V_PRED,   /* "10" subtree: DC_PRED = "100",
                              V_PRED = "101" */
      -H_PRED, -TM_PRED    /* "11" subtree: H_PRED = "110",
                              TM_PRED = "111" */
   };
        
   const tree_index uv_mode_tree [2 * (num_uv_modes - 1)] =
   {
    -DC_PRED, 2,          /* root: DC_PRED = "0", "1" subtree */
     -V_PRED, 4,          /* "1" subtree:  V_PRED = "10",
                             "11" subtree */
      -H_PRED, -TM_PRED   /* "11" subtree: H_PRED = "110",
                             TM_PRED = "111" */
   };
        
   const tree_index uv_mode_tree [2 * (num_uv_modes - 1)] =
   {
    -DC_PRED, 2,          /* root: DC_PRED = "0", "1" subtree */
     -V_PRED, 4,          /* "1" subtree:  V_PRED = "10",
                             "11" subtree */
      -H_PRED, -TM_PRED   /* "11" subtree: H_PRED = "110",
                             TM_PRED = "111" */
   };
        
   /* Given a bool_decoder d, a Y mode might be decoded as follows. */
        
   /* Given a bool_decoder d, a Y mode might be decoded as follows. */
        
   const Prob pretend_its_huffman [num_ymodes - 1] =
     { 128, 128, 128, 128};
        
   const Prob pretend_its_huffman [num_ymodes - 1] =
     { 128, 128, 128, 128};
        
   Ymode = (intra_mbmode) treed_read(d, ymode_tree,
     pretend_its_huffman);
        
   Ymode = (intra_mbmode) treed_read(d, ymode_tree,
     pretend_its_huffman);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Since it greatly facilitates re-use of reference code, and since there is no real reason to do otherwise, it is strongly suggested that any decoder implementation use exactly the same enumeration values and probability table layouts as those described in this document (and in the reference code) for all tree-coded data in VP8.

由于它极大地促进了参考代码的重复使用,并且没有真正的理由这样做,因此强烈建议任何解码器实现对VP8中的所有树编码数据使用与本文档(以及参考代码)中描述的完全相同的枚举值和概率表布局。

9. Frame Header
9. 帧头

The uncompressed data chunk at the start of each frame and at the first part of the first data partition contains information pertaining to the frame as a whole. We list the fields in the order of occurrence. Most of the header decoding occurs in the reference decoder file dixie.c (Section 20.4).

每个帧开头和第一个数据分区的第一部分的未压缩数据块包含与整个帧相关的信息。我们按出现的顺序列出字段。大多数头解码发生在参考解码器文件dixie.c中(第20.4节)。

9.1. Uncompressed Data Chunk
9.1. 未压缩数据块

The uncompressed data chunk comprises a common (for key frames and interframes) 3-byte frame tag that contains four fields, as follows:

未压缩数据块包含一个公共(用于关键帧和帧间)3字节帧标记,该标记包含四个字段,如下所示:

1. A 1-bit frame type (0 for key frames, 1 for interframes).

1. 1位帧类型(0表示关键帧,1表示干涉帧)。

2. A 3-bit version number (0 - 3 are defined as four different profiles with different decoding complexity; other values may be defined for future variants of the VP8 data format).

2. 一个3位版本号(0-3被定义为具有不同解码复杂度的四个不同配置文件;其他值可为VP8数据格式的未来变体定义)。

3. A 1-bit show_frame flag (0 when current frame is not for display, 1 when current frame is for display).

3. 1位显示帧标志(当前帧不用于显示时为0,当前帧用于显示时为1)。

4. A 19-bit field containing the size of the first data partition in bytes.

4. 包含第一个数据分区大小(字节)的19位字段。

The version number setting enables or disables certain features in the bitstream, as follows:

版本号设置启用或禁用位流中的某些功能,如下所示:

            +---------+-------------------------+-------------+
            | Version | Reconstruction Filter   | Loop Filter |
            +---------+-------------------------+-------------+
            | 0       | Bicubic                 | Normal      |
            |         |                         |             |
            | 1       | Bilinear                | Simple      |
            |         |                         |             |
            | 2       | Bilinear                | None        |
            |         |                         |             |
            | 3       | None                    | None        |
            |         |                         |             |
            | Other   | Reserved for future use |             |
            +---------+-------------------------+-------------+
        
            +---------+-------------------------+-------------+
            | Version | Reconstruction Filter   | Loop Filter |
            +---------+-------------------------+-------------+
            | 0       | Bicubic                 | Normal      |
            |         |                         |             |
            | 1       | Bilinear                | Simple      |
            |         |                         |             |
            | 2       | Bilinear                | None        |
            |         |                         |             |
            | 3       | None                    | None        |
            |         |                         |             |
            | Other   | Reserved for future use |             |
            +---------+-------------------------+-------------+
        

The reference software also adjusts the loop filter based on version number, as per the table above. Version number 1 implies a "simple" loop filter, and version numbers 2 and 3 imply no loop filter. However, the "simple" filter setting in this context has no effect whatsoever on the decoding process, and the "no loop filter" setting only forces the reference encoder to set filter level equal to 0. Neither affect the decoding process. In decoding, the only loop filter settings that matter are those in the frame header.

参考软件还根据上表,根据版本号调整循环过滤器。版本号1表示“简单”循环过滤器,版本号2和3表示没有循环过滤器。然而,在此上下文中的“简单”滤波器设置对解码过程没有任何影响,“无环路滤波器”设置仅强制参考编码器将滤波器电平设置为0。两者都不影响解码过程。在解码中,唯一重要的循环过滤器设置是帧头中的设置。

For key frames, the frame tag is followed by a further 7 bytes of uncompressed data, as follows:

对于关键帧,帧标记后面还有7个字节的未压缩数据,如下所示:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        

Start code byte 0 0x9d Start code byte 1 0x01 Start code byte 2 0x2a

开始代码字节0 0x9d开始代码字节1 0x01开始代码字节2 0x2a

   16 bits      :     (2 bits Horizontal Scale << 14) | Width (14 bits)
   16 bits      :     (2 bits Vertical Scale << 14) | Height (14 bits)
        
   16 bits      :     (2 bits Horizontal Scale << 14) | Width (14 bits)
   16 bits      :     (2 bits Vertical Scale << 14) | Height (14 bits)
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The following source code segment illustrates validation of the start code and reading the width, height, and scale factors for a key frame.

下面的源代码段演示了开始代码的验证以及读取关键帧的宽度、高度和比例因子。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   unsigned char *c = pbi->source+3;
        
   unsigned char *c = pbi->source+3;
        
   // vet via sync code
   if (c[0]!=0x9d||c[1]!=0x01||c[2]!=0x2a)
       return -1;
        
   // vet via sync code
   if (c[0]!=0x9d||c[1]!=0x01||c[2]!=0x2a)
       return -1;
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Where pbi->source points to the beginning of the frame.

其中pbi->source指向帧的开头。

The following code reads the image dimension from the bitstream:

以下代码从比特流读取图像维度:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   pc->Width      = swap2(*(unsigned short*)(c+3))&0x3fff;
   pc->horiz_scale = swap2(*(unsigned short*)(c+3))>>14;
   pc->Height     = swap2(*(unsigned short*)(c+5))&0x3fff;
   pc->vert_scale  = swap2(*(unsigned short*)(c+5))>>14;
        
   pc->Width      = swap2(*(unsigned short*)(c+3))&0x3fff;
   pc->horiz_scale = swap2(*(unsigned short*)(c+3))>>14;
   pc->Height     = swap2(*(unsigned short*)(c+5))&0x3fff;
   pc->vert_scale  = swap2(*(unsigned short*)(c+5))>>14;
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Where the swap2 macro takes care of the endian on a different platform:

swap2宏在不同平台上处理endian时:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   #if defined(__ppc__) || defined(__ppc64__)
   # define swap2(d)  \
     ((d&0x000000ff)<<8) |  \
     ((d&0x0000ff00)>>8)
   #else
     # define swap2(d) d
   #endif
        
   #if defined(__ppc__) || defined(__ppc64__)
   # define swap2(d)  \
     ((d&0x000000ff)<<8) |  \
     ((d&0x0000ff00)>>8)
   #else
     # define swap2(d) d
   #endif
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

While each frame is encoded as a raster scan of 16x16 macroblocks, the frame dimensions are not necessarily evenly divisible by 16. In this case, write ew = 16 - (width & 15) and eh = 16 - (height & 15) for the excess width and height, respectively. Although they are

虽然每个帧编码为16x16宏块的光栅扫描,但帧尺寸不一定能被16整除。在这种情况下,将多余的宽度和高度分别写入ew=16-(宽度和高度15)和eh=16-(高度和高度15)。虽然他们是

encoded, the last ew columns and eh rows are not actually part of the image and should be discarded before final output. However, these "excess pixels" should be maintained in the internal reconstruction buffer used to predict ensuing frames.

编码后,最后的ew列和eh行实际上不是图像的一部分,应该在最终输出之前丢弃。然而,这些“多余像素”应该保留在用于预测后续帧的内部重建缓冲区中。

The scaling specifications for each dimension are encoded as follows.

每个维度的缩放规格编码如下。

             +-------+--------------------------------------+
             | Value | Scaling                              |
             +-------+--------------------------------------+
             | 0     | No upscaling (the most common case). |
             |       |                                      |
             | 1     | Upscale by 5/4.                      |
             |       |                                      |
             | 2     | Upscale by 5/3.                      |
             |       |                                      |
             | 3     | Upscale by 2.                        |
             +-------+--------------------------------------+
        
             +-------+--------------------------------------+
             | Value | Scaling                              |
             +-------+--------------------------------------+
             | 0     | No upscaling (the most common case). |
             |       |                                      |
             | 1     | Upscale by 5/4.                      |
             |       |                                      |
             | 2     | Upscale by 5/3.                      |
             |       |                                      |
             | 3     | Upscale by 2.                        |
             +-------+--------------------------------------+
        

Upscaling does not affect the reconstruction buffer, which should be maintained at the encoded resolution. Any reasonable method of upsampling (including any that may be supported by video hardware in the playback environment) may be used. Since scaling has no effect on decoding, we do not discuss it any further.

放大不影响重建缓冲区,重建缓冲区应保持编码分辨率。可以使用任何合理的上采样方法(包括回放环境中视频硬件支持的任何上采样方法)。由于缩放对解码没有影响,我们不再进一步讨论它。

As discussed in Section 5, allocation (or re-allocation) of data structures (such as the reconstruction buffer) whose size depends on dimension will be triggered here.

如第5节所述,此处将触发大小取决于维度的数据结构(如重建缓冲区)的分配(或重新分配)。

9.2. Color Space and Pixel Type (Key Frames Only)
9.2. 颜色空间和像素类型(仅限关键帧)
           +-------+------------------------------------------+
           | Field | Value                                    |
           +-------+------------------------------------------+
           | L(1)  | 1-bit color space type specification     |
           |       |                                          |
           | L(1)  | 1-bit pixel value clamping specification |
           +-------+------------------------------------------+
        
           +-------+------------------------------------------+
           | Field | Value                                    |
           +-------+------------------------------------------+
           | L(1)  | 1-bit color space type specification     |
           |       |                                          |
           | L(1)  | 1-bit pixel value clamping specification |
           +-------+------------------------------------------+
        

The color space type bit is encoded as follows:

颜色空间类型位编码如下:

o 0 - YUV color space similar to the YCrCb color space defined in [ITU-R_BT.601]

o 0-YUV颜色空间,类似于[ITU-R_BT.601]中定义的YCrCb颜色空间

o 1 - Reserved for future use

o 1-保留供将来使用

The pixel value clamping type bit is encoded as follows:

像素值箝位类型位编码如下:

o 0 - Decoders are required to clamp the reconstructed pixel values to between 0 and 255 (inclusive).

o 0-需要使用解码器将重建的像素值钳制在0和255(包括0和255)之间。

o 1 - Reconstructed pixel values are guaranteed to be between 0 and 255; no clamping is necessary.

o 1-重建像素值保证在0到255之间;无需夹紧。

Information in this subsection does not appear in interframes.

本小节中的信息不会出现在干涉图中。

9.3. Segment-Based Adjustments
9.3. 基于分部的调整

This subsection contains probability and value information for implementing segment adaptive adjustments to default decoder behavior. The data in this subsection is used in the decoding of the ensuing per-segment information and applies to the entire frame. When segment adaptive adjustments are enabled, each macroblock will be assigned a segment ID. Macroblocks with the same segment ID belong to the same segment and have the same adaptive adjustments over default baseline values for the frame. The adjustments can be quantizer level or loop filter strength.

本小节包含对默认解码器行为实施段自适应调整的概率和值信息。本小节中的数据用于随后的每段信息的解码,并应用于整个帧。启用段自适应调整时,将为每个宏块分配一个段ID。具有相同段ID的宏块属于同一段,并且在帧的默认基线值上具有相同的自适应调整。调整可以是量化器电平或环路滤波器强度。

The context for decoding this feature at the macroblock level is provided by a subsection in the frame header, which contains:

在宏块级别解码该特征的上下文由帧头中的子部分提供,该子部分包含:

1. A segmentation_enabled flag that enables the feature for this frame if set to 1, and disables it if set to 0. The following fields occur if the feature is enabled.

1. 一个segmentation_enabled标志,如果设置为1,则启用此帧的功能,如果设置为0,则禁用该功能。如果启用该功能,则会出现以下字段。

2. L(1) indicates if the segment map is updated for the current frame (update_mb_segmentation_map).

2. L(1)表示是否为当前帧更新了段映射(更新\u mb\u segmentation\u映射)。

3. L(1) indicates if the segment feature data items are updated for the current frame (update_segment_feature_data).

3. L(1)表示是否为当前帧更新段特征数据项(更新段特征数据)。

4. If Item 3 above (update_segment_feature_data) is 1, the following fields occur:

4. 如果上面的第3项(更新\段\特征\数据)为1,则出现以下字段:

a. L(1), the mode of segment feature data (segment_feature_mode), can be absolute-value mode (0) or delta value mode (1).

a. L(1),段特征数据的模式(段特征模式),可以是绝对值模式(0)或增量值模式(1)。

b. Segment feature data items are decoded segment by segment for each segment feature. For every data item, a one-bit flag indicates whether the item is 0, or a non-zero value to be decoded. If the value is non-zero, then the value is decoded as a magnitude L(n), followed by a one-bit sign (L(1) -- 0 for positive and 1 for negative). The length n can be looked up from a pre-defined length table for all feature data.

b. 段特征数据项针对每个段特征逐段解码。对于每个数据项,一位标志指示该项是0还是要解码的非零值。如果该值不为零,则该值被解码为幅值L(n),后跟一位符号(L(1)——0表示正,1表示负)。可以从预定义的长度表中查找所有特征数据的长度n。

5. If the L(1) flag as noted in Item 2 above is set to 1, the probabilities of the decoding tree for the segment map are decoded from the bitstream. Each probability is decoded with a one-bit flag indicating whether the probability is the default value of 255 (flag is set to 0), or an 8-bit value, L(8), from the bitstream.

5. 如果如上面项目2中所述的L(1)标志被设置为1,则从比特流解码段映射的解码树的概率。使用一位标志对每个概率进行解码,该标志指示概率是来自比特流的默认值255(标志设置为0)还是8位值L(8)。

The layout and semantics supporting this feature at the macroblock level are described in Section 10.

第10节描述了在宏块级别支持此功能的布局和语义。

9.4. Loop Filter Type and Levels
9.4. 环路滤波器类型和电平

VP8 supports two types of loop filters having different computational complexity. The following bits occur in the header to support the selection of the baseline type, strength, and sharpness behavior of the loop filter used for the current frame.

VP8支持两种计算复杂度不同的环路滤波器。以下位出现在标题中,以支持选择用于当前帧的循环过滤器的基线类型、强度和锐度行为。

                       +-------+-------------------+
                       | Index | Description       |
                       +-------+-------------------+
                       | L(1)  | filter_type       |
                       |       |                   |
                       | L(6)  | loop_filter_level |
                       |       |                   |
                       | L(3)  | sharpness_level   |
                       +-------+-------------------+
        
                       +-------+-------------------+
                       | Index | Description       |
                       +-------+-------------------+
                       | L(1)  | filter_type       |
                       |       |                   |
                       | L(6)  | loop_filter_level |
                       |       |                   |
                       | L(3)  | sharpness_level   |
                       +-------+-------------------+
        

The meaning of these numbers will be further explained in Section 15.

第15节将进一步解释这些数字的含义。

VP8 has a feature in the bitstream that enables adjustment of the loop filter level based on a macroblock's prediction mode and reference frame. The per-macroblock adjustment is done through delta values against the default loop filter level for the current frame. This subsection contains flag and value information for implementing per-macroblock loop filter level adjustment to default decoder behavior. The data in this section is used in the decoding of the ensuing per-macroblock information and applies to the entire frame.

VP8在比特流中具有一个特性,该特性使得能够基于宏块的预测模式和参考帧来调整循环滤波器电平。每宏块调整是根据当前帧的默认循环过滤器级别,通过增量值完成的。本小节包含用于将每个宏块循环滤波器电平调整到默认解码器行为的标志和值信息。该部分中的数据用于随后的每个宏块信息的解码,并应用于整个帧。

L(1) is a one-bit flag indicating if the macroblock loop filter adjustment is on for the current frame. 0 means that such a feature is not supported in the current frame, and 1 means this feature is enabled for the current frame.

L(1)是一位标志,指示当前帧的宏块循环滤波器调整是否开启。0表示当前帧不支持此功能,1表示当前帧已启用此功能。

Whether the adjustment is based on a reference frame or encoding mode, the adjustment of the loop filter level is done via a delta value against a baseline loop filter value. The delta values are updated for the current frame if an L(1) bit, mode_ref_lf_delta_update, takes the value 1. There are two groups of delta values: One group of delta values is for reference frame-based adjustments, and the other group is for mode-based adjustments. The number of delta values in the two groups is MAX_REF_LF_DELTAS and MAX_MODE_LF_DELTAS, respectively. For every value within the two groups, there is a one-bit L(1) to indicate if the particular value is updated. When one is updated (1), it is transmitted as a six-bit-magnitude L(6) followed by a one-bit sign flag (L(1) -- 0 for positive and 1 for negative).

无论调整是基于参考帧还是编码模式,循环滤波器电平的调整都是通过相对于基线循环滤波器值的增量值来完成的。如果L(1)位mode_ref_lf_delta_update的值为1,则更新当前帧的delta值。有两组增量值:一组增量值用于基于参考帧的调整,另一组用于基于模式的调整。两组中的增量值数量分别为MAX_REF_LF_delta和MAX_MODE_LF_delta。对于两个组中的每个值,都有一个1位L(1)来指示是否更新了特定值。当一个被更新(1)时,它被传输为一个六位幅值L(6),后跟一位符号标志(L(1)——0表示正,1表示负)。

9.5. Token Partition and Partition Data Offsets
9.5. 令牌分区和分区数据偏移

VP8 allows DCT coefficients to be packed into multiple partitions, besides the first partition with header and per-macroblock prediction information, so the decoder can perform parallel decoding in an efficient manner. A two-bit L(2) is used to indicate the number of coefficient data partitions within a compressed frame. The two bits are defined in the following table:

VP8允许将DCT系数打包到多个分区中,除了第一个分区具有报头和每宏块预测信息之外,因此解码器可以高效地执行并行解码。两位L(2)用于指示压缩帧内系数数据分区的数量。下表中定义了这两个位:

                 +-------+-------+----------------------+
                 | Bit 1 | Bit 0 | Number of Partitions |
                 +-------+-------+----------------------+
                 | 0     | 0     | 1                    |
                 |       |       |                      |
                 | 0     | 1     | 2                    |
                 |       |       |                      |
                 | 1     | 0     | 4                    |
                 |       |       |                      |
                 | 1     | 1     | 8                    |
                 +-------+-------+----------------------+
        
                 +-------+-------+----------------------+
                 | Bit 1 | Bit 0 | Number of Partitions |
                 +-------+-------+----------------------+
                 | 0     | 0     | 1                    |
                 |       |       |                      |
                 | 0     | 1     | 2                    |
                 |       |       |                      |
                 | 1     | 0     | 4                    |
                 |       |       |                      |
                 | 1     | 1     | 8                    |
                 +-------+-------+----------------------+
        

Offsets are embedded in the bitstream to provide the decoder direct access to token partitions. If the number of data partitions is greater than 1, the size of each partition (except the last) is written in 3 bytes (24 bits). The size of the last partition is the remainder of the data not used by any of the previous partitions.

偏移量嵌入在比特流中,以便解码器直接访问令牌分区。如果数据分区的数量大于1,则每个分区(最后一个除外)的大小以3字节(24位)写入。最后一个分区的大小是前一个分区未使用的剩余数据。

The partitioned data are consecutive in the bitstream, so the size can also be used to calculate the offset of each partition. The following pseudocode illustrates how the size/offset is defined by the three bytes in the bitstream.

分区数据在比特流中是连续的,因此大小也可用于计算每个分区的偏移量。以下伪代码说明了如何通过位流中的三个字节定义大小/偏移量。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   Offset/size  =  (uint32)(byte0) + ((uint32)(byte1)<<8)
     + ((uint32)(byte2)<<16);
        
   Offset/size  =  (uint32)(byte0) + ((uint32)(byte1)<<8)
     + ((uint32)(byte2)<<16);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
9.6. Dequantization Indices
9.6. 去量化指数

All residue signals are specified via a quantized 4x4 DCT applied to the Y, U, V, or Y2 subblocks of a macroblock. As detailed in Section 14, before inverting the transform, each decoded coefficient is multiplied by one of six dequantization factors, the choice of which depends on the plane (Y, chroma = U or V, Y2) and coefficient position (DC = coefficient 0, AC = coefficients 1-15). The six values are specified using 7-bit indices into six corresponding fixed tables (the tables are given in Section 14).

所有剩余信号通过应用于宏块的Y、U、V或Y2子块的量化4x4 DCT来指定。如第14节所述,在逆变换变换之前,每个解码系数乘以六个去量化因子中的一个,其选择取决于平面(Y,色度=U或V,Y2)和系数位置(DC=系数0,AC=系数1-15)。使用7位索引将六个值指定为六个相应的固定表(表在第14节中给出)。

The first 7-bit index gives the dequantization table index for Y-plane AC coefficients, called yac_qi. It is always coded and acts as a baseline for the other 5 quantization indices, each of which is represented by a delta from this baseline index. Pseudocode for reading the indices follows:

第一个7位索引给出Y平面AC系数的去量化表索引,称为yac_qi。它总是被编码并充当其他5个量化索引的基线,每个量化索引都由该基线索引的增量表示。用于读取索引的伪代码如下所示:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   yac_qi     = L(7);           /* Y ac index always specified */
   ydc_delta  = F? delta(): 0;  /* Y dc delta specified if
                                   flag is true */
        
   yac_qi     = L(7);           /* Y ac index always specified */
   ydc_delta  = F? delta(): 0;  /* Y dc delta specified if
                                   flag is true */
        
   y2dc_delta = F? delta(): 0;  /* Y2 dc delta specified if
                                   flag is true */
   y2ac_delta = F? delta(): 0;  /* Y2 ac delta specified if
                                   flag is true */
        
   y2dc_delta = F? delta(): 0;  /* Y2 dc delta specified if
                                   flag is true */
   y2ac_delta = F? delta(): 0;  /* Y2 ac delta specified if
                                   flag is true */
        
   uvdc_delta = F? delta(): 0;  /* chroma dc delta specified
                                   if flag is true */
   uvac_delta = F? delta(): 0;  /* chroma ac delta specified
                                   if flag is true */
        
   uvdc_delta = F? delta(): 0;  /* chroma dc delta specified
                                   if flag is true */
   uvac_delta = F? delta(): 0;  /* chroma ac delta specified
                                   if flag is true */
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Where delta() is the process to read 5 bits from the bitstream to determine a signed delta value:

其中delta()是从比特流中读取5位以确定有符号delta值的过程:

       +-------+--------------------------------------------------+
       | Index | Description                                      |
       +-------+--------------------------------------------------+
       | L(4)  | Magnitude of delta                               |
       |       |                                                  |
       | L(1)  | Sign of delta, 0 for positive and 1 for negative |
       +-------+--------------------------------------------------+
        
       +-------+--------------------------------------------------+
       | Index | Description                                      |
       +-------+--------------------------------------------------+
       | L(4)  | Magnitude of delta                               |
       |       |                                                  |
       | L(1)  | Sign of delta, 0 for positive and 1 for negative |
       +-------+--------------------------------------------------+
        
9.7. Refresh Golden Frame and Altref Frame
9.7. 刷新金色框架和Altref框架

For key frames, both the golden frame and the altref frame are refreshed/ replaced by the current reconstructed frame, by default. For non-key frames, VP8 uses two bits to indicate whether the two frame buffers are refreshed, using the reconstructed current frame:

对于关键帧,默认情况下,黄金帧和altref帧都将刷新/替换为当前重建帧。对于非关键帧,VP8使用两个位指示是否使用重建的当前帧刷新两个帧缓冲区:

   +-------+----------------------------------------------------------+
   | Index | Description                                              |
   +-------+----------------------------------------------------------+
   | L(1)  | Whether golden frame is refreshed (0 for no, 1 for yes). |
   |       |                                                          |
   | L(1)  | Whether altref frame is refreshed (0 for no, 1 for yes). |
   +-------+----------------------------------------------------------+
        
   +-------+----------------------------------------------------------+
   | Index | Description                                              |
   +-------+----------------------------------------------------------+
   | L(1)  | Whether golden frame is refreshed (0 for no, 1 for yes). |
   |       |                                                          |
   | L(1)  | Whether altref frame is refreshed (0 for no, 1 for yes). |
   +-------+----------------------------------------------------------+
        

When the flag for the golden frame is 0, VP8 uses 2 more bits in the bitstream to indicate whether the buffer (and which buffer) is copied to the golden frame, or if no buffer is copied:

当黄金帧的标志为0时,VP8在比特流中再使用2位来指示是否将缓冲区(以及哪个缓冲区)复制到黄金帧,或者如果没有复制缓冲区:

           +-------+------------------------------------------+
           | Index | Description                              |
           +-------+------------------------------------------+
           | L(2)  | Buffer copy flag for golden frame buffer |
           +-------+------------------------------------------+
        
           +-------+------------------------------------------+
           | Index | Description                              |
           +-------+------------------------------------------+
           | L(2)  | Buffer copy flag for golden frame buffer |
           +-------+------------------------------------------+
        

Where:

哪里:

o 0 means no buffer is copied to the golden frame

o 0表示没有缓冲区复制到黄金帧

o 1 means last_frame is copied to the golden frame

o 1表示最后一帧复制到黄金帧

o 2 means alt_ref_frame is copied to the golden frame

o 2表示alt_ref_帧复制到黄金帧

Similarly, when the flag for altref is 0, VP8 uses 2 bits in the bitstream to indicate which buffer is copied to alt_ref_frame.

类似地,当altref的标志为0时,VP8使用位流中的2位来指示将哪个缓冲区复制到alt_ref_帧。

           +-------+------------------------------------------+
           | Index | Description                              |
           +-------+------------------------------------------+
           | L(2)  | Buffer copy flag for altref frame buffer |
           +-------+------------------------------------------+
        
           +-------+------------------------------------------+
           | Index | Description                              |
           +-------+------------------------------------------+
           | L(2)  | Buffer copy flag for altref frame buffer |
           +-------+------------------------------------------+
        

Where:

哪里:

o 0 means no buffer is copied to the altref frame

o 0表示未将缓冲区复制到altref帧

o 1 means last_frame is copied to the altref frame

o 1表示最后一帧复制到altref帧

o 2 means golden_frame is copied to the altref frame

o 2表示金色框架复制到altref框架

Two bits are transmitted for ref_frame_sign_bias for golden_frame and alt_ref_frame, respectively.

分别为黄金帧和alt\u ref\u帧的ref\u frame\u sign\u bias发送两位。

                +-------+---------------------------------+
                | Index | Description                     |
                +-------+---------------------------------+
                | L(1)  | Sign bias flag for golden frame |
                |       |                                 |
                | L(1)  | Sign bias flag for altref frame |
                +-------+---------------------------------+
        
                +-------+---------------------------------+
                | Index | Description                     |
                +-------+---------------------------------+
                | L(1)  | Sign bias flag for golden frame |
                |       |                                 |
                | L(1)  | Sign bias flag for altref frame |
                +-------+---------------------------------+
        

These values are used to control the sign of the motion vectors when a golden frame or an altref frame is used as the reference frame for a macroblock.

当黄金帧或altref帧用作宏块的参考帧时,这些值用于控制运动向量的符号。

9.8. Refresh Last Frame Buffer
9.8. 刷新最后一帧缓冲区

VP8 uses one bit, L(1), to indicate if the last frame reference buffer is refreshed using the constructed current frame. On a key frame, this bit is overridden, and the last frame buffer is always refreshed.

VP8使用一个位L(1)来指示是否使用构造的当前帧刷新最后一个帧参考缓冲区。在关键帧上,此位被覆盖,并且始终刷新最后一个帧缓冲区。

9.9. DCT Coefficient Probability Update
9.9. DCT系数概率更新

This field contains updates to the probability tables used to decode DCT coefficients. For each of the probabilities in the tables, there is an L(1) flag indicating if the probability is updated for the current frame, and if the L(1) flag is set to 1, there follows an additional 8-bit value representing the new probability value. These tables are maintained across interframes but are of course replaced with their defaults at the beginning of every key frame.

此字段包含用于解码DCT系数的概率表的更新。对于表中的每个概率,存在一个L(1)标志,指示是否针对当前帧更新了概率,并且如果L(1)标志被设置为1,则跟随表示新概率值的附加8位值。这些表格在帧间进行维护,但在每个关键帧的开头,当然会替换为其默认值。

The layout and semantics of this field will be taken up in Section 13.

该字段的布局和语义将在第13节中讨论。

9.10. Remaining Frame Header Data (Non-Key Frame)
9.10. 剩余帧头数据(非关键帧)
   +-------+-----------------------------------------------------------+
   | Index | Description                                               |
   +-------+-----------------------------------------------------------+
   | L(1)  | mb_no_skip_coeff.  This flag indicates at the frame level |
   |       | if skipping of macroblocks with no non-zero coefficients  |
   |       | is enabled.  If it is set to 0, then prob_skip_false is   |
   |       | not read and mb_skip_coeff is forced to 0 for all         |
   |       | macroblocks (see Sections 11.1 and 12.1).                 |
   |       |                                                           |
   | L(8)  | prob_skip_false = probability used for decoding a         |
   |       | macroblock-level flag, which indicates if a macroblock    |
   |       | has any non-zero coefficients.  Only read if              |
   |       | mb_no_skip_coeff is 1.                                    |
   |       |                                                           |
   | L(8)  | prob_intra = probability that a macroblock is "intra"     |
   |       | predicted (that is, predicted from the already-encoded    |
   |       | portions of the current frame), as opposed to "inter"     |
   |       | predicted (that is, predicted from the contents of a      |
   |       | prior frame).                                             |
   |       |                                                           |
   | L(8)  | prob_last = probability that an inter-predicted           |
   |       | macroblock is predicted from the immediately previous     |
   |       | frame, as opposed to the most recent golden frame or      |
   |       | altref frame.                                             |
   |       |                                                           |
   | L(8)  | prob_gf = probability that an inter-predicted macroblock  |
   |       | is predicted from the most recent golden frame, as        |
   |       | opposed to the altref frame.                              |
   |       |                                                           |
   | F     | If true, followed by four L(8)s updating the              |
   |       | probabilities for the different types of intra-prediction |
   |       | for the Y plane.  These probabilities correspond to the   |
   |       | four interior nodes of the decoding tree for intra-Y      |
   |       | modes in an interframe, that is, the even positions in    |
   |       | the ymode_tree array given above.                         |
   |       |                                                           |
   | F     | If true, followed by three L(8)s updating the             |
   |       | probabilities for the different types of intra-prediction |
   |       | for the chroma planes.  These probabilities correspond to |
   |       | the even positions in the uv_mode_tree array given above. |
   |       |                                                           |
   | X     | Motion vector probability update.  Details are given in   |
   |       | Section 17.2, "Probability Updates".                      |
   +-------+-----------------------------------------------------------+
        
   +-------+-----------------------------------------------------------+
   | Index | Description                                               |
   +-------+-----------------------------------------------------------+
   | L(1)  | mb_no_skip_coeff.  This flag indicates at the frame level |
   |       | if skipping of macroblocks with no non-zero coefficients  |
   |       | is enabled.  If it is set to 0, then prob_skip_false is   |
   |       | not read and mb_skip_coeff is forced to 0 for all         |
   |       | macroblocks (see Sections 11.1 and 12.1).                 |
   |       |                                                           |
   | L(8)  | prob_skip_false = probability used for decoding a         |
   |       | macroblock-level flag, which indicates if a macroblock    |
   |       | has any non-zero coefficients.  Only read if              |
   |       | mb_no_skip_coeff is 1.                                    |
   |       |                                                           |
   | L(8)  | prob_intra = probability that a macroblock is "intra"     |
   |       | predicted (that is, predicted from the already-encoded    |
   |       | portions of the current frame), as opposed to "inter"     |
   |       | predicted (that is, predicted from the contents of a      |
   |       | prior frame).                                             |
   |       |                                                           |
   | L(8)  | prob_last = probability that an inter-predicted           |
   |       | macroblock is predicted from the immediately previous     |
   |       | frame, as opposed to the most recent golden frame or      |
   |       | altref frame.                                             |
   |       |                                                           |
   | L(8)  | prob_gf = probability that an inter-predicted macroblock  |
   |       | is predicted from the most recent golden frame, as        |
   |       | opposed to the altref frame.                              |
   |       |                                                           |
   | F     | If true, followed by four L(8)s updating the              |
   |       | probabilities for the different types of intra-prediction |
   |       | for the Y plane.  These probabilities correspond to the   |
   |       | four interior nodes of the decoding tree for intra-Y      |
   |       | modes in an interframe, that is, the even positions in    |
   |       | the ymode_tree array given above.                         |
   |       |                                                           |
   | F     | If true, followed by three L(8)s updating the             |
   |       | probabilities for the different types of intra-prediction |
   |       | for the chroma planes.  These probabilities correspond to |
   |       | the even positions in the uv_mode_tree array given above. |
   |       |                                                           |
   | X     | Motion vector probability update.  Details are given in   |
   |       | Section 17.2, "Probability Updates".                      |
   +-------+-----------------------------------------------------------+
        

Decoding of this portion of the frame header is handled in the reference decoder file dixie.c (Section 20.4).

这部分帧头的解码在参考解码器文件dixie.c(第20.4节)中处理。

9.11. Remaining Frame Header Data (Key Frame)
9.11. 剩余帧头数据(关键帧)
   +-------+-----------------------------------------------------------+
   | Index | Description                                               |
   +-------+-----------------------------------------------------------+
   | L(1)  | mb_no_skip_coeff.  This flag indicates at the frame level |
   |       | if skipping of macroblocks with no non-zero coefficients  |
   |       | is enabled.  If it is set to 0, then prob_skip_false is   |
   |       | not read and mb_skip_coeff is forced to 0 for all         |
   |       | macroblocks (see Sections 11.1 and 12.1).                 |
   |       |                                                           |
   | L(8)  | prob_skip_false = Probability used for decoding a         |
   |       | macroblock-level flag, which indicates if a macroblock    |
   |       | has any non-zero coefficients.  Only read if              |
   |       | mb_no_skip_coeff is 1.                                    |
   +-------+-----------------------------------------------------------+
        
   +-------+-----------------------------------------------------------+
   | Index | Description                                               |
   +-------+-----------------------------------------------------------+
   | L(1)  | mb_no_skip_coeff.  This flag indicates at the frame level |
   |       | if skipping of macroblocks with no non-zero coefficients  |
   |       | is enabled.  If it is set to 0, then prob_skip_false is   |
   |       | not read and mb_skip_coeff is forced to 0 for all         |
   |       | macroblocks (see Sections 11.1 and 12.1).                 |
   |       |                                                           |
   | L(8)  | prob_skip_false = Probability used for decoding a         |
   |       | macroblock-level flag, which indicates if a macroblock    |
   |       | has any non-zero coefficients.  Only read if              |
   |       | mb_no_skip_coeff is 1.                                    |
   +-------+-----------------------------------------------------------+
        

Decoding of this portion of the frame header is handled in the reference decoder file modemv.c (Section 20.11).

帧头这一部分的解码在参考解码器文件modemv.c(第20.11节)中处理。

This completes the layout of the frame header. The remainder of the first data partition consists of macroblock-level prediction data.

这就完成了框架标题的布局。第一数据分区的其余部分由宏块级预测数据组成。

After the frame header is processed, all probabilities needed to decode the prediction and residue data are known and will not change until the next frame.

在处理帧头之后,解码预测和剩余数据所需的所有概率都是已知的,并且在下一帧之前不会改变。

10. Segment-Based Feature Adjustments
10. 基于段的特征调整

Every macroblock may optionally override some of the default behaviors of the decoder. Specifically, VP8 uses segment-based adjustments to support changing quantizer level and loop filter level for a macroblock. When the segment-based adjustment feature is enabled for a frame, each macroblock within the frame is coded with a segment_id. This effectively segments all the macroblocks in the current frame into a number of different segments. Macroblocks within the same segment behave exactly the same for quantizer and loop filter level adjustments.

每个宏块可以选择性地覆盖解码器的一些默认行为。具体而言,VP8使用基于段的调整来支持改变宏块的量化器电平和环路滤波器电平。当为帧启用基于段的调整功能时,帧内的每个宏块都使用段id进行编码。这有效地将当前帧中的所有宏块分割为多个不同的段。对于量化器和环路滤波器电平调整,同一段中的宏块的行为完全相同。

If both the segmentation_enabled and update_mb_segmentation_map flags in subsection B of the frame header take a value of 1, the prediction data for each (intra- or inter-coded) macroblock begins with a specification of segment_id for the current macroblock. It is decoded using this simple tree ...

如果帧头的分段B中的分段启用和更新分段映射标志的值均为1,则每个(帧内或帧间编码的)宏块的预测数据从当前宏块的分段id的指定开始。它是用这个简单的树解码的。。。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const tree_index mb_segment_tree [2 * (4-1)] =
     {
       2,  4,     /* root: "0", "1" subtrees */
       -0, -1,    /* "00" = 0th value, "01" = 1st value */
        -2, -3    /* "10" = 2nd value, "11" = 3rd value */
     }
        
   const tree_index mb_segment_tree [2 * (4-1)] =
     {
       2,  4,     /* root: "0", "1" subtrees */
       -0, -1,    /* "00" = 0th value, "01" = 1st value */
        -2, -3    /* "10" = 2nd value, "11" = 3rd value */
     }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

... combined with a 3-entry probability table, mb_segment_tree_probs[3]. The macroblock's segment_id is used later in the decoding process to look into the segment_feature_data table and determine how the quantizer and loop filter levels are adjusted.

... 结合一个三项概率表,mb_段_树_问题[3]。宏块的segment_id稍后在解码过程中用于查看segment_feature_数据表并确定如何调整量化器和环路滤波器电平。

The decoding of segment_id, together with the parsing of intra-prediction modes (which is taken up next), is implemented in the reference decoder file modemv.c.

在参考解码器文件modemv.c中实现段_id的解码以及帧内预测模式的解析(下一步讨论)。

11. Key Frame Macroblock Prediction Records
11. 关键帧宏块预测记录

After specifying the features described above, the macroblock prediction record next specifies the prediction mode used for the macroblock.

在指定上述特征之后,宏块预测记录接下来指定用于宏块的预测模式。

11.1. mb_skip_coeff
11.1. mb_skip_coeff

The single bool flag is decoded using prob_skip_false if and only if mb_no_skip_coeff is set to 1 (see Sections 9.10 and 9.11). If mb_no_skip_coeff is set to 0, then this value defaults to 0.

当且仅当mb_no_skip_coeff设置为1时(见第9.10节和第9.11节),使用prob_skip_false对单个bool标志进行解码。如果mb_no_skip_coeff设置为0,则该值默认为0。

11.2. Luma Modes
11.2. 亮度模式

First comes the luma specification of type intra_mbmode, coded using the kf_ymode_tree, as described in Section 8 and repeated here for convenience:

首先是intra_mbmode类型的luma规范,使用kf_ymode_树进行编码,如第8节所述,为了方便起见在此处重复:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef enum
   {
       DC_PRED, /* predict DC using row above and column to the left */
       V_PRED,  /* predict rows using row above */
       H_PRED,  /* predict columns using column to the left */
       TM_PRED, /* propagate second differences a la "True Motion" */
        
   typedef enum
   {
       DC_PRED, /* predict DC using row above and column to the left */
       V_PRED,  /* predict rows using row above */
       H_PRED,  /* predict columns using column to the left */
       TM_PRED, /* propagate second differences a la "True Motion" */
        
       B_PRED,  /* each Y subblock is independently predicted */
        
       B_PRED,  /* each Y subblock is independently predicted */
        
       num_uv_modes = B_PRED,  /* first four modes apply to chroma */
       num_ymodes   /* all modes apply to luma */
   }
   intra_mbmode;
        
       num_uv_modes = B_PRED,  /* first four modes apply to chroma */
       num_ymodes   /* all modes apply to luma */
   }
   intra_mbmode;
        
   const tree_index kf_ymode_tree [2 * (num_ymodes - 1)] =
   {
    -B_PRED, 2,            /* root: B_PRED = "0", "1" subtree */
     4, 6,                 /* "1" subtree has 2 descendant subtrees */
      -DC_PRED, -V_PRED,   /* "10" subtree: DC_PRED = "100",
                              V_PRED = "101" */
      -H_PRED, -TM_PRED    /* "11" subtree: H_PRED = "110",
                              TM_PRED = "111" */
   };
        
   const tree_index kf_ymode_tree [2 * (num_ymodes - 1)] =
   {
    -B_PRED, 2,            /* root: B_PRED = "0", "1" subtree */
     4, 6,                 /* "1" subtree has 2 descendant subtrees */
      -DC_PRED, -V_PRED,   /* "10" subtree: DC_PRED = "100",
                              V_PRED = "101" */
      -H_PRED, -TM_PRED    /* "11" subtree: H_PRED = "110",
                              TM_PRED = "111" */
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

For key frames, the Y mode is decoded using a fixed probability array as follows:

对于关键帧,使用固定概率数组解码Y模式,如下所示:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const Prob kf_ymode_prob [num_ymodes - 1] = { 145, 156, 163, 128};
   Ymode = (intra_mbmode) treed_read(d, kf_ymode_tree, kf_ymode_prob);
        
   const Prob kf_ymode_prob [num_ymodes - 1] = { 145, 156, 163, 128};
   Ymode = (intra_mbmode) treed_read(d, kf_ymode_tree, kf_ymode_prob);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

d is of course the bool_decoder being used to read the first data partition.

d当然是用于读取第一个数据分区的bool_解码器。

If the Ymode is B_PRED, it is followed by a (tree-coded) mode for each of the 16 Y subblocks. The 10 subblock modes and their coding tree are as follows:

如果Ymode是B_PRED,则16个Y子块中的每一个子块后面都有一个(树编码)模式。10个子块模式及其编码树如下:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef enum
   {
       B_DC_PRED,  /* predict DC using row above and column
                      to the left */
       B_TM_PRED,  /* propagate second differences a la
                      "True Motion" */
        
   typedef enum
   {
       B_DC_PRED,  /* predict DC using row above and column
                      to the left */
       B_TM_PRED,  /* propagate second differences a la
                      "True Motion" */
        
       B_VE_PRED,  /* predict rows using row above */
       B_HE_PRED,  /* predict columns using column to the left */
        
       B_VE_PRED,  /* predict rows using row above */
       B_HE_PRED,  /* predict columns using column to the left */
        
       B_LD_PRED,  /* southwest (left and down) 45 degree diagonal
                      prediction */
       B_RD_PRED,  /* southeast (right and down) "" */
        
       B_LD_PRED,  /* southwest (left and down) 45 degree diagonal
                      prediction */
       B_RD_PRED,  /* southeast (right and down) "" */
        
       B_VR_PRED,  /* SSE (vertical right) diagonal prediction */
       B_VL_PRED,  /* SSW (vertical left) "" */
       B_HD_PRED,  /* ESE (horizontal down) "" */
       B_HU_PRED,  /* ENE (horizontal up) "" */
        
       B_VR_PRED,  /* SSE (vertical right) diagonal prediction */
       B_VL_PRED,  /* SSW (vertical left) "" */
       B_HD_PRED,  /* ESE (horizontal down) "" */
       B_HU_PRED,  /* ENE (horizontal up) "" */
        
       num_intra_bmodes
   }
   intra_bmode;
        
       num_intra_bmodes
   }
   intra_bmode;
        
   /* Coding tree for the above, with implied codings as comments */
        
   /* Coding tree for the above, with implied codings as comments */
        
   const tree_index bmode_tree [2 * (num_intra_bmodes - 1)] =
   {
    -B_DC_PRED, 2,                   /* B_DC_PRED = "0" */
     -B_TM_PRED, 4,                  /* B_TM_PRED = "10" */
      -B_VE_PRED, 6,                 /* B_VE_PRED = "110" */
       8, 12,
        -B_HE_PRED, 10,              /* B_HE_PRED = "11100" */
         -B_RD_PRED, -B_VR_PRED,     /* B_RD_PRED = "111010",
                                        B_VR_PRED = "111011" */
        -B_LD_PRED, 14,              /* B_LD_PRED = "111110" */
          -B_VL_PRED, 16,            /* B_VL_PRED = "1111110" */
            -B_HD_PRED, -B_HU_PRED   /* HD = "11111110",
                                        HU = "11111111" */
   };
        
   const tree_index bmode_tree [2 * (num_intra_bmodes - 1)] =
   {
    -B_DC_PRED, 2,                   /* B_DC_PRED = "0" */
     -B_TM_PRED, 4,                  /* B_TM_PRED = "10" */
      -B_VE_PRED, 6,                 /* B_VE_PRED = "110" */
       8, 12,
        -B_HE_PRED, 10,              /* B_HE_PRED = "11100" */
         -B_RD_PRED, -B_VR_PRED,     /* B_RD_PRED = "111010",
                                        B_VR_PRED = "111011" */
        -B_LD_PRED, 14,              /* B_LD_PRED = "111110" */
          -B_VL_PRED, 16,            /* B_VL_PRED = "1111110" */
            -B_HD_PRED, -B_HU_PRED   /* HD = "11111110",
                                        HU = "11111111" */
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The first four modes are smaller versions of the similarly named 16x16 modes above, albeit with slightly different numbering. The last six "diagonal" modes are unique to luma subblocks.

前四种模式是上述类似命名的16x16模式的较小版本,尽管编号略有不同。最后六个“对角”模式是luma子块所特有的。

11.3. Subblock Mode Contexts
11.3. 子块模式上下文

The coding of subblock modes in key frames uses the modes already coded for the subblocks to the left of and above the subblock to select a probability array for decoding the current subblock mode. This is our first instance of contextual prediction, and there are several caveats associated with it:

关键帧中的子块模式的编码使用已经为子块左侧和上方的子块编码的模式来选择用于解码当前子块模式的概率阵列。这是我们的第一个上下文预测实例,有几个与之相关的注意事项:

1. The adjacency relationships between subblocks are based on the normal default raster placement of the subblocks.

1. 子块之间的邻接关系基于子块的正常默认光栅放置。

2. The adjacent subblocks need not lie in the current macroblock. The subblocks to the left of the left-edge subblocks 0, 4, 8, and 12 are the right-edge subblocks 3, 7, 11, and 15, respectively, of the (already coded) macroblock immediately to the left. Similarly, the subblocks above the top-edge subblocks 0, 1, 2, and 3 are the bottom-edge subblocks 12, 13, 14, and 15 of the already-coded macroblock immediately above us.

2. 相邻子块不必位于当前宏块中。左边缘子块0、4、8和12左侧的子块分别是紧靠左侧的(已编码的)宏块的右边缘子块3、7、11和15。类似地,上边缘子块0、1、2和3上方的子块是紧挨着我们上方的已编码宏块的下边缘子块12、13、14和15。

3. For macroblocks on the top row or left edge of the image, some of the predictors will be non-existent. Such predictors are taken to have had the value B_DC_PRED, which, perhaps conveniently, takes the value 0 in the enumeration above. A simple management scheme for these contexts might maintain a row of above predictors and four left predictors. Before decoding the frame, the entire row is initialized to B_DC_PRED; before decoding each row of macroblocks, the four left predictors are also set to B_DC_PRED. After decoding a macroblock, the bottom four subblock modes are copied into the row predictor (at the current position, which then advances to be above the next macroblock), and the right four subblock modes are copied into the left predictor.

3. 对于图像顶行或左边缘的宏块,某些预测器将不存在。这些预测值被认为具有值B_DC_PRED,这可能很方便,在上面的枚举中取值0。对于这些上下文,一个简单的管理方案可能会维护一行上述预测器和四个左预测器。在解码帧之前,整行被初始化为B_DC_PRED;在解码每行宏块之前,四个左预测器也被设置为B_DC_PRED。解码宏块后,将底部的四个子块模式复制到行预测器中(在当前位置,然后前进到下一个宏块的上方),并将右侧的四个子块模式复制到左侧预测器中。

4. Many macroblocks will of course be coded using a 16x16 luma prediction mode. For the purpose of predicting ensuing subblock modes (only), such macroblocks derive a subblock mode, constant throughout the macroblock, from the 16x16 luma mode as follows: DC_PRED uses B_DC_PRED, V_PRED uses B_VE_PRED, H_PRED uses B_HE_PRED, and TM_PRED uses B_TM_PRED.

4. 当然,许多宏块将使用16x16 luma预测模式进行编码。为了预测随后的子块模式(仅限),此类宏块从16x16 luma模式导出整个宏块恒定的子块模式,如下所示:DC_PRED使用B_DC_PRED,V_PRED使用B_VE_PRED,H_PRED使用B_HE_PRED,TM_PRED使用B_TM_PRED。

5. Although we discuss interframe modes in Section 16, we remark here that, while interframes do use all the intra-coding modes described here and below, the subblock modes in an interframe are coded using a single constant probability array that does not depend on any context.

5. 尽管我们在第16节中讨论了帧间模式,但我们在这里指出,虽然帧间确实使用这里和下面描述的所有帧内编码模式,但帧间中的子块模式使用不依赖于任何上下文的单个恒定概率数组进行编码。

The dependence of subblock mode probability on the nearby subblock mode context is most easily handled using a three-dimensional constant array:

子块模式概率对附近子块模式上下文的依赖性最容易使用三维常量数组处理:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        

const Prob kf_bmode_prob [num_intra_bmodes] [num_intra_bmodes] [num_intra_bmodes-1];

const Prob kf_bmode_Prob[num_intra_bmodes][num_intra_bmodes][num_intra_bmodes][num_intra_bmodes-1];

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The outer two dimensions of this array are indexed by the already-coded subblock modes above and to the left of the current block, respectively. The inner dimension is a typical tree probability list whose indices correspond to the even indices of the bmode_tree above. The mode for the j^(th) luma subblock is then

此数组的外部二维分别由当前块上方和左侧已编码的子块模式索引。内维是一个典型的树概率列表,其索引对应于上面bmode_树的偶数索引。然后,j^(th)luma子块的模式为

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   Bmode = (intra_bmode) treed_read(d, bmode_tree, kf_bmode_prob
     [A] [L]);
        
   Bmode = (intra_bmode) treed_read(d, bmode_tree, kf_bmode_prob
     [A] [L]);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Where the 4x4 Y subblock index j varies from 0 to 15 in raster order, and A and L are the modes used above and to the left of the j^(th) subblock.

其中,4x4 Y子块索引j按光栅顺序从0到15变化,A和L是上面和j^(th)子块左侧使用的模式。

The contents of the kf_bmode_prob array are given at the end of this section.

kf_bmode_prob数组的内容在本节末尾给出。

11.4. Chroma Modes
11.4. 色度模式

After the Y mode (and optional subblock mode) specification comes the chroma mode. The chroma modes are a subset of the Y modes and are coded using the uv_mode_tree, as described in Section 8 and repeated here for convenience:

在Y模式(和可选子块模式)规范之后是色度模式。色度模式是Y模式的子集,并使用uv_模式_树进行编码,如第8节所述,为方便起见,在此重复:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const tree_index uv_mode_tree [2 * (num_uv_modes - 1)] =
   {
    -DC_PRED, 2,           /* root: DC_PRED = "0", "1" subtree */
     -V_PRED, 4,           /* "1" subtree:  V_PRED = "10",
                              "11" subtree */
      -H_PRED, -TM_PRED    /* "11" subtree: H_PRED = "110",
                              TM_PRED = "111" */
   };
        
   const tree_index uv_mode_tree [2 * (num_uv_modes - 1)] =
   {
    -DC_PRED, 2,           /* root: DC_PRED = "0", "1" subtree */
     -V_PRED, 4,           /* "1" subtree:  V_PRED = "10",
                              "11" subtree */
      -H_PRED, -TM_PRED    /* "11" subtree: H_PRED = "110",
                              TM_PRED = "111" */
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

As for the Y modes (in a key frame), the chroma modes are coded using a fixed, contextless probability table:

对于Y模式(在关键帧中),色度模式使用固定的、无上下文的概率表进行编码:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const Prob kf_uv_mode_prob [num_uv_modes - 1] = { 142, 114, 183};
   uv_mode = (intra_mbmode) treed_read(d, uv_mode_tree,
     kf_uv_mode_prob);
        
   const Prob kf_uv_mode_prob [num_uv_modes - 1] = { 142, 114, 183};
   uv_mode = (intra_mbmode) treed_read(d, uv_mode_tree,
     kf_uv_mode_prob);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

This completes the description of macroblock prediction coding for key frames. As will be discussed in Section 16, the coding of intra modes within interframes is similar, but not identical, to that described here (and in the reference code) for prediction modes and, indeed, for all tree-coded data in VP8.

这就完成了对关键帧的宏块预测编码的描述。如将在第16节中讨论的,帧间内模式的编码与此处(和参考代码中)针对预测模式以及VP8中的所有树编码数据描述的编码相似,但不相同。

11.5. Subblock Mode Probability Table
11.5. 子块模式概率表

Finally, here is the fixed probability table used to decode subblock modes in key frames.

最后,这里是用于解码关键帧中的子块模式的固定概率表。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const Prob kf_bmode_prob [num_intra_bmodes] [num_intra_bmodes]
     [num_intra_bmodes-1] =
   {
     {
       { 231, 120,  48,  89, 115, 113, 120, 152, 112},
       { 152, 179,  64, 126, 170, 118,  46,  70,  95},
       { 175,  69, 143,  80,  85,  82,  72, 155, 103},
       {  56,  58,  10, 171, 218, 189,  17,  13, 152},
       { 144,  71,  10,  38, 171, 213, 144,  34,  26},
       { 114,  26,  17, 163,  44, 195,  21,  10, 173},
       { 121,  24,  80, 195,  26,  62,  44,  64,  85},
       { 170,  46,  55,  19, 136, 160,  33, 206,  71},
       {  63,  20,   8, 114, 114, 208,  12,   9, 226},
       {  81,  40,  11,  96, 182,  84,  29,  16,  36}
     },
        
   const Prob kf_bmode_prob [num_intra_bmodes] [num_intra_bmodes]
     [num_intra_bmodes-1] =
   {
     {
       { 231, 120,  48,  89, 115, 113, 120, 152, 112},
       { 152, 179,  64, 126, 170, 118,  46,  70,  95},
       { 175,  69, 143,  80,  85,  82,  72, 155, 103},
       {  56,  58,  10, 171, 218, 189,  17,  13, 152},
       { 144,  71,  10,  38, 171, 213, 144,  34,  26},
       { 114,  26,  17, 163,  44, 195,  21,  10, 173},
       { 121,  24,  80, 195,  26,  62,  44,  64,  85},
       { 170,  46,  55,  19, 136, 160,  33, 206,  71},
       {  63,  20,   8, 114, 114, 208,  12,   9, 226},
       {  81,  40,  11,  96, 182,  84,  29,  16,  36}
     },
        
     {
       { 134, 183,  89, 137,  98, 101, 106, 165, 148},
       {  72, 187, 100, 130, 157, 111,  32,  75,  80},
       {  66, 102, 167,  99,  74,  62,  40, 234, 128},
       {  41,  53,   9, 178, 241, 141,  26,   8, 107},
       { 104,  79,  12,  27, 217, 255,  87,  17,   7},
       {  74,  43,  26, 146,  73, 166,  49,  23, 157},
       {  65,  38, 105, 160,  51,  52,  31, 115, 128},
       {  87,  68,  71,  44, 114,  51,  15, 186,  23},
       {  47,  41,  14, 110, 182, 183,  21,  17, 194},
       {  66,  45,  25, 102, 197, 189,  23,  18,  22}
     },
     {
       {  88,  88, 147, 150,  42,  46,  45, 196, 205},
       {  43,  97, 183, 117,  85,  38,  35, 179,  61},
       {  39,  53, 200,  87,  26,  21,  43, 232, 171},
       {  56,  34,  51, 104, 114, 102,  29,  93,  77},
       { 107,  54,  32,  26,  51,   1,  81,  43,  31},
       {  39,  28,  85, 171,  58, 165,  90,  98,  64},
       {  34,  22, 116, 206,  23,  34,  43, 166,  73},
       {  68,  25, 106,  22,  64, 171,  36, 225, 114},
       {  34,  19,  21, 102, 132, 188,  16,  76, 124},
       {  62,  18,  78,  95,  85,  57,  50,  48,  51}
     },
     {
       { 193, 101,  35, 159, 215, 111,  89,  46, 111},
       {  60, 148,  31, 172, 219, 228,  21,  18, 111},
       { 112, 113,  77,  85, 179, 255,  38, 120, 114},
       {  40,  42,   1, 196, 245, 209,  10,  25, 109},
       { 100,  80,   8,  43, 154,   1,  51,  26,  71},
       {  88,  43,  29, 140, 166, 213,  37,  43, 154},
       {  61,  63,  30, 155,  67,  45,  68,   1, 209},
       { 142,  78,  78,  16, 255, 128,  34, 197, 171},
       {  41,  40,   5, 102, 211, 183,   4,   1, 221},
       {  51,  50,  17, 168, 209, 192,  23,  25,  82}
     },
     {
       { 125,  98,  42,  88, 104,  85, 117, 175,  82},
       {  95,  84,  53,  89, 128, 100, 113, 101,  45},
       {  75,  79, 123,  47,  51, 128,  81, 171,   1},
       {  57,  17,   5,  71, 102,  57,  53,  41,  49},
       { 115,  21,   2,  10, 102, 255, 166,  23,   6},
       {  38,  33,  13, 121,  57,  73,  26,   1,  85},
       {  41,  10,  67, 138,  77, 110,  90,  47, 114},
       { 101,  29,  16,  10,  85, 128, 101, 196,  26},
       {  57,  18,  10, 102, 102, 213,  34,  20,  43},
       { 117,  20,  15,  36, 163, 128,  68,   1,  26}
     },
        
     {
       { 134, 183,  89, 137,  98, 101, 106, 165, 148},
       {  72, 187, 100, 130, 157, 111,  32,  75,  80},
       {  66, 102, 167,  99,  74,  62,  40, 234, 128},
       {  41,  53,   9, 178, 241, 141,  26,   8, 107},
       { 104,  79,  12,  27, 217, 255,  87,  17,   7},
       {  74,  43,  26, 146,  73, 166,  49,  23, 157},
       {  65,  38, 105, 160,  51,  52,  31, 115, 128},
       {  87,  68,  71,  44, 114,  51,  15, 186,  23},
       {  47,  41,  14, 110, 182, 183,  21,  17, 194},
       {  66,  45,  25, 102, 197, 189,  23,  18,  22}
     },
     {
       {  88,  88, 147, 150,  42,  46,  45, 196, 205},
       {  43,  97, 183, 117,  85,  38,  35, 179,  61},
       {  39,  53, 200,  87,  26,  21,  43, 232, 171},
       {  56,  34,  51, 104, 114, 102,  29,  93,  77},
       { 107,  54,  32,  26,  51,   1,  81,  43,  31},
       {  39,  28,  85, 171,  58, 165,  90,  98,  64},
       {  34,  22, 116, 206,  23,  34,  43, 166,  73},
       {  68,  25, 106,  22,  64, 171,  36, 225, 114},
       {  34,  19,  21, 102, 132, 188,  16,  76, 124},
       {  62,  18,  78,  95,  85,  57,  50,  48,  51}
     },
     {
       { 193, 101,  35, 159, 215, 111,  89,  46, 111},
       {  60, 148,  31, 172, 219, 228,  21,  18, 111},
       { 112, 113,  77,  85, 179, 255,  38, 120, 114},
       {  40,  42,   1, 196, 245, 209,  10,  25, 109},
       { 100,  80,   8,  43, 154,   1,  51,  26,  71},
       {  88,  43,  29, 140, 166, 213,  37,  43, 154},
       {  61,  63,  30, 155,  67,  45,  68,   1, 209},
       { 142,  78,  78,  16, 255, 128,  34, 197, 171},
       {  41,  40,   5, 102, 211, 183,   4,   1, 221},
       {  51,  50,  17, 168, 209, 192,  23,  25,  82}
     },
     {
       { 125,  98,  42,  88, 104,  85, 117, 175,  82},
       {  95,  84,  53,  89, 128, 100, 113, 101,  45},
       {  75,  79, 123,  47,  51, 128,  81, 171,   1},
       {  57,  17,   5,  71, 102,  57,  53,  41,  49},
       { 115,  21,   2,  10, 102, 255, 166,  23,   6},
       {  38,  33,  13, 121,  57,  73,  26,   1,  85},
       {  41,  10,  67, 138,  77, 110,  90,  47, 114},
       { 101,  29,  16,  10,  85, 128, 101, 196,  26},
       {  57,  18,  10, 102, 102, 213,  34,  20,  43},
       { 117,  20,  15,  36, 163, 128,  68,   1,  26}
     },
        
     {
       { 138,  31,  36, 171,  27, 166,  38,  44, 229},
       {  67,  87,  58, 169,  82, 115,  26,  59, 179},
       {  63,  59,  90, 180,  59, 166,  93,  73, 154},
       {  40,  40,  21, 116, 143, 209,  34,  39, 175},
       {  57,  46,  22,  24, 128,   1,  54,  17,  37},
       {  47,  15,  16, 183,  34, 223,  49,  45, 183},
       {  46,  17,  33, 183,   6,  98,  15,  32, 183},
       {  65,  32,  73, 115,  28, 128,  23, 128, 205},
       {  40,   3,   9, 115,  51, 192,  18,   6, 223},
       {  87,  37,   9, 115,  59,  77,  64,  21,  47}
     },
     {
       { 104,  55,  44, 218,   9,  54,  53, 130, 226},
       {  64,  90,  70, 205,  40,  41,  23,  26,  57},
       {  54,  57, 112, 184,   5,  41,  38, 166, 213},
       {  30,  34,  26, 133, 152, 116,  10,  32, 134},
       {  75,  32,  12,  51, 192, 255, 160,  43,  51},
       {  39,  19,  53, 221,  26, 114,  32,  73, 255},
       {  31,   9,  65, 234,   2,  15,   1, 118,  73},
       {  88,  31,  35,  67, 102,  85,  55, 186,  85},
       {  56,  21,  23, 111,  59, 205,  45,  37, 192},
       {  55,  38,  70, 124,  73, 102,   1,  34,  98}
     },
     {
       { 102,  61,  71,  37,  34,  53,  31, 243, 192},
       {  69,  60,  71,  38,  73, 119,  28, 222,  37},
       {  68,  45, 128,  34,   1,  47,  11, 245, 171},
       {  62,  17,  19,  70, 146,  85,  55,  62,  70},
       {  75,  15,   9,   9,  64, 255, 184, 119,  16},
       {  37,  43,  37, 154, 100, 163,  85, 160,   1},
       {  63,   9,  92, 136,  28,  64,  32, 201,  85},
       {  86,   6,  28,   5,  64, 255,  25, 248,   1},
       {  56,   8,  17, 132, 137, 255,  55, 116, 128},
       {  58,  15,  20,  82, 135,  57,  26, 121,  40}
     },
     {
       { 164,  50,  31, 137, 154, 133,  25,  35, 218},
       {  51, 103,  44, 131, 131, 123,  31,   6, 158},
       {  86,  40,  64, 135, 148, 224,  45, 183, 128},
       {  22,  26,  17, 131, 240, 154,  14,   1, 209},
       {  83,  12,  13,  54, 192, 255,  68,  47,  28},
       {  45,  16,  21,  91,  64, 222,   7,   1, 197},
       {  56,  21,  39, 155,  60, 138,  23, 102, 213},
       {  85,  26,  85,  85, 128, 128,  32, 146, 171},
       {  18,  11,   7,  63, 144, 171,   4,   4, 246},
       {  35,  27,  10, 146, 174, 171,  12,  26, 128}
     },
        
     {
       { 138,  31,  36, 171,  27, 166,  38,  44, 229},
       {  67,  87,  58, 169,  82, 115,  26,  59, 179},
       {  63,  59,  90, 180,  59, 166,  93,  73, 154},
       {  40,  40,  21, 116, 143, 209,  34,  39, 175},
       {  57,  46,  22,  24, 128,   1,  54,  17,  37},
       {  47,  15,  16, 183,  34, 223,  49,  45, 183},
       {  46,  17,  33, 183,   6,  98,  15,  32, 183},
       {  65,  32,  73, 115,  28, 128,  23, 128, 205},
       {  40,   3,   9, 115,  51, 192,  18,   6, 223},
       {  87,  37,   9, 115,  59,  77,  64,  21,  47}
     },
     {
       { 104,  55,  44, 218,   9,  54,  53, 130, 226},
       {  64,  90,  70, 205,  40,  41,  23,  26,  57},
       {  54,  57, 112, 184,   5,  41,  38, 166, 213},
       {  30,  34,  26, 133, 152, 116,  10,  32, 134},
       {  75,  32,  12,  51, 192, 255, 160,  43,  51},
       {  39,  19,  53, 221,  26, 114,  32,  73, 255},
       {  31,   9,  65, 234,   2,  15,   1, 118,  73},
       {  88,  31,  35,  67, 102,  85,  55, 186,  85},
       {  56,  21,  23, 111,  59, 205,  45,  37, 192},
       {  55,  38,  70, 124,  73, 102,   1,  34,  98}
     },
     {
       { 102,  61,  71,  37,  34,  53,  31, 243, 192},
       {  69,  60,  71,  38,  73, 119,  28, 222,  37},
       {  68,  45, 128,  34,   1,  47,  11, 245, 171},
       {  62,  17,  19,  70, 146,  85,  55,  62,  70},
       {  75,  15,   9,   9,  64, 255, 184, 119,  16},
       {  37,  43,  37, 154, 100, 163,  85, 160,   1},
       {  63,   9,  92, 136,  28,  64,  32, 201,  85},
       {  86,   6,  28,   5,  64, 255,  25, 248,   1},
       {  56,   8,  17, 132, 137, 255,  55, 116, 128},
       {  58,  15,  20,  82, 135,  57,  26, 121,  40}
     },
     {
       { 164,  50,  31, 137, 154, 133,  25,  35, 218},
       {  51, 103,  44, 131, 131, 123,  31,   6, 158},
       {  86,  40,  64, 135, 148, 224,  45, 183, 128},
       {  22,  26,  17, 131, 240, 154,  14,   1, 209},
       {  83,  12,  13,  54, 192, 255,  68,  47,  28},
       {  45,  16,  21,  91,  64, 222,   7,   1, 197},
       {  56,  21,  39, 155,  60, 138,  23, 102, 213},
       {  85,  26,  85,  85, 128, 128,  32, 146, 171},
       {  18,  11,   7,  63, 144, 171,   4,   4, 246},
       {  35,  27,  10, 146, 174, 171,  12,  26, 128}
     },
        
     {
       { 190,  80,  35,  99, 180,  80, 126,  54,  45},
       {  85, 126,  47,  87, 176,  51,  41,  20,  32},
       { 101,  75, 128, 139, 118, 146, 116, 128,  85},
       {  56,  41,  15, 176, 236,  85,  37,   9,  62},
       { 146,  36,  19,  30, 171, 255,  97,  27,  20},
       {  71,  30,  17, 119, 118, 255,  17,  18, 138},
       { 101,  38,  60, 138,  55,  70,  43,  26, 142},
       { 138,  45,  61,  62, 219,   1,  81, 188,  64},
       {  32,  41,  20, 117, 151, 142,  20,  21, 163},
       { 112,  19,  12,  61, 195, 128,  48,   4,  24}
     }
   };
        
     {
       { 190,  80,  35,  99, 180,  80, 126,  54,  45},
       {  85, 126,  47,  87, 176,  51,  41,  20,  32},
       { 101,  75, 128, 139, 118, 146, 116, 128,  85},
       {  56,  41,  15, 176, 236,  85,  37,   9,  62},
       { 146,  36,  19,  30, 171, 255,  97,  27,  20},
       {  71,  30,  17, 119, 118, 255,  17,  18, 138},
       { 101,  38,  60, 138,  55,  70,  43,  26, 142},
       { 138,  45,  61,  62, 219,   1,  81, 188,  64},
       {  32,  41,  20, 117, 151, 142,  20,  21, 163},
       { 112,  19,  12,  61, 195, 128,  48,   4,  24}
     }
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
12. Intraframe Prediction
12. 帧内预测

Intraframe prediction uses already-coded macroblocks within the current frame to approximate the contents of the current macroblock. It applies to intra-coded macroblocks in an interframe and to all macroblocks in a key frame.

帧内预测使用当前帧内已编码的宏块来近似当前宏块的内容。它适用于帧间中的帧内编码宏块和关键帧中的所有宏块。

Relative to the current macroblock "M", the already-coded macroblocks include all macroblocks above M together with the macroblocks on the same row as, and to the left of, M, though at most four of these macroblocks are actually used: the block "A" directly above M, the blocks immediately to the left and right of A, and the block immediately to the left of M.

相对于当前宏块“M”,已经编码的宏块包括M上方的所有宏块以及与M同一行且在M左侧的宏块,尽管实际使用的这些宏块中最多有四个:直接在M上方的块“A”、紧靠M左右的块,和M左边的街区。

Each of the prediction modes (i.e., means of extrapolation from already-calculated values) uses fairly simple arithmetic on pixel values whose positions, relative to the current position, are defined by the mode.

每个预测模式(即,从已经计算的值外推的手段)对像素值使用相当简单的算法,其相对于当前位置的位置由模式定义。

The chroma (U and V) and luma (Y) predictions are independent of each other.

色度(U和V)和亮度(Y)预测相互独立。

The relative addressing of pixels applied to macroblocks on the upper row or left column of the frame will sometimes cause pixels outside the visible frame to be referenced. Usually such out-of-bounds pixels have an assumed value of 129 for pixels to the left of the leftmost column of the visible frame and 127 for pixels above the top row of the visible frame (including the special case of the pixel above and to the left of the top-left pixel in the visible frame). Exceptions to this (associated to certain modes) will be noted below.

应用于帧的上行或左列上的宏块的像素的相对寻址有时会导致引用可见帧之外的像素。通常,对于可见帧最左列左侧的像素,此类越界像素的假设值为129,对于可见帧顶行上方的像素,此类越界像素的假设值为127(包括可见帧中左上像素上方和左侧的像素的特殊情况)。以下将说明例外情况(与某些模式相关)。

The already-coded macroblocks referenced by intra-prediction have been "reconstructed", that is, have been predicted and residue-adjusted (as described in Section 14), but have not been loop-filtered. While it does process the edges between individual macroblocks and individual subblocks, loop filtering (described in Section 15) is applied to the frame as a whole, after all of the macroblocks have been reconstructed.

帧内预测所引用的已经编码的宏块已经被“重构”,也就是说,已经被预测和残余调整(如第14节所述),但是没有被循环滤波。虽然它确实处理各个宏块和各个子块之间的边缘,但是在所有宏块都被重构之后,循环滤波(在第15节中描述)被应用于作为一个整体的帧。

12.1. mb_skip_coeff
12.1. mb_skip_coeff

The single bool flag is decoded using prob_skip_false if and only if mb_no_skip_coeff is set to 1 (see Sections 9.10 and 9.11). If mb_no_skip_coeff is set to 0, then this value defaults to 0.

当且仅当mb_no_skip_coeff设置为1时(见第9.10节和第9.11节),使用prob_skip_false对单个bool标志进行解码。如果mb_no_skip_coeff设置为0,则该值默认为0。

12.2. Chroma Prediction
12.2. 色度预测

The chroma prediction is a little simpler than the luma prediction, so we treat it first. Each of the chroma modes treats U and V identically; that is, the U and V prediction values are calculated in parallel, using the same relative addressing and arithmetic in each of the two planes.

色度预测比亮度预测简单一点,所以我们先处理它。每个色度模式都相同地处理U和V;也就是说,U和V预测值是并行计算的,在两个平面的每个平面中使用相同的相对寻址和算法。

The modes extrapolate prediction values using the 8-pixel row "A" lying immediately above the block (that is, the bottom chroma row of the macroblock immediately above the current macroblock) and the 8-pixel column "L" immediately to the left of the block (that is, the rightmost chroma column of the macroblock immediately to the left of the current macroblock).

模式使用紧靠块上方的8像素行“A”(即,紧靠当前宏块上方的宏块的底部色度行)和紧靠块左侧的8像素列“L”来外推预测值(即,紧靠当前宏块左侧的宏块最右边的色度列)。

Vertical prediction (chroma mode V_PRED) simply fills each 8-pixel row of the 8x8 chroma block with a copy of the "above" row (A). If the current macroblock lies on the top row of the frame, all 8 of the pixel values in A are assigned the value 127.

垂直预测(色度模式V_PRED)仅用“以上”行(a)的副本填充8x8色度块的每个8像素行。如果当前宏块位于帧的顶行上,则A中的所有8个像素值被分配值127。

Similarly, horizontal prediction (H_PRED) fills each 8-pixel column of the 8x8 chroma block with a copy of the "left" column (L). If the current macroblock is in the left column of the frame, all 8 pixel values in L are assigned the value 129.

类似地,水平预测(H_PRED)用“左”列(L)的副本填充8x8色度块的每个8像素列。如果当前宏块在帧的左列中,则L中的所有8个像素值被分配值129。

DC prediction (DC_PRED) fills the 8x8 chroma block with a single value. In the generic case of a macroblock lying below the top row and right of the leftmost column of the frame, this value is the average of the 16 (genuinely visible) pixels in the (union of the) above row A and left column L.

直流预测(DC_PRED)用单个值填充8x8色度块。在一般情况下,宏块位于帧的顶行和最左列的右侧下方,该值是行a和左列L上方(并集)的16个(真正可见)像素的平均值。

Otherwise, if the current macroblock lies on the top row of the frame, the average of the 8 pixels in L is used; if it lies in the left column of the frame, the average of the 8 pixels in A is used.

否则,如果当前宏块位于帧的顶行上,则使用L中的8个像素的平均值;如果它位于帧的左列,则使用A中8个像素的平均值。

Note that the averages used in these exceptional cases are not the same as those that would be arrived at by using the out-of-bounds A and L values defined for V_PRED and H_PRED. In the case of the leftmost macroblock on the top row of the frame, the 8x8 block is simply filled with the constant value 128.

请注意,这些例外情况下使用的平均值与使用为V_PRED和H_PRED定义的越界A和L值得出的平均值不同。对于帧顶行最左侧的宏块,8x8块仅用常量值128填充。

For DC_PRED, apart from the exceptional case of the top-left macroblock, we are averaging either 16 or 8 pixel values to get a single prediction value that fills the 8x8 block. The rounding is done as follows:

对于DC_PRED,除了左上宏块的例外情况外,我们对16或8个像素值进行平均,以获得填充8x8块的单个预测值。四舍五入操作如下:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   int sum;  /* sum of 8 or 16 pixels at (at least) 16-bit precision */
   int shf;  /* base 2 logarithm of the number of pixels (3 or 4) */
        
   int sum;  /* sum of 8 or 16 pixels at (at least) 16-bit precision */
   int shf;  /* base 2 logarithm of the number of pixels (3 or 4) */
        
   Pixel DCvalue = (sum + (1 << (shf-1))) >> shf;
        
   Pixel DCvalue = (sum + (1 << (shf-1))) >> shf;
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Because the summands are all valid pixels, no "clamp" is necessary in the calculation of DCvalue.

由于总和都是有效像素,因此在计算DCvalue时不需要“钳制”。

The remaining "True Motion" (TM_PRED) chroma mode gets its name from an older technique of video compression used by On2 Technologies, to which it bears some relation. In addition to the row "A" and column "L", TM_PRED uses the pixel "P" above and to the left of the chroma block.

剩下的“真实运动”(TM_PRED)色度模式的名称来自On2 Technologies使用的一种较旧的视频压缩技术,与此有一定关系。除了行“A”和列“L”之外,TM_PRED使用色度块上方和左侧的像素“P”。

The following figure gives an example of how TM_PRED works:

下图给出了TM_PRED如何工作的示例:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | P   | A0  | A1  | A2  | A3  | A4  | A5  | A6  | A7  |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L0  | X00 | X01 | X02 | X03 | X04 | X05 | X06 | X07 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L1  | X10 | X11 | X12 | X13 | X14 | X15 | X16 | X17 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L2  | X20 | X21 | X22 | X23 | X24 | X25 | X26 | X27 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L3  | X30 | X31 | X32 | X33 | X34 | X35 | X36 | X37 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L4  | X40 | X41 | X42 | X43 | X44 | X45 | X46 | X47 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L5  | X50 | X51 | X52 | X53 | X54 | X55 | X56 | X57 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L6  | X60 | X61 | X62 | X63 | X64 | X65 | X66 | X67 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L7  | X70 | X71 | X72 | X73 | X74 | X75 | X76 | X77 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
        
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | P   | A0  | A1  | A2  | A3  | A4  | A5  | A6  | A7  |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L0  | X00 | X01 | X02 | X03 | X04 | X05 | X06 | X07 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L1  | X10 | X11 | X12 | X13 | X14 | X15 | X16 | X17 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L2  | X20 | X21 | X22 | X23 | X24 | X25 | X26 | X27 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L3  | X30 | X31 | X32 | X33 | X34 | X35 | X36 | X37 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L4  | X40 | X41 | X42 | X43 | X44 | X45 | X46 | X47 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L5  | X50 | X51 | X52 | X53 | X54 | X55 | X56 | X57 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L6  | X60 | X61 | X62 | X63 | X64 | X65 | X66 | X67 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
   | L7  | X70 | X71 | X72 | X73 | X74 | X75 | X76 | X77 |
   |-----|-----|-----|-----|-----|-----|-----|-----|-----|
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Where P, As, and Ls represent reconstructed pixel values from previously coded blocks, and X00 through X77 represent predicted values for the current block. TM_PRED uses the following equation to calculate X_ij:

其中P、As和Ls表示来自先前编码块的重构像素值,X00到X77表示当前块的预测值。TM_PRED使用以下方程式计算X_ij:

   X_ij = L_i + A_j - P (i, j=0, 1, 2, 3)
        
   X_ij = L_i + A_j - P (i, j=0, 1, 2, 3)
        

The exact algorithm is as follows:

具体算法如下:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   void TMpred(
       Pixel b[8][8],      /* chroma (U or V) prediction block */
       const Pixel A[8],   /* row of already-constructed pixels
                              above block */
       const Pixel L[8],   /* column of "" just to the left of
                              block */
       const Pixel P       /* pixel just to the left of A and
                              above L*/
   ) {
       int r = 0;          /* row */
       do {
           int c = 0;      /* column */
           do {
               b[r][c] = clamp255(L[r]+ A[c] - P);
           } while (++c < 8);
       } while (++r < 8);
   }
        
   void TMpred(
       Pixel b[8][8],      /* chroma (U or V) prediction block */
       const Pixel A[8],   /* row of already-constructed pixels
                              above block */
       const Pixel L[8],   /* column of "" just to the left of
                              block */
       const Pixel P       /* pixel just to the left of A and
                              above L*/
   ) {
       int r = 0;          /* row */
       do {
           int c = 0;      /* column */
           do {
               b[r][c] = clamp255(L[r]+ A[c] - P);
           } while (++c < 8);
       } while (++r < 8);
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Note that the process could equivalently be described as propagating the vertical differences between pixels in L (starting from P), using the pixels from A to start each column.

注意,该过程可以等效地描述为传播L中的像素之间的垂直差异(从P开始),使用A中的像素来开始每个列。

An implementation of chroma intra-prediction may be found in the reference decoder file predict.c (Section 20.14).

色度帧内预测的实现可在参考解码器文件predict.c(第20.14节)中找到。

Unlike DC_PRED, for macroblocks on the top row or left edge, TM_PRED does use the out-of-bounds values of 127 and 129 (respectively) defined for V_PRED and H_PRED.

与DC_PRED不同,对于顶行或左边缘上的宏块,TM_PRED使用为V_PRED和H_PRED定义的127和129(分别)越界值。

12.3. Luma Prediction
12.3. 亮度预测

The prediction processes for the first four 16x16 luma modes (DC_PRED, V_PRED, H_PRED, and TM_PRED) are essentially identical to the corresponding chroma prediction processes described above, the only difference being that we are predicting a single 16x16 luma block instead of two 8x8 chroma blocks.

前四个16x16亮度模式(DC_PRED、V_PRED、H_PRED和TM_PRED)的预测过程基本上与上述相应的色度预测过程相同,唯一的区别是我们预测的是一个16x16亮度块而不是两个8x8色度块。

Thus, the row "A" and column "L" here contain 16 pixels, the DC prediction is calculated using 16 or 32 pixels (and shf is 4 or 5), and we of course fill the entire prediction buffer, that is, 16 rows (or columns) containing 16 pixels each. The reference implementation of 16x16 luma prediction is also in predict.c.

因此,这里的行“A”和列“L”包含16个像素,使用16或32个像素计算DC预测(并且shf是4或5),并且我们当然填充整个预测缓冲区,即,16行(或列)每个包含16个像素。16x16 luma预测的参考实现也在predict.c中。

In the remaining luma mode (B_PRED), each 4x4 Y subblock is independently predicted using one of ten modes (listed, along with their encodings, in Section 11).

在剩余的luma模式(B_PRED)中,每个4x4 Y子块使用十种模式中的一种进行独立预测(在第11节中列出,以及它们的编码)。

Also, unlike the full-macroblock modes already described, some of the subblock modes use prediction pixels above and to the right of the current subblock. In detail, each 4x4 subblock "B" is predicted using (at most) the 4-pixel column "L" immediately to the left of B and the 8-pixel row "A" immediately above B, consisting of the 4 pixels above B followed by the 4 adjacent pixels above and to the right of B, together with the single pixel "P" immediately to the left of A (and immediately above L).

此外,与已经描述的全宏块模式不同,一些子块模式使用当前子块上方和右侧的预测像素。具体地说,每个4x4子块“B”使用(最多)紧靠B左侧的4像素列“L”和紧靠B上方的8像素行“A”进行预测,该行由B上方的4个像素和B上方和右侧的4个相邻像素以及紧靠A左侧(紧靠L上方)的单个像素“P”组成。

For the purpose of subblock intra-prediction, the pixels immediately to the left and right of a pixel in a subblock are the same as the pixels immediately to the left and right of the corresponding pixel in the frame buffer "F". Vertical offsets behave similarly: The above row A lies immediately above B in F, and the adjacent pixels in the left column L are separated by a single row in F.

为了子块内预测的目的,子块中的像素的紧邻左侧和右侧的像素与帧缓冲器“F”中的对应像素的紧邻左侧和右侧的像素相同。垂直偏移的行为类似:上面的行A位于F中B的正上方,左列L中的相邻像素由F中的一行分隔。

Because entire macroblocks (as opposed to their constituent subblocks) are reconstructed in raster-scan order, for subblocks lying along the right edge (and not along the top row) of the current macroblock, the four "extra" prediction pixels in A above and to the right of B have not yet actually been constructed.

由于以光栅扫描顺序重建整个宏块(与其组成的子块相反),因此对于沿当前宏块的右边缘(而不是沿顶行)的子块,还没有实际构造B的上方和右侧A中的四个“额外”预测像素。

Subblocks 7, 11, and 15 are affected. All three of these subblocks use the same extra pixels as does subblock 3 (at the upper right corner of the macroblock), namely the 4 pixels immediately above and to the right of subblock 3. Writing (R,C) for a frame buffer position offset from the upper left corner of the current macroblock by R rows and C columns, the extra pixels for all the right-edge subblocks (3, 7, 11, and 15) are at positions (-1,16), (-1,17), (-1,18), and (-1,19). For the rightmost macroblock in each macroblock row except the top row, the extra pixels shall use the same value as the pixel at position (-1,15), which is the rightmost visible pixel on the line immediately above the macroblock row. For the top macroblock row, all the extra pixels assume a value of 127.

子块7、11和15受到影响。所有这三个子块使用与子块3(在宏块的右上角)相同的额外像素,即子块3正上方和右侧的4个像素。为从当前宏块左上角偏移R行和C列的帧缓冲区位置写入(R,C),所有右边缘子块(3、7、11和15)的额外像素位于位置(-1,16),(-1,17),(-1,18)和(-1,19)。对于除顶行之外的每个宏块行中最右边的宏块,额外像素应使用与位置(-1,15)处的像素相同的值,该位置是宏块行正上方行上最右边的可见像素。对于顶部宏块行,所有额外像素的值均为127。

The details of the prediction modes are most easily described in code.

预测模式的细节最容易在代码中描述。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* Result pixels are often averages of two or three predictor
      pixels.  The following subroutines are used to calculate
      these averages.  Because the arguments are valid pixels, no
      clamping is necessary.  An actual implementation would
      probably use inline functions or macros. */
        
   /* Result pixels are often averages of two or three predictor
      pixels.  The following subroutines are used to calculate
      these averages.  Because the arguments are valid pixels, no
      clamping is necessary.  An actual implementation would
      probably use inline functions or macros. */
        
   /* Compute weighted average centered at y w/adjacent x, z */
        
   /* Compute weighted average centered at y w/adjacent x, z */
        
   Pixel avg3(Pixel x, Pixel y, Pixel z) {
     return (x + y + y + z + 2) >> 2;}
        
   Pixel avg3(Pixel x, Pixel y, Pixel z) {
     return (x + y + y + z + 2) >> 2;}
        
   /* Weighted average of 3 adjacent pixels centered at p */
        
   /* Weighted average of 3 adjacent pixels centered at p */
        
   Pixel avg3p(const Pixel *p) { return avg3(p[-1], p[0], p[1]);}
        
   Pixel avg3p(const Pixel *p) { return avg3(p[-1], p[0], p[1]);}
        
   /* Simple average of x and y */
        
   /* Simple average of x and y */
        
   Pixel avg2(Pixel x, Pixel y) { return (x + y + 1) >> 1;}
        
   Pixel avg2(Pixel x, Pixel y) { return (x + y + 1) >> 1;}
        
   /* Average of p[0] and p[1] may be considered to be a synthetic
      pixel lying between the two, that is, one half-step past p. */
        
   /* Average of p[0] and p[1] may be considered to be a synthetic
      pixel lying between the two, that is, one half-step past p. */
        
   Pixel avg2p(const Pixel *p) { return avg2(p[0], p[1]);}
        
   Pixel avg2p(const Pixel *p) { return avg2(p[0], p[1]);}
        
   void subblock_intra_predict(
       Pixel B[4][4],     /* Y subblock prediction buffer */
       const Pixel *A,    /* A[0]...A[7] = above row, A[-1] = P */
       const Pixel *L,    /* L[0]...L[3] = left column, L[-1] = P */
       intra_bmode mode   /* enum is in Section 11.2 */
   ) {
       Pixel E[9];        /* 9 already-constructed edge pixels */
       E[0] = L[3];  E[1] = L[2];  E[2] = L[1];  E[3] = L[0];
       E[4] = A[-1];      /* == L[-1] == P */
       E[5] = A[0];  E[6] = A[1];  E[7] = A[2];  E[8] = A[3];
        
   void subblock_intra_predict(
       Pixel B[4][4],     /* Y subblock prediction buffer */
       const Pixel *A,    /* A[0]...A[7] = above row, A[-1] = P */
       const Pixel *L,    /* L[0]...L[3] = left column, L[-1] = P */
       intra_bmode mode   /* enum is in Section 11.2 */
   ) {
       Pixel E[9];        /* 9 already-constructed edge pixels */
       E[0] = L[3];  E[1] = L[2];  E[2] = L[1];  E[3] = L[0];
       E[4] = A[-1];      /* == L[-1] == P */
       E[5] = A[0];  E[6] = A[1];  E[7] = A[2];  E[8] = A[3];
        
     switch(mode) {
       /* First four modes are similar to corresponding
          full-block modes. */
        
     switch(mode) {
       /* First four modes are similar to corresponding
          full-block modes. */
        
       case B_DC_PRED:
       {
           int v = 4;      /* DC sum/avg, 4 is rounding adjustment */
           int i = 0;  do { v += A[i] + L[i];}  while (++i < 4);
           v >>= 3;        /* averaging 8 pixels */
           i = 0;  do {    /* fill prediction buffer with constant DC
                              value */
        
       case B_DC_PRED:
       {
           int v = 4;      /* DC sum/avg, 4 is rounding adjustment */
           int i = 0;  do { v += A[i] + L[i];}  while (++i < 4);
           v >>= 3;        /* averaging 8 pixels */
           i = 0;  do {    /* fill prediction buffer with constant DC
                              value */
        
               int j = 0;  do { B[i][j] = v;}  while (++j < 4);
           } while (++i < 4);
           break;
       }
        
               int j = 0;  do { B[i][j] = v;}  while (++j < 4);
           } while (++i < 4);
           break;
       }
        
       case B_TM_PRED: /* just like 16x16 TM_PRED */
       {
           int r = 0;  do {
               int c = 0;  do {
                   B[r][c] = clamp255(L[r] + A[c] - A[-1]);
               } while (++c < 4);
           } while (++r < 4);
           break;
       }
        
       case B_TM_PRED: /* just like 16x16 TM_PRED */
       {
           int r = 0;  do {
               int c = 0;  do {
                   B[r][c] = clamp255(L[r] + A[c] - A[-1]);
               } while (++c < 4);
           } while (++r < 4);
           break;
       }
        
       case B_VE_PRED: /* like 16x16 V_PRED except using averages */
       {
           int c = 0;  do { /* all 4 rows = smoothed top row */
               B[0][c] = B[1][c] = B[2][c] = B[3][c] = avg3p(A + c);
           } while (++c < 4);
           break;
       }
        
       case B_VE_PRED: /* like 16x16 V_PRED except using averages */
       {
           int c = 0;  do { /* all 4 rows = smoothed top row */
               B[0][c] = B[1][c] = B[2][c] = B[3][c] = avg3p(A + c);
           } while (++c < 4);
           break;
       }
        
       case B_HE_PRED: /* like 16x16 H_PRED except using averages */
       {
           /* Bottom row is exceptional because L[4] does not exist */
           int v = avg3(L[2], L[3], L[3]);
           int r = 3;  while (1) {  /* all 4 columns = smoothed left
                                       column */
               B[r][0] = B[r][1] = B[r][2] = B[r][3] = v;
               if (--r < 0)
                   break;
               v = avg3p(L + r);  /* upper 3 rows use average of
                                      3 pixels */
           }
           break;
       }
        
       case B_HE_PRED: /* like 16x16 H_PRED except using averages */
       {
           /* Bottom row is exceptional because L[4] does not exist */
           int v = avg3(L[2], L[3], L[3]);
           int r = 3;  while (1) {  /* all 4 columns = smoothed left
                                       column */
               B[r][0] = B[r][1] = B[r][2] = B[r][3] = v;
               if (--r < 0)
                   break;
               v = avg3p(L + r);  /* upper 3 rows use average of
                                      3 pixels */
           }
           break;
       }
        
       /* The remaining six "diagonal" modes subdivide the
          prediction buffer into diagonal lines.  All the pixels
          on each line are assigned the same value; this value is
          (a smoothed or synthetic version of) an
          already-constructed predictor value lying on the same
          line.  For clarity, in the comments, we express the
          positions of these predictor pixels relative to the
          upper left corner of the destination array B.
        
       /* The remaining six "diagonal" modes subdivide the
          prediction buffer into diagonal lines.  All the pixels
          on each line are assigned the same value; this value is
          (a smoothed or synthetic version of) an
          already-constructed predictor value lying on the same
          line.  For clarity, in the comments, we express the
          positions of these predictor pixels relative to the
          upper left corner of the destination array B.
        
          These modes are unique to subblock prediction and have
          no full-block analogs.  The first two use lines at
          +|- 45 degrees from horizontal (or, equivalently,
          vertical), that is, lines whose slopes are +|- 1. */
        
          These modes are unique to subblock prediction and have
          no full-block analogs.  The first two use lines at
          +|- 45 degrees from horizontal (or, equivalently,
          vertical), that is, lines whose slopes are +|- 1. */
        
       case B_LD_PRED:    /* southwest (left and down) step =
                             (-1, 1) or (1,-1) */
           /* avg3p(A + j) is the "smoothed" pixel at (-1,j) */
           B[0][0] = avg3p(A + 1);
           B[0][1] = B[1][0] = avg3p(A + 2);
           B[0][2] = B[1][1] = B[2][0] = avg3p(A + 3);
           B[0][3] = B[1][2] = B[2][1] = B[3][0] = avg3p(A + 4);
           B[1][3] = B[2][2] = B[3][1] = avg3p(A + 5);
           B[2][3] = B[3][2] = avg3p(A + 6);
           B[3][3] = avg3(A[6], A[7], A[7]); /* A[8] does not exist */
           break;
        
       case B_LD_PRED:    /* southwest (left and down) step =
                             (-1, 1) or (1,-1) */
           /* avg3p(A + j) is the "smoothed" pixel at (-1,j) */
           B[0][0] = avg3p(A + 1);
           B[0][1] = B[1][0] = avg3p(A + 2);
           B[0][2] = B[1][1] = B[2][0] = avg3p(A + 3);
           B[0][3] = B[1][2] = B[2][1] = B[3][0] = avg3p(A + 4);
           B[1][3] = B[2][2] = B[3][1] = avg3p(A + 5);
           B[2][3] = B[3][2] = avg3p(A + 6);
           B[3][3] = avg3(A[6], A[7], A[7]); /* A[8] does not exist */
           break;
        
       case B_RD_PRED: /* southeast (right and down) step =
                          (1,1) or (-1,-1) */
           B[3][0] = avg3p(E + 1);  /* predictor is from (2, -1) */
           B[3][1] = B[2][0] = avg3p(E + 2);  /* (1, -1) */
           B[3][2] = B[2][1] = B[1][0] = avg3p(E + 3);  /* (0, -1) */
           B[3][3] = B[2][2] = B[1][1] = B[0][0] =
             avg3p(E + 4);  /* (-1, -1) */
           B[2][3] = B[1][2] = B[0][1] = avg3p(E + 5);  /* (-1, 0) */
           B[1][3] = B[0][2] = avg3p(E + 6);  /* (-1, 1) */
           B[0][3] = avg3p(E + 7);  /* (-1, 2) */
           break;
        
       case B_RD_PRED: /* southeast (right and down) step =
                          (1,1) or (-1,-1) */
           B[3][0] = avg3p(E + 1);  /* predictor is from (2, -1) */
           B[3][1] = B[2][0] = avg3p(E + 2);  /* (1, -1) */
           B[3][2] = B[2][1] = B[1][0] = avg3p(E + 3);  /* (0, -1) */
           B[3][3] = B[2][2] = B[1][1] = B[0][0] =
             avg3p(E + 4);  /* (-1, -1) */
           B[2][3] = B[1][2] = B[0][1] = avg3p(E + 5);  /* (-1, 0) */
           B[1][3] = B[0][2] = avg3p(E + 6);  /* (-1, 1) */
           B[0][3] = avg3p(E + 7);  /* (-1, 2) */
           break;
        
       /* The remaining 4 diagonal modes use lines whose slopes are
          +|- 2 and +|- 1/2.  The angles of these lines are roughly
          +|- 27 degrees from horizontal or vertical.
        
       /* The remaining 4 diagonal modes use lines whose slopes are
          +|- 2 and +|- 1/2.  The angles of these lines are roughly
          +|- 27 degrees from horizontal or vertical.
        
          Unlike the 45 degree diagonals, here we often need to
          "synthesize" predictor pixels midway between two actual
          predictors using avg2p(p), which we think of as returning
          the pixel "at" p[1/2]. */
        
          Unlike the 45 degree diagonals, here we often need to
          "synthesize" predictor pixels midway between two actual
          predictors using avg2p(p), which we think of as returning
          the pixel "at" p[1/2]. */
        
       case B_VR_PRED:    /* SSE (vertical right) step =
                             (2,1) or (-2,-1) */
           B[3][0] = avg3p(E + 2);  /* predictor is from (1, -1) */
           B[2][0] = avg3p(E + 3);  /* (0, -1) */
           B[3][1] = B[1][0] = avg3p(E + 4);  /* (-1,   -1) */
           B[2][1] = B[0][0] = avg2p(E + 4);  /* (-1, -1/2) */
           B[3][2] = B[1][1] = avg3p(E + 5);  /* (-1,    0) */
           B[2][2] = B[0][1] = avg2p(E + 5);  /* (-1,  1/2) */
           B[3][3] = B[1][2] = avg3p(E + 6);  /* (-1,    1) */
           B[2][3] = B[0][2] = avg2p(E + 6);  /* (-1,  3/2) */
        
       case B_VR_PRED:    /* SSE (vertical right) step =
                             (2,1) or (-2,-1) */
           B[3][0] = avg3p(E + 2);  /* predictor is from (1, -1) */
           B[2][0] = avg3p(E + 3);  /* (0, -1) */
           B[3][1] = B[1][0] = avg3p(E + 4);  /* (-1,   -1) */
           B[2][1] = B[0][0] = avg2p(E + 4);  /* (-1, -1/2) */
           B[3][2] = B[1][1] = avg3p(E + 5);  /* (-1,    0) */
           B[2][2] = B[0][1] = avg2p(E + 5);  /* (-1,  1/2) */
           B[3][3] = B[1][2] = avg3p(E + 6);  /* (-1,    1) */
           B[2][3] = B[0][2] = avg2p(E + 6);  /* (-1,  3/2) */
        
           B[1][3] = avg3p(E + 7);  /* (-1, 2) */
           B[0][3] = avg2p(E + 7);  /* (-1, 5/2) */
           break;
        
           B[1][3] = avg3p(E + 7);  /* (-1, 2) */
           B[0][3] = avg2p(E + 7);  /* (-1, 5/2) */
           break;
        
       case B_VL_PRED:    /* SSW (vertical left) step =
                             (2,-1) or (-2,1) */
           B[0][0] = avg2p(A);  /* predictor is from (-1, 1/2) */
           B[1][0] = avg3p(A + 1);  /* (-1, 1) */
           B[2][0] = B[0][1] = avg2p(A + 1);  /* (-1, 3/2) */
           B[1][1] = B[3][0] = avg3p(A + 2);  /* (-1,   2) */
           B[2][1] = B[0][2] = avg2p(A + 2);  /* (-1, 5/2) */
           B[3][1] = B[1][2] = avg3p(A + 3);  /* (-1,   3) */
           B[2][2] = B[0][3] = avg2p(A + 3);  /* (-1, 7/2) */
           B[3][2] = B[1][3] = avg3p(A + 4);  /* (-1,   4) */
           /* Last two values do not strictly follow the pattern. */
           B[2][3] = avg3p(A + 5);  /* (-1, 5) [avg2p(A + 4) =
                                        (-1,9/2)] */
           B[3][3] = avg3p(A + 6);  /* (-1, 6) [avg3p(A + 5) =
                                        (-1,5)] */
           break;
        
       case B_VL_PRED:    /* SSW (vertical left) step =
                             (2,-1) or (-2,1) */
           B[0][0] = avg2p(A);  /* predictor is from (-1, 1/2) */
           B[1][0] = avg3p(A + 1);  /* (-1, 1) */
           B[2][0] = B[0][1] = avg2p(A + 1);  /* (-1, 3/2) */
           B[1][1] = B[3][0] = avg3p(A + 2);  /* (-1,   2) */
           B[2][1] = B[0][2] = avg2p(A + 2);  /* (-1, 5/2) */
           B[3][1] = B[1][2] = avg3p(A + 3);  /* (-1,   3) */
           B[2][2] = B[0][3] = avg2p(A + 3);  /* (-1, 7/2) */
           B[3][2] = B[1][3] = avg3p(A + 4);  /* (-1,   4) */
           /* Last two values do not strictly follow the pattern. */
           B[2][3] = avg3p(A + 5);  /* (-1, 5) [avg2p(A + 4) =
                                        (-1,9/2)] */
           B[3][3] = avg3p(A + 6);  /* (-1, 6) [avg3p(A + 5) =
                                        (-1,5)] */
           break;
        
       case B_HD_PRED:    /* ESE (horizontal down) step =
                             (1,2) or (-1,-2) */
           B[3][0] = avg2p(E);  /* predictor is from (5/2, -1) */
           B[3][1] = avg3p(E + 1);  /* (2, -1) */
           B[2][0] = B[3][2] = svg2p(E + 1);  /* ( 3/2, -1) */
           B[2][1] = B[3][3] = avg3p(E + 2);  /* (   1, -1) */
           B[2][2] = B[1][0] = avg2p(E + 2);  /* ( 1/2, -1) */
           B[2][3] = B[1][1] = avg3p(E + 3);  /* (   0, -1) */
           B[1][2] = B[0][0] = avg2p(E + 3);  /* (-1/2, -1) */
           B[1][3] = B[0][1] = avg3p(E + 4);  /* (  -1, -1) */
           B[0][2] = avg3p(E + 5);  /* (-1, 0) */
           B[0][3] = avg3p(E + 6);  /* (-1, 1) */
           break;
        
       case B_HD_PRED:    /* ESE (horizontal down) step =
                             (1,2) or (-1,-2) */
           B[3][0] = avg2p(E);  /* predictor is from (5/2, -1) */
           B[3][1] = avg3p(E + 1);  /* (2, -1) */
           B[2][0] = B[3][2] = svg2p(E + 1);  /* ( 3/2, -1) */
           B[2][1] = B[3][3] = avg3p(E + 2);  /* (   1, -1) */
           B[2][2] = B[1][0] = avg2p(E + 2);  /* ( 1/2, -1) */
           B[2][3] = B[1][1] = avg3p(E + 3);  /* (   0, -1) */
           B[1][2] = B[0][0] = avg2p(E + 3);  /* (-1/2, -1) */
           B[1][3] = B[0][1] = avg3p(E + 4);  /* (  -1, -1) */
           B[0][2] = avg3p(E + 5);  /* (-1, 0) */
           B[0][3] = avg3p(E + 6);  /* (-1, 1) */
           break;
        
       case B_HU_PRED:    /* ENE (horizontal up) step = (1,-2)
                             or (-1,2) */
           B[0][0] = avg2p(L);  /* predictor is from (1/2, -1) */
           B[0][1] = avg3p(L + 1);  /* (1, -1) */
           B[0][2] = B[1][0] = avg2p(L + 1);  /* (3/2, -1) */
           B[0][3] = B[1][1] = avg3p(L + 2);  /* (  2, -1) */
           B[1][2] = B[2][0] = avg2p(L + 2);  /* (5/2, -1) */
           B[1][3] = B[2][1] = avg3(L[2], L[3], L[3]);  /* (3, -1) */
        
       case B_HU_PRED:    /* ENE (horizontal up) step = (1,-2)
                             or (-1,2) */
           B[0][0] = avg2p(L);  /* predictor is from (1/2, -1) */
           B[0][1] = avg3p(L + 1);  /* (1, -1) */
           B[0][2] = B[1][0] = avg2p(L + 1);  /* (3/2, -1) */
           B[0][3] = B[1][1] = avg3p(L + 2);  /* (  2, -1) */
           B[1][2] = B[2][0] = avg2p(L + 2);  /* (5/2, -1) */
           B[1][3] = B[2][1] = avg3(L[2], L[3], L[3]);  /* (3, -1) */
        
           /* Not possible to follow pattern for much of the bottom
              row because no (nearby) already-constructed pixels lie
              on the diagonals in question. */
           B[2][2] = B[2][3] = B[3][0] = B[3][1] = B[3][2] = B[3][3]
             = L[3];
     }
   }
        
           /* Not possible to follow pattern for much of the bottom
              row because no (nearby) already-constructed pixels lie
              on the diagonals in question. */
           B[2][2] = B[2][3] = B[3][0] = B[3][1] = B[3][2] = B[3][3]
             = L[3];
     }
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The reference decoder implementation of subblock intra-prediction may be found in predict.c (Section 20.14).

子块帧内预测的参考解码器实现可在predict.c(第20.14节)中找到。

13. DCT Coefficient Decoding
13. DCT系数解码

The second data partition consists of an encoding of the quantized DCT (and WHT) coefficients of the residue signal. As discussed in the format overview (Section 2), for each macroblock, the residue is added to the (intra- or inter-generated) prediction buffer to produce the final (except for loop filtering) reconstructed macroblock.

第二个数据分区由剩余信号的量化DCT(和WHT)系数的编码组成。如格式概述(第2节)中所述,对于每个宏块,将剩余添加到(帧内或帧间生成的)预测缓冲器中,以产生最终(循环滤波除外)重构宏块。

VP8 works exclusively with 4x4 DCTs and WHTs, applied to the 24 (or 25 with the Y2 subblock) 4x4 subblocks of a macroblock. The ordering of macroblocks within any of the "residue" partitions in general follows the same raster scan as used in the first "prediction" partition.

VP8仅适用于4x4 DCT和WHT,应用于宏块的24个(或25个Y2子块)4x4子块。任何“剩余”分区内宏块的排序通常遵循与第一个“预测”分区中使用的相同光栅扫描。

For all intra- and inter-prediction modes apart from B_PRED (intra: whose Y subblocks are independently predicted) and SPLITMV (inter), each macroblock's residue record begins with the Y2 component of the residue, coded using a WHT. B_PRED and SPLITMV coded macroblocks omit this WHT and specify the 0th DCT coefficient in each of the 16 Y subblocks.

对于所有帧内和帧间预测模式,除了B_PRED(帧内:其Y子块被独立预测)和SPLITMV(帧间),每个宏块的剩余记录从剩余的Y2分量开始,使用WHT编码。B_PRED和SPLITMV编码宏块省略该WHT,并在16个Y子块中的每个子块中指定第0个DCT系数。

After the optional Y2 block, the residue record continues with 16 DCTs for the Y subblocks, followed by 4 DCTs for the U subblocks, ending with 4 DCTs for the V subblocks. The subblocks occur in the usual order.

在可选的Y2块之后,剩余记录继续进行Y子块的16个DCT,接着是U子块的4个DCT,最后是V子块的4个DCT。子块以通常的顺序出现。

The DCTs and WHT are tree-coded using a 12-element alphabet whose members we call "tokens". Except for the end-of-block token (which sets the remaining subblock coefficients to zero and is followed by the next block), each token (sometimes augmented with data immediately following the token) specifies the value of the single coefficient at the current (implicit) position and is followed by a token applying to the next (implicit) position.

DCT和WHT使用12元素字母表进行树编码,我们称其成员为“标记”。除了块结束标记(将剩余的子块系数设置为零,然后是下一个块)之外,每个标记(有时在标记后面加上数据)在当前(隐式)位置指定单个系数的值,然后是应用于下一个(隐式)位置的标记位置

For all the Y and chroma subblocks, the ordering of the coefficients follows a so-called zig-zag order. DCTs begin at coefficient 1 if Y2 is present, and begin at coefficient 0 if Y2 is absent. The WHT for a Y2 subblock always begins at coefficient 0.

对于所有Y和色度子块,系数的顺序遵循所谓的Z字形顺序。如果存在Y2,则DCT从系数1开始,如果不存在Y2,则从系数0开始。Y2子块的WHT始终从系数0开始。

13.1. Macroblock without Non-Zero Coefficient Values
13.1. 没有非零系数值的宏块

If the flag within macroblock (MB) MODE_INFO indicates that a macroblock does not have any non-zero coefficients, the decoding process of DCT coefficients is skipped for the macroblock.

如果宏块(MB)模式_INFO内的标志指示宏块不具有任何非零系数,则针对该宏块跳过DCT系数的解码过程。

13.2. Coding of Individual Coefficient Values
13.2. 单个系数值的编码

The coding of coefficient tokens is the same for the DCT and WHT, and for the remainder of this section "DCT" should be taken to mean either DCT or WHT.

系数标记的编码对于DCT和WHT是相同的,对于本节的其余部分,“DCT”应表示DCT或WHT。

All tokens (except end-of-block) specify either a single unsigned value or a range of unsigned values (immediately) followed by a simple probabilistic encoding of the offset of the value from the base of that range.

所有标记(块末尾除外)指定单个无符号值或一个无符号值范围(立即),然后对该值从该范围底部的偏移量进行简单的概率编码。

Non-zero values (of either type) are then followed by a flag indicating the sign of the coded value (negative if 1, positive if 0).

非零值(任何一种类型)后面都会有一个标志,指示编码值的符号(如果为1,则为负,如果为0,则为正)。

Below are the tokens and decoding tree.

下面是令牌和解码树。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef enum
   {
       DCT_0,      /* value 0 */
       DCT_1,      /* 1 */
       DCT_2,      /* 2 */
       DCT_3,      /* 3 */
       DCT_4,      /* 4 */
       dct_cat1,   /* range 5 - 6  (size 2) */
       dct_cat2,   /* 7 - 10   (4) */
       dct_cat3,   /* 11 - 18  (8) */
       dct_cat4,   /* 19 - 34  (16) */
       dct_cat5,   /* 35 - 66  (32) */
       dct_cat6,   /* 67 - 2048  (1982) */
       dct_eob,    /* end of block */
        
   typedef enum
   {
       DCT_0,      /* value 0 */
       DCT_1,      /* 1 */
       DCT_2,      /* 2 */
       DCT_3,      /* 3 */
       DCT_4,      /* 4 */
       dct_cat1,   /* range 5 - 6  (size 2) */
       dct_cat2,   /* 7 - 10   (4) */
       dct_cat3,   /* 11 - 18  (8) */
       dct_cat4,   /* 19 - 34  (16) */
       dct_cat5,   /* 35 - 66  (32) */
       dct_cat6,   /* 67 - 2048  (1982) */
       dct_eob,    /* end of block */
        
       num_dct_tokens   /* 12 */
   }
   dct_token;
        
       num_dct_tokens   /* 12 */
   }
   dct_token;
        
   const tree_index coeff_tree [2 * (num_dct_tokens - 1)] =
   {
    -dct_eob, 2,               /* eob = "0"   */
     -DCT_0, 4,                /* 0   = "10"  */
      -DCT_1, 6,               /* 1   = "110" */
       8, 12,
        -DCT_2, 10,            /* 2   = "11100" */
         -DCT_3, -DCT_4,       /* 3   = "111010", 4 = "111011" */
        14, 16,
         -dct_cat1, -dct_cat2, /* cat1 =  "111100",
                                  cat2 = "111101" */
        18, 20,
         -dct_cat3, -dct_cat4, /* cat3 = "1111100",
                                  cat4 = "1111101" */
         -dct_cat5, -dct_cat6  /* cat4 = "1111110",
                                  cat4 = "1111111" */
   };
        
   const tree_index coeff_tree [2 * (num_dct_tokens - 1)] =
   {
    -dct_eob, 2,               /* eob = "0"   */
     -DCT_0, 4,                /* 0   = "10"  */
      -DCT_1, 6,               /* 1   = "110" */
       8, 12,
        -DCT_2, 10,            /* 2   = "11100" */
         -DCT_3, -DCT_4,       /* 3   = "111010", 4 = "111011" */
        14, 16,
         -dct_cat1, -dct_cat2, /* cat1 =  "111100",
                                  cat2 = "111101" */
        18, 20,
         -dct_cat3, -dct_cat4, /* cat3 = "1111100",
                                  cat4 = "1111101" */
         -dct_cat5, -dct_cat6  /* cat4 = "1111110",
                                  cat4 = "1111111" */
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

In general, all DCT coefficients are decoded using the same tree. However, if the preceding coefficient is a DCT_0, decoding will skip the first branch, since it is not possible for dct_eob to follow a DCT_0.

通常,所有DCT系数都使用同一棵树进行解码。然而,如果前面的系数是DCT_0,则解码将跳过第一个分支,因为DCT_eob不可能跟随DCT_0。

The tokens dct_cat1 ... dct_cat6 specify ranges of unsigned values, the value within the range being formed by adding an unsigned offset (whose width is 1, 2, 3, 4, 5, or 11 bits, respectively) to the base of the range, using the following algorithm and fixed probability tables.

令牌dct_cat1。。。dct_cat6指定无符号值的范围,该范围内的值是通过使用以下算法和固定概率表将无符号偏移量(其宽度分别为1、2、3、4、5或11位)添加到范围的基来形成的。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   uint DCTextra(bool_decoder *d, const Prob *p)
   {
       uint v = 0;
       do { v += v + read_bool(d, *p);}  while (*++p);
       return v;
   }
        
   uint DCTextra(bool_decoder *d, const Prob *p)
   {
       uint v = 0;
       do { v += v + read_bool(d, *p);}  while (*++p);
       return v;
   }
        
   const Prob Pcat1[] = { 159, 0};
   const Prob Pcat2[] = { 165, 145, 0};
   const Prob Pcat3[] = { 173, 148, 140, 0};
   const Prob Pcat4[] = { 176, 155, 140, 135, 0};
   const Prob Pcat5[] = { 180, 157, 141, 134, 130, 0};
   const Prob Pcat6[] =
       { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0};
        
   const Prob Pcat1[] = { 159, 0};
   const Prob Pcat2[] = { 165, 145, 0};
   const Prob Pcat3[] = { 173, 148, 140, 0};
   const Prob Pcat4[] = { 176, 155, 140, 135, 0};
   const Prob Pcat5[] = { 180, 157, 141, 134, 130, 0};
   const Prob Pcat6[] =
       { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0};
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

If v -- the unsigned value decoded using the coefficient tree, possibly augmented by the process above -- is non-zero, its sign is set by simply reading a flag:

如果v——使用系数树解码的无符号值(可能通过上述过程增加)为非零,则其符号仅通过读取一个标志来设置:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   if (read_bool(d, 128))
       v = -v;
        
   if (read_bool(d, 128))
       v = -v;
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
13.3. Token Probabilities
13.3. 标记概率

The probability specification for the token tree (unlike that for the "extra bits" described above) is rather involved. It uses three pieces of context to index a large probability table, the contents of which may be incrementally modified in the frame header. The full (non-constant) probability table is laid out as follows.

令牌树的概率规范(与上述“额外比特”的概率规范不同)相当复杂。它使用三个上下文来索引一个大概率表,其内容可以在帧头中进行增量修改。完整(非常数)概率表如下所示。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        

Prob coeff_probs [4] [8] [3] [num_dct_tokens-1];

Prob coeff_probs[4][8][3][num_dct_tokens-1];

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Working from the outside in, the outermost dimension is indexed by the type of plane being decoded:

从外到内工作时,最外层尺寸根据解码的平面类型进行索引:

o 0 - Y beginning at coefficient 1 (i.e., Y after Y2)

o 0-从系数1开始的Y(即Y2之后的Y)

o 1 - Y2

o 1-Y2

o 2 - U or V

o 2-U或V

o 3 - Y beginning at coefficient 0 (i.e., Y in the absence of Y2).

o 3-从系数0开始的Y(即,在没有Y2的情况下为Y)。

The next dimension is selected by the position of the coefficient being decoded. That position, c, steps by ones up to 15, starting from zero for block types 1, 2, or 3 and starting from one for block type 0. The second array index is then

下一个维度由解码系数的位置选择。该位置,c,从1、2或3型块的0开始,从1型块的0开始,逐步递增至15。第二个数组索引是

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        

coeff_bands [c]

系数带[c]

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Where:

哪里:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const int coeff_bands [16] = {
        0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7
   };
        
   const int coeff_bands [16] = {
        0, 1, 2, 3, 6, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

is a fixed mapping of position to "band".

是位置到“波段”的固定映射。

The third dimension is the trickiest. Roughly speaking, it measures the "local complexity" or extent to which nearby coefficients are non-zero.

第三维度是最棘手的。粗略地说,它衡量“局部复杂性”或附近系数非零的程度。

For the first coefficient (DC, unless the block type is 0), we consider the (already encoded) blocks within the same plane (Y2, Y, U, or V) above and to the left of the current block. The context index is then the number (0, 1, or 2) of these blocks that had at least one non-zero coefficient in their residue record. Specifically for Y2, because macroblocks above and to the left may or may not have a Y2 block, the block above is determined by the most recent macroblock in the same column that has a Y2 block, and the block to the left is determined by the most recent macroblock in the same row that has a Y2 block.

对于第一系数(DC,除非块类型为0),我们考虑在当前块上方和左侧的同一平面(Y2、Y、U或V)中的(已编码)块。然后,上下文索引是在剩余记录中至少有一个非零系数的这些块的数目(0、1或2)。特别是对于Y2,因为上面和左边的宏块可能有也可能没有Y2块,上面的块由具有Y2块的同一列中的最新宏块确定,左边的块由具有Y2块的同一行中的最新宏块确定。

Beyond the first coefficient, the context index is determined by the absolute value of the most recently decoded coefficient (necessarily within the current block) and is 0 if the last coefficient was a zero, 1 if it was plus or minus one, and 2 if its absolute value exceeded one.

在第一个系数之外,上下文索引由最近解码的系数(必须在当前块内)的绝对值确定,如果最后一个系数为零,则上下文索引为0,如果其为正或负1,则上下文索引为1,如果其绝对值超过1,则上下文索引为2。

Note that the intuitive meaning of this measure changes as coefficients are decoded. For example, prior to the first token, a zero means that the neighbors are empty, suggesting that the current block may also be empty. After the first token, because an end-of-block token must have at least one non-zero value before it, a zero means that we just decoded a zero and hence guarantees that a non-zero coefficient will appear later in this block. However, this shift in meaning is perfectly okay because the complete context depends also on the coefficient band (and since band 0 is occupied exclusively by position 0).

请注意,随着系数被解码,此度量的直观含义会发生变化。例如,在第一个令牌之前,零表示邻居为空,表明当前块也可能为空。在第一个令牌之后,因为块结束令牌之前必须至少有一个非零值,所以零表示我们刚刚解码了一个零,因此保证非零系数稍后将出现在该块中。然而,这种意义上的转移是完全正确的,因为完整的上下文也取决于系数带(并且因为带0完全被位置0占据)。

As with other contexts used by VP8, the "neighboring block" context described here needs a special definition for subblocks lying along the top row or left edge of the frame. These "non-existent" predictors above and to the left of the image are simply taken to be empty -- that is, taken to contain no non-zero coefficients.

与VP8使用的其他上下文一样,此处描述的“相邻块”上下文需要对位于帧顶行或左边缘的子块进行特殊定义。图像上方和左侧的这些“不存在”预测器被简单地认为是空的——也就是说,不包含非零系数。

The residue decoding of each macroblock then requires, in each of two directions (above and to the left), an aggregate coefficient predictor consisting of a single Y2 predictor, two predictors for each of U and V, and four predictors for Y. In accordance with the scan-ordering of macroblocks, a decoder needs to maintain a single "left" aggregate predictor and a row of "above" aggregate predictors.

然后,每个宏块的剩余解码在两个方向(上方和左侧)的每个方向上都需要一个聚合系数预测器,该预测器由一个Y2预测器、两个U和V预测器以及四个Y预测器组成。根据宏块的扫描顺序,解码器需要保持一个“左”聚合预测值和一行“以上”聚合预测值。

Before decoding any residue, these maintained predictors may simply be cleared, in compliance with the definition of "non-existent" prediction. After each block is decoded, the two predictors referenced by the block are replaced with the (empty or non-empty) state of the block, in preparation for the later decoding of the blocks below and to the right of the block just decoded.

在解码任何剩余之前,可以根据“不存在”预测的定义,简单地清除这些保持的预测器。在解码每个块之后,由块引用的两个预测器被块的(空或非空)状态替换,以准备稍后解码刚刚解码的块的右下方的块。

The fourth, and final, dimension of the token probability array is of course indexed by (half) the position in the token tree structure, as are all tree probability arrays.

令牌概率数组的第四个也是最后一个维度当然是由令牌树结构中的位置(一半)索引的,就像所有树概率数组一样。

The pseudocode below illustrates the decoding process. Note that criteria, functions, etc. delimited with ** are either dependent on decoder architecture or are elaborated on elsewhere in this document.

下面的伪码说明了解码过程。请注意,用**分隔的标准、功能等取决于解码器架构,或在本文档其他地方详细说明。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   int block[16] = { 0 }; /* current 4x4 block coeffs */
   int firstCoeff = 0;
   int plane;
   int ctx2;
   int ctx3 = 0; /* the 3rd context referred to in above description */
   Prob *probTable;
   int token;
   int sign;
   int absValue;
   int extraBits;
   bool prevCoeffWasZero = false;
   bool currentBlockHasCoeffs = false;
   /* base coeff abs values per each category, elem #0 is
      DCT_VAL_CATEGORY1, * #1 is DCT_VAL_CATEGORY2, etc. */
   int categoryBase[6] = { 5, 7, 11, 19, 35, 67 };
        
   int block[16] = { 0 }; /* current 4x4 block coeffs */
   int firstCoeff = 0;
   int plane;
   int ctx2;
   int ctx3 = 0; /* the 3rd context referred to in above description */
   Prob *probTable;
   int token;
   int sign;
   int absValue;
   int extraBits;
   bool prevCoeffWasZero = false;
   bool currentBlockHasCoeffs = false;
   /* base coeff abs values per each category, elem #0 is
      DCT_VAL_CATEGORY1, * #1 is DCT_VAL_CATEGORY2, etc. */
   int categoryBase[6] = { 5, 7, 11, 19, 35, 67 };
        
   /* Determine plane to use */
   if ( **current_block_is_Y2_block** )       plane = 0;
   else if ( **current_block_is_chroma** )   plane = 2;
   else if ( **current_macroblock_has_Y2** ) plane = 1;
   else                                      plane = 3;
        
   /* Determine plane to use */
   if ( **current_block_is_Y2_block** )       plane = 0;
   else if ( **current_block_is_chroma** )   plane = 2;
   else if ( **current_macroblock_has_Y2** ) plane = 1;
   else                                      plane = 3;
        
   /* For luma blocks of a "Y2 macroblock" we skip coeff index #0 */
   if ( plane == 1 )
       firstCoeff++;
        
   /* For luma blocks of a "Y2 macroblock" we skip coeff index #0 */
   if ( plane == 1 )
       firstCoeff++;
        
   /* Determine whether neighbor 4x4 blocks have coefficients.
      This is dependent on the plane we are currently decoding;
      i.e., we check only coefficients from the same plane as the
      current block. */
   if ( **left_neighbor_block_has_coefficients(plane)** )
       ctx3++;
   if ( **above_neighbor_block_has_coefficients(plane)** )
       ctx3++;
        
   /* Determine whether neighbor 4x4 blocks have coefficients.
      This is dependent on the plane we are currently decoding;
      i.e., we check only coefficients from the same plane as the
      current block. */
   if ( **left_neighbor_block_has_coefficients(plane)** )
       ctx3++;
   if ( **above_neighbor_block_has_coefficients(plane)** )
       ctx3++;
        
   for( i = firstCoeff; i < 16; ++i )
   {
       ctx2 = coeff_bands[i];
       probTable = coeff_probs[plane][ctx2][ctx3];
        
   for( i = firstCoeff; i < 16; ++i )
   {
       ctx2 = coeff_bands[i];
       probTable = coeff_probs[plane][ctx2][ctx3];
        
       /* skip first code (dct_eob) if previous token was DCT_0 */
       if ( prevCoeffWasZero )
           token = treed_read ( d, **coeff_tree_without_eob**,
             probTable );
       else
           token = treed_read ( d, coeff_tree, probTable );
        
       /* skip first code (dct_eob) if previous token was DCT_0 */
       if ( prevCoeffWasZero )
           token = treed_read ( d, **coeff_tree_without_eob**,
             probTable );
       else
           token = treed_read ( d, coeff_tree, probTable );
        

if ( token == dct_eob ) break;

如果(令牌==dct_eob)中断;

       if ( token != DCT_0 )
       {
           currentBlockHasCoeffs = true;
     if ( **token_has_extra_bits(token)** )
     {
         extraBits = DCTextra( token );
         absValue =
             categoryBase[**token_to_cat_index(token)**] +
       extraBits;
     }
     else
     {
         absValue = **token_to_abs_value(token)**;
     }
        
       if ( token != DCT_0 )
       {
           currentBlockHasCoeffs = true;
     if ( **token_has_extra_bits(token)** )
     {
         extraBits = DCTextra( token );
         absValue =
             categoryBase[**token_to_cat_index(token)**] +
       extraBits;
     }
     else
     {
         absValue = **token_to_abs_value(token)**;
     }
        
     sign = read_bool(d, 128);
           block[i] = sign ? -absValue : absValue;
       }
       else
       {
           absValue = 0;
       }
        
     sign = read_bool(d, 128);
           block[i] = sign ? -absValue : absValue;
       }
       else
       {
           absValue = 0;
       }
        
       /* Set contexts and stuff for next coeff */
       if ( absValue == 0 )         ctx3 = 0;
       else if ( absValue == 1 )   ctx3 = 1;
       else                        ctx3 = 2;
       prevCoeffWasZero = true;
   }
        
       /* Set contexts and stuff for next coeff */
       if ( absValue == 0 )         ctx3 = 0;
       else if ( absValue == 1 )   ctx3 = 1;
       else                        ctx3 = 2;
       prevCoeffWasZero = true;
   }
        
   /* Store current block status to decoder internals */
   **block_has_coefficients[currentMb][currentBlock]** =
     currentBlockHasCoeffs;
        
   /* Store current block status to decoder internals */
   **block_has_coefficients[currentMb][currentBlock]** =
     currentBlockHasCoeffs;
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

While we have in fact completely described the coefficient decoding procedure, the reader will probably find it helpful to consult the reference implementation, which can be found in the file tokens.c (Section 20.16).

虽然我们实际上已经完全描述了系数解码过程,但读者可能会发现参考实现很有帮助,参考实现可以在文件tokens.c(第20.16节)中找到。

13.4. Token Probability Updates
13.4. 令牌概率更新

As mentioned above, the token-decoding probabilities may change from frame to frame. After detection of a key frame, they are of course set to their defaults as shown in Section 13.5; this must occur before decoding the remainder of the header, as both key frames and interframes may adjust these probabilities.

如上所述,令牌解码概率可以在帧之间改变。在检测到关键帧后,它们当然被设置为第13.5节所示的默认值;这必须在解码报头的其余部分之前发生,因为关键帧和帧间都可以调整这些概率。

The layout and semantics of the coefficient probability update record (Section I of the frame header) are straightforward. For each position in the coeff_probs array there occurs a fixed-probability bool indicating whether or not the corresponding probability should be updated. If the bool is true, there follows a P(8) replacing that probability. Note that updates are cumulative; that is, a probability updated on one frame is in effect for all ensuing frames until the next key frame, or until the probability is explicitly updated by another frame.

系数概率更新记录(帧头的第一部分)的布局和语义非常简单。对于coeff_probs阵列中的每个位置,都会出现一个固定的概率bool,指示是否应更新相应的概率。如果布尔值为真,则会有一个P(8)替换该概率。注意,更新是累积的;也就是说,在一帧上更新的概率对所有后续帧有效,直到下一关键帧,或者直到该概率被另一帧显式更新。

The algorithm to effect the foregoing is simple:

实现上述目的的算法很简单:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   int i = 0;  do {
    int j = 0;  do {
     int k = 0;  do {
      int t = 0;  do {
        
   int i = 0;  do {
    int j = 0;  do {
     int k = 0;  do {
      int t = 0;  do {
        
           if (read_bool(d, coeff_update_probs [i] [j] [k] [t]))
               coeff_probs [i] [j] [k] [t] = read_literal(d, 8);
        
           if (read_bool(d, coeff_update_probs [i] [j] [k] [t]))
               coeff_probs [i] [j] [k] [t] = read_literal(d, 8);
        
      } while (++t < num_dct_tokens - 1);
     } while (++k < 3);
    } while (++j < 8);
   } while (++i < 4);
        
      } while (++t < num_dct_tokens - 1);
     } while (++k < 3);
    } while (++j < 8);
   } while (++i < 4);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The (constant) update probabilities are as follows:

(恒定)更新概率如下所示:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const Prob coeff_update_probs [4] [8] [3] [num_dct_tokens-1] =
   {
    {
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255},
      { 249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255},
      { 234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255},
      { 250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     }
    },
        
   const Prob coeff_update_probs [4] [8] [3] [num_dct_tokens-1] =
   {
    {
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255},
      { 249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255},
      { 234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255},
      { 250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     }
    },
        
    {
     {
      { 217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255},
      { 234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255}
     },
     {
      { 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     }
    },
    {
     {
      { 186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255},
      { 234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255},
      { 251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255}
     },
        
    {
     {
      { 217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255},
      { 234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255}
     },
     {
      { 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     }
    },
    {
     {
      { 186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255},
      { 234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255},
      { 251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255}
     },
        
     {
      { 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     }
    },
    {
     {
      { 248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255},
      { 248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255}
     },
        
     {
      { 255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     }
    },
    {
     {
      { 248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255},
      { 248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255}
     },
        
     {
      { 255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255},
      { 248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     }
    }
   };
        
     {
      { 255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255},
      { 248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255},
      { 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     },
     {
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
      { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
     }
    }
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
13.5. Default Token Probability Table
13.5. 默认令牌概率表

The default token probabilities are as follows.

默认令牌概率如下所示。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const Prob default_coeff_probs [4] [8] [3] [num_dct_tokens - 1] =
   {
    {
     {
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}
     },
     {
      { 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128},
      { 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128},
      { 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128}
     },
     {
      {   1,  98, 248, 255, 236, 226, 255, 255, 128, 128, 128},
      { 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128},
      {  78, 134, 202, 247, 198, 180, 255, 219, 128, 128, 128}
     },
     {
      {   1, 185, 249, 255, 243, 255, 128, 128, 128, 128, 128},
      { 184, 150, 247, 255, 236, 224, 128, 128, 128, 128, 128},
      {  77, 110, 216, 255, 236, 230, 128, 128, 128, 128, 128}
     },
     {
      {   1, 101, 251, 255, 241, 255, 128, 128, 128, 128, 128},
      { 170, 139, 241, 252, 236, 209, 255, 255, 128, 128, 128},
      {  37, 116, 196, 243, 228, 255, 255, 255, 128, 128, 128}
     },
     {
      {   1, 204, 254, 255, 245, 255, 128, 128, 128, 128, 128},
      { 207, 160, 250, 255, 238, 128, 128, 128, 128, 128, 128},
      { 102, 103, 231, 255, 211, 171, 128, 128, 128, 128, 128}
     },
     {
      {   1, 152, 252, 255, 240, 255, 128, 128, 128, 128, 128},
      { 177, 135, 243, 255, 234, 225, 128, 128, 128, 128, 128},
      {  80, 129, 211, 255, 194, 224, 128, 128, 128, 128, 128}
     },
        
   const Prob default_coeff_probs [4] [8] [3] [num_dct_tokens - 1] =
   {
    {
     {
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}
     },
     {
      { 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128},
      { 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128},
      { 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128}
     },
     {
      {   1,  98, 248, 255, 236, 226, 255, 255, 128, 128, 128},
      { 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128},
      {  78, 134, 202, 247, 198, 180, 255, 219, 128, 128, 128}
     },
     {
      {   1, 185, 249, 255, 243, 255, 128, 128, 128, 128, 128},
      { 184, 150, 247, 255, 236, 224, 128, 128, 128, 128, 128},
      {  77, 110, 216, 255, 236, 230, 128, 128, 128, 128, 128}
     },
     {
      {   1, 101, 251, 255, 241, 255, 128, 128, 128, 128, 128},
      { 170, 139, 241, 252, 236, 209, 255, 255, 128, 128, 128},
      {  37, 116, 196, 243, 228, 255, 255, 255, 128, 128, 128}
     },
     {
      {   1, 204, 254, 255, 245, 255, 128, 128, 128, 128, 128},
      { 207, 160, 250, 255, 238, 128, 128, 128, 128, 128, 128},
      { 102, 103, 231, 255, 211, 171, 128, 128, 128, 128, 128}
     },
     {
      {   1, 152, 252, 255, 240, 255, 128, 128, 128, 128, 128},
      { 177, 135, 243, 255, 234, 225, 128, 128, 128, 128, 128},
      {  80, 129, 211, 255, 194, 224, 128, 128, 128, 128, 128}
     },
        
     {
      {   1,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 246,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}
     }
    },
    {
     {
      { 198,  35, 237, 223, 193, 187, 162, 160, 145, 155,  62},
      { 131,  45, 198, 221, 172, 176, 220, 157, 252, 221,   1},
      {  68,  47, 146, 208, 149, 167, 221, 162, 255, 223, 128}
     },
     {
      {   1, 149, 241, 255, 221, 224, 255, 255, 128, 128, 128},
      { 184, 141, 234, 253, 222, 220, 255, 199, 128, 128, 128},
      {  81,  99, 181, 242, 176, 190, 249, 202, 255, 255, 128}
     },
     {
      {   1, 129, 232, 253, 214, 197, 242, 196, 255, 255, 128},
      {  99, 121, 210, 250, 201, 198, 255, 202, 128, 128, 128},
      {  23,  91, 163, 242, 170, 187, 247, 210, 255, 255, 128}
     },
     {
      {   1, 200, 246, 255, 234, 255, 128, 128, 128, 128, 128},
      { 109, 178, 241, 255, 231, 245, 255, 255, 128, 128, 128},
      {  44, 130, 201, 253, 205, 192, 255, 255, 128, 128, 128}
     },
     {
      {   1, 132, 239, 251, 219, 209, 255, 165, 128, 128, 128},
      {  94, 136, 225, 251, 218, 190, 255, 255, 128, 128, 128},
      {  22, 100, 174, 245, 186, 161, 255, 199, 128, 128, 128}
     },
     {
      {   1, 182, 249, 255, 232, 235, 128, 128, 128, 128, 128},
      { 124, 143, 241, 255, 227, 234, 128, 128, 128, 128, 128},
      {  35,  77, 181, 251, 193, 211, 255, 205, 128, 128, 128}
     },
     {
      {   1, 157, 247, 255, 236, 231, 255, 255, 128, 128, 128},
      { 121, 141, 235, 255, 225, 227, 255, 255, 128, 128, 128},
      {  45,  99, 188, 251, 195, 217, 255, 224, 128, 128, 128}
     },
     {
      {   1,   1, 251, 255, 213, 255, 128, 128, 128, 128, 128},
      { 203,   1, 248, 255, 255, 128, 128, 128, 128, 128, 128},
      { 137,   1, 177, 255, 224, 255, 128, 128, 128, 128, 128}
     }
    },
        
     {
      {   1,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 246,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}
     }
    },
    {
     {
      { 198,  35, 237, 223, 193, 187, 162, 160, 145, 155,  62},
      { 131,  45, 198, 221, 172, 176, 220, 157, 252, 221,   1},
      {  68,  47, 146, 208, 149, 167, 221, 162, 255, 223, 128}
     },
     {
      {   1, 149, 241, 255, 221, 224, 255, 255, 128, 128, 128},
      { 184, 141, 234, 253, 222, 220, 255, 199, 128, 128, 128},
      {  81,  99, 181, 242, 176, 190, 249, 202, 255, 255, 128}
     },
     {
      {   1, 129, 232, 253, 214, 197, 242, 196, 255, 255, 128},
      {  99, 121, 210, 250, 201, 198, 255, 202, 128, 128, 128},
      {  23,  91, 163, 242, 170, 187, 247, 210, 255, 255, 128}
     },
     {
      {   1, 200, 246, 255, 234, 255, 128, 128, 128, 128, 128},
      { 109, 178, 241, 255, 231, 245, 255, 255, 128, 128, 128},
      {  44, 130, 201, 253, 205, 192, 255, 255, 128, 128, 128}
     },
     {
      {   1, 132, 239, 251, 219, 209, 255, 165, 128, 128, 128},
      {  94, 136, 225, 251, 218, 190, 255, 255, 128, 128, 128},
      {  22, 100, 174, 245, 186, 161, 255, 199, 128, 128, 128}
     },
     {
      {   1, 182, 249, 255, 232, 235, 128, 128, 128, 128, 128},
      { 124, 143, 241, 255, 227, 234, 128, 128, 128, 128, 128},
      {  35,  77, 181, 251, 193, 211, 255, 205, 128, 128, 128}
     },
     {
      {   1, 157, 247, 255, 236, 231, 255, 255, 128, 128, 128},
      { 121, 141, 235, 255, 225, 227, 255, 255, 128, 128, 128},
      {  45,  99, 188, 251, 195, 217, 255, 224, 128, 128, 128}
     },
     {
      {   1,   1, 251, 255, 213, 255, 128, 128, 128, 128, 128},
      { 203,   1, 248, 255, 255, 128, 128, 128, 128, 128, 128},
      { 137,   1, 177, 255, 224, 255, 128, 128, 128, 128, 128}
     }
    },
        
    {
     {
      { 253,   9, 248, 251, 207, 208, 255, 192, 128, 128, 128},
      { 175,  13, 224, 243, 193, 185, 249, 198, 255, 255, 128},
      {  73,  17, 171, 221, 161, 179, 236, 167, 255, 234, 128}
     },
     {
      {   1,  95, 247, 253, 212, 183, 255, 255, 128, 128, 128},
      { 239,  90, 244, 250, 211, 209, 255, 255, 128, 128, 128},
      { 155,  77, 195, 248, 188, 195, 255, 255, 128, 128, 128}
     },
     {
      {   1,  24, 239, 251, 218, 219, 255, 205, 128, 128, 128},
      { 201,  51, 219, 255, 196, 186, 128, 128, 128, 128, 128},
      {  69,  46, 190, 239, 201, 218, 255, 228, 128, 128, 128}
     },
     {
      {   1, 191, 251, 255, 255, 128, 128, 128, 128, 128, 128},
      { 223, 165, 249, 255, 213, 255, 128, 128, 128, 128, 128},
      { 141, 124, 248, 255, 255, 128, 128, 128, 128, 128, 128}
     },
     {
      {   1,  16, 248, 255, 255, 128, 128, 128, 128, 128, 128},
      { 190,  36, 230, 255, 236, 255, 128, 128, 128, 128, 128},
      { 149,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128}
     },
     {
      {   1, 226, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 247, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 240, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128}
     },
     {
      {   1, 134, 252, 255, 255, 128, 128, 128, 128, 128, 128},
      { 213,  62, 250, 255, 255, 128, 128, 128, 128, 128, 128},
      {  55,  93, 255, 128, 128, 128, 128, 128, 128, 128, 128}
     },
     {
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}
     }
    },
    {
     {
      { 202,  24, 213, 235, 186, 191, 220, 160, 240, 175, 255},
      { 126,  38, 182, 232, 169, 184, 228, 174, 255, 187, 128},
      {  61,  46, 138, 219, 151, 178, 240, 170, 255, 216, 128}
     },
        
    {
     {
      { 253,   9, 248, 251, 207, 208, 255, 192, 128, 128, 128},
      { 175,  13, 224, 243, 193, 185, 249, 198, 255, 255, 128},
      {  73,  17, 171, 221, 161, 179, 236, 167, 255, 234, 128}
     },
     {
      {   1,  95, 247, 253, 212, 183, 255, 255, 128, 128, 128},
      { 239,  90, 244, 250, 211, 209, 255, 255, 128, 128, 128},
      { 155,  77, 195, 248, 188, 195, 255, 255, 128, 128, 128}
     },
     {
      {   1,  24, 239, 251, 218, 219, 255, 205, 128, 128, 128},
      { 201,  51, 219, 255, 196, 186, 128, 128, 128, 128, 128},
      {  69,  46, 190, 239, 201, 218, 255, 228, 128, 128, 128}
     },
     {
      {   1, 191, 251, 255, 255, 128, 128, 128, 128, 128, 128},
      { 223, 165, 249, 255, 213, 255, 128, 128, 128, 128, 128},
      { 141, 124, 248, 255, 255, 128, 128, 128, 128, 128, 128}
     },
     {
      {   1,  16, 248, 255, 255, 128, 128, 128, 128, 128, 128},
      { 190,  36, 230, 255, 236, 255, 128, 128, 128, 128, 128},
      { 149,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128}
     },
     {
      {   1, 226, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 247, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 240, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128}
     },
     {
      {   1, 134, 252, 255, 255, 128, 128, 128, 128, 128, 128},
      { 213,  62, 250, 255, 255, 128, 128, 128, 128, 128, 128},
      {  55,  93, 255, 128, 128, 128, 128, 128, 128, 128, 128}
     },
     {
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
      { 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}
     }
    },
    {
     {
      { 202,  24, 213, 235, 186, 191, 220, 160, 240, 175, 255},
      { 126,  38, 182, 232, 169, 184, 228, 174, 255, 187, 128},
      {  61,  46, 138, 219, 151, 178, 240, 170, 255, 216, 128}
     },
        
     {
      {   1, 112, 230, 250, 199, 191, 247, 159, 255, 255, 128},
      { 166, 109, 228, 252, 211, 215, 255, 174, 128, 128, 128},
      {  39,  77, 162, 232, 172, 180, 245, 178, 255, 255, 128}
     },
     {
      {   1,  52, 220, 246, 198, 199, 249, 220, 255, 255, 128},
      { 124,  74, 191, 243, 183, 193, 250, 221, 255, 255, 128},
      {  24,  71, 130, 219, 154, 170, 243, 182, 255, 255, 128}
     },
     {
      {   1, 182, 225, 249, 219, 240, 255, 224, 128, 128, 128},
      { 149, 150, 226, 252, 216, 205, 255, 171, 128, 128, 128},
      {  28, 108, 170, 242, 183, 194, 254, 223, 255, 255, 128}
     },
     {
      {   1,  81, 230, 252, 204, 203, 255, 192, 128, 128, 128},
      { 123, 102, 209, 247, 188, 196, 255, 233, 128, 128, 128},
      {  20,  95, 153, 243, 164, 173, 255, 203, 128, 128, 128}
     },
     {
      {   1, 222, 248, 255, 216, 213, 128, 128, 128, 128, 128},
      { 168, 175, 246, 252, 235, 205, 255, 255, 128, 128, 128},
      {  47, 116, 215, 255, 211, 212, 255, 255, 128, 128, 128}
     },
     {
      {   1, 121, 236, 253, 212, 214, 255, 255, 128, 128, 128},
      { 141,  84, 213, 252, 201, 202, 255, 219, 128, 128, 128},
      {  42,  80, 160, 240, 162, 185, 255, 205, 128, 128, 128}
     },
     {
      {   1,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 244,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 238,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128}
     }
    }
   };
        
     {
      {   1, 112, 230, 250, 199, 191, 247, 159, 255, 255, 128},
      { 166, 109, 228, 252, 211, 215, 255, 174, 128, 128, 128},
      {  39,  77, 162, 232, 172, 180, 245, 178, 255, 255, 128}
     },
     {
      {   1,  52, 220, 246, 198, 199, 249, 220, 255, 255, 128},
      { 124,  74, 191, 243, 183, 193, 250, 221, 255, 255, 128},
      {  24,  71, 130, 219, 154, 170, 243, 182, 255, 255, 128}
     },
     {
      {   1, 182, 225, 249, 219, 240, 255, 224, 128, 128, 128},
      { 149, 150, 226, 252, 216, 205, 255, 171, 128, 128, 128},
      {  28, 108, 170, 242, 183, 194, 254, 223, 255, 255, 128}
     },
     {
      {   1,  81, 230, 252, 204, 203, 255, 192, 128, 128, 128},
      { 123, 102, 209, 247, 188, 196, 255, 233, 128, 128, 128},
      {  20,  95, 153, 243, 164, 173, 255, 203, 128, 128, 128}
     },
     {
      {   1, 222, 248, 255, 216, 213, 128, 128, 128, 128, 128},
      { 168, 175, 246, 252, 235, 205, 255, 255, 128, 128, 128},
      {  47, 116, 215, 255, 211, 212, 255, 255, 128, 128, 128}
     },
     {
      {   1, 121, 236, 253, 212, 214, 255, 255, 128, 128, 128},
      { 141,  84, 213, 252, 201, 202, 255, 219, 128, 128, 128},
      {  42,  80, 160, 240, 162, 185, 255, 205, 128, 128, 128}
     },
     {
      {   1,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 244,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
      { 238,   1, 255, 128, 128, 128, 128, 128, 128, 128, 128}
     }
    }
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
14. DCT and WHT Inversion and Macroblock Reconstruction
14. DCT和WHT反演与宏块重建
14.1. Dequantization
14.1. 去量化

After decoding the DCTs/WHTs as described above, each (quantized) coefficient in each subblock is multiplied by one of six dequantization factors, the choice of factor depending on the plane (Y2, Y, or chroma) and position (DC = coefficient zero, AC = any

在如上所述解码dct/wht之后,每个子块中的每个(量化)系数乘以六个去量化因子中的一个,因子的选择取决于平面(Y2、Y或色度)和位置(DC=系数零,AC=任意)

other coefficient). If the current macroblock has overridden the quantizer level (as described in Section 10), then the six factors are looked up from two dequantization tables with appropriate scaling and clamping using the single index supplied by the override. Otherwise, the frame-level dequantization factors (as described in Section 9.6) are used. In either case, the multiplies are computed and stored using 16-bit signed integers.

其他系数)。如果当前宏块覆盖了量化器级别(如第10节所述),则使用覆盖提供的单个索引,通过适当的缩放和钳位,从两个去量化表中查找六个因子。否则,使用帧级去量化因子(如第9.6节所述)。在这两种情况下,乘法都是使用16位有符号整数计算和存储的。

The two dequantization tables, which may also be found in the reference decoder file dequant_data.h (Section 20.3), are as follows.

也可在参考解码器文件dequant_data.h(第20.3节)中找到的两个去量化表如下所示。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   static const int dc_qlookup[QINDEX_RANGE] =
   {
       4,   5,   6,   7,   8,   9,  10,  10,   11,  12,  13,  14,  15,
      16,  17,  17,  18,  19,  20,  20,  21,   21,  22,  22,  23,  23,
      24,  25,  25,  26,  27,  28,  29,  30,   31,  32,  33,  34,  35,
      36,  37,  37,  38,  39,  40,  41,  42,   43,  44,  45,  46,  46,
      47,  48,  49,  50,  51,  52,  53,  54,   55,  56,  57,  58,  59,
      60,  61,  62,  63,  64,  65,  66,  67,   68,  69,  70,  71,  72,
      73,  74,  75,  76,  76,  77,  78,  79,   80,  81,  82,  83,  84,
      85,  86,  87,  88,  89,  91,  93,  95,   96,  98, 100, 101, 102,
      104, 106, 108, 110, 112, 114, 116, 118, 122, 124, 126, 128, 130,
      132, 134, 136, 138, 140, 143, 145, 148, 151, 154, 157,
   };
        
   static const int dc_qlookup[QINDEX_RANGE] =
   {
       4,   5,   6,   7,   8,   9,  10,  10,   11,  12,  13,  14,  15,
      16,  17,  17,  18,  19,  20,  20,  21,   21,  22,  22,  23,  23,
      24,  25,  25,  26,  27,  28,  29,  30,   31,  32,  33,  34,  35,
      36,  37,  37,  38,  39,  40,  41,  42,   43,  44,  45,  46,  46,
      47,  48,  49,  50,  51,  52,  53,  54,   55,  56,  57,  58,  59,
      60,  61,  62,  63,  64,  65,  66,  67,   68,  69,  70,  71,  72,
      73,  74,  75,  76,  76,  77,  78,  79,   80,  81,  82,  83,  84,
      85,  86,  87,  88,  89,  91,  93,  95,   96,  98, 100, 101, 102,
      104, 106, 108, 110, 112, 114, 116, 118, 122, 124, 126, 128, 130,
      132, 134, 136, 138, 140, 143, 145, 148, 151, 154, 157,
   };
        
   static const int ac_qlookup[QINDEX_RANGE] =
   {
       4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,  16,
      17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
      30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,
      43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,
      56,  57,  58,  60,  62,  64,  66,  68,  70,  72,  74,  76,  78,
      80,  82,  84,  86,  88,  90,  92,  94,  96,  98, 100, 102, 104,
     106, 108, 110, 112, 114, 116, 119, 122, 125, 128, 131, 134, 137,
     140, 143, 146, 149, 152, 155, 158, 161, 164, 167, 170, 173, 177,
     181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229,
     234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284,
   };
        
   static const int ac_qlookup[QINDEX_RANGE] =
   {
       4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,  16,
      17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
      30,  31,  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,
      43,  44,  45,  46,  47,  48,  49,  50,  51,  52,  53,  54,  55,
      56,  57,  58,  60,  62,  64,  66,  68,  70,  72,  74,  76,  78,
      80,  82,  84,  86,  88,  90,  92,  94,  96,  98, 100, 102, 104,
     106, 108, 110, 112, 114, 116, 119, 122, 125, 128, 131, 134, 137,
     140, 143, 146, 149, 152, 155, 158, 161, 164, 167, 170, 173, 177,
     181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229,
     234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284,
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Lookup values from the above two tables are directly used in the DC and AC coefficients in Y1, respectively. For Y2 and chroma, values from the above tables undergo either scaling or clamping before the multiplies. Details regarding these scaling and clamping processes can be found in related lookup functions in dixie.c (Section 20.4).

上述两个表中的查找值分别直接用于Y1中的DC和AC系数。对于Y2和色度,上表中的值在倍增之前进行缩放或钳制。有关这些缩放和夹紧过程的详细信息,请参见dixie.c(第20.4节)中的相关查找函数。

14.2. Inverse Transforms
14.2. 逆变换

If the Y2 residue block exists (i.e., the macroblock luma mode is not SPLITMV or B_PRED), it is inverted first (using the inverse WHT) and the element of the result at row i, column j is used as the 0th coefficient of the Y subblock at position (i, j), that is, the Y subblock whose index is (i * 4) + j. As discussed in Section 13, if the luma mode is B_PRED or SPLITMV, the 0th Y coefficients are part of the residue signal for the subblocks themselves.

如果Y2剩余块存在(即,宏块luma模式不是SPLITMV或B_PRED),则首先将其反转(使用逆WHT),并且第i行、第j列的结果元素用作位置(i,j)处Y子块的第0个系数,即索引为(i*4)+j的Y子块。如第13节中所讨论的,如果luma模式是B_PRED或SPLITMV,则第0y系数是子块本身的剩余信号的一部分。

In either case, the inverse transforms for the sixteen Y subblocks and eight chroma subblocks are computed next. All 24 of these inversions are independent of each other; their results may (at least conceptually) be stored in 24 separate 4x4 arrays.

在这两种情况下,接下来计算十六个Y子块和八个色度子块的逆变换。所有这24种反演都是相互独立的;其结果可能(至少在概念上)存储在24个单独的4x4阵列中。

As is done by the reference decoder, an implementation may wish to represent the prediction and residue buffers as macroblock-sized arrays (that is, a 16x16 Y buffer and two 8x8 chroma buffers). Regarding the inverse DCT implementation given below, this requires a simple adjustment to the address calculation for the resulting residue pixels.

如参考解码器所做的,实现可能希望将预测和剩余缓冲器表示为宏块大小的阵列(即,一个16x16y缓冲器和两个8x8色度缓冲器)。关于下面给出的逆DCT实现,这需要对结果剩余像素的地址计算进行简单调整。

14.3. Implementation of the WHT Inversion
14.3. WHT反演的实现

As previously discussed (see Sections 2 and 13), for macroblocks encoded using prediction modes other than B_PRED and SPLITMV, the DC values derived from the DCT transform on the 16 Y blocks are collected to construct a 25th block of a macroblock (16 Y, 4 U, 4 V constitute the 24 blocks). This 25th block is transformed using a Walsh-Hadamard transform (WHT).

如前所述(参见第2节和第13节),对于使用B_PRED和SPLITMV以外的预测模式编码的宏块,从16 Y块上的DCT变换导出的DC值被收集以构造宏块的第25块(16 Y,4 U,4 V构成24个块)。第25个块使用沃尔什-阿达玛变换(WHT)进行变换。

The inputs to the inverse WHT (that is, the dequantized coefficients), the intermediate "horizontally detransformed" signal, and the completely detransformed residue signal are all stored as arrays of 16-bit signed integers.

逆WHT(即,去量化系数)、中间“水平去变换”信号和完全去变换的剩余信号的输入都存储为16位有符号整数的阵列。

Following the tradition of specifying bitstream format using the decoding process, we specify the inverse WHT in the decoding process using the following C-style source code:

按照使用解码过程指定比特流格式的传统,我们使用以下C风格源代码在解码过程中指定逆WHT:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   void vp8_short_inv_walsh4x4_c(short *input, short *output)
   {
     int i;
     int a1, b1, c1, d1;
     int a2, b2, c2, d2;
     short *ip = input;
     short *op = output;
     int temp1, temp2;
        
   void vp8_short_inv_walsh4x4_c(short *input, short *output)
   {
     int i;
     int a1, b1, c1, d1;
     int a2, b2, c2, d2;
     short *ip = input;
     short *op = output;
     int temp1, temp2;
        
     for(i=0;i<4;i++)
     {
       a1 = ip[0] + ip[12];
       b1 = ip[4] + ip[8];
       c1 = ip[4] - ip[8];
       d1 = ip[0] - ip[12];
        
     for(i=0;i<4;i++)
     {
       a1 = ip[0] + ip[12];
       b1 = ip[4] + ip[8];
       c1 = ip[4] - ip[8];
       d1 = ip[0] - ip[12];
        
       op[0] = a1 + b1;
       op[4] = c1 + d1;
       op[8] = a1 - b1;
       op[12]= d1 - c1;
       ip++;
       op++;
     }
     ip = output;
     op = output;
     for(i=0;i<4;i++)
     {
       a1 = ip[0] + ip[3];
       b1 = ip[1] + ip[2];
       c1 = ip[1] - ip[2];
       d1 = ip[0] - ip[3];
        
       op[0] = a1 + b1;
       op[4] = c1 + d1;
       op[8] = a1 - b1;
       op[12]= d1 - c1;
       ip++;
       op++;
     }
     ip = output;
     op = output;
     for(i=0;i<4;i++)
     {
       a1 = ip[0] + ip[3];
       b1 = ip[1] + ip[2];
       c1 = ip[1] - ip[2];
       d1 = ip[0] - ip[3];
        
       a2 = a1 + b1;
       b2 = c1 + d1;
       c2 = a1 - b1;
       d2 = d1 - c1;
        
       a2 = a1 + b1;
       b2 = c1 + d1;
       c2 = a1 - b1;
       d2 = d1 - c1;
        
       op[0] = (a2+3)>>3;
       op[1] = (b2+3)>>3;
       op[2] = (c2+3)>>3;
       op[3] = (d2+3)>>3;
        
       op[0] = (a2+3)>>3;
       op[1] = (b2+3)>>3;
       op[2] = (c2+3)>>3;
       op[3] = (d2+3)>>3;
        
       ip+=4;
       op+=4;
     }
   }
        
       ip+=4;
       op+=4;
     }
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

In the case that there is only one non-zero DC value in input, the inverse transform can be simplified to the following:

在输入中只有一个非零DC值的情况下,逆变换可简化为:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   void vp8_short_inv_walsh4x4_1_c(short *input, short *output)
   {
     int i;
     int a1;
     short *op=output;
        
   void vp8_short_inv_walsh4x4_1_c(short *input, short *output)
   {
     int i;
     int a1;
     short *op=output;
        
     a1 = ((input[0] + 3)>>3);
        
     a1 = ((input[0] + 3)>>3);
        
     for(i=0;i<4;i++)
     {
       op[0] = a1;
       op[1] = a1;
       op[2] = a1;
       op[3] = a1;
       op+=4;
     }
   }
        
     for(i=0;i<4;i++)
     {
       op[0] = a1;
       op[1] = a1;
       op[2] = a1;
       op[3] = a1;
       op+=4;
     }
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

It should be noted that a conforming decoder should implement the inverse transform using exactly the same rounding to achieve bit-wise matching output to the output of the process specified by the above C source code.

应注意,一致性解码器应使用完全相同的舍入实现逆变换,以实现与上述C源代码指定的过程输出的逐位匹配输出。

The reference decoder WHT inversion may be found in the file idct_add.c (Section 20.8).

参考解码器WHT反转可在文件idct_add.c(第20.8节)中找到。

14.4. Implementation of the DCT Inversion
14.4. DCT逆变换的实现

All of the DCT inversions are computed in exactly the same way. In principle, VP8 uses a classical 2-D inverse discrete cosine transform, implemented as two passes of 1-D inverse DCT. The 1-D inverse DCT was calculated using a similar algorithm to what was described in [Loeffler]. However, the paper only provided the 8-point and 16-point version of the algorithms, which was adapted by On2 to perform the 4-point 1-D DCT.

所有DCT反演的计算方法都完全相同。原则上,VP8使用经典的二维离散余弦逆变换,实现为两次一维逆DCT。使用与[Loeffler]中描述的类似算法计算1-D逆DCT。然而,本文只提供了算法的8点和16点版本,On2对其进行了调整,以执行4点1-D DCT。

Accurate calculation of 1-D DCT of the above algorithm requires infinite precision. VP8 of course can use only a finite-precision approximation. Also, the inverse DCT used by VP8 takes care of normalization of the standard unitary transform; that is, every dequantized coefficient has roughly double the size of the corresponding unitary coefficient. However, at all but the highest datarates, the discrepancy between transmitted and ideal coefficients is due almost entirely to (lossy) compression and not to errors induced by finite-precision arithmetic.

上述算法的1-D DCT的精确计算需要无限的精度。VP8当然只能使用有限精度近似值。此外,VP8使用的逆DCT负责标准酉变换的归一化;也就是说,每个去量化系数的大小大约是相应的酉系数的两倍。然而,除了最高的数据速率外,传输系数和理想系数之间的差异几乎完全是由于(有损)压缩,而不是由有限精度算法引起的错误。

The inputs to the inverse DCT (that is, the dequantized coefficients), the intermediate "horizontally detransformed" signal, and the completely detransformed residue signal are all stored as arrays of 16-bit signed integers. The details of the computation are as follows.

逆DCT(即,去量化系数)、中间“水平去变换”信号和完全去变换的剩余信号的输入都存储为16位有符号整数的数组。计算的细节如下。

It should also be noted that this implementation makes use of the 16-bit fixed-point version of two multiplication constants:

还应注意,此实现使用两个乘法常数的16位定点版本:

   sqrt(2) * cos (pi/8)
        
   sqrt(2) * cos (pi/8)
        
   sqrt(2) * sin (pi/8)
        
   sqrt(2) * sin (pi/8)
        

Because the first constant is bigger than 1, to maintain the same 16-bit fixed-point precision as the second one, we make use of the fact that

由于第一个常数大于1,为了保持与第二个常数相同的16位定点精度,我们利用以下事实:

   x * a = x + x*(a-1)
        
   x * a = x + x*(a-1)
        

therefore

因此

   x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) * cos(pi/8)-1)
        
   x * sqrt(2) * cos (pi/8) = x + x * (sqrt(2) * cos(pi/8)-1)
        
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* IDCT implementation */
   static const int cospi8sqrt2minus1=20091;
   static const int sinpi8sqrt2      =35468;
   void short_idct4x4llm_c(short *input, short *output, int pitch)
   {
     int i;
     int a1, b1, c1, d1;
        
   /* IDCT implementation */
   static const int cospi8sqrt2minus1=20091;
   static const int sinpi8sqrt2      =35468;
   void short_idct4x4llm_c(short *input, short *output, int pitch)
   {
     int i;
     int a1, b1, c1, d1;
        
     short *ip=input;
     short *op=output;
     int temp1, temp2;
     int shortpitch = pitch>>1;
        
     short *ip=input;
     short *op=output;
     int temp1, temp2;
     int shortpitch = pitch>>1;
        
     for(i=0;i<4;i++)
     {
       a1 = ip[0]+ip[8];
       b1 = ip[0]-ip[8];
        
     for(i=0;i<4;i++)
     {
       a1 = ip[0]+ip[8];
       b1 = ip[0]-ip[8];
        
       temp1 = (ip[4] * sinpi8sqrt2)>>16;
       temp2 = ip[12]+((ip[12] * cospi8sqrt2minus1)>>16);
       c1 = temp1 - temp2;
        
       temp1 = (ip[4] * sinpi8sqrt2)>>16;
       temp2 = ip[12]+((ip[12] * cospi8sqrt2minus1)>>16);
       c1 = temp1 - temp2;
        
       temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1)>>16);
       temp2 = (ip[12] * sinpi8sqrt2)>>16;
       d1 = temp1 + temp2;
        
       temp1 = ip[4] + ((ip[4] * cospi8sqrt2minus1)>>16);
       temp2 = (ip[12] * sinpi8sqrt2)>>16;
       d1 = temp1 + temp2;
        
       op[shortpitch*0] = a1+d1;
       op[shortpitch*3] = a1-d1;
       op[shortpitch*1] = b1+c1;
       op[shortpitch*2] = b1-c1;
        
       op[shortpitch*0] = a1+d1;
       op[shortpitch*3] = a1-d1;
       op[shortpitch*1] = b1+c1;
       op[shortpitch*2] = b1-c1;
        
       ip++;
       op++;
     }
     ip = output;
     op = output;
     for(i=0;i<4;i++)
     {
       a1 = ip[0]+ip[2];
       b1 = ip[0]-ip[2];
        
       ip++;
       op++;
     }
     ip = output;
     op = output;
     for(i=0;i<4;i++)
     {
       a1 = ip[0]+ip[2];
       b1 = ip[0]-ip[2];
        
       temp1 = (ip[1] * sinpi8sqrt2)>>16;
       temp2 = ip[3]+((ip[3] * cospi8sqrt2minus1)>>16);
       c1 = temp1 - temp2;
        
       temp1 = (ip[1] * sinpi8sqrt2)>>16;
       temp2 = ip[3]+((ip[3] * cospi8sqrt2minus1)>>16);
       c1 = temp1 - temp2;
        
       temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1)>>16);
        
       temp1 = ip[1] + ((ip[1] * cospi8sqrt2minus1)>>16);
        
       temp2 = (ip[3] * sinpi8sqrt2)>>16;
       d1 = temp1 + temp2;
        
       temp2 = (ip[3] * sinpi8sqrt2)>>16;
       d1 = temp1 + temp2;
        
       op[0] = (a1+d1+4)>>3;
       op[3] = (a1-d1+4)>>3;
       op[1] = (b1+c1+4)>>3;
       op[2] = (b1-c1+4)>>3;
        
       op[0] = (a1+d1+4)>>3;
       op[3] = (a1-d1+4)>>3;
       op[1] = (b1+c1+4)>>3;
       op[2] = (b1-c1+4)>>3;
        
       ip+=shortpitch;
       op+=shortpitch;
     }
   }
        
       ip+=shortpitch;
       op+=shortpitch;
     }
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The reference decoder DCT inversion may be found in the file idct_add.c (Section 20.8).

参考解码器DCT反转可在文件idct_add.c(第20.8节)中找到。

14.5. Summation of Predictor and Residue
14.5. 预测器与残差之和

Finally, the prediction and residue signals are summed to form the reconstructed macroblock, which, except for loop filtering (taken up next), completes the decoding process.

最后,将预测信号和残差信号相加,形成重构宏块,除循环滤波(下一步)外,完成解码过程。

The summing procedure is fairly straightforward, having only a couple of details. The prediction and residue buffers are both arrays of 16-bit signed integers. Each individual (Y, U, and V pixel) result is calculated first as a 32-bit sum of the prediction and residue, and is then saturated to 8-bit unsigned range (using, say, the clamp255 function defined above) before being stored as an 8-bit unsigned pixel value.

求和过程相当简单,只有几个细节。预测和剩余缓冲区都是16位有符号整数的数组。每个单独的(Y、U和V像素)结果首先作为预测和残差的32位和进行计算,然后在存储为8位无符号像素值之前,饱和到8位无符号范围(例如,使用上面定义的clamp255函数)。

VP8 also supports a mode where the encoding of a bitstream guarantees all reconstructed pixel values between 0 and 255; compliant bitstreams of such requirements have the clamp_type bit in the frame header set to 1. In such a case, the clamp255 function is no longer required.

VP8还支持一种模式,其中比特流的编码保证所有重建像素值在0到255之间;此类要求的兼容比特流将帧头中的clamp_类型比特设置为1。在这种情况下,不再需要clamp255功能。

The summation process is the same, regardless of the (intra or inter) mode of prediction in effect for the macroblock. The reference decoder implementation of reconstruction may be found in the file idct_add.c.

求和过程是相同的,而与宏块的有效预测模式(帧内或帧间)无关。重构的参考解码器实现可以在文件idct_add.c中找到。

15. Loop Filter
15. 环路滤波器

Loop filtering is the last stage of frame reconstruction and the next-to-last stage of the decoding process. The loop filter is applied to the entire frame after the summation of predictor and residue signals, as described in Section 14.

环路滤波是帧重建的最后一个阶段,也是解码过程的下一个到最后一个阶段。如第14节所述,在预测器信号和剩余信号求和之后,将环路滤波器应用于整个帧。

The purpose of the loop filter is to eliminate (or at least reduce) visually objectionable artifacts associated with the semi-independence of the coding of macroblocks and their constituent subblocks.

环路滤波器的目的是消除(或至少减少)与宏块及其组成子块的编码的半独立性相关联的视觉上令人不快的伪影。

As was discussed in Section 5, the loop filter is "integral" to decoding, in that the results of loop filtering are used in the prediction of subsequent frames. Consequently, a functional decoder implementation must perform loop filtering exactly as described here. This is distinct from any postprocessing that may be applied only to the image immediately before display; such postprocessing is entirely at the option of the implementor (and/or user) and has no effect on decoding per se.

如第5节所述,环路滤波器与解码是“积分”的,因为环路滤波的结果用于后续帧的预测。因此,功能解码器实现必须完全按照此处所述执行循环滤波。这不同于仅在显示之前应用于图像的任何后处理;这种后处理完全由实现者(和/或用户)选择,对解码本身没有影响。

The baseline frame-level parameters controlling the loop filter are defined in the frame header (Section 9.4) along with a mechanism for adjustment based on a macroblock's prediction mode and/or reference frame. The first is a flag (filter_type) selecting the type of filter (normal or simple); the other two are numbers (loop_filter_level and sharpness_level) that adjust the strength or sensitivity of the filter. As described in Sections 9.3 and 10, loop_filter_level may also be overridden on a per-macroblock basis using segmentation.

控制环路滤波器的基线帧级参数在帧头(第9.4节)中定义,以及基于宏块的预测模式和/或参考帧的调整机制。第一个是选择过滤器类型(普通或简单)的标志(过滤器类型);另外两个是数字(环路滤波器电平和锐度电平),用于调整滤波器的强度或灵敏度。如第9.3节和第10节所述,还可以使用分段在每个宏块的基础上覆盖循环过滤器级别。

Loop filtering is one of the more computationally intensive aspects of VP8 decoding. This is the reason for the existence of the optional, less-demanding simple filter type.

环路滤波是VP8解码的计算密集型方面之一。这就是存在可选、要求较低的简单过滤器类型的原因。

Note carefully that loop filtering must be skipped entirely if loop_filter_level at either the frame header level or macroblock override level is 0. In no case should the loop filter be run with a value of 0; it should instead be skipped.

请注意,如果帧头级别或宏块覆盖级别的循环过滤器级别为0,则必须完全跳过循环过滤。在任何情况下,循环过滤器的运行值均不得为0;应该跳过它。

We begin by discussing the aspects of loop filtering that are independent of the controlling parameters and type of filter chosen.

我们首先讨论环路滤波的各个方面,这些方面与所选择的控制参数和滤波器类型无关。

15.1. Filter Geometry and Overall Procedure
15.1. 过滤器几何结构和总体程序

The Y, U, and V planes are processed independently and identically.

Y、U和V平面分别进行相同的处理。

The loop filter acts on the edges between adjacent macroblocks and on the edges between adjacent subblocks of a macroblock. All such edges are horizontal or vertical. For each pixel position on an edge, a small number (two or three) of pixels adjacent to either side of the position are examined and possibly modified. The displacements of these pixels are at a right angle to the edge orientation; that is, for a horizontal edge, we treat the pixels immediately above and below the edge position, and for a vertical edge, we treat the pixels immediately to the left and right of the edge.

循环滤波器作用于相邻宏块之间的边缘和宏块的相邻子块之间的边缘。所有这些边缘都是水平或垂直的。对于边缘上的每个像素位置,检查并可能修改与该位置任一侧相邻的少量(两个或三个)像素。这些像素的位移与边缘方向成直角;也就是说,对于水平边缘,我们处理边缘位置正上方和正下方的像素,对于垂直边缘,我们处理边缘左右两侧的像素。

We call this collection of pixels associated to an edge position a segment; the length of a segment is 2, 4, 6, or 8. Excepting that the normal filter uses slightly different algorithms for, and either filter may apply different control parameters to, the edges between macroblocks and those between subblocks, the treatment of edges is quite uniform: All segments straddling an edge are treated identically; there is no distinction between the treatment of horizontal and vertical edges, whether between macroblocks or between subblocks.

我们将与边缘位置相关联的像素集合称为一段;线段的长度为2、4、6或8。除了普通滤波器对宏块之间的边和子块之间的边使用略微不同的算法,并且任一滤波器可以对宏块之间的边和子块之间的边应用不同的控制参数外,对边的处理是相当一致的:横跨边的所有段都被相同地处理;无论是宏块之间还是子块之间,水平边缘和垂直边缘的处理都没有区别。

As a consequence, adjacent subblock edges within a macroblock may be concatenated and processed in their entirety. There is a single 8-pixel-long vertical edge horizontally centered in each of the U and V blocks (the concatenation of upper and lower 4-pixel edges between chroma subblocks), and three 16-pixel-long vertical edges at horizontal positions 1/4, 1/2, and 3/4 the width of the luma macroblock, each representing the concatenation of four 4-pixel sub-edges between pairs of Y subblocks.

结果,宏块内的相邻子块边缘可以全部连接和处理。在每个U和V块中水平居中有一个8像素长的垂直边(色度子块之间的上下4像素边的串联),在亮度宏块宽度的水平位置1/4、1/2和3/4处有三个16像素长的垂直边,每个表示Y子块对之间四个4像素子边的串联。

The macroblocks comprising the frame are processed in the usual raster-scan order. Each macroblock is "responsible for" the inter-macroblock edges immediately above and to the left of it (but not the edges below and to the right of it), as well as the edges between its subblocks.

构成帧的宏块按照通常的光栅扫描顺序进行处理。每个宏块“负责”其正上方和左侧的宏块间边缘(但不负责其下方和右侧的边缘),以及其子块之间的边缘。

For each macroblock M, there are four filtering steps, which are, (almost) in order:

对于每个宏块M,有四个过滤步骤,其顺序为(几乎):

1. If M is not on the leftmost column of macroblocks, filter across the left (vertical) inter-macroblock edge of M.

1. 如果M不在宏块的最左侧列上,则在M的左侧(垂直)宏块间边缘进行过滤。

2. Filter across the vertical subblock edges within M.

2. 过滤M内的垂直子块边缘。

3. If M is not on the topmost row of macroblocks, filter across the top (horizontal) inter-macroblock edge of M.

3. 如果M不在宏块的最顶层行,则在M的顶部(水平)宏块间边缘进行过滤。

4. Filter across the horizontal subblock edges within M.

4. 过滤M内的水平子块边缘。

We write MY, MU, and MV for the planar constituents of M, that is, the 16x16 luma block, 8x8 U block, and 8x8 V block comprising M.

我们为M的平面成分编写MY、MU和MV,即16x16 luma块、8x8 U块和包含M的8x8 V块。

In step 1, for each of the three blocks MY, MU, and MV, we filter each of the (16 luma or 8 chroma) segments straddling the column separating the block from the block immediately to the left of it, using the inter-macroblock filter and controls associated to the loop_filter_level and sharpness_level.

在步骤1中,对于三个块MY、MU和MV中的每一个,我们使用宏块间过滤器和与loop_filter_level和sharpness_level相关联的控件,过滤横跨将块与其左侧块分离的列的每个(16 luma或8色度)段。

In step 4, we filter across the (three luma and one each for U and V) vertical subblock edges described above, this time using the inter-subblock filter and controls.

在步骤4中,我们过滤上述垂直子块边缘(三个luma,每个luma用于U和V),这次使用子块间过滤器和控件。

Steps 2 and 4 are skipped for macroblocks that satisfy both of the following two conditions:

对于同时满足以下两个条件的宏块,跳过步骤2和4:

1. Macroblock coding mode is neither B_PRED nor SPLITMV; and

1. 宏块编码模式既不是B_PRED也不是SPLITMV;和

2. There is no DCT coefficient coded for the whole macroblock.

2. 整个宏块没有DCT系数编码。

For these macroblocks, loop filtering for edges between subblocks internal to a macroblock is effectively skipped. This skip strategy significantly reduces VP8 loop-filtering complexity.

对于这些宏块,有效地跳过宏块内部子块之间的边的循环过滤。这种跳过策略显著降低了VP8循环过滤的复杂性。

Edges between macroblocks and those between subblocks are treated with different control parameters (and, in the case of the normal filter, with different algorithms). Except for pixel addressing, there is no distinction between the treatment of vertical and horizontal edges. Luma edges are always 16 pixels long, chroma edges are always 8 pixels long, and the segments straddling an edge are treated identically; this of course facilitates vector processing.

宏块之间的边缘和子块之间的边缘用不同的控制参数处理(在普通滤波器的情况下,用不同的算法处理)。除了像素寻址,垂直和水平边缘的处理没有区别。亮度边缘始终为16像素长,色度边缘始终为8像素长,跨边的线段处理相同;这当然有助于向量处理。

Because many pixels belong to segments straddling two or more edges, and so will be filtered more than once, the order in which edges are processed given above must be respected by any implementation. Within a single edge, however, the segments straddling that edge are disjoint, and the order in which these segments are processed is immaterial.

由于许多像素属于跨越两条或多条边的线段,因此将被多次过滤,因此任何实现都必须遵守上面给出的边处理顺序。但是,在一条边内,跨越该边的线段是不相交的,处理这些线段的顺序无关紧要。

Before taking up the filtering algorithms themselves, we should emphasize a point already made: Even though the pixel segments associated to a macroblock are antecedent to the macroblock (that is, lie within the macroblock or in already-constructed macroblocks), a

在讨论过滤算法本身之前,我们应该强调已经提出的一点:即使与宏块相关联的像素段在宏块之前(即,位于宏块内或在已经构造的宏块中),但是

macroblock must not be filtered immediately after its "reconstruction" (described in Section 14). Rather, the loop filter applies after all the macroblocks have been "reconstructed" (i.e., had their predictor summed with their residue); correct decoding is predicated on the fact that already-constructed portions of the current frame referenced via intra-prediction (described in Section 12) are not yet filtered.

宏块“重建”后不得立即过滤(如第14节所述)。相反,在所有宏块都已“重建”(即,将其预测器与其余数求和)之后应用循环滤波器;正确解码的前提是,通过帧内预测(在第12节中描述)引用的当前帧的已经构造的部分尚未被过滤。

15.2. Simple Filter
15.2. 简单过滤器

Having described the overall procedure of, and pixels affected by, the loop filter, we turn our attention to the treatment of individual segments straddling edges. We begin by describing the simple filter, which, as the reader might guess, is somewhat simpler than the normal filter.

在描述了环路滤波器的整体过程和受其影响的像素之后,我们将注意力转向处理跨越边缘的各个分段。我们首先描述简单过滤器,正如读者可能猜测的那样,它比普通过滤器稍微简单一些。

Note that the simple filter only applies to luma edges. Chroma edges are left unfiltered.

请注意,简单过滤器仅适用于luma边。色度边缘未经过滤。

Roughly speaking, the idea of loop filtering is, within limits, to reduce the difference between pixels straddling an edge. Differences in excess of a threshold (associated to the loop_filter_level) are assumed to be "natural" and are unmodified; differences below the threshold are assumed to be artifacts of quantization and the (partially) separate coding of blocks, and are reduced via the procedures described below. While the loop_filter_level is in principle arbitrary, the levels chosen by a VP8 compressor tend to be correlated to quantizer levels.

粗略地说,循环过滤的思想是在一定范围内减少跨越边缘的像素之间的差异。超过阈值的差异(与环路滤波器电平相关)被认为是“自然”的且未经修改;低于阈值的差异被假定为量化的伪影和块的(部分)单独编码,并且通过下面描述的过程被减少。虽然环路滤波器电平原则上是任意的,但VP8压缩器选择的电平往往与量化器电平相关。

Most of the filtering arithmetic is done using 8-bit signed operands (having a range of -128 to +127, inclusive), supplemented by 16-bit temporaries holding results of multiplies.

大多数滤波算法都是使用8位有符号操作数(范围为-128到+127,包括-128到+127)完成的,并辅之以保存乘法结果的16位临时操作数。

Sums and other temporaries need to be "clamped" to a valid signed 8-bit range:

总和和其他临时值需要“钳制”到有效的有符号8位范围:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   int8 c(int v)
   {
       return (int8) (v < -128 ? -128 : (v < 128 ? v : 127));
   }
        
   int8 c(int v)
   {
       return (int8) (v < -128 ? -128 : (v < 128 ? v : 127));
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Since pixel values themselves are unsigned 8-bit numbers, we need to convert between signed and unsigned values:

由于像素值本身是无符号8位数字,我们需要在有符号值和无符号值之间进行转换:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* Convert pixel value (0 <= v <= 255) to an 8-bit signed
      number. */
   int8 u2s(Pixel v) { return (int8) (v - 128);}
        
   /* Convert pixel value (0 <= v <= 255) to an 8-bit signed
      number. */
   int8 u2s(Pixel v) { return (int8) (v - 128);}
        
   /* Clamp, then convert signed number back to pixel value. */
   Pixel s2u(int v) { return (Pixel) (c(v) + 128);}
        
   /* Clamp, then convert signed number back to pixel value. */
   Pixel s2u(int v) { return (Pixel) (c(v) + 128);}
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Filtering is often predicated on absolute-value thresholds. The following function is the equivalent of the standard library function abs, whose prototype is found in the standard header file stdlib.h. For us, the argument v is always the difference between two pixels and lies in the range -255 <= v <= +255.

过滤通常基于绝对值阈值。以下函数相当于标准库函数abs,其原型可在标准头文件stdlib.h中找到。对于我们来说,参数v始终是两个像素之间的差值,并且位于-255<=v<=255的范围内。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   int abs(int v) { return v < 0?  -v : v;}
        
   int abs(int v) { return v < 0?  -v : v;}
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

An actual implementation would of course use inline functions or macros to accomplish these trivial procedures (which are used by both the normal and simple loop filters). An optimal implementation would probably express them in machine language, perhaps using single instruction, multiple data (SIMD) vector instructions. On many SIMD processors, the saturation accomplished by the above clamping function is often folded into the arithmetic instructions themselves, obviating the explicit step taken here.

实际的实现当然会使用内联函数或宏来完成这些琐碎的过程(普通循环过滤器和简单循环过滤器都使用这些过程)。一个最佳的实现可能会用机器语言来表达它们,可能会使用单指令多数据(SIMD)向量指令。在许多SIMD处理器上,通过上述箝位函数实现的饱和通常被折叠到算术指令本身中,从而避免了此处采取的显式步骤。

To simplify the specification of relative pixel positions, we use the word "before" to mean "immediately above" (for a vertical segment straddling a horizontal edge) or "immediately to the left of" (for a horizontal segment straddling a vertical edge), and the word "after" to mean "immediately below" or "immediately to the right of".

为了简化对相对像素位置的说明,我们使用“before”一词表示“紧上方”(对于横跨水平边缘的垂直段)或“紧靠左侧”(对于横跨垂直边缘的水平段),使用“after”一词表示“紧靠下方”或“紧靠右侧”。

Given an edge, a segment, and a limit value, the simple loop filter computes a value based on the four pixels that straddle the edge (two either side). If that value is below a supplied limit, then, very roughly speaking, the two pixel values are brought closer to each other, "shaving off" something like a quarter of the difference. The

给定一条边、一个段和一个限制值,简单循环过滤器将基于横跨该边的四个像素(两边各两个)计算一个值。如果该值低于提供的限制,那么,非常粗略地说,这两个像素值彼此更接近,“去除”大约四分之一的差异。这个

same procedure is used for all segments straddling any type of edge, regardless of the nature (inter-macroblock, inter-subblock, luma, or chroma) of the edge; only the limit value depends on the edge type.

对于跨越任何类型边缘的所有段,无论边缘的性质(宏块间、子块间、亮度或色度)如何,都使用相同的程序;仅限值取决于边类型。

The exact procedure (for a single segment) is as follows; the subroutine common_adjust is used by both the simple filter presented here and the normal filters discussed in Section 15.3.

具体程序(针对单个管段)如下所示:;这里介绍的简单滤波器和第15.3节讨论的普通滤波器都使用了子程序common_adjust。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   int8 common_adjust(
       int use_outer_taps,   /* filter is 2 or 4 taps wide */
       const Pixel *P1,    /* pixel before P0 */
       Pixel *P0,          /* pixel before edge */
       Pixel *Q0,          /* pixel after edge */
       const Pixel *Q1     /* pixel after Q0 */
   ) {
       cint8 p1 = u2s(*P1);   /* retrieve and convert all 4 pixels */
       cint8 p0 = u2s(*P0);
       cint8 q0 = u2s(*Q0);
       cint8 q1 = u2s(*Q1);
        
   int8 common_adjust(
       int use_outer_taps,   /* filter is 2 or 4 taps wide */
       const Pixel *P1,    /* pixel before P0 */
       Pixel *P0,          /* pixel before edge */
       Pixel *Q0,          /* pixel after edge */
       const Pixel *Q1     /* pixel after Q0 */
   ) {
       cint8 p1 = u2s(*P1);   /* retrieve and convert all 4 pixels */
       cint8 p0 = u2s(*P0);
       cint8 q0 = u2s(*Q0);
       cint8 q1 = u2s(*Q1);
        
       /* Disregarding clamping, when "use_outer_taps" is false,
          "a" is 3*(q0-p0).  Since we are about to divide "a" by
          8, in this case we end up multiplying the edge
          difference by 5/8.
        
       /* Disregarding clamping, when "use_outer_taps" is false,
          "a" is 3*(q0-p0).  Since we are about to divide "a" by
          8, in this case we end up multiplying the edge
          difference by 5/8.
        
          When "use_outer_taps" is true (as for the simple filter),
          "a" is p1 - 3*p0 + 3*q0 - q1, which can be thought of as
          a refinement of 2*(q0 - p0), and the adjustment is
          something like (q0 - p0)/4. */
        
          When "use_outer_taps" is true (as for the simple filter),
          "a" is p1 - 3*p0 + 3*q0 - q1, which can be thought of as
          a refinement of 2*(q0 - p0), and the adjustment is
          something like (q0 - p0)/4. */
        
       int8 a = c((use_outer_taps? c(p1 - q1) : 0) + 3*(q0 - p0));
        
       int8 a = c((use_outer_taps? c(p1 - q1) : 0) + 3*(q0 - p0));
        
       /* b is used to balance the rounding of a/8 in the case where
          the "fractional" part "f" of a/8 is exactly 1/2. */
        
       /* b is used to balance the rounding of a/8 in the case where
          the "fractional" part "f" of a/8 is exactly 1/2. */
        
       cint8 b = (c(a + 3)) >> 3;
        
       cint8 b = (c(a + 3)) >> 3;
        
       /* Divide a by 8, rounding up when f >= 1/2.
          Although not strictly part of the C language,
          the right shift is assumed to propagate the sign bit. */
        
       /* Divide a by 8, rounding up when f >= 1/2.
          Although not strictly part of the C language,
          the right shift is assumed to propagate the sign bit. */
        
       a = c(a + 4) >> 3;
        
       a = c(a + 4) >> 3;
        
       /* Subtract "a" from q0, "bringing it closer" to p0. */
        
       /* Subtract "a" from q0, "bringing it closer" to p0. */
        
       *Q0 = s2u(q0 - a);
        
       *Q0 = s2u(q0 - a);
        
       /* Add "a" (with adjustment "b") to p0, "bringing it closer"
          to q0.
        
       /* Add "a" (with adjustment "b") to p0, "bringing it closer"
          to q0.
        
          The clamp of "a+b", while present in the reference decoder,
          is superfluous; we have -16 <= a <= 15 at this point. */
        
          The clamp of "a+b", while present in the reference decoder,
          is superfluous; we have -16 <= a <= 15 at this point. */
        
       *P0 = s2u(p0 + b);
        
       *P0 = s2u(p0 + b);
        
       return a;
   }
        
       return a;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   void simple_segment(
       uint8 edge_limit,   /* do nothing if edge difference
                              exceeds limit */
       const Pixel *P1,    /* pixel before P0 */
       Pixel *P0,          /* pixel before edge */
       Pixel *Q0,          /* pixel after edge */
       const Pixel *Q1     /* pixel after Q0 */
   ) {
       if ((abs(*P0 - *Q0)*2 + abs(*P1 - *Q1)/2) <= edge_limit))
           common_adjust(1, P1, P0, Q0, Q1);   /* use outer taps */
   }
        
   void simple_segment(
       uint8 edge_limit,   /* do nothing if edge difference
                              exceeds limit */
       const Pixel *P1,    /* pixel before P0 */
       Pixel *P0,          /* pixel before edge */
       Pixel *Q0,          /* pixel after edge */
       const Pixel *Q1     /* pixel after Q0 */
   ) {
       if ((abs(*P0 - *Q0)*2 + abs(*P1 - *Q1)/2) <= edge_limit))
           common_adjust(1, P1, P0, Q0, Q1);   /* use outer taps */
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

We make a couple of remarks about the rounding procedure above. When b is zero (that is, when the "fractional part" of a is not 1/2), we are (except for clamping) adding the same number to p0 as we are subtracting from q0. This preserves the average value of p0 and q0, but the resulting difference between p0 and q0 is always even; in particular, the smallest non-zero gradation +-1 is not possible here.

我们对上述四舍五入程序作几点评论。当b为零时(即,当a的“分数部分”不是1/2时),我们(除了钳位)向p0添加的数字与从q0中减去的数字相同。这保留了p0和q0的平均值,但由此产生的p0和q0之间的差异始终是均匀的;特别是,此处不可能出现最小的非零灰度+-1。

When b is one, the value we add to p0 (again except for clamping) is one less than the value we are subtracting from q0. In this case, the resulting difference is always odd (and the small gradation +-1 is possible), but the average value is reduced by 1/2, yielding, for instance, a very slight darkening in the luma plane. (In the very unlikely event of appreciable darkening after a large number of interframes, a compressor would of course eventually compensate for this in the selection of predictor and/or residue.)

当b为1时,我们加在p0上的值(同样,除了箝位)比我们从q0中减去的值小1。在这种情况下,产生的差异总是奇数(并且小灰度+-1是可能的),但是平均值减少1/2,例如,在亮度平面中产生非常轻微的变暗。(在大量帧后出现明显变暗的极不可能的情况下,压缩机当然最终会在预测器和/或残差的选择中对此进行补偿。)

The derivation of the edge_limit value used above, which depends on the loop_filter_level and sharpness_level, as well as the type of edge being processed, will be taken up after we describe the normal loop filtering algorithm below.

在我们描述了下面的正常循环滤波算法后,将开始推导上面使用的边缘极限值,该极限值取决于循环滤波水平和锐度水平,以及正在处理的边缘类型。

15.3. Normal Filter
15.3. 普通滤波器

The normal loop filter is a refinement of the simple loop filter; all of the general discussion above applies here as well. In particular, the functions c, u2s, s2u, abs, and common_adjust are used by both the normal and simple filters.

普通环路滤波器是简单环路滤波器的改进;上面所有的一般性讨论也适用于这里。特别是,普通和简单滤波器都使用功能c、u2s、s2u、abs和common_adjust。

As mentioned above, the normal algorithms for inter-macroblock and inter-subblock edges differ. Nonetheless, they have a great deal in common: They use similar threshold algorithms to disable the filter and to detect high internal edge variance (which influences the filtering algorithm). Both algorithms also use, at least conditionally, the simple filter adjustment procedure described above.

如上所述,宏块间和子块间边缘的常规算法不同。尽管如此,它们有很多共同点:它们使用类似的阈值算法来禁用过滤器并检测较高的内部边缘方差(这会影响过滤算法)。这两种算法还至少有条件地使用上述简单的滤波器调整程序。

The common thresholding algorithms are as follows.

常用的阈值算法如下所示。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* All functions take (among other things) a segment (of length
      at most 4 + 4 = 8) symmetrically straddling an edge.
        
   /* All functions take (among other things) a segment (of length
      at most 4 + 4 = 8) symmetrically straddling an edge.
        
      The pixel values (or pointers) are always given in order,
      from the "beforemost" to the "aftermost".  So, for a
      horizontal edge (written "|"), an 8-pixel segment would be
      ordered p3 p2 p1 p0 | q0 q1 q2 q3. */
        
      The pixel values (or pointers) are always given in order,
      from the "beforemost" to the "aftermost".  So, for a
      horizontal edge (written "|"), an 8-pixel segment would be
      ordered p3 p2 p1 p0 | q0 q1 q2 q3. */
        
   /* Filtering is disabled if the difference between any two
      adjacent "interior" pixels in the 8-pixel segment exceeds
      the relevant threshold (I).  A more complex thresholding
      calculation is done for the group of four pixels that
      straddle the edge, in line with the calculation in
      simple_segment() above. */
        
   /* Filtering is disabled if the difference between any two
      adjacent "interior" pixels in the 8-pixel segment exceeds
      the relevant threshold (I).  A more complex thresholding
      calculation is done for the group of four pixels that
      straddle the edge, in line with the calculation in
      simple_segment() above. */
        
   int filter_yes(
       uint8 I,        /* limit on interior differences */
       uint8 E,        /* limit at the edge */
        
   int filter_yes(
       uint8 I,        /* limit on interior differences */
       uint8 E,        /* limit at the edge */
        
       cint8 p3, cint8 p2, cint8 p1, cint8 p0, /* pixels before
                                                  edge */
       cint8 q0, cint8 q1, cint8 q2, cint8 q3  /* pixels after
                                                  edge */
   ) {
       return  (abs(p0 - q0)*2 + abs(p1 - q1)/2) <= E
           &&  abs(p3 - p2) <= I  &&  abs(p2 - p1) <= I  &&
             abs(p1 - p0) <= I
           &&  abs(q3 - q2) <= I  &&  abs(q2 - q1) <= I  &&
             abs(q1 - q0) <= I;
   }
        
       cint8 p3, cint8 p2, cint8 p1, cint8 p0, /* pixels before
                                                  edge */
       cint8 q0, cint8 q1, cint8 q2, cint8 q3  /* pixels after
                                                  edge */
   ) {
       return  (abs(p0 - q0)*2 + abs(p1 - q1)/2) <= E
           &&  abs(p3 - p2) <= I  &&  abs(p2 - p1) <= I  &&
             abs(p1 - p0) <= I
           &&  abs(q3 - q2) <= I  &&  abs(q2 - q1) <= I  &&
             abs(q1 - q0) <= I;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* Filtering is altered if (at least) one of the differences
      on either side of the edge exceeds a threshold (we have
      "high edge variance"). */
        
   /* Filtering is altered if (at least) one of the differences
      on either side of the edge exceeds a threshold (we have
      "high edge variance"). */
        
   int hev(
       uint8 threshold,
       cint8 p1, cint8 p0, /* pixels before edge */
       cint8 q0, cint8 q1  /* pixels after edge */
   ) {
       return abs(p1 - p0) > threshold  ||  abs(q1 - q0) > threshold;
   }
        
   int hev(
       uint8 threshold,
       cint8 p1, cint8 p0, /* pixels before edge */
       cint8 q0, cint8 q1  /* pixels after edge */
   ) {
       return abs(p1 - p0) > threshold  ||  abs(q1 - q0) > threshold;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The subblock filter is a variant of the simple filter. In fact, if we have high edge variance, the adjustment is exactly as for the simple filter. Otherwise, the simple adjustment (without outer taps) is applied, and the two pixels one step in from the edge pixels are adjusted by roughly half the amount by which the two edge pixels are adjusted; since the edge adjustment here is essentially 3/8 the edge difference, the inner adjustment is approximately 3/16 the edge difference.

子块过滤器是简单过滤器的一种变体。事实上,如果我们有很高的边缘方差,调整是完全一样的简单过滤器。否则,应用简单调整(无外部抽头),并且从边缘像素一步进的两个像素被调整大约两个边缘像素被调整的量的一半;因为这里的边缘调整基本上是边缘差的3/8,所以内部调整大约是边缘差的3/16。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   void subblock_filter(
       uint8 hev_threshold,     /* detect high edge variance */
       uint8 interior_limit,    /* possibly disable filter */
       uint8 edge_limit,
       cint8 *P3, cint8 *P2, int8 *P1, int8 *P0,   /* pixels before
                                                      edge */
       int8 *Q0, int8 *Q1, cint8 *Q2, cint8 *Q3    /* pixels after
                                                      edge */
   ) {
       cint8 p3 = u2s(*P3), p2 = u2s(*P2), p1 = u2s(*P1),
         p0 = u2s(*P0);
       cint8 q0 = u2s(*Q0), q1 = u2s(*Q1), q2 = u2s(*Q2),
         q3 = u2s(*Q3);
        
   void subblock_filter(
       uint8 hev_threshold,     /* detect high edge variance */
       uint8 interior_limit,    /* possibly disable filter */
       uint8 edge_limit,
       cint8 *P3, cint8 *P2, int8 *P1, int8 *P0,   /* pixels before
                                                      edge */
       int8 *Q0, int8 *Q1, cint8 *Q2, cint8 *Q3    /* pixels after
                                                      edge */
   ) {
       cint8 p3 = u2s(*P3), p2 = u2s(*P2), p1 = u2s(*P1),
         p0 = u2s(*P0);
       cint8 q0 = u2s(*Q0), q1 = u2s(*Q1), q2 = u2s(*Q2),
         q3 = u2s(*Q3);
        
       if (filter_yes(interior_limit, edge_limit, q3, q2, q1, q0,
         p0, p1, p2, p3))
       {
           const int hv = hev(hev_threshold, p1, p0, q0, q1);
        
       if (filter_yes(interior_limit, edge_limit, q3, q2, q1, q0,
         p0, p1, p2, p3))
       {
           const int hv = hev(hev_threshold, p1, p0, q0, q1);
        
           cint8 a = (common_adjust(hv, P1, P0, Q0, Q1) + 1) >> 1;
        
           cint8 a = (common_adjust(hv, P1, P0, Q0, Q1) + 1) >> 1;
        
           if (!hv) {
               *Q1 = s2u(q1 - a);
               *P1 = s2u(p1 + a);
           }
       }
   }
        
           if (!hv) {
               *Q1 = s2u(q1 - a);
               *P1 = s2u(p1 + a);
           }
       }
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The inter-macroblock filter has potentially wider scope. If the edge variance is high, it performs the simple adjustment (using the outer taps, just like the simple filter and the corresponding case of the normal subblock filter). If the edge variance is low, we begin with the same basic filter calculation and apply multiples of it to pixel pairs symmetric about the edge; the magnitude of adjustment decays as we move away from the edge and six of the pixels in the segment are affected.

宏块间滤波器具有潜在的更大范围。如果边缘方差较高,则执行简单调整(使用外部抽头,就像简单滤波器和正常子块滤波器的相应情况一样)。如果边缘方差较低,我们从相同的基本滤波器计算开始,并将其倍数应用于边缘对称的像素对;当我们离开边缘时,调整的幅度会衰减,并且段中的六个像素会受到影响。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   void MBfilter(
       uint8 hev_threshold,     /* detect high edge variance */
       uint8 interior_limit,    /* possibly disable filter */
       uint8 edge_limit,
       cint8 *P3, int8 *P2, int8 *P1, int8 *P0,  /* pixels before
                                                    edge */
       int8 *Q0, int8 *Q1, int8 *Q2, cint8 *Q3   /* pixels after
                                                    edge */
   ) {
       cint8 p3 = u2s(*P3), p2 = u2s(*P2), p1 = u2s(*P1),
         p0 = u2s(*P0);
       cint8 q0 = u2s(*Q0), q1 = u2s(*Q1), q2 = u2s(*Q2),
         q3 = u2s(*Q3);
        
   void MBfilter(
       uint8 hev_threshold,     /* detect high edge variance */
       uint8 interior_limit,    /* possibly disable filter */
       uint8 edge_limit,
       cint8 *P3, int8 *P2, int8 *P1, int8 *P0,  /* pixels before
                                                    edge */
       int8 *Q0, int8 *Q1, int8 *Q2, cint8 *Q3   /* pixels after
                                                    edge */
   ) {
       cint8 p3 = u2s(*P3), p2 = u2s(*P2), p1 = u2s(*P1),
         p0 = u2s(*P0);
       cint8 q0 = u2s(*Q0), q1 = u2s(*Q1), q2 = u2s(*Q2),
         q3 = u2s(*Q3);
        
       if (filter_yes(interior_limit, edge_limit, q3, q2, q1, q0,
         p0, p1, p2, p3))
       {
           if (!hev(hev_threshold, p1, p0, q0, q1))
           {
               /* Same as the initial calculation in "common_adjust",
                  w is something like twice the edge difference */
        
       if (filter_yes(interior_limit, edge_limit, q3, q2, q1, q0,
         p0, p1, p2, p3))
       {
           if (!hev(hev_threshold, p1, p0, q0, q1))
           {
               /* Same as the initial calculation in "common_adjust",
                  w is something like twice the edge difference */
        
               const int8 w = c(c(p1 - q1) + 3*(q0 - p0));
        
               const int8 w = c(c(p1 - q1) + 3*(q0 - p0));
        
               /* 9/64 is approximately 9/63 = 1/7, and 1<<7 = 128 =
                  2*64.  So this a, used to adjust the pixels adjacent
                  to the edge, is something like 3/7 the edge
                  difference. */
        
               /* 9/64 is approximately 9/63 = 1/7, and 1<<7 = 128 =
                  2*64.  So this a, used to adjust the pixels adjacent
                  to the edge, is something like 3/7 the edge
                  difference. */
        
               int8 a = c((27*w + 63) >> 7);
        
               int8 a = c((27*w + 63) >> 7);
        
               *Q0 = s2u(q0 - a);  *P0 = s2u(p0 + a);
        
               *Q0 = s2u(q0 - a);  *P0 = s2u(p0 + a);
        
               /* Next two are adjusted by 2/7 the edge difference */
        
               /* Next two are adjusted by 2/7 the edge difference */
        
               a = c((18*w + 63) >> 7);
        
               a = c((18*w + 63) >> 7);
        
               *Q1 = s2u(q1 - a);  *P1 = s2u(p1 + a);
        
               *Q1 = s2u(q1 - a);  *P1 = s2u(p1 + a);
        
               /* Last two are adjusted by 1/7 the edge difference */
        
               /* Last two are adjusted by 1/7 the edge difference */
        
               a = c((9*w + 63) >> 7);
        
               a = c((9*w + 63) >> 7);
        
               *Q2 = s2u(q2 - a);  *P2 = s2u(p2 + a);
        
               *Q2 = s2u(q2 - a);  *P2 = s2u(p2 + a);
        
           } else                      /* if hev, do simple filter */
               common_adjust(1, P1, P0, Q0, Q1);   /* using outer
                                                       taps */
       }
   }
        
           } else                      /* if hev, do simple filter */
               common_adjust(1, P1, P0, Q0, Q1);   /* using outer
                                                       taps */
       }
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
15.4. Calculation of Control Parameters
15.4. 控制参数的计算

We conclude the discussion of loop filtering by showing how the thresholds supplied to the procedures above are derived from the two control parameters sharpness_level (an unsigned 3-bit number having maximum value 7) and loop_filter_level (an unsigned 6-bit number having maximum value 63).

我们通过展示提供给上述过程的阈值是如何从两个控制参数sharpness_level(最大值为7的无符号3位数字)和loop_filter_level(最大值为63的无符号6位数字)导出的,从而结束对循环过滤的讨论。

While the sharpness_level is constant over the frame, individual macroblocks may override the loop_filter_level with one of four possibilities supplied in the frame header (as described in Section 10).

虽然锐度_级别在帧上是恒定的,但是单个宏块可以使用帧头中提供的四种可能性之一覆盖循环_过滤器_级别(如第10节所述)。

Both the simple and normal filters disable filtering if a value derived from the four pixels that straddle the edge (2 either side) exceeds a threshold / limit value.

如果从横跨边缘(两侧各2个)的四个像素派生的值超过阈值/限制值,则简单过滤器和普通过滤器都会禁用过滤。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* Luma and Chroma use the same inter-macroblock edge limit */
   uint8 mbedge_limit = ((loop_filter_level + 2) * 2) +
     interior_limit;
        
   /* Luma and Chroma use the same inter-macroblock edge limit */
   uint8 mbedge_limit = ((loop_filter_level + 2) * 2) +
     interior_limit;
        
   /* Luma and Chroma use the same inter-subblock edge limit */
   uint8 sub_bedge_limit = (loop_filter_level * 2) + interior_limit;
        
   /* Luma and Chroma use the same inter-subblock edge limit */
   uint8 sub_bedge_limit = (loop_filter_level * 2) + interior_limit;
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The remaining thresholds are used only by the normal filters. The filter-disabling interior difference limit is the same for all edges (luma, chroma, inter-subblock, inter-macroblock) and is given by the following.

其余的阈值仅由普通过滤器使用。禁用过滤器的内部差异限制对于所有边缘(亮度、色度、子块间、宏块间)都是相同的,如下所示。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        

uint8 interior_limit = loop_filter_level;

uint8内部\u限值=环路\u过滤器\u电平;

   if (sharpness_level)
   {
       interior_limit  >>=  sharpness_level > 4 ?  2 : 1;
       if (interior_limit > 9 - sharpness_level)
           interior_limit = 9 - sharpness_level;
   }
   if (!interior_limit)
       interior_limit = 1;
        
   if (sharpness_level)
   {
       interior_limit  >>=  sharpness_level > 4 ?  2 : 1;
       if (interior_limit > 9 - sharpness_level)
           interior_limit = 9 - sharpness_level;
   }
   if (!interior_limit)
       interior_limit = 1;
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Finally, we give the derivation of the high edge-variance threshold, which is also the same for all edge types.

最后,我们给出了高边缘方差阈值的推导,这对于所有边缘类型也是相同的。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        

uint8 hev_threshold = 0;

uint8 hev_阈值=0;

   if (we_are_decoding_akey_frame)   /* current frame is a key frame */
   {
       if (loop_filter_level >= 40)
           hev_threshold = 2;
       else if (loop_filter_level >= 15)
           hev_threshold = 1;
   }
   else                            /* current frame is an interframe */
   {
       if (loop_filter_level >= 40)
           hev_threshold = 3;
       else if (loop_filter_level >= 20)
           hev_threshold = 2;
       else if (loop_filter_level >= 15)
           hev_threshold = 1;
   }
        
   if (we_are_decoding_akey_frame)   /* current frame is a key frame */
   {
       if (loop_filter_level >= 40)
           hev_threshold = 2;
       else if (loop_filter_level >= 15)
           hev_threshold = 1;
   }
   else                            /* current frame is an interframe */
   {
       if (loop_filter_level >= 40)
           hev_threshold = 3;
       else if (loop_filter_level >= 20)
           hev_threshold = 2;
       else if (loop_filter_level >= 15)
           hev_threshold = 1;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
16. Interframe Macroblock Prediction Records
16. 帧间宏块预测记录

We describe the layout and semantics of the prediction records for macroblocks in an interframe.

我们描述帧间宏块预测记录的布局和语义。

After the feature specification (which is described in Section 10 and is identical for intraframes and interframes), there comes a Bool(prob_intra), which indicates inter-prediction (i.e., prediction from prior frames) when true and intra-prediction (i.e., prediction from already-coded portions of the current frame) when false. The zero-probability prob_intra is set by field J of the frame header.

在特征规范(在第10节中描述并且对于帧内和帧间相同)之后,出现Bool(prob_intra),当为真时指示帧间预测(即,来自先前帧的预测),当为假时指示帧内预测(即,来自当前帧的已编码部分的预测)。零概率prob_intra由帧头的字段J设置。

16.1. Intra-Predicted Macroblocks
16.1. 帧内预测宏块

For intra-prediction, the layout of the prediction data is essentially the same as the layout for key frames, although the contexts used by the decoding process are slightly different.

对于帧内预测,预测数据的布局基本上与关键帧的布局相同,尽管解码过程使用的上下文略有不同。

As discussed in Section 8, the "outer" Y mode here uses a different tree from that used in key frames, repeated here for convenience.

如第8节所述,此处的“外部”Y模式使用与关键帧中使用的不同的树,为了方便起见在此处重复。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const tree_index ymode_tree [2 * (num_ymodes - 1)] =
   {
    -DC_PRED, 2,           /* root: DC_PRED = "0", "1" subtree */
     4, 6,                 /* "1" subtree has 2 descendant subtrees */
      -V_PRED, -H_PRED,    /* "10" subtree:  V_PRED = "100",
                              H_PRED = "101" */
      -TM_PRED, -B_PRED    /* "11" subtree:  TM_PRED = "110",
                              B_PRED = "111" */
   };
        
   const tree_index ymode_tree [2 * (num_ymodes - 1)] =
   {
    -DC_PRED, 2,           /* root: DC_PRED = "0", "1" subtree */
     4, 6,                 /* "1" subtree has 2 descendant subtrees */
      -V_PRED, -H_PRED,    /* "10" subtree:  V_PRED = "100",
                              H_PRED = "101" */
      -TM_PRED, -B_PRED    /* "11" subtree:  TM_PRED = "110",
                              B_PRED = "111" */
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The probability table used to decode this tree is variable. As described in Section 11, it (along with the similarly treated UV table) can be updated by field J of the frame header. Similar to the coefficient-decoding probabilities, such updates are cumulative and affect all ensuing frames until the next key frame or explicit update. The default probabilities for the Y and UV tables are:

用于解码此树的概率表是可变的。如第11节所述,它(以及类似处理的UV表)可以通过帧头的字段J进行更新。与系数解码概率类似,此类更新是累积的,并且影响所有后续帧,直到下一关键帧或显式更新。Y和UV表的默认概率为:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   Prob ymode_prob [num_ymodes - 1] = { 112, 86, 140, 37};
   Prob uv_mode_prob [num_uv_modes - 1] = { 162, 101, 204};
        
   Prob ymode_prob [num_ymodes - 1] = { 112, 86, 140, 37};
   Prob uv_mode_prob [num_uv_modes - 1] = { 162, 101, 204};
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

These defaults must be restored after detection of a key frame.

检测到关键帧后,必须恢复这些默认值。

Just as for key frames, if the Y mode is B_PRED, there next comes an encoding of the intra_bpred mode used by each of the sixteen Y subblocks. These encodings use the same tree as does that for key frames but, in place of the contexts used in key frames, these encodings use the single fixed probability table.

与关键帧一样,如果Y模式是B_PRED,则接下来是16个Y子块中的每个所使用的帧内模式的编码。这些编码使用与关键帧相同的树,但代替关键帧中使用的上下文,这些编码使用单个固定概率表。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const Prob bmode_prob [num_intra_bmodes - 1] = {
       120, 90, 79, 133, 87, 85, 80, 111, 151
   };
        
   const Prob bmode_prob [num_intra_bmodes - 1] = {
       120, 90, 79, 133, 87, 85, 80, 111, 151
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Last comes the chroma mode, again coded using the same tree as that used for key frames, this time using the dynamic uv_mode_prob table described above.

最后是色度模式,再次使用与关键帧相同的树进行编码,这次使用上述动态uv_模式_prob表。

The calculation of the intra-prediction buffer is identical to that described for key frames in Section 12.

帧内预测缓冲器的计算与第12部分中针对关键帧描述的计算相同。

16.2. Inter-Predicted Macroblocks
16.2. 帧间预测宏块

Otherwise (when the above bool is true), we are using inter-prediction (which of course only happens for interframes), to which we now restrict our attention.

否则(当上述bool为真时),我们将使用帧间预测(当然,这只发生在帧间),我们现在将注意力限制在这一点上。

The next datum is then another bool, B(prob_last), selecting the reference frame. If 0, the reference frame is the previous frame (the last frame); if 1, another bool (prob_gf) selects the reference frame between the golden frame (0) and the altref frame (1). The probabilities prob_last and prob_gf are set in field J of the frame header.

然后,下一个基准是另一个布尔B(prob_last),选择参考坐标系。如果为0,则参考帧为前一帧(最后一帧);如果为1,则另一个布尔(prob_gf)选择黄金帧(0)和altref帧(1)之间的参考帧。在帧头的字段J中设置概率prob_last和prob_gf。

Together with setting the reference frame, the purpose of inter-mode decoding is to set a motion vector for each of the sixteen Y subblocks of the current macroblock. These settings then define the calculation of the inter-prediction buffer (detailed in Section 18). While the net effect of inter-mode decoding is straightforward, the implementation is somewhat complex; the (lossless) compression achieved by this method justifies the complexity.

与设置参考帧一起,模式间解码的目的是为当前宏块的十六个Y子块中的每一个设置运动矢量。然后,这些设置定义帧间预测缓冲器的计算(在第18节中详细说明)。虽然模式间解码的净效果是直接的,但实现有点复杂;这种方法实现的(无损)压缩证明了其复杂性。

After the reference frame selector comes the mode (or motion vector reference) applied to the macroblock as a whole, coded using the following enumeration and tree. Setting mv_nearest = num_ymodes is a convenience that allows a single variable to unambiguously hold an inter- or intra-prediction mode.

参考帧选择器之后是应用于整个宏块的模式(或运动矢量参考),使用以下枚举和树进行编码。设置mv_nearest=num_ymodes是一种方便,它允许单个变量明确地保持帧间或帧内预测模式。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef enum
   {
       mv_nearest = num_ymodes, /* use "nearest" motion vector
                                   for entire MB */
       mv_near,                 /* use "next nearest" "" */
       mv_zero,                 /* use zero "" */
       mv_new,                  /* use explicit offset from
                                   implicit "" */
       mv_split,                /* use multiple motion vectors */
        
   typedef enum
   {
       mv_nearest = num_ymodes, /* use "nearest" motion vector
                                   for entire MB */
       mv_near,                 /* use "next nearest" "" */
       mv_zero,                 /* use zero "" */
       mv_new,                  /* use explicit offset from
                                   implicit "" */
       mv_split,                /* use multiple motion vectors */
        
       num_mv_refs = mv_split + 1 - mv_nearest
   }
   mv_ref;
        
       num_mv_refs = mv_split + 1 - mv_nearest
   }
   mv_ref;
        
   const tree_index mv_ref_tree [2 * (num_mv_refs - 1)] =
   {
    -mv_zero, 2,                /* zero = "0" */
     -mv_nearest, 4,            /* nearest = "10" */
      -mv_near, 6,              /* near = "110" */
        -mv_new, -mv_split      /* new = "1110", split = "1111" */
   };
        
   const tree_index mv_ref_tree [2 * (num_mv_refs - 1)] =
   {
    -mv_zero, 2,                /* zero = "0" */
     -mv_nearest, 4,            /* nearest = "10" */
      -mv_near, 6,              /* near = "110" */
        -mv_new, -mv_split      /* new = "1110", split = "1111" */
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
16.3. Mode and Motion Vector Contexts
16.3. 模式和运动矢量上下文

The probability table used to decode the mv_ref, along with three reference motion vectors used by the selected mode, is calculated via a survey of the already-decoded motion vectors in (up to) 3 nearby macroblocks.

用于解码mv_ref的概率表以及所选模式使用的三个参考运动矢量,通过对(最多)3个相邻宏块中已解码运动矢量的调查来计算。

The algorithm generates a sorted list of distinct motion vectors adjacent to the search site. The best_mv is the vector with the highest score. The mv_nearest is the non-zero vector with the highest score. The mv_near is the non-zero vector with the next highest score. The number of motion vectors coded using the SPLITMV mode is scored using the same weighting and is returned with the scores of the best, nearest, and near vectors.

该算法生成与搜索站点相邻的不同运动矢量的排序列表。最好的是得分最高的向量。最近的mv_是得分最高的非零向量。mv_near是得分次高的非零向量。使用SPLITMV模式编码的运动矢量数使用相同的权重进行评分,并返回最佳、最近和接近矢量的评分。

The three adjacent macroblocks above, left, and above-left are considered in order. If the macroblock is intra-coded, no action is taken. Otherwise, the motion vector is compared to other previously found motion vectors to determine if it has been seen before, and if so contributes its weight to that vector; otherwise, it enters a new vector in the list. The above and left vectors have twice the weight of the above-left vector.

按顺序考虑左上方、左上方和左上方的三个相邻宏块。如果宏块是帧内编码的,则不采取任何操作。否则,将该运动向量与先前发现的其他运动向量进行比较,以确定其之前是否已被看见,并且如果是,则将其权重贡献给该向量;否则,它将在列表中输入一个新向量。上方向向量和左方向向量的权重是上方向向量的两倍。

As is the case with many contexts used by VP8, it is possible for macroblocks near the top or left edges of the image to reference blocks that are outside the visible image. VP8 provides a border of 1 macroblock filled with 0x0 motion vectors left of the left edge, and a border filled with 0,0 motion vectors of 1 macroblocks above the top edge.

与VP8使用的许多上下文的情况一样,靠近图像上边缘或左边缘的宏块可以参考可见图像之外的块。VP8提供了一个由1个宏块组成的边界,该宏块填充了左边缘左侧的0x0运动矢量,以及一个由上边缘上方的1个宏块的0,0运动矢量填充的边界。

Much of the process is more easily described in C than in English. The reference code for this can be found in modemv.c (Section 20.11). The calculation of reference vectors, probability table, and, finally, the inter-prediction mode itself is implemented as follows.

用C语言比用英语更容易描述这个过程。可在modemv.c(第20.11节)中找到这方面的参考代码。参考向量、概率表的计算,以及最后帧间预测模式本身的计算如下所示。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef union
   {
       unsigned int as_int;
       MV           as_mv;
   } int_mv;        /* facilitates rapid equality tests */
        
   typedef union
   {
       unsigned int as_int;
       MV           as_mv;
   } int_mv;        /* facilitates rapid equality tests */
        
   static void mv_bias(MODE_INFO *x,int refframe, int_mv *mvp,
     int * ref_frame_sign_bias)
   {
       MV xmv;
       xmv = x->mbmi.mv.as_mv;
       if ( ref_frame_sign_bias[x->mbmi.ref_frame] !=
         ref_frame_sign_bias[refframe] )
       {
           xmv.row*=-1;
           xmv.col*=-1;
       }
       mvp->as_mv = xmv;
   }
        
   static void mv_bias(MODE_INFO *x,int refframe, int_mv *mvp,
     int * ref_frame_sign_bias)
   {
       MV xmv;
       xmv = x->mbmi.mv.as_mv;
       if ( ref_frame_sign_bias[x->mbmi.ref_frame] !=
         ref_frame_sign_bias[refframe] )
       {
           xmv.row*=-1;
           xmv.col*=-1;
       }
       mvp->as_mv = xmv;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   void vp8_clamp_mv(MV *mv, const MACROBLOCKD *xd)
   {
       if ( mv->col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN) )
           mv->col = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
       else if ( mv->col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN )
           mv->col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
        
   void vp8_clamp_mv(MV *mv, const MACROBLOCKD *xd)
   {
       if ( mv->col < (xd->mb_to_left_edge - LEFT_TOP_MARGIN) )
           mv->col = xd->mb_to_left_edge - LEFT_TOP_MARGIN;
       else if ( mv->col > xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN )
           mv->col = xd->mb_to_right_edge + RIGHT_BOTTOM_MARGIN;
        
       if ( mv->row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN) )
           mv->row = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
       else if ( mv->row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN )
           mv->row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
   }
        
       if ( mv->row < (xd->mb_to_top_edge - LEFT_TOP_MARGIN) )
           mv->row = xd->mb_to_top_edge - LEFT_TOP_MARGIN;
       else if ( mv->row > xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN )
           mv->row = xd->mb_to_bottom_edge + RIGHT_BOTTOM_MARGIN;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

In the function vp8_find_near_mvs(), the vectors "nearest" and "near" are used by the corresponding modes.

在函数vp8_find_near_mvs()中,向量“nearest”和“near”由相应的模式使用。

The vector best_mv is used as a base for explicitly coded motion vectors.

矢量best_mv用作显式编码运动矢量的基础。

The first three entries in the return value cnt are (in order) weighted census values for "zero", "nearest", and "near" vectors. The final value indicates the extent to which SPLITMV was used by the neighboring macroblocks. The largest possible "weight" value in each case is 5.

返回值cnt中的前三个条目(按顺序)是“零”、“最近”和“近”向量的加权普查值。最终值指示相邻宏块使用SPLITMV的程度。在每种情况下,最大可能的“重量”值为5。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        

void vp8_find_near_mvs ( MACROBLOCKD *xd, const MODE_INFO *here, MV *nearest, MV *near, MV *best_mv, int cnt[4], int refframe, int * ref_frame_sign_bias )

void vp8_find_near_mvs(宏块D*xd,此处常量模式信息,MV*最近,MV*近,MV*最佳,int cnt[4],int refframe,int*ref框架符号偏差)

   {
       const MODE_INFO *above = here - xd->mode_info_stride;
       const MODE_INFO *left = here - 1;
       const MODE_INFO *aboveleft = above - 1;
       int_mv            near_mvs[4];
       int_mv           *mv = near_mvs;
       int             *cntx = cnt;
       enum {CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV};
        
   {
       const MODE_INFO *above = here - xd->mode_info_stride;
       const MODE_INFO *left = here - 1;
       const MODE_INFO *aboveleft = above - 1;
       int_mv            near_mvs[4];
       int_mv           *mv = near_mvs;
       int             *cntx = cnt;
       enum {CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV};
        
       /* Zero accumulators */
       mv[0].as_int = mv[1].as_int = mv[2].as_int = 0;
       cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
        
       /* Zero accumulators */
       mv[0].as_int = mv[1].as_int = mv[2].as_int = 0;
       cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
        
       /* Process above */
       if (above->mbmi.ref_frame != INTRA_FRAME) {
           if (above->mbmi.mv.as_int) {
               (++mv)->as_int = above->mbmi.mv.as_int;
               mv_bias(above, refframe, mv, ref_frame_sign_bias);
               ++cntx;
           }
           *cntx += 2;
       }
        
       /* Process above */
       if (above->mbmi.ref_frame != INTRA_FRAME) {
           if (above->mbmi.mv.as_int) {
               (++mv)->as_int = above->mbmi.mv.as_int;
               mv_bias(above, refframe, mv, ref_frame_sign_bias);
               ++cntx;
           }
           *cntx += 2;
       }
        
       /* Process left */
       if (left->mbmi.ref_frame != INTRA_FRAME) {
           if (left->mbmi.mv.as_int) {
               int_mv this_mv;
        
       /* Process left */
       if (left->mbmi.ref_frame != INTRA_FRAME) {
           if (left->mbmi.mv.as_int) {
               int_mv this_mv;
        
               this_mv.as_int = left->mbmi.mv.as_int;
               mv_bias(left, refframe, &this_mv, ref_frame_sign_bias);
        
               this_mv.as_int = left->mbmi.mv.as_int;
               mv_bias(left, refframe, &this_mv, ref_frame_sign_bias);
        
               if (this_mv.as_int != mv->as_int) {
                   (++mv)->as_int = this_mv.as_int;
                   ++cntx;
               }
               *cntx += 2;
           } else
               cnt[CNT_ZERO] += 2;
       }
        
               if (this_mv.as_int != mv->as_int) {
                   (++mv)->as_int = this_mv.as_int;
                   ++cntx;
               }
               *cntx += 2;
           } else
               cnt[CNT_ZERO] += 2;
       }
        
       /* Process above left */
       if (aboveleft->mbmi.ref_frame != INTRA_FRAME) {
           if (aboveleft->mbmi.mv.as_int) {
               int_mv this_mv;
        
       /* Process above left */
       if (aboveleft->mbmi.ref_frame != INTRA_FRAME) {
           if (aboveleft->mbmi.mv.as_int) {
               int_mv this_mv;
        
               this_mv.as_int = aboveleft->mbmi.mv.as_int;
               mv_bias(aboveleft, refframe, &this_mv,
                 ref_frame_sign_bias);
        
               this_mv.as_int = aboveleft->mbmi.mv.as_int;
               mv_bias(aboveleft, refframe, &this_mv,
                 ref_frame_sign_bias);
        
               if (this_mv.as_int != mv->as_int) {
                   (++mv)->as_int = this_mv.as_int;
                   ++cntx;
               }
               *cntx += 1;
           } else
               cnt[CNT_ZERO] += 1;
       }
        
               if (this_mv.as_int != mv->as_int) {
                   (++mv)->as_int = this_mv.as_int;
                   ++cntx;
               }
               *cntx += 1;
           } else
               cnt[CNT_ZERO] += 1;
       }
        
       /* If we have three distinct MVs ... */
       if (cnt[CNT_SPLITMV]) {
           /* See if above-left MV can be merged with NEAREST */
           if (mv->as_int == near_mvs[CNT_NEAREST].as_int)
               cnt[CNT_NEAREST] += 1;
       }
        
       /* If we have three distinct MVs ... */
       if (cnt[CNT_SPLITMV]) {
           /* See if above-left MV can be merged with NEAREST */
           if (mv->as_int == near_mvs[CNT_NEAREST].as_int)
               cnt[CNT_NEAREST] += 1;
       }
        
       cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
                            + (left->mbmi.mode == SPLITMV)) * 2
                           + (aboveleft->mbmi.mode == SPLITMV);
        
       cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
                            + (left->mbmi.mode == SPLITMV)) * 2
                           + (aboveleft->mbmi.mode == SPLITMV);
        
       /* Swap near and nearest if necessary */
       if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
           int tmp;
           tmp = cnt[CNT_NEAREST];
           cnt[CNT_NEAREST] = cnt[CNT_NEAR];
           cnt[CNT_NEAR] = tmp;
           tmp = near_mvs[CNT_NEAREST].as_int;
           near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
           near_mvs[CNT_NEAR].as_int = tmp;
       }
        
       /* Swap near and nearest if necessary */
       if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
           int tmp;
           tmp = cnt[CNT_NEAREST];
           cnt[CNT_NEAREST] = cnt[CNT_NEAR];
           cnt[CNT_NEAR] = tmp;
           tmp = near_mvs[CNT_NEAREST].as_int;
           near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
           near_mvs[CNT_NEAR].as_int = tmp;
       }
        
       /* Use near_mvs[0] to store the "best" MV */
       if (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])
           near_mvs[CNT_ZERO] = near_mvs[CNT_NEAREST];
        
       /* Use near_mvs[0] to store the "best" MV */
       if (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])
           near_mvs[CNT_ZERO] = near_mvs[CNT_NEAREST];
        
       /* Set up return values */
       *best_mv = near_mvs[0].as_mv;
       *nearest = near_mvs[CNT_NEAREST].as_mv;
       *near = near_mvs[CNT_NEAR].as_mv;
        
       /* Set up return values */
       *best_mv = near_mvs[0].as_mv;
       *nearest = near_mvs[CNT_NEAREST].as_mv;
       *near = near_mvs[CNT_NEAR].as_mv;
        
       vp8_clamp_mv(nearest, xd);
       vp8_clamp_mv(near, xd);
       vp8_clamp_mv(best_mv, xd); //TODO: Move this up before
                                    the copy
   }
        
       vp8_clamp_mv(nearest, xd);
       vp8_clamp_mv(near, xd);
       vp8_clamp_mv(best_mv, xd); //TODO: Move this up before
                                    the copy
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The mv_ref probability table (mv_ref_p) is then derived from the census as follows.

mv_ref概率表(mv_ref_p)由人口普查得出,如下所示。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const int vp8_mode_contexts[6][4] =
   {
     {   7,     1,     1,   143,   },
     {  14,    18,    14,   107,   },
     { 135,    64,    57,    68,   },
     {  60,    56,   128,    65,   },
     { 159,   134,   128,    34,   },
     { 234,   188,   128,    28,   },
   }
        
   const int vp8_mode_contexts[6][4] =
   {
     {   7,     1,     1,   143,   },
     {  14,    18,    14,   107,   },
     { 135,    64,    57,    68,   },
     {  60,    56,   128,    65,   },
     { 159,   134,   128,    34,   },
     { 234,   188,   128,    28,   },
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   vp8_prob *vp8_mv_ref_probs(vp8_prob mv_ref_p[VP8_MVREFS-1],
     int cnt[4])
   {
       mv_ref_p[0] = vp8_mode_contexts [cnt[0]] [0];
       mv_ref_p[1] = vp8_mode_contexts [cnt[1]] [1];
       mv_ref_p[2] = vp8_mode_contexts [cnt[2]] [2];
       mv_ref_p[3] = vp8_mode_contexts [cnt[3]] [3];
       return p;
   }
        
   vp8_prob *vp8_mv_ref_probs(vp8_prob mv_ref_p[VP8_MVREFS-1],
     int cnt[4])
   {
       mv_ref_p[0] = vp8_mode_contexts [cnt[0]] [0];
       mv_ref_p[1] = vp8_mode_contexts [cnt[1]] [1];
       mv_ref_p[2] = vp8_mode_contexts [cnt[2]] [2];
       mv_ref_p[3] = vp8_mode_contexts [cnt[3]] [3];
       return p;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Once mv_ref_p is established, the mv_ref is decoded as usual.

一旦mv_ref_p建立,mv_ref将像往常一样解码。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
     mvr = (mv_ref) treed_read(d, mv_ref_tree, mv_ref_p);
        
     mvr = (mv_ref) treed_read(d, mv_ref_tree, mv_ref_p);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

For the first four inter-coding modes, the same motion vector is used for all the Y subblocks. The first three modes use an implicit motion vector.

对于前四种帧间编码模式,相同的运动矢量用于所有Y子块。前三种模式使用隐式运动矢量。

   +------------+------------------------------------------------------+
   | Mode       | Instruction                                          |
   +------------+------------------------------------------------------+
   | mv_nearest | Use the nearest vector returned by                   |
   |            | vp8_find_near_mvs.                                   |
   |            |                                                      |
   | mv_near    | Use the near vector returned by vp8_find_near_mvs.   |
   |            |                                                      |
   | mv_zero    | Use a zero vector; that is, predict the current      |
   |            | macroblock from the corresponding macroblock in the  |
   |            | prediction frame.                                    |
   |            |                                                      |
   | NEWMV      | This mode is followed by an explicitly coded motion  |
   |            | vector (the format of which is described in the next |
   |            | section) that is added (component-wise) to the       |
   |            | best_mv reference vector returned by find_near_mvs   |
   |            | and applied to all 16 subblocks.                     |
   +------------+------------------------------------------------------+
        
   +------------+------------------------------------------------------+
   | Mode       | Instruction                                          |
   +------------+------------------------------------------------------+
   | mv_nearest | Use the nearest vector returned by                   |
   |            | vp8_find_near_mvs.                                   |
   |            |                                                      |
   | mv_near    | Use the near vector returned by vp8_find_near_mvs.   |
   |            |                                                      |
   | mv_zero    | Use a zero vector; that is, predict the current      |
   |            | macroblock from the corresponding macroblock in the  |
   |            | prediction frame.                                    |
   |            |                                                      |
   | NEWMV      | This mode is followed by an explicitly coded motion  |
   |            | vector (the format of which is described in the next |
   |            | section) that is added (component-wise) to the       |
   |            | best_mv reference vector returned by find_near_mvs   |
   |            | and applied to all 16 subblocks.                     |
   +------------+------------------------------------------------------+
        
16.4. Split Prediction
16.4. 分裂预测

The remaining mode (SPLITMV) causes multiple vectors to be applied to the Y subblocks. It is immediately followed by a partition specification that determines how many vectors will be specified and how they will be assigned to the subblocks. The possible partitions, with indicated subdivisions and coding tree, are as follows.

剩余模式(SPLITMV)使多个向量应用于Y子块。紧接着是一个分区规范,该规范确定将指定多少个向量以及如何将它们分配给子块。可能的分区(带有指示的子分区和编码树)如下所示。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef enum
   {
       mv_top_bottom,   /* two pieces {0...7} and {8...15} */
       mv_left_right,   /* {0,1,4,5,8,9,12,13} and
                           {2,3,6,7,10,11,14,15} */
       mv_quarters,    /* {0,1,4,5}, {2,3,6,7}, {8,9,12,13},
                          {10,11,14,15} */
       MV_16,          /* every subblock gets its own vector
                          {0} ... {15} */
        
   typedef enum
   {
       mv_top_bottom,   /* two pieces {0...7} and {8...15} */
       mv_left_right,   /* {0,1,4,5,8,9,12,13} and
                           {2,3,6,7,10,11,14,15} */
       mv_quarters,    /* {0,1,4,5}, {2,3,6,7}, {8,9,12,13},
                          {10,11,14,15} */
       MV_16,          /* every subblock gets its own vector
                          {0} ... {15} */
        
       mv_num_partitions
   }
   MVpartition;
        
       mv_num_partitions
   }
   MVpartition;
        
   const tree_index mvpartition_tree [2 * (mvnum_partition - 1)] =
   {
    -MV_16, 2,                         /* MV_16 = "0" */
     -mv_quarters, 4,                  /* mv_quarters = "10" */
      -mv_top_bottom, -mv_left_right   /* top_bottom = "110",
                                          left_right = "111" */
   };
        
   const tree_index mvpartition_tree [2 * (mvnum_partition - 1)] =
   {
    -MV_16, 2,                         /* MV_16 = "0" */
     -mv_quarters, 4,                  /* mv_quarters = "10" */
      -mv_top_bottom, -mv_left_right   /* top_bottom = "110",
                                          left_right = "111" */
   };
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The partition is decoded using a fixed, constant probability table:

使用固定不变的概率表对分区进行解码:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   const Prob mvpartition_probs [mvnum_partition - 1] =
     { 110, 111, 150};
   part = (MVpartition) treed_read(d, mvpartition_tree,
     mvpartition_probs);
        
   const Prob mvpartition_probs [mvnum_partition - 1] =
     { 110, 111, 150};
   part = (MVpartition) treed_read(d, mvpartition_tree,
     mvpartition_probs);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

After the partition come two (for mv_top_bottom or mv_left_right), four (for mv_quarters), or sixteen (for MV_16) subblock inter-prediction modes. These modes occur in the order indicated by the partition layouts (given as comments to the MVpartition enum) and are coded as follows. (As was done for the macroblock-level modes, we offset the mode enumeration so that a single variable may unambiguously hold either an intra- or inter-subblock mode.)

分区后出现两个(用于mv_顶部_底部或mv_左侧_右侧)、四个(用于mv_四分之一)或十六个(用于mv_16)子块间预测模式。这些模式按照分区布局指示的顺序出现(作为MVpartition枚举的注释给出),并按如下方式编码。(与宏块级模式一样,我们偏移了模式枚举,以便单个变量可以明确地保持子块内或子块间模式。)

Prior to decoding each subblock, a decoding tree context is chosen as illustrated in the code snippet below. The context is based on the immediate left and above subblock neighbors, and whether they are equal, are zero, or a combination of those.

在解码每个子块之前,选择解码树上下文,如下面的代码片段所示。上下文基于直接的左侧和上方子块邻居,以及它们是否相等、为零或它们的组合。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef enum
   {
       LEFT4x4 = num_intra_bmodes,   /* use already-coded MV to
                                        my left */
       ABOVE4x4,             /* use already-coded MV above me */
       ZERO4x4,              /* use zero MV */
       NEW4x4,               /* explicit offset from "best" */
        
   typedef enum
   {
       LEFT4x4 = num_intra_bmodes,   /* use already-coded MV to
                                        my left */
       ABOVE4x4,             /* use already-coded MV above me */
       ZERO4x4,              /* use zero MV */
       NEW4x4,               /* explicit offset from "best" */
        
       num_sub_mv_ref
   };
   sub_mv_ref;
        
       num_sub_mv_ref
   };
   sub_mv_ref;
        
   const tree_index sub_mv_ref_tree [2 * (num_sub_mv_ref - 1)] =
   {
    -LEFT4X4, 2,           /* LEFT = "0" */
     -ABOVE4X4, 4,         /* ABOVE = "10" */
      -ZERO4X4, -NEW4X4    /* ZERO = "110", NEW = "111" */
   };
        
   const tree_index sub_mv_ref_tree [2 * (num_sub_mv_ref - 1)] =
   {
    -LEFT4X4, 2,           /* LEFT = "0" */
     -ABOVE4X4, 4,         /* ABOVE = "10" */
      -ZERO4X4, -NEW4X4    /* ZERO = "110", NEW = "111" */
   };
        
   /* Choose correct decoding tree context
    * Function parameters are left subblock neighbor MV and above
    * subblock neighbor MV */
   int vp8_mvCont(MV *l, MV*a)
   {
       int lez = (l->row == 0 && l->col == 0);   /* left neighbor
                                                    is zero */
       int aez = (a->row == 0 && a->col == 0);   /* above neighbor
                                                    is zero */
       int lea = (l->row == a->row && l->col == a->col);  /* left
                                neighbor equals above neighbor */
        
   /* Choose correct decoding tree context
    * Function parameters are left subblock neighbor MV and above
    * subblock neighbor MV */
   int vp8_mvCont(MV *l, MV*a)
   {
       int lez = (l->row == 0 && l->col == 0);   /* left neighbor
                                                    is zero */
       int aez = (a->row == 0 && a->col == 0);   /* above neighbor
                                                    is zero */
       int lea = (l->row == a->row && l->col == a->col);  /* left
                                neighbor equals above neighbor */
        
       if (lea && lez)
           return SUBMVREF_LEFT_ABOVE_ZED; /* =4 */
        
       if (lea && lez)
           return SUBMVREF_LEFT_ABOVE_ZED; /* =4 */
        
       if (lea)
           return SUBMVREF_LEFT_ABOVE_SAME; /* =3 */
        
       if (lea)
           return SUBMVREF_LEFT_ABOVE_SAME; /* =3 */
        
       if (aez)
           return SUBMVREF_ABOVE_ZED; /* =2 */
        
       if (aez)
           return SUBMVREF_ABOVE_ZED; /* =2 */
        
       if (lez)
           return SUBMVREF_LEFT_ZED; /* =1*/
        
       if (lez)
           return SUBMVREF_LEFT_ZED; /* =1*/
        
       return SUBMVREF_NORMAL; /* =0 */
   }
        
       return SUBMVREF_NORMAL; /* =0 */
   }
        
   /* Constant probabilities and decoding procedure. */
        
   /* Constant probabilities and decoding procedure. */
        
   const Prob sub_mv_ref_prob [5][num_sub_mv_ref - 1] = {
       { 147,136,18 },
       { 106,145,1  },
       { 179,121,1  },
       { 223,1  ,34 },
       { 208,1  ,1  }
   };
        
   const Prob sub_mv_ref_prob [5][num_sub_mv_ref - 1] = {
       { 147,136,18 },
       { 106,145,1  },
       { 179,121,1  },
       { 223,1  ,34 },
       { 208,1  ,1  }
   };
        
       sub_ref = (sub_mv_ref) treed_read(d, sub_mv_ref_tree,
         sub_mv_ref_prob[context]);
        
       sub_ref = (sub_mv_ref) treed_read(d, sub_mv_ref_tree,
         sub_mv_ref_prob[context]);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

The first two sub-prediction modes simply copy the already-coded motion vectors used by the blocks above and to the left of the subblock at the upper left corner of the current subset (i.e., collection of subblocks being predicted). These prediction blocks need not lie in the current macroblock and, if the current subset lies at the top or left edges of the frame, need not lie in the frame. In this latter case, their motion vectors are taken to be zero, as are subblock motion vectors within an intra-predicted macroblock. Also, to ensure the correctness of prediction within this macroblock, all subblocks lying in an already-decoded subset of the current macroblock must have their motion vectors set.

前两个子预测模式简单地复制当前子集左上角(即,被预测的子块的集合)的子块上方和左侧的块所使用的已编码运动向量。这些预测块不必位于当前宏块中,并且如果当前子集位于帧的上边缘或左边缘,则不必位于帧中。在后一种情况下,它们的运动矢量被取为零,如同帧内预测宏块内的子块运动矢量一样。此外,为了确保该宏块内预测的正确性,位于当前宏块的已解码子集中的所有子块必须设置其运动向量。

ZERO4x4 uses a zero motion vector and predicts the current subset using the corresponding subset from the prediction frame.

ZERO4x4使用零运动矢量,并使用来自预测帧的相应子集预测当前子集。

NEW4x4 is exactly like NEWMV except that NEW4x4 is applied only to the current subset. It is followed by a two-dimensional motion vector offset (described in the next section) that is added to the best vector returned by the earlier call to find_near_mvs to form the motion vector in effect for the subset.

NEW4x4与NEWMV完全相同,只是NEW4x4仅应用于当前子集。然后是一个二维运动矢量偏移量(在下一节中描述),该偏移量被添加到先前调用返回的最佳矢量中,以查找_near_mvs,从而形成对子集有效的运动矢量。

Parsing of both inter-prediction modes and motion vectors (described next) can be found in the reference decoder file modemv.c (Section 20.11).

帧间预测模式和运动矢量(如下所述)的解析可在参考解码器文件modemv.c(第20.11节)中找到。

17. Motion Vector Decoding
17. 运动矢量解码

As discussed above, motion vectors appear in two places in the VP8 datastream: applied to whole macroblocks in NEWMV mode and applied to subsets of macroblocks in NEW4x4 mode. The format of the vectors is identical in both cases.

如上所述,运动矢量出现在VP8数据流中的两个位置:在NEWMV模式下应用于整个宏块,在NEW4x4模式下应用于宏块子集。在这两种情况下,向量的格式是相同的。

Each vector has two pieces: a vertical component (row) followed by a horizontal component (column). The row and column use separate coding probabilities but are otherwise represented identically.

每个向量有两个部分:一个垂直分量(行)后跟一个水平分量(列)。行和列使用单独的编码概率,但在其他方面表示相同。

17.1. Coding of Each Component
17.1. 每个部件的编码

Each component is a signed integer V representing a vertical or horizontal luma displacement of V quarter-pixels (and a chroma displacement of V eighth-pixels). The absolute value of V, if non-zero, is followed by a boolean sign. V may take any value between -1023 and +1023, inclusive.

每个分量是一个有符号整数V,表示V四分之一像素的垂直或水平亮度位移(以及V八分之一像素的色度位移)。如果V的绝对值不为零,则后跟布尔符号。V可以取-1023和+1023之间的任何值,包括-1023和+1023。

The absolute value A is coded in one of two different ways according to its size. For 0 <= A <= 7, A is tree-coded, and for 8 <= A <= 1023, the bits in the binary expansion of A are coded using independent boolean probabilities. The coding of A begins with a bool specifying which range is in effect.

绝对值A根据其大小以两种不同方式之一进行编码。对于0<=A<=7,对A进行树编码,对于8<=A<=1023,对A的二进制展开中的位使用独立的布尔概率进行编码。A的编码从指定有效范围的布尔开始。

Decoding a motion vector component then requires a 19-position probability table, whose offsets, along with the procedure used to decode components, are as follows:

解码运动矢量分量需要一个19位概率表,其偏移量以及用于解码分量的过程如下所示:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   typedef enum
   {
       mvpis_short,         /* short (<= 7) vs long (>= 8) */
       MVPsign,             /* sign for non-zero */
       MVPshort,            /* 8 short values = 7-position tree */
        
   typedef enum
   {
       mvpis_short,         /* short (<= 7) vs long (>= 8) */
       MVPsign,             /* sign for non-zero */
       MVPshort,            /* 8 short values = 7-position tree */
        
       MVPbits = MVPshort + 7,      /* 8 long value bits
                                       w/independent probs */
        
       MVPbits = MVPshort + 7,      /* 8 long value bits
                                       w/independent probs */
        
       MVPcount = MVPbits + 10      /* 19 probabilities in total */
   }
   MVPindices;
        
       MVPcount = MVPbits + 10      /* 19 probabilities in total */
   }
   MVPindices;
        
   typedef Prob MV_CONTEXT [MVPcount];    /* Decoding spec for
                                             a single component */
        
   typedef Prob MV_CONTEXT [MVPcount];    /* Decoding spec for
                                             a single component */
        
   /* Tree used for small absolute values (has expected
      correspondence). */
        
   /* Tree used for small absolute values (has expected
      correspondence). */
        
   const tree_index small_mvtree [2 * (8 - 1)] =
   {
    2, 8,          /* "0" subtree, "1" subtree */
     4, 6,         /* "00" subtree, "01" subtree */
      -0, -1,      /* 0 = "000", 1 = "001" */
      -2, -3,      /* 2 = "010", 3 = "011" */
     10, 12,       /* "10" subtree, "11" subtree */
      -4, -5,      /* 4 = "100", 5 = "101" */
      -6, -7       /* 6 = "110", 7 = "111" */
   };
        
   const tree_index small_mvtree [2 * (8 - 1)] =
   {
    2, 8,          /* "0" subtree, "1" subtree */
     4, 6,         /* "00" subtree, "01" subtree */
      -0, -1,      /* 0 = "000", 1 = "001" */
      -2, -3,      /* 2 = "010", 3 = "011" */
     10, 12,       /* "10" subtree, "11" subtree */
      -4, -5,      /* 4 = "100", 5 = "101" */
      -6, -7       /* 6 = "110", 7 = "111" */
   };
        
   /* Read MV component at current decoder position, using
      supplied probs. */
        
   /* Read MV component at current decoder position, using
      supplied probs. */
        
   int read_mvcomponent(bool_decoder *d, const MV_CONTEXT *mvc)
   {
       const Prob * const p = (const Prob *) mvc;
        
   int read_mvcomponent(bool_decoder *d, const MV_CONTEXT *mvc)
   {
       const Prob * const p = (const Prob *) mvc;
        

int A = 0;

int A=0;

       if (read_bool(d, p [mvpis_short]))    /* 8 <= A <= 1023 */
       {
           /* Read bits 0, 1, 2 */
        
       if (read_bool(d, p [mvpis_short]))    /* 8 <= A <= 1023 */
       {
           /* Read bits 0, 1, 2 */
        
           int i = 0;
           do { A += read_bool(d, p [MVPbits + i]) << i;}
             while (++i < 3);
        
           int i = 0;
           do { A += read_bool(d, p [MVPbits + i]) << i;}
             while (++i < 3);
        
           /* Read bits 9, 8, 7, 6, 5, 4 */
        
           /* Read bits 9, 8, 7, 6, 5, 4 */
        
           i = 9;
           do { A += read_bool(d, p [MVPbits + i]) << i;}
             while (--i > 3);
        
           i = 9;
           do { A += read_bool(d, p [MVPbits + i]) << i;}
             while (--i > 3);
        
           /* We know that A >= 8 because it is coded long,
              so if A <= 15, bit 3 is one and is not
              explicitly coded. */
        
           /* We know that A >= 8 because it is coded long,
              so if A <= 15, bit 3 is one and is not
              explicitly coded. */
        
           if (!(A & 0xfff0)  ||  read_bool(d, p [MVPbits + 3]))
               A += 8;
       }
       else    /* 0 <= A <= 7 */
           A = treed_read(d, small_mvtree, p + MVPshort);
        
           if (!(A & 0xfff0)  ||  read_bool(d, p [MVPbits + 3]))
               A += 8;
       }
       else    /* 0 <= A <= 7 */
           A = treed_read(d, small_mvtree, p + MVPshort);
        
       return A && read_bool(r, p [MVPsign]) ?  -A : A;
   }
        
       return A && read_bool(r, p [MVPsign]) ?  -A : A;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
17.2. Probability Updates
17.2. 概率更新

The decoder should maintain an array of two MV_CONTEXTs for decoding row and column components, respectively. These MV_CONTEXTs should be set to their defaults every key frame. Each individual probability may be updated every interframe (by field J of the frame header) using a constant table of update probabilities. Each optional update is of the form B? P(7), that is, a bool followed by a 7-bit probability specification if true.

解码器应保持两个MV_上下文的数组,分别用于解码行和列组件。这些MV_上下文应在每个关键帧设置为默认值。可以使用恒定的更新概率表在每个帧间(通过帧头的字段J)更新每个单独的概率。每个可选更新都是表格B?P(7),也就是说,如果为真,则为bool后跟7位概率规范。

As with other dynamic probabilities used by VP8, the updates remain in effect until the next key frame or until replaced via another update.

与VP8使用的其他动态概率一样,更新保持有效,直到下一个关键帧或通过另一个更新替换。

In detail, the probabilities should then be managed as follows.

具体而言,概率应按如下方式进行管理。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* Never-changing table of update probabilities for each
      individual probability used in decoding motion vectors. */
        
   /* Never-changing table of update probabilities for each
      individual probability used in decoding motion vectors. */
        
   const MV_CONTEXT vp8_mv_update_probs[2] =
   {
     {
       237,
       246,
       253, 253, 254, 254, 254, 254, 254,
       254, 254, 254, 254, 254, 250, 250, 252, 254, 254
     },
     {
       231,
       243,
       245, 253, 254, 254, 254, 254, 254,
       254, 254, 254, 254, 254, 251, 251, 254, 254, 254
     }
   };
        
   const MV_CONTEXT vp8_mv_update_probs[2] =
   {
     {
       237,
       246,
       253, 253, 254, 254, 254, 254, 254,
       254, 254, 254, 254, 254, 250, 250, 252, 254, 254
     },
     {
       231,
       243,
       245, 253, 254, 254, 254, 254, 254,
       254, 254, 254, 254, 254, 251, 251, 254, 254, 254
     }
   };
        
   /* Default MV decoding probabilities. */
        
   /* Default MV decoding probabilities. */
        

const MV_CONTEXT default_mv_context[2] = { { // row 162, // is short 128, // sign 225, 146, 172, 147, 214, 39, 156, // short tree 128, 129, 132, 75, 145, 178, 206, 239, 254, 254 // long bits },

const MV_CONTEXT default_MV_CONTEXT[2]={{//row 162,//短128,//符号225、146、172、147、214、39、156,//短树128、129、132、75、145、178、206、239、254、254//长位},

     {                       // same for column
       164,                    // is short
       128,
       204, 170, 119, 235, 140, 230, 228,
       128, 130, 130,  74, 148, 180, 203, 236, 254, 254 // long bits
        
     {                       // same for column
       164,                    // is short
       128,
       204, 170, 119, 235, 140, 230, 228,
       128, 130, 130,  74, 148, 180, 203, 236, 254, 254 // long bits
        
     }
   };
        
     }
   };
        
   /* Current MV decoding probabilities, set to above defaults
      every key frame. */
        
   /* Current MV decoding probabilities, set to above defaults
      every key frame. */
        
   MV_CONTEXT mvc [2];     /* always row, then column */
        
   MV_CONTEXT mvc [2];     /* always row, then column */
        
   /* Procedure for decoding a complete motion vector. */
        
   /* Procedure for decoding a complete motion vector. */
        
   typedef struct { int16 row, col;}  MV;  /* as in previous section */
        
   typedef struct { int16 row, col;}  MV;  /* as in previous section */
        
   MV read_mv(bool_decoder *d)
   {
       MV v;
       v.row = (int16) read_mvcomponent(d, mvc);
       v.col = (int16) read_mvcomponent(d, mvc + 1);
       return v;
   }
        
   MV read_mv(bool_decoder *d)
   {
       MV v;
       v.row = (int16) read_mvcomponent(d, mvc);
       v.col = (int16) read_mvcomponent(d, mvc + 1);
       return v;
   }
        
   /* Procedure for updating MV decoding probabilities, called
      every interframe with "d" at the appropriate position in
      the frame header. */
        
   /* Procedure for updating MV decoding probabilities, called
      every interframe with "d" at the appropriate position in
      the frame header. */
        
   void update_mvcontexts(bool_decoder *d)
   {
       int i = 0;
       do {                      /* component = row, then column */
           const Prob *up = mv_update_probs[i];    /* update probs
                                                      for component */
           Prob *p = mvc[i];                  /* start decode tbl "" */
           Prob * const pstop = p + MVPcount; /* end decode tbl "" */
           do {
               if (read_bool(d, *up++))     /* update this position */
               {
                   const Prob x = read_literal(d, 7);
        
   void update_mvcontexts(bool_decoder *d)
   {
       int i = 0;
       do {                      /* component = row, then column */
           const Prob *up = mv_update_probs[i];    /* update probs
                                                      for component */
           Prob *p = mvc[i];                  /* start decode tbl "" */
           Prob * const pstop = p + MVPcount; /* end decode tbl "" */
           do {
               if (read_bool(d, *up++))     /* update this position */
               {
                   const Prob x = read_literal(d, 7);
        
                   *p = x? x<<1 : 1;
               }
           } while (++p < pstop);              /* next position */
       } while (++i < 2);                      /* next component */
   }
        
                   *p = x? x<<1 : 1;
               }
           } while (++p < pstop);              /* next position */
       } while (++i < 2);                      /* next component */
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

This completes the description of the motion-vector decoding procedure and, with it, the procedure for decoding interframe macroblock prediction records.

这就完成了对运动矢量解码过程的描述,以及对帧间宏块预测记录进行解码的过程的描述。

18. Interframe Prediction
18. 帧间预测

Given an inter-prediction specification for the current macroblock, that is, a reference frame together with a motion vector for each of the sixteen Y subblocks, we describe the calculation of the prediction buffer for the macroblock. Frame reconstruction is then completed via the previously described processes of residue summation (Section 14) and loop filtering (Section 15).

给定当前宏块的帧间预测规范,即16个Y子块中的每个的参考帧和运动向量,我们描述宏块的预测缓冲器的计算。然后,通过前面描述的剩余求和(第14节)和循环滤波(第15节)过程完成帧重建。

The management of inter-predicted subblocks and sub-pixel interpolation may be found in the reference decoder file predict.c (Section 20.14).

帧间预测子块和子像素插值的管理可在参考解码器文件predict.c(第20.14节)中找到。

18.1. Bounds on, and Adjustment of, Motion Vectors
18.1. 运动矢量的边界和调整

Since each motion vector is differentially encoded from a neighboring block or macroblock and the only clamp is to ensure that the referenced motion vector represents a valid location inside a reference frame buffer, it is technically possible within the VP8 format for a block or macroblock to have arbitrarily large motion vectors, up to the size of the input image plus the extended border areas. For practical reasons, VP8 imposes a motion vector size range limit of -4096 to 4095 full pixels, regardless of image size (VP8 defines 14 raw bits for width and height; 16383x16383 is the maximum possible image size). Bitstream-compliant encoders and decoders shall enforce this limit.

由于每个运动矢量从相邻块或宏块进行差分编码,并且唯一的钳制是确保参考运动矢量表示参考帧缓冲器内的有效位置,因此在VP8格式中,块或宏块具有任意大的运动矢量在技术上是可能的,最大为输入图像的大小加上扩展的边界区域。出于实际原因,VP8将运动矢量大小范围限制为-4096到4095个完整像素,而不考虑图像大小(VP8定义了14个原始位的宽度和高度;163816383是可能的最大图像大小)。符合比特流的编码器和解码器应执行此限制。

Because the motion vectors applied to the chroma subblocks have 1/8-pixel resolution, the synthetic pixel calculation, outlined in Section 5 and detailed below, uses this resolution for the luma subblocks as well. In accordance, the stored luma motion vectors are all doubled, each component of each luma vector becoming an even integer in the range -2046 to +2046, inclusive.

由于应用于色度子块的运动矢量具有1/8像素分辨率,因此第5节中概述并在下文详述的合成像素计算也将该分辨率用于亮度子块。相应地,存储的luma运动向量全部加倍,每个luma向量的每个分量成为-2046到+2046(包括-2046到+2046)范围内的偶数整数。

The vector applied to each chroma subblock is calculated by averaging the vectors for the 4 luma subblocks occupying the same visible area as the chroma subblock in the usual correspondence; that is, the vector for U and V block 0 is the average of the vectors for the Y subblocks { 0, 1, 4, 5}, chroma block 1 corresponds to Y blocks { 2, 3, 6, 7}, chroma block 2 to Y blocks { 8, 9, 12, 13}, and chroma block 3 to Y blocks { 10, 11, 14, 15}.

应用于每个色度子块的向量是通过对占据与通常对应中的色度子块相同可见区域的4个luma子块的向量求平均来计算的;即,U和V块0的向量是Y子块{0、1、4、5}的向量的平均值,色度块1对应于Y块{2、3、6、7},色度块2对应于Y块{8、9、12、13},色度块3对应于Y块{10、11、14、15}。

In detail, each of the two components of the vectors for each of the chroma subblocks is calculated from the corresponding luma vector components as follows:

具体而言,根据相应的亮度向量分量计算每个色度子块的向量的两个分量中的每一个,如下所示:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   int avg(int c1, int c2, int c3, int c4)
   {
       int s = c1 + c2 + c3 + c4;
        
   int avg(int c1, int c2, int c3, int c4)
   {
       int s = c1 + c2 + c3 + c4;
        
       /* The shift divides by 8 (not 4) because chroma pixels
          have twice the diameter of luma pixels.  The handling
          of negative motion vector components is slightly
          cumbersome because, strictly speaking, right shifts
          of negative numbers are not well-defined in C. */
        
       /* The shift divides by 8 (not 4) because chroma pixels
          have twice the diameter of luma pixels.  The handling
          of negative motion vector components is slightly
          cumbersome because, strictly speaking, right shifts
          of negative numbers are not well-defined in C. */
        
       return s >= 0 ?  (s + 4) >> 3 : -((-s + 4) >> 3);
   }
        
       return s >= 0 ?  (s + 4) >> 3 : -((-s + 4) >> 3);
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Furthermore, if the version number in the frame tag specifies only full-pel chroma motion vectors, then the fractional parts of both components of the vector are truncated to zero, as illustrated in the following pseudocode (assuming 3 bits of fraction for both luma and chroma vectors):

此外,如果帧标签中的版本号仅指定完整像素色度运动向量,则向量的两个分量的分数部分被截断为零,如以下伪码中所示(假设亮度和色度向量的分数均为3位):

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
       x = x & (~7);
       y = y & (~7);
        
       x = x & (~7);
       y = y & (~7);
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Earlier in this document we described the vp8_clamp_mv() function to limit "nearest" and "near" motion vector predictors inside specified margins within the frame boundaries. Additional clamping is performed for NEWMV macroblocks, for which the final motion vector is clamped again after combining the "best" predictor and the differential vector decoded from the stream.

在本文档前面,我们描述了vp8_clamp_mv()函数,该函数用于将“最近”和“近”运动矢量预测器限制在帧边界内指定的边距内。对NEWMV宏块执行附加箝位,在组合“最佳”预测器和从流解码的差分向量之后,对其再次箝位最终运动向量。

However, the secondary clamping is not performed for SPLITMV macroblocks, meaning that any subblock's motion vector within the SPLITMV macroblock may point outside the clamping zone. These non-clamped vectors are also used when determining the decoding tree context for subsequent subblocks' modes in the vp8_mvCont() function.

然而,不针对SPLITMV宏块执行二次箝位,这意味着SPLITMV宏块内的任何子块的运动矢量可能指向箝位区域之外。在vp8_mvCont()函数中确定后续子块模式的解码树上下文时,也使用这些非钳位向量。

18.2. Prediction Subblocks
18.2. 预测子块

The prediction calculation for each subblock is then as follows. Temporarily disregarding the fractional part of the motion vector (that is, rounding "up" or "left" by right-shifting each component 3 bits with sign propagation) and adding the origin (upper left position) of the (16x16 luma or 8x8 chroma) current macroblock gives us an origin in the Y, U, or V plane of the predictor frame (either the golden frame or previous frame).

每个子块的预测计算如下所示。暂时忽略运动矢量的分数部分(即,通过符号传播将每个分量右移3位来“向上”或“向左”取整),并添加(16x16 luma或8x8色度)当前宏块的原点(左上位置),我们可以在预测器帧的Y、U或V平面中获得原点(金色边框或上一个边框)。

Considering that origin to be the upper left corner of a (luma or chroma) macroblock, we need to specify the relative positions of the pixels associated to that subblock, that is, any pixels that might be involved in the sub-pixel interpolation processes for the subblock.

考虑到原点是(亮度或色度)宏块的左上角,我们需要指定与该子块相关联的像素的相对位置,即,可能涉及子块的子像素插值过程的任何像素。

18.3. Sub-Pixel Interpolation
18.3. 亚像素插值

The sub-pixel interpolation is effected via two one-dimensional convolutions. These convolutions may be thought of as operating on a two-dimensional array of pixels whose origin is the subblock origin, that is the origin of the prediction macroblock described above plus the offset to the subblock. Because motion vectors are arbitrary, so are these "prediction subblock origins".

亚像素插值通过两个一维卷积实现。这些卷积可以被认为是在其原点是子块原点的像素的二维阵列上操作的,该子块原点是上述预测宏块的原点加上到子块的偏移。因为运动矢量是任意的,所以这些“预测子块原点”也是任意的。

The integer part of the motion vector is subsumed in the origin of the prediction subblock; the 16 (synthetic) pixels we need to construct are given by 16 offsets from the origin. The integer part of each of these offsets is the offset of the corresponding pixel from the subblock origin (using the vertical stride). To these integer parts is added a constant fractional part, which is simply the difference between the actual motion vector and its integer truncation used to calculate the origins of the prediction macroblock and subblock. Each component of this fractional part is an integer between 0 and 7, representing a forward displacement in eighths of a pixel.

运动矢量的整数部分包含在预测子块的原点中;我们需要构造的16个(合成)像素由距原点的16个偏移量给出。每个偏移的整数部分是对应像素相对于子块原点的偏移(使用垂直步幅)。向这些整数部分添加一个常量分数部分,该部分仅为实际运动矢量与其整数截断之间的差值,用于计算预测宏块和子块的原点。该分数部分的每个分量都是0到7之间的整数,表示八分之一像素的正向位移。

It is these fractional displacements that determine the filtering process. If they both happen to be zero (that is, we had a "whole pixel" motion vector), the prediction subblock is simply copied into the corresponding piece of the current macroblock's prediction buffer. As discussed in Section 14, the layout of the macroblock's prediction buffer can depend on the specifics of the reconstruction implementation chosen. Of course, the vertical displacement between lines of the prediction subblock is given by the stride, as are all vertical displacements used here.

正是这些分数位移决定了过滤过程。如果它们恰好都为零(即,我们有一个“整像素”运动矢量),则预测子块将被简单地复制到当前宏块的预测缓冲区的相应部分中。如第14节中所讨论的,宏块的预测缓冲器的布局可以取决于所选择的重建实现的细节。当然,预测子块行之间的垂直位移由步幅给出,这里使用的所有垂直位移也是如此。

Otherwise, at least one of the fractional displacements is non-zero. We then synthesize the missing pixels via a horizontal, followed by a vertical, one-dimensional interpolation.

否则,至少一个分数位移为非零。然后,我们通过一个水平的,然后是一个垂直的,一维插值合成丢失的像素。

The two interpolations are essentially identical. Each uses a (at most) six-tap filter (the choice of which of course depends on the one-dimensional offset). Thus, every calculated pixel references at most three pixels before (above or to the left of) it and at most three pixels after (below or to the right of) it. The horizontal interpolation must calculate two extra rows above and three extra rows below the 4x4 block, to provide enough samples for the vertical interpolation to proceed.

这两种插值基本相同。每个都使用(最多)六抽头滤波器(当然,其选择取决于一维偏移)。因此,每个计算的像素在其前面(上方或左侧)最多参考三个像素,在其后面(下方或右侧)最多参考三个像素。水平插值必须计算4x4块上方的两个额外行和下方的三个额外行,以便为垂直插值提供足够的样本。

Depending on the reconstruction filter type given in the version number field in the frame tag, either a bicubic or a bilinear tap set is used.

根据帧标记的版本号字段中给定的重建过滤器类型,使用双三次或双线性抽头集。

The exact implementation of subsampling is as follows.

子采样的具体实现如下所示。

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /* Filter taps taken to 7-bit precision.
      Because DC is always passed, taps always sum to 128. */
        
   /* Filter taps taken to 7-bit precision.
      Because DC is always passed, taps always sum to 128. */
        
   const int BilinearFilters[8][6] =
   {
       { 0, 0, 128,   0, 0, 0 },
       { 0, 0, 112,  16, 0, 0 },
       { 0, 0,  96,  32, 0, 0 },
       { 0, 0,  80,  48, 0, 0 },
       { 0, 0,  64,  64, 0, 0 },
       { 0, 0,  48,  80, 0, 0 },
       { 0, 0,  32,  96, 0, 0 },
       { 0, 0,  16, 112, 0, 0 }
   };
        
   const int BilinearFilters[8][6] =
   {
       { 0, 0, 128,   0, 0, 0 },
       { 0, 0, 112,  16, 0, 0 },
       { 0, 0,  96,  32, 0, 0 },
       { 0, 0,  80,  48, 0, 0 },
       { 0, 0,  64,  64, 0, 0 },
       { 0, 0,  48,  80, 0, 0 },
       { 0, 0,  32,  96, 0, 0 },
       { 0, 0,  16, 112, 0, 0 }
   };
        
   const int filters [8] [6] = {        /* indexed by displacement */
       { 0,  0,  128,    0,   0,  0 },  /* degenerate whole-pixel */
       { 0, -6,  123,   12,  -1,  0 },  /* 1/8 */
       { 2, -11, 108,   36,  -8,  1 },  /* 1/4 */
       { 0, -9,   93,   50,  -6,  0 },  /* 3/8 */
       { 3, -16,  77,   77, -16,  3 },  /* 1/2 is symmetric */
       { 0, -6,   50,   93,  -9,  0 },  /* 5/8 = reverse of 3/8 */
       { 1, -8,   36,  108, -11,  2 },  /* 3/4 = reverse of 1/4 */
       { 0, -1,   12,  123,  -6,  0 }   /* 7/8 = reverse of 1/8 */
   };
        
   const int filters [8] [6] = {        /* indexed by displacement */
       { 0,  0,  128,    0,   0,  0 },  /* degenerate whole-pixel */
       { 0, -6,  123,   12,  -1,  0 },  /* 1/8 */
       { 2, -11, 108,   36,  -8,  1 },  /* 1/4 */
       { 0, -9,   93,   50,  -6,  0 },  /* 3/8 */
       { 3, -16,  77,   77, -16,  3 },  /* 1/2 is symmetric */
       { 0, -6,   50,   93,  -9,  0 },  /* 5/8 = reverse of 3/8 */
       { 1, -8,   36,  108, -11,  2 },  /* 3/4 = reverse of 1/4 */
       { 0, -1,   12,  123,  -6,  0 }   /* 7/8 = reverse of 1/8 */
   };
        
   /* One-dimensional synthesis of a single sample.
      Filter is determined by fractional displacement */
        
   /* One-dimensional synthesis of a single sample.
      Filter is determined by fractional displacement */
        
   Pixel interp(
       const int fil[6],   /* filter to apply */
       const Pixel *p,     /* origin (rounded "before") in
                              prediction area */
       const int s         /* size of one forward step "" */
   ) {
       int32 a = 0;
       int i = 0;
       p -= s + s;         /* move back two positions */
        
   Pixel interp(
       const int fil[6],   /* filter to apply */
       const Pixel *p,     /* origin (rounded "before") in
                              prediction area */
       const int s         /* size of one forward step "" */
   ) {
       int32 a = 0;
       int i = 0;
       p -= s + s;         /* move back two positions */
        
       do {
           a += *p * fil[i];
           p += s;
       }  while (++i < 6);
        
       do {
           a += *p * fil[i];
           p += s;
       }  while (++i < 6);
        
       return clamp255((a + 64) >> 7);    /* round to nearest
                                              8-bit value */
   }
        
       return clamp255((a + 64) >> 7);    /* round to nearest
                                              8-bit value */
   }
        
   /* First do horizontal interpolation, producing intermediate
      buffer. */
        
   /* First do horizontal interpolation, producing intermediate
      buffer. */
        
   void Hinterp(
       Pixel temp[9][4],   /* 9 rows of 4 (intermediate)
                              destination values */
       const Pixel *p,     /* subblock origin in prediction
                              frame */
       int s,              /* vertical stride to be used in
                              prediction frame */
       uint hfrac,         /* 0 <= horizontal displacement <= 7 */
       uint bicubic        /* 1=bicubic filter, 0=bilinear */
   ) {
       const int * const fil = bicubic ? filters [hfrac] :
         BilinearFilters[hfrac];
        
   void Hinterp(
       Pixel temp[9][4],   /* 9 rows of 4 (intermediate)
                              destination values */
       const Pixel *p,     /* subblock origin in prediction
                              frame */
       int s,              /* vertical stride to be used in
                              prediction frame */
       uint hfrac,         /* 0 <= horizontal displacement <= 7 */
       uint bicubic        /* 1=bicubic filter, 0=bilinear */
   ) {
       const int * const fil = bicubic ? filters [hfrac] :
         BilinearFilters[hfrac];
        
       int r = 0;  do              /* for each row */
       {
           int c = 0;  do          /* for each destination sample */
           {
               /* Pixel separation = one horizontal step = 1 */
        
       int r = 0;  do              /* for each row */
       {
           int c = 0;  do          /* for each destination sample */
           {
               /* Pixel separation = one horizontal step = 1 */
        
               temp[r][c] = interp(fil, p + c, 1);
           }
        
               temp[r][c] = interp(fil, p + c, 1);
           }
        
           while (++c < 4);
       }
       while (p += s, ++r < 9);    /* advance p to next row */
   }
        
           while (++c < 4);
       }
       while (p += s, ++r < 9);    /* advance p to next row */
   }
        
   /* Finish with vertical interpolation, producing final results.
      Input array "temp" is of course that computed above. */
        
   /* Finish with vertical interpolation, producing final results.
      Input array "temp" is of course that computed above. */
        
   void Vinterp(
       Pixel final[4][4],  /* 4 rows of 4 (final) destination values */
       const Pixel temp[9][4],
       uint vfrac,         /* 0 <= vertical displacement <= 7 */
       uint bicubic        /* 1=bicubic filter, 0=bilinear */
   ) {
       const int * const fil = bicubic ? filters [vfrac] :
         BilinearFilters[vfrac];
        
   void Vinterp(
       Pixel final[4][4],  /* 4 rows of 4 (final) destination values */
       const Pixel temp[9][4],
       uint vfrac,         /* 0 <= vertical displacement <= 7 */
       uint bicubic        /* 1=bicubic filter, 0=bilinear */
   ) {
       const int * const fil = bicubic ? filters [vfrac] :
         BilinearFilters[vfrac];
        
       int r = 0;  do              /* for each row */
       {
           int c = 0;  do          /* for each destination sample */
           {
               /* Pixel separation = one vertical step = width
                  of array = 4 */
        
       int r = 0;  do              /* for each row */
       {
           int c = 0;  do          /* for each destination sample */
           {
               /* Pixel separation = one vertical step = width
                  of array = 4 */
        
               final[r][c] = interp(fil, temp[r] + c, 4);
           }
           while (++c < 4);
       }
       while (++r < 4);
   }
        
               final[r][c] = interp(fil, temp[r] + c, 4);
           }
           while (++c < 4);
       }
       while (++r < 4);
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
18.4. Filter Properties
18.4. 过滤器特性

We discuss briefly the rationale behind the choice of filters. Our approach is necessarily cursory; a genuinely accurate discussion would require a couple of books. Readers unfamiliar with signal processing may or may not wish to skip this.

我们简要讨论了选择滤波器的基本原理。我们的做法必然是草率的;真正准确的讨论需要几本书。不熟悉信号处理的读者可能希望也可能不希望跳过这一步。

All digital signals are of course sampled in some fashion. The case where the inter-sample spacing (say in time for audio samples, or space for pixels) is uniform, that is, the same at all positions, is particularly common and amenable to analysis. Many aspects of the treatment of such signals are best-understood in the frequency domain via Fourier Analysis, particularly those aspects of the signal that are not changed by shifts in position, especially when those positional shifts are not given by a whole number of samples.

当然,所有数字信号都是以某种方式采样的。样本间间隔(例如,对于音频样本的时间间隔,或者对于像素的空间)是均匀的(即,在所有位置上相同)的情况尤其常见并且易于分析。通过傅里叶分析,在频域中最好地理解此类信号处理的许多方面,尤其是那些不因位置偏移而改变的信号方面,尤其是当这些位置偏移不是由整数个样本给出时。

Non-integral translates of a sampled signal are a textbook example of the foregoing. In our case of non-integral motion vectors, we wish to say what the underlying image "really is" at these pixels; although we don't have values for them, we feel that it makes sense to talk about them. The correctness of this feeling is predicated on the underlying signal being band-limited, that is, not containing any energy in spatial frequencies that cannot be faithfully rendered at the pixel resolution at our disposal. In one dimension, this range of "OK" frequencies is called the Nyquist band; in our two-dimensional case of integer-grid samples, this range might be termed a Nyquist rectangle. The finer the grid, the more we know about the image, and the wider the Nyquist rectangle.

采样信号的非积分平移是前述的教科书示例。在我们的非积分运动矢量的例子中,我们希望说明这些像素处的基础图像“实际上是什么”;虽然我们对他们没有价值观,但我们觉得谈论他们是有意义的。这种感觉的正确性取决于基本信号的带宽限制,即不包含空间频率中的任何能量,这些能量无法以像素分辨率忠实呈现。在一维中,这种“OK”频率范围称为奈奎斯特频带;在整数网格样本的二维情况下,这个范围可以称为奈奎斯特矩形。网格越细,我们对图像的了解就越多,奈奎斯特矩形越宽。

It turns out that, for such band-limited signals, there is indeed an exact mathematical formula to produce the correct sample value at an arbitrary point. Unfortunately, this calculation requires the consideration of every single sample in the image, as well as needing to operate at infinite precision. Also, strictly speaking, all band-limited signals have infinite spatial (or temporal) extent, so everything we are discussing is really some sort of approximation.

事实证明,对于这种带限信号,确实存在一个精确的数学公式,可以在任意点产生正确的采样值。不幸的是,此计算需要考虑图像中的每个样本,并且需要以无限精度进行操作。而且,严格地说,所有带限信号都有无限的空间(或时间)范围,所以我们讨论的一切实际上都是某种近似。

It is true that the theoretically correct subsampling procedure, as well as any approximation thereof, is always given by a translation-invariant weighted sum (or filter) similar to that used by VP8. It is also true that the reconstruction error made by such a filter can be simply represented as a multiplier in the frequency domain; that is, such filters simply multiply the Fourier transform of any signal to which they are applied by a fixed function associated to the filter. This fixed function is usually called the frequency response (or transfer function); the ideal subsampling filter has a frequency response equal to one in the Nyquist rectangle and zero everywhere else.

的确,理论上正确的子采样过程及其任何近似值总是由平移不变加权和(或滤波器)给出,类似于VP8所使用的方法。同样,这种滤波器产生的重构误差可以简单地表示为频域中的乘法器;也就是说,这种滤波器只是将其应用到的任何信号的傅里叶变换乘以与滤波器相关联的固定函数。这种固定函数通常称为频率响应(或传递函数);理想的子采样滤波器的频率响应在奈奎斯特矩形中等于一,在其他地方等于零。

Another basic fact about approximations to "truly correct" subsampling is that the wider the subrectangle (within the Nyquist rectangle) of spatial frequencies one wishes to "pass" (that is, correctly render) or, put more accurately, the closer one wishes to approximate the ideal transfer function, the more samples of the original signal must be considered by the subsampling, and the wider the calculation precision necessitated.

关于近似“真正正确”子采样的另一个基本事实是,希望“通过”(即正确渲染)的空间频率的子矩形(在奈奎斯特矩形内)越宽,或者更准确地说,希望近似理想传递函数的子矩形越近,子采样必须考虑的原始信号样本越多,计算精度就越高。

The filters chosen by VP8 were chosen, within the constraints of 4 or 6 taps and 7-bit precision, to do the best possible job of handling the low spatial frequencies near the 0th DC frequency along with introducing no resonances (places where the absolute value of the frequency response exceeds one).

VP8选择的滤波器在4或6抽头和7位精度的限制范围内,尽可能最好地处理第0个直流频率附近的低空间频率,同时不引入共振(频率响应的绝对值超过1的地方)。

The justification for the foregoing has two parts. First, resonances can produce extremely objectionable visible artifacts when, as often happens in actual compressed video streams, filters are applied repeatedly. Second, the vast majority of energy in real-world images lies near DC and not at the high end.

上述理由分为两部分。首先,当反复应用滤波器时,共振会产生非常令人讨厌的可见伪影,这在实际压缩视频流中经常发生。第二,现实世界图像中的绝大多数能量位于直流附近,而不是高端。

To get slightly more specific, the filters chosen by VP8 are the best resonance-free 4- or 6-tap filters possible, where "best" describes the frequency response near the origin: The response at 0 is required to be 1, and the graph of the response at 0 is as flat as possible.

更具体地说,VP8选择的滤波器是最好的无共振4抽头或6抽头滤波器,其中“最佳”描述原点附近的频率响应:0处的响应要求为1,0处的响应曲线尽可能平坦。

To provide an intuitively more obvious point of reference, the "best" 2-tap filter is given by simple linear interpolation between the surrounding actual pixels.

为了提供更直观的参考点,“最佳”2抽头滤波器通过周围实际像素之间的简单线性插值给出。

Finally, it should be noted that, because of the way motion vectors are calculated, the (shorter) 4-tap filters (used for odd fractional displacements) are applied in the chroma plane only. Human color perception is notoriously poor, especially where higher spatial frequencies are involved. The shorter filters are easier to understand mathematically, and the difference between them and a theoretically slightly better 6-tap filter is negligible where chroma is concerned.

最后,应注意,由于计算运动矢量的方式,仅在色度平面中应用(较短的)4抽头滤波器(用于奇数分数位移)。人类的颜色感知能力是出了名的差,尤其是在涉及更高空间频率的情况下。较短的滤波器在数学上更容易理解,它们与理论上稍好的6抽头滤波器之间的差异在色度方面可以忽略不计。

19. Annex A: Bitstream Syntax
19. 附件A:比特流语法

This annex presents the bitstream syntax in a tabular form. All the information elements have been introduced and explained in the previous sections but are collected here for a quick reference. Each syntax element is briefly described after the tabular representation along with a reference to the corresponding paragraph in the main document. The meaning of each syntax element value is not repeated here.

本附录以表格形式提供了位流语法。所有的信息元素都在前面的章节中介绍和解释过,但这里收集的信息仅供快速参考。每个语法元素在表格表示法之后进行简要描述,并参考主文档中的相应段落。这里不重复每个语法元素值的含义。

The top-level hierarchy of the bitstream is introduced in Section 4.

第4节介绍了比特流的顶级层次结构。

Definition of syntax element coding types can be found in Section 8. The types used in the representation in this annex are:

语法元素编码类型的定义见第8节。本附件中表示中使用的类型为:

o f(n), n-bit value from stream (n successive bits, not boolean encoded)

o f(n),来自流的n位值(n个连续位,非布尔编码)

o L(n), n-bit number encoded as n booleans (with equal probability of being 0 or 1)

o L(n),编码为n布尔的n位数字(0或1的概率相等)

o B(p), bool with probability p of being 0

o 概率p为0的B(p),bool

o T, tree-encoded value

o T、 树编码值

19.1. Uncompressed Data Chunk
19.1. 未压缩数据块
   | Frame Tag                                         | Type  |
   | ------------------------------------------------- | ----- |
   | frame_tag                                         | f(24) |
   | if (key_frame) {                                  |       |
   |     start_code                                    | f(24) |
   |     horizontal_size_code                          | f(16) |
   |     vertical_size_code                            | f(16) |
   | }                                                 |       |
        
   | Frame Tag                                         | Type  |
   | ------------------------------------------------- | ----- |
   | frame_tag                                         | f(24) |
   | if (key_frame) {                                  |       |
   |     start_code                                    | f(24) |
   |     horizontal_size_code                          | f(16) |
   |     vertical_size_code                            | f(16) |
   | }                                                 |       |
        

The 3-byte frame tag can be parsed as follows:

3字节帧标记可以按如下方式解析:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   unsigned char *c = pbi->source;
   unsigned int tmp;
        
   unsigned char *c = pbi->source;
   unsigned int tmp;
        
   tmp = (c[2] << 16) | (c[1] << 8) | c[0];
        
   tmp = (c[2] << 16) | (c[1] << 8) | c[0];
        
   key_frame = tmp & 0x1;
   version = (tmp >> 1) & 0x7;
   show_frame = (tmp >> 4) & 0x1;
   first_part_size = (tmp >> 5) & 0x7FFFF;
        
   key_frame = tmp & 0x1;
   version = (tmp >> 1) & 0x7;
   show_frame = (tmp >> 4) & 0x1;
   first_part_size = (tmp >> 5) & 0x7FFFF;
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        

Where:

哪里:

o key_frame indicates whether the current frame is a key frame or not.

o 关键帧指示当前帧是否为关键帧。

o version determines the bitstream version.

o 版本决定比特流的版本。

o show_frame indicates whether the current frame is meant to be displayed or not.

o show_frame指示是否要显示当前帧。

o first_part_size determines the size of the first partition (control partition), excluding the uncompressed data chunk.

o 第一部分大小决定第一个分区(控制分区)的大小,不包括未压缩的数据块。

The start_code is a constant 3-byte pattern having value 0x9d012a. The latter part of the uncompressed chunk (after the start_code) can be parsed as follows:

start_代码是一个恒定的3字节模式,其值为0x9d012a。未压缩块的后半部分(在start_代码之后)可以按如下方式解析:

   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   unsigned char *c = pbi->source + 6;
   unsigned int tmp;
        
   unsigned char *c = pbi->source + 6;
   unsigned int tmp;
        
   tmp = (c[1] << 8) | c[0];
        
   tmp = (c[1] << 8) | c[0];
        
   width = tmp & 0x3FFF;
   horizontal_scale = tmp >> 14;
        
   width = tmp & 0x3FFF;
   horizontal_scale = tmp >> 14;
        
   tmp = (c[3] << 8) | c[2];
        
   tmp = (c[3] << 8) | c[2];
        
   height = tmp & 0x3FFF;
   vertical_scale = tmp >> 14;
        
   height = tmp & 0x3FFF;
   vertical_scale = tmp >> 14;
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
19.2. Frame Header
19.2. 帧头
   | Frame Header                                      | Type  |
   | ------------------------------------------------- | ----- |
   | if (key_frame) {                                  |       |
   |   color_space                                     | L(1)  |
   |   clamping_type                                   | L(1)  |
   | }                                                 |       |
   | segmentation_enabled                              | L(1)  |
   | if (segmentation_enabled)                         |       |
   |   update_segmentation()                           |       |
   | filter_type                                       | L(1)  |
   | loop_filter_level                                 | L(6)  |
   | sharpness_level                                   | L(3)  |
   | mb_lf_adjustments()                               |       |
   | log2_nbr_of_dct_partitions                        | L(2)  |
   | quant_indices()                                   |       |
   | if (key_frame)                                    |       |
   |   refresh_entropy_probs                           | L(1)  |
        
   | Frame Header                                      | Type  |
   | ------------------------------------------------- | ----- |
   | if (key_frame) {                                  |       |
   |   color_space                                     | L(1)  |
   |   clamping_type                                   | L(1)  |
   | }                                                 |       |
   | segmentation_enabled                              | L(1)  |
   | if (segmentation_enabled)                         |       |
   |   update_segmentation()                           |       |
   | filter_type                                       | L(1)  |
   | loop_filter_level                                 | L(6)  |
   | sharpness_level                                   | L(3)  |
   | mb_lf_adjustments()                               |       |
   | log2_nbr_of_dct_partitions                        | L(2)  |
   | quant_indices()                                   |       |
   | if (key_frame)                                    |       |
   |   refresh_entropy_probs                           | L(1)  |
        
   | else {                                            |       |
   |   refresh_golden_frame                            | L(1)  |
   |   refresh_alternate_frame                         | L(1)  |
   |   if (!refresh_golden_frame)                      |       |
   |     copy_buffer_to_golden                         | L(2)  |
   |   if (!refresh_alternate_frame)                   |       |
   |     copy_buffer_to_alternate                      | L(2)  |
   |   sign_bias_golden                                | L(1)  |
   |   sign_bias_alternate                             | L(1)  |
   |   refresh_entropy_probs                           | L(1)  |
   |   refresh_last                                    | L(1)  |
   | }                                                 |       |
   | token_prob_update()                               |       |
   | mb_no_skip_coeff                                  | L(1)  |
   | if (mb_no_skip_coeff)                             |       |
   |   prob_skip_false                                 | L(8)  |
   | if (!key_frame) {                                 |       |
   |   prob_intra                                      | L(8)  |
   |   prob_last                                       | L(8)  |
   |   prob_gf                                         | L(8)  |
   |   intra_16x16_prob_update_flag                    | L(1)  |
   |   if (intra_16x16_prob_update_flag) {             |       |
   |     for (i = 0; i < 4; i++)                       |       |
   |       intra_16x16_prob                            | L(8)  |
   |   }                                               |       |
   |   intra_chroma prob_update_flag                   | L(1)  |
   |   if (intra_chroma_prob_update_flag) {            |       |
   |     for (i = 0; i < 3; i++)                       |       |
   |       intra_chroma_prob                           | L(8)  |
   |   }                                               |       |
   |   mv_prob_update()                                |       |
   | }                                                 |       |
        
   | else {                                            |       |
   |   refresh_golden_frame                            | L(1)  |
   |   refresh_alternate_frame                         | L(1)  |
   |   if (!refresh_golden_frame)                      |       |
   |     copy_buffer_to_golden                         | L(2)  |
   |   if (!refresh_alternate_frame)                   |       |
   |     copy_buffer_to_alternate                      | L(2)  |
   |   sign_bias_golden                                | L(1)  |
   |   sign_bias_alternate                             | L(1)  |
   |   refresh_entropy_probs                           | L(1)  |
   |   refresh_last                                    | L(1)  |
   | }                                                 |       |
   | token_prob_update()                               |       |
   | mb_no_skip_coeff                                  | L(1)  |
   | if (mb_no_skip_coeff)                             |       |
   |   prob_skip_false                                 | L(8)  |
   | if (!key_frame) {                                 |       |
   |   prob_intra                                      | L(8)  |
   |   prob_last                                       | L(8)  |
   |   prob_gf                                         | L(8)  |
   |   intra_16x16_prob_update_flag                    | L(1)  |
   |   if (intra_16x16_prob_update_flag) {             |       |
   |     for (i = 0; i < 4; i++)                       |       |
   |       intra_16x16_prob                            | L(8)  |
   |   }                                               |       |
   |   intra_chroma prob_update_flag                   | L(1)  |
   |   if (intra_chroma_prob_update_flag) {            |       |
   |     for (i = 0; i < 3; i++)                       |       |
   |       intra_chroma_prob                           | L(8)  |
   |   }                                               |       |
   |   mv_prob_update()                                |       |
   | }                                                 |       |
        

o color_space defines the YUV color space of the sequence (Section 9.2)

o 颜色空间定义序列的YUV颜色空间(第9.2节)

o clamping_type specifies if the decoder is required to clamp the reconstructed pixel values (Section 9.2)

o 钳制类型指定解码器是否需要钳制重构像素值(第9.2节)

o segmentation_enabled enables the segmentation feature for the current frame (Section 9.3)

o segmentation_enabled启用当前帧的分段功能(第9.3节)

o filter_type determines whether the normal or the simple loop filter is used (Sections 9.4, 15)

o 过滤器类型决定使用普通还是简单环路过滤器(第9.4、15节)

o loop_filter_level controls the deblocking filter (Sections 9.4, 15)

o 环路滤波器电平控制去块滤波器(第9.4、15节)

o sharpness_level controls the deblocking filter (Sections 9.4, 15)

o 锐度水平控制去块滤波器(第9.4、15节)

o log2_nbr_of_dct_partitions determines the number of separate partitions containing the DCT coefficients of the macroblocks (Section 9.5)

o dct分区的log2\u nbr\u确定包含宏块dct系数的单独分区的数量(第9.5节)

o refresh_entropy_probs determines whether updated token probabilities are used only for this frame or until further update

o refresh_entropy_probs确定更新的令牌概率是仅用于此帧还是在进一步更新之前使用

o refresh_golden_frame determines if the current decoded frame refreshes the golden frame (Section 9.7)

o 刷新黄金帧确定当前解码帧是否刷新黄金帧(第9.7节)

o refresh_alternate_frame determines if the current decoded frame refreshes the alternate reference frame (Section 9.7)

o refresh_alternate_frame确定当前解码帧是否刷新备用参考帧(第9.7节)

o copy_buffer_to_golden determines if the golden reference is replaced by another reference (Section 9.7)

o 将“缓冲区”复制到“黄金”以确定黄金参考是否被另一参考替换(第9.7节)

o copy_buffer_to_alternate determines if the alternate reference is replaced by another reference (Section 9.7)

o 将“缓冲区”复制到“备用”确定备用参考是否被另一个参考替换(第9.7节)

o sign_bias_golden controls the sign of motion vectors when the golden frame is referenced (Section 9.7)

o 参考黄金帧时,符号\偏差\黄金控制运动矢量的符号(第9.7节)

o sign_bias_alternate controls the sign of motion vectors when the alternate frame is referenced (Section 9.7)

o 符号\偏移\交替控制参考交替帧时运动矢量的符号(第9.7节)

o refresh_last determines if the current decoded frame refreshes the last frame reference buffer (Section 9.8)

o refresh_last确定当前解码帧是否刷新最后一帧参考缓冲区(第9.8节)

o mb_no_skip_coeff enables or disables the skipping of macroblocks containing no non-zero coefficients (Section 9.10)

o mb_no_skip_coeff启用或禁用跳过不包含非零系数的宏块(第9.10节)

o prob_skip_false indicates the probability that the macroblock is not skipped (flag indicating skipped macroblock is false) (Section 9.10)

o prob_skip_false表示宏块未被跳过的概率(表示跳过的宏块为false的标志)(第9.10节)

o prob_intra indicates the probability of an intra macroblock (Section 9.10)

o prob_intra表示帧内宏块的概率(第9.10节)

o prob_last indicates the probability that the last reference frame is used for inter-prediction (Section 9.10)

o prob_last表示最后一个参考帧用于帧间预测的概率(第9.10节)

o prob_gf indicates the probability that the golden reference frame is used for inter-prediction (Section 9.10)

o prob_gf表示黄金参考帧用于帧间预测的概率(第9.10节)

o intra_16x16_prob_update_flag indicates if the branch probabilities used in the decoding of the luma intra-prediction mode are updated (Section 9.10)

o INTERRAL_16x16_prob_update_标志指示luma帧内预测模式解码中使用的分支概率是否更新(第9.10节)

o intra_16x16_prob indicates the branch probabilities of the luma intra-prediction mode decoding tree

o intra_16x16_prob指示luma帧内预测模式解码树的分支概率

o intra_chroma_prob_update_flag indicates if the branch probabilities used in the decoding of the chroma intra-prediction mode are updated (Section 9.10)

o 帧内色度概率更新标志指示在色度帧内预测模式解码中使用的分支概率是否更新(第9.10节)

o intra_chroma_prob indicates the branch probabilities of the chroma intra-prediction mode decoding tree

o intra_chroma_prob指示色度帧内预测模式解码树的分支概率

   | update_segmentation()                             | Type  |
   | ------------------------------------------------- | ----- |
   | update_mb_segmentation_map                        | L(1)  |
   | update_segment_feature_data                       | L(1)  |
   | if (update_segment_feature_data) {                |       |
   |   segment_feature_mode                            | L(1)  |
   |   for (i = 0; i < 4; i++) {                       |       |
   |     quantizer_update                              | L(1)  |
   |     if (quantizer_update) {                       |       |
   |       quantizer_update_value                      | L(7)  |
   |       quantizer_update_sign                       | L(1)  |
   |     }                                             |       |
   |   }                                               |       |
   |   for (i = 0; i < 4; i++) {                       |       |
   |     loop_filter_update                            | L(1)  |
   |     if (loop_filter_update) {                     |       |
   |       lf_update_value                             | L(6)  |
   |       lf_update_sign                              | L(1)  |
   |     }                                             |       |
   |   }                                               |       |
   | }                                                 |       |
   | if (update_mb_segmentation_map) {                 |       |
   |   for (i = 0; i < 3; i++) {                       |       |
   |     segment_prob_update                           | L(1)  |
   |     if (segment_prob_update)                      |       |
   |       segment_prob                                | L(8)  |
   |   }                                               |       |
   | }                                                 |       |
        
   | update_segmentation()                             | Type  |
   | ------------------------------------------------- | ----- |
   | update_mb_segmentation_map                        | L(1)  |
   | update_segment_feature_data                       | L(1)  |
   | if (update_segment_feature_data) {                |       |
   |   segment_feature_mode                            | L(1)  |
   |   for (i = 0; i < 4; i++) {                       |       |
   |     quantizer_update                              | L(1)  |
   |     if (quantizer_update) {                       |       |
   |       quantizer_update_value                      | L(7)  |
   |       quantizer_update_sign                       | L(1)  |
   |     }                                             |       |
   |   }                                               |       |
   |   for (i = 0; i < 4; i++) {                       |       |
   |     loop_filter_update                            | L(1)  |
   |     if (loop_filter_update) {                     |       |
   |       lf_update_value                             | L(6)  |
   |       lf_update_sign                              | L(1)  |
   |     }                                             |       |
   |   }                                               |       |
   | }                                                 |       |
   | if (update_mb_segmentation_map) {                 |       |
   |   for (i = 0; i < 3; i++) {                       |       |
   |     segment_prob_update                           | L(1)  |
   |     if (segment_prob_update)                      |       |
   |       segment_prob                                | L(8)  |
   |   }                                               |       |
   | }                                                 |       |
        

o update_mb_segmentation_map determines if the MB segmentation map is updated in the current frame (Section 9.3)

o update_mb_segmentation_map确定mb segmentation map是否在当前帧中更新(第9.3节)

o update_segment_feature_data indicates if the segment feature data is updated in the current frame (Section 9.3)

o 更新\段\特征\数据表示段特征数据是否在当前帧中更新(第9.3节)

o segment_feature_mode indicates the feature data update mode, 0 for delta and 1 for the absolute value (Section 9.3)

o 段\特征\模式表示特征数据更新模式,0表示增量,1表示绝对值(第9.3节)

o quantizer_update indicates if the quantizer value is updated for the i^(th) segment (Section 9.3)

o 量化器_update表示是否为i^(th)段更新量化器值(第9.3节)

o quantizer_update_value indicates the update value for the segment quantizer (Section 9.3)

o 量化器\更新\值表示段量化器的更新值(第9.3节)

o quantizer_update_sign indicates the update sign for the segment quantizer (Section 9.3)

o 量化器\更新\符号表示段量化器的更新符号(第9.3节)

o loop_filter_update indicates if the loop filter level value is updated for the i^(th) segment (Section 9.3)

o loop_filter_update表示是否为i^(th)段更新了loop过滤器级别值(第9.3节)

o lf_update_value indicates the update value for the loop filter level (Section 9.3)

o lf_update_值表示循环过滤器级别的更新值(第9.3节)

o lf_update_sign indicates the update sign for the loop filter level (Section 9.3)

o lf_update_符号表示循环过滤器级别的更新符号(第9.3节)

o segment_prob_update indicates whether the branch probabilities used to decode the segment_id in the MB header are decoded from the stream or use the default value of 255 (Section 9.3)

o segment_prob_update表示用于解码MB头中的segment_id的分支概率是从流中解码的,还是使用默认值255(第9.3节)

o segment_prob indicates the branch probabilities of the segment_id decoding tree (Section 9.3)

o segment_prob表示segment_id解码树的分支概率(第9.3节)

   | mb_lf_adjustments()                               | Type  |
   | ------------------------------------------------- | ----- |
   | loop_filter_adj_enable                            | L(1)  |
   | if (loop_filter_adj_enable) {                     |       |
   |   mode_ref_lf_delta_update                        | L(1)  |
   |   if (mode_ref_lf_delta_update) {                 |       |
   |     for (i = 0; i < 4; i++) {                     |       |
   |       ref_frame_delta_update_flag                 | L(1)  |
   |       if (ref_frame_delta_update_flag) {          |       |
   |         delta_magnitude                           | L(6)  |
   |         delta_sign                                | L(1)  |
   |       }                                           |       |
   |     }                                             |       |
   |     for (i = 0; i < 4; i++) {                     |       |
   |       mb_mode_delta_update_flag                   | L(1)  |
   |       if (mb_mode_delta_update_flag) {            |       |
   |         delta_magnitude                           | L(6)  |
   |         delta_sign                                | L(1)  |
   |       }                                           |       |
   |     }                                             |       |
   |   }                                               |       |
   | }                                                 |       |
        
   | mb_lf_adjustments()                               | Type  |
   | ------------------------------------------------- | ----- |
   | loop_filter_adj_enable                            | L(1)  |
   | if (loop_filter_adj_enable) {                     |       |
   |   mode_ref_lf_delta_update                        | L(1)  |
   |   if (mode_ref_lf_delta_update) {                 |       |
   |     for (i = 0; i < 4; i++) {                     |       |
   |       ref_frame_delta_update_flag                 | L(1)  |
   |       if (ref_frame_delta_update_flag) {          |       |
   |         delta_magnitude                           | L(6)  |
   |         delta_sign                                | L(1)  |
   |       }                                           |       |
   |     }                                             |       |
   |     for (i = 0; i < 4; i++) {                     |       |
   |       mb_mode_delta_update_flag                   | L(1)  |
   |       if (mb_mode_delta_update_flag) {            |       |
   |         delta_magnitude                           | L(6)  |
   |         delta_sign                                | L(1)  |
   |       }                                           |       |
   |     }                                             |       |
   |   }                                               |       |
   | }                                                 |       |
        

o loop_filter_adj_enable indicates if the MB-level loop filter adjustment (based on the used reference frame and coding mode) is on for the current frame (Section 9.4)

o loop_filter_adj_enable表示当前帧的MB级环路滤波器调整(基于使用的参考帧和编码模式)是否开启(第9.4节)

o mode_ref_lf_delta_update indicates if the delta values used in an adjustment are updated in the current frame (Section 9.4)

o 模式_ref_lf_delta_update表示调整中使用的delta值是否在当前帧中更新(第9.4节)

o ref_frame_delta_update_flag indicates if the adjustment delta value corresponding to a certain used reference frame is updated (Section 9.4)

o ref_frame_delta_update_标志表示是否更新了与某个使用的参考坐标系对应的调整delta值(第9.4节)

o delta_magnitude is the absolute value of the delta value

o delta_震级是delta值的绝对值

o delta_sign is the sign of the delta value

o delta_符号是delta值的符号

o mb_mode_delta_update_flag indicates if the adjustment delta value corresponding to a certain MB prediction mode is updated (Section 9.4)

o mb_mode_delta_update_标志指示是否更新了与某mb预测模式对应的调整delta值(第9.4节)

   | quant_indices()                                   | Type  |
   | ------------------------------------------------- | ----- |
   | y_ac_qi                                           | L(7)  |
   | y_dc_delta_present                                | L(1)  |
   | if (y_dc_delta_present) {                         |       |
   |   y_dc_delta_magnitude                            | L(4)  |
   |   y_dc_delta_sign                                 | L(1)  |
   | }                                                 |       |
   | y2_dc_delta_present                               | L(1)  |
   | if (y2_dc_delta_present) {                        |       |
   |   y2_dc_delta_magnitude                           | L(4)  |
   |   y2_dc_delta_sign                                | L(1)  |
   | }                                                 |       |
   | y2_ac_delta_present                               | L(1)  |
   | if (y2_ac_delta_present) {                        |       |
   |   y2_ac_delta_magnitude                           | L(4)  |
   |   y2_ac_delta_sign                                | L(1)  |
   | }                                                 |       |
   | uv_dc_delta_present                               | L(1)  |
   | if (uv_dc_delta_present) {                        |       |
   |   uv_dc_delta_magnitude                           | L(4)  |
   |   uv_dc_delta_sign                                | L(1)  |
   | }                                                 |       |
   | uv_ac_delta_present                               | L(1)  |
   | if (uv_ac_delta_present) {                        |       |
   |   uv_ac_delta_magnitude                           | L(4)  |
   |   uv_ac_delta_sign                                | L(1)  |
   | }                                                 |       |
        
   | quant_indices()                                   | Type  |
   | ------------------------------------------------- | ----- |
   | y_ac_qi                                           | L(7)  |
   | y_dc_delta_present                                | L(1)  |
   | if (y_dc_delta_present) {                         |       |
   |   y_dc_delta_magnitude                            | L(4)  |
   |   y_dc_delta_sign                                 | L(1)  |
   | }                                                 |       |
   | y2_dc_delta_present                               | L(1)  |
   | if (y2_dc_delta_present) {                        |       |
   |   y2_dc_delta_magnitude                           | L(4)  |
   |   y2_dc_delta_sign                                | L(1)  |
   | }                                                 |       |
   | y2_ac_delta_present                               | L(1)  |
   | if (y2_ac_delta_present) {                        |       |
   |   y2_ac_delta_magnitude                           | L(4)  |
   |   y2_ac_delta_sign                                | L(1)  |
   | }                                                 |       |
   | uv_dc_delta_present                               | L(1)  |
   | if (uv_dc_delta_present) {                        |       |
   |   uv_dc_delta_magnitude                           | L(4)  |
   |   uv_dc_delta_sign                                | L(1)  |
   | }                                                 |       |
   | uv_ac_delta_present                               | L(1)  |
   | if (uv_ac_delta_present) {                        |       |
   |   uv_ac_delta_magnitude                           | L(4)  |
   |   uv_ac_delta_sign                                | L(1)  |
   | }                                                 |       |
        

o y_ac_qi is the dequantization table index used for the luma AC coefficients (and other coefficient groups if no delta value is present) (Section 9.6)

o y_ac_qi是用于luma ac系数(以及其他系数组,如果不存在增量值)的去量化表索引(第9.6节)

o y_dc_delta_present indicates if the stream contains a delta value that is added to the baseline index to obtain the luma DC coefficient dequantization index (Section 9.6)

o y_dc_delta_present表示流是否包含一个增量值,该增量值被添加到基线索引以获得luma dc系数去量化索引(第9.6节)

o y_dc_delta_magnitude is the magnitude of the delta value (Section 9.6)

o y_dc_delta_震级是delta值的震级(第9.6节)

o y_dc_delta_sign is the sign of the delta value (Section 9.6)

o y_dc_delta_符号是delta值的符号(第9.6节)

o y2_dc_delta_present indicates if the stream contains a delta value that is added to the baseline index to obtain the Y2 block DC coefficient dequantization index (Section 9.6)

o y2_dc_delta_present表示流是否包含添加到基线索引以获得y2块dc系数去量化索引的delta值(第9.6节)

o y2_ac_delta_present indicates if the stream contains a delta value that is added to the baseline index to obtain the Y2 block AC coefficient dequantization index (Section 9.6)

o y2_ac_delta_present表示流是否包含一个增量值,该增量值被添加到基线索引以获得y2块ac系数去量化索引(第9.6节)

o uv_dc_delta_present indicates if the stream contains a delta value that is added to the baseline index to obtain the chroma DC coefficient dequantization index (Section 9.6)

o uv_dc_delta_present表示流是否包含添加到基线索引以获得色度dc系数去量化索引的delta值(第9.6节)

o uv_ac_delta_present indicates if the stream contains a delta value that is added to the baseline index to obtain the chroma AC coefficient dequantization index (Section 9.6)

o uv_ac_delta_present表示流是否包含添加到基线索引以获得色度ac系数去量化索引的delta值(第9.6节)

   | token_prob_update()                               | Type  |
   | ------------------------------------------------- | ----- |
   | for (i = 0; i < 4; i++) {                         |       |
   |   for (j = 0; j < 8; j++) {                       |       |
   |     for (k = 0; k < 3; k++) {                     |       |
   |       for (l = 0; l < 11; l++) {                  |       |
   |         coeff_prob_update_flag                    | L(1)  |
   |         if (coeff_prob_update_flag)               |       |
   |           coeff_prob                              | L(8)  |
   |       }                                           |       |
   |     }                                             |       |
   |   }                                               |       |
   | }                                                 |       |
        
   | token_prob_update()                               | Type  |
   | ------------------------------------------------- | ----- |
   | for (i = 0; i < 4; i++) {                         |       |
   |   for (j = 0; j < 8; j++) {                       |       |
   |     for (k = 0; k < 3; k++) {                     |       |
   |       for (l = 0; l < 11; l++) {                  |       |
   |         coeff_prob_update_flag                    | L(1)  |
   |         if (coeff_prob_update_flag)               |       |
   |           coeff_prob                              | L(8)  |
   |       }                                           |       |
   |     }                                             |       |
   |   }                                               |       |
   | }                                                 |       |
        

o coeff_prob_update_flag indicates if the corresponding branch probability is updated in the current frame (Section 13.4)

o coeff_prob_update_标志表示当前帧中是否更新了相应的分支概率(第13.4节)

o coeff_prob is the new branch probability (Section 13.4)

o coeff_prob是新的分支概率(第13.4节)

   | mv_prob_update()                                  | Type  |
   | ------------------------------------------------- | ----- |
   | for (i = 0; i < 2; i++) {                         |       |
   |   for (j = 0; j < 19; j++) {                      |       |
   |     mv_prob_update_flag                           | L(1)  |
   |     if (mv_prob_update_flag)                      |       |
   |       prob                                        | L(7)  |
   |   }                                               |       |
   | }                                                 |       |
        
   | mv_prob_update()                                  | Type  |
   | ------------------------------------------------- | ----- |
   | for (i = 0; i < 2; i++) {                         |       |
   |   for (j = 0; j < 19; j++) {                      |       |
   |     mv_prob_update_flag                           | L(1)  |
   |     if (mv_prob_update_flag)                      |       |
   |       prob                                        | L(7)  |
   |   }                                               |       |
   | }                                                 |       |
        

o mv_prob_update_flag indicates if the corresponding MV decoding probability is updated in the current frame (Section 17.2)

o mv_prob_update_标志表示当前帧中是否更新了相应的mv解码概率(第17.2节)

o prob is the updated probability (Section 17.2)

o prob是更新的概率(第17.2节)

19.3. Macroblock Data
19.3. 宏块数据
   | Macroblock Data                                   | Type  |
   | ------------------------------------------------- | ----- |
   | macroblock_header()                               |       |
   | residual_data()                                   |       |
        
   | Macroblock Data                                   | Type  |
   | ------------------------------------------------- | ----- |
   | macroblock_header()                               |       |
   | residual_data()                                   |       |
        
   | macroblock_header()                               | Type  |
   | ------------------------------------------------- | ----- |
   | if (update_mb_segmentation_map)                   |       |
   |   segment_id                                      | T     |
   | if (mb_no_skip_coeff)                             |       |
   |   mb_skip_coeff                                   | B(p)  |
   | if (!key_frame)                                   |       |
   |   is_inter_mb                                     | B(p)  |
   | if (is_inter_mb) {                                |       |
   |   mb_ref_frame_sel1                               | B(p)  |
   |   if (mb_ref_frame_sel1)                          |       |
   |     mb_ref_frame_sel2                             | B(p)  |
   |   mv_mode                                         | T     |
   |   if (mv_mode == SPLITMV) {                       |       |
   |     mv_split_mode                                 | T     |
   |     for (i = 0; i < numMvs; i++) {                |       |
   |       sub_mv_mode                                 | T     |
   |       if (sub_mv_mode == NEWMV4x4) {              |       |
   |         read_mvcomponent()                        |       |
   |         read_mvcomponent()                        |       |
   |       }                                           |       |
   |     }                                             |       |
   |   } else if (mv_mode == NEWMV) {                  |       |
   |     read_mvcomponent()                            |       |
   |     read_mvcomponent()                            |       |
   |   }                                               |       |
   | } else { /* intra mb */                           |       |
   |   intra_y_mode                                    | T     |
   |   if (intra_y_mode == B_PRED) {                   |       |
   |     for (i = 0; i < 16; i++)                      |       |
   |       intra_b_mode                                | T     |
   |   }                                               |       |
   |   intra_uv_mode                                   | T     |
   | }                                                 |       |
        
   | macroblock_header()                               | Type  |
   | ------------------------------------------------- | ----- |
   | if (update_mb_segmentation_map)                   |       |
   |   segment_id                                      | T     |
   | if (mb_no_skip_coeff)                             |       |
   |   mb_skip_coeff                                   | B(p)  |
   | if (!key_frame)                                   |       |
   |   is_inter_mb                                     | B(p)  |
   | if (is_inter_mb) {                                |       |
   |   mb_ref_frame_sel1                               | B(p)  |
   |   if (mb_ref_frame_sel1)                          |       |
   |     mb_ref_frame_sel2                             | B(p)  |
   |   mv_mode                                         | T     |
   |   if (mv_mode == SPLITMV) {                       |       |
   |     mv_split_mode                                 | T     |
   |     for (i = 0; i < numMvs; i++) {                |       |
   |       sub_mv_mode                                 | T     |
   |       if (sub_mv_mode == NEWMV4x4) {              |       |
   |         read_mvcomponent()                        |       |
   |         read_mvcomponent()                        |       |
   |       }                                           |       |
   |     }                                             |       |
   |   } else if (mv_mode == NEWMV) {                  |       |
   |     read_mvcomponent()                            |       |
   |     read_mvcomponent()                            |       |
   |   }                                               |       |
   | } else { /* intra mb */                           |       |
   |   intra_y_mode                                    | T     |
   |   if (intra_y_mode == B_PRED) {                   |       |
   |     for (i = 0; i < 16; i++)                      |       |
   |       intra_b_mode                                | T     |
   |   }                                               |       |
   |   intra_uv_mode                                   | T     |
   | }                                                 |       |
        

o segment_id indicates to which segment the macroblock belongs (Section 10)

o 段\ id指示宏块所属的段(第10节)

o mb_skip_coeff indicates whether the macroblock contains any coded coefficients or not (Section 11.1)

o mb_skip_coeff表示宏块是否包含任何编码系数(第11.1节)

o is_inter_mb indicates whether the macroblock is intra- or inter-coded (Section 16)

o is_inter_mb表示宏块是帧内编码还是帧间编码(第16节)

o mb_ref_frame_sel1 selects the reference frame to be used; last frame (0), golden/alternate (1) (Section 16.2)

o mb_ref_frame_sel1选择要使用的参考帧;最后一帧(0),金色/备选(1)(第16.2节)

o mb_ref_frame_sel2 selects whether the golden (0) or alternate reference frame (1) is used (Section 16.2)

o mb_ref_frame_sel2选择是使用黄金参考系(0)还是备用参考系(1)(第16.2节)

o mv_mode determines the macroblock motion vector mode (Section 16.2)

o mv_模式确定宏块运动矢量模式(第16.2节)

o mv_split_mode gives the macroblock partitioning specification and determines the number of motion vectors used (numMvs) (Section 16.2)

o mv_split_模式给出宏块分区规范,并确定使用的运动矢量数(NUMMV)(第16.2节)

o sub_mv_mode determines the sub-macroblock motion vector mode for macroblocks coded using the SPLITMV motion vector mode (Section 16.2)

o sub_mv_模式确定使用SPLITMV运动矢量模式编码的宏块的子宏块运动矢量模式(第16.2节)

o intra_y_mode selects the luminance intra-prediction mode (Section 16.1)

o 帧内模式选择亮度帧内预测模式(第16.1节)

o intra_b_mode selects the sub-macroblock luminance prediction mode for macroblocks coded using B_PRED mode (Section 16.1)

o 帧内b_模式为使用b_PRED模式编码的宏块选择子宏块亮度预测模式(第16.1节)

o intra_uv_mode selects the chrominance intra-prediction mode (Section 16.1)

o 帧内uv模式选择色度帧内预测模式(第16.1节)

   | residual_data()                                   | Type  |
   | ------------------------------------------------- | ----- |
   | if (!mb_skip_coeff) {                             |       |
   |   if ( (is_inter_mb && mv_mode != SPLITMV) ||     |       |
   |        (!is_inter_mb && intra_y_mode != B_PRED) ) |       |
   |     residual_block() /* Y2 */                     |       |
   |   for (i = 0; i < 24; i++)                        |       |
   |     residual_block() /* 16 Y, 4 U, 4 V */         |       |
   | }                                                 |       |
        
   | residual_data()                                   | Type  |
   | ------------------------------------------------- | ----- |
   | if (!mb_skip_coeff) {                             |       |
   |   if ( (is_inter_mb && mv_mode != SPLITMV) ||     |       |
   |        (!is_inter_mb && intra_y_mode != B_PRED) ) |       |
   |     residual_block() /* Y2 */                     |       |
   |   for (i = 0; i < 24; i++)                        |       |
   |     residual_block() /* 16 Y, 4 U, 4 V */         |       |
   | }                                                 |       |
        
   | residual_block()                                  | Type  |
   | ------------------------------------------------- | ----- |
   | for (i = firstCoeff; i < 16; i++) {               |       |
   |   token                                           | T     |
   |   if (token == EOB) break;                        |       |
   |   if (token_has_extra_bits)                       |       |
   |     extra_bits                                    | L(n)  |
   |   if (coefficient != 0)                           |       |
   |     sign                                          | L(1)  |
   | }                                                 |       |
        
   | residual_block()                                  | Type  |
   | ------------------------------------------------- | ----- |
   | for (i = firstCoeff; i < 16; i++) {               |       |
   |   token                                           | T     |
   |   if (token == EOB) break;                        |       |
   |   if (token_has_extra_bits)                       |       |
   |     extra_bits                                    | L(n)  |
   |   if (coefficient != 0)                           |       |
   |     sign                                          | L(1)  |
   | }                                                 |       |
        

o firstCoeff is 1 for luma blocks of macroblocks containing Y2 subblock; otherwise 0

o 对于包含Y2子块的宏块的luma块,firstCoeff为1;否则0

o token defines the value of the coefficient, the value range of the coefficient, or the end of block (Section 13.2)

o 标记定义了系数的值、系数的值范围或块的末尾(第13.2节)

o extra_bits determines the value of the coefficient within the value range defined by the token (Section 13.2)

o 额外_位确定令牌定义的值范围内的系数值(第13.2节)

o sign indicates the sign of the coefficient (Section 13.2)

o 符号表示系数的符号(第13.2节)

20. Attachment One: Reference Decoder Source Code
20. 附件一:参考解码器源代码
20.1. bit_ops.h
20.1. 比特运算
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef BIT_OPS_H
   #define BIT_OPS_H
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef BIT_OPS_H
   #define BIT_OPS_H
        
   /* Evaluates to a mask with n bits set */
   #define BITS_MASK(n) ((1<<(n))-1)
        
   /* Evaluates to a mask with n bits set */
   #define BITS_MASK(n) ((1<<(n))-1)
        
   /* Returns len bits, with the LSB at position bit */
   #define BITS_GET(val, bit, len) (((val)>>(bit))&BITS_MASK(len))
        
   /* Returns len bits, with the LSB at position bit */
   #define BITS_GET(val, bit, len) (((val)>>(bit))&BITS_MASK(len))
        

#endif

#恩迪夫

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.2. bool_decoder.h
20.2. bool_解码器
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef BOOL_DECODER_H
   #define BOOL_DECODER_H
   #include <stddef.h>
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef BOOL_DECODER_H
   #define BOOL_DECODER_H
   #include <stddef.h>
        
   struct bool_decoder
   {
       const unsigned char *input;      /* next compressed data byte */
       size_t               input_len;  /* length of the input buffer */
       unsigned int         range;      /* identical to encoder's
                                         * range */
       unsigned int         value;      /* contains at least 8
                                         * significant bits */
       int                  bit_count;  /* # of bits shifted out of
                                         * value, max 7 */
   };
        
   struct bool_decoder
   {
       const unsigned char *input;      /* next compressed data byte */
       size_t               input_len;  /* length of the input buffer */
       unsigned int         range;      /* identical to encoder's
                                         * range */
       unsigned int         value;      /* contains at least 8
                                         * significant bits */
       int                  bit_count;  /* # of bits shifted out of
                                         * value, max 7 */
   };
        
   static void
   init_bool_decoder(struct bool_decoder *d,
                     const unsigned char *start_partition,
                     size_t               sz)
   {
       if (sz >= 2)
       {
           d->value = (start_partition[0] << 8) /* first 2 input
                                                 * bytes */
                      | start_partition[1];
           d->input = start_partition + 2;      /* ptr to next byte */
           d->input_len = sz - 2;
       }
       else
       {
           d->value = 0;
           d->input = NULL;
           d->input_len = 0;
       }
        
   static void
   init_bool_decoder(struct bool_decoder *d,
                     const unsigned char *start_partition,
                     size_t               sz)
   {
       if (sz >= 2)
       {
           d->value = (start_partition[0] << 8) /* first 2 input
                                                 * bytes */
                      | start_partition[1];
           d->input = start_partition + 2;      /* ptr to next byte */
           d->input_len = sz - 2;
       }
       else
       {
           d->value = 0;
           d->input = NULL;
           d->input_len = 0;
       }
        
       d->range = 255;    /* initial range is full */
       d->bit_count = 0;  /* have not yet shifted out any bits */
   }
        
       d->range = 255;    /* initial range is full */
       d->bit_count = 0;  /* have not yet shifted out any bits */
   }
        
   static int bool_get(struct bool_decoder *d, int probability)
   {
       /* range and split are identical to the corresponding values
          used by the encoder when this bool was written */
        
   static int bool_get(struct bool_decoder *d, int probability)
   {
       /* range and split are identical to the corresponding values
          used by the encoder when this bool was written */
        
       unsigned int  split = 1 + (((d->range - 1) * probability) >> 8);
       unsigned int  SPLIT = split << 8;
       int           retval;           /* will be 0 or 1 */
        
       unsigned int  split = 1 + (((d->range - 1) * probability) >> 8);
       unsigned int  SPLIT = split << 8;
       int           retval;           /* will be 0 or 1 */
        
       if (d->value >= SPLIT)    /* encoded a one */
       {
           retval = 1;
           d->range -= split;  /* reduce range */
           d->value -= SPLIT;  /* subtract off left endpoint of
                                * interval */
       }
       else                  /* encoded a zero */
       {
           retval = 0;
           d->range = split; /* reduce range, no change in left
                              * endpoint */
       }
        
       if (d->value >= SPLIT)    /* encoded a one */
       {
           retval = 1;
           d->range -= split;  /* reduce range */
           d->value -= SPLIT;  /* subtract off left endpoint of
                                * interval */
       }
       else                  /* encoded a zero */
       {
           retval = 0;
           d->range = split; /* reduce range, no change in left
                              * endpoint */
       }
        
       while (d->range < 128)    /* shift out irrelevant value bits */
       {
           d->value <<= 1;
           d->range <<= 1;
        
       while (d->range < 128)    /* shift out irrelevant value bits */
       {
           d->value <<= 1;
           d->range <<= 1;
        
           if (++d->bit_count == 8)  /* shift in new bits 8 at a time */
           {
               d->bit_count = 0;
        
           if (++d->bit_count == 8)  /* shift in new bits 8 at a time */
           {
               d->bit_count = 0;
        
               if (d->input_len)
               {
                   d->value |= *d->input++;
                   d->input_len--;
               }
           }
       }
        
               if (d->input_len)
               {
                   d->value |= *d->input++;
                   d->input_len--;
               }
           }
       }
        
       return retval;
   }
        
       return retval;
   }
        
   static int bool_get_bit(struct bool_decoder *br)
   {
       return bool_get(br, 128);
   }
        
   static int bool_get_bit(struct bool_decoder *br)
   {
       return bool_get(br, 128);
   }
        
   static int bool_get_uint(struct bool_decoder *br, int bits)
   {
       int z = 0;
       int bit;
        
   static int bool_get_uint(struct bool_decoder *br, int bits)
   {
       int z = 0;
       int bit;
        
       for (bit = bits - 1; bit >= 0; bit--)
       {
           z |= (bool_get_bit(br) << bit);
       }
        
       for (bit = bits - 1; bit >= 0; bit--)
       {
           z |= (bool_get_bit(br) << bit);
       }
        
       return z;
   }
        
       return z;
   }
        
   static int bool_get_int(struct bool_decoder *br, int bits)
   {
       int z = 0;
       int bit;
        
   static int bool_get_int(struct bool_decoder *br, int bits)
   {
       int z = 0;
       int bit;
        
       for (bit = bits - 1; bit >= 0; bit--)
       {
           z |= (bool_get_bit(br) << bit);
       }
        
       for (bit = bits - 1; bit >= 0; bit--)
       {
           z |= (bool_get_bit(br) << bit);
       }
        
       return bool_get_bit(br) ? -z : z;
   }
        
       return bool_get_bit(br) ? -z : z;
   }
        
   static int bool_maybe_get_int(struct bool_decoder *br, int bits)
   {
       return bool_get_bit(br) ? bool_get_int(br, bits) : 0;
   }
        
   static int bool_maybe_get_int(struct bool_decoder *br, int bits)
   {
       return bool_get_bit(br) ? bool_get_int(br, bits) : 0;
   }
        
   static int
   bool_read_tree(struct bool_decoder *bool,
                  const int           *t,
                  const unsigned char *p)
   {
       int i = 0;
        
   static int
   bool_read_tree(struct bool_decoder *bool,
                  const int           *t,
                  const unsigned char *p)
   {
       int i = 0;
        
       while ((i = t[ i + bool_get(bool, p[i>>1])]) > 0);
        
       while ((i = t[ i + bool_get(bool, p[i>>1])]) > 0);
        
       return -i;
   }
   #endif
        
       return -i;
   }
   #endif
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.3. dequant_data.h
20.3. dequant_data.h
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
        
   static const int dc_q_lookup[128] =
   {
       4,    5,    6,    7,    8,    9,    10,   10,
       11,   12,   13,   14,   15,   16,   17,   17,
       18,   19,   20,   20,   21,   21,   22,   22,
       23,   23,   24,   25,   25,   26,   27,   28,
       29,   30,   31,   32,   33,   34,   35,   36,
       37,   37,   38,   39,   40,   41,   42,   43,
       44,   45,   46,   46,   47,   48,   49,   50,
       51,   52,   53,   54,   55,   56,   57,   58,
       59,   60,   61,   62,   63,   64,   65,   66,
       67,   68,   69,   70,   71,   72,   73,   74,
       75,   76,   76,   77,   78,   79,   80,   81,
       82,   83,   84,   85,   86,   87,   88,   89,
       91,   93,   95,   96,   98,   100,  101,  102,
       104,  106,  108,  110,  112,  114,  116,  118,
       122,  124,  126,  128,  130,  132,  134,  136,
       138,  140,  143,  145,  148,  151,  154,  157
   };
        
   static const int dc_q_lookup[128] =
   {
       4,    5,    6,    7,    8,    9,    10,   10,
       11,   12,   13,   14,   15,   16,   17,   17,
       18,   19,   20,   20,   21,   21,   22,   22,
       23,   23,   24,   25,   25,   26,   27,   28,
       29,   30,   31,   32,   33,   34,   35,   36,
       37,   37,   38,   39,   40,   41,   42,   43,
       44,   45,   46,   46,   47,   48,   49,   50,
       51,   52,   53,   54,   55,   56,   57,   58,
       59,   60,   61,   62,   63,   64,   65,   66,
       67,   68,   69,   70,   71,   72,   73,   74,
       75,   76,   76,   77,   78,   79,   80,   81,
       82,   83,   84,   85,   86,   87,   88,   89,
       91,   93,   95,   96,   98,   100,  101,  102,
       104,  106,  108,  110,  112,  114,  116,  118,
       122,  124,  126,  128,  130,  132,  134,  136,
       138,  140,  143,  145,  148,  151,  154,  157
   };
        

static const int ac_q_lookup[128] = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149, 152,

静态常量int ac_q_查找[128]={ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149, 152,

155, 158, 161, 164, 167, 170, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284 };

155, 158, 161, 164, 167, 170, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284 };

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.4. dixie.c
20.4. 迪克西
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #include "vpx_codec_internal.h"
   #include "bit_ops.h"
   #include "dixie.h"
   #include "vp8_prob_data.h"
   #include "dequant_data.h"
   #include "modemv.h"
   #include "tokens.h"
   #include "predict.h"
   #include "dixie_loopfilter.h"
   #include <string.h>
   #include <assert.h>
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #include "vpx_codec_internal.h"
   #include "bit_ops.h"
   #include "dixie.h"
   #include "vp8_prob_data.h"
   #include "dequant_data.h"
   #include "modemv.h"
   #include "tokens.h"
   #include "predict.h"
   #include "dixie_loopfilter.h"
   #include <string.h>
   #include <assert.h>
        
   enum
   {
       FRAME_HEADER_SZ = 3,
       KEYFRAME_HEADER_SZ = 7
   };
        
   enum
   {
       FRAME_HEADER_SZ = 3,
       KEYFRAME_HEADER_SZ = 7
   };
        
   #define ARRAY_COPY(a,b) {\
       assert(sizeof(a)==sizeof(b));memcpy(a,b,sizeof(a));}
   static void
   decode_entropy_header(struct vp8_decoder_ctx    *ctx,
                         struct bool_decoder       *bool,
                         struct vp8_entropy_hdr    *hdr)
        
   #define ARRAY_COPY(a,b) {\
       assert(sizeof(a)==sizeof(b));memcpy(a,b,sizeof(a));}
   static void
   decode_entropy_header(struct vp8_decoder_ctx    *ctx,
                         struct bool_decoder       *bool,
                         struct vp8_entropy_hdr    *hdr)
        
   {
       int i, j, k, l;
        
   {
       int i, j, k, l;
        
       /* Read coefficient probability updates */
       for (i = 0; i < BLOCK_TYPES; i++)
           for (j = 0; j < COEFF_BANDS; j++)
               for (k = 0; k < PREV_COEFF_CONTEXTS; k++)
                   for (l = 0; l < ENTROPY_NODES; l++)
                       if (bool_get(bool,
                                    k_coeff_entropy_update_probs
                                        [i][j][k][l]))
                           hdr->coeff_probs[i][j][k][l] =
                               bool_get_uint(bool, 8);
        
       /* Read coefficient probability updates */
       for (i = 0; i < BLOCK_TYPES; i++)
           for (j = 0; j < COEFF_BANDS; j++)
               for (k = 0; k < PREV_COEFF_CONTEXTS; k++)
                   for (l = 0; l < ENTROPY_NODES; l++)
                       if (bool_get(bool,
                                    k_coeff_entropy_update_probs
                                        [i][j][k][l]))
                           hdr->coeff_probs[i][j][k][l] =
                               bool_get_uint(bool, 8);
        
       /* Read coefficient skip mode probability */
       hdr->coeff_skip_enabled = bool_get_bit(bool);
        
       /* Read coefficient skip mode probability */
       hdr->coeff_skip_enabled = bool_get_bit(bool);
        
       if (hdr->coeff_skip_enabled)
           hdr->coeff_skip_prob = bool_get_uint(bool, 8);
        
       if (hdr->coeff_skip_enabled)
           hdr->coeff_skip_prob = bool_get_uint(bool, 8);
        
       /* Parse interframe probability updates */
       if (!ctx->frame_hdr.is_keyframe)
       {
           hdr->prob_inter = bool_get_uint(bool, 8);
           hdr->prob_last  = bool_get_uint(bool, 8);
           hdr->prob_gf    = bool_get_uint(bool, 8);
        
       /* Parse interframe probability updates */
       if (!ctx->frame_hdr.is_keyframe)
       {
           hdr->prob_inter = bool_get_uint(bool, 8);
           hdr->prob_last  = bool_get_uint(bool, 8);
           hdr->prob_gf    = bool_get_uint(bool, 8);
        
           if (bool_get_bit(bool))
               for (i = 0; i < 4; i++)
                   hdr->y_mode_probs[i] = bool_get_uint(bool, 8);
        
           if (bool_get_bit(bool))
               for (i = 0; i < 4; i++)
                   hdr->y_mode_probs[i] = bool_get_uint(bool, 8);
        
           if (bool_get_bit(bool))
               for (i = 0; i < 3; i++)
                   hdr->uv_mode_probs[i] = bool_get_uint(bool, 8);
        
           if (bool_get_bit(bool))
               for (i = 0; i < 3; i++)
                   hdr->uv_mode_probs[i] = bool_get_uint(bool, 8);
        
           for (i = 0; i < 2; i++)
               for (j = 0; j < MV_PROB_CNT; j++)
                   if (bool_get(bool, k_mv_entropy_update_probs[i][j]))
                   {
                       int x = bool_get_uint(bool, 7);
                       hdr->mv_probs[i][j] = x ? x << 1 : 1;
                   }
       }
   }
        
           for (i = 0; i < 2; i++)
               for (j = 0; j < MV_PROB_CNT; j++)
                   if (bool_get(bool, k_mv_entropy_update_probs[i][j]))
                   {
                       int x = bool_get_uint(bool, 7);
                       hdr->mv_probs[i][j] = x ? x << 1 : 1;
                   }
       }
   }
        
   static void
   decode_reference_header(struct vp8_decoder_ctx    *ctx,
                           struct bool_decoder       *bool,
                           struct vp8_reference_hdr  *hdr)
   {
       unsigned int key = ctx->frame_hdr.is_keyframe;
        
   static void
   decode_reference_header(struct vp8_decoder_ctx    *ctx,
                           struct bool_decoder       *bool,
                           struct vp8_reference_hdr  *hdr)
   {
       unsigned int key = ctx->frame_hdr.is_keyframe;
        
       hdr->refresh_gf    = key ? 1 : bool_get_bit(bool);
       hdr->refresh_arf   = key ? 1 : bool_get_bit(bool);
       hdr->copy_gf       = key ? 0 : !hdr->refresh_gf
                            ? bool_get_uint(bool, 2) : 0;
       hdr->copy_arf      = key ? 0 : !hdr->refresh_arf
                            ? bool_get_uint(bool, 2) : 0;
       hdr->sign_bias[GOLDEN_FRAME] = key ? 0 : bool_get_bit(bool);
       hdr->sign_bias[ALTREF_FRAME] = key ? 0 : bool_get_bit(bool);
       hdr->refresh_entropy = bool_get_bit(bool);
       hdr->refresh_last  = key ? 1 : bool_get_bit(bool);
   }
        
       hdr->refresh_gf    = key ? 1 : bool_get_bit(bool);
       hdr->refresh_arf   = key ? 1 : bool_get_bit(bool);
       hdr->copy_gf       = key ? 0 : !hdr->refresh_gf
                            ? bool_get_uint(bool, 2) : 0;
       hdr->copy_arf      = key ? 0 : !hdr->refresh_arf
                            ? bool_get_uint(bool, 2) : 0;
       hdr->sign_bias[GOLDEN_FRAME] = key ? 0 : bool_get_bit(bool);
       hdr->sign_bias[ALTREF_FRAME] = key ? 0 : bool_get_bit(bool);
       hdr->refresh_entropy = bool_get_bit(bool);
       hdr->refresh_last  = key ? 1 : bool_get_bit(bool);
   }
        
   static void
   decode_quantizer_header(struct vp8_decoder_ctx    *ctx,
                           struct bool_decoder       *bool,
                           struct vp8_quant_hdr      *hdr)
   {
       int update;
       int last_q = hdr->q_index;
        
   static void
   decode_quantizer_header(struct vp8_decoder_ctx    *ctx,
                           struct bool_decoder       *bool,
                           struct vp8_quant_hdr      *hdr)
   {
       int update;
       int last_q = hdr->q_index;
        
       hdr->q_index = bool_get_uint(bool, 7);
       update = last_q != hdr->q_index;
       update |= (hdr->y1_dc_delta_q = bool_maybe_get_int(bool, 4));
       update |= (hdr->y2_dc_delta_q = bool_maybe_get_int(bool, 4));
       update |= (hdr->y2_ac_delta_q = bool_maybe_get_int(bool, 4));
       update |= (hdr->uv_dc_delta_q = bool_maybe_get_int(bool, 4));
       update |= (hdr->uv_ac_delta_q = bool_maybe_get_int(bool, 4));
       hdr->delta_update = update;
   }
        
       hdr->q_index = bool_get_uint(bool, 7);
       update = last_q != hdr->q_index;
       update |= (hdr->y1_dc_delta_q = bool_maybe_get_int(bool, 4));
       update |= (hdr->y2_dc_delta_q = bool_maybe_get_int(bool, 4));
       update |= (hdr->y2_ac_delta_q = bool_maybe_get_int(bool, 4));
       update |= (hdr->uv_dc_delta_q = bool_maybe_get_int(bool, 4));
       update |= (hdr->uv_ac_delta_q = bool_maybe_get_int(bool, 4));
       hdr->delta_update = update;
   }
        

static void decode_and_init_token_partitions(struct vp8_decoder_ctx *ctx, struct bool_decoder *bool, const unsigned char *data, unsigned int sz, struct vp8_token_hdr *hdr)

静态void decode_和_init_token_分区(struct vp8_decoder_ctx*ctx,struct bool_decoder*bool,const unsigned char*data,unsigned int sz,struct vp8_token_hdr*hdr)

   {
       int i;
        
   {
       int i;
        
       hdr->partitions = 1 << bool_get_uint(bool, 2);
        
       hdr->partitions = 1 << bool_get_uint(bool, 2);
        
       if (sz < 3 *(hdr->partitions - 1))
           vpx_internal_error(&ctx->error, VPX_CODEC_CORRUPT_FRAME,
                              "Truncated packet found parsing partition"
                              " lengths.");
        
       if (sz < 3 *(hdr->partitions - 1))
           vpx_internal_error(&ctx->error, VPX_CODEC_CORRUPT_FRAME,
                              "Truncated packet found parsing partition"
                              " lengths.");
        
       sz -= 3 * (hdr->partitions - 1);
        
       sz -= 3 * (hdr->partitions - 1);
        
       for (i = 0; i < hdr->partitions; i++)
       {
           if (i < hdr->partitions - 1)
           {
               hdr->partition_sz[i] = (data[2] << 16)
                                      | (data[1] << 8) | data[0];
               data += 3;
           }
           else
               hdr->partition_sz[i] = sz;
        
       for (i = 0; i < hdr->partitions; i++)
       {
           if (i < hdr->partitions - 1)
           {
               hdr->partition_sz[i] = (data[2] << 16)
                                      | (data[1] << 8) | data[0];
               data += 3;
           }
           else
               hdr->partition_sz[i] = sz;
        
           if (sz < hdr->partition_sz[i])
               vpx_internal_error(&ctx->error, VPX_CODEC_CORRUPT_FRAME,
                                  "Truncated partition %d", i);
        
           if (sz < hdr->partition_sz[i])
               vpx_internal_error(&ctx->error, VPX_CODEC_CORRUPT_FRAME,
                                  "Truncated partition %d", i);
        
           sz -= hdr->partition_sz[i];
       }
        
           sz -= hdr->partition_sz[i];
       }
        
       for (i = 0; i < ctx->token_hdr.partitions; i++)
       {
           init_bool_decoder(&ctx->tokens[i].bool, data,
                             ctx->token_hdr.partition_sz[i]);
           data += ctx->token_hdr.partition_sz[i];
       }
   }
        
       for (i = 0; i < ctx->token_hdr.partitions; i++)
       {
           init_bool_decoder(&ctx->tokens[i].bool, data,
                             ctx->token_hdr.partition_sz[i]);
           data += ctx->token_hdr.partition_sz[i];
       }
   }
        

static void decode_loopfilter_header(struct vp8_decoder_ctx *ctx, struct bool_decoder *bool, struct vp8_loopfilter_hdr *hdr)

静态无效解码\u loopfilter\u头(结构vp8\u解码器\u ctx*ctx,结构bool\u解码器*bool,结构vp8\u loopfilter\u hdr*hdr)

   {
       if (ctx->frame_hdr.is_keyframe)
           memset(hdr, 0, sizeof(*hdr));
        
   {
       if (ctx->frame_hdr.is_keyframe)
           memset(hdr, 0, sizeof(*hdr));
        
       hdr->use_simple    = bool_get_bit(bool);
       hdr->level         = bool_get_uint(bool, 6);
       hdr->sharpness     = bool_get_uint(bool, 3);
       hdr->delta_enabled = bool_get_bit(bool);
        
       hdr->use_simple    = bool_get_bit(bool);
       hdr->level         = bool_get_uint(bool, 6);
       hdr->sharpness     = bool_get_uint(bool, 3);
       hdr->delta_enabled = bool_get_bit(bool);
        
       if (hdr->delta_enabled && bool_get_bit(bool))
       {
           int i;
        
       if (hdr->delta_enabled && bool_get_bit(bool))
       {
           int i;
        
           for (i = 0; i < BLOCK_CONTEXTS; i++)
               hdr->ref_delta[i] = bool_maybe_get_int(bool, 6);
        
           for (i = 0; i < BLOCK_CONTEXTS; i++)
               hdr->ref_delta[i] = bool_maybe_get_int(bool, 6);
        
           for (i = 0; i < BLOCK_CONTEXTS; i++)
               hdr->mode_delta[i] = bool_maybe_get_int(bool, 6);
       }
   }
        
           for (i = 0; i < BLOCK_CONTEXTS; i++)
               hdr->mode_delta[i] = bool_maybe_get_int(bool, 6);
       }
   }
        
   static void
   decode_segmentation_header(struct vp8_decoder_ctx *ctx,
                              struct bool_decoder    *bool,
                              struct vp8_segment_hdr *hdr)
   {
       if (ctx->frame_hdr.is_keyframe)
           memset(hdr, 0, sizeof(*hdr));
        
   static void
   decode_segmentation_header(struct vp8_decoder_ctx *ctx,
                              struct bool_decoder    *bool,
                              struct vp8_segment_hdr *hdr)
   {
       if (ctx->frame_hdr.is_keyframe)
           memset(hdr, 0, sizeof(*hdr));
        
       hdr->enabled = bool_get_bit(bool);
        
       hdr->enabled = bool_get_bit(bool);
        
       if (hdr->enabled)
       {
           int i;
        
       if (hdr->enabled)
       {
           int i;
        
           hdr->update_map = bool_get_bit(bool);
           hdr->update_data = bool_get_bit(bool);
        
           hdr->update_map = bool_get_bit(bool);
           hdr->update_data = bool_get_bit(bool);
        
           if (hdr->update_data)
           {
               hdr->abs = bool_get_bit(bool);
        
           if (hdr->update_data)
           {
               hdr->abs = bool_get_bit(bool);
        
               for (i = 0; i < MAX_MB_SEGMENTS; i++)
                   hdr->quant_idx[i] = bool_maybe_get_int(bool, 7);
        
               for (i = 0; i < MAX_MB_SEGMENTS; i++)
                   hdr->quant_idx[i] = bool_maybe_get_int(bool, 7);
        
               for (i = 0; i < MAX_MB_SEGMENTS; i++)
                   hdr->lf_level[i] = bool_maybe_get_int(bool, 6);
           }
        
               for (i = 0; i < MAX_MB_SEGMENTS; i++)
                   hdr->lf_level[i] = bool_maybe_get_int(bool, 6);
           }
        
           if (hdr->update_map)
           {
               for (i = 0; i < MB_FEATURE_TREE_PROBS; i++)
                   hdr->tree_probs[i] = bool_get_bit(bool)
                                        ? bool_get_uint(bool, 8)
                                        : 255;
           }
       }
       else
       {
           hdr->update_map = 0;
           hdr->update_data = 0;
       }
   }
        
           if (hdr->update_map)
           {
               for (i = 0; i < MB_FEATURE_TREE_PROBS; i++)
                   hdr->tree_probs[i] = bool_get_bit(bool)
                                        ? bool_get_uint(bool, 8)
                                        : 255;
           }
       }
       else
       {
           hdr->update_map = 0;
           hdr->update_data = 0;
       }
   }
        
   static void
   dequant_global_init(struct dequant_factors dqf[MAX_MB_SEGMENTS])
   {
       int i;
        
   static void
   dequant_global_init(struct dequant_factors dqf[MAX_MB_SEGMENTS])
   {
       int i;
        
       for (i = 0; i < MAX_MB_SEGMENTS; i++)
           dqf[i].quant_idx = -1;
   }
        
       for (i = 0; i < MAX_MB_SEGMENTS; i++)
           dqf[i].quant_idx = -1;
   }
        
   static int
   clamp_q(int q)
   {
       if (q < 0) return 0;
       else if (q > 127) return 127;
        
   static int
   clamp_q(int q)
   {
       if (q < 0) return 0;
       else if (q > 127) return 127;
        
       return q;
   }
        
       return q;
   }
        
   static int
   dc_q(int q)
   {
       return dc_q_lookup[clamp_q(q)];
   }
        
   static int
   dc_q(int q)
   {
       return dc_q_lookup[clamp_q(q)];
   }
        
   static int
   ac_q(int q)
   {
       return ac_q_lookup[clamp_q(q)];
   }
        
   static int
   ac_q(int q)
   {
       return ac_q_lookup[clamp_q(q)];
   }
        
   static void
   dequant_init(struct dequant_factors        factors[MAX_MB_SEGMENTS],
                const struct vp8_segment_hdr *seg,
                const struct vp8_quant_hdr   *quant_hdr)
   {
       int i, q;
       struct dequant_factors *dqf = factors;
        
   static void
   dequant_init(struct dequant_factors        factors[MAX_MB_SEGMENTS],
                const struct vp8_segment_hdr *seg,
                const struct vp8_quant_hdr   *quant_hdr)
   {
       int i, q;
       struct dequant_factors *dqf = factors;
        
       for (i = 0; i < (seg->enabled ? MAX_MB_SEGMENTS : 1); i++)
       {
           q = quant_hdr->q_index;
        
       for (i = 0; i < (seg->enabled ? MAX_MB_SEGMENTS : 1); i++)
       {
           q = quant_hdr->q_index;
        
           if (seg->enabled)
               q = (!seg->abs) ? q + seg->quant_idx[i]
                               : seg->quant_idx[i];
        
           if (seg->enabled)
               q = (!seg->abs) ? q + seg->quant_idx[i]
                               : seg->quant_idx[i];
        
           if (dqf->quant_idx != q || quant_hdr->delta_update)
           {
               dqf->factor[TOKEN_BLOCK_Y1][0] =
                   dc_q(q + quant_hdr->y1_dc_delta_q);
               dqf->factor[TOKEN_BLOCK_Y1][1] =
                   ac_q(q);
               dqf->factor[TOKEN_BLOCK_UV][0] =
                   dc_q(q + quant_hdr->uv_dc_delta_q);
               dqf->factor[TOKEN_BLOCK_UV][1] =
                   ac_q(q + quant_hdr->uv_ac_delta_q);
               dqf->factor[TOKEN_BLOCK_Y2][0] =
                   dc_q(q + quant_hdr->y2_dc_delta_q) * 2;
               dqf->factor[TOKEN_BLOCK_Y2][1] =
                   ac_q(q + quant_hdr->y2_ac_delta_q) * 155 / 100;
        
           if (dqf->quant_idx != q || quant_hdr->delta_update)
           {
               dqf->factor[TOKEN_BLOCK_Y1][0] =
                   dc_q(q + quant_hdr->y1_dc_delta_q);
               dqf->factor[TOKEN_BLOCK_Y1][1] =
                   ac_q(q);
               dqf->factor[TOKEN_BLOCK_UV][0] =
                   dc_q(q + quant_hdr->uv_dc_delta_q);
               dqf->factor[TOKEN_BLOCK_UV][1] =
                   ac_q(q + quant_hdr->uv_ac_delta_q);
               dqf->factor[TOKEN_BLOCK_Y2][0] =
                   dc_q(q + quant_hdr->y2_dc_delta_q) * 2;
               dqf->factor[TOKEN_BLOCK_Y2][1] =
                   ac_q(q + quant_hdr->y2_ac_delta_q) * 155 / 100;
        
               if (dqf->factor[TOKEN_BLOCK_Y2][1] < 8)
                   dqf->factor[TOKEN_BLOCK_Y2][1] = 8;
        
               if (dqf->factor[TOKEN_BLOCK_Y2][1] < 8)
                   dqf->factor[TOKEN_BLOCK_Y2][1] = 8;
        
               if (dqf->factor[TOKEN_BLOCK_UV][0] > 132)
                   dqf->factor[TOKEN_BLOCK_UV][0] = 132;
        
               if (dqf->factor[TOKEN_BLOCK_UV][0] > 132)
                   dqf->factor[TOKEN_BLOCK_UV][0] = 132;
        
               dqf->quant_idx = q;
           }
        
               dqf->quant_idx = q;
           }
        
           dqf++;
       }
   }
        
           dqf++;
       }
   }
        
   static void
   decode_frame(struct vp8_decoder_ctx *ctx,
                const unsigned char    *data,
                unsigned int            sz)
   {
       vpx_codec_err_t  res;
       struct bool_decoder  bool;
       int                  i, row, partition;
        
   static void
   decode_frame(struct vp8_decoder_ctx *ctx,
                const unsigned char    *data,
                unsigned int            sz)
   {
       vpx_codec_err_t  res;
       struct bool_decoder  bool;
       int                  i, row, partition;
        
       ctx->saved_entropy_valid = 0;
        
       ctx->saved_entropy_valid = 0;
        
       if ((res = vp8_parse_frame_header(data, sz, &ctx->frame_hdr)))
           vpx_internal_error(&ctx->error, res,
                              "Failed to parse frame header");
        
       if ((res = vp8_parse_frame_header(data, sz, &ctx->frame_hdr)))
           vpx_internal_error(&ctx->error, res,
                              "Failed to parse frame header");
        

if (ctx->frame_hdr.is_experimental) vpx_internal_error(&ctx->error, VPX_CODEC_UNSUP_BITSTREAM, "Experimental bitstreams not supported.");

如果(ctx->frame_hdr.是实验性的)vpx_内部错误(&ctx->错误,vpx_编解码器_UNSUP_比特流,“不支持实验性比特流”);

       data += FRAME_HEADER_SZ;
       sz -= FRAME_HEADER_SZ;
        
       data += FRAME_HEADER_SZ;
       sz -= FRAME_HEADER_SZ;
        
       if (ctx->frame_hdr.is_keyframe)
       {
           data += KEYFRAME_HEADER_SZ;
           sz -= KEYFRAME_HEADER_SZ;
           ctx->mb_cols = (ctx->frame_hdr.kf.w + 15) / 16;
           ctx->mb_rows = (ctx->frame_hdr.kf.h + 15) / 16;
       }
        
       if (ctx->frame_hdr.is_keyframe)
       {
           data += KEYFRAME_HEADER_SZ;
           sz -= KEYFRAME_HEADER_SZ;
           ctx->mb_cols = (ctx->frame_hdr.kf.w + 15) / 16;
           ctx->mb_rows = (ctx->frame_hdr.kf.h + 15) / 16;
       }
        
       /* Start the bitreader for the header/entropy partition */
       init_bool_decoder(&bool, data, ctx->frame_hdr.part0_sz);
        
       /* Start the bitreader for the header/entropy partition */
       init_bool_decoder(&bool, data, ctx->frame_hdr.part0_sz);
        
       /* Skip the colorspace and clamping bits */
       if (ctx->frame_hdr.is_keyframe)
           if (bool_get_uint(&bool, 2))
               vpx_internal_error(
                   &ctx->error, VPX_CODEC_UNSUP_BITSTREAM,
                   "Reserved bits not supported.");
        
       /* Skip the colorspace and clamping bits */
       if (ctx->frame_hdr.is_keyframe)
           if (bool_get_uint(&bool, 2))
               vpx_internal_error(
                   &ctx->error, VPX_CODEC_UNSUP_BITSTREAM,
                   "Reserved bits not supported.");
        
       decode_segmentation_header(ctx, &bool, &ctx->segment_hdr);
       decode_loopfilter_header(ctx, &bool, &ctx->loopfilter_hdr);
       decode_and_init_token_partitions(ctx,
                                        &bool,
                                        data + ctx->frame_hdr.part0_sz,
                                        sz - ctx->frame_hdr.part0_sz,
                                        &ctx->token_hdr);
       decode_quantizer_header(ctx, &bool, &ctx->quant_hdr);
       decode_reference_header(ctx, &bool, &ctx->reference_hdr);
        
       decode_segmentation_header(ctx, &bool, &ctx->segment_hdr);
       decode_loopfilter_header(ctx, &bool, &ctx->loopfilter_hdr);
       decode_and_init_token_partitions(ctx,
                                        &bool,
                                        data + ctx->frame_hdr.part0_sz,
                                        sz - ctx->frame_hdr.part0_sz,
                                        &ctx->token_hdr);
       decode_quantizer_header(ctx, &bool, &ctx->quant_hdr);
       decode_reference_header(ctx, &bool, &ctx->reference_hdr);
        
       /* Set keyframe entropy defaults.  These get updated on keyframes
        * regardless of the refresh_entropy setting.
        */
       if (ctx->frame_hdr.is_keyframe)
       {
           ARRAY_COPY(ctx->entropy_hdr.coeff_probs,
                      k_default_coeff_probs);
           ARRAY_COPY(ctx->entropy_hdr.mv_probs,
                      k_default_mv_probs);
           ARRAY_COPY(ctx->entropy_hdr.y_mode_probs,
                      k_default_y_mode_probs);
           ARRAY_COPY(ctx->entropy_hdr.uv_mode_probs,
                      k_default_uv_mode_probs);
       }
        
       /* Set keyframe entropy defaults.  These get updated on keyframes
        * regardless of the refresh_entropy setting.
        */
       if (ctx->frame_hdr.is_keyframe)
       {
           ARRAY_COPY(ctx->entropy_hdr.coeff_probs,
                      k_default_coeff_probs);
           ARRAY_COPY(ctx->entropy_hdr.mv_probs,
                      k_default_mv_probs);
           ARRAY_COPY(ctx->entropy_hdr.y_mode_probs,
                      k_default_y_mode_probs);
           ARRAY_COPY(ctx->entropy_hdr.uv_mode_probs,
                      k_default_uv_mode_probs);
       }
        
       if (!ctx->reference_hdr.refresh_entropy)
       {
           ctx->saved_entropy = ctx->entropy_hdr;
           ctx->saved_entropy_valid = 1;
       }
        
       if (!ctx->reference_hdr.refresh_entropy)
       {
           ctx->saved_entropy = ctx->entropy_hdr;
           ctx->saved_entropy_valid = 1;
       }
        
       decode_entropy_header(ctx, &bool, &ctx->entropy_hdr);
        
       decode_entropy_header(ctx, &bool, &ctx->entropy_hdr);
        
       vp8_dixie_modemv_init(ctx);
       vp8_dixie_tokens_init(ctx);
       vp8_dixie_predict_init(ctx);
       dequant_init(ctx->dequant_factors, &ctx->segment_hdr,
                    &ctx->quant_hdr);
        
       vp8_dixie_modemv_init(ctx);
       vp8_dixie_tokens_init(ctx);
       vp8_dixie_predict_init(ctx);
       dequant_init(ctx->dequant_factors, &ctx->segment_hdr,
                    &ctx->quant_hdr);
        
       for (row = 0, partition = 0; row < ctx->mb_rows; row++)
       {
           vp8_dixie_modemv_process_row(
               ctx, &bool, row, 0, ctx->mb_cols);
           vp8_dixie_tokens_process_row(ctx, partition, row, 0,
                                        ctx->mb_cols);
           vp8_dixie_predict_process_row(ctx, row, 0, ctx->mb_cols);
        
       for (row = 0, partition = 0; row < ctx->mb_rows; row++)
       {
           vp8_dixie_modemv_process_row(
               ctx, &bool, row, 0, ctx->mb_cols);
           vp8_dixie_tokens_process_row(ctx, partition, row, 0,
                                        ctx->mb_cols);
           vp8_dixie_predict_process_row(ctx, row, 0, ctx->mb_cols);
        
           if (ctx->loopfilter_hdr.level && row)
               vp8_dixie_loopfilter_process_row(ctx, row - 1, 0,
                                                ctx->mb_cols);
        
           if (ctx->loopfilter_hdr.level && row)
               vp8_dixie_loopfilter_process_row(ctx, row - 1, 0,
                                                ctx->mb_cols);
        
           if (++partition == ctx->token_hdr.partitions)
               partition = 0;
       }
        
           if (++partition == ctx->token_hdr.partitions)
               partition = 0;
       }
        
       if (ctx->loopfilter_hdr.level)
           vp8_dixie_loopfilter_process_row(
               ctx, row - 1, 0, ctx->mb_cols);
        
       if (ctx->loopfilter_hdr.level)
           vp8_dixie_loopfilter_process_row(
               ctx, row - 1, 0, ctx->mb_cols);
        
       ctx->frame_cnt++;
        
       ctx->frame_cnt++;
        
       if (!ctx->reference_hdr.refresh_entropy)
       {
           ctx->entropy_hdr = ctx->saved_entropy;
           ctx->saved_entropy_valid = 0;
       }
        
       if (!ctx->reference_hdr.refresh_entropy)
       {
           ctx->entropy_hdr = ctx->saved_entropy;
           ctx->saved_entropy_valid = 0;
       }
        
       /* Handle reference frame updates */
       if (ctx->reference_hdr.copy_arf == 1)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
           ctx->ref_frames[ALTREF_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[LAST_FRAME]);
       }
       else if (ctx->reference_hdr.copy_arf == 2)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
           ctx->ref_frames[ALTREF_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
       }
        
       /* Handle reference frame updates */
       if (ctx->reference_hdr.copy_arf == 1)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
           ctx->ref_frames[ALTREF_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[LAST_FRAME]);
       }
       else if (ctx->reference_hdr.copy_arf == 2)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
           ctx->ref_frames[ALTREF_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
       }
        
       if (ctx->reference_hdr.copy_gf == 1)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
           ctx->ref_frames[GOLDEN_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[LAST_FRAME]);
       }
        
       if (ctx->reference_hdr.copy_gf == 1)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
           ctx->ref_frames[GOLDEN_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[LAST_FRAME]);
       }
        
       else if (ctx->reference_hdr.copy_gf == 2)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
           ctx->ref_frames[GOLDEN_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
       }
        
       else if (ctx->reference_hdr.copy_gf == 2)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
           ctx->ref_frames[GOLDEN_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
       }
        
       if (ctx->reference_hdr.refresh_gf)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
           ctx->ref_frames[GOLDEN_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[CURRENT_FRAME]);
       }
        
       if (ctx->reference_hdr.refresh_gf)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
           ctx->ref_frames[GOLDEN_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[CURRENT_FRAME]);
       }
        
       if (ctx->reference_hdr.refresh_arf)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
           ctx->ref_frames[ALTREF_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[CURRENT_FRAME]);
       }
        
       if (ctx->reference_hdr.refresh_arf)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
           ctx->ref_frames[ALTREF_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[CURRENT_FRAME]);
       }
        
       if (ctx->reference_hdr.refresh_last)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[LAST_FRAME]);
           ctx->ref_frames[LAST_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[CURRENT_FRAME]);
       }
        
       if (ctx->reference_hdr.refresh_last)
       {
           vp8_dixie_release_ref_frame(ctx->ref_frames[LAST_FRAME]);
           ctx->ref_frames[LAST_FRAME] =
               vp8_dixie_ref_frame(ctx->ref_frames[CURRENT_FRAME]);
       }
        

}

}

   void
   vp8_dixie_decode_init(struct vp8_decoder_ctx *ctx)
   {
       dequant_global_init(ctx->dequant_factors);
   }
        
   void
   vp8_dixie_decode_init(struct vp8_decoder_ctx *ctx)
   {
       dequant_global_init(ctx->dequant_factors);
   }
        
   #define CHECK_FOR_UPDATE(lval,rval,update_flag) do {\
           unsigned int old = lval; \
           update_flag |= (old != (lval = rval)); \
       } while (0)
        
   #define CHECK_FOR_UPDATE(lval,rval,update_flag) do {\
           unsigned int old = lval; \
           update_flag |= (old != (lval = rval)); \
       } while (0)
        
   vpx_codec_err_t
   vp8_parse_frame_header(const unsigned char   *data,
                          unsigned int           sz,
                          struct vp8_frame_hdr  *hdr)
   {
       unsigned long raw;
        
   vpx_codec_err_t
   vp8_parse_frame_header(const unsigned char   *data,
                          unsigned int           sz,
                          struct vp8_frame_hdr  *hdr)
   {
       unsigned long raw;
        

if (sz < 10) return VPX_CODEC_CORRUPT_FRAME;

如果(sz<10)返回VPX_编解码器_损坏_帧;

       /* The frame header is defined as a three-byte little endian
        * value
        */
       raw = data[0] | (data[1] << 8) | (data[2] << 16);
       hdr->is_keyframe     = !BITS_GET(raw, 0, 1);
       hdr->version         = BITS_GET(raw, 1, 2);
       hdr->is_experimental = BITS_GET(raw, 3, 1);
       hdr->is_shown        = BITS_GET(raw, 4, 1);
       hdr->part0_sz        = BITS_GET(raw, 5, 19);
        
       /* The frame header is defined as a three-byte little endian
        * value
        */
       raw = data[0] | (data[1] << 8) | (data[2] << 16);
       hdr->is_keyframe     = !BITS_GET(raw, 0, 1);
       hdr->version         = BITS_GET(raw, 1, 2);
       hdr->is_experimental = BITS_GET(raw, 3, 1);
       hdr->is_shown        = BITS_GET(raw, 4, 1);
       hdr->part0_sz        = BITS_GET(raw, 5, 19);
        
       if (sz <= hdr->part0_sz + (hdr->is_keyframe ? 10 : 3))
           return VPX_CODEC_CORRUPT_FRAME;
        
       if (sz <= hdr->part0_sz + (hdr->is_keyframe ? 10 : 3))
           return VPX_CODEC_CORRUPT_FRAME;
        
       hdr->frame_size_updated = 0;
        
       hdr->frame_size_updated = 0;
        
       if (hdr->is_keyframe)
       {
           unsigned int update = 0;
        
       if (hdr->is_keyframe)
       {
           unsigned int update = 0;
        
           /* Keyframe header consists of a three-byte sync code
            * followed by the width and height and associated scaling
            * factors.
            */
           if (data[3] != 0x9d || data[4] != 0x01 || data[5] != 0x2a)
               return VPX_CODEC_UNSUP_BITSTREAM;
        
           /* Keyframe header consists of a three-byte sync code
            * followed by the width and height and associated scaling
            * factors.
            */
           if (data[3] != 0x9d || data[4] != 0x01 || data[5] != 0x2a)
               return VPX_CODEC_UNSUP_BITSTREAM;
        
           raw = data[6] | (data[7] << 8)
                 | (data[8] << 16) | (data[9] << 24);
           CHECK_FOR_UPDATE(hdr->kf.w,       BITS_GET(raw,  0, 14),
                            update);
           CHECK_FOR_UPDATE(hdr->kf.scale_w, BITS_GET(raw, 14,  2),
                            update);
           CHECK_FOR_UPDATE(hdr->kf.h,       BITS_GET(raw, 16, 14),
                            update);
           CHECK_FOR_UPDATE(hdr->kf.scale_h, BITS_GET(raw, 30,  2),
                            update);
        
           raw = data[6] | (data[7] << 8)
                 | (data[8] << 16) | (data[9] << 24);
           CHECK_FOR_UPDATE(hdr->kf.w,       BITS_GET(raw,  0, 14),
                            update);
           CHECK_FOR_UPDATE(hdr->kf.scale_w, BITS_GET(raw, 14,  2),
                            update);
           CHECK_FOR_UPDATE(hdr->kf.h,       BITS_GET(raw, 16, 14),
                            update);
           CHECK_FOR_UPDATE(hdr->kf.scale_h, BITS_GET(raw, 30,  2),
                            update);
        
           hdr->frame_size_updated = update;
        
           hdr->frame_size_updated = update;
        
           if (!hdr->kf.w || !hdr->kf.h)
               return VPX_CODEC_UNSUP_BITSTREAM;
       }
        
           if (!hdr->kf.w || !hdr->kf.h)
               return VPX_CODEC_UNSUP_BITSTREAM;
       }
        
       return VPX_CODEC_OK;
   }
        
       return VPX_CODEC_OK;
   }
        
   vpx_codec_err_t
   vp8_dixie_decode_frame(struct vp8_decoder_ctx *ctx,
                          const unsigned char    *data,
                          unsigned int            sz)
   {
       volatile struct vp8_decoder_ctx *ctx_ = ctx;
        
   vpx_codec_err_t
   vp8_dixie_decode_frame(struct vp8_decoder_ctx *ctx,
                          const unsigned char    *data,
                          unsigned int            sz)
   {
       volatile struct vp8_decoder_ctx *ctx_ = ctx;
        
       ctx->error.error_code = VPX_CODEC_OK;
       ctx->error.has_detail = 0;
        
       ctx->error.error_code = VPX_CODEC_OK;
       ctx->error.has_detail = 0;
        
       if (!setjmp(ctx->error.jmp))
           decode_frame(ctx, data, sz);
        
       if (!setjmp(ctx->error.jmp))
           decode_frame(ctx, data, sz);
        
       return ctx_->error.error_code;
   }
        
       return ctx_->error.error_code;
   }
        
   void
   vp8_dixie_decode_destroy(struct vp8_decoder_ctx *ctx)
   {
       vp8_dixie_predict_destroy(ctx);
       vp8_dixie_tokens_destroy(ctx);
       vp8_dixie_modemv_destroy(ctx);
   }
        
   void
   vp8_dixie_decode_destroy(struct vp8_decoder_ctx *ctx)
   {
       vp8_dixie_predict_destroy(ctx);
       vp8_dixie_tokens_destroy(ctx);
       vp8_dixie_modemv_destroy(ctx);
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.5. dixie.h
20.5. 迪克西
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef DIXIE_H
   #define DIXIE_H
   #include "vpx_codec_internal.h"
   #include "bool_decoder.h"
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef DIXIE_H
   #define DIXIE_H
   #include "vpx_codec_internal.h"
   #include "bool_decoder.h"
        
   struct vp8_frame_hdr
   {
       unsigned int is_keyframe;      /* Frame is a keyframe */
       unsigned int is_experimental;  /* Frame is a keyframe */
       unsigned int version;          /* Bitstream version */
       unsigned int is_shown;         /* Frame is to be displayed. */
       unsigned int part0_sz;         /* Partition 0 length, in bytes */
        
   struct vp8_frame_hdr
   {
       unsigned int is_keyframe;      /* Frame is a keyframe */
       unsigned int is_experimental;  /* Frame is a keyframe */
       unsigned int version;          /* Bitstream version */
       unsigned int is_shown;         /* Frame is to be displayed. */
       unsigned int part0_sz;         /* Partition 0 length, in bytes */
        
       struct vp8_kf_hdr
       {
           unsigned int w;        /* Width */
           unsigned int h;        /* Height */
           unsigned int scale_w;  /* Scaling factor, Width */
           unsigned int scale_h;  /* Scaling factor, Height */
       } kf;
        
       struct vp8_kf_hdr
       {
           unsigned int w;        /* Width */
           unsigned int h;        /* Height */
           unsigned int scale_w;  /* Scaling factor, Width */
           unsigned int scale_h;  /* Scaling factor, Height */
       } kf;
        
       unsigned int frame_size_updated; /* Flag to indicate a resolution
                                         * update.
                                         */
   };
        
       unsigned int frame_size_updated; /* Flag to indicate a resolution
                                         * update.
                                         */
   };
        
   enum
   {
       MB_FEATURE_TREE_PROBS = 3,
       MAX_MB_SEGMENTS = 4
   };
        
   enum
   {
       MB_FEATURE_TREE_PROBS = 3,
       MAX_MB_SEGMENTS = 4
   };
        
   struct vp8_segment_hdr
   {
       unsigned int         enabled;
       unsigned int         update_data;
       unsigned int         update_map;
       unsigned int         abs;    /* 0=deltas, 1=absolute values */
       unsigned int         tree_probs[MB_FEATURE_TREE_PROBS];
       int                  lf_level[MAX_MB_SEGMENTS];
       int                  quant_idx[MAX_MB_SEGMENTS];
        
   struct vp8_segment_hdr
   {
       unsigned int         enabled;
       unsigned int         update_data;
       unsigned int         update_map;
       unsigned int         abs;    /* 0=deltas, 1=absolute values */
       unsigned int         tree_probs[MB_FEATURE_TREE_PROBS];
       int                  lf_level[MAX_MB_SEGMENTS];
       int                  quant_idx[MAX_MB_SEGMENTS];
        

};

};

   enum
   {
       BLOCK_CONTEXTS = 4
   };
        
   enum
   {
       BLOCK_CONTEXTS = 4
   };
        
   struct vp8_loopfilter_hdr
   {
       unsigned int         use_simple;
       unsigned int         level;
       unsigned int         sharpness;
       unsigned int         delta_enabled;
       int                  ref_delta[BLOCK_CONTEXTS];
       int                  mode_delta[BLOCK_CONTEXTS];
   };
        
   struct vp8_loopfilter_hdr
   {
       unsigned int         use_simple;
       unsigned int         level;
       unsigned int         sharpness;
       unsigned int         delta_enabled;
       int                  ref_delta[BLOCK_CONTEXTS];
       int                  mode_delta[BLOCK_CONTEXTS];
   };
        
   enum
   {
       MAX_PARTITIONS = 8
   };
        
   enum
   {
       MAX_PARTITIONS = 8
   };
        
   struct vp8_token_hdr
   {
       unsigned int        partitions;
       unsigned int        partition_sz[MAX_PARTITIONS];
   };
        
   struct vp8_token_hdr
   {
       unsigned int        partitions;
       unsigned int        partition_sz[MAX_PARTITIONS];
   };
        
   struct vp8_quant_hdr
   {
       unsigned int       q_index;
       int                delta_update;
       int                y1_dc_delta_q;
       int                y2_dc_delta_q;
       int                y2_ac_delta_q;
       int                uv_dc_delta_q;
       int                uv_ac_delta_q;
   };
        
   struct vp8_quant_hdr
   {
       unsigned int       q_index;
       int                delta_update;
       int                y1_dc_delta_q;
       int                y2_dc_delta_q;
       int                y2_ac_delta_q;
       int                uv_dc_delta_q;
       int                uv_ac_delta_q;
   };
        
   struct vp8_reference_hdr
   {
       unsigned int refresh_last;
       unsigned int refresh_gf;
       unsigned int refresh_arf;
       unsigned int copy_gf;
       unsigned int copy_arf;
       unsigned int sign_bias[4];
       unsigned int refresh_entropy;
   };
        
   struct vp8_reference_hdr
   {
       unsigned int refresh_last;
       unsigned int refresh_gf;
       unsigned int refresh_arf;
       unsigned int copy_gf;
       unsigned int copy_arf;
       unsigned int sign_bias[4];
       unsigned int refresh_entropy;
   };
        
   enum
   {
       BLOCK_TYPES        = 4,
       PREV_COEFF_CONTEXTS = 3,
       COEFF_BANDS         = 8,
       ENTROPY_NODES      = 11,
   };
   typedef unsigned char coeff_probs_table_t[BLOCK_TYPES][COEFF_BANDS]
   [PREV_COEFF_CONTEXTS]
   [ENTROPY_NODES];
        
   enum
   {
       BLOCK_TYPES        = 4,
       PREV_COEFF_CONTEXTS = 3,
       COEFF_BANDS         = 8,
       ENTROPY_NODES      = 11,
   };
   typedef unsigned char coeff_probs_table_t[BLOCK_TYPES][COEFF_BANDS]
   [PREV_COEFF_CONTEXTS]
   [ENTROPY_NODES];
        
   enum
   {
       MV_PROB_CNT = 2 + 8 - 1 + 10 /* from entropymv.h */
   };
   typedef unsigned char mv_component_probs_t[MV_PROB_CNT];
        
   enum
   {
       MV_PROB_CNT = 2 + 8 - 1 + 10 /* from entropymv.h */
   };
   typedef unsigned char mv_component_probs_t[MV_PROB_CNT];
        
   struct vp8_entropy_hdr
   {
       coeff_probs_table_t   coeff_probs;
       mv_component_probs_t  mv_probs[2];
       unsigned int          coeff_skip_enabled;
       unsigned char         coeff_skip_prob;
       unsigned char         y_mode_probs[4];
       unsigned char         uv_mode_probs[3];
       unsigned char         prob_inter;
       unsigned char         prob_last;
       unsigned char         prob_gf;
   };
        
   struct vp8_entropy_hdr
   {
       coeff_probs_table_t   coeff_probs;
       mv_component_probs_t  mv_probs[2];
       unsigned int          coeff_skip_enabled;
       unsigned char         coeff_skip_prob;
       unsigned char         y_mode_probs[4];
       unsigned char         uv_mode_probs[3];
       unsigned char         prob_inter;
       unsigned char         prob_last;
       unsigned char         prob_gf;
   };
        
   enum reference_frame
   {
       CURRENT_FRAME,
       LAST_FRAME,
       GOLDEN_FRAME,
       ALTREF_FRAME,
       NUM_REF_FRAMES
   };
        
   enum reference_frame
   {
       CURRENT_FRAME,
       LAST_FRAME,
       GOLDEN_FRAME,
       ALTREF_FRAME,
       NUM_REF_FRAMES
   };
        
   enum prediction_mode
   {
       /* 16x16 intra modes */
       DC_PRED, V_PRED, H_PRED, TM_PRED, B_PRED,
        
   enum prediction_mode
   {
       /* 16x16 intra modes */
       DC_PRED, V_PRED, H_PRED, TM_PRED, B_PRED,
        
       /* 16x16 inter modes */
       NEARESTMV, NEARMV, ZEROMV, NEWMV, SPLITMV,
        
       /* 16x16 inter modes */
       NEARESTMV, NEARMV, ZEROMV, NEWMV, SPLITMV,
        

MB_MODE_COUNT,

MB_模式_计数,

       /* 4x4 intra modes */
       B_DC_PRED = 0, B_TM_PRED, B_VE_PRED, B_HE_PRED, B_LD_PRED,
       B_RD_PRED, B_VR_PRED, B_VL_PRED, B_HD_PRED, B_HU_PRED,
        
       /* 4x4 intra modes */
       B_DC_PRED = 0, B_TM_PRED, B_VE_PRED, B_HE_PRED, B_LD_PRED,
       B_RD_PRED, B_VR_PRED, B_VL_PRED, B_HD_PRED, B_HU_PRED,
        
       /* 4x4 inter modes */
       LEFT4X4, ABOVE4X4, ZERO4X4, NEW4X4,
        
       /* 4x4 inter modes */
       LEFT4X4, ABOVE4X4, ZERO4X4, NEW4X4,
        

B_MODE_COUNT };

B_模式_计数};

   enum splitmv_partitioning
   {
       SPLITMV_16X8,
       SPLITMV_8X16,
       SPLITMV_8X8,
       SPLITMV_4X4
   };
        
   enum splitmv_partitioning
   {
       SPLITMV_16X8,
       SPLITMV_8X16,
       SPLITMV_8X8,
       SPLITMV_4X4
   };
        

typedef short filter_t[6];

typedef短过滤器[6];

   typedef union mv
   {
       struct
       {
           int16_t x, y;
       }  d;
       uint32_t               raw;
   } mv_t;
        
   typedef union mv
   {
       struct
       {
           int16_t x, y;
       }  d;
       uint32_t               raw;
   } mv_t;
        
   struct mb_base_info
   {
       unsigned char y_mode     : 4;
       unsigned char uv_mode    : 4;
       unsigned char segment_id : 2;
       unsigned char ref_frame  : 2;
       unsigned char skip_coeff : 1;
       unsigned char need_mc_border : 1;
       enum splitmv_partitioning  partitioning : 2;
       union mv      mv;
       unsigned int  eob_mask;
   };
        
   struct mb_base_info
   {
       unsigned char y_mode     : 4;
       unsigned char uv_mode    : 4;
       unsigned char segment_id : 2;
       unsigned char ref_frame  : 2;
       unsigned char skip_coeff : 1;
       unsigned char need_mc_border : 1;
       enum splitmv_partitioning  partitioning : 2;
       union mv      mv;
       unsigned int  eob_mask;
   };
        
   struct mb_info
   {
       struct mb_base_info base;
       union
       {
           union mv              mvs[16];
           enum prediction_mode  modes[16];
       } split;
   };
        
   struct mb_info
   {
       struct mb_base_info base;
       union
       {
           union mv              mvs[16];
           enum prediction_mode  modes[16];
       } split;
   };
        
   /* A "token entropy context" has 4 Y values, 2 U, 2 V, and 1 Y2 */
   typedef int token_entropy_ctx_t[4 + 2 + 2 + 1];
        
   /* A "token entropy context" has 4 Y values, 2 U, 2 V, and 1 Y2 */
   typedef int token_entropy_ctx_t[4 + 2 + 2 + 1];
        
   struct token_decoder
   {
       struct bool_decoder  bool;
       token_entropy_ctx_t  left_token_entropy_ctx;
       short               *coeffs;
   };
        
   struct token_decoder
   {
       struct bool_decoder  bool;
       token_entropy_ctx_t  left_token_entropy_ctx;
       short               *coeffs;
   };
        
   enum token_block_type
   {
       TOKEN_BLOCK_Y1,
       TOKEN_BLOCK_UV,
       TOKEN_BLOCK_Y2,
       TOKEN_BLOCK_TYPES,
   };
        
   enum token_block_type
   {
       TOKEN_BLOCK_Y1,
       TOKEN_BLOCK_UV,
       TOKEN_BLOCK_Y2,
       TOKEN_BLOCK_TYPES,
   };
        
   struct dequant_factors
   {
       int   quant_idx;
       short factor[TOKEN_BLOCK_TYPES][2]; /* [ Y1, UV, Y2 ]
                                            * [ DC, AC ] */
   };
        
   struct dequant_factors
   {
       int   quant_idx;
       short factor[TOKEN_BLOCK_TYPES][2]; /* [ Y1, UV, Y2 ]
                                            * [ DC, AC ] */
   };
        
   struct ref_cnt_img
   {
       vpx_image_t  img;
       unsigned int ref_cnt;
   };
        
   struct ref_cnt_img
   {
       vpx_image_t  img;
       unsigned int ref_cnt;
   };
        
   struct vp8_decoder_ctx
   {
       struct vpx_internal_error_info  error;
       unsigned int                    frame_cnt;
        
   struct vp8_decoder_ctx
   {
       struct vpx_internal_error_info  error;
       unsigned int                    frame_cnt;
        
       struct vp8_frame_hdr            frame_hdr;
       struct vp8_segment_hdr          segment_hdr;
       struct vp8_loopfilter_hdr       loopfilter_hdr;
       struct vp8_token_hdr            token_hdr;
       struct vp8_quant_hdr            quant_hdr;
       struct vp8_reference_hdr        reference_hdr;
       struct vp8_entropy_hdr          entropy_hdr;
        
       struct vp8_frame_hdr            frame_hdr;
       struct vp8_segment_hdr          segment_hdr;
       struct vp8_loopfilter_hdr       loopfilter_hdr;
       struct vp8_token_hdr            token_hdr;
       struct vp8_quant_hdr            quant_hdr;
       struct vp8_reference_hdr        reference_hdr;
       struct vp8_entropy_hdr          entropy_hdr;
        
       struct vp8_entropy_hdr          saved_entropy;
       unsigned int                    saved_entropy_valid;
        
       struct vp8_entropy_hdr          saved_entropy;
       unsigned int                    saved_entropy_valid;
        
       unsigned int                    mb_rows;
       unsigned int                    mb_cols;
       struct mb_info                 *mb_info_storage;
       struct mb_info                **mb_info_rows_storage;
       struct mb_info                **mb_info_rows;
        
       unsigned int                    mb_rows;
       unsigned int                    mb_cols;
       struct mb_info                 *mb_info_storage;
       struct mb_info                **mb_info_rows_storage;
       struct mb_info                **mb_info_rows;
        
       token_entropy_ctx_t            *above_token_entropy_ctx;
       struct token_decoder            tokens[MAX_PARTITIONS];
       struct dequant_factors          dequant_factors[MAX_MB_SEGMENTS];
        
       token_entropy_ctx_t            *above_token_entropy_ctx;
       struct token_decoder            tokens[MAX_PARTITIONS];
       struct dequant_factors          dequant_factors[MAX_MB_SEGMENTS];
        
       struct ref_cnt_img              frame_strg[NUM_REF_FRAMES];
       struct ref_cnt_img             *ref_frames[NUM_REF_FRAMES];
       ptrdiff_t                       ref_frame_offsets[4];
        
       struct ref_cnt_img              frame_strg[NUM_REF_FRAMES];
       struct ref_cnt_img             *ref_frames[NUM_REF_FRAMES];
       ptrdiff_t                       ref_frame_offsets[4];
        
       const filter_t                 *subpixel_filters;
   };
        
       const filter_t                 *subpixel_filters;
   };
        

void vp8_dixie_decode_init(struct vp8_decoder_ctx *ctx);

void vp8_dixie_decode_init(结构vp8_decoder_ctx*ctx);

void vp8_dixie_decode_destroy(struct vp8_decoder_ctx *ctx);

void vp8_dixie_decode_destroy(结构vp8_decoder_ctx*ctx);

vpx_codec_err_t vp8_parse_frame_header(const unsigned char *data, unsigned int sz, struct vp8_frame_hdr *hdr);

vpx_编解码器_err_t vp8_parse_frame_头(const unsigned char*data,unsigned int sz,struct vp8_frame_hdr*hdr);

vpx_codec_err_t vp8_dixie_decode_frame(struct vp8_decoder_ctx *ctx, const unsigned char *data, unsigned int sz);

vpx_编解码器_err_t vp8_dixie_解码_帧(结构vp8_解码器_ctx*ctx,常量无符号字符*数据,无符号整数sz);

   #define CLAMP_255(x) ((x)<0?0:((x)>255?255:(x)))
        
   #define CLAMP_255(x) ((x)<0?0:((x)>255?255:(x)))
        

#endif

#恩迪夫

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.6. dixie_loopfilter.c
20.6. dixie_loopfilter.c
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #include "dixie.h"
   #include "dixie_loopfilter.h"
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #include "dixie.h"
   #include "dixie_loopfilter.h"
        
   #define ABS(x) ((x) >= 0 ? (x) : -(x))
        
   #define ABS(x) ((x) >= 0 ? (x) : -(x))
        
   #define p3 pixels[-4*stride]
   #define p2 pixels[-3*stride]
   #define p1 pixels[-2*stride]
   #define p0 pixels[-1*stride]
   #define q0 pixels[ 0*stride]
   #define q1 pixels[ 1*stride]
   #define q2 pixels[ 2*stride]
   #define q3 pixels[ 3*stride]
        
   #define p3 pixels[-4*stride]
   #define p2 pixels[-3*stride]
   #define p1 pixels[-2*stride]
   #define p0 pixels[-1*stride]
   #define q0 pixels[ 0*stride]
   #define q1 pixels[ 1*stride]
   #define q2 pixels[ 2*stride]
   #define q3 pixels[ 3*stride]
        

#define static static int

#定义静态整型

   saturate_int8(int x)
   {
       if (x < -128)
           return -128;
        
   saturate_int8(int x)
   {
       if (x < -128)
           return -128;
        

if (x > 127) return 127;

如果(x>127)返回127;

       return x;
   }
        
       return x;
   }
        
   static int
   saturate_uint8(int x)
   {
       if (x < 0)
           return 0;
        
   static int
   saturate_uint8(int x)
   {
       if (x < 0)
           return 0;
        

if (x > 255) return 255;

如果(x>255),则返回255;

       return x;
   }
        
       return x;
   }
        
   static int
   high_edge_variance(unsigned char *pixels,
                      int            stride,
                      int            hev_threshold)
   {
       return ABS(p1 - p0) > hev_threshold ||
              ABS(q1 - q0) > hev_threshold;
   }
        
   static int
   high_edge_variance(unsigned char *pixels,
                      int            stride,
                      int            hev_threshold)
   {
       return ABS(p1 - p0) > hev_threshold ||
              ABS(q1 - q0) > hev_threshold;
   }
        
   static int
   simple_threshold(unsigned char *pixels,
                    int            stride,
                    int            filter_limit)
   {
       return (ABS(p0 - q0) * 2 + (ABS(p1 - q1) >> 1)) <= filter_limit;
   }
        
   static int
   simple_threshold(unsigned char *pixels,
                    int            stride,
                    int            filter_limit)
   {
       return (ABS(p0 - q0) * 2 + (ABS(p1 - q1) >> 1)) <= filter_limit;
   }
        
   static int
   normal_threshold(unsigned char *pixels,
                    int            stride,
                    int            edge_limit,
                    int            interior_limit)
   {
       int E = edge_limit;
       int I = interior_limit;
        
   static int
   normal_threshold(unsigned char *pixels,
                    int            stride,
                    int            edge_limit,
                    int            interior_limit)
   {
       int E = edge_limit;
       int I = interior_limit;
        
       return simple_threshold(pixels, stride, 2 * E + I)
              && ABS(p3 - p2) <= I && ABS(p2 - p1) <= I
              && ABS(p1 - p0) <= I && ABS(q3 - q2) <= I
              && ABS(q2 - q1) <= I && ABS(q1 - q0) <= I;
   }
        
       return simple_threshold(pixels, stride, 2 * E + I)
              && ABS(p3 - p2) <= I && ABS(p2 - p1) <= I
              && ABS(p1 - p0) <= I && ABS(q3 - q2) <= I
              && ABS(q2 - q1) <= I && ABS(q1 - q0) <= I;
   }
        
   static void
   filter_common(unsigned char *pixels,
                 int            stride,
                 int            use_outer_taps)
   {
       int a, f1, f2;
        
   static void
   filter_common(unsigned char *pixels,
                 int            stride,
                 int            use_outer_taps)
   {
       int a, f1, f2;
        
       a = 3 * (q0 - p0);
        
       a = 3 * (q0 - p0);
        
       if (use_outer_taps)
           a += saturate_int8(p1 - q1);
        
       if (use_outer_taps)
           a += saturate_int8(p1 - q1);
        
       a = saturate_int8(a);
        
       a = saturate_int8(a);
        
       f1 = ((a + 4 > 127) ? 127 : a + 4) >> 3;
       f2 = ((a + 3 > 127) ? 127 : a + 3) >> 3;
        
       f1 = ((a + 4 > 127) ? 127 : a + 4) >> 3;
       f2 = ((a + 3 > 127) ? 127 : a + 3) >> 3;
        
       p0 = saturate_uint8(p0 + f2);
       q0 = saturate_uint8(q0 - f1);
        
       p0 = saturate_uint8(p0 + f2);
       q0 = saturate_uint8(q0 - f1);
        
       if (!use_outer_taps)
       {
           /* This handles the case of subblock_filter()
            * (from the bitstream guide.
            */
           a = (f1 + 1) >> 1;
           p1 = saturate_uint8(p1 + a);
           q1 = saturate_uint8(q1 - a);
       }
   }
        
       if (!use_outer_taps)
       {
           /* This handles the case of subblock_filter()
            * (from the bitstream guide.
            */
           a = (f1 + 1) >> 1;
           p1 = saturate_uint8(p1 + a);
           q1 = saturate_uint8(q1 - a);
       }
   }
        
   static void
   filter_mb_edge(unsigned char *pixels,
                  int            stride)
   {
       int w, a;
        
   static void
   filter_mb_edge(unsigned char *pixels,
                  int            stride)
   {
       int w, a;
        
       w = saturate_int8(saturate_int8(p1 - q1) + 3 * (q0 - p0));
        
       w = saturate_int8(saturate_int8(p1 - q1) + 3 * (q0 - p0));
        
       a = (27 * w + 63) >> 7;
       p0 = saturate_uint8(p0 + a);
       q0 = saturate_uint8(q0 - a);
        
       a = (27 * w + 63) >> 7;
       p0 = saturate_uint8(p0 + a);
       q0 = saturate_uint8(q0 - a);
        
       a = (18 * w + 63) >> 7;
       p1 = saturate_uint8(p1 + a);
       q1 = saturate_uint8(q1 - a);
        
       a = (18 * w + 63) >> 7;
       p1 = saturate_uint8(p1 + a);
       q1 = saturate_uint8(q1 - a);
        
       a = (9 * w + 63) >> 7;
       p2 = saturate_uint8(p2 + a);
       q2 = saturate_uint8(q2 - a);
   }
        
       a = (9 * w + 63) >> 7;
       p2 = saturate_uint8(p2 + a);
       q2 = saturate_uint8(q2 - a);
   }
        
   static void
   filter_mb_v_edge(unsigned char *src,
                    int            stride,
                    int            edge_limit,
                    int            interior_limit,
                    int            hev_threshold,
                    int            size)
   {
       int i;
        
   static void
   filter_mb_v_edge(unsigned char *src,
                    int            stride,
                    int            edge_limit,
                    int            interior_limit,
                    int            hev_threshold,
                    int            size)
   {
       int i;
        
       for (i = 0; i < 8 * size; i++)
       {
           if (normal_threshold(src, 1, edge_limit, interior_limit))
           {
               if (high_edge_variance(src, 1, hev_threshold))
                   filter_common(src, 1, 1);
               else
                   filter_mb_edge(src, 1);
           }
        
       for (i = 0; i < 8 * size; i++)
       {
           if (normal_threshold(src, 1, edge_limit, interior_limit))
           {
               if (high_edge_variance(src, 1, hev_threshold))
                   filter_common(src, 1, 1);
               else
                   filter_mb_edge(src, 1);
           }
        
           src += stride;
       }
   }
        
           src += stride;
       }
   }
        
   static void
   filter_subblock_v_edge(unsigned char *src,
                          int            stride,
                          int            edge_limit,
                          int            interior_limit,
                          int            hev_threshold,
                          int            size)
   {
       int i;
        
   static void
   filter_subblock_v_edge(unsigned char *src,
                          int            stride,
                          int            edge_limit,
                          int            interior_limit,
                          int            hev_threshold,
                          int            size)
   {
       int i;
        
       for (i = 0; i < 8 * size; i++)
       {
           if (normal_threshold(src, 1, edge_limit, interior_limit))
               filter_common(src, 1,
                             high_edge_variance(src, 1, hev_threshold));
        
       for (i = 0; i < 8 * size; i++)
       {
           if (normal_threshold(src, 1, edge_limit, interior_limit))
               filter_common(src, 1,
                             high_edge_variance(src, 1, hev_threshold));
        
           src += stride;
       }
   }
        
           src += stride;
       }
   }
        
   static void
   filter_mb_h_edge(unsigned char *src,
                    int            stride,
                    int            edge_limit,
                    int            interior_limit,
                    int            hev_threshold,
                    int            size)
   {
       int i;
        
   static void
   filter_mb_h_edge(unsigned char *src,
                    int            stride,
                    int            edge_limit,
                    int            interior_limit,
                    int            hev_threshold,
                    int            size)
   {
       int i;
        
       for (i = 0; i < 8 * size; i++)
       {
           if (normal_threshold(src, stride, edge_limit,
                                interior_limit))
           {
               if (high_edge_variance(src, stride, hev_threshold))
                   filter_common(src, stride, 1);
               else
                   filter_mb_edge(src, stride);
           }
        
       for (i = 0; i < 8 * size; i++)
       {
           if (normal_threshold(src, stride, edge_limit,
                                interior_limit))
           {
               if (high_edge_variance(src, stride, hev_threshold))
                   filter_common(src, stride, 1);
               else
                   filter_mb_edge(src, stride);
           }
        
           src += 1;
       }
   }
        
           src += 1;
       }
   }
        
   static void
   filter_subblock_h_edge(unsigned char *src,
                          int            stride,
                          int            edge_limit,
                          int            interior_limit,
                          int            hev_threshold,
                          int            size)
   {
       int i;
        
   static void
   filter_subblock_h_edge(unsigned char *src,
                          int            stride,
                          int            edge_limit,
                          int            interior_limit,
                          int            hev_threshold,
                          int            size)
   {
       int i;
        
       for (i = 0; i < 8 * size; i++)
       {
           if (normal_threshold(src, stride, edge_limit,
                                interior_limit))
               filter_common(src, stride,
                             high_edge_variance(src, stride,
                                                hev_threshold));
        
       for (i = 0; i < 8 * size; i++)
       {
           if (normal_threshold(src, stride, edge_limit,
                                interior_limit))
               filter_common(src, stride,
                             high_edge_variance(src, stride,
                                                hev_threshold));
        
           src += 1;
       }
   }
        
           src += 1;
       }
   }
        
   static void
   filter_v_edge_simple(unsigned char *src,
                        int            stride,
                        int            filter_limit)
   {
       int i;
        
   static void
   filter_v_edge_simple(unsigned char *src,
                        int            stride,
                        int            filter_limit)
   {
       int i;
        
       for (i = 0; i < 16; i++)
       {
           if (simple_threshold(src, 1, filter_limit))
               filter_common(src, 1, 1);
        
       for (i = 0; i < 16; i++)
       {
           if (simple_threshold(src, 1, filter_limit))
               filter_common(src, 1, 1);
        
           src += stride;
       }
   }
        
           src += stride;
       }
   }
        
   static void
   filter_h_edge_simple(unsigned char *src,
                        int            stride,
                        int            filter_limit)
   {
       int i;
        
   static void
   filter_h_edge_simple(unsigned char *src,
                        int            stride,
                        int            filter_limit)
   {
       int i;
        
       for (i = 0; i < 16; i++)
       {
           if (simple_threshold(src, stride, filter_limit))
               filter_common(src, stride, 1);
        
       for (i = 0; i < 16; i++)
       {
           if (simple_threshold(src, stride, filter_limit))
               filter_common(src, stride, 1);
        
           src += 1;
       }
   }
        
           src += 1;
       }
   }
        
   static void
   calculate_filter_parameters(struct vp8_decoder_ctx *ctx,
                               struct mb_info         *mbi,
                               int                    *edge_limit_,
                               int                    *interior_limit_,
                               int                    *hev_threshold_)
   {
       int filter_level, interior_limit, hev_threshold;
        
   static void
   calculate_filter_parameters(struct vp8_decoder_ctx *ctx,
                               struct mb_info         *mbi,
                               int                    *edge_limit_,
                               int                    *interior_limit_,
                               int                    *hev_threshold_)
   {
       int filter_level, interior_limit, hev_threshold;
        
       /* Reference code/spec seems to conflate filter_level and
        * edge_limit
        */
        
       /* Reference code/spec seems to conflate filter_level and
        * edge_limit
        */
        
       filter_level = ctx->loopfilter_hdr.level;
        
       filter_level = ctx->loopfilter_hdr.level;
        
       if (ctx->segment_hdr.enabled)
       {
           if (!ctx->segment_hdr.abs)
               filter_level +=
                   ctx->segment_hdr.lf_level[mbi->base.segment_id];
           else
               filter_level =
                   ctx->segment_hdr.lf_level[mbi->base.segment_id];
       }
        
       if (ctx->segment_hdr.enabled)
       {
           if (!ctx->segment_hdr.abs)
               filter_level +=
                   ctx->segment_hdr.lf_level[mbi->base.segment_id];
           else
               filter_level =
                   ctx->segment_hdr.lf_level[mbi->base.segment_id];
       }
        
       if (filter_level > 63)
           filter_level = 63;
       else if (filter_level < 0)
           filter_level = 0;
        
       if (filter_level > 63)
           filter_level = 63;
       else if (filter_level < 0)
           filter_level = 0;
        
       if (ctx->loopfilter_hdr.delta_enabled)
       {
           filter_level +=
               ctx->loopfilter_hdr.ref_delta[mbi->base.ref_frame];
        
       if (ctx->loopfilter_hdr.delta_enabled)
       {
           filter_level +=
               ctx->loopfilter_hdr.ref_delta[mbi->base.ref_frame];
        
           if (mbi->base.ref_frame == CURRENT_FRAME)
           {
               if (mbi->base.y_mode == B_PRED)
                   filter_level += ctx->loopfilter_hdr.mode_delta[0];
           }
           else if (mbi->base.y_mode == ZEROMV)
               filter_level += ctx->loopfilter_hdr.mode_delta[1];
           else if (mbi->base.y_mode == SPLITMV)
               filter_level += ctx->loopfilter_hdr.mode_delta[3];
           else
               filter_level += ctx->loopfilter_hdr.mode_delta[2];
       }
        
           if (mbi->base.ref_frame == CURRENT_FRAME)
           {
               if (mbi->base.y_mode == B_PRED)
                   filter_level += ctx->loopfilter_hdr.mode_delta[0];
           }
           else if (mbi->base.y_mode == ZEROMV)
               filter_level += ctx->loopfilter_hdr.mode_delta[1];
           else if (mbi->base.y_mode == SPLITMV)
               filter_level += ctx->loopfilter_hdr.mode_delta[3];
           else
               filter_level += ctx->loopfilter_hdr.mode_delta[2];
       }
        
       if (filter_level > 63)
           filter_level = 63;
       else if (filter_level < 0)
           filter_level = 0;
        
       if (filter_level > 63)
           filter_level = 63;
       else if (filter_level < 0)
           filter_level = 0;
        

interior_limit = filter_level;

内部极限=过滤器水平;

       if (ctx->loopfilter_hdr.sharpness)
       {
           interior_limit >>= ctx->loopfilter_hdr.sharpness > 4 ? 2 : 1;
        
       if (ctx->loopfilter_hdr.sharpness)
       {
           interior_limit >>= ctx->loopfilter_hdr.sharpness > 4 ? 2 : 1;
        
           if (interior_limit > 9 - ctx->loopfilter_hdr.sharpness)
               interior_limit = 9 - ctx->loopfilter_hdr.sharpness;
       }
        
           if (interior_limit > 9 - ctx->loopfilter_hdr.sharpness)
               interior_limit = 9 - ctx->loopfilter_hdr.sharpness;
       }
        

if (interior_limit < 1) interior_limit = 1;

如果(内部极限<1)内部极限=1;

       hev_threshold = (filter_level >= 15);
        
       hev_threshold = (filter_level >= 15);
        
       if (filter_level >= 40)
           hev_threshold++;
        
       if (filter_level >= 40)
           hev_threshold++;
        
       if (filter_level >= 20 && !ctx->frame_hdr.is_keyframe)
           hev_threshold++;
        
       if (filter_level >= 20 && !ctx->frame_hdr.is_keyframe)
           hev_threshold++;
        
       *edge_limit_ = filter_level;
       *interior_limit_ = interior_limit;
       *hev_threshold_ = hev_threshold;
   }
        
       *edge_limit_ = filter_level;
       *interior_limit_ = interior_limit;
       *hev_threshold_ = hev_threshold;
   }
        
   static void
   filter_row_normal(struct vp8_decoder_ctx *ctx,
                     unsigned int            row,
                     unsigned int            start_col,
                     unsigned int            num_cols)
   {
       unsigned char  *y, *u, *v;
       int             stride, uv_stride;
       struct mb_info *mbi;
       unsigned int    col;
        
   static void
   filter_row_normal(struct vp8_decoder_ctx *ctx,
                     unsigned int            row,
                     unsigned int            start_col,
                     unsigned int            num_cols)
   {
       unsigned char  *y, *u, *v;
       int             stride, uv_stride;
       struct mb_info *mbi;
       unsigned int    col;
        
       /* Adjust pointers based on row, start_col */
        
       /* Adjust pointers based on row, start_col */
        
       stride    = ctx->ref_frames[CURRENT_FRAME]->img.stride[PLANE_Y];
       uv_stride = ctx->ref_frames[CURRENT_FRAME]->img.stride[PLANE_U];
       y = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_Y];
       u = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_U];
       v = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_V];
       y += (stride * row + start_col) * 16;
       u += (uv_stride * row + start_col) * 8;
       v += (uv_stride * row + start_col) * 8;
       mbi = ctx->mb_info_rows[row] + start_col;
        
       stride    = ctx->ref_frames[CURRENT_FRAME]->img.stride[PLANE_Y];
       uv_stride = ctx->ref_frames[CURRENT_FRAME]->img.stride[PLANE_U];
       y = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_Y];
       u = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_U];
       v = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_V];
       y += (stride * row + start_col) * 16;
       u += (uv_stride * row + start_col) * 8;
       v += (uv_stride * row + start_col) * 8;
       mbi = ctx->mb_info_rows[row] + start_col;
        
       for (col = start_col; col < start_col + num_cols; col++)
       {
           int edge_limit, interior_limit, hev_threshold;
        
       for (col = start_col; col < start_col + num_cols; col++)
       {
           int edge_limit, interior_limit, hev_threshold;
        
           /* TODO: Only need to recalculate every MB if segmentation is
            * enabled.
            */
           calculate_filter_parameters(ctx, mbi, &edge_limit,
                                       &interior_limit, &hev_threshold);
        
           /* TODO: Only need to recalculate every MB if segmentation is
            * enabled.
            */
           calculate_filter_parameters(ctx, mbi, &edge_limit,
                                       &interior_limit, &hev_threshold);
        
           if (edge_limit)
           {
               if (col)
               {
                   filter_mb_v_edge(y, stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 2);
                   filter_mb_v_edge(u, uv_stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 1);
                   filter_mb_v_edge(v, uv_stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 1);
               }
        
           if (edge_limit)
           {
               if (col)
               {
                   filter_mb_v_edge(y, stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 2);
                   filter_mb_v_edge(u, uv_stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 1);
                   filter_mb_v_edge(v, uv_stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 1);
               }
        
               /* NOTE: This conditional is actually dependent on the
                * number of coefficients decoded, not the skip flag as
                * coded in the bitstream.  The tokens task is expected
                * to set 31 if there is *any* non-zero data.
                */
               if (mbi->base.eob_mask
                   || mbi->base.y_mode == SPLITMV
                   || mbi->base.y_mode == B_PRED)
               {
                   filter_subblock_v_edge(y + 4, stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          2);
                   filter_subblock_v_edge(y + 8, stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          2);
                   filter_subblock_v_edge(y + 12, stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          2);
                   filter_subblock_v_edge(u + 4, uv_stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          1);
                   filter_subblock_v_edge(v + 4, uv_stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          1);
               }
        
               /* NOTE: This conditional is actually dependent on the
                * number of coefficients decoded, not the skip flag as
                * coded in the bitstream.  The tokens task is expected
                * to set 31 if there is *any* non-zero data.
                */
               if (mbi->base.eob_mask
                   || mbi->base.y_mode == SPLITMV
                   || mbi->base.y_mode == B_PRED)
               {
                   filter_subblock_v_edge(y + 4, stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          2);
                   filter_subblock_v_edge(y + 8, stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          2);
                   filter_subblock_v_edge(y + 12, stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          2);
                   filter_subblock_v_edge(u + 4, uv_stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          1);
                   filter_subblock_v_edge(v + 4, uv_stride, edge_limit,
                                          interior_limit, hev_threshold,
                                          1);
               }
        
               if (row)
               {
                   filter_mb_h_edge(y, stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 2);
                   filter_mb_h_edge(u, uv_stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 1);
                   filter_mb_h_edge(v, uv_stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 1);
               }
        
               if (row)
               {
                   filter_mb_h_edge(y, stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 2);
                   filter_mb_h_edge(u, uv_stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 1);
                   filter_mb_h_edge(v, uv_stride, edge_limit + 2,
                                    interior_limit, hev_threshold, 1);
               }
        
               if (mbi->base.eob_mask
                   || mbi->base.y_mode == SPLITMV
                   || mbi->base.y_mode == B_PRED)
               {
                   filter_subblock_h_edge(y + 4 * stride, stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 2);
                   filter_subblock_h_edge(y + 8 * stride, stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 2);
                   filter_subblock_h_edge(y + 12 * stride, stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 2);
                   filter_subblock_h_edge(u + 4 * uv_stride, uv_stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 1);
                   filter_subblock_h_edge(v + 4 * uv_stride, uv_stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 1);
               }
           }
        
               if (mbi->base.eob_mask
                   || mbi->base.y_mode == SPLITMV
                   || mbi->base.y_mode == B_PRED)
               {
                   filter_subblock_h_edge(y + 4 * stride, stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 2);
                   filter_subblock_h_edge(y + 8 * stride, stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 2);
                   filter_subblock_h_edge(y + 12 * stride, stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 2);
                   filter_subblock_h_edge(u + 4 * uv_stride, uv_stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 1);
                   filter_subblock_h_edge(v + 4 * uv_stride, uv_stride,
                                          edge_limit, interior_limit,
                                          hev_threshold, 1);
               }
           }
        
           y += 16;
           u += 8;
           v += 8;
           mbi++;
       }
   }
        
           y += 16;
           u += 8;
           v += 8;
           mbi++;
       }
   }
        
   static void
   filter_row_simple(struct vp8_decoder_ctx *ctx,
                     unsigned int            row,
                     unsigned int            start_col,
                     unsigned int            num_cols)
   {
       unsigned char  *y;
       int             stride;
       struct mb_info *mbi;
       unsigned int    col;
        
   static void
   filter_row_simple(struct vp8_decoder_ctx *ctx,
                     unsigned int            row,
                     unsigned int            start_col,
                     unsigned int            num_cols)
   {
       unsigned char  *y;
       int             stride;
       struct mb_info *mbi;
       unsigned int    col;
        
       /* Adjust pointers based on row, start_col */
       stride    = ctx->ref_frames[CURRENT_FRAME]->img.stride[PLANE_Y];
       y = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_Y];
       y += (stride * row + start_col) * 16;
       mbi = ctx->mb_info_rows[row] + start_col;
        
       /* Adjust pointers based on row, start_col */
       stride    = ctx->ref_frames[CURRENT_FRAME]->img.stride[PLANE_Y];
       y = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_Y];
       y += (stride * row + start_col) * 16;
       mbi = ctx->mb_info_rows[row] + start_col;
        
       for (col = start_col; col < start_col + num_cols; col++)
       {
           int edge_limit, interior_limit, hev_threshold;
        
       for (col = start_col; col < start_col + num_cols; col++)
       {
           int edge_limit, interior_limit, hev_threshold;
        
           /* TODO: Only need to recalculate every MB if segmentation is
            * enabled.
            */
           calculate_filter_parameters(ctx, mbi, &edge_limit,
                                       &interior_limit, &hev_threshold);
        
           /* TODO: Only need to recalculate every MB if segmentation is
            * enabled.
            */
           calculate_filter_parameters(ctx, mbi, &edge_limit,
                                       &interior_limit, &hev_threshold);
        

if (edge_limit) {

if(边缘限制){

               /* NOTE: This conditional is actually dependent on the
                * number of coefficients decoded, not the skip flag as
                * coded in the bitstream.  The tokens task is expected
                * to set 31 if there is *any* non-zero data.
                */
               int filter_subblocks = (mbi->base.eob_mask
                                       || mbi->base.y_mode == SPLITMV
                                       || mbi->base.y_mode == B_PRED);
               int mb_limit = (edge_limit + 2) * 2 + interior_limit;
               int b_limit = edge_limit * 2 + interior_limit;
        
               /* NOTE: This conditional is actually dependent on the
                * number of coefficients decoded, not the skip flag as
                * coded in the bitstream.  The tokens task is expected
                * to set 31 if there is *any* non-zero data.
                */
               int filter_subblocks = (mbi->base.eob_mask
                                       || mbi->base.y_mode == SPLITMV
                                       || mbi->base.y_mode == B_PRED);
               int mb_limit = (edge_limit + 2) * 2 + interior_limit;
               int b_limit = edge_limit * 2 + interior_limit;
        

if (col) filter_v_edge_simple(y, stride, mb_limit);

if(col)filter_v_edge_simple(y、步幅、mb_限制);

               if (filter_subblocks)
               {
                   filter_v_edge_simple(y + 4, stride, b_limit);
                   filter_v_edge_simple(y + 8, stride, b_limit);
                   filter_v_edge_simple(y + 12, stride, b_limit);
               }
        
               if (filter_subblocks)
               {
                   filter_v_edge_simple(y + 4, stride, b_limit);
                   filter_v_edge_simple(y + 8, stride, b_limit);
                   filter_v_edge_simple(y + 12, stride, b_limit);
               }
        

if (row) filter_h_edge_simple(y, stride, mb_limit);

if(row)filter_h_edge_simple(y、步幅、mb_限制);

               if (filter_subblocks)
               {
                   filter_h_edge_simple(y + 4 * stride, stride,
                                        b_limit);
                   filter_h_edge_simple(y + 8 * stride, stride,
                                        b_limit);
                   filter_h_edge_simple(y + 12 * stride, stride,
                                        b_limit);
               }
           }
        
               if (filter_subblocks)
               {
                   filter_h_edge_simple(y + 4 * stride, stride,
                                        b_limit);
                   filter_h_edge_simple(y + 8 * stride, stride,
                                        b_limit);
                   filter_h_edge_simple(y + 12 * stride, stride,
                                        b_limit);
               }
           }
        
           y += 16;
           mbi++;
       }
   }
        
           y += 16;
           mbi++;
       }
   }
        
   void
   vp8_dixie_loopfilter_process_row(struct vp8_decoder_ctx *ctx,
                                    unsigned int            row,
                                    unsigned int            start_col,
                                    unsigned int            num_cols)
   {
       if (ctx->loopfilter_hdr.use_simple)
           filter_row_simple(ctx, row, start_col, num_cols);
       else
           filter_row_normal(ctx, row, start_col, num_cols);
   }
        
   void
   vp8_dixie_loopfilter_process_row(struct vp8_decoder_ctx *ctx,
                                    unsigned int            row,
                                    unsigned int            start_col,
                                    unsigned int            num_cols)
   {
       if (ctx->loopfilter_hdr.use_simple)
           filter_row_simple(ctx, row, start_col, num_cols);
       else
           filter_row_normal(ctx, row, start_col, num_cols);
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.7. dixie_loopfilter.h
20.7. dixie_loopfilter.h
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef DIXIE_LOOPFILTER_H
   #define DIXIE_LOOPFILTER_H
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef DIXIE_LOOPFILTER_H
   #define DIXIE_LOOPFILTER_H
        

void vp8_dixie_loopfilter_process_row(struct vp8_decoder_ctx *ctx, unsigned int row, unsigned int start_col, unsigned int num_cols);

void vp8_dixie_loopfilter_process_row(结构vp8_解码器_ctx*ctx,无符号整数行,无符号整数起始列,无符号整数列);

#endif

#恩迪夫

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.8. idct_add.c
20.8. idct\U add.c
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #include "dixie.h"
   #include "idct_add.h"
   #include <assert.h>
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #include "dixie.h"
   #include "idct_add.h"
   #include <assert.h>
        
   void
   vp8_dixie_walsh(const short *input, short *output)
   {
       int i;
       int a1, b1, c1, d1;
       int a2, b2, c2, d2;
       const short *ip = input;
       short *op = output;
        
   void
   vp8_dixie_walsh(const short *input, short *output)
   {
       int i;
       int a1, b1, c1, d1;
       int a2, b2, c2, d2;
       const short *ip = input;
       short *op = output;
        
       for (i = 0; i < 4; i++)
       {
           a1 = ip[0] + ip[12];
           b1 = ip[4] + ip[8];
           c1 = ip[4] - ip[8];
           d1 = ip[0] - ip[12];
        
       for (i = 0; i < 4; i++)
       {
           a1 = ip[0] + ip[12];
           b1 = ip[4] + ip[8];
           c1 = ip[4] - ip[8];
           d1 = ip[0] - ip[12];
        
           op[0] = a1 + b1;
           op[4] = c1 + d1;
           op[8] = a1 - b1;
           op[12] = d1 - c1;
           ip++;
           op++;
       }
        
           op[0] = a1 + b1;
           op[4] = c1 + d1;
           op[8] = a1 - b1;
           op[12] = d1 - c1;
           ip++;
           op++;
       }
        
       ip = output;
       op = output;
        
       ip = output;
       op = output;
        
       for (i = 0; i < 4; i++)
       {
           a1 = ip[0] + ip[3];
           b1 = ip[1] + ip[2];
           c1 = ip[1] - ip[2];
           d1 = ip[0] - ip[3];
        
       for (i = 0; i < 4; i++)
       {
           a1 = ip[0] + ip[3];
           b1 = ip[1] + ip[2];
           c1 = ip[1] - ip[2];
           d1 = ip[0] - ip[3];
        
           a2 = a1 + b1;
           b2 = c1 + d1;
           c2 = a1 - b1;
           d2 = d1 - c1;
        
           a2 = a1 + b1;
           b2 = c1 + d1;
           c2 = a1 - b1;
           d2 = d1 - c1;
        
           op[0] = (a2 + 3) >> 3;
           op[1] = (b2 + 3) >> 3;
           op[2] = (c2 + 3) >> 3;
           op[3] = (d2 + 3) >> 3;
        
           op[0] = (a2 + 3) >> 3;
           op[1] = (b2 + 3) >> 3;
           op[2] = (c2 + 3) >> 3;
           op[3] = (d2 + 3) >> 3;
        
           ip += 4;
           op += 4;
       }
   }
        
           ip += 4;
           op += 4;
       }
   }
        
   #define cospi8sqrt2minus1 20091
   #define sinpi8sqrt2       35468
   #define rounding          0
   static void
   idct_columns(const short *input, short *output)
   {
       int i;
       int a1, b1, c1, d1;
        
   #define cospi8sqrt2minus1 20091
   #define sinpi8sqrt2       35468
   #define rounding          0
   static void
   idct_columns(const short *input, short *output)
   {
       int i;
       int a1, b1, c1, d1;
        
       const short *ip = input;
       short *op = output;
       int temp1, temp2;
       int shortpitch = 4;
        
       const short *ip = input;
       short *op = output;
       int temp1, temp2;
       int shortpitch = 4;
        
       for (i = 0; i < 4; i++)
       {
           a1 = ip[0] + ip[8];
           b1 = ip[0] - ip[8];
        
       for (i = 0; i < 4; i++)
       {
           a1 = ip[0] + ip[8];
           b1 = ip[0] - ip[8];
        
           temp1 = (ip[4] * sinpi8sqrt2 + rounding) >> 16;
           temp2 = ip[12] +
               ((ip[12] * cospi8sqrt2minus1 + rounding) >> 16);
           c1 = temp1 - temp2;
        
           temp1 = (ip[4] * sinpi8sqrt2 + rounding) >> 16;
           temp2 = ip[12] +
               ((ip[12] * cospi8sqrt2minus1 + rounding) >> 16);
           c1 = temp1 - temp2;
        
           temp1 = ip[4] +
               ((ip[4] * cospi8sqrt2minus1 + rounding) >> 16);
           temp2 = (ip[12] * sinpi8sqrt2 + rounding) >> 16;
           d1 = temp1 + temp2;
        
           temp1 = ip[4] +
               ((ip[4] * cospi8sqrt2minus1 + rounding) >> 16);
           temp2 = (ip[12] * sinpi8sqrt2 + rounding) >> 16;
           d1 = temp1 + temp2;
        
           op[shortpitch*0] = a1 + d1;
           op[shortpitch*3] = a1 - d1;
        
           op[shortpitch*0] = a1 + d1;
           op[shortpitch*3] = a1 - d1;
        
           op[shortpitch*1] = b1 + c1;
           op[shortpitch*2] = b1 - c1;
        
           op[shortpitch*1] = b1 + c1;
           op[shortpitch*2] = b1 - c1;
        
           ip++;
           op++;
       }
   }
        
           ip++;
           op++;
       }
   }
        
   void
   vp8_dixie_idct_add(unsigned char        *recon,
                      const unsigned char  *predict,
                      int                   stride,
                      const short          *coeffs)
   {
       int i;
       int a1, b1, c1, d1, temp1, temp2;
       short tmp[16];
       idct_columns(coeffs, tmp);
       coeffs = tmp;
        
   void
   vp8_dixie_idct_add(unsigned char        *recon,
                      const unsigned char  *predict,
                      int                   stride,
                      const short          *coeffs)
   {
       int i;
       int a1, b1, c1, d1, temp1, temp2;
       short tmp[16];
       idct_columns(coeffs, tmp);
       coeffs = tmp;
        
       for (i = 0; i < 4; i++)
       {
           a1 = coeffs[0] + coeffs[2];
           b1 = coeffs[0] - coeffs[2];
        
       for (i = 0; i < 4; i++)
       {
           a1 = coeffs[0] + coeffs[2];
           b1 = coeffs[0] - coeffs[2];
        
           temp1 = (coeffs[1] * sinpi8sqrt2 + rounding) >> 16;
           temp2 = coeffs[3] +
               ((coeffs[3] * cospi8sqrt2minus1 + rounding) >> 16);
           c1 = temp1 - temp2;
        
           temp1 = (coeffs[1] * sinpi8sqrt2 + rounding) >> 16;
           temp2 = coeffs[3] +
               ((coeffs[3] * cospi8sqrt2minus1 + rounding) >> 16);
           c1 = temp1 - temp2;
        
           temp1 = coeffs[1] +
               ((coeffs[1] * cospi8sqrt2minus1 + rounding) >> 16);
           temp2 = (coeffs[3] * sinpi8sqrt2 + rounding) >> 16;
           d1 = temp1 + temp2;
        
           temp1 = coeffs[1] +
               ((coeffs[1] * cospi8sqrt2minus1 + rounding) >> 16);
           temp2 = (coeffs[3] * sinpi8sqrt2 + rounding) >> 16;
           d1 = temp1 + temp2;
        
           recon[0] = CLAMP_255(predict[0] + ((a1 + d1 + 4) >> 3));
           recon[3] = CLAMP_255(predict[3] + ((a1 - d1 + 4) >> 3));
           recon[1] = CLAMP_255(predict[1] + ((b1 + c1 + 4) >> 3));
           recon[2] = CLAMP_255(predict[2] + ((b1 - c1 + 4) >> 3));
        
           recon[0] = CLAMP_255(predict[0] + ((a1 + d1 + 4) >> 3));
           recon[3] = CLAMP_255(predict[3] + ((a1 - d1 + 4) >> 3));
           recon[1] = CLAMP_255(predict[1] + ((b1 + c1 + 4) >> 3));
           recon[2] = CLAMP_255(predict[2] + ((b1 - c1 + 4) >> 3));
        
           coeffs += 4;
           recon += stride;
           predict += stride;
       }
   }
        
           coeffs += 4;
           recon += stride;
           predict += stride;
       }
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.9. idct_add.h
20.9. idct_add.h
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef IDCT_ADD_H
   #define IDCT_ADD_H
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef IDCT_ADD_H
   #define IDCT_ADD_H
        

void vp8_dixie_idct_add_init(struct vp8_decoder_ctx *ctx);

void vp8_dixie_idct_add_init(结构vp8_解码器_ctx*ctx);

void vp8_dixie_idct_add(unsigned char *recon, const unsigned char *predict, int stride, const short *coeffs);

void vp8_dixie_idct_add(无符号字符*侦察,常数无符号字符*预测,整数步长,常数短*系数);

   void
   vp8_dixie_walsh(const short *in, short *out);
        
   void
   vp8_dixie_walsh(const short *in, short *out);
        

void vp8_dixie_idct_add_process_row(struct vp8_decoder_ctx *ctx, short *coeffs, unsigned int row, unsigned int start_col, unsigned int num_cols); #endif

void vp8_dixie_idct_add_process_row(结构vp8_decoder_ctx*ctx,short*coefs,unsigned int row,unsigned int start_col,unsigned int num cols)#恩迪夫

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.10. mem.h
20.10. 成员h
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef VPX_PORTS_MEM_H
   #define VPX_PORTS_MEM_H
   #include "vpx_config.h"
   #include "vpx_integer.h"
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef VPX_PORTS_MEM_H
   #define VPX_PORTS_MEM_H
   #include "vpx_config.h"
   #include "vpx_integer.h"
        
   #if defined(__GNUC__) && __GNUC__
   #define DECLARE_ALIGNED(n,typ,val)  typ val __attribute__ \
       ((aligned (n)))
   #elif defined(_MSC_VER)
   #define DECLARE_ALIGNED(n,typ,val)  __declspec(align(n)) typ val
   #else
   #warning No alignment directives known for this compiler.
   #define DECLARE_ALIGNED(n,typ,val)  typ val
   #endif
   #endif
        
   #if defined(__GNUC__) && __GNUC__
   #define DECLARE_ALIGNED(n,typ,val)  typ val __attribute__ \
       ((aligned (n)))
   #elif defined(_MSC_VER)
   #define DECLARE_ALIGNED(n,typ,val)  __declspec(align(n)) typ val
   #else
   #warning No alignment directives known for this compiler.
   #define DECLARE_ALIGNED(n,typ,val)  typ val
   #endif
   #endif
        
   /* Declare an aligned array on the stack, for situations where the
    * stack pointer may not have the alignment we expect.  Creates an
    * array with a modified name, then defines val to be a pointer, and
    * aligns that pointer within the array.
    */
   #define DECLARE_ALIGNED_ARRAY(a,typ,val,n)\
   typ val##_[(n)+(a)/sizeof(typ)+1];\
   typ *val = (typ*)((((intptr_t)val##_)+(a)-1)&((intptr_t)-(a)))
        
   /* Declare an aligned array on the stack, for situations where the
    * stack pointer may not have the alignment we expect.  Creates an
    * array with a modified name, then defines val to be a pointer, and
    * aligns that pointer within the array.
    */
   #define DECLARE_ALIGNED_ARRAY(a,typ,val,n)\
   typ val##_[(n)+(a)/sizeof(typ)+1];\
   typ *val = (typ*)((((intptr_t)val##_)+(a)-1)&((intptr_t)-(a)))
        
   /* Indicates that the usage of the specified variable has been
    * audited to assure that it's safe to use uninitialized.  Silences
    * 'may be used uninitialized' warnings on gcc.
    */
   #if defined(__GNUC__) && __GNUC__
   #define UNINITIALIZED_IS_SAFE(x) x=x
   #else
   #define UNINITIALIZED_IS_SAFE(x) x
   #endif
        
   /* Indicates that the usage of the specified variable has been
    * audited to assure that it's safe to use uninitialized.  Silences
    * 'may be used uninitialized' warnings on gcc.
    */
   #if defined(__GNUC__) && __GNUC__
   #define UNINITIALIZED_IS_SAFE(x) x=x
   #else
   #define UNINITIALIZED_IS_SAFE(x) x
   #endif
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.11. modemv.c
20.11. modemv.c
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #include "dixie.h"
   #include "modemv_data.h"
   #include <stdlib.h>
   #include <assert.h>
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #include "dixie.h"
   #include "modemv_data.h"
   #include <stdlib.h>
   #include <assert.h>
        
   struct mv_clamp_rect
   {
       int to_left, to_right, to_top, to_bottom;
   };
        
   struct mv_clamp_rect
   {
       int to_left, to_right, to_top, to_bottom;
   };
        
   static union mv
           clamp_mv(union mv raw, const struct mv_clamp_rect *bounds)
   {
       union mv newmv;
        
   static union mv
           clamp_mv(union mv raw, const struct mv_clamp_rect *bounds)
   {
       union mv newmv;
        
       newmv.d.x = (raw.d.x < bounds->to_left)
                   ? bounds->to_left : raw.d.x;
       newmv.d.x = (raw.d.x > bounds->to_right)
                   ? bounds->to_right : newmv.d.x;
       newmv.d.y = (raw.d.y < bounds->to_top)
                   ? bounds->to_top : raw.d.y;
       newmv.d.y = (raw.d.y > bounds->to_bottom)
                   ? bounds->to_bottom : newmv.d.y;
       return newmv;
   }
        
       newmv.d.x = (raw.d.x < bounds->to_left)
                   ? bounds->to_left : raw.d.x;
       newmv.d.x = (raw.d.x > bounds->to_right)
                   ? bounds->to_right : newmv.d.x;
       newmv.d.y = (raw.d.y < bounds->to_top)
                   ? bounds->to_top : raw.d.y;
       newmv.d.y = (raw.d.y > bounds->to_bottom)
                   ? bounds->to_bottom : newmv.d.y;
       return newmv;
   }
        
   static int
   read_segment_id(struct bool_decoder *bool,
                   struct vp8_segment_hdr *seg)
   {
       return bool_get(bool, seg->tree_probs[0])
              ? 2 + bool_get(bool, seg->tree_probs[2])
              : bool_get(bool, seg->tree_probs[1]);
   }
        
   static int
   read_segment_id(struct bool_decoder *bool,
                   struct vp8_segment_hdr *seg)
   {
       return bool_get(bool, seg->tree_probs[0])
              ? 2 + bool_get(bool, seg->tree_probs[2])
              : bool_get(bool, seg->tree_probs[1]);
   }
        
   static enum prediction_mode
   above_block_mode(const struct mb_info *this,
                    const struct mb_info *above,
                    unsigned int b)
   {
       if (b < 4)
       {
           switch (above->base.y_mode)
           {
           case DC_PRED:
               return B_DC_PRED;
           case V_PRED:
               return B_VE_PRED;
           case H_PRED:
               return B_HE_PRED;
        
   static enum prediction_mode
   above_block_mode(const struct mb_info *this,
                    const struct mb_info *above,
                    unsigned int b)
   {
       if (b < 4)
       {
           switch (above->base.y_mode)
           {
           case DC_PRED:
               return B_DC_PRED;
           case V_PRED:
               return B_VE_PRED;
           case H_PRED:
               return B_HE_PRED;
        
           case TM_PRED:
               return B_TM_PRED;
           case B_PRED:
               return above->split.modes[b+12];
           default:
               assert(0);
           }
       }
        
           case TM_PRED:
               return B_TM_PRED;
           case B_PRED:
               return above->split.modes[b+12];
           default:
               assert(0);
           }
       }
        
       return this->split.modes[b-4];
   }
        
       return this->split.modes[b-4];
   }
        
   static enum prediction_mode
   left_block_mode(const struct mb_info *this,
                   const struct mb_info *left,
                   unsigned int b)
   {
       if (!(b & 3))
       {
           switch (left->base.y_mode)
           {
           case DC_PRED:
               return B_DC_PRED;
           case V_PRED:
               return B_VE_PRED;
           case H_PRED:
               return B_HE_PRED;
           case TM_PRED:
               return B_TM_PRED;
           case B_PRED:
               return left->split.modes[b+3];
           default:
               assert(0);
           }
       }
        
   static enum prediction_mode
   left_block_mode(const struct mb_info *this,
                   const struct mb_info *left,
                   unsigned int b)
   {
       if (!(b & 3))
       {
           switch (left->base.y_mode)
           {
           case DC_PRED:
               return B_DC_PRED;
           case V_PRED:
               return B_VE_PRED;
           case H_PRED:
               return B_HE_PRED;
           case TM_PRED:
               return B_TM_PRED;
           case B_PRED:
               return left->split.modes[b+3];
           default:
               assert(0);
           }
       }
        
       return this->split.modes[b-1];
   }
        
       return this->split.modes[b-1];
   }
        
   static void
   decode_kf_mb_mode(struct mb_info      *this,
                     struct mb_info      *left,
                     struct mb_info      *above,
                     struct bool_decoder *bool)
   {
       int y_mode, uv_mode;
        
   static void
   decode_kf_mb_mode(struct mb_info      *this,
                     struct mb_info      *left,
                     struct mb_info      *above,
                     struct bool_decoder *bool)
   {
       int y_mode, uv_mode;
        
       y_mode = bool_read_tree(bool, kf_y_mode_tree, kf_y_mode_probs);
        
       y_mode = bool_read_tree(bool, kf_y_mode_tree, kf_y_mode_probs);
        
       if (y_mode == B_PRED)
       {
           unsigned int i;
        
       if (y_mode == B_PRED)
       {
           unsigned int i;
        
           for (i = 0; i < 16; i++)
           {
               enum prediction_mode a = above_block_mode(this, above,
                                                         i);
               enum prediction_mode l = left_block_mode(this, left, i);
               enum prediction_mode b;
        
           for (i = 0; i < 16; i++)
           {
               enum prediction_mode a = above_block_mode(this, above,
                                                         i);
               enum prediction_mode l = left_block_mode(this, left, i);
               enum prediction_mode b;
        
               b = bool_read_tree(bool, b_mode_tree,
                                  kf_b_mode_probs[a][l]);
               this->split.modes[i] = b;
           }
       }
        
               b = bool_read_tree(bool, b_mode_tree,
                                  kf_b_mode_probs[a][l]);
               this->split.modes[i] = b;
           }
       }
        
       uv_mode = bool_read_tree(bool, uv_mode_tree, kf_uv_mode_probs);
        
       uv_mode = bool_read_tree(bool, uv_mode_tree, kf_uv_mode_probs);
        
       this->base.y_mode = y_mode;
       this->base.uv_mode = uv_mode;
       this->base.mv.raw = 0;
       this->base.ref_frame = 0;
   }
        
       this->base.y_mode = y_mode;
       this->base.uv_mode = uv_mode;
       this->base.mv.raw = 0;
       this->base.ref_frame = 0;
   }
        
   static void
   decode_intra_mb_mode(struct mb_info         *this,
                        struct vp8_entropy_hdr *hdr,
                        struct bool_decoder    *bool)
   {
       /* Like decode_kf_mb_mode, but with probabilities transmitted in
        * the bitstream and no context on the above/left block mode.
        */
       int y_mode, uv_mode;
        
   static void
   decode_intra_mb_mode(struct mb_info         *this,
                        struct vp8_entropy_hdr *hdr,
                        struct bool_decoder    *bool)
   {
       /* Like decode_kf_mb_mode, but with probabilities transmitted in
        * the bitstream and no context on the above/left block mode.
        */
       int y_mode, uv_mode;
        
       y_mode = bool_read_tree(bool, y_mode_tree, hdr->y_mode_probs);
        
       y_mode = bool_read_tree(bool, y_mode_tree, hdr->y_mode_probs);
        
       if (y_mode == B_PRED)
       {
           unsigned int i;
        
       if (y_mode == B_PRED)
       {
           unsigned int i;
        
           for (i = 0; i < 16; i++)
           {
               enum prediction_mode b;
        
           for (i = 0; i < 16; i++)
           {
               enum prediction_mode b;
        
               b = bool_read_tree(bool, b_mode_tree,
                                  default_b_mode_probs);
               this->split.modes[i] = b;
           }
       }
        
               b = bool_read_tree(bool, b_mode_tree,
                                  default_b_mode_probs);
               this->split.modes[i] = b;
           }
       }
        
       uv_mode = bool_read_tree(bool, uv_mode_tree, hdr->uv_mode_probs);
        
       uv_mode = bool_read_tree(bool, uv_mode_tree, hdr->uv_mode_probs);
        
       this->base.y_mode = y_mode;
       this->base.uv_mode = uv_mode;
       this->base.mv.raw = 0;
       this->base.ref_frame = CURRENT_FRAME;
   }
        
       this->base.y_mode = y_mode;
       this->base.uv_mode = uv_mode;
       this->base.mv.raw = 0;
       this->base.ref_frame = CURRENT_FRAME;
   }
        
   static int
   read_mv_component(struct bool_decoder *bool,
                     const unsigned char  mvc[MV_PROB_CNT])
   {
       enum {IS_SHORT, SIGN, SHORT, BITS = SHORT + 8 - 1,
             LONG_WIDTH = 10};
       int x = 0;
        
   static int
   read_mv_component(struct bool_decoder *bool,
                     const unsigned char  mvc[MV_PROB_CNT])
   {
       enum {IS_SHORT, SIGN, SHORT, BITS = SHORT + 8 - 1,
             LONG_WIDTH = 10};
       int x = 0;
        
       if (bool_get(bool, mvc[IS_SHORT])) /* Large */
       {
           int i = 0;
        
       if (bool_get(bool, mvc[IS_SHORT])) /* Large */
       {
           int i = 0;
        
           for (i = 0; i < 3; i++)
               x += bool_get(bool, mvc[BITS + i]) << i;
        
           for (i = 0; i < 3; i++)
               x += bool_get(bool, mvc[BITS + i]) << i;
        
           /* Skip bit 3, which is sometimes implicit */
           for (i = LONG_WIDTH - 1; i > 3; i--)
               x += bool_get(bool, mvc[BITS + i]) << i;
        
           /* Skip bit 3, which is sometimes implicit */
           for (i = LONG_WIDTH - 1; i > 3; i--)
               x += bool_get(bool, mvc[BITS + i]) << i;
        
           if (!(x & 0xFFF0)  ||  bool_get(bool, mvc[BITS + 3]))
               x += 8;
       }
       else   /* small */
           x = bool_read_tree(bool, small_mv_tree, mvc + SHORT);
        
           if (!(x & 0xFFF0)  ||  bool_get(bool, mvc[BITS + 3]))
               x += 8;
       }
       else   /* small */
           x = bool_read_tree(bool, small_mv_tree, mvc + SHORT);
        
       if (x && bool_get(bool, mvc[SIGN]))
           x = -x;
        
       if (x && bool_get(bool, mvc[SIGN]))
           x = -x;
        
       return x << 1;
   }
        
       return x << 1;
   }
        
   static mv_t
   above_block_mv(const struct mb_info *this,
                  const struct mb_info *above,
                  unsigned int          b)
   {
       if (b < 4)
       {
           if (above->base.y_mode == SPLITMV)
               return above->split.mvs[b+12];
        
   static mv_t
   above_block_mv(const struct mb_info *this,
                  const struct mb_info *above,
                  unsigned int          b)
   {
       if (b < 4)
       {
           if (above->base.y_mode == SPLITMV)
               return above->split.mvs[b+12];
        
           return above->base.mv;
       }
        
           return above->base.mv;
       }
        
       return this->split.mvs[b-4];
   }
        
       return this->split.mvs[b-4];
   }
        
   static mv_t
   left_block_mv(const struct mb_info *this,
                 const struct mb_info *left,
                 unsigned int          b)
   {
       if (!(b & 3))
       {
           if (left->base.y_mode == SPLITMV)
               return left->split.mvs[b+3];
        
   static mv_t
   left_block_mv(const struct mb_info *this,
                 const struct mb_info *left,
                 unsigned int          b)
   {
       if (!(b & 3))
       {
           if (left->base.y_mode == SPLITMV)
               return left->split.mvs[b+3];
        
           return left->base.mv;
       }
        
           return left->base.mv;
       }
        
       return this->split.mvs[b-1];
   }
        
       return this->split.mvs[b-1];
   }
        
   static enum prediction_mode
   submv_ref(struct bool_decoder *bool, union mv l, union mv a)
   {
       enum subblock_mv_ref
       {
           SUBMVREF_NORMAL,
           SUBMVREF_LEFT_ZED,
           SUBMVREF_ABOVE_ZED,
           SUBMVREF_LEFT_ABOVE_SAME,
           SUBMVREF_LEFT_ABOVE_ZED
       };
        
   static enum prediction_mode
   submv_ref(struct bool_decoder *bool, union mv l, union mv a)
   {
       enum subblock_mv_ref
       {
           SUBMVREF_NORMAL,
           SUBMVREF_LEFT_ZED,
           SUBMVREF_ABOVE_ZED,
           SUBMVREF_LEFT_ABOVE_SAME,
           SUBMVREF_LEFT_ABOVE_ZED
       };
        
       int lez = !(l.raw);
       int aez = !(a.raw);
       int lea = l.raw == a.raw;
       enum subblock_mv_ref ctx = SUBMVREF_NORMAL;
        
       int lez = !(l.raw);
       int aez = !(a.raw);
       int lea = l.raw == a.raw;
       enum subblock_mv_ref ctx = SUBMVREF_NORMAL;
        
       if (lea && lez)
           ctx = SUBMVREF_LEFT_ABOVE_ZED;
       else if (lea)
           ctx = SUBMVREF_LEFT_ABOVE_SAME;
       else if (aez)
           ctx = SUBMVREF_ABOVE_ZED;
       else if (lez)
           ctx = SUBMVREF_LEFT_ZED;
        
       if (lea && lez)
           ctx = SUBMVREF_LEFT_ABOVE_ZED;
       else if (lea)
           ctx = SUBMVREF_LEFT_ABOVE_SAME;
       else if (aez)
           ctx = SUBMVREF_ABOVE_ZED;
       else if (lez)
           ctx = SUBMVREF_LEFT_ZED;
        
       return bool_read_tree(bool, submv_ref_tree,
                             submv_ref_probs2[ctx]);
   }
        
       return bool_read_tree(bool, submv_ref_tree,
                             submv_ref_probs2[ctx]);
   }
        
   static void
   read_mv(struct bool_decoder  *bool,
           union mv             *mv,
           mv_component_probs_t  mvc[2])
   {
       mv->d.y = read_mv_component(bool, mvc[0]);
       mv->d.x = read_mv_component(bool, mvc[1]);
   }
        
   static void
   read_mv(struct bool_decoder  *bool,
           union mv             *mv,
           mv_component_probs_t  mvc[2])
   {
       mv->d.y = read_mv_component(bool, mvc[0]);
       mv->d.x = read_mv_component(bool, mvc[1]);
   }
        
   static void
   mv_bias(const struct mb_info *mb,
           const unsigned int   sign_bias[3],
           enum reference_frame ref_frame,
           union mv             *mv)
   {
       if (sign_bias[mb->base.ref_frame] ^ sign_bias[ref_frame])
       {
           mv->d.x *= -1;
           mv->d.y *= -1;
       }
   }
        
   static void
   mv_bias(const struct mb_info *mb,
           const unsigned int   sign_bias[3],
           enum reference_frame ref_frame,
           union mv             *mv)
   {
       if (sign_bias[mb->base.ref_frame] ^ sign_bias[ref_frame])
       {
           mv->d.x *= -1;
           mv->d.y *= -1;
       }
   }
        
   enum near_mv_v
   {
       CNT_BEST = 0,
       CNT_ZEROZERO = 0,
       CNT_NEAREST,
       CNT_NEAR,
       CNT_SPLITMV
   };
        
   enum near_mv_v
   {
       CNT_BEST = 0,
       CNT_ZEROZERO = 0,
       CNT_NEAREST,
       CNT_NEAR,
       CNT_SPLITMV
   };
        
   static void
   find_near_mvs(const struct mb_info   *this,
                 const struct mb_info   *left,
                 const struct mb_info   *above,
                 const unsigned int      sign_bias[3],
                 union  mv               near_mvs[4],
                 int                     cnt[4])
   {
       const struct mb_info *aboveleft = above - 1;
       union  mv             *mv = near_mvs;
       int                   *cntx = cnt;
        
   static void
   find_near_mvs(const struct mb_info   *this,
                 const struct mb_info   *left,
                 const struct mb_info   *above,
                 const unsigned int      sign_bias[3],
                 union  mv               near_mvs[4],
                 int                     cnt[4])
   {
       const struct mb_info *aboveleft = above - 1;
       union  mv             *mv = near_mvs;
       int                   *cntx = cnt;
        
       /* Zero accumulators */
       mv[0].raw = mv[1].raw = mv[2].raw = 0;
       cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
        
       /* Zero accumulators */
       mv[0].raw = mv[1].raw = mv[2].raw = 0;
       cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
        
       /* Process above */
       if (above->base.ref_frame != CURRENT_FRAME)
       {
           if (above->base.mv.raw)
           {
               (++mv)->raw = above->base.mv.raw;
               mv_bias(above, sign_bias, this->base.ref_frame, mv);
               ++cntx;
           }
        
       /* Process above */
       if (above->base.ref_frame != CURRENT_FRAME)
       {
           if (above->base.mv.raw)
           {
               (++mv)->raw = above->base.mv.raw;
               mv_bias(above, sign_bias, this->base.ref_frame, mv);
               ++cntx;
           }
        
           *cntx += 2;
       }
        
           *cntx += 2;
       }
        
       /* Process left */
       if (left->base.ref_frame != CURRENT_FRAME)
       {
           if (left->base.mv.raw)
           {
               union mv this_mv;
        
       /* Process left */
       if (left->base.ref_frame != CURRENT_FRAME)
       {
           if (left->base.mv.raw)
           {
               union mv this_mv;
        
               this_mv.raw = left->base.mv.raw;
               mv_bias(left, sign_bias, this->base.ref_frame, &this_mv);
        
               this_mv.raw = left->base.mv.raw;
               mv_bias(left, sign_bias, this->base.ref_frame, &this_mv);
        
               if (this_mv.raw != mv->raw)
               {
                   (++mv)->raw = this_mv.raw;
                   ++cntx;
               }
        
               if (this_mv.raw != mv->raw)
               {
                   (++mv)->raw = this_mv.raw;
                   ++cntx;
               }
        
               *cntx += 2;
           }
           else
               cnt[CNT_ZEROZERO] += 2;
       }
        
               *cntx += 2;
           }
           else
               cnt[CNT_ZEROZERO] += 2;
       }
        
       /* Process above left */
       if (aboveleft->base.ref_frame != CURRENT_FRAME)
       {
           if (aboveleft->base.mv.raw)
           {
               union mv this_mv;
        
       /* Process above left */
       if (aboveleft->base.ref_frame != CURRENT_FRAME)
       {
           if (aboveleft->base.mv.raw)
           {
               union mv this_mv;
        
               this_mv.raw = aboveleft->base.mv.raw;
               mv_bias(aboveleft, sign_bias, this->base.ref_frame,
                       &this_mv);
        
               this_mv.raw = aboveleft->base.mv.raw;
               mv_bias(aboveleft, sign_bias, this->base.ref_frame,
                       &this_mv);
        
               if (this_mv.raw != mv->raw)
               {
                   (++mv)->raw = this_mv.raw;
                   ++cntx;
               }
        
               if (this_mv.raw != mv->raw)
               {
                   (++mv)->raw = this_mv.raw;
                   ++cntx;
               }
        
               *cntx += 1;
           }
           else
               cnt[CNT_ZEROZERO] += 1;
       }
        
               *cntx += 1;
           }
           else
               cnt[CNT_ZEROZERO] += 1;
       }
        
       /* If we have three distinct MVs ... */
        
       /* If we have three distinct MVs ... */
        
       if (cnt[CNT_SPLITMV])
       {
           /* See if above-left MV can be merged with NEAREST */
           if (mv->raw == near_mvs[CNT_NEAREST].raw)
               cnt[CNT_NEAREST] += 1;
       }
        
       if (cnt[CNT_SPLITMV])
       {
           /* See if above-left MV can be merged with NEAREST */
           if (mv->raw == near_mvs[CNT_NEAREST].raw)
               cnt[CNT_NEAREST] += 1;
       }
        
       cnt[CNT_SPLITMV] = ((above->base.y_mode == SPLITMV)
                           + (left->base.y_mode == SPLITMV)) * 2
                          + (aboveleft->base.y_mode == SPLITMV);
        
       cnt[CNT_SPLITMV] = ((above->base.y_mode == SPLITMV)
                           + (left->base.y_mode == SPLITMV)) * 2
                          + (aboveleft->base.y_mode == SPLITMV);
        
       /* Swap near and nearest if necessary */
       if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
       {
           int tmp;
           tmp = cnt[CNT_NEAREST];
           cnt[CNT_NEAREST] = cnt[CNT_NEAR];
           cnt[CNT_NEAR] = tmp;
           tmp = near_mvs[CNT_NEAREST].raw;
           near_mvs[CNT_NEAREST].raw = near_mvs[CNT_NEAR].raw;
           near_mvs[CNT_NEAR].raw = tmp;
       }
        
       /* Swap near and nearest if necessary */
       if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
       {
           int tmp;
           tmp = cnt[CNT_NEAREST];
           cnt[CNT_NEAREST] = cnt[CNT_NEAR];
           cnt[CNT_NEAR] = tmp;
           tmp = near_mvs[CNT_NEAREST].raw;
           near_mvs[CNT_NEAREST].raw = near_mvs[CNT_NEAR].raw;
           near_mvs[CNT_NEAR].raw = tmp;
       }
        
       /* Use near_mvs[CNT_BEST] to store the "best" MV.  Note that this
        * storage shares the same address as near_mvs[CNT_ZEROZERO].
        */
       if (cnt[CNT_NEAREST] >= cnt[CNT_BEST])
           near_mvs[CNT_BEST] = near_mvs[CNT_NEAREST];
   }
        
       /* Use near_mvs[CNT_BEST] to store the "best" MV.  Note that this
        * storage shares the same address as near_mvs[CNT_ZEROZERO].
        */
       if (cnt[CNT_NEAREST] >= cnt[CNT_BEST])
           near_mvs[CNT_BEST] = near_mvs[CNT_NEAREST];
   }
        
   static void
   decode_split_mv(struct mb_info         *this,
                   const struct mb_info   *left,
                   const struct mb_info   *above,
                   struct vp8_entropy_hdr *hdr,
                   union  mv              *best_mv,
                   struct bool_decoder    *bool)
   {
       const int *partition;
       int        j, k, mask, partition_id;
        
   static void
   decode_split_mv(struct mb_info         *this,
                   const struct mb_info   *left,
                   const struct mb_info   *above,
                   struct vp8_entropy_hdr *hdr,
                   union  mv              *best_mv,
                   struct bool_decoder    *bool)
   {
       const int *partition;
       int        j, k, mask, partition_id;
        
       partition_id = bool_read_tree(bool, split_mv_tree,
                                     split_mv_probs);
       partition = mv_partitions[partition_id];
       this->base.partitioning = partition_id;
        
       partition_id = bool_read_tree(bool, split_mv_tree,
                                     split_mv_probs);
       partition = mv_partitions[partition_id];
       this->base.partitioning = partition_id;
        
       for (j = 0, mask = 0; mask < 65535; j++)
       {
           union mv mv, left_mv, above_mv;
           enum prediction_mode subblock_mode;
        
       for (j = 0, mask = 0; mask < 65535; j++)
       {
           union mv mv, left_mv, above_mv;
           enum prediction_mode subblock_mode;
        
           /* Find the first subblock in this partition. */
           for (k = 0; j != partition[k]; k++);
        
           /* Find the first subblock in this partition. */
           for (k = 0; j != partition[k]; k++);
        
           /* Decode the next MV */
           left_mv = left_block_mv(this, left, k);
           above_mv = above_block_mv(this, above, k);
           subblock_mode = submv_ref(bool, left_mv,  above_mv);
        
           /* Decode the next MV */
           left_mv = left_block_mv(this, left, k);
           above_mv = above_block_mv(this, above, k);
           subblock_mode = submv_ref(bool, left_mv,  above_mv);
        
           switch (subblock_mode)
           {
           case LEFT4X4:
               mv = left_mv;
               break;
           case ABOVE4X4:
               mv = above_mv;
               break;
           case ZERO4X4:
               mv.raw = 0;
               break;
           case NEW4X4:
               read_mv(bool, &mv, hdr->mv_probs);
               mv.d.x += best_mv->d.x;
               mv.d.y += best_mv->d.y;
               break;
           default:
               assert(0);
           }
        
           switch (subblock_mode)
           {
           case LEFT4X4:
               mv = left_mv;
               break;
           case ABOVE4X4:
               mv = above_mv;
               break;
           case ZERO4X4:
               mv.raw = 0;
               break;
           case NEW4X4:
               read_mv(bool, &mv, hdr->mv_probs);
               mv.d.x += best_mv->d.x;
               mv.d.y += best_mv->d.y;
               break;
           default:
               assert(0);
           }
        
           /* Fill the MVs for this partition */
           for (; k < 16; k++)
               if (j == partition[k])
               {
                   this->split.mvs[k] = mv;
                   mask |= 1 << k;
               }
       }
   }
        
           /* Fill the MVs for this partition */
           for (; k < 16; k++)
               if (j == partition[k])
               {
                   this->split.mvs[k] = mv;
                   mask |= 1 << k;
               }
       }
   }
        
   static int
   need_mc_border(union mv mv, int l, int t, int b_w, int w, int h)
   {
       int b, r;
        
   static int
   need_mc_border(union mv mv, int l, int t, int b_w, int w, int h)
   {
       int b, r;
        
       /* Get distance to edge for top-left pixel */
       l += (mv.d.x >> 3);
       t += (mv.d.y >> 3);
        
       /* Get distance to edge for top-left pixel */
       l += (mv.d.x >> 3);
       t += (mv.d.y >> 3);
        
       /* Get distance to edge for bottom-right pixel */
       r = w - (l + b_w);
       b = h - (t + b_w);
        
       /* Get distance to edge for bottom-right pixel */
       r = w - (l + b_w);
       b = h - (t + b_w);
        
       return (l >> 1 < 2 || r >> 1 < 3 || t >> 1 < 2 || b >> 1 < 3);
   }
        
       return (l >> 1 < 2 || r >> 1 < 3 || t >> 1 < 2 || b >> 1 < 3);
   }
        
   static void
   decode_mvs(struct vp8_decoder_ctx       *ctx,
              struct mb_info               *this,
              const struct mb_info         *left,
              const struct mb_info         *above,
              const struct mv_clamp_rect   *bounds,
              struct bool_decoder          *bool)
   {
       struct vp8_entropy_hdr *hdr = &ctx->entropy_hdr;
       union mv          near_mvs[4];
       union mv          clamped_best_mv;
       int               mv_cnts[4];
       unsigned char     probs[4];
       enum {BEST, NEAREST, NEAR};
       int x, y, w, h, b;
        
   static void
   decode_mvs(struct vp8_decoder_ctx       *ctx,
              struct mb_info               *this,
              const struct mb_info         *left,
              const struct mb_info         *above,
              const struct mv_clamp_rect   *bounds,
              struct bool_decoder          *bool)
   {
       struct vp8_entropy_hdr *hdr = &ctx->entropy_hdr;
       union mv          near_mvs[4];
       union mv          clamped_best_mv;
       int               mv_cnts[4];
       unsigned char     probs[4];
       enum {BEST, NEAREST, NEAR};
       int x, y, w, h, b;
        
       this->base.ref_frame = bool_get(bool, hdr->prob_last)
                              ? 2 + bool_get(bool, hdr->prob_gf)
                              : 1;
        
       this->base.ref_frame = bool_get(bool, hdr->prob_last)
                              ? 2 + bool_get(bool, hdr->prob_gf)
                              : 1;
        
       find_near_mvs(this, this - 1, above,
                     ctx->reference_hdr.sign_bias, near_mvs, mv_cnts);
       probs[0] = mv_counts_to_probs[mv_cnts[0]][0];
       probs[1] = mv_counts_to_probs[mv_cnts[1]][1];
       probs[2] = mv_counts_to_probs[mv_cnts[2]][2];
       probs[3] = mv_counts_to_probs[mv_cnts[3]][3];
        
       find_near_mvs(this, this - 1, above,
                     ctx->reference_hdr.sign_bias, near_mvs, mv_cnts);
       probs[0] = mv_counts_to_probs[mv_cnts[0]][0];
       probs[1] = mv_counts_to_probs[mv_cnts[1]][1];
       probs[2] = mv_counts_to_probs[mv_cnts[2]][2];
       probs[3] = mv_counts_to_probs[mv_cnts[3]][3];
        
       this->base.y_mode = bool_read_tree(bool, mv_ref_tree, probs);
       this->base.uv_mode = this->base.y_mode;
        
       this->base.y_mode = bool_read_tree(bool, mv_ref_tree, probs);
       this->base.uv_mode = this->base.y_mode;
        
       this->base.need_mc_border = 0;
       x = (-bounds->to_left - 128) >> 3;
       y = (-bounds->to_top - 128) >> 3;
       w = ctx->mb_cols * 16;
       h = ctx->mb_rows * 16;
        
       this->base.need_mc_border = 0;
       x = (-bounds->to_left - 128) >> 3;
       y = (-bounds->to_top - 128) >> 3;
       w = ctx->mb_cols * 16;
       h = ctx->mb_rows * 16;
        
       switch (this->base.y_mode)
       {
       case NEARESTMV:
           this->base.mv = clamp_mv(near_mvs[NEAREST], bounds);
           break;
       case NEARMV:
           this->base.mv = clamp_mv(near_mvs[NEAR], bounds);
           break;
       case ZEROMV:
           this->base.mv.raw = 0;
           return; //skip need_mc_border check
       case NEWMV:
           clamped_best_mv = clamp_mv(near_mvs[BEST], bounds);
           read_mv(bool, &this->base.mv, hdr->mv_probs);
           this->base.mv.d.x += clamped_best_mv.d.x;
           this->base.mv.d.y += clamped_best_mv.d.y;
           break;
       case SPLITMV:
       {
           union mv          chroma_mv[4] = {{{0}}};
        
       switch (this->base.y_mode)
       {
       case NEARESTMV:
           this->base.mv = clamp_mv(near_mvs[NEAREST], bounds);
           break;
       case NEARMV:
           this->base.mv = clamp_mv(near_mvs[NEAR], bounds);
           break;
       case ZEROMV:
           this->base.mv.raw = 0;
           return; //skip need_mc_border check
       case NEWMV:
           clamped_best_mv = clamp_mv(near_mvs[BEST], bounds);
           read_mv(bool, &this->base.mv, hdr->mv_probs);
           this->base.mv.d.x += clamped_best_mv.d.x;
           this->base.mv.d.y += clamped_best_mv.d.y;
           break;
       case SPLITMV:
       {
           union mv          chroma_mv[4] = {{{0}}};
        
           clamped_best_mv = clamp_mv(near_mvs[BEST], bounds);
           decode_split_mv(this, left, above, hdr, &clamped_best_mv,
                           bool);
           this->base.mv = this->split.mvs[15];
        
           clamped_best_mv = clamp_mv(near_mvs[BEST], bounds);
           decode_split_mv(this, left, above, hdr, &clamped_best_mv,
                           bool);
           this->base.mv = this->split.mvs[15];
        
           for (b = 0; b < 16; b++)
           {
               chroma_mv[(b>>1&1) + (b>>2&2)].d.x +=
                   this->split.mvs[b].d.x;
               chroma_mv[(b>>1&1) + (b>>2&2)].d.y +=
                   this->split.mvs[b].d.y;
        
           for (b = 0; b < 16; b++)
           {
               chroma_mv[(b>>1&1) + (b>>2&2)].d.x +=
                   this->split.mvs[b].d.x;
               chroma_mv[(b>>1&1) + (b>>2&2)].d.y +=
                   this->split.mvs[b].d.y;
        
               if (need_mc_border(this->split.mvs[b],
               x + (b & 3) * 4, y + (b & ~3), 4, w, h))
               {
                   this->base.need_mc_border = 1;
                   break;
               }
           }
        
               if (need_mc_border(this->split.mvs[b],
               x + (b & 3) * 4, y + (b & ~3), 4, w, h))
               {
                   this->base.need_mc_border = 1;
                   break;
               }
           }
        
           for (b = 0; b < 4; b++)
           {
               chroma_mv[b].d.x += 4 + 8 * (chroma_mv[b].d.x >> 31);
               chroma_mv[b].d.y += 4 + 8 * (chroma_mv[b].d.y >> 31);
               chroma_mv[b].d.x /= 4;
               chroma_mv[b].d.y /= 4;
        
           for (b = 0; b < 4; b++)
           {
               chroma_mv[b].d.x += 4 + 8 * (chroma_mv[b].d.x >> 31);
               chroma_mv[b].d.y += 4 + 8 * (chroma_mv[b].d.y >> 31);
               chroma_mv[b].d.x /= 4;
               chroma_mv[b].d.y /= 4;
        

//note we're passing in non-subsampled coordinates

//注意,我们传递的是非二次采样坐标

               if (need_mc_border(chroma_mv[b],
               x + (b & 1) * 8, y + (b >> 1) * 8, 16, w, h))
               {
                   this->base.need_mc_border = 1;
                   break;
               }
           }
        
               if (need_mc_border(chroma_mv[b],
               x + (b & 1) * 8, y + (b >> 1) * 8, 16, w, h))
               {
                   this->base.need_mc_border = 1;
                   break;
               }
           }
        
           return; //skip need_mc_border check
       }
       default:
           assert(0);
       }
        
           return; //skip need_mc_border check
       }
       default:
           assert(0);
       }
        
       if (need_mc_border(this->base.mv, x, y, 16, w, h))
           this->base.need_mc_border = 1;
   }
        
       if (need_mc_border(this->base.mv, x, y, 16, w, h))
           this->base.need_mc_border = 1;
   }
        
   void
   vp8_dixie_modemv_process_row(struct vp8_decoder_ctx *ctx,
   struct bool_decoder    *bool,
   int                     row,
   int                     start_col,
   int                     num_cols)
   {
       struct mb_info       *above, *this;
       unsigned int          col;
       struct mv_clamp_rect  bounds;
        
   void
   vp8_dixie_modemv_process_row(struct vp8_decoder_ctx *ctx,
   struct bool_decoder    *bool,
   int                     row,
   int                     start_col,
   int                     num_cols)
   {
       struct mb_info       *above, *this;
       unsigned int          col;
       struct mv_clamp_rect  bounds;
        
       this = ctx->mb_info_rows[row] + start_col;
       above = ctx->mb_info_rows[row - 1] + start_col;
        
       this = ctx->mb_info_rows[row] + start_col;
       above = ctx->mb_info_rows[row - 1] + start_col;
        
       /* Calculate the eighth-pel MV bounds using a 1 MB border. */
       bounds.to_left   = -((start_col + 1) << 7);
       bounds.to_right  = (ctx->mb_cols - start_col) << 7;
       bounds.to_top    = -((row + 1) << 7);
       bounds.to_bottom = (ctx->mb_rows - row) << 7;
        
       /* Calculate the eighth-pel MV bounds using a 1 MB border. */
       bounds.to_left   = -((start_col + 1) << 7);
       bounds.to_right  = (ctx->mb_cols - start_col) << 7;
       bounds.to_top    = -((row + 1) << 7);
       bounds.to_bottom = (ctx->mb_rows - row) << 7;
        
       for (col = start_col; col < start_col + num_cols; col++)
       {
           if (ctx->segment_hdr.update_map)
               this->base.segment_id = read_segment_id(bool,
               &ctx->segment_hdr);
        
       for (col = start_col; col < start_col + num_cols; col++)
       {
           if (ctx->segment_hdr.update_map)
               this->base.segment_id = read_segment_id(bool,
               &ctx->segment_hdr);
        
           if (ctx->entropy_hdr.coeff_skip_enabled)
               this->base.skip_coeff = bool_get(bool,
               ctx->entropy_hdr.coeff_skip_prob);
        
           if (ctx->entropy_hdr.coeff_skip_enabled)
               this->base.skip_coeff = bool_get(bool,
               ctx->entropy_hdr.coeff_skip_prob);
        
           if (ctx->frame_hdr.is_keyframe)
           {
               if (!ctx->segment_hdr.update_map)
                   this->base.segment_id = 0;
        
           if (ctx->frame_hdr.is_keyframe)
           {
               if (!ctx->segment_hdr.update_map)
                   this->base.segment_id = 0;
        
               decode_kf_mb_mode(this, this - 1, above, bool);
           }
           else
           {
               if (bool_get(bool, ctx->entropy_hdr.prob_inter))
                   decode_mvs(ctx, this, this - 1, above, &bounds,
                              bool);
               else
                   decode_intra_mb_mode(this, &ctx->entropy_hdr, bool);
        
               decode_kf_mb_mode(this, this - 1, above, bool);
           }
           else
           {
               if (bool_get(bool, ctx->entropy_hdr.prob_inter))
                   decode_mvs(ctx, this, this - 1, above, &bounds,
                              bool);
               else
                   decode_intra_mb_mode(this, &ctx->entropy_hdr, bool);
        
               bounds.to_left -= 16 << 3;
               bounds.to_right -= 16 << 3;
           }
        
               bounds.to_left -= 16 << 3;
               bounds.to_right -= 16 << 3;
           }
        
           /* Advance to next mb */
           this++;
           above++;
       }
   }
        
           /* Advance to next mb */
           this++;
           above++;
       }
   }
        
   void
   vp8_dixie_modemv_init(struct vp8_decoder_ctx *ctx)
   {
       unsigned int    mbi_w, mbi_h, i;
       struct mb_info *mbi;
        
   void
   vp8_dixie_modemv_init(struct vp8_decoder_ctx *ctx)
   {
       unsigned int    mbi_w, mbi_h, i;
       struct mb_info *mbi;
        
       mbi_w = ctx->mb_cols + 1; /* For left border col */
       mbi_h = ctx->mb_rows + 1; /* For above border row */
        
       mbi_w = ctx->mb_cols + 1; /* For left border col */
       mbi_h = ctx->mb_rows + 1; /* For above border row */
        
       if (ctx->frame_hdr.frame_size_updated)
       {
           free(ctx->mb_info_storage);
           ctx->mb_info_storage = NULL;
           free(ctx->mb_info_rows_storage);
           ctx->mb_info_rows_storage = NULL;
       }
        
       if (ctx->frame_hdr.frame_size_updated)
       {
           free(ctx->mb_info_storage);
           ctx->mb_info_storage = NULL;
           free(ctx->mb_info_rows_storage);
           ctx->mb_info_rows_storage = NULL;
       }
        
       if (!ctx->mb_info_storage)
           ctx->mb_info_storage = calloc(mbi_w * mbi_h,
           sizeof(*ctx->mb_info_storage));
        
       if (!ctx->mb_info_storage)
           ctx->mb_info_storage = calloc(mbi_w * mbi_h,
           sizeof(*ctx->mb_info_storage));
        

if (!ctx->mb_info_rows_storage)

如果(!ctx->mb\u信息\u行\u存储)

           ctx->mb_info_rows_storage = calloc(mbi_h,
           sizeof(*ctx->mb_info_rows_storage));
        
           ctx->mb_info_rows_storage = calloc(mbi_h,
           sizeof(*ctx->mb_info_rows_storage));
        
       /* Set up row pointers */
       mbi = ctx->mb_info_storage + 1;
        
       /* Set up row pointers */
       mbi = ctx->mb_info_storage + 1;
        
       for (i = 0; i < mbi_h; i++)
       {
           ctx->mb_info_rows_storage[i] = mbi;
           mbi += mbi_w;
       }
        
       for (i = 0; i < mbi_h; i++)
       {
           ctx->mb_info_rows_storage[i] = mbi;
           mbi += mbi_w;
       }
        
       ctx->mb_info_rows = ctx->mb_info_rows_storage + 1;
   }
        
       ctx->mb_info_rows = ctx->mb_info_rows_storage + 1;
   }
        
   void
   vp8_dixie_modemv_destroy(struct vp8_decoder_ctx *ctx)
   {
       free(ctx->mb_info_storage);
       ctx->mb_info_storage = NULL;
       free(ctx->mb_info_rows_storage);
       ctx->mb_info_rows_storage = NULL;
   }
        
   void
   vp8_dixie_modemv_destroy(struct vp8_decoder_ctx *ctx)
   {
       free(ctx->mb_info_storage);
       ctx->mb_info_storage = NULL;
       free(ctx->mb_info_rows_storage);
       ctx->mb_info_rows_storage = NULL;
   }
        
   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.12. modemv.h
20.12. modemv.h
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef MODEMV_H
   #define MODEMV_H
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
   #ifndef MODEMV_H
   #define MODEMV_H
        

void vp8_dixie_modemv_init(struct vp8_decoder_ctx *ctx);

无效vp8_dixie_modemv_init(结构vp8_解码器_ctx*ctx);

void vp8_dixie_modemv_destroy(struct vp8_decoder_ctx *ctx);

无效vp8_dixie_modemv_destroy(结构vp8_解码器_ctx*ctx);

void vp8_dixie_modemv_process_row(struct vp8_decoder_ctx *ctx, struct bool_decoder *bool, int row, int start_col, int num_cols);

无效vp8_dixie_modemv_process_row(结构vp8_decoder_ctx*ctx,结构bool_decoder*bool,int row,int start_col,int num_cols);

#endif

#恩迪夫

   ---- End code block ----------------------------------------
        
   ---- End code block ----------------------------------------
        
20.13. modemv_data.h
20.13. modemv_data.h
   ---- Begin code block --------------------------------------
        
   ---- Begin code block --------------------------------------
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
        
   /*
    *  Copyright (c) 2010, 2011, Google Inc.  All rights reserved.
    *
    *  Use of this source code is governed by a BSD-style license
    *  that can be found in the LICENSE file in the root of the source
    *  tree.  An additional intellectual property rights grant can be
    *  found in the file PATENTS.  All contributing project authors may
    *  be found in the AUTHORS file in the root of the source tree.
    */
        
   static const unsigned char kf_y_mode_probs[] = { 145, 156, 163, 128};
   static const unsigned char kf_uv_mode_probs[] = { 142, 114, 183};
   static const unsigned char kf_b_mode_probs[10][10][9] =
   {
     { /* above mode 0 */
       { /* left mode 0 */ 231, 120,  48,  89, 115, 113, 120, 152, 112},
       { /* left mode 1 */ 152, 179,  64, 126, 170, 118,  46,  70,  95},
       { /* left mode 2 */ 175,  69, 143,  80,  85,  82,  72, 155, 103},
       { /* left mode 3 */  56,  58,  10, 171, 218, 189,  17,  13, 152},
       { /* left mode 4 */ 144,  71,  10,  38, 171, 213, 144,  34,  26},
       { /* left mode 5 */ 114,  26,  17, 163,  44, 195,  21,  10, 173},
       { /* left mode 6 */ 121,  24,  80, 195,  26,  62,  44,  64,  85},
       { /* left mode 7 */ 170,  46,  55,  19, 136, 160,  33, 206,  71},
       { /* left mode 8 */  63,  20,   8, 114, 114, 208,  12,   9, 226},
       { /* left mode 9 */  81,  40,  11,  96, 182,  84,  29,  16,  36}
     },
     { /* above mode 1 */
       { /* left mode 0 */ 134, 183,  89, 137,  98, 101, 106, 165, 148},
       { /* left mode 1 */  72, 187, 100, 130, 157, 111,  32,  75,  80},
       { /* left mode 2 */  66, 102, 167,  99,  74,  62,  40, 234, 128},
       { /* left mode 3 */  41,  53,   9, 178, 241, 141,  26,   8, 107},
       { /* left mode 4 */ 104,  79,  12,  27, 217, 255,  87,  17,   7},
       { /* left mode 5 */  74,  43,  26, 146,  73, 166,  49,  23, 157},
       { /* left mode 6 */  65,  38, 105, 160,  51,  52,  31, 115, 128},
       { /* left mode 7 */  87,  68,  71,  44, 114,  51,  15, 186,  23},
       { /* left mode 8 */  47,  41,  14, 110, 182, 183,  21,  17, 194},
       { /* left mode 9 */  66,  45,  25, 102, 197, 189,  23,  18,  22}
     },
     { /* above mode 2 */
       { /* left mode 0 */  88,  88, 147, 150,  42,  46,  45, 196, 205},
       { /* left mode 1 */  43,  97, 183, 117,  85,  38,  35, 179,  61},
       { /* left mode 2 */  39,  53, 200,  87,  26,  21,  43, 232, 171},
       { /* left mode 3 */  56,  34,  51, 104, 114, 102,  29,  93,  77},
       { /* left mode 4 */ 107,  54,  32,  26,  51,   1,  81,  43,  31},
        
   static const unsigned char kf_y_mode_probs[] = { 145, 156, 163, 128};
   static const unsigned char kf_uv_mode_probs[] = { 142, 114, 183};
   static const unsigned char kf_b_mode_probs[10][10][9] =
   {
     { /* above mode 0 */
       { /* left mode 0 */ 231, 120,  48,  89, 115, 113, 120, 152, 112},
       { /* left mode 1 */ 152, 179,  64, 126, 170, 118,  46,  70,  95},
       { /* left mode 2 */ 175,  69, 143,  80,  85,  82,  72, 155, 103},
       { /* left mode 3 */  56,  58,  10, 171, 218, 189,  17,  13, 152},
       { /* left mode 4 */ 144,  71,  10,  38, 171, 213, 144,  34,  26},
       { /* left mode 5 */ 114,  26,  17, 163,  44, 195,  21,  10, 173},
       { /* left mode 6 */ 121,  24,  80, 195,  26,  62,  44,  64,  85},
       { /* left mode 7 */ 170,  46,  55,  19, 136, 160,  33, 206,  71},
       { /* left mode 8 */  63,  20,   8, 114, 114, 208,  12,   9, 226},
       { /* left mode 9 */  81,  40,  11,  96, 182,  84,  29,  16,  36}
     },
     { /* above mode 1 */
       { /* left mode 0 */ 134, 183,  89, 137,  98, 101, 106, 165, 148},
       { /* left mode 1 */  72, 187, 100, 130, 157, 111,  32,  75,  80},
       { /* left mode 2 */  66, 102, 167,  99,  74,  62,  40, 234, 128},
       { /* left mode 3 */  41,  53,   9, 178, 241, 141,  26,   8, 107},
       { /* left mode 4 */ 104,  79,  12,  27, 217, 255,  87,  17,   7},
       { /* left mode 5 */  74,  43,  26, 146,  73, 166,  49,  23, 157},
       { /* left mode 6 */  65,  38, 105, 160,  51,  52,  31, 115, 128},
       { /* left mode 7 */  87,  68,  71,  44, 114,  51,  15, 186,  23},
       { /* left mode 8 */  47,  41,  14, 110, 182, 183,  21,  17, 194},
       { /* left mode 9 */  66,  45,  25, 102, 197, 189,  23,  18,  22}
     },
     { /* above mode 2 */
       { /* left mode 0 */  88,  88, 147, 150,  42,  46,  45, 196, 205},
       { /* left mode 1 */  43,  97, 183, 117,  85,  38,  35, 179,  61},
       { /* left mode 2 */  39,  53, 200,  87,  26,  21,  43, 232, 171},
       { /* left mode 3 */  56,  34,  51, 104, 114, 102,  29,  93,  77},
       { /* left mode 4 */ 107,  54,  32,  26,  51,   1,  81,  43,  31},
        
       { /* left mode 5 */  39,  28,  85, 171,  58, 165,  90,  98,  64},
       { /* left mode 6 */  34,  22, 116, 206,  23,  34,  43, 166,  73},
       { /* left mode 7 */  68,  25, 106,  22,  64, 171,  36, 225, 114},
       { /* left mode 8 */  34,  19,  21, 102, 132, 188,  16,  76, 124},
       { /* left mode 9 */  62,  18,  78,  95,  85,  57,  50,  48,  51}
     },
     { /* above mode 3 */
       { /* left mode 0 */ 193, 101,  35, 159, 215, 111,  89,  46, 111},
       { /* left mode 1 */  60, 148,  31, 172, 219, 228,  21,  18, 111},
       { /* left mode 2 */ 112, 113,  77,  85, 179, 255,  38, 120, 114},
       { /* left mode 3 */  40,  42,   1, 196, 245, 209,  10,  25, 109},
       { /* left mode 4 */ 100,  80,   8,  43, 154,   1,  51,  26,  71},
       { /* left mode 5 */  88,  43,  29, 140, 166, 213,  37,  43, 154},
       { /* left mode 6 */  61,  63,  30, 155,  67,  45,  68,   1, 209},
       { /* left mode 7 */ 142,  78,  78,  16, 255, 128,  34, 197, 171},
       { /* left mode 8 */  41,  40,   5, 102, 211, 183,   4,   1, 221},
       { /* left mode 9 */  51,  50,  17, 168, 209, 192,  23,  25,  82}
     },
     { /* above mode 4 */
       { /* left mode 0 */ 125,  98,  42,  88, 104,  85, 117, 175,  82},
       { /* left mode 1 */  95,  84,  53,  89, 128, 100, 113, 101,  45},
       { /* left mode 2 */  75,  79, 123,  47,  51, 128,  81, 171,   1},
       { /* left mode 3 */  57,  17,   5,  71, 102,  57,  53,  41,  49},
       { /* left mode 4 */ 115,  21,   2,  10, 102, 255, 166,  23,   6},
       { /* left mode 5 */  38,  33,  13, 121,  57,  73,  26,   1,  85},
       { /* left mode 6 */  41,  10,  67, 138,  77, 110,  90,  47, 114},
       { /* left mode 7 */ 101,  29,  16,  10,  85, 128, 101, 196,  26},
       { /* left mode 8 */  57,  18,  10, 102, 102, 213,  34,  20,  43},
       { /* left mode 9 */ 117,  20,  15,  36, 163, 128,  68,   1,  26}
     },
     { /* above mode 5 */
       { /* left mode 0 */ 138,  31,  36, 171,  27, 166,  38,  44, 229},
       { /* left mode 1 */  67,  87,  58, 169,  82, 115,  26,  59, 179},
       { /* left mode 2 */  63,  59,  90, 180,  59, 166,  93,  73, 154},
       { /* left mode 3 */  40,  40,  21, 116, 143, 209,  34,  39, 175},
       { /* left mode 4 */  57,  46,  22,  24, 128,   1,  54,  17,  37},
       { /* left mode 5 */  47,  15,  16, 183,  34, 223,  49,  45, 183},
       { /* left mode 6 */  46,  17,  33, 183,   6,  98,  15,  32, 183},
       { /* left mode 7 */  65,  32,  73, 115,  28, 128,  23, 128, 205},
       { /* left mode 8 */  40,   3,   9, 115,  51, 192,  18,   6, 223},
       { /* left mode 9 */  87,  37,   9, 115,  59,  77,  64,  21,  47}
     },
     { /* above mode 6 */
       { /* left mode 0 */ 104,  55,  44, 218,   9,  54,  53, 130, 226},
       { /* left mode 1 */  64,  90,  70, 205,  40,  41,  23,  26,  57},
       { /* left mode 2 */  54,  57, 112, 184,   5,  41,  38, 166, 213},
       { /* left mode 3 */  30,  34,  26, 133, 152, 116,  10,  32, 134},
       { /* left mode 4 */  75,  32,  12,  51, 192, 255, 160,  43,  51},
        
       { /* left mode 5 */  39,  28,  85, 171,  58, 165,  90,  98,  64},
       { /* left mode 6 */  34,  22, 116, 206,  23,  34,  43, 166,  73},
       { /* left mode 7 */  68,  25, 106,  22,  64, 171,  36, 225, 114},
       { /* left mode 8 */  34,  19,  21, 102, 132, 188,  16,  76, 124},
       { /* left mode 9 */  62,  18,  78,  95,  85,  57,  50,  48,  51}
     },
     { /* above mode 3 */
       { /* left mode 0 */ 193, 101,  35, 159, 215, 111,  89,  46, 111},
       { /* left mode 1 */  60, 148,  31, 172, 219, 228,  21,  18, 111},
       { /* left mode 2 */ 112, 113,  77,  85, 179, 255,  38, 120, 114},
       { /* left mode 3 */  40,  42,   1, 196, 245, 209,  10,  25, 109},
       { /* left mode 4 */ 100,  80,   8,  43, 154,   1,  51,  26,  71},
       { /* left mode 5 */  88,  43,  29, 140, 166, 213,  37,  43, 154},
       { /* left mode 6 */  61,  63,  30, 155,  67,  45,  68,   1, 209},
       { /* left mode 7 */ 142,  78,  78,  16, 255, 128,  34, 197, 171},
       { /* left mode 8 */  41,  40,   5, 102, 211, 183,   4,   1, 221},
       { /* left mode 9 */  51,  50,  17, 168, 209, 192,  23,  25,  82}
     },
     { /* above mode 4 */
       { /* left mode 0 */ 125,  98,  42,  88, 104,  85, 117, 175,  82},
       { /* left mode 1 */  95,  84,  53,  89, 128, 100, 113, 101,  45},
       { /* left mode 2 */  75,  79, 123,  47,  51, 128,  81, 171,   1},
       { /* left mode 3 */  57,  17,   5,  71, 102,  57,  53,  41,  49},
       { /* left mode 4 */ 115,  21,   2,  10, 102, 255, 166,  23,   6},
       { /* left mode 5 */  38,  33,  13, 121,  57,  73,  26,   1,  85},
       { /* left mode 6 */  41,  10,  67, 138,  77, 110,  90,  47, 114},
       { /* left mode 7 */ 101,  29,  16,  10,  85, 128, 101, 196,  26},
       { /* left mode 8 */  57,  18,  10, 102, 102, 213,  34,  20,  43},
       { /* left mode 9 */ 117,  20,  15,  36, 163, 128,  68,   1,  26}
     },
     { /* above mode 5 */
       { /* left mode 0 */ 138,  31,  36, 171,  27, 166,  38,  44, 229},
       { /* left mode 1 */  67,  87,  58, 169,  82, 115,  26,  59, 179},
       { /* left mode 2 */  63,  59,  90, 180,  59, 166,  93,  73, 154},
       { /* left mode 3 */  40,  40,  21, 116, 143, 209,  34,  39, 175},
       { /* left mode 4 */  57,  46,  22,  24, 128,   1,  54,  17,  37},
       { /* left mode 5 */  47,  15,  16, 183,  34, 223,  49,  45, 183},
       { /* left mode 6 */  46,  17,  33, 183,   6,  98,  15,  32, 183},
       { /* left mode 7 */  65,  32,  73, 115,  28, 128,  23, 128, 205},
       { /* left mode 8 */  40,   3,   9, 115,  51, 192,  18,   6, 223},
       { /* left mode 9 */  87,  37,   9, 115,  59,  77,  64,  21,  47}
     },
     { /* above mode 6 */
       { /* left mode 0 */ 104,  55,  44, 218,   9,  54,  53, 130, 226},
       { /* left mode 1 */  64,  90,  70, 205,  40,  41,  23,  26,  57},
       { /* left mode 2 */  54,  57, 112, 184,   5,  41,  38, 166, 213},
       { /* left mode 3 */  30,  34,  26, 133, 152, 116,  10,  32, 134},
       { /* left mode 4 */  75,  32,  12,  51, 192, 255, 160,  43,  51},
        
       { /* left mode 5 */  39,  19,  53, 221,  26, 114,  32,  73, 255},
       { /* left mode 6 */  31,   9,  65, 234,   2,  15,   1, 118,  73},
       { /* left mode 7 */  88,  31,  35,  67, 102,  85,  55, 186,  85},
       { /* left mode 8 */  56,  21,  23, 111,  59, 205,  45,  37, 192},
       { /* left mode 9 */  55,  38,  70, 124,  73, 102,   1,  34,  98}
     },
     { /* above mode 7 */
       { /* left mode 0 */ 102,  61,  71,  37,  34,  53,  31, 243, 192},
       { /* left mode 1 */  69,  60,  71,  38,  73, 119,  28, 222,  37},
       { /* left mode 2 */  68,  45, 128,  34,   1,  47,  11, 245, 171},
       { /* left mode 3 */  62,  17,  19,  70, 146,  85,  55,  62,  70},
       { /* left mode 4 */  75,  15,   9,   9,  64, 255, 184, 119,  16},
       { /* left mode 5 */  37,  43,  37, 154, 100, 163,  85, 160,   1},
       { /* left mode 6 */  63,   9,  92, 136,  28,  64,  32, 201,  85},
       { /* left mode 7 */  86,   6,  28,   5,  64, 255,  25, 248,   1},
       { /* left mode 8 */  56,   8,  17, 132, 137, 255,  55, 116, 128},
       { /* left mode 9 */  58,  15,  20,  82, 135,  57,  26, 121,  40}
     },
     { /* above mode 8 */
       { /* left mode 0 */ 164,  50,  31, 137, 154, 133,  25,  35, 218},
       { /* left mode 1 */  51, 103,  44, 131, 131, 123,  31,   6, 158},
       { /* left mode 2 */  86,  40,  64, 135, 148, 224,  45, 183, 128},
       { /* left mode 3 */  22,  26,  17, 131, 240, 154,  14,   1, 209},
       { /* left mode 4 */  83,  12,  13,  54, 192, 255,  68,  47,  28},
       { /* left mode 5 */  45,  16,  21,  91,  64, 222,   7,   1, 197},
       { /* left mode 6 */  56,  21,  39, 155,  60, 138,  23, 102, 213},
       { /* left mode 7 */  85,  26,  85,  85, 128, 128,  32, 146, 171},
       { /* left mode 8 */  18,  11,   7,  63, 144, 171,   4,   4, 246},
       { /* left mode 9 */  35,  27,  10, 146, 174, 171,  12,  26, 128}
     },
     { /* above mode 9 */
       { /* left mode 0 */ 190,  80,  35,  99, 180,  80, 126,  54,  45},
       { /* left mode 1 */  85, 126,  47,  87, 176,  51,  41,  20,  32},
       { /* left mode 2 */ 101,  75, 128, 139, 118, 146, 116, 128,  85},
       { /* left mode 3 */  56,  41,  15, 176, 236,  85,  37,   9,  62},
       { /* left mode 4 */ 146,  36,  19,  30, 171, 255,  97,  27,  20},
       { /* left mode 5 */  71,  30,  17, 119, 118, 255,  17,  18, 138},
       { /* left mode 6 */ 101,  38,  60, 138,  55,  70,  43,  26, 142},
       { /* left mode 7 */ 138,  45,  61,  62, 219,   1,  81, 188,  64},
       { /* left mode 8 */  32,  41,  20, 117, 151, 142,  20,  21, 163},
       { /* left mode 9 */ 112,  19,  12,  61, 195, 128,  48,   4,  24}
     }
   };
        
       { /* left mode 5 */  39,  19,  53, 221,  26, 114,  32,  73, 255},
       { /* left mode 6 */  31,   9,  65, 234,   2,  15,   1, 118,  73},
       { /* left mode 7 */  88,  31,  35,  67, 102,  85,  55, 186,  85},
       { /* left mode 8 */  56,  21,  23, 111,  59, 205,  45,  37, 192},
       { /* left mode 9 */  55,  38,  70, 124,  73, 102,   1,  34,  98}
     },
     { /* above mode 7 */
       { /* left mode 0 */ 102,  61,  71,  37,  34,  53,  31, 243, 192},
       { /* left mode 1 */  69,  60,  71,  38,  73, 119,  28, 222,  37},
       { /* left mode 2 */  68,  45, 128,  34,   1,  47,  11, 245, 171},
       { /* left mode 3 */  62,  17,  19,  70, 146,  85,  55,  62,  70},
       { /* left mode 4 */  75,  15,   9,   9,  64, 255, 184, 119,  16},
       { /* left mode 5 */  37,  43,  37, 154, 100, 163,  85, 160,   1},
       { /* left mode 6 */  63,   9,  92, 136,  28,  64,  32, 201,  85},
       { /* left mode 7 */  86,   6,  28,   5,  64, 255,  25, 248,   1},
       { /* left mode 8 */  56,   8,  17, 132, 137, 255,  55, 116, 128},
       { /* left mode 9 */  58,  15,  20,  82, 135,  57,  26, 121,  40}
     },
     { /* above mode 8 */
       { /* left mode 0 */ 164,  50,  31, 137, 154, 133,  25,  35, 218},
       { /* left mode 1 */  51, 103,  44, 131, 131, 123,  31,   6, 158},
       { /* left mode 2 */  86,  40,  64, 135, 148, 224,  45, 183, 128},
       { /* left mode 3 */  22,  26,  17, 131, 240, 154,  14,   1, 209},
       { /* left mode 4 */  83,  12,  13,  54, 192, 255,  68,  47,  28},
       { /* left mode 5 */  45,  16,  21,  91,  64, 222,   7,   1, 197},
       { /* left mode 6 */  56,  21,  39, 155,  60, 138,  23, 102, 213},
       { /* left mode 7 */  85,  26,  85,  85, 128, 128,  32, 146, 171},
       { /* left mode 8 */  18,  11,   7,  63, 144, 171,   4,   4, 246},
       { /* left mode 9 */  35,  27,  10, 146, 174, 171,  12,  26, 128}
     },
     { /* above mode 9 */
       { /* left mode 0 */ 190,  80,  35,  99, 180,  80, 126,  54,  45},
       { /* left mode 1 */  85, 126,  47,  87, 176,  51,  41,  20,  32},
       { /* left mode 2 */ 101,  75, 128, 139, 118, 146, 116, 128,  85},
       { /* left mode 3 */  56,  41,  15, 176, 236,  85,  37,   9,  62},
       { /* left mode 4 */ 146,  36,  19,  30, 171, 255,  97,  27,  20},
       { /* left mode 5 */  71,  30,  17, 119, 118, 255,  17,  18, 138},
       { /* left mode 6 */ 101,  38,  60, 138,  55,  70,  43,  26, 142},
       { /* left mode 7 */ 138,  45,  61,  62, 219,   1,  81, 188,  64},
       { /* left mode 8 */  32,  41,  20, 117, 151, 142,  20,  21, 163},
       { /* left mode 9 */ 112,  19,  12,  61, 195, 128,  48,   4,  24}
     }
   };
        
   static const int kf_y_mode_tree[] =
   {
     -B_PRED, 2,
     4, 6,
     -DC_PRED, -V_PRED,
     -H_PRED, -TM_PRED
   };
   static const int y_mode_tree[] =
   {
     -DC_PRED, 2,
     4, 6,
     -V_PRED, -H_PRED,
     -TM_PRED, -B_PRED
   };
   static const int uv_mode_tree[6] =
   {
     -DC_PRED, 2,
     -V_PRED, 4,
     -H_PRED, -TM_PRED
   };
   static const int b_mode_tree[18] =
   {
     -B_DC_PRED, 2,               /* 0 = DC_NODE */
     -B_TM_PRED, 4,               /* 1 = TM_NODE */
     -B_VE_PRED, 6,               /* 2 = VE_NODE */
     8, 12,                       /* 3 = COM_NODE */
     -B_HE_PRED, 10,              /* 4 = HE_NODE */
     -B_RD_PRED, -B_VR_PRED,      /* 5 = RD_NODE */
     -B_LD_PRED, 14,              /* 6 = LD_NODE */
     -B_VL_PRED, 16,              /* 7 = VL_NODE */
     -B_HD_PRED, -B_HU_PRED       /* 8 = HD_NODE */
   };
   static const int small_mv_tree[14] =
   {
     2, 8,
     4, 6,
     -0, -1,
     -2, -3,
     10, 12,
     -4, -5,
     -6, -7
   };
        
   static const int kf_y_mode_tree[] =
   {
     -B_PRED, 2,
     4, 6,
     -DC_PRED, -V_PRED,
     -H_PRED, -TM_PRED
   };
   static const int y_mode_tree[] =
   {
     -DC_PRED, 2,
     4, 6,
     -V_PRED, -H_PRED,
     -TM_PRED, -B_PRED
   };
   static const int uv_mode_tree[6] =
   {
     -DC_PRED, 2,
     -V_PRED, 4,
     -H_PRED, -TM_PRED
   };
   static const int b_mode_tree[18] =
   {
     -B_DC_PRED, 2,               /* 0 = DC_NODE */
     -B_TM_PRED, 4,               /* 1 = TM_NODE */
     -B_VE_PRED, 6,               /* 2 = VE_NODE */
     8, 12,                       /* 3 = COM_NODE */
     -B_HE_PRED, 10,              /* 4 = HE_NODE */
     -B_RD_PRED, -B_VR_PRED,      /* 5 = RD_NODE */
     -B_LD_PRED, 14,              /* 6 = LD_NODE */
     -B_VL_PRED, 16,              /* 7 = VL_NODE */
     -B_HD_PRED, -B_HU_PRED       /* 8 = HD_NODE */
   };
   static const int small_mv_tree[14] =
   {
     2, 8,
     4, 6,
     -0, -1,
     -2, -3,
     10, 12,
     -4, -5,
     -6, -7
   };
        
   static const int mv_ref_tree[8] =
   {
     -ZEROMV, 2,
     -NEARESTMV, 4,
     -NEARMV, 6,
     -NEWMV, -SPLITMV
   };
   static const int submv_ref_tree[6] =
   {
     -LEFT4X4, 2,
     -ABOVE4X4, 4,
     -ZERO4X4, -NEW4X4
   };
   static const int split_mv_tree[6] =
   {
     -3, 2,
     -2, 4,
     -0, -1
   };
   static const unsigned char default_b_mode_probs[] =
   { 120,  90,  79, 133,  87,  85,  80, 111, 151};
   static const unsigned char mv_counts_to_probs[6][4] =
   {
     {   7,   1,   1, 143 },
     {  14,  18,  14, 107 },
     { 135,  64,  57,  68 },
     {  60,  56, 128,  65 },
     { 159, 134, 128,  34 },
     { 234, 188, 128,  28 }
        
   static const int mv_ref_tree[8] =
   {
     -ZEROMV, 2,
     -NEARESTMV, 4,
     -NEARMV, 6,
     -NEWMV, -SPLITMV
   };
   static const int submv_ref_tree[6] =
   {
     -LEFT4X4, 2,
     -ABOVE4X4, 4,
     -ZERO4X4, -NEW4X4
   };
   static const int split_mv_tree[6] =
   {
     -3, 2,
     -2, 4,
     -0, -1
   };
   static const unsigned char default_b_mode_probs[] =
   { 120,  90,  79, 133,  87,  85,  80, 111, 151};
   s