/* generate and save the entire fractal returns: 0 if successful 1 otherwise */ int generate_fractal(char *file, float width, float height, int workers) { /* TODO: use fork(), mmap(), and munmap() to create a region of shared memory to store fractal data, as generated by several child processes */ int fd = open(file,O_RDONLY); color_t *fractal_data = mmap(NULL,sizeof(color_t)*height*width,PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_SHARED,fd,0); int i,status; int pids[workers]; for(i = 0; i < workers; i++) { if((pids[i]=fork())==0) { generate_fractal_region(fractal_data, width, height, i*(height/workers), (height/workers)); munmap(fractal_data,sizeof(color_t)*height*width); exit(0); } } for(i = 0; i < workers; i++) { waitpid(pids[i],&status,0); } if (save_image_data(file, fractal_data, width, height)) { fprintf(stderr, "error saving to image file.\n"); free(fractal_data); return 1; } munmap(fractal_data,sizeof(color_t)*height*width); printf("Complete.\n"); return 0; }
main( ) { load_image_data( ); /* Input of image1 */ sobel_filtering( ); /* Sobel filter is applied to image1 */ save_image_data( ); /* Output of image2 */ return 0; }
main( ) { load_image_data( ); /* 画像データを image1 に読み込む */ make_inverse_image( ); /* image1 を反転させ image2 へ */ save_image_data( ); /* image2 を保存する */ return 0; }
main( ) { load_image_data( ); /* 画像データを image1 に読み込む */ make_sampling_image( ); /* image1 を標本化させ image2 へ */ save_image_data( ); /* image2 を保存する */ return 0; }
/* generate and save the entire fractal returns: 0 if successful 1 otherwise */ int generate_fractal(char *file, float width, float height, int workers) { color_t *fractal_data = malloc(sizeof(color_t)*width*height); /* generate data for the entire fractal */ generate_fractal_region(fractal_data, width, height, 0, height); /* save the generated fractal data into the file specified by argv[1] */ if (save_image_data(file, fractal_data, width, height)) { fprintf(stderr, "error saving to image file.\n"); free(fractal_data); return 1; } free(fractal_data); printf("Complete \n"); return 0; }
size_t map_io::map_save(const char* map_file,map_context* context) { if ( !context ) { return MAP_STATUS_INVALID_CONTEXT; } FILE* fptr = fopen(map_file,"rb+"); if ( !fptr ) { // 文件不存在时,需要创建文件 fptr = fopen(map_file,"wb+"); if ( !fptr ) { return MAP_STATUS_FILE_NOT_FOUND; } } size_t ret = 0; do { if ( context->type == MAP_CONTEXT_PSD ) { context->terrain.image_data_offset = sizeof(map_header); // 地图图片信息之后紧跟遮挡物件图片信息 context->mask_data_offset = context->terrain.image_data_offset + context->terrain.image_data_size; //map_terrain::image_data multiple ret = save_image_data(fptr,context); //if(ret == 0) break; //map_mask::mask_data multiple ret = save_mask_image_data(fptr,context); //if(ret == 0) break; context->header.block_offset = context->mask_data_offset + context->mask_data_size; } //blocks ret = save_map_blocks(fptr,context); //if(ret == 0) break; // header ret = save_map_header(fptr,context); //if(ret == 0) break; } while(0); fflush(fptr); fclose(fptr); return MAP_STATUS_OK; }