1 /********************************************************************
3 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2003 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
16 ********************************************************************/
18 #include "codec_internal.h"
20 static void CreateMapping ( ogg_int32_t (*BlockMap
)[4][4],
22 ogg_uint32_t FirstFrag
, ogg_uint32_t HFrags
,
23 ogg_uint32_t VFrags
){
24 ogg_uint32_t i
, j
= 0;
27 ogg_uint32_t SBrow
, SBcol
;
28 ogg_uint32_t SBRows
, SBCols
;
31 ogg_uint32_t SB
=FirstSB
;
32 ogg_uint32_t FragIndex
=FirstFrag
;
34 /* Set Super-Block dimensions */
35 SBRows
= VFrags
/4 + ( VFrags
%4 ? 1 : 0 );
36 SBCols
= HFrags
/4 + ( HFrags
%4 ? 1 : 0 );
38 /* Map each Super-Block */
39 for ( SBrow
=0; SBrow
<SBRows
; SBrow
++ ){
40 for ( SBcol
=0; SBcol
<SBCols
; SBcol
++ ){
41 /* Y co-ordinate of Super-Block in Block units */
44 /* Map Blocks within this Super-Block */
45 for ( i
=0; (i
<4) && (ypos
<VFrags
); i
++, ypos
++ ){
46 /* X co-ordinate of Super-Block in Block units */
49 for ( j
=0; (j
<4) && (xpos
<HFrags
); j
++, xpos
++ ){
62 /* Set mapping and move to next fragment */
63 BlockMap
[SB
][MB
][B
] = FragIndex
++;
66 /* Move to first fragment in next row in Super-Block */
67 FragIndex
+= HFrags
-j
;
70 /* Move on to next Super-Block */
72 FragIndex
-= i
*HFrags
-j
;
75 /* Move to first Super-Block in next row */
76 FragIndex
+= 3*HFrags
;
80 void CreateBlockMapping ( ogg_int32_t (*BlockMap
)[4][4],
81 ogg_uint32_t YSuperBlocks
,
82 ogg_uint32_t UVSuperBlocks
,
83 ogg_uint32_t HFrags
, ogg_uint32_t VFrags
) {
86 for ( i
=0; i
<YSuperBlocks
+ UVSuperBlocks
* 2; i
++ ){
87 for ( j
=0; j
<4; j
++ ) {
88 BlockMap
[i
][j
][0] = -1;
89 BlockMap
[i
][j
][1] = -1;
90 BlockMap
[i
][j
][2] = -1;
91 BlockMap
[i
][j
][3] = -1;
95 CreateMapping ( BlockMap
, 0, 0, HFrags
, VFrags
);
96 CreateMapping ( BlockMap
, YSuperBlocks
, HFrags
*VFrags
, HFrags
/2, VFrags
/2 );
97 CreateMapping ( BlockMap
, YSuperBlocks
+ UVSuperBlocks
, (HFrags
*VFrags
*5)/4,