📄 fmo.c
字号:
int p = NumSliceGroups+1; // Number of Slice Groups
for (x=0; x<XSize*YSize; x++)
{
MBAmap[x] = ((x/XSize)&1)? // even or odd?
((x%n)+1+p/2)%p: // odd
((x%n)+1) % p; // even
}
/*
{
int i;
printf ("FMO MBAmap of type 1 as follows\n");
for (i=0; i<XSize*YSize;i++){
if (i%XSize==0) printf ("\n");
printf ("%d ", MBAmap[i]);}
printf ("\n");
}
*/
return 0;
}
/*
************************************************************************
* \brief
* FmoGenerateType2MBAmap: generates a type 2 MBAmap
*
* \par
* Type 2 MBAmaps are fully flexible. See JVT-C167
* \par Input:
* XSize, Ysize: Size of MBAmap (== picture) in macroblocks
* MBAMap: MBAmap to be filled
* \par Return
* always 0 (success)
************************************************************************
*/
int FmoGenerateType2MBAmap (int NumSliceGroups, int *MapData, int xs, int ys, int *MBAmap)
{
printf ("Type 2 MBAmap generation not yet implemented\n");
exit (-1);
/*
FILE *f;
if ((f = fopen (input->FmoConfigFileName, "r")) == NULL)
{
printf ("Cannot open FMO config file %d for reading, FMO type %d\n",
input->FmoConfigFileName, input->FmoType);
exit (-1);
}
*/
return 0;
}
// JVT-D095
int FmoGenerateType3MBAmap (int NumSliceGroups, int XSize, int YSize, int *MBAmap)
{
int x, y, xx;
int n = XSize; // Number of columns
// int p = NumSliceGroups+1; // Number of Slice Groups
int rx0, rx1, ry0, ry1; // coordinates of the rectangule
assert (NumSliceGroups == 1);
rx0 = input->top_left_mb%n;
ry0 = input->top_left_mb/n;
rx1 = input->bottom_right_mb%n;
ry1 = input->bottom_right_mb/n;
for (y=0; y<YSize; y++)
for (x=0; x<XSize; x++)
{
xx = y*XSize+x;
if(x >= rx0 && x <= rx1 && y >= ry0 && y<= ry1) // within the rectangular slice group
MBAmap[xx] = 0;
else
MBAmap[xx] = 1;
}
return 0;
}
// End JVT-D095
// JVT-D097
int FmoInitEvolvingMBAmap (int FmoMode, int XSize, int YSize, int *MBAmap)
{
int i;
assert (MBAmap != NULL);
for(i=0; i< XSize*YSize; i++)
MBAmap[i] = 1;
fmo_evlv_NewPeriod = 0;
slice_group_change_cycle = -1;
switch(FmoMode)
{
case 4:
if(input->slice_group_change_direction == 0)
{
fmo_evlv_x = XSize / 2;
fmo_evlv_y = YSize / 2;
fmo_evlv_directx = -1;
fmo_evlv_directy = 0;
}
else
{
fmo_evlv_x = ( XSize - 1 ) / 2;
fmo_evlv_y = ( YSize - 1) / 2;
fmo_evlv_directx = 0;
fmo_evlv_directy = 1;
}
fmo_evlv_left = fmo_evlv_x;
fmo_evlv_right = fmo_evlv_x;
fmo_evlv_top = fmo_evlv_y;
fmo_evlv_bottom = fmo_evlv_y;
break;
case 5:
if(input->slice_group_change_direction == 0)
{
fmo_evlv_x = 0;
fmo_evlv_y = 0;
}
else
{
fmo_evlv_x = XSize-1;
fmo_evlv_y = YSize-1;
}
break;
case 6:
if(input->slice_group_change_direction == 0)
{
fmo_evlv_x = 0;
fmo_evlv_y = 0;
}
else
{
fmo_evlv_x = XSize-1;
fmo_evlv_y = YSize-1;
}
break;
}
return 0;
}
int FmoUpdateEvolvingMBAmap (int FmoMode, int XSize, int YSize, int *MBAmap)
{
switch(FmoMode)
{
case 4:
if(input->slice_group_change_direction == 0)
FmoBoxoutClockwise (XSize, YSize, MBAmap);
else
FmoBoxoutCounterClockwise (XSize, YSize, MBAmap);
break;
case 5:
if(input->slice_group_change_direction == 0)
FmoRasterScan (XSize, YSize, MBAmap);
else
FmoInverseRasterScan (XSize, YSize, MBAmap);
break;
case 6:
if(input->slice_group_change_direction == 0)
FmoWipeRight (XSize, YSize, MBAmap);
else
FmoWipeLeft (XSize, YSize, MBAmap);
break;
}
/*
{
int xx, yy;
for (yy=0;yy<YSize; yy++) {
for (xx=0; xx<XSize;xx++) printf ("%d ", MBAmap [yy*XSize+xx]);
printf ("\n"); }
printf ("\n");
}
*/
return 0;
}
int FmoWipeLeft(int XSize, int YSize, int *MBAmap)
{
int i;
int x = fmo_evlv_x;
int y = fmo_evlv_y;
slice_group_change_cycle++;
for(i=0; i<input->slice_group_change_rate_minus1+1; i++)
{
// update the MBAmap unit of the MB (x,y)
MBAmap[y*XSize+x] = 0;
// go to the next MB
if(y > 0) y--;
else if(x > 0)
{
y = YSize-1;
x--;
}
else
{
fmo_evlv_NewPeriod = 1;
break;
}
}
fmo_evlv_x = x;
fmo_evlv_y = y;
return 0;
}
int FmoWipeRight(int XSize, int YSize, int *MBAmap)
{
int i;
int x = fmo_evlv_x;
int y = fmo_evlv_y;
slice_group_change_cycle++;
for(i=0; i<input->slice_group_change_rate_minus1+1; i++)
{
// update the MBAmap unit of the MB (x,y)
MBAmap[y*XSize+x] = 0;
// go to the next MB
if(y < YSize-1) y++;
else if(x < XSize-1)
{
y = 0;
x++;
}
else
{
fmo_evlv_NewPeriod = 1;
break;
}
}
fmo_evlv_x = x;
fmo_evlv_y = y;
return 0;
}
int FmoInverseRasterScan(int XSize, int YSize, int *MBAmap)
{
int i;
int nextMBnum = fmo_evlv_y * XSize + fmo_evlv_x;
slice_group_change_cycle++;
for(i=0; i<input->slice_group_change_rate_minus1+1; i++)
{
// update the next MBAmap unit
MBAmap[nextMBnum] = 0;
// go to the next MB
nextMBnum--;
// check whether passed already the last MB in the evolving period
if( nextMBnum < 0 )
{
fmo_evlv_NewPeriod = 1;
break;
}
}
fmo_evlv_x = nextMBnum%XSize;
fmo_evlv_y = nextMBnum/XSize;
return 0;
}
int FmoRasterScan(int XSize, int YSize, int *MBAmap)
{
int i;
int nextMBnum = fmo_evlv_y * XSize + fmo_evlv_x;
slice_group_change_cycle++;
for(i=0; i<input->slice_group_change_rate_minus1+1; i++)
{
// update the next MBAmap unit
MBAmap[nextMBnum] = 0;
// go to the next MB
nextMBnum++;
// check whether passed already the last MB in the evolving period
if( nextMBnum >= XSize*YSize )
{
fmo_evlv_NewPeriod = 1;
break;
}
}
fmo_evlv_x = nextMBnum%XSize;
fmo_evlv_y = nextMBnum/XSize;
return 0;
}
int FmoBoxoutCounterClockwise (int XSize, int YSize, int *MBAmap)
{
int i;
int W = XSize, H = YSize;
int x = fmo_evlv_x;
int y = fmo_evlv_y;
int left = fmo_evlv_left;
int right = fmo_evlv_right;
int top = fmo_evlv_top;
int bottom = fmo_evlv_bottom;
int directx = fmo_evlv_directx;
int directy = fmo_evlv_directy;
slice_group_change_cycle++;
for(i=0; i<input->slice_group_change_rate_minus1+1; i++)
{
// update the MBAmap unit of the MB (x,y)
MBAmap[y*XSize+x] = 0;
// go to the next mb (x, y)
if ( directx == -1 && directy == 0 )
{
if (x > left) x--;
else if (x == 0)
{
y = bottom + 1;
bottom++;
directx = 1;
directy = 0;
}
else if (x == left)
{
x--;
left--;
directx = 0;
directy = 1;
}
}
else if ( directx == 1 && directy == 0 )
{
if (x < right) x++;
else if (x == W - 1)
{
y = top - 1;
top--;
directx = -1;
directy = 0;
}
else if (x == right)
{
x++;
right++;
directx = 0;
directy = -1;
}
}
else if ( directx == 0 && directy == -1 )
{
if ( y > top) y--;
else if (y == 0)
{
x = left - 1;
left--;
directx = 0;
directy = 1;
}
else if (y == top)
{
y--;
top--;
directx = -1;
directy = 0;
}
}
else if ( directx == 0 && directy == 1 )
{
if (y < bottom) y++;
else if (y == H - 1)
{
x = right+1;
right++;
directx = 0;
directy = -1;
}
else if (y == bottom)
{
y++;
bottom++;
directx = 1;
directy = 0;
}
}
// check whether passed already the last MB in the evolving period
if( !(left >= 0 && right < W && top >= 0 && bottom < H) )
{
fmo_evlv_NewPeriod = 1;
break;
}
}
fmo_evlv_x = x;
fmo_evlv_y = y;
fmo_evlv_left = left;
fmo_evlv_right = right;
fmo_evlv_top = top;
fmo_evlv_bottom = bottom;
fmo_evlv_directx = directx;
fmo_evlv_directy = directy;
return 0;
}
int FmoBoxoutClockwise (int XSize, int YSize, int *MBAmap)
{
int i;
int W = XSize, H = YSize;
int x = fmo_evlv_x;
int y = fmo_evlv_y;
int left = fmo_evlv_left;
int right = fmo_evlv_right;
int top = fmo_evlv_top;
int bottom = fmo_evlv_bottom;
int directx = fmo_evlv_directx;
int directy = fmo_evlv_directy;
slice_group_change_cycle++;
for(i=0; i<input->slice_group_change_rate_minus1+1; i++)
{
// update the MBAmap unit of the MB (x,y)
MBAmap[y*XSize+x] = 0;
// go to the next mb (x, y)
if ( directx == -1 && directy == 0 )
{
if (x > left) x--;
else if (x == 0)
{
y = top - 1;
top--;
directx = 1;
directy = 0;
}
else if (x == left)
{
x--;
left--;
directx = 0;
directy = -1;
}
}
else if ( directx == 1 && directy == 0 )
{
if (x < right) x++;
else if (x == W - 1)
{
y = bottom + 1;
bottom++;
directx = -1;
directy = 0;
}
else if (x == right)
{
x++;
right++;
directx = 0;
directy = 1;
}
}
else if ( directx == 0 && directy == -1 )
{
if ( y > top) y--;
else if (y == 0)
{
x = right + 1;
right++;
directx = 0;
directy = 1;
}
else if (y == top)
{
y--;
top--;
directx = 1;
directy = 0;
}
}
else if ( directx == 0 && directy == 1 )
{
if (y < bottom) y++;
else if (y == H - 1)
{
x = left - 1;
left--;
directx = 0;
directy = -1;
}
else if (y == bottom)
{
y++;
bottom++;
directx = -1;
directy = 0;
}
}
// check whether passed already the last MB in the evolving period
if( !(left >= 0 && right < W && top >= 0 && bottom < H) )
{
fmo_evlv_NewPeriod = 1;
break;
}
}
fmo_evlv_x = x;
fmo_evlv_y = y;
fmo_evlv_left = left;
fmo_evlv_right = right;
fmo_evlv_top = top;
fmo_evlv_bottom = bottom;
fmo_evlv_directx = directx;
fmo_evlv_directy = directy;
return 0;
}
// End JVT-D097
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -