Make clear that this isn't the official version
[dirac-spec-errata.git] / motion-dec.tex
bloba79cd3781c8d250f970cf9f784f0611edf530149
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % - This chapter defines how motion data - %
3 % - is decoded - %
4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 \label{motiondec}
8 This section defines the operation of the $block\_motion\_data()$ process for extracting
9 block motion data from the Dirac stream.
11 Block motion data is aggregated into {\em superblocks}, consisting of a 4x4 array of
12 blocks. The number of superblocks horizontally and vertically shall be determined so
13 that there are sufficient superblocks to cover the picture area. Superblocks
14 may overlap the right and bottom edge of the picture.
16 \begin{informative}
18 \begin{enumerate}
19 \item Since superblocks may overlap the right and bottom edge of the picture, blocks in
20 such superblocks may also overlap the edges or even fall outside the picture area
21 altogether. Motion data for blocks which fall outside the picture area is still decoded, but
22 will not be used for motion compensation (Section \ref{motioncompensate}).
24 \item Unlike macroblocks in MPEG standards, a superblock does not encapsulate all
25 data within a given area of the picture. It is merely an aggregation device for motion data,
26 and for this reason a different nomenclature has been adopted.
27 \end{enumerate}
28 \end{informative}
30 \subsection{Prediction modes and splitting modes}
32 \subsubsection{Prediction modes}
34 Two types of prediction mode shall be defined: a reference prediction mode, indicating
35 which references are to be used for motion compensation, and a global motion
36 mode flag, indicating how prediction is to be performed (using global motion or block
37 motion for a given block).
39 Four reference prediction modes shall be defined and shall be denoted by integer
40 constant values:
41 \begin{enumerate}
42 \item \Intra~shall denote value 0, and shall indicate that DC values for a block
43 shall be decoded and that no motion vectors shall be decoded.
44 \item \RefOneOnly~shall denote value 1 and shall indicate that a motion vector
45 for the first reference picture shall be decoded, but no motion vector for the second
46 reference picture shall be decoded.
47 \item \RefTwoOnly~shall denote value 2 and shall indicate that a motion vector
48 for the second reference picture shall be decoded, but no motion vector for the first
49 reference picture shall be decoded.
50 \item \RefOneAndTwo~shall denote value 3 and shall indicate that motion vectors
51 for both the first and second reference picture shall be decoded.
52 \end{enumerate}
54 In addition, where global motion is used for a picture (i.e.\ $\PictureUsingGlobal$ is set),
55 a global motion mode flag shall be encoded for each block. If $\true$, global motion
56 compensation shall be used for this block, and no block motion vectors or DC values
57 shall be encoded. If $\false$, block motion compensation shall be employed and
58 one or more motion vectors shall be encoded.
60 \subsubsection{Splitting modes}
62 Block motion data shall be aggregated into superblocks, consisting of a 4x4 array
63 of blocks, for each block motion data element.
65 Three superblock splitting levels shall be defined, numbered 0, 1, and 2.
67 When level 0 splitting is used, if a block motion data element is
68 present for that superblock, only one value shall be coded. This value shall be
69 applied to all blocks within the superblock.
71 When level 1 splitting is used, at most 4 values shall be coded for each
72 block motion data element. Where present, each of these values
73 shall be applied to the blocks in within the corresponding 2x2 sub-array of blocks
74 within the superblock.
76 When level 2 splitting is used, if a block motion data element is
77 present for that superblock, only four values shall be coded. Each of these values
78 shall be applied to all the four blocks in one of the four 2x2 sub-arrays of blocks
79 within the superblock.
81 \subsection{Structure of block motion data arrays}
83 \label{motionconventions}
85 For the purposes of this specification, block motion data shall be stored in the
86 two dimensional array $\BlockData$. Superblock
87 splitting modes shall be stored in the two dimensional array $\SBSplit$.
89 For each block with coordinates $(i,j)$, a block motion data element
90 $\BlockData[j][i]$ shall be defined. It is a map (Section \ref{datatypes}) and shall
91 consist of up to five elements:
93 \begin{enumerate}
94 \item A motion vector for reference 1, $\BlockData[j][i][\Vect][1]$, consisting of
95 integral horizontal and vertical elements $\BlockData[j][i][\Vect][1][0]$ and
96 $\BlockData[j][i][\Vect][1][1]$.
97 \item A motion vector for reference 2, $\BlockData[j][i][\Vect][2]$, consisting of
98 integral horizontal and vertical elements $\BlockData[j][i][\Vect][2][0]$ and
99 $\BlockData[j][i][\Vect][2][1]$.
100 \item A set of integral DC values for each component, $\BlockData[j][i][\DC][Y]$,
101 $\BlockData[j][i][\DC][C1]$, and $\BlockData[j][i][\DC][C2]$.
102 \item A reference prediction mode, $\BlockData[j][i][\RMode]$, taking values \Intra,
103 \RefOneOnly, \RefTwoOnly, or \RefOneAndTwo~and indicating which references
104 (if any) are to be used for predicting block $(i,j)$.
105 \item A global motion mode flag, $\BlockData[j][i][\GMode]$.
106 \end{enumerate}
108 \subsubsection{Block motion data initialisation}
110 \label{motioninit}
112 This section specifies the operation of the $initialise\_motion\_data()$ process.
113 It shall set the dimensions of the block motion parameter arrays according to the numbers
114 of blocks and superblocks defined in Section {motiondatadimensions}.
116 The array $\BlockData$ shall be set to have horizontal dimension $\BlocksX$ and
117 vertical dimension $\BlocksY$.
119 The array $\SBSplit$ shall be set to have horizontal dimension $\SuperblocksX$
120 and vertical dimension $\SuperblocksY$.
122 \subsection{Motion data decoding process}
123 \label{decodingprocess}
125 This section defines the $block\_motion\_data()$ process for extracting
126 block motion data elements.
128 This process depends upon the picture prediction parameters (Section
129 \ref{picpredparams}).
131 Block motion data elements shall be coded differentially with respect to a spatial
132 prediction. The spatial prediction processes for the block motion elements are
133 defined in Section \ref{spatialprediction}
135 The decoding process for the block motion data shall consist of:
136 \begin{enumerate}
137 \item decoding the superblock split modes,
138 \item decoding the prediction modes in each superblock according to the split mode, and
139 \item decoding the motion vectors and DC values according to the split mode and the
140 decoded mode for each block.
141 \end{enumerate}
143 The motion vector elements are further decomposed into horizontal and vertical
144 components which are encoded as separate parts. The DC values are further
145 decomposed into the the components which are encoded as separate parts.
147 The coded data for each part (splitting mode, prediction mode, vector component,
148 or DC component values) shall consist of an entropy coded block
149 preceded by a length code.
151 \begin{pseudo}{block\_motion\_data}{}
152 \bsCODE{initialise\_motion\_data()}{\ref{motioninit}}
153 \bsCODE{superblock\_split\_modes()}{\ref{superblocksplit}}
154 \bsCODE{prediction\_modes()}{\ref{blockpredmodes}}
155 \bsCODE{vector\_elements(1, 0)}{\ref{blockmvelements}}
156 \bsCODE{vector\_elements(1, 1)}{\ref{blockmvelements}}
157 \bsIF{num\_refs()==2}
158 \bsCODE{vector\_elements(2,0)}{\ref{blockmvelements}}
159 \bsCODE{vector\_elements(2,1)}{\ref{blockmvelements}}
160 \bsEND
161 \bsCODE{dc\_values(Y)}{\ref{DCvalues}}
162 \bsCODE{dc\_values(C1)}{\ref{DCvalues}}
163 \bsCODE{dc\_values(C2)}{\ref{DCvalues}}
164 \end{pseudo}
166 \begin{informative}
167 The superblock splitting modes determine the number, and location, of
168 prediction mode values to be decoded -- there
169 must be one for each `prediction unit' (block, 2x2 array or blocks, or 4x4 array or
170 blocks) within a superblock. Together, the split
171 mode and the prediction mode determine the number and location of all other
172 motion data parts, which can each then be decoded in parallel. Indeed,
173 by attempting to decode the maximum possible number of prediction residue
174 values for all motion data elements, the first
175 two motion data elements may also be decoded in parallel with the others.
176 Once all residue values are decoded, excess
177 values can be discarded, the location of values determined and actual
178 values reconstructed by prediction. This approach
179 may be particularly valuable in hardware. Decoding may proceed in this way,
180 as the arithmetic decoding engine allows bits to be read beyond the nominal end of an
181 arithmetically-coded chunk by inserting 1s, hence allowing virtual values to be read.
182 \end{informative}
184 \subsubsection{Superblock splitting modes}
185 \label{superblocksplit}
187 This section defines the decoding of the superblock splitting mode values.
189 The superblock splitting mode shall determine the number of prediction modes
190 coded for each superblock.
192 $superblock\_split\_modes()$ process shall be defined as follows:
194 \begin{pseudo}{superblock\_split\_modes}{}
195 \bsITEM{length}{uint}{}
196 \bsCODE{\ABitsLeft= 8*length}
197 \bsCODE{byte\_align()}
198 \bsCODE{ctx\_labels=[\SBSplitFollowOne,\SBSplitFollowTwo,\SBSplitData]}
199 \bsCODE{initialise\_arithmetic\_decoding(ctx\_labels)}{\ref{initarith}}
200 \bsFOR{ysb=0}{\SuperblocksY-1}
201 \bsFOR{xsb=0}{\SuperblocksX-1}
202 \bsCODE{sb\_split\_residual=read\_uinta(sb\_split\_contexts() ) }{\ref{sbcontexts}}
203 \bsCODE{\SBSplit[ysb][xsb] = sb\_split\_residual}
204 \bsCODE{\SBSplit[ysb][xsb]+=split\_prediction(xsb, ysb)}{\ref{splitprediction}}
205 \bsCODE{\SBSplit[ysb][xsb] \%= 3}
206 \bsEND
207 \bsEND
208 \bsCODE{flush\_inputb()}{\ref{blockreadbit}}
209 \end{pseudo}
211 \subsubsection{Propagating data between blocks}
212 \label{propagatedata}
214 The superblock splitting mode determines the maximum number of values to be
215 decoded for each block motion data element: 0, 4, or 16. If the splitting mode
216 is 0 or 1 and a value is decoded it applies to all 16 blocks or to one of the 4 2x2
217 sub-arrays of blocks within the superblock. So that prediction of values shall
218 operate correctly, once decoded a value shall be propagated to all blocks to
219 which it applies.
221 The $propagate\_data(xtl, ytl, k,idx)$ shall copy decoded block data from the
222 top-left-most block $(xtl, ytl)$ of an array of $k\times k$ blocks, where $k$ shall be 4 if the
223 splitting mode is 0 and $k$ shall be 2 if the splitting mode is 1. It shall be defined
224 as follows:
226 \begin{pseudo}{propagate\_data}{xtl, ytl, k,label}
227 \bsFOR{y=ytl}{ytl+k-1}
228 \bsFOR{x=xtl}{xtl+k-1}
229 \bsCODE{\BlockData[y][x][label]=\BlockData[ytl][xtl][label]}
230 \bsEND
231 \bsEND
232 \end{pseudo}
234 \subsubsection{Block prediction modes}
235 \label{blockpredmodes}
237 The prediction mode process shall decode global motion and reference
238 prediction modes required for each superblock according to the
239 the superblock splitting mode.: 16 values shall be decoded for split mode 2,
240 4 values shall be decoded for split mode 1, and 1 value for split mode 0.
242 For split modes 0 and 1, decoded values shall placed in the top-left corner block
243 of the array (4x4 or 2x2) of blocks to which they apply, and then propagated to the
244 other blocks.
246 The $prediction\_modes()$ process shall be defined as follows:
248 \begin{pseudo}{prediction\_modes}{}
249 \bsITEM{length}{uint}{}
250 \bsCODE{\ABitsLeft= 8*length}
251 \bsCODE{byte\_align()}
252 \bsCODE{ctx\_labels=[\PredModeOne,\PredModeTwo,\BlockGlobal]}
253 \bsCODE{initialise\_arithmetic\_decoding(ctx\_labels)}{\ref{initarith}}
254 \bsFOR{ysb=0}{\SuperblocksY-1}
255 \bsFOR{xsb=0}{\SuperblocksX-1}
256 \bsCODE{block\_count = 2^{\SBSplit[ysb][xsb]}}
257 \bsCODE{step = 4//block\_count }
258 \bsFOR{q=0}{block\_count-1}
259 \bsFOR{p=0}{block\_count-1}
260 \bsCODE{block\_ref\_mode(4*xsb+p*step, 4*ysb+q*step)}{\ref{blockmode}}
261 \bsCODE{propagate\_data(4*xsb+p*step, 4*ysb+q*step, step,\RMode)}{\ref{propagatedata}}
262 \bsCODE{block\_global\_mode(4*xsb+p*step, 4*ysb+q*step)}{\ref{blockglobal}}
263 \bsCODE{propagate\_data(4*xsb+p*step, 4*ysb+q*step, step,\GMode)}{\ref{propagatedata}}
264 \bsEND
265 \bsEND
266 \bsEND
267 \bsEND
268 \bsCODE{flush\_inputb()}{\ref{blockreadbit}}
269 \end{pseudo}
271 \paragraph{Block prediction mode}
272 \label{blockmode}
274 The $block\_ref\_mode()$ process shall be defined as follows:
276 \begin{pseudo}{block\_ref\_mode}{x, y}
277 \bsCODE{\BlockData[y][x][\RMode] = 0}
278 \bsIF{read\_boola(\PredModeOne)==\true}
279 \bsCODE{\BlockData[y][x][\RMode] = 1}
280 \bsEND
281 \bsIF{num\_refs() == 2}
282 \bsIF{read\_boola(\PredModeTwo)==\true}
283 \bsCODE{\BlockData[y][x][\RMode] += 2}
284 \bsEND
285 \bsEND
286 \bsCODE{\BlockData[y][x][\RMode] \wedge=ref\_mode\_prediction(x, y)}{\ref{modeprediction}}
287 \end{pseudo}
289 \paragraph{Block global mode}
290 \label{blockglobal}
291 $\ $\newline
293 The $block\_global\_mode()$ process shall be defined as follows:
295 \begin{pseudo}{block\_global}{x, y}
296 \bsCODE{\BlockData[y][x][\GMode]=\false}
297 \bsIF{\PictureUsingGlobal==\true}
298 \bsIF{\BlockData[y][x][\RMode]!=\Intra}
299 \bsCODE{block\_global\_residue = read\_boola(\BlockGlobal)}
300 \bsCODE{\BlockData[y][x][\GMode] = block\_global\_residue}
301 \bsCODE{\BlockData[y][x][\GMode] \wedge= block\_global\_prediction(x, y)}{\ref{blockglobalprediction}}
302 \bsEND
303 \bsEND
304 \end{pseudo}
306 \subsubsection{Block motion vector elements}
307 \label{blockmvelements}
309 The vector element process shall decode the set of horizontal, or the set of vertical
310 motion vector elements associated with one of the reference pictures.
312 $vector\_elements()$ process shall be defined as follows:
314 \begin{pseudo}{vector\_elements}{ref,dirn}
315 \bsITEM{length}{uint}{}
316 \bsCODE{\ABitsLeft= 8*length}
317 \bsCODE{byte\_align()}
318 \bsCODE{ctx\_labels=\begin{array}{l}[\VectorFollowOne,\VectorFollowTwo,\VectorFollowThree,
319 \VectorFollowFour,\VectorFollowFivePlus,\\
320 \VectorData,\VectorSign]
321 \end{array}}
322 \bsCODE{initialise\_arithmetic\_decoding(ctx\_labels)}{\ref{initarith}}
323 \bsFOR{ysb=0}{\SuperblocksY-1}
324 \bsFOR{xsb=0}{\SuperblocksX-1}
325 \bsCODE{block\_count = 2^{\SBSplit[ysb][xsb]}}
326 \bsCODE{step = 4//block\_count }
327 \bsFOR{q=0}{block\_count-1}
328 \bsFOR{p=0}{block\_count-1}
329 \bsCODE{block\_vector(4*xsb+p*step, 4*ysb+q*step, ref, dirn)}
330 \bsCODE{propagate\_data(4*xsb+p*step, 4*ysb+q*step, step,\Vect)}{\ref{propagatedata}}
331 \bsEND
332 \bsEND
333 \bsEND
334 \bsEND
335 \bsCODE{flush\_inputb()}{\ref{blockreadbit}}
336 \end{pseudo}
338 The block vector proces shall decode an individual motion vector element.
339 It shall be defined as follows:
341 \begin{pseudo}{block\_vector}{x, y, ref, dirn}
342 \bsIF{\BlockData[y][x][\RMode][ref] == \true}
343 \bsIF{\BlockData[y][x][\GMode]==\false}
344 \bsCODE{mv\_residual = read\_sinta(mv\_contexts() ) }{\ref{mvcontexts}}
345 \bsCODE{\BlockData[y][x][\Vect][ref][dirn] = mv\_residual}
346 \bsCODE{\BlockData[y][x][\Vect][ref][dirn] +=mv\_prediction(x, y, ref, dirn)}
347 \bsEND
348 \bsEND
349 \end{pseudo}
351 \subsubsection{DC values}
352 \label{DCvalues}
354 The DV value process shall decode the DC values for a intra blocks for a given video component (Y, C1 or C2). It shall be defined as follows:
356 \begin{pseudo}{dc\_values}{c}
357 \bsITEM{length}{uint}{}
358 \bsCODE{\ABitsLeft= 8*length}
359 \bsCODE{byte\_align()}
360 \bsCODE{ctx\_labels=[\DCFollowOne,\DCFollowTwoPlus,\DCData,\DCSign]}
361 \bsCODE{initialise\_arithmetic\_decoding(ctx\_labels)}{\ref{initarith}}
362 \bsFOR{ysb=0}{\SuperblocksY-1}
363 \bsFOR{xsb=0}{\SuperblocksX-1}
364 \bsCODE{block\_count = 2^{\SBSplit[ysb][xsb]}}
365 \bsCODE{step = 4//block\_count }
366 \bsFOR{q=0}{block\_count-1}
367 \bsFOR{p=0}{block\_count-1}
368 \bsCODE{block\_dc(4*xsb+p*step, 4*ysb+q*step, c)}
369 \bsCODE{propagate\_data(4*xsb+p*step, 4*ysb+q*step, step,\DC)}{\ref{propagatedata}}
370 \bsEND
371 \bsEND
372 \bsEND
373 \bsEND
374 \bsCODE{flush\_inputb()}{\ref{blockreadbit}}
375 \end{pseudo}
377 The block DC process shall decode an individual component DC value. It shall
378 be defined as follows:
380 \begin{pseudo}{block\_dc}{x, y,c}
381 \bsIF{\BlockData[y][x][\RMode]=\Intra}
382 \bsCODE{dc\_residual = read\_sinta(dc\_contexts()) }{\ref{dcvaluecontexts}}
383 \bsCODE{\BlockData[y][x][\DC][c] = dc\_residual}
384 \bsCODE{\BlockData[y][x][\DC][c] +=dc\_prediction(x, y, c)}{\ref{dcprediction}}
385 \bsEND
386 \end{pseudo}
388 \subsubsection{Spatial prediction of motion data elements}
390 \label{spatialprediction}
392 \paragraph{Prediction apertures\\}
394 A consistent convention for prediction apertures is used. The nominal prediction
395 aperture for block motion data is defined to be the relevant data to the left, top
396 and top-left of the data element in question (Figure \ref{predaperture}).
397 For the superblock split mode of
398 the superblock with index $(i,j)$ this means the superblocks with indices $(i-1,j)$,
399 $(i,j-1)$ and $(i-1,j-1)$. For the block motion data itself, the same applies where these
400 indices are {\em block} indices.
402 \setlength{\unitlength}{1em}
403 \begin{figure}[!ht]
404 \centering
405 \begin{picture}(15,20)
406 \multiput(0,0)(8,0){3}%
407 {\line(0,1){16}}
408 \multiput(0,0)(0,8){3}%
409 {\line(1,0){16}}
411 %Shading
413 \multiput(0,0)0.2,0){40}%
414 {\multiput(8,0.1)(0,.2){40}%
415 {\tiny.}
418 %Arrows
419 \put(4,12){\vector(1,-1){6}}
420 \put(12,12){\vector(0,-1){6}}
421 \put(4,4){\vector(1,0){6}}
422 \end{picture}
423 \caption{Basic prediction aperture}\label{predaperture}
424 \end{figure}
426 This is the nominal prediction aperture. Not all data elements in this prediction
427 aperture may be available, either because they would require negative indices, or
428 because the data is not available - for example a block to the left of a block with
429 reference mode \RefTwoOnly may have reference mode \RefOneOnly and so
430 can furnish no contribution for a prediction to the
431 Reference 2 motion vector.
433 When superblocks have split level 1 or 0, block data shall be propagated
434 (Section \ref{propagatedata}) across 4 or 16 blocks so as to furnish a prediction. The
435 effect is illustrated in Figure \ref{splitapertures}.
437 \setlength{\unitlength}{.75em}
438 \begin{figure}[!ht]
439 \centering
440 \begin{picture}(60,17.5)
442 \multiput(0,0)(20,0){3}%
445 %Main Grid
446 \multiput(0,0)(8,0){3}%
447 {\line(0,1){16}}
448 \multiput(0,0)(0,8){3}%
449 {\line(1,0){16}}
450 \multiput(0,0)0.2,0){40}%
452 %Shading
453 \multiput(0,0)0.4,0){20}%
454 {\multiput(8,0.2)(0,.4){20}%
455 {\tiny.}
458 %Dotted Grid
459 \multiput(0,0)(0,2){3}%
460 {\multiput(0,2)(0.5,0){16}%
461 {\line(1,0){.25}}
463 \multiput(0,0)(2,0){3}%
464 {\multiput(2,0)(0,0.5){16}%
465 {\line(0,1){.25}}
468 \multiput(8,0)(0,8){2}%
469 {\multiput(0,4)(0.5,0){16}%
470 {\line(1,0){.25}}
473 \multiput(12,0)(0,0.5){32}%
474 {\line(0,1){.25}}
476 %Arrows
477 \put(4,12){\vector(1,-1){5}}
478 \put(7,7) {\vector(2,-1){1.5}}
479 \put(10,10){\vector(0,-1){3}}
481 \put(30,6){\vector(0,-1){3.5}}
482 \put(27,5) {\vector(1,-1){2}}
483 \put(27,3){\vector(2,-1){2}}
485 \put(50,2){\vector(1,0){3.5}}
486 \put(50,6) {\vector(1,-1){3.5}}
487 \put(54,6){\vector(0,-1){3.5}}
489 \end{picture}
490 \caption{Effect of splitting modes on spatial prediction}\label{splitapertures}
491 \end{figure}
493 \paragraph{Superblock split prediction}
494 \label{splitprediction}
495 $\ $\newline
496 $split\_prediction$ returns the mean of the the neighbouring split values:
498 \begin{pseudo}{split\_prediction}{x, y}
499 \bsIF{ x==0 \text{ \bf and } y==0 }
500 \bsRET{0}
501 \bsELSEIF{y==0}
502 \bsRET{\SBSplit[0][x-1]}
503 \bsELSEIF{x==0}
504 \bsRET{\SBSplit[y-1][0]}
505 \bsELSE
506 \bsCODE{
507 \begin{array}{ll}
508 \text{\bf return} & \mean(\SBSplit[y-1][x-1], \\
509 & \quad\quad\quad \SBSplit[y][x-1], \\
510 & \quad\quad\quad \SBSplit[y-1][x])
511 \end{array}
513 \bsEND
514 \end{pseudo}
516 \paragraph{Block mode prediction}
517 \label{modeprediction}
518 $\ $\newline
519 The $ref\_mode\_prediction()$ function shall return a value that represents a majority
520 verdict for the presence of each of the references individually. It shall be defined
521 as follows:
523 \begin{pseudo}{ref\_mode\_prediction}{x, y}
524 \bsIF{ x==0 \text{ \bf and } y==0 }
525 \bsRET{\Intra}
526 \bsELSEIF{y==0}
527 \bsRET{\BlockData[0][x-1][\RMode]}
528 \bsELSEIF{x==0}
529 \bsRET{\BlockData[y-1][0][\RMode]}
530 \bsELSE
531 \bsCODE{num\_ref1\_nbrs=\BlockData[y-1][x][\RMode] \& 1}
532 \bsCODE{num\_ref1\_nbrs +=\BlockData[y-1][x-1][\RMode] \& 1}
533 \bsCODE{num\_ref1\_nbrs +=\BlockData[y][x-1][\RMode] \& 1}
534 \bsCODE{pred=num\_ref1\_nbrs//2}
535 \bsCODE{num\_ref2\_nbrs=(\BlockData[y-1][x][\RMode]\gg 1) \& 1}
536 \bsCODE{num\_ref2\_nbrs +=(\BlockData[y-1][x-1][\RMode] \gg 1) \& 1}
537 \bsCODE{num\_ref2\_nbrs +=(\BlockData[y][x-1][\RMode] \gg 1) \& 1}
538 \bsCODE{pred \wedge= (num\_ref2\_nbrs//2)\ll 1}
539 \bsRET{pred}
540 \bsEND
541 \end{pseudo}
543 \paragraph{Block global flag prediction}
544 \label{blockglobalprediction}
545 $\ $\newline
546 The $block\_global\_prediction()$ function shall return a value that represents a majority
547 verdict of the neighbouring blocks. It shall be defined as follows:
549 \begin{pseudo}{block\_global\_prediction}{x, y}
550 \bsIF{ x==0 \text{ \bf and } y==0 }
551 \bsRET{\false}
552 \bsELSEIF{ y==0 }
553 \bsRET{\BlockData[0][x-1][\GMode]}
554 \bsELSEIF{x==0}
555 \bsRET{\BlockData[y-1][0][\GMode]}
556 \bsELSE
557 \bsCODE{
558 \begin{array}{ll}
559 \text{\bf return} & \majority(\BlockData[y-1][x-1][\GMode], \\
560 & \quad\quad\quad \BlockData[y-1][x][\GMode], \\
561 & \quad\quad\quad \BlockData[y][x-1][\GMode])
562 \end{array}
564 \bsEND
565 \end{pseudo}
567 \paragraph{Motion vector prediction}
568 \label{mvprediction}
569 $\ $\newline
570 Motion vectors shall be predicted using the median of available block vectors
571 in the aperture. A vector shall be available for prediction if:
572 \begin{enumerate}
573 \item its block falls within the picture area,
574 \item its prediction mode allows it to be defined, and
575 \item it is not a global motion block.
576 \end{enumerate}
578 The $mv\_prediction(x, y, ref, dirn)$ shall return motion values according to
579 the following rules:
581 {\bf Case 1.} If $x==0$ and $y==0$, the value $0$ shall be returned.
583 {\bf Case 2.} If $x>0$ and $y==0$ then:
584 \begin{enumerate}
585 \item If $\BlockData[0][x-1][\GMode]==\false$ and
586 $(\BlockData[0][x-1][\RMode] \& ref) != 0$ then vector element $\BlockData[0][x-1][\Vect][ref][dirn]$ shall be returned,
587 \item otherwise, $0$ shall be returned
588 \end{enumerate}
590 {\bf Case 3.} If $x==0$ and $y>0$ then:
591 \begin{enumerate}
592 \item If $\BlockData[y-1][0][\GMode]==\false$ and
593 $(\BlockData[y-1][0][\RMode] \& ref)!=0$ then vector element
594 $\BlockData[y-1][0][\Vect][ref][dirn]$ shall be returned,
595 \item otherwise, $0$ shall be returned
596 \end{enumerate}
598 {\bf Case 4.} If both $x>0$ and $y>0$ then all 3 blocks in the prediction aperture
599 may potentially contribute to the prediction. Define the set $values=\{\}$. The prediction
600 shall be the median of the available vector elements, as defined in the following
601 pseudocode:
603 \begin{pseudo*}
604 \bsIF{x>0 \text{ \bf and } y>0 }
605 \bsIF{\BlockData[y][x-1][\GMode]==\false}
606 \bsIF{(\BlockData[y][x-1][\RMode] \& ref) != 0}
607 \bsCODE{values = values\cup\{\BlockData[y][x-1][\Vect][ref][dirn] \} }
608 \bsEND
609 \bsEND
610 \bsIF{\BlockData[y-1][x][\GMode]==\false}
611 \bsIF{(\BlockData[y-1][x][\RMode] \& ref) != 0}
612 \bsCODE{values = values\cup\{\BlockData[y-1][x][\Vect][ref][dirn] \} }
613 \bsEND
614 \bsEND
615 \bsIF{\BlockData[y-1][x-1][\GMode]==\false}
616 \bsIF{(\BlockData[y-1][x-1][\RMode] \& ref) != 0}
617 \bsCODE{values = values\cup\{\BlockData[y-1][x-1][\Vect][ref][dirn] \} }
618 \bsEND
619 \bsEND
621 \bsRET{\median(values)}{\ref{integerops}}
622 \bsEND
623 \end{pseudo*}
625 (Note that the median of an empty set is zero.)
627 \paragraph{DC value prediction}
628 \label{dcprediction}
629 $\ $\newline
630 DC values shall be predicted using the unbiased mean of available values
631 in the prediction aperture.
633 The process $dc\_prediction(x, y, c)$ shall return values according to
634 the following rules:
636 {\bf Case 1.} If $x==0$ and $y==0$, $0$ shall be returned.
638 {\bf Case 2.} If $x>0$ and $y==0$ then:
639 \begin{enumerate}
640 \item If $\BlockData[0][x-1][\RMode]==\Intra$, $\BlockData[0][x-1][\DC][c]$
641 shall be returned,
642 \item otherwise, $0$ shall be returned.
643 \end{enumerate}
645 {\bf Case 3.} If $x==0$ and $y>0$ then:
646 \begin{enumerate}
647 \item If $\BlockData[y-1][0][\RMode]==\Intra$, $\BlockData[y-1][0][\DC][c]$
648 shall be returned,
649 \item otherwise, 0 shall be returned.
650 \end{enumerate}
652 {\bf Case 4.} If both $x>0$ and $y>0$ then all 3 blocks in the prediction aperture may
653 potentially contribute to the prediction. Define a set $values=\{\}$. The prediction shall
654 be the unbiased mean of available values, as defined in the following pseudocode:
656 \begin{pseudo*}
657 \bsIF{ x>0 \text{ \bf and } y>0 }
658 \bsIF{\BlockData[y][x-1][\RMode]==\Intra}
659 \bsCODE{values = values\cup\{\BlockData[y][x-1][\DC][c] \} }
660 \bsEND
661 \bsIF{\BlockData[y-1][x][\RMode]==\Intra}
662 \bsCODE{values = values\cup\{\BlockData[y-1][x][ref][\DC][c] \} }
663 \bsEND
664 \bsIF{\BlockData[y-1][x-1][\RMode]==\Intra}
665 \bsCODE{values = values\cup\{\BlockData[y-1][x-1][ref][\DC][c] \} }
666 \bsEND
667 \bsIF{values!=\{\}}
668 \bsRET{pred =\mean(values)}
669 \bsELSE
670 \bsRET{0}
671 \bsEND
672 \bsEND
673 \end{pseudo*}
675 \subsubsection{Block motion parameter contexts}
677 \paragraph{Superblock splitting mode}\label{sbcontexts}
678 $\ $\newline
679 The $sb\_split\_contexts()$ function shall return a context label map $c$ with the
680 following values:
682 \begin{itemize}
683 \item $c[FOLLOW] = [ \SBSplitFollowOne, \SBSplitFollowTwo ]$
684 \item $c[DATA] = \SBSplitData$
685 \end{itemize}
687 \paragraph{Motion vectors}
688 \label{mvcontexts}
689 $\ $\newline
690 The $mv\_contexts()$ function shall return a context label map $c$ with the
691 following values:
693 \begin{itemize}
694 \item $c[FOLLOW] = [ \VectorFollowOne, \VectorFollowTwo, \VectorFollowThree, \VectorFollowFour, \VectorFollowFivePlus ]$
695 \item $c[DATA] = \VectorData$
696 \item $c[SIGN] = \VectorSign$
697 \end{itemize}
699 \paragraph{DC values}
700 \label{dcvaluecontexts}
702 The $dc\_contexts()$ function shall return a context label map $c$ with the
703 following values:
705 \begin{itemize}
706 \item $c[FOLLOW] = [ \DCFollowOne, \DCFollowTwoPlus ]$
707 \item $c[DATA] = \DCData$
708 \item $c[SIGN] = \DCSign$
709 \end{itemize}