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