00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "global.h"
00018
00019 static int *RefreshPattern;
00020 static int *IntraMBs;
00021 static int WalkAround = 0;
00022 static int NumberOfMBs = 0;
00023 static int NumberIntraPerPicture;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 void RandomIntraInit(int xsize, int ysize, int refresh)
00041 {
00042 int i, pos;
00043
00044 srand (1);
00045 NumberOfMBs = xsize * ysize;
00046 NumberIntraPerPicture = refresh;
00047
00048 if (refresh != 0)
00049 {
00050 RefreshPattern = malloc (sizeof (int) * NumberOfMBs);
00051 if (RefreshPattern == NULL) no_mem_exit("RandomIntraInit: RefreshPattern");
00052
00053 IntraMBs = malloc (sizeof (int) * refresh);
00054 if (IntraMBs == NULL) no_mem_exit("RandomIntraInit: IntraMBs");
00055
00056 for (i= 0; i<NumberOfMBs; i++)
00057 RefreshPattern[i] = -1;
00058
00059 for (i=0; i<NumberOfMBs; i++)
00060 {
00061 do
00062 {
00063 pos = rand() % NumberOfMBs;
00064 } while (RefreshPattern [pos] != -1);
00065 RefreshPattern [pos] = i;
00066 }
00067
00068
00069
00070
00071 }
00072 else
00073 {
00074 RefreshPattern = NULL;
00075 IntraMBs = NULL;
00076 }
00077 }
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 int RandomIntra (int mb)
00095 {
00096 int i;
00097
00098 for (i=0; i<NumberIntraPerPicture; i++)
00099 if (IntraMBs[i] == mb)
00100 return 1;
00101 return 0;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 void RandomIntraNewPicture ()
00118 {
00119 int i, j;
00120
00121 WalkAround += NumberIntraPerPicture;
00122 for (j=0,i=WalkAround; j<NumberIntraPerPicture; j++, i++)
00123 IntraMBs[j] = RefreshPattern [i%NumberOfMBs];
00124 }
00125
00126 void RandomIntraUninit()
00127 {
00128 if (NumberIntraPerPicture >0 )
00129 {
00130 free(RefreshPattern);
00131 free(IntraMBs);
00132 }
00133 }