Ejemplo n.º 1
0
void testApp::applyFx(unsigned char *pixels) {
    int totalPixels = camWidth*camHeight*3;
    for (int i = 0; i < totalPixels; i+= 3) {
        if(holdingBuffer) {
            /*
            			if(videoBuffer[i] > 0 || videoBuffer[i+1] > 0 || videoBuffer[i+2] > 0){
            				videoOut[i] = videoBuffer[i];
            				videoOut[i+1] = videoBuffer[i+1];
            				videoOut[i+2] = videoBuffer[i+2];
            				continue;
            			}*/
            if(different(videoOut[i], videoOut[i+1], videoOut[i+2], pixels[i], pixels[i+1], pixels[i+2])) {
                videoOut[i] = videoBuffer[i] = pixels[i];
                videoOut[i+1] = videoBuffer[i+1] = pixels[i+1];
                videoOut[i+2] = videoBuffer[i+2] = pixels[i+2];
                continue;
            }
        } else {
            videoOut[i] =  pixels[i];
            videoOut[i+1] = pixels[i+1];
            videoOut[i+2] = pixels[i+2];
            continue;
        }
    }
}
int
main ()
{
    different (5);
    validity (5, data ());
    invalid (data2 ());
    return 0;
}
Ejemplo n.º 3
0
int
compare(Gif_Stream *s1, Gif_Stream *s2)
{
  Gif_Colormap *newcm;
  int imageno1, imageno2, background1, background2;
  char buf1[256], buf2[256], fbuf[256];

  was_different = 0;

  /* Compare image counts and screen sizes. If either of these differs, quit
     early. */
  Gif_CalculateScreenSize(s1, 0);
  Gif_CalculateScreenSize(s2, 0);

  if (s1->nimages != s2->nimages
      && (s1->nimages == 0 || s2->nimages == 0)) {
    different("frame counts differ: <#%d >#%d", s1->nimages, s2->nimages);
    return DIFFERENT;
  }

  if (s1->screen_width != s2->screen_width
      || s1->screen_height != s2->screen_height) {
    different("screen sizes differ: <%dx%d >%dx%d", s1->screen_width,
	      s1->screen_height, s2->screen_width, s2->screen_height);
    return DIFFERENT;
  }

  if (s1->screen_width == 0 || s1->screen_height == 0
      || s2->screen_width == 0 || s2->screen_height == 0) {
    /* paranoia -- don't think this can happen */
    different("zero screen sizes");
    return DIFFERENT;
  }

  /* Create arrays for the image data */
  screen_width = s1->screen_width;
  screen_height = s1->screen_height;

  gdata[0] = Gif_NewArray(uint16_t, screen_width * screen_height);
  gdata[1] = Gif_NewArray(uint16_t, screen_width * screen_height);
  glast[0] = Gif_NewArray(uint16_t, screen_width * screen_height);
  glast[1] = Gif_NewArray(uint16_t, screen_width * screen_height);
  scratch = Gif_NewArray(uint16_t, screen_width * screen_height);
  line = Gif_NewArray(uint16_t, screen_width);

  /* Merge all distinct colors from the two images into one colormap, setting
     the 'pixel' slots in the images' colormaps to the corresponding values
     in the merged colormap. Don't forget transparency */
  newcm = Gif_NewFullColormap(1, 256);
  combine_colormaps(s1->global, newcm);
  combine_colormaps(s2->global, newcm);
  for (imageno1 = 0; imageno1 < s1->nimages; ++imageno1)
    combine_colormaps(s1->images[imageno1]->local, newcm);
  for (imageno2 = 0; imageno2 < s2->nimages; ++imageno2)
    combine_colormaps(s2->images[imageno2]->local, newcm);

  /* Choose the background values and clear the image data arrays */
  if (s1->images[0]->transparent >= 0 || !s1->global)
    background1 = TRANSP;
  else
    background1 = s1->global->col[ s1->background ].pixel;

  if (s2->images[0]->transparent >= 0 || !s2->global)
    background2 = TRANSP;
  else
    background2 = s2->global->col[ s2->background ].pixel;

  fill_area(gdata[0], 0, 0, screen_width, screen_height, background1);
  fill_area(gdata[1], 0, 0, screen_width, screen_height, background2);

  /* Loopcounts differ? */
  if (s1->loopcount != s2->loopcount) {
    name_loopcount(s1->loopcount, buf1);
    name_loopcount(s2->loopcount, buf2);
    different("loop counts differ: <%s >%s", buf1, buf2);
  }

  /* Loop over frames, comparing image data and delays */
  apply_image(0, s1, 0, background1);
  apply_image(1, s2, 0, background2);
  imageno1 = imageno2 = 0;
  while (imageno1 != s1->nimages && imageno2 != s2->nimages) {
    int fi1 = imageno1, fi2 = imageno2,
      delay1 = s1->images[fi1]->delay, delay2 = s2->images[fi2]->delay;

    /* get message right */
    if (imageno1 == imageno2)
      sprintf(fbuf, "#%d", imageno1);
    else
      sprintf(fbuf, "<#%d >#%d", imageno1, imageno2);

    /* compare pixels */
    if (memcmp(gdata[0], gdata[1],
	       screen_width * screen_height * sizeof(uint16_t)) != 0) {
      unsigned d, c = screen_width * screen_height;
      uint16_t *d1 = gdata[0], *d2 = gdata[1];
      for (d = 0; d < c; d++, d1++, d2++)
	if (*d1 != *d2) {
	  name_color(*d1, newcm, buf1);
	  name_color(*d2, newcm, buf2);
	  different("frame %s pixels differ: %d,%d <%s >%s",
		    fbuf, d % screen_width, d / screen_width, buf1, buf2);
	  break;
	}
    }

    /* move to next images, skipping redundancy */
    for (++imageno1;
	 imageno1 < s1->nimages && !apply_image(0, s1, imageno1, background1);
	 ++imageno1)
      delay1 += s1->images[imageno1]->delay;
    for (++imageno2;
	 imageno2 < s2->nimages && !apply_image(1, s2, imageno2, background2);
	 ++imageno2)
      delay2 += s2->images[imageno2]->delay;

    if (!ignore_redundancy) {
      fi1 = (imageno1 - fi1) - (imageno2 - fi2);
      for (; fi1 > 0; --fi1)
	different("extra redundant frame: <#%d", imageno1 - fi1);
      for (; fi1 < 0; ++fi1)
	different("extra redundant frame: >#%d", imageno2 + fi1);
    }

    if (delay1 != delay2) {
      name_delay(delay1, buf1);
      name_delay(delay2, buf2);
      different("frame %s delays differ: <%s >%s", fbuf, buf1, buf2);
    }
  }

  if (imageno1 != s1->nimages || imageno2 != s2->nimages)
    different("frame counts differ: <#%d >#%d", s1->nimages, s2->nimages);

  /* That's it! */
  Gif_DeleteColormap(newcm);
  Gif_DeleteArray(gdata[0]);
  Gif_DeleteArray(gdata[1]);
  Gif_DeleteArray(glast[0]);
  Gif_DeleteArray(glast[1]);
  Gif_DeleteArray(scratch);
  Gif_DeleteArray(line);

  return was_different ? DIFFERENT : SAME;
}
Ejemplo n.º 4
0
folly::SemiFuture<apache::thrift::Stream<std::string>> PubSubStreamingServiceSvIf::semifuture_different(apache::thrift::SemiStream<int32_t> foo, int64_t firstparam) {
  return apache::thrift::detail::si::semifuture([&] { return different(std::move(foo), firstparam); });
}
Ejemplo n.º 5
0
int improve(int ring,clock_t start,int p,int levelMax,int iterMax,int *currBestScore, int *bestScore,elem_sol **currBest,int width,int heigth,pos_t * pos_centers,pos_t *pos_borders,pos_t* pos_corners,
        int numCenters,int  numBorders,int  numCorners,int perc_shake_coner,int perc_shake_border,int perc_shake_center,int maxTotal,elem_sol**best,
        int stepStarts,int maxUguale){

        int stepTot=0;
        int iter,neighborOfcurrBestScore;
        int prev;
        clock_t stop;
        float difference;
        int uguale;
        int fine=0,i;
        elem_sol**neighborOfcurrBest;
        neighborOfcurrBest=allocaMatrix(width,heigth);

        int num,binCenter,binCorner,binBorder;
        binCorner=bin(numCorners);
        binBorder=bin(numBorders);

        ring++;
        //if(ring>2) {
          //  printf("Ring %d",ring);
            //char c=getchar();
            //}
    fine=0;
    uguale=0;
    int cnt=0;
    while(!fine && cnt < MAX_COUNT){
        cnt++;
        levelMax=heigth/2;
        p=LEVEL_MIN;
        while ( p< levelMax && !fine){
            iter=0;
            num=centersOnFrame(p,heigth,numCenters);
            binCenter=bin(num);
            computePercShake(binCorner,binBorder,binCenter,&perc_shake_coner,&perc_shake_border,&perc_shake_center);

            //uguale=0;
            //printf("p %d\n",p);
            while(iter < iterMax*p && !fine){
                stepTot++;
                neighborOfcurrBestScore=*currBestScore;
                storeSolution(neighborOfcurrBest,currBest,width,heigth);

               for (i=0; i<p; i++){
                    shake(p,neighborOfcurrBest, width, heigth, pos_centers, pos_borders, pos_corners, numCenters, numBorders, numCorners,perc_shake_coner,perc_shake_border,perc_shake_center);
                    //speedStarting(neighborOfcurrBest, width, heigth, pos_centers, pos_borders, pos_corners, numCenters, numBorders, numCorners);
                }
                neighborOfcurrBestScore=CheckMatchingEdgesSol(neighborOfcurrBest,width,heigth);
                //printf("ring %d p %d iter %d- Before %d \n",ring,p,iter,neighborOfcurrBestScore);

                if(p>1)
                    improvedLocal(&neighborOfcurrBestScore,neighborOfcurrBest,
                              width,heigth,pos_centers,pos_borders,pos_corners,numCenters,numBorders,numCorners,p);

                //improve(ring,start,LEVEL_MIN,LEVEL_MIN+1, iterMax,&neighborOfcurrBestScore,*currBestScore,neighborOfcurrBest,width,heigth,pos_centers,pos_borders,pos_corners,
                //numCenters,numBorders,numCorners,perc_shake_coner,perc_shake_border,perc_shake_center,maxTotal,best,stepStarts,maxUguale/p);
                //printf("ring %d p %d iter %d- After %d -%d\n",ring,p,iter,neighborOfcurrBestScore,CheckMatchingEdgesSol(neighborOfcurrBest,width,heigth));

              if(LOCAL_ROTATE){
                    localSearch3(pos_centers, numCenters, neighborOfcurrBest, vector, width, heigth);
                }
                //speedStarting(neighborOfcurrBest, width, heigth, pos_centers, pos_borders, pos_corners, numCenters, numBorders, numCorners);

                neighborOfcurrBestScore=CheckMatchingEdgesSol(neighborOfcurrBest,width,heigth);
                //printf("Dopo local ring %d p %d iter %d- After %d \n",ring,p,iter,neighborOfcurrBestScore);
                //if(ring==0) printf("Sono tornato!\n");

                if (DOLOCAL){
                    if (FROM_CORNERS_TO_CENTERS) {
                        doLocalSearchHun(CORNER,VALUE_K_CORNER,numCorners,pos_corners,neighborOfcurrBest,heigth,width,&neighborOfcurrBestScore);
                        doLocalSearchHun(BORDER,VALUE_K_BORDER,numBorders,pos_borders,neighborOfcurrBest,heigth,width,&neighborOfcurrBestScore);
                        doLocalSearchHun(CENTER,VALUE_K_CENTER,numCenters,pos_centers,neighborOfcurrBest,heigth,width,&neighborOfcurrBestScore);
                    }
                    else {
                    doLocalSearchHun(CENTER,VALUE_K_CENTER,numCenters,pos_centers,neighborOfcurrBest,heigth,width,&neighborOfcurrBestScore);
                    doLocalSearchHun(BORDER,VALUE_K_BORDER,numBorders,pos_borders,neighborOfcurrBest,heigth,width,&neighborOfcurrBestScore);
                    doLocalSearchHun(CORNER,VALUE_K_CORNER,numCorners,pos_corners,neighborOfcurrBest,heigth,width,&neighborOfcurrBestScore);
                    }
                }

                if(DOLOCAL_REPEAT){
                    do{
                        do{
                            doLocalSearchHun(CORNER,VALUE_K_CORNER,numCorners,pos_corners,neighborOfcurrBest,heigth,width,&neighborOfcurrBestScore);
                            prev=neighborOfcurrBestScore;
                            doLocalSearchHun(BORDER,VALUE_K_BORDER,numBorders,pos_borders,neighborOfcurrBest,heigth,width,&neighborOfcurrBestScore);
                        }while (prev !=neighborOfcurrBestScore );
                    doLocalSearchHun(CENTER,VALUE_K_CENTER,numCenters,pos_centers,neighborOfcurrBest,heigth,width,&neighborOfcurrBestScore);
                    }while (prev != neighborOfcurrBestScore);
                }

                stop = clock();
                difference = ((float)(stop - globalTime))/CLOCKS_PER_SEC;

                if( maxTime>0 && difference >= maxTime){
                    goto end;
                }

                if ( (neighborOfcurrBestScore > *currBestScore)  ||
                    ( /*p==1 &&*/uguale < maxUguale && (neighborOfcurrBestScore == *currBestScore) && different(neighborOfcurrBest,currBest,heigth,width)) ){
                 if (neighborOfcurrBestScore == *currBestScore)
                    uguale ++;


                 //   if(ring >= 3 ){
                    //printf ("\nRing %d nedges matching = %d \t currBestScore = %d \t bestScore = %d\n", ring,neighborOfcurrBestScore, *currBestScore, bestScore);
                    //printf("\nTime %f - Passaggio %d: Sono all'iter %d e shake è fatta %d volte A %3d B %3d C %3d  pt uguale per %d- Sono ripartito %d volte\n",
                    //        difference,stepTot, iter, p, perc_shake_coner,perc_shake_border,perc_shake_center,uguale,stepStarts);
                   // }
                    //printGame(heigth, width,neighborOfcurrBest);


                    //printf("p %d\n",p);

                    if (neighborOfcurrBestScore > *currBestScore){
                        p=LEVEL_MIN;
                        uguale=0;
                        //printGame(heigth, width, currBest);
                        //printf("\a\a\a");
                        p=LEVEL_MIN;iter=0;
                        num=centersOnFrame(p,heigth,numCenters);
                        binCenter=bin(num);
                        computePercShake(binCorner,binBorder,binCenter,&perc_shake_coner,&perc_shake_border,&perc_shake_center);
                        *currBestScore=neighborOfcurrBestScore;
                        /*
                        stop = clock();
                        difference = ((float)(stop - start))/CLOCKS_PER_SEC;
                        printf("\nTime %f - Best Score: %d\n",difference,*currBestScore);
                        */
                        }


                    *currBestScore=neighborOfcurrBestScore;
                    if ( (*currBestScore) > *bestScore ){
                        storeSolution(best,currBest,width,heigth);
                        *bestScore= (*currBestScore);

                        stop = clock();
                        difference = ((float)(stop - start))/CLOCKS_PER_SEC;
                        float differenceGlobal = ((float)(stop - globalTime))/CLOCKS_PER_SEC;
                        printf("\nGlobal Time %.2f - Time %.2f for %d instance - Best Score: %d\n",differenceGlobal,difference,stepStarts,*bestScore);

                    }

                    storeSolution(currBest,neighborOfcurrBest,width,heigth);
                    printer(width,heigth,currBest);
/*
                    stop = clock();
                    difference = ((float)(stop - globalTime))/CLOCKS_PER_SEC;
                    printf("\nGlobal Time %.2f\n",difference);
*/
                    if (stepTot >= MAXITERTOT || *bestScore == maxTotal ||
                        ( maxScore >0 && *bestScore >=maxScore) || ( maxTime>0 &&  difference>=maxTime) ){
                        end:
                        printf("\nDone!\n");
                        storeSolution(best,currBest,width,heigth);
                        printf("\nBest score = best %d in %f seconds\nResult matrix following:\n", *bestScore,difference);
                        printGame2(heigth, width, best);
                        printer(width,heigth,best);
                        fine = 1;
                        }
                }
                iter++;
                }
            p+=1;
            }
    }
    return fine;
}