Add Russian translation provided by Валерий Крувялис <valkru@mail.ru>
[xiph-mirror.git] / theora-old / lib / blockmap.c
blobf776fad754840744f86fea1c4d6a85289ac3a03f
1 /********************************************************************
2 * *
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. *
7 * *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2003 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
10 * *
11 ********************************************************************
13 function:
14 last mod: $Id$
16 ********************************************************************/
18 #include "codec_internal.h"
20 static void CreateMapping ( ogg_int32_t (*BlockMap)[4][4],
21 ogg_uint32_t FirstSB,
22 ogg_uint32_t FirstFrag, ogg_uint32_t HFrags,
23 ogg_uint32_t VFrags ){
24 ogg_uint32_t i, j = 0;
25 ogg_uint32_t xpos;
26 ogg_uint32_t ypos;
27 ogg_uint32_t SBrow, SBcol;
28 ogg_uint32_t SBRows, SBCols;
29 ogg_uint32_t MB, B;
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 */
42 ypos = SBrow<<2;
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 */
47 xpos = SBcol<<2;
49 for ( j=0; (j<4) && (xpos<HFrags); j++, xpos++ ){
50 if ( i<2 ){
51 MB = ( j<2 ? 0 : 1 );
52 }else{
53 MB = ( j<2 ? 2 : 3 );
56 if ( i%2 ){
57 B = ( j%2 ? 3 : 2 );
58 }else{
59 B = ( j%2 ? 1 : 0 );
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 */
71 SB++;
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 ) {
84 ogg_uint32_t i, j;
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,
98 HFrags/2, VFrags/2 );