void solve_case(void) { char C[MAX_MN][MAX_MN+1]; opening(A, B, C); print_image(C); fprintf(out, "\n"); closing(A, B, C); print_image(C); }
int main (int argc, char const *argv[]) { const int N = 7; int **im; im = allocate2D(im, N); generate_image(im, N); print_image(im, N); rotate_image(im, N); printf("\n"); print_image(im, N); release2D(im, N); return 0; }
int main(int argc, const char **argv) { init_letters(); const char *string = "hello world! :)"; int num_lines = 20; int freq_min = 1000; int freq_max = 1500; int col_time_ms = 400; int from_image = 0; for (int i = 1; i < argc; i++) { int val = 0; if (sscanf(argv[i], "lines=%d", &val)) num_lines = val; else if (sscanf(argv[i], "min=%d", &val)) freq_min = val; else if (sscanf(argv[i], "max=%d", &val)) freq_max = val; else if (sscanf(argv[i], "time=%d", &val)) col_time_ms = val; else if (strcmp(argv[i], "image=true") == 0) from_image = 1; else string = argv[i]; } if (from_image) { print_image(string, freq_min, freq_max, col_time_ms); } else { print_string(string, num_lines, freq_min, freq_max, col_time_ms); } return 0; }
/** Funcao que imprime os inimigos*/ void print_enemies(ESTADO e) { int i; for(i = 0; i < e.num_inimigos; i++){ print_move_enemie(e,+1,0); print_image(e.inimigo[i].x, e.inimigo[i].y, TAM,ENEMY); } }
static void print_image_list(struct deltacloud_image *images) { struct deltacloud_image *image; deltacloud_for_each(image, images) print_image(image); }
int main(void) { int ret; ret = configureFpga(PFS_FPGA_MMAP_FILE); if (!ret) exit(1); ret = print_image(PIX_H, PIX_W); exit(ret); }
/** Funcao que imprime o jogador*/ void print_player(ESTADO e){ print_image(e.jog.x, e.jog.y, TAM,PLAYER); print_move(e,+1,0); print_move(e,-1,0); print_move(e,0,+1); print_move(e,0,-1); print_move(e,+1,+1); print_move(e,-1,-1); print_move(e,+1,-1); print_move(e,-1,+1); }
int main(void) { printf("Enter N, followed by the NxN values\n"); size_t dim; while (scanf("%zu", &dim) == 1) { unsigned image[dim][dim]; size_t i, j; for (i = 0; i < dim; i++) { for (j = 0; j < dim; j++) { scanf("%u", &image[i][j]); } } printf("Before rotation:\n"); print_image(dim, image); printf("After rotation:\n"); rotate_image(dim, image); print_image(dim, image); } return 0; }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[2]; GimpRunMode run_mode; GimpPDBStatusType status; gint32 image_ID; GError *error = NULL; run_mode = param[0].data.d_int32; INIT_I18N (); *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; image_ID = param[1].data.d_int32; if (strcmp (name, PRINT_PROC_NAME) == 0) { status = print_image (image_ID, run_mode == GIMP_RUN_INTERACTIVE, &error); if (error && run_mode == GIMP_RUN_INTERACTIVE) { print_show_error (error->message); } } else { status = GIMP_PDB_CALLING_ERROR; } if (status != GIMP_PDB_SUCCESS && error) { *nreturn_vals = 2; values[1].type = GIMP_PDB_STRING; values[1].data.d_string = error->message; } values[0].data.d_status = status; }
int main(void) { char *filename = "asciiArt.txt"; //Open a text file called asciiArt.txt FILE *fptr = NULL; if((fptr = fopen(filename,"r")) == NULL) { fprintf(stderr,"error opening %s\n",filename); //If there is no file by the name, then whine. return 1337; //1337. Elite. } print_image(fptr); fclose(fptr); return 0; }
int main (int argc, char* argv[]) { // Read inputs Inputs* inputs = read_inputs(); // Create image Image* image = new_image( inputs->box.xMax - inputs->box.xMin, inputs->box.yMax - inputs->box.xMin); // Generate random colors Color colors[inputs->numSites]; for (int i = 0; i < inputs->numSites; i++) { colors[i] = random_color(); } // Bruteforce voronoi for (int i = inputs->box.xMin; i < inputs->box.xMax; i++) { for (int j = inputs->box.yMin; j < inputs->box.yMax; j++) { Point curr = { .x = i, .y = j }; int nearest = 0; for (int k = 0; k < inputs->numSites; k++) { double old_dist = distance_squared(&curr, &inputs->sites[nearest]); double new_dist = distance_squared(&curr, &inputs->sites[k]); if (new_dist < old_dist) { nearest = k; } } set_pixel(i, j, colors[nearest], image); } } // Do line sweep fortune(inputs, image); print_image(image); // Free memory free_image(image); free_inputs(inputs); return 0; }
int main(int argc, char **argv) { char *left_file = NULL; char *right_file = NULL; char *out_file = NULL; int feature_width = -1; int feature_height = -1; int maximum_displacement = -1; int verbosity = 0; int i; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'l': if (argc > i + 1) left_file = argv[++i]; break; case 'r': if (argc > i + 1) right_file = argv[++i]; break; case 'o': if (argc > i + 1) out_file = argv[++i]; break; case 'w': if (argc > i + 1) feature_width = atoi(argv[++i]); break; case 'h': if (argc > i + 1) feature_height = atoi(argv[++i]); break; case 't': if (argc > i + 1) maximum_displacement = atoi(argv[++i]); break; case 'v': verbosity = 1; break; default: printf("Unknown option: %s\n", argv[i]); exit(EINVAL); } } } if (left_file == NULL || right_file == NULL || feature_width == -1 || feature_height == -1 || maximum_displacement == -1) { printf(USAGE, argv[0]); exit(EINVAL); } Image left_image = load_image(left_file); Image right_image = load_image(right_file); if (left_image.height != right_image.height || left_image.width != right_image.width) { printf("The two images do not have the same dimensions.\n"); exit(EINVAL); } Image depth; depth.width = left_image.width; depth.height = right_image.height; depth.data = (unsigned char*) malloc(depth.width * depth.height); if (!depth.data) allocation_failed(); srand((unsigned int) time(NULL)); for (i = 0; i < depth.width * depth.height; i++) { depth.data[i] = rand(); } calc_depth(depth.data, left_image.data, right_image.data, left_image.width, left_image.height, feature_width, feature_height, maximum_displacement); if (out_file != NULL) { save_image_with_depth(out_file, left_image.data, depth.data, left_image.width, left_image.height, feature_width, feature_height); } if (verbosity >= 1) { print_image(depth.data, depth.width, depth.height); } return 0; }
int main(int argc, char *argv[]) { struct deltacloud_api api; struct deltacloud_api zeroapi; struct deltacloud_image image; struct deltacloud_image *images = NULL; //struct deltacloud_instance instance; //char *instid; //char *imgid; //int timeout; int ret = 3; if (argc != 4) { fprintf(stderr, "Usage: %s <url> <user> <password>\n", argv[0]); return 1; } memset(&zeroapi, 0, sizeof(struct deltacloud_api)); if (deltacloud_initialize(&api, argv[1], argv[2], argv[3]) < 0) { fprintf(stderr, "Failed to find links for the API: %s\n", deltacloud_get_last_error_string()); return 2; } /* test out deltacloud_supports_images */ if (deltacloud_supports_images(NULL) >= 0) { fprintf(stderr, "Expected deltacloud_supports_images to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_images(&zeroapi) >= 0) { fprintf(stderr, "Expected deltacloud_supports_images to fail with uninitialized api, but succeeded\n"); goto cleanup; } if (deltacloud_supports_images(&api)) { /* test out deltacloud_get_images */ if (deltacloud_get_images(NULL, &images) >= 0) { fprintf(stderr, "Expected deltacloud_get_images to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_images(&api, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_images to fail with NULL images, but succeeded\n"); goto cleanup; } if (deltacloud_get_images(&zeroapi, &images) >= 0) { fprintf(stderr, "Expected deltacloud_get_images to fail with unintialized api, but succeeded\n"); goto cleanup; } if (deltacloud_get_images(&api, &images) < 0) { fprintf(stderr, "Failed to get_images: %s\n", deltacloud_get_last_error_string()); goto cleanup; } print_image_list(images); if (images != NULL) { /* test out deltacloud_get_image_by_id */ if (deltacloud_get_image_by_id(NULL, images->id, &image) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with NULL api, but succeeded\n"); goto cleanup; } if (deltacloud_get_image_by_id(&api, NULL, &image) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with NULL id, but succeeded\n"); goto cleanup; } if (deltacloud_get_image_by_id(&api, images->id, NULL) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with NULL image, but succeeded\n"); goto cleanup; } if (deltacloud_get_image_by_id(&api, "bogus_id", &image) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with bogus id, but succeeded\n"); goto cleanup; } if (deltacloud_get_image_by_id(&zeroapi, images->id, &image) >= 0) { fprintf(stderr, "Expected deltacloud_get_image_by_id to fail with unintialized api, but succeeded\n"); goto cleanup; } /* here we use the first image from the list above */ if (deltacloud_get_image_by_id(&api, images->id, &image) < 0) { fprintf(stderr, "Failed to get image by id: %s\n", deltacloud_get_last_error_string()); goto cleanup; } print_image(&image); deltacloud_free_image(&image); } /* FIXME: due to bugs in deltacloud, I can't seem to make this work * at present. We'll have to revisit. */ #if 0 if (deltacloud_supports_instances(&api)) { /* the first thing we need to do is create an instance that we will * snapshot from. In order to create an instance, we need to find * an image to base the instance off of. We fetch the list of images * and just use the first one */ if (deltacloud_get_images(&api, &images) < 0) { fprintf(stderr, "Failed to get images: %s\n", deltacloud_get_last_error_string()); goto cleanup; } if (deltacloud_create_instance(&api, images->id, NULL, 0, &instid) < 0) { deltacloud_free_image_list(&images); fprintf(stderr, "Failed to create instance: %s\n", deltacloud_get_last_error_string()); goto cleanup; } deltacloud_free_image_list(&images); if (wait_for_instance_boot(api, instid, &instance) != 1) { free(instid); goto cleanup; } free(instid); /* if we made it here, then the instance went to running. We can * now do operations on it */ if (deltacloud_create_image(&api, "newimage", &instance, NULL, 0, &imgid) < 0) { deltacloud_instance_destroy(&api, &instance); deltacloud_free_instance(&instance); fprintf(stderr, "Failed to create image from instance: %s\n", deltacloud_get_last_error_string()); goto cleanup; } free(imgid); deltacloud_instance_destroy(&api, &instance); deltacloud_free_instance(&instance); } else fprintf(stderr, "Instances are not supported, so image creation test is skipped\n"); #endif } else fprintf(stderr, "Images are not supported\n"); ret = 0; cleanup: deltacloud_free_image_list(&images); deltacloud_free(&api); return ret; }
int main(int argc, char **argv) { // _MM_ROUND_NEAREST // _MM_ROUND_DOWN // _MM_ROUND_UP // _MM_ROUND_TOWARD_ZERO // _MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST); if (argc != 5) { printf("Invalid arguments\n"); printf("\tprogram height width ix iy\n"); exit(EXIT_FAILURE); } struct timeval t, t2; int height = atoi(argv[1]), width = atoi(argv[2]); float ix = atof(argv[3]), //zoom en x iy = atof(argv[4]); //zoom en y int delay = 2; short *mirror = NULL; //donde dira el padre que empieza el espejo global short *scale = NULL; //donde dira el padre que hay que guardar las cosas //Las dos siguientes las modifica MPI int nprocs, myid; MPI_Init(&argc, &argv);//inicializamos mpi MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); int aux_rows[nprocs];//Las filas con las que trabajara cada proceso int size_send_child[nprocs];//El numero de elementos a enviar a cada hijo int aux_split[nprocs];//Es para saber donde empezar a contar (este es para enviar a los hijos) int size_send_dad[nprocs]; //para saber el tamano que se le va a enviar al padre int aux_begin[nprocs]; //Es el para saber donde empezar a contar (este es para enviar al padre) //Con esto indicamos que todos saben lo que tienen todos fill_aux_rows(aux_rows, nprocs, height, delay); fill_size_send_child(size_send_child, nprocs, aux_rows, width, delay); fill_aux_split(aux_split, nprocs, size_send_child[0], width, delay); fill_size_send_dady(size_send_dad, nprocs, aux_rows, width, ix, iy, delay); fill_aux_begin(aux_begin, nprocs, size_send_dad[0]); if (myid == 0) {//Parent process short *originalImage = malloc(sizeof(short) * height * width); //Imagen original mirror = malloc(sizeof(short) * (height+delay*2) * (width+delay*2)); //Imagen en espejo if (originalImage == NULL || mirror == NULL) { exit_msg("main: cannot allocate memory", myid); } getImage(originalImage, height, width); getMirror(originalImage, mirror, height, width, delay); free(originalImage); gettimeofday(&t, NULL);//Empezamos a contar el tiempo } short *work = malloc(sizeof(short) * (aux_rows[myid]) * (width+2*delay) ); //con la que trabajara cada proceso if (work == NULL) exit_msg("main: cannot allocate memory (for work)", myid); //Enviamos a los procesos la informacion if (0 != MPI_Scatterv(mirror, size_send_child, aux_split, MPI_SHORT, work, size_send_child[myid], MPI_SHORT, 0, MPI_COMM_WORLD)) exit_msg("main: MPI_Scatterv", myid); short *result = malloc(sizeof(short) * ((int) ((aux_rows[myid]-2*delay)*iy)) * (int) (width*ix)); if (result == NULL) exit_msg("main: cannot allocate memory (for result)", myid); getScale(work, result, aux_rows[myid]-2*delay, width, delay, ix, iy); free(work); if (myid == 0) { free(mirror); scale = malloc(sizeof(short) * ((int) (height*iy)) * ((int) (width*ix))); // donde se guardara el resultado final } //Los procesos envian la informacion al padre if (0 != MPI_Gatherv(result, size_send_dad[myid], MPI_SHORT, scale, size_send_dad, aux_begin, MPI_SHORT, 0, MPI_COMM_WORLD)) exit_msg("main: MPI_Gatherv", myid); if (myid == 0) { gettimeofday(&t2, NULL); struct timeval diff; diff_time(&diff, &t2, &t); print_image(scale, height*iy, width*ix); printf("Tiempo = %ld:%ld(seg:mseg)\n\n", diff.tv_sec, diff.tv_usec/1000 ); } MPI_Finalize(); //Clean UP for MPI exit(EXIT_SUCCESS); }
main () { int i,j,k; for (i=0; i < PICTURE_VERTICAL_SIZE; i++) { for (j=PICTURE_HORIZONTAL_OFFSET; j < PICTURE_HORIZONTAL_SIZE+PICTURE_HORIZONTAL_OFFSET; j++) { image_original[i][j-PICTURE_HORIZONTAL_OFFSET] = Y_test[i][j]; } } for (i=0; i < PICTURE_VERTICAL_SIZE; i++) { for (j=PICTURE_HORIZONTAL_OFFSET; j < PICTURE_HORIZONTAL_SIZE+PICTURE_HORIZONTAL_OFFSET; j++) { image_test[i][j-PICTURE_HORIZONTAL_OFFSET] = Y_test[i][j]; } } for (i=0; i < PICTURE_VERTICAL_SIZE; i++) { for (j=PICTURE_HORIZONTAL_OFFSET; j < PICTURE_HORIZONTAL_SIZE+PICTURE_HORIZONTAL_OFFSET; j++) { image_back[i][j-PICTURE_HORIZONTAL_OFFSET] = Y_back[i][j]; } } printf("Starting Motion Detection Application: \n\n"); printf("__attribute__((section(\".heapl2ram\"))) pixel Y_back[%d][%d] = \n{\n",PICTURE_VERTICAL_SIZE,PICTURE_HORIZONTAL_SIZE); print_image_vect((pixel*)image_back); printf("};\n"); printf("__attribute__((section(\".heapl2ram\"))) pixel Y_test[%d][%d] = \n{\n",PICTURE_VERTICAL_SIZE,PICTURE_HORIZONTAL_SIZE); print_image_vect((pixel*)image_test); printf("};\n"); printf("Subtraction and binarization treshold \n\n"); sub_image((pixel*)image_test, (pixel*)image_back); print_image((pixel*)image_test); max_pixel= max_image((pixel*)image_test); printf("Max pixel = %d \n\n",max_pixel); printf("Binarization \n\n"); binarisation((pixel*)image_test, (int)max_pixel*3/10,1,0); print_image((pixel*)image_test); printf("Erosion \n\n"); erosion((pixel*)image_test,KERNEL_SIZE,(pixel*)image_back); print_image((pixel*)image_back); printf("Dilatation \n\n"); dilatation((pixel*)image_back,KERNEL_SIZE ,(pixel*)image_test_out); print_image((pixel*)image_test_out); printf("Sobel Horizontal \n\n"); convolution_rect((pixel*)image_test_out, KERNEL_SIZE, sobel1,(pixel*)image_test); val_abs((pixel*)image_test); print_image((pixel*)image_test); printf("Sobel Vertical \n\n"); convolution_rect( (pixel*)image_test_out, KERNEL_SIZE, sobel2,(pixel*)image_back); val_abs((pixel*)image_back); print_image((pixel*)image_back); printf("Final Sum \n\n"); sum_image((pixel*)image_test, (pixel*)image_back); binarisation((pixel*)image_test, 1,0,1); print_image((pixel*)image_test); printf("Final Multiplication \n\n"); multiply((pixel*)image_test, (pixel*)image_original); printf("__attribute__((section(\".heapl2ram\"))) pixel Y_golden[%d][%d] = \n{\n",PICTURE_VERTICAL_SIZE,PICTURE_HORIZONTAL_SIZE); print_image_vect((pixel*)image_test); printf("};\n\n"); printf("Motion Detection Application Completed\n"); }
/* * Main test method */ static void test( void ) { int rc; char start_dir[MOUNT_DIR_SIZE + START_DIR_SIZE + 2]; rtems_dosfs_mount_options mount_opts[2]; rc = mkdir( MOUNT_DIR, S_IRWXU | S_IRWXG | S_IRWXO ); rtems_test_assert( rc == 0 ); snprintf( start_dir, sizeof( start_dir ), "%s/%s", MOUNT_DIR, "strt" ); /* * Tests with code page 850 compatible directory and file names * and the code page 850 backwards compatible default mode mode of the * FAT file system */ mount_device_with_defaults( start_dir ); test_creating_duplicate_directories( &start_dir[0], &DIRECTORY_DUPLICATES[0], NUMBER_OF_DIRECTORIES_DUPLICATED ); unmount_and_close_device(); mount_device_with_defaults( start_dir ); test_duplicated_files( MOUNT_DIR, FILES_DUPLICATES, NUMBER_OF_FILES_DUPLICATED ); unmount_and_close_device(); mount_device_with_defaults( start_dir ); test_creating_invalid_directories(); test_creating_directories( &start_dir[0], &DIRECTORY_NAMES[0][0], NUMBER_OF_DIRECTORIES ); test_handling_directories( &start_dir[0], &DIRECTORY_NAMES[0][0], NUMBER_OF_DIRECTORIES, &FILE_NAMES[0][0], NUMBER_OF_FILES ); compare_image( MOUNT_DIR, "/dev/rdb", NULL); rc = unmount( MOUNT_DIR ); rtems_test_assert( rc == 0 ); /* * Again tests with code page 850 compatible directory and file names * but with multibyte string compatible conversion methods which use * iconv and utf8proc */ mount_opts[0].converter = rtems_dosfs_create_utf8_converter( "CP850" ); rtems_test_assert( mount_opts[0].converter != NULL ); rc = mount( RAMDISK_PATH, MOUNT_DIR, "dosfs", RTEMS_FILESYSTEM_READ_WRITE, &mount_opts ); rtems_test_assert( rc == 0 ); test_finding_directories( &start_dir[0], &DIRECTORY_NAMES[0][0], NUMBER_OF_DIRECTORIES, &FILE_NAMES[0][0], NUMBER_OF_FILES ); unmount_and_close_device(); mount_device_with_iconv( start_dir, &mount_opts[0] ); test_creating_invalid_directories(); test_creating_duplicate_directories( &start_dir[0], &DIRECTORY_DUPLICATES[0], NUMBER_OF_DIRECTORIES_DUPLICATED ); unmount_and_close_device(); mount_device_with_iconv( start_dir, &mount_opts[0] ); test_duplicated_files( MOUNT_DIR, FILES_DUPLICATES, NUMBER_OF_FILES_DUPLICATED ); unmount_and_close_device(); mount_device_with_iconv( start_dir, &mount_opts[0] ); test_creating_directories( &start_dir[0], &DIRECTORY_NAMES[0][0], NUMBER_OF_DIRECTORIES ); test_handling_directories( &start_dir[0], &DIRECTORY_NAMES[0][0], NUMBER_OF_DIRECTORIES, &FILE_NAMES[0][0], NUMBER_OF_FILES ); mount_opts[1].converter = rtems_dosfs_create_utf8_converter( "CP850" ); rtems_test_assert( mount_opts[1].converter != NULL ); compare_image( MOUNT_DIR, "/dev/rdb", &mount_opts[1]); rc = unmount( MOUNT_DIR ); rtems_test_assert( rc == 0 ); print_image( "IMAGE_BIN_LE_SINGLEBYTE_H_", "IMAGE_BIN_LE_SINGLEBYTE"); rc = mount( RAMDISK_PATH, MOUNT_DIR, "dosfs", RTEMS_FILESYSTEM_READ_WRITE, NULL ); rtems_test_assert( rc == 0 ); unmount_and_close_device(); /* * Tests with multibyte directory and file names and * with multibyte string compatible conversion methods which use * iconv and utf8proc */ mount_device_with_iconv( start_dir, &mount_opts[0] ); test_creating_duplicate_directories( &start_dir[0], &MULTIBYTE_DUPLICATES[0], NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED ); unmount_and_close_device(); mount_device_with_iconv( start_dir, &mount_opts[0] ); test_duplicated_files( MOUNT_DIR, &MULTIBYTE_DUPLICATES[0], NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED ); unmount_and_close_device(); mount_device_with_iconv( start_dir, &mount_opts[0] ); test_creating_directories( &start_dir[0], &NAMES_MULTIBYTE[0][0], NUMBER_OF_NAMES_MULTIBYTE ); test_handling_directories( &start_dir[0], &NAMES_MULTIBYTE[0][0], NUMBER_OF_NAMES_MULTIBYTE, &NAMES_MULTIBYTE[0][0], NUMBER_OF_NAMES_MULTIBYTE ); mount_opts[1].converter = rtems_dosfs_create_utf8_converter( "CP850" ); rtems_test_assert( mount_opts[1].converter != NULL ); compare_image( MOUNT_DIR, "/dev/rdc", &mount_opts[1]); rc = unmount( MOUNT_DIR ); rtems_test_assert( rc == 0 ); print_image( "IMAGE_BIN_LE_MULTIBYTE_H_", "IMAGE_BIN_LE_MULTIBYTE"); rc = mount( RAMDISK_PATH, MOUNT_DIR, "dosfs", RTEMS_FILESYSTEM_READ_WRITE, NULL ); rtems_test_assert( rc == 0 ); test_finding_directories( &start_dir[0], &NAMES_MULTIBYTE_IN_CODEPAGE_FORMAT[0][0], NUMBER_OF_NAMES_MULTIBYTE, &NAMES_MULTIBYTE_IN_CODEPAGE_FORMAT[0][0], NUMBER_OF_NAMES_MULTIBYTE ); unmount_and_close_device(); test_compatibility(); }
/** Funcao que imprime o objetivo*/ void print_goal(ESTADO e){ print_image(e.goal.x, e.goal.y,TAM,GOAL); }
int main(int argc, char **argv) { int size, rank, i, j; int **result = NULL; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Status stat; // Primul thread citeste din fisier si trimite datele necesare // catre restul threadurilor if (rank == 0) { read_from_file(argv[1]); for (i = 1; i < size; i ++) { MPI_Send(&type, 1, MPI_INT, i, 1, MPI_COMM_WORLD); MPI_Send(&w, 1, MPI_INT, i, 1, MPI_COMM_WORLD); MPI_Send(&h, 1, MPI_INT, i, 1, MPI_COMM_WORLD); MPI_Send(&max_it, 1, MPI_INT, i, 1, MPI_COMM_WORLD); MPI_Send(&x_min, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD); MPI_Send(&x_max, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD); MPI_Send(&y_min, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD); MPI_Send(&y_max, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD); MPI_Send(&resolution, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD); if (type == 1) { MPI_Send(&cr, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD); MPI_Send(&ci, 1, MPI_DOUBLE, i, 1, MPI_COMM_WORLD); } } } else { // Fiecare thread va primi datele de intrare in ordinea in care au fost // trimise de threadul 0 MPI_Recv(&type, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); MPI_Recv(&w, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); MPI_Recv(&h, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); MPI_Recv(&max_it, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); MPI_Recv(&x_min, 1, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); MPI_Recv(&x_max, 1, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); MPI_Recv(&y_min, 1, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); MPI_Recv(&y_max, 1, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); MPI_Recv(&resolution, 1, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); if (type == 1) { MPI_Recv(&cr, 1, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); MPI_Recv(&ci, 1, MPI_DOUBLE, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &stat); } } split_task(rank, size); // ficare thread isi calculeaza portiunea din matrice // pe care o va completa int **timage = set_image_plane(width_thread, timage); result = set_image_plane(w, result); // matricea finala. if (type == 0){ timage = mondelbrot(max_it, timage, rank, size); } else julia(max_it ,timage, cr, ci, rank, size); int send = 0; if (rank != 0) { // fiecare thread ii trimitele threadului cu rank 0 matricea pe care // a calculat-o for (j = 0; j < width_thread; j++) MPI_Send(timage[j], h, MPI_INT, 0, 1, MPI_COMM_WORLD); } else { // daca sunt rank 0, copiez ce am calculat in matricea finala while (send < width_thread) { for (j = 0; j < h; j++) { result[send][j] = timage[send][j]; } send++; } // adaug in matricea finala ce primesc de la restul threadurilor result = receive_tasks(result, timage, size); } // dupa ce rank 0 a finalizat de completat matricea finala, afisez imaginea. MPI_Barrier(MPI_COMM_WORLD); if (rank == 0) print_image(argv[2], result); MPI_Finalize(); return 0; }
// MAIN int main(int argc, char ** argv){ printf("Lancement du programme Main...\n"); // CHOIX PERIPHERIQUE POUR LE ZIGBEE if(argc < 1){ printf("Please provide a dev name.\n"); return 0; } devname = argv[1]; // POUR POUVOIR FACILEMENT ENVOYER VERS LE COORDINATEUR uint8_t destRequest[8]; destRequest[0] = 0x00; destRequest[1] = 0x00; destRequest[2] = 0x00; destRequest[3] = 0x00; destRequest[4] = 0x00; destRequest[5] = 0x00; destRequest[6] = 0x00; destRequest[7] = 0x00; //CREATION D'UNE LISTE DE CAPTEUR listeCapteurs = initCaptorsList(); uint8_t question = 0x3F; // Pour pouvoir repondre a la demande '?' uint8_t numberCaptors = 0x01; // Nombre de capteurs // INITIALISATION D'UN UNIQUE CAPTEUR (A FAIRE POUR TOUS LES CAPTEURS) uint8_t id = ID_TEMPERATURE; // Type de capteur uint8_t unitData = 0x0C; // unite (ici en degre celsius) uint8_t dataSize = 0x02; // le nombre d'octets qui composent la donnee (ici 2) uint8_t minTemp[2]; // Valeurs min et max et leur affectation (on suppose dataSize = 0x02) uint8_t maxTemp[2]; minTemp[0] = 0x00; minTemp[1] = 0x00; maxTemp[0] = 0x00; maxTemp[1] = 0x40; uint8_t fpgaName[2]; // Nom du FPGA (ici "#1") fpgaName[0] = 0x23; fpgaName[1] = 0x31; addCaptor(listeCapteurs,ID_TEMPERATURE,dataSize,unitData,minTemp,maxTemp); //showCaptor(listeCapteurs->premier); // Pour afficher les differents champs du capteur // A FAIRE POUR TOUS LES AUTRES CAPTEURS //POUR AFFICHER UN TRUC SYMPA AU LANCEMENT DU PROGRAMME char *filename = "main/image2.txt"; FILE *fptr = NULL; if((fptr = fopen(filename,"r")) == NULL) { fprintf(stderr,"error opening %s\n",filename); return 1; } print_image(fptr); fclose(fptr); if(argc < 1){ printf("Please provide a dev name.\n"); return 0; } char * devname = argv[1]; printf("Lancement du programme DUMMYFPGA...\n"); int xbeeRNE = serial_init(devname,9600); int * xbeeRNEPointer = &xbeeRNE; int count = 0; int finish = 0; while(!finish){ printf("Count Value : %d", count); count++; struct TrameXbee * trameRetour = getTrame(xbeeRNEPointer); if(trameRetour){ afficherTrame(trameRetour); // // FIN DU PROGRAMME uint8_t idRetour = trameRetour->header.frameID; switch(idRetour){ case ID_NI :{ // ARRIVEE D'UN NOUVEAU FPGA DANS LE RESEAU, ON VA METTRE A JOUR LA TABLE // ICI ON NE SERA PAS DANS CE CAS LA break; } case ID_TX_STATUS :{ if (trameRetour->trameData[4] == 0x00){ printf("La trame a bien ete tranmise"); } break; } case ID_RX :{ uint8_t askCode = trameRetour->trameData[11]; switch(askCode){ case 0x3F :{ // REQUETE INFO CAPTEUR printf("On a reçu une requete de demande d'infos sur les capteurs !\n"); minTemp[0] = 0x00; minTemp[1] = 0x00; maxTemp[0] = 0x00; maxTemp[1] = 0x40; uint8_t testString [11*2 +1]; sprintf(&testString[0],"%02x",question); sprintf(&testString[2],"%02x",fpgaName[0]); sprintf(&testString[4],"%02x",fpgaName[1]); sprintf(&testString[6],"%02x",numberCaptors); sprintf(&testString[8],"%02x",id); sprintf(&testString[10],"%02x",dataSize); sprintf(&testString[12],"%02x",unitData); sprintf(&testString[14],"%02x",minTemp[0]); sprintf(&testString[16],"%02x",minTemp[1]); sprintf(&testString[18],"%02x",maxTemp[0]); sprintf(&testString[20],"%02x",maxTemp[1]); uint8_t bufferInfo[11]; convertZeroPadedHexIntoByte(testString,bufferInfo); struct TrameXbee * atToSend = computeATTrame(0x19, destRequest,bufferInfo); sendTrame(xbeeRNEPointer, atToSend); break; } case 0x2A :{ // REQUETE VALEUR CAPTEUR uint8_t capteurCode = trameRetour->trameData[12]; fprintf(stderr, "Voici le code reçu : %02x\n", capteurCode); switch(capteurCode){ case ID_TEMPERATURE :{ printf("On a recu une requête du maitre qui veut connaitre la temperature\n"); uint8_t valeur[2]; valeur[0] = 0x00; valeur[1] = 0x3F; uint8_t destRequest[8]; destRequest[0] = 0x00; destRequest[1] = 0x00; destRequest[2] = 0x00; destRequest[3] = 0x00; destRequest[4] = 0x00; destRequest[5] = 0x00; destRequest[6] = 0x00; destRequest[7] = 0x00; uint8_t testString [4*2 +1]; sprintf(&testString[0],"%02x",0x2A); sprintf(&testString[2],"%02x",capteurCode); sprintf(&testString[4],"%02x",valeur[0]); sprintf(&testString[6],"%02x",valeur[1]); uint8_t bufferInfo[4]; convertZeroPadedHexIntoByte(testString,bufferInfo); struct TrameXbee * atToSend = computeATTrame(0x12, destRequest ,bufferInfo); sendTrame(xbeeRNEPointer, atToSend); break; } case ID_LIGHT :{ printf("On a recu une requête du maitre qui veut connaitre la luminosite\n"); break; } case ID_GYRO :{ printf("On a recu une requête du maitre qui veut connaitre l'orientation\n"); break; } case ID_ANALOG :{ printf("On a recu une requête du maitre qui veut connaitre la valeur analogique\n"); break; } default : printf("ERREUR PAS DE CAPTEUR ICI...\n"); break; } break; } default: break; } break; } default : break; } } else { printf("Pas de trame reçu on recommence !\n"); } } printf("Fin Du Programme. Merci d'avoir participe au test!\n"); close(xbeeRNE); }
int OnObjectNotifyIBrowser(void *gw, int obj) { GEM_WINDOW *wnd = (GEM_WINDOW *) gw ; WBROWSER *wb = wnd->Extension ; CMD_BROWSER *wdlg = wnd->DlgData->UserData ; OBJECT *bobj = wnd->DlgData->BaseObject ; int i, off_x, off_y ; int code = -1 ; char buf[PATH_MAX] ; switch( obj ) { case IMGB_OPEN : if ( wb->base_path[0] ) sprintf( buf, "%s\\*.*", wb->base_path ) ; else sprintf( buf, "%s\\*.*", config.path_img ) ; if ( file_name( buf, "", buf ) == 1 ) { strcpy( wb->nom, buf ) ; DisplayImg( wnd, 0, 1 ) ; } deselect( bobj, obj ) ; update_nav( wnd ) ; break ; case IMGB_PREVIOUS : if ( wb->fimg_list ) { if ( wb->pos > 0 ) { wb->pos-- ; sprintf( wb->nom, "%s\\%s", wb->base_path, wb->fimg_list[wb->pos] ) ; DisplayImg( wnd, 0, 0 ) ; } } deselect( bobj, obj ) ; update_nav( wnd ) ; break ; case IMGB_NEXT : if ( wb->fimg_list ) { if ( wb->pos < wb->nb_files - 1 ) { wb->pos++ ; sprintf( wb->nom, "%s\\%s", wb->base_path, wb->fimg_list[wb->pos] ) ; DisplayImg( wnd, 0, 0 ) ; } } deselect( bobj, obj ) ; update_nav( wnd ) ; break ; case IMGB_SCALE : deselect( bobj, obj ) ; objc_offset( bobj, obj, &off_x, &off_y ) ; i = popup_formdo( &wdlg->popup_zoom, off_x, off_y, 1 + wb->pzoom_index, 0 ) ; if ( i > 0 ) { wb->pzoom_index = i - 1 ; write_text( bobj, obj, wdlg->popup_zoom[i].ob_spec.free_string ) ; if ( i > 1 ) sscanf( wdlg->popup_zoom[i].ob_spec.free_string, "%d%%", &wb->pczoom ) ; else wb->pczoom = -1 ; adapt_display( wnd ) ; } break ; case IMGB_EDIT : deselect( bobj, obj ) ; if ( wb->fimg_list ) new_edit_vximage( wb ) ; xobjc_draw( wnd->window_handle, bobj, obj ) ; break ; case IMGB_DELETE : deselect( bobj, obj ) ; if ( wb->fimg_list ) { if ( form_interrogation( 2, msg[MSG_CONFIRMDEL] ) == 1 ) { if ( Fdelete( wb-> nom ) ) form_stop( 1, msg[MSG_WRITEERROR] ) ; } } xobjc_draw( wnd->window_handle, bobj, obj ) ; break ; case IMGB_PRINT : deselect( bobj, obj ) ; switch( print_image( &wb->raster, &wb->inf_img ) ) { case PNOGDOS : form_stop(1, msg[MSG_PNOGDOS]) ; break ; case PTIMEOUT : form_stop(1, msg[MSG_PTIMEOUT]) ; break ; case PWRITERR : form_stop(1, msg[MSG_PWRITERR]) ; break ; case PNOHANDLE : form_stop(1, msg[MSG_PNOHANDLE]) ; break ; case PROTERR : form_error(8) ; break ; case PNODRIVER : form_stop(1, msg[MSG_PNODRIVER]) ; break ; } xobjc_draw( wnd->window_handle, bobj, obj ) ; break ; } return( code ) ; }
/* * Composite operation with pseudorandom images */ uint32_t test_composite (int testnum, int verbose) { pixman_image_t *src_img = NULL; pixman_image_t *dst_img = NULL; pixman_image_t *mask_img = NULL; int src_width, src_height; int dst_width, dst_height; int src_stride, dst_stride; int src_x, src_y; int dst_x, dst_y; int mask_x, mask_y; int w, h; pixman_op_t op; pixman_format_code_t src_fmt, dst_fmt, mask_fmt; uint32_t *srcbuf, *maskbuf; uint32_t crc32; int max_width, max_height, max_extra_stride; FLOAT_REGS_CORRUPTION_DETECTOR_START (); max_width = max_height = 24 + testnum / 10000; max_extra_stride = 4 + testnum / 1000000; if (max_width > 256) max_width = 256; if (max_height > 16) max_height = 16; if (max_extra_stride > 8) max_extra_stride = 8; prng_srand (testnum); op = op_list[prng_rand_n (ARRAY_LENGTH (op_list))]; if (prng_rand_n (8)) { /* normal image */ src_img = create_random_image (img_fmt_list, max_width, max_height, max_extra_stride, &src_fmt); } else { /* solid case */ src_img = create_random_image (img_fmt_list, 1, 1, max_extra_stride, &src_fmt); pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL); } dst_img = create_random_image (img_fmt_list, max_width, max_height, max_extra_stride, &dst_fmt); src_width = pixman_image_get_width (src_img); src_height = pixman_image_get_height (src_img); src_stride = pixman_image_get_stride (src_img); dst_width = pixman_image_get_width (dst_img); dst_height = pixman_image_get_height (dst_img); dst_stride = pixman_image_get_stride (dst_img); srcbuf = pixman_image_get_data (src_img); src_x = prng_rand_n (src_width); src_y = prng_rand_n (src_height); dst_x = prng_rand_n (dst_width); dst_y = prng_rand_n (dst_height); mask_img = NULL; mask_fmt = PIXMAN_null; mask_x = 0; mask_y = 0; maskbuf = NULL; if ((src_fmt == PIXMAN_x8r8g8b8 || src_fmt == PIXMAN_x8b8g8r8) && (prng_rand_n (4) == 0)) { /* PIXBUF */ mask_fmt = prng_rand_n (2) ? PIXMAN_a8r8g8b8 : PIXMAN_a8b8g8r8; mask_img = pixman_image_create_bits (mask_fmt, src_width, src_height, srcbuf, src_stride); mask_x = src_x; mask_y = src_y; maskbuf = srcbuf; } else if (prng_rand_n (2)) { if (prng_rand_n (2)) { mask_img = create_random_image (mask_fmt_list, max_width, max_height, max_extra_stride, &mask_fmt); } else { /* solid case */ mask_img = create_random_image (mask_fmt_list, 1, 1, max_extra_stride, &mask_fmt); pixman_image_set_repeat (mask_img, PIXMAN_REPEAT_NORMAL); } if (prng_rand_n (2)) pixman_image_set_component_alpha (mask_img, 1); mask_x = prng_rand_n (pixman_image_get_width (mask_img)); mask_y = prng_rand_n (pixman_image_get_height (mask_img)); } w = prng_rand_n (dst_width - dst_x + 1); h = prng_rand_n (dst_height - dst_y + 1); if (verbose) { printf ("op=%s\n", operator_name (op)); printf ("src_fmt=%s, dst_fmt=%s, mask_fmt=%s\n", format_name (src_fmt), format_name (dst_fmt), format_name (mask_fmt)); printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n", src_width, src_height, dst_width, dst_height); printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n", src_x, src_y, dst_x, dst_y); printf ("src_stride=%d, dst_stride=%d\n", src_stride, dst_stride); printf ("w=%d, h=%d\n", w, h); } pixman_image_composite (op, src_img, mask_img, dst_img, src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h); if (verbose) print_image (dst_img); free_random_image (0, src_img, PIXMAN_null); crc32 = free_random_image (0, dst_img, dst_fmt); if (mask_img) { if (srcbuf == maskbuf) pixman_image_unref(mask_img); else free_random_image (0, mask_img, PIXMAN_null); } FLOAT_REGS_CORRUPTION_DETECTOR_FINISH (); return crc32; }
int main() { int i, j, m, n; // gaussian low pass filter const float gaussFloat[SIZE][SIZE] = { {0.1019, 0.1154, 0.1019}, {0.1154, 0.1308, 0.1154}, {0.1019, 0.1154, 0.1019} }; int gauss[SIZE][SIZE]; for (m = 0; m < SIZE; m++) { for (n = 0; n < SIZE; n++) { gauss[m][n] = gaussFloat[m][n] * int2fixed(1); } } /* const float gauss[SIZE][SIZE] = { {1, 2, 1}, {2, 5, 2}, {1, 2, 1}, }; */ unsigned char blur[width-2][height-2]; int count = 0; /* * Non-striped memory version for (j = 0; j < height-2; j++) { for (i = 0; i < width-2; i++) { #ifdef FLOAT float sumFloat = 0; #endif int sum = 0; for (m = 0; m < SIZE; m++) { for (n = 0; n < SIZE; n++) { #ifdef FLOAT sumFloat += gaussFloat[m][n]*img[i+m][j+n]; #endif sum += fixedmul(gauss[m][n], int2fixed(img[i+m][j+n])); } } blur[i][j] = fixed2int(sum); count += blur[i][j]; //blur[i+1][j+1] = sum/17; #ifdef FLOAT float diff = fabs((float)blur[i][j]-sumFloat); assert (diff < 1.2); printf("fixed: %d expected: %f diff: %f\n", blur[i][j], sumFloat, diff); #endif } } */ int order = 0; int j_stride = 0; for (j = 0; j < height-2; j++) { // im00 im10 im20 // im01 im11 im21 // im02 im12 im22 unsigned char im00, im01, im02, im10, im11, im12, im20, im21, im22; unsigned char tmp00, tmp10, tmp01, tmp11, tmp20, tmp21; i = 0; int j1, j2, j3; if (order == 0) { j1 = j2 = j3 = j_stride; } else if (order == 1) { j2 = j3 = j_stride; j1 = j_stride+1; } else { j3 = j_stride; j1 = j2 = j_stride+1; } im00 = img1[i][j1]; im10 = img1[i+1][j1]; //assert(img[i][j]==im00); im01 = img2[i][j2]; im11 = img2[i+1][j2]; im02 = img3[i][j3]; im12 = img3[i+1][j3]; if (order == 0) { } else if (order == 1) { tmp00 = im00; tmp10 = im10; // first row from img2 im00 = im01; im10 = im11; // second row from img3 im01 = im02; im11 = im12; // third row from img1 im02 = tmp00; im12 = tmp10; } else { tmp00 = im00; tmp10 = im10; tmp01 = im01; tmp11 = im11; // first row from img3 im00 = im02; im10 = im12; // second row from img1 im01 = tmp00; im11 = tmp10; // third row from img2 im02 = tmp01; im12 = tmp11; } for (i = 0; i < width-2; i++) { im20 = img1[i+2][j1]; im21 = img2[i+2][j2]; im22 = img3[i+2][j3]; int pred1 = (order == 1); tmp20 = im20; // first row from img2 im20 = (pred1) ? im21 : im20; // second row from img3 im21 = (pred1) ? im22: im21; // third row from img1 im22 = (pred1) ? tmp20: im22; tmp20 = im20; tmp21 = im21; int pred2 = (order == 2); // first row from img3 im20 = (pred2) ? im22 : im20; // second row from img1 im21 = (pred2) ? tmp20 : im21; // third row from img2 im22 = (pred2) ? tmp21 : im22; int sum = 0; //assert(img[i][j]==im00); sum += fixedmul(gauss[0][0], int2fixed(im00)); sum += fixedmul(gauss[0][1], int2fixed(im01)); sum += fixedmul(gauss[0][2], int2fixed(im02)); sum += fixedmul(gauss[1][0], int2fixed(im10)); sum += fixedmul(gauss[1][1], int2fixed(im11)); sum += fixedmul(gauss[1][2], int2fixed(im12)); sum += fixedmul(gauss[2][0], int2fixed(im20)); sum += fixedmul(gauss[2][1], int2fixed(im21)); sum += fixedmul(gauss[2][2], int2fixed(im22)); blur[i][j] = fixed2int(sum); //blur[i+1][j+1] = sum/17; count += blur[i][j]; #ifdef FLOAT float sumFloat = 0; for (m = 0; m < SIZE; m++) { for (n = 0; n < SIZE; n++) { sumFloat += gaussFloat[m][n]*img[i+m][j+n]; } } float diff = fabs((float)blur[i][j]-sumFloat); assert (diff < 1.2); printf("fixed: %d expected: %f diff: %f\n", blur[i][j], sumFloat, diff); #endif // shift over to the right by 1 im00 = im10; im10 = im20; im01 = im11; im11 = im21; im02 = im12; im12 = im22; } if (order == 2) { order = 0; j_stride++; } else { order++; } } #ifdef PRINT_IMG //print_image(width, height, 255, img); print_image(width-2, height-2, 255, blur); #else printf("count: %d\n", count); if (count == 1931186) { printf(" _____ _____ _____ ______ _____ \n"); printf("| __ \\ /\\ / ____/ ____| ____| __ \\ \n"); printf("| |__) / \\ | (___| (___ | |__ | | | |\n"); printf("| ___/ /\\ \\ \\___ \\\\___ \\| __| | | | |\n"); printf("| | / ____ \\ ____) |___) | |____| |__| |\n"); printf("|_| /_/ \\_\\_____/_____/|______|_____/ \n"); } else { printf(" ______ _____ _ ______ _____ \n"); printf("| ____/\\ |_ _| | | ____| __ \\ \n"); printf("| |__ / \\ | | | | | |__ | | | |\n"); printf("| __/ /\\ \\ | | | | | __| | | | |\n"); printf("| | / ____ \\ _| |_| |____| |____| |__| |\n"); printf("|_|/_/ \\_\\_____|______|______|_____/ \n"); } #endif return count; }
/* * Composite operation with pseudorandom images */ uint32_t test_composite (int testnum, int verbose) { int i; pixman_image_t * src_img; pixman_image_t * dst_img; pixman_region16_t clip; int dst_width, dst_height; int dst_stride; int dst_x, dst_y; int dst_bpp; pixman_op_t op; uint32_t * dst_bits; uint32_t crc32; pixman_format_code_t mask_format, dst_format; pixman_trapezoid_t *traps; int src_x, src_y; int n_traps; static pixman_color_t colors[] = { { 0xffff, 0xffff, 0xffff, 0xffff }, { 0x0000, 0x0000, 0x0000, 0x0000 }, { 0xabcd, 0xabcd, 0x0000, 0xabcd }, { 0x0000, 0x0000, 0x0000, 0xffff }, { 0x0101, 0x0101, 0x0101, 0x0101 }, { 0x7777, 0x6666, 0x5555, 0x9999 }, }; FLOAT_REGS_CORRUPTION_DETECTOR_START (); prng_srand (testnum); op = RANDOM_ELT (operators); mask_format = RANDOM_ELT (mask_formats); /* Create source image */ if (prng_rand_n (4) == 0) { src_img = pixman_image_create_solid_fill ( &(colors[prng_rand_n (ARRAY_LENGTH (colors))])); src_x = 10; src_y = 234; } else { pixman_format_code_t src_format = RANDOM_ELT(formats); int src_bpp = (PIXMAN_FORMAT_BPP (src_format) + 7) / 8; int src_width = prng_rand_n (MAX_SRC_WIDTH) + 1; int src_height = prng_rand_n (MAX_SRC_HEIGHT) + 1; int src_stride = src_width * src_bpp + prng_rand_n (MAX_STRIDE) * src_bpp; uint32_t *bits, *orig; src_x = -(src_width / 4) + prng_rand_n (src_width * 3 / 2); src_y = -(src_height / 4) + prng_rand_n (src_height * 3 / 2); src_stride = (src_stride + 3) & ~3; orig = bits = (uint32_t *)make_random_bytes (src_stride * src_height); if (prng_rand_n (2) == 0) { bits += (src_stride / 4) * (src_height - 1); src_stride = - src_stride; } src_img = pixman_image_create_bits ( src_format, src_width, src_height, bits, src_stride); pixman_image_set_destroy_function (src_img, destroy_bits, orig); if (prng_rand_n (8) == 0) { pixman_box16_t clip_boxes[2]; int n = prng_rand_n (2) + 1; for (i = 0; i < n; i++) { clip_boxes[i].x1 = prng_rand_n (src_width); clip_boxes[i].y1 = prng_rand_n (src_height); clip_boxes[i].x2 = clip_boxes[i].x1 + prng_rand_n (src_width - clip_boxes[i].x1); clip_boxes[i].y2 = clip_boxes[i].y1 + prng_rand_n (src_height - clip_boxes[i].y1); if (verbose) { printf ("source clip box: [%d,%d-%d,%d]\n", clip_boxes[i].x1, clip_boxes[i].y1, clip_boxes[i].x2, clip_boxes[i].y2); } } pixman_region_init_rects (&clip, clip_boxes, n); pixman_image_set_clip_region (src_img, &clip); pixman_image_set_source_clipping (src_img, 1); pixman_region_fini (&clip); } image_endian_swap (src_img); } /* Create destination image */ { dst_format = RANDOM_ELT(formats); dst_bpp = (PIXMAN_FORMAT_BPP (dst_format) + 7) / 8; dst_width = prng_rand_n (MAX_DST_WIDTH) + 1; dst_height = prng_rand_n (MAX_DST_HEIGHT) + 1; dst_stride = dst_width * dst_bpp + prng_rand_n (MAX_STRIDE) * dst_bpp; dst_stride = (dst_stride + 3) & ~3; dst_bits = (uint32_t *)make_random_bytes (dst_stride * dst_height); if (prng_rand_n (2) == 0) { dst_bits += (dst_stride / 4) * (dst_height - 1); dst_stride = - dst_stride; } dst_x = -(dst_width / 4) + prng_rand_n (dst_width * 3 / 2); dst_y = -(dst_height / 4) + prng_rand_n (dst_height * 3 / 2); dst_img = pixman_image_create_bits ( dst_format, dst_width, dst_height, dst_bits, dst_stride); image_endian_swap (dst_img); } /* Create traps */ { int i; n_traps = prng_rand_n (25); traps = fence_malloc (n_traps * sizeof (pixman_trapezoid_t)); for (i = 0; i < n_traps; ++i) { pixman_trapezoid_t *t = &(traps[i]); t->top = random_fixed (MAX_DST_HEIGHT) - MAX_DST_HEIGHT / 2; t->bottom = t->top + random_fixed (MAX_DST_HEIGHT); t->left.p1.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2; t->left.p1.y = t->top - random_fixed (50); t->left.p2.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2; t->left.p2.y = t->bottom + random_fixed (50); t->right.p1.x = t->left.p1.x + random_fixed (MAX_DST_WIDTH); t->right.p1.y = t->top - random_fixed (50); t->right.p2.x = t->left.p2.x + random_fixed (MAX_DST_WIDTH); t->right.p2.y = t->bottom - random_fixed (50); } } if (prng_rand_n (8) == 0) { pixman_box16_t clip_boxes[2]; int n = prng_rand_n (2) + 1; for (i = 0; i < n; i++) { clip_boxes[i].x1 = prng_rand_n (dst_width); clip_boxes[i].y1 = prng_rand_n (dst_height); clip_boxes[i].x2 = clip_boxes[i].x1 + prng_rand_n (dst_width - clip_boxes[i].x1); clip_boxes[i].y2 = clip_boxes[i].y1 + prng_rand_n (dst_height - clip_boxes[i].y1); if (verbose) { printf ("destination clip box: [%d,%d-%d,%d]\n", clip_boxes[i].x1, clip_boxes[i].y1, clip_boxes[i].x2, clip_boxes[i].y2); } } pixman_region_init_rects (&clip, clip_boxes, n); pixman_image_set_clip_region (dst_img, &clip); pixman_region_fini (&clip); } pixman_composite_trapezoids (op, src_img, dst_img, mask_format, src_x, src_y, dst_x, dst_y, n_traps, traps); crc32 = compute_crc32_for_image (0, dst_img); if (verbose) print_image (dst_img); if (dst_stride < 0) dst_bits += (dst_stride / 4) * (dst_height - 1); fence_free (dst_bits); pixman_image_unref (src_img); pixman_image_unref (dst_img); fence_free (traps); FLOAT_REGS_CORRUPTION_DETECTOR_FINISH (); return crc32; }
/** Funcao que imprime os obstaculos*/ void print_walls(ESTADO e) { int i; for(i = 0; i < e.num_obstaculos; i++) print_image(e.obstaculo[i].x, e.obstaculo[i].y, TAM,WALL); }
static void mainloop (void) { int i,j; unsigned char processedPixels[FRAME_HEIGHT][FRAME_WIDTH]; for (;;) { fd_set fds; struct timeval tv; int r; FD_ZERO (&fds); FD_SET (fd, &fds); /* Timeout. */ tv.tv_sec = 2; tv.tv_usec = 0; r = select (fd + 1, &fds, NULL, NULL, &tv); if (-1 == r) { if (EINTR == errno) continue; errno_exit ("select"); } if (0 == r) { fprintf (stderr, "select timeout\n"); exit (EXIT_FAILURE); } if (read_frame ()) { // process the video process_video(pixels, processedPixels); // convert grayscale processed pixels to an RGB format convert_grayscale_to_rgb(pixels, processedPixels,FRAME_WIDTH, FRAME_HEIGHT); // process blobs int labels[FRAME_HEIGHT][FRAME_WIDTH]; for(i = 0; i < FRAME_HEIGHT; i++) { for(j = 0; j < FRAME_WIDTH; j++) { labels[i][j] = -1; } } int numBlobs = two_pass(processedPixels, labels, FRAME_WIDTH, FRAME_HEIGHT); blob blobs[MAX_BLOBS]; extract_blobs(blobs, numBlobs, labels, FRAME_WIDTH, FRAME_HEIGHT); // remove too small/big blobs numBlobs = apply_blob_size_heuristic(blobs, numBlobs); // get all center points for blobs coord centerCoords[MAX_BLOBS];// = (coord*)malloc(sizeof(coord) * numBlobs); get_blob_centers(blobs, numBlobs, centerCoords); collinear points[MAX_BLOBS]; int shortSegments = get_more_straight_sides(centerCoords, numBlobs, points); coord shapeCoords[5]; int shapeFound = 0; for(i = 0; i < shortSegments; i++) { coord p1 = points[i].point1; coord p2 = points[i].point2; coord p3 = points[i].point3; double m1 = fabs(distance(p1, p2)); double m2 = fabs(distance(p2, p3)); double m3 = fabs(distance(p1, p3)); if(is_long_side(points[i])) { collinear shortSide; int shortSideFound = get_short_side(centerCoords, numBlobs, points[i], &shortSide); if(shortSideFound) { draw_collinear(pixels, shortSide); draw_collinear(pixels, points[i]); /*print_point(p1); print_point(p2); print_point(p3); */ //printf(" -------------------- SHORT SIDE \n"); /* print_point(shortSide.point1); print_point(shortSide.point2); print_point(shortSide.point3);*/ printf("\n"); shapeCoords[0] = p1; shapeCoords[1] = p2; shapeCoords[2] = p3; shapeCoords[3] = shortSide.point1; shapeCoords[4] = shortSide.point3; shapeFound = 1; break; } } else if(is_short_side(points[i])) { collinear longSide; int longSideFound = get_long_side(centerCoords, numBlobs, points[i], &longSide); if(longSideFound) { draw_collinear(pixels, longSide); draw_collinear(pixels, points[i]); /* print_point(p1); print_point(p2); print_point(p3); */ //printf(" ======================== LONG SIDE\n"); /* print_point(longSide.point1); print_point(longSide.point2); print_point(longSide.point3); */ printf("\n"); shapeCoords[0] = p1; shapeCoords[1] = p2; shapeCoords[2] = p3; shapeCoords[3] = longSide.point1; shapeCoords[4] = longSide.point3; shapeFound = 1; break; } } } if(shapeFound) { int imageCenterX = FRAME_WIDTH / 2; int imageCenterY = FRAME_HEIGHT / 2; coord center; center.x = imageCenterX; center.y = imageCenterY; double distance = distance_from_center(shapeCoords[1]); double angle = quadrant_angle(shapeCoords[1]); if(distance > 100) { printf("MOVE TOWARDS CENTER :: ANGLE : %f :: DISTANCE : %f(pixels)\n", angle, distance); //print_direction(angle); } else { printf("MOVE DOWN HEIGHT : ?\n"); } print_image(centerCoords, numBlobs, shapeCoords, 5); } free_blobs(blobs, numBlobs); frame = create_cam_img(pixels, FRAME_WIDTH, FRAME_HEIGHT); apply_surface(0, 0, frame, screen); SDL_Flip(screen); } } }
bool compare(const char *name, const char *ext, const uint8_t *image_data, uint32_t image_data_stride, uint32_t image_width, uint32_t image_height, const char *image_error_message, const uint8_t *rgba_data, unsigned long rgba_data_length, bool info_only, uint8_t fuzziness, bool verbose) { double p_identical; int peak_diff; bool success = false; if (info_only) { if (rgba_data_length > 0 && image_width * image_height * 4 != rgba_data_length) { printf("Failure: Incorrect dimensions for %s.%s " "(%u x %u - data length should be %lu but is %u)\n", name, ext, image_width, image_height, rgba_data_length, (image_width * image_height * 4)); } else if (image_data != NULL) { printf("Failure: Data incorrectly loaded for %s.%s \n", name, ext); } else { if (verbose) { printf("File: %16.16s.%s (Info only: %u x %u)\n", name, ext, image_width, image_height); } success = true; } } else if (!image_data && (!rgba_data || rgba_data_length == 0)) { if (verbose) { printf("File: %16.16s.%s (invalid file correctly detected).\n", name, ext); } success = true; } else if (!image_data) { printf("Failure: Couldn't load %s.%s. %s\n", name, ext, image_error_message); } else if (!rgba_data) { printf("Warning: Couldn't load %s.rgba. Possibly invalid file.\n", name); success = true; } else if (image_width * image_height * 4 != rgba_data_length) { printf("Failure: Incorrect dimensions for %s.%s " "(%u x %u - data length should be %lu but is %u)\n", name, ext, image_width, image_height, rgba_data_length, (image_width * image_height * 4)); } else if (!fuzzy_memcmp(image_data, rgba_data, image_data_stride, image_width * 4, image_width * 4, image_height, fuzziness, &p_identical, &peak_diff)) { if (fuzziness > 0) { printf("Failure: Data is different for image %s.%s (%f%% diff<=1, peak diff=%i)\n", name, ext, (p_identical * 100.0), peak_diff); } else { printf("Failure: Data is different for image %s.%s\n", name, ext); } if (verbose) { printf("raw:\n"); print_image(rgba_data, image_width, image_height); printf("as decoded:\n"); print_image(image_data, image_width, image_height); uint8_t *diff_data = malloc(rgba_data_length); for (unsigned long i = 0; i < rgba_data_length; i++) { diff_data[i] = (uint8_t)abs(rgba_data[i] - image_data[i]); } printf("diff:\n"); print_image_diff(diff_data, image_width, image_height); free(diff_data); } } else if (fuzziness > 0) { if (verbose) { printf("File: %16.16s.%s (%9.5f%% diff<=1, peak diff=%i)\n", name, ext, (p_identical * 100.0), peak_diff); } success = true; } else { if (verbose) { printf("File: %16.16s.%s\n", name, ext); } success = true; } return success; }