static int request_frame(AVFilterLink *outlink) { MPTestContext *test = outlink->src->priv; AVFrame *picref; int w = WIDTH, h = HEIGHT, cw = FF_CEIL_RSHIFT(w, test->hsub), ch = FF_CEIL_RSHIFT(h, test->vsub); unsigned int frame = outlink->frame_count; enum test_type tt = test->test; int i; if (test->max_pts >= 0 && test->pts > test->max_pts) return AVERROR_EOF; picref = ff_get_video_buffer(outlink, w, h); if (!picref) return AVERROR(ENOMEM); picref->pts = test->pts++; // clean image for (i = 0; i < h; i++) memset(picref->data[0] + i*picref->linesize[0], 0, w); for (i = 0; i < ch; i++) { memset(picref->data[1] + i*picref->linesize[1], 128, cw); memset(picref->data[2] + i*picref->linesize[2], 128, cw); } if (tt == TEST_ALL && frame%30) /* draw a black frame at the beginning of each test */ tt = (frame/30)%(TEST_NB-1); switch (tt) { case TEST_DC_LUMA: dc_test(picref->data[0], picref->linesize[0], 256, 256, frame%30); break; case TEST_DC_CHROMA: dc_test(picref->data[1], picref->linesize[1], 256, 256, frame%30); break; case TEST_FREQ_LUMA: freq_test(picref->data[0], picref->linesize[0], frame%30); break; case TEST_FREQ_CHROMA: freq_test(picref->data[1], picref->linesize[1], frame%30); break; case TEST_AMP_LUMA: amp_test(picref->data[0], picref->linesize[0], frame%30); break; case TEST_AMP_CHROMA: amp_test(picref->data[1], picref->linesize[1], frame%30); break; case TEST_CBP: cbp_test(picref->data , picref->linesize , frame%30); break; case TEST_MV: mv_test(picref->data[0], picref->linesize[0], frame%30); break; case TEST_RING1: ring1_test(picref->data[0], picref->linesize[0], frame%30); break; case TEST_RING2: ring2_test(picref->data[0], picref->linesize[0], frame%30); break; } return ff_filter_frame(outlink, picref); }
void test_perm(int N, int NN, unsigned int M) { int j; unsigned long i; double sum2 = 0; Array<long> count(0,NN-1); // count number of times each ball is drawn Array<int> last(0,NN-1); // details of last draw long consec = 0; // count number of consecutive balls last = 0; count = 0; // set the arrays to zero cout << endl; cout << "Size of urn = " << NN << "; "; cout << "no. of balls = " << N << "; "; cout << "no. of trials = " << M << endl; cout << BaseTest::Header << endl; if (N > NN) { Throw(Runtime_error("N > NN")); } long double S0 = 0.0; // sum of ball numbers long double S1 = 0.0; // sum of ball * draw double centre = (NN+1) / 2.0; // average ball number double avj = (N+1)/2.0; // average draw number Array2<int> table1(0,NN-1,0,N-1); // times ball i occurs at draw j Array2<int> table2(0,NN-1,0,NN-1); // times ball i and ball j both occur table1 = 0; table2 = 0; // clear the tables long turnings = 0; // number of turning points RandomPermutation RP; // reset the Urn Array<int> Draw(0,N-1); // for the draw for (i=1; i<=M; i++) // iterate over total number of trials { int last_ball = -1; RP.Next(NN,N,Draw.base(),1); // do the draw Array<int> check(0,NN-1); check = 0; // for checking no repeats for (j = 1; j <= N; j++) // N balls in draw { int x = Draw(j-1); if (x<1 || x>NN) Throw(Runtime_error("Invalid number")); check(x-1)++; count(x-1)++; sum2 += last(x-1); if (x == last_ball+1 || x == last_ball-1) consec++; last_ball = x; double xc = x - centre; S0 += xc; S1 += xc * (j-avj); table1(x-1,j-1)++; } for (j=0; j<NN; j++) { if (check(j) > 1) Throw(Runtime_error("Repeated number")); last(j) = check(j); if (check(j)) // increment table of pairs { for (int k = j+1; k<NN; k++) if (check(k)) table2(j,k)++; } } // count number of turnings for (j = 2; j < N; j++) { long last = Draw(j-2); long current = Draw(j-1); long next = Draw(j); if ( (last < current && next < current) || (last > current && next > current) ) turnings++; } } // do the tests double sum1 = 0.0; double d = M * (N / (double)NN); for (j=0; j<NN; j++) { sum1 += square(count(j) - d); } if (N < NN) { sum1 /= d; double sd = (NN - N) * sqrt( 2 * (M - 1) / (M * ((double)(NN - 1))) ); NormalTestTwoSided freq_test("Ball freq.", sum1, NN - N, square(sd)); freq_test.DoTest(); NormalTestTwoSided repeats_test("Repeats", sum2, (M - 1) * (N * N / (double)NN), square((double)(N * (NN - N)) / (double)NN) * (M - 1) / (NN - 1) ); repeats_test.DoTest(); double V0 = ((double)N * (NN+1.0) * (NN-N))/12.0; NormalTestTwoSided average_test("Average", S0, 0, M * V0); average_test.DoTest(); } if (N > 1) { double V1 = (double)N * (N*N - 1) * NN * (NN + 1) / 144.0; NormalTestTwoSided ball_times_draw("Ball * draw", S1, 0, M * V1); ball_times_draw.DoTest(); double e = 2 * M * (N - 1) / (double)NN; // expected # of consecutive balls NormalTestTwoSided consec_test("Consec balls", consec, e, e); consec_test.DoTest(); } if (N > 1) { // balls vs draws double CS = 0; double ev = (double)M / NN; for (int i = 0; i < NN; i++) for (int j = 0; j < N; j++) CS += square(table1(i,j)-ev); CS /= ev; ev = N * (NN - 1); double v = 2.0 * N * (M - 1) * (N - (2 - NN) * NN) / M / (NN - 1); NormalTestTwoSided ball_draw("Ball vs draw", CS, ev, v); ball_draw.DoTest(); } if (N>1 && N < NN) { // pairs of balls double CS = 0; double ev = (double)M*N*(N-1)/ NN / (NN-1); for (int i = 0; i < NN; i++) for (int j = i+1; j < NN; j++) CS += square(table2(i,j)-ev); CS /= ev; ev = (NN-N)*(NN+N-1)/2.0; double v = (double)(M-1)*square(NN-N)*(-3+6*N-3.0*N*N+2*NN-6.0*N*NN+ 2.0*N*N*NN+NN*NN)/(M*(NN-2)*(NN-3)); NormalTestTwoSided pairs_test("Pairs table", CS, ev, v); pairs_test.DoTest(); } if (N > 2) { double V2 = (16.0 * N - 29.0) / 90.0; NormalTestTwoSided runs_test("Runs test", turnings, (double)M * (N-2) / 1.5, M * V2); runs_test.DoTest(); } }