static void rsvg_destroy(struct content *c) { rsvg_content *d = (rsvg_content *) c; if (d->bitmap != NULL) bitmap_destroy(d->bitmap); if (d->rsvgh != NULL) g_object_unref(d->rsvgh); if (d->ct != NULL) cairo_destroy(d->ct); if (d->cs != NULL) cairo_surface_destroy(d->cs); return; }
int gr_lock_screen() { if ( screen_locked ) return 1 ; screen_locked = 1 ; if ( scale_resolution != -1 ) { if ( SDL_MUSTLOCK( scale_screen ) ) SDL_LockSurface( scale_screen ) ; } else { if ( SDL_MUSTLOCK( screen ) ) SDL_LockSurface( screen ) ; } if ( enable_scale || scale_mode != SCALE_NONE ) { if ( scrbitmap && ( scrbitmap->info_flags & GI_EXTERNAL_DATA ) ) { bitmap_destroy( scrbitmap ) ; scrbitmap = NULL ; } if ( !scrbitmap ) { scrbitmap = bitmap_new( 0, screen->w / 2, screen->h / 2, sys_pixel_format->depth ) ; bitmap_add_cpoint( scrbitmap, 0, 0 ) ; } } else { if ( !scrbitmap || !( scrbitmap->info_flags & GI_EXTERNAL_DATA ) ) { if ( scrbitmap ) bitmap_destroy( scrbitmap ) ; scrbitmap = bitmap_new_ex( 0, screen->w, screen->h, screen->format->BitsPerPixel, screen->pixels, screen->pitch ); bitmap_add_cpoint( scrbitmap, 0, 0 ) ; } } return 1 ; }
int gr_load_pal( const char * filename ) { if ( !filename ) return 0; file * fp = file_open( filename, "rb" ) ; char header[8] ; PALETTE * r = NULL ; PALETTE * old_sys_pal = sys_pixel_format->palette ; if ( !fp ) return 0 ; file_read( fp, header, 8 ) ; if ( !strcmp( header, MAP_MAGIC ) ) { file_seek( fp, 48, SEEK_SET ) ; r = gr_read_pal_with_gamma( fp ) ; } else if ( !strcmp( header, FPG_MAGIC ) || !strcmp( header, FNT_MAGIC ) || !strcmp( header, PAL_MAGIC ) ) { r = gr_read_pal_with_gamma( fp ) ; } else if ( memcmp( header, "\x89PNG", 4 ) == 0 ) { GRAPH * graph ; file_close( fp ); fp = NULL; graph = gr_read_png( filename ); if ( graph ) { r = pal_new( graph->format->palette ); bitmap_destroy( graph ); } } if ( r ) { // pal_use( r ); if ( old_sys_pal ) { pal_destroy( old_sys_pal ); sys_pixel_format->palette = pal_new( r ); /* pal_use( sys_pixel_format->palette ); */ palette_changed = 1 ; } } if ( fp ) file_close( fp ) ; return ( int ) r; }
void testfs_close_super_block(struct super_block *sb) { testfs_write_super_block(sb); inode_hash_destroy(); if (sb->inode_freemap) { write_blocks(sb, bitmap_getdata(sb->inode_freemap), sb->sb.inode_freemap_start, INODE_FREEMAP_SIZE); bitmap_destroy(sb->inode_freemap); sb->inode_freemap = NULL; } if (sb->block_freemap) { write_blocks(sb, bitmap_getdata(sb->block_freemap), sb->sb.block_freemap_start, BLOCK_FREEMAP_SIZE); bitmap_destroy(sb->block_freemap); sb->block_freemap = NULL; } fflush(sb->dev); fclose(sb->dev); sb->dev = NULL; free(sb); }
static int sfs_unmount(struct fs *fs) { struct sfs_fs *sfs = fsop_info(fs, sfs); if (!list_empty(&(sfs->inode_list))) { return -E_BUSY; } assert(!sfs->super_dirty); bitmap_destroy(sfs->freemap); kfree(sfs->sfs_buffer); kfree(sfs->hash_list); kfree(sfs); return 0; }
void block_store_destroy(block_store_t *const bs, const bs_flush_flag flush) { if (bs) { // If we aren't linked, no problem // If we ARE, flush if they asked AND unlink block_store_unlink(bs, flush); bitmap_destroy(bs->fbm); bitmap_destroy(bs->dbm); free(bs->data_blocks); free(bs); if (!flush) { // flush result takes priority of our standard OK // I'd just put this up at the unlink but // I really prefer setting the errno before the return // to make sure it's always "correct" bs_errno = BS_OK; // Haha, is it really ok if we just deleted it? } return; } bs_errno = BS_PARAM; }
/* * PURPOSE: imports block store * INPUTS: char, filename * RETURN: block_store_t **/ block_store_t *block_store_import(const char *const filename) { block_store_t *bs = block_store_create(); //create blockstore bs if(bs){ bitmap_destroy(bs -> fbm); //destroy fbm in bs bitmap_format(bs -> dbm, 0); //format dbm in bs struct stat file_info; // size_t urf = 0; if(stat(filename, &file_info) != -1){ if(file_info.st_size == BLOCK_SIZE * BLOCK_COUNT){ int fd; fd = open(filename, O_RDONLY); if(fd != -1){ size_t ct = FBM_SIZE * BLOCK_SIZE; urf = utility_read_file(fd, bs -> data_blocks, ct); if (urf) { bs -> fbm = bitmap_import(BLOCK_COUNT, bs -> data_blocks); if (bs -> fbm) { ct = (BLOCK_COUNT - FBM_SIZE) * BLOCK_SIZE; urf = utility_read_file(fd, bs -> data_blocks, ct); if (urf) { block_store_errno = BS_OK; close(fd); }return 0; } } } } } } // struct stat { // dev_t st_dev; /* ID of device containing file */ // ino_t st_ino; /* inode number */ // mode_t st_mode; /* protection */ // nlink_t st_nlink; /* number of hard links */ // uid_t st_uid; /* user ID of owner */ // gid_t st_gid; /* group ID of owner */ // dev_t st_rdev; /* device ID (if special file) */ // off_t st_size; /* total size, in bytes */ // blksize_t st_blksize; /* blocksize for filesystem I/O */ // blkcnt_t st_blocks; /* number of 512B blocks allocated */ block_store_errno = BS_FATAL; return NULL; }
void font_reset_one_glyph(DviDevice *dev, DviFontChar *ch, int what) { if(!glyph_present(ch)) return; if(what & MDVI_FONTSEL_BITMAP) { if(MDVI_GLYPH_NONEMPTY(ch->shrunk.data)) bitmap_destroy((BITMAP *)ch->shrunk.data); ch->shrunk.data = NULL; } if(what & MDVI_FONTSEL_GREY) { if(MDVI_GLYPH_NONEMPTY(ch->grey.data)) { if(dev->free_image) dev->free_image(ch->grey.data); } ch->grey.data = NULL; } if(what & MDVI_FONTSEL_GLYPH) { if(MDVI_GLYPH_NONEMPTY(ch->glyph.data)) bitmap_destroy((BITMAP *)ch->glyph.data); ch->glyph.data = NULL; ch->loaded = 0; } }
void bitmap_destroy(void *bitmap) { struct bitmap *bm = bitmap; if (bitmap == NULL) { LOG(("NULL bitmap!")); return; } if( bm->resized != NULL ) { bitmap_destroy(bm->resized); } free(bm->pixdata); free(bm); }
/** * The bitmap image has changed, so flush any persistant cache. * * \param bitmap a bitmap, as returned by bitmap_create() */ void bitmap_modified(void *bitmap) { struct bitmap *bm = bitmap; if( bm->resized != NULL ) { bitmap_destroy( bm->resized ); bm->resized = NULL; } if( bm->converted ){ if( bm->pixdata != bm->native.fd_addr ){ free( bm->native.fd_addr ); } bm->native.fd_addr = NULL; bm->converted = false; } }
void bitmap_destroy(void *bitmap) { struct bitmap *bm = bitmap; if (bitmap == NULL) { LOG(("NULL bitmap!")); return; } if( bm->resized != NULL ) { bitmap_destroy(bm->resized); } if( bm->converted && ( bm->native.fd_addr != bm->pixdata ) ) free( bm->native.fd_addr ); free(bm->pixdata); free(bm); }
/* * Unmount code. * * VFS calls FS_SYNC on the filesystem prior to unmounting it. * * Locking: gets sfs_vnlock, then sfs_bitlock. */ static int sfs_unmount(struct fs *fs) { struct sfs_fs *sfs = fs->fs_data; lock_acquire(sfs->sfs_vnlock); lock_acquire(sfs->sfs_bitlock); /* Do we have any files open? If so, can't unmount. */ if (array_getnum(sfs->sfs_vnodes)>0) { lock_release(sfs->sfs_vnlock); lock_release(sfs->sfs_bitlock); return EBUSY; } /* * We should have just had sfs_sync called. * The VFS locking prevents anyone from opening any files on the * fs before we get here - in order to open any files, one would * have to go through the volume/device name stuff in vfslist.c, * and it's locked during the sync/unmount. */ assert(sfs->sfs_superdirty==0); assert(sfs->sfs_freemapdirty==0); /* Once we start nuking stuff we can't fail. */ array_destroy(sfs->sfs_vnodes); bitmap_destroy(sfs->sfs_freemap); /* The vfs layer takes care of the device for us */ (void)sfs->sfs_device; /* Free the lock. VFS guarantees we can do this safely */ lock_release(sfs->sfs_vnlock); lock_release(sfs->sfs_bitlock); lock_destroy(sfs->sfs_vnlock); lock_destroy(sfs->sfs_bitlock); /* Destroy the fs object */ kfree(sfs); /* nothing else to do */ return 0; }
static inline void nfa_closure_destroy(s_fa_closure_t **closure) { s_fa_closure_t *closure_tmp; assert_exit(closure && *closure); closure_tmp = *closure; bitmap_destroy(&closure_tmp->bitmap); array_queue_destroy(&closure_tmp->path_queue); array_queue_destroy(&closure_tmp->collection); nfa_closure_match_dp_destroy(&closure_tmp->match_dp); dp_free(closure_tmp); *closure = NULL; }
static void image_cache__free_bitmap(struct image_cache_entry_s *centry) { if (centry->bitmap != NULL) { #ifdef IMAGE_CACHE_VERBOSE LOG(("Freeing bitmap %p size %d age %d redraw count %d", centry->bitmap, centry->bitmap_size, image_cache->current_age - centry->bitmap_age, centry->redraw_count)); #endif bitmap_destroy(centry->bitmap); centry->bitmap = NULL; image_cache->total_bitmap_size -= centry->bitmap_size; image_cache->bitmap_count--; if (centry->redraw_count == 0) { image_cache->specultive_miss_count++; } } }
int main(void) { bitmap_t bitmap = bitmap_allocate(6); if (bitmap == NULL) exit(EXIT_FAILURE); int i; for (i = 0; i < 3; i++) { bitmap_setbit(bitmap, i); } // Check up to 3 digits print_result(bitmap_alltrue(bitmap, 3)); // Check up all digits print_result(bitmap_alltrue(bitmap, 0)); bitmap_print(bitmap); bitmap_destroy(&bitmap); return (EXIT_SUCCESS); }
static inline void ptest_bitmap_destroy(uint32 count) { s_bitmap_t *bitmap; native_wide_t min, max; min = 0xda1; max = 0xdeac; PERFORMANCE_TEST_BEGIN(bitmap_destroy); PERFORMANCE_TEST_CHECKPOINT; while (count--) { bitmap = bitmap_create(min, max); bitmap_destroy(&bitmap); } PERFORMANCE_TEST_ENDPOINT; PERFORMANCE_TEST_RESULT(bitmap_destroy); }
bool allocator_init (struct allocator *a, bool userspace, size_t members, size_t item_size) { ASSERT (a != NULL); ASSERT (members > 0); ASSERT (item_size > 0); memset (a, 0, sizeof (*a)); a->item_size = item_size; a->used_map = bitmap_create (members); if (a->used_map == NULL) return false; size_t pages = (members*item_size + PGSIZE-1) / PGSIZE; a->items = palloc_get_multiple (userspace ? PAL_USER : 0, pages); if (!a->items) { bitmap_destroy (a->used_map); return false; } return true; }
GRAPH * gr_read_png( const char * filename ) { GRAPH * bitmap ; unsigned int n, x ; uint16_t * ptr ; uint32_t * ptr32 ; uint32_t * orig ; uint32_t * row ; uint32_t Rshift, Gshift, Bshift ; uint32_t Rmask, Gmask, Bmask ; png_bytep * rowpointers ; png_structp png_ptr ; png_infop info_ptr, end_info ; png_uint_32 width, height, rowbytes; int depth, color ; /* Abre el fichero y se asegura de que screen está inicializada */ file * png = file_open( filename, "rb" ) ; if ( !png ) return NULL; /* Prepara las estructuras internas */ png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 ) ; if ( !png_ptr ) { file_close( png ); return NULL; } info_ptr = png_create_info_struct( png_ptr ) ; end_info = png_create_info_struct( png_ptr ) ; if ( !info_ptr || !end_info ) { png_destroy_read_struct( &png_ptr, &info_ptr, &end_info ) ; file_close( png ) ; return NULL; } /* Rutina de error */ #if (PNG_LIBPNG_VER>=10500) if ( setjmp( png_jmpbuf( png_ptr ) ) ) #else if ( setjmp( png_ptr->jmpbuf ) ) #endif { png_destroy_read_struct( &png_ptr, &info_ptr, &end_info ) ; file_close( png ) ; return NULL; } /* Recupera información sobre el PNG */ png_set_read_fn( png_ptr, png, user_read_data ) ; png_read_info( png_ptr, info_ptr ) ; png_get_IHDR( png_ptr, info_ptr, &width, &height, &depth, &color, 0, 0, 0 ) ; row = malloc( sizeof( uint32_t ) * width ); if ( !row ) { png_destroy_read_struct( &png_ptr, &info_ptr, &end_info ) ; file_close( png ) ; return NULL; } rowpointers = malloc( sizeof( png_bytep ) * height ); if ( !rowpointers ) { png_destroy_read_struct( &png_ptr, &info_ptr, &end_info ) ; free( row ) ; file_close( png ) ; return NULL; } /* Configura los distintos modos disponibles */ /* if ( ( color == PNG_COLOR_TYPE_GRAY && depth == 1 ) || color == PNG_COLOR_TYPE_GRAY_ALPHA ) { png_set_gray_to_rgb( png_ptr ); if ( color == PNG_COLOR_TYPE_GRAY ) png_set_filler( png_ptr, 0xFF, PNG_FILLER_AFTER ) ; } */ if ( depth == 16 ) png_set_strip_16( png_ptr ) ; if ( color == PNG_COLOR_TYPE_RGB ) png_set_filler( png_ptr, 0xFF, PNG_FILLER_AFTER ) ; png_set_bgr( png_ptr ) ; /* Recupera el fichero, convirtiendo a 16 bits si es preciso */ rowbytes = png_get_rowbytes( png_ptr, info_ptr ) ; bitmap = bitmap_new( 0, width, height, ( color == PNG_COLOR_TYPE_GRAY ) ? depth : ( color == PNG_COLOR_TYPE_PALETTE ) ? 8 : ( sys_pixel_format->depth == 16 ? 16 : 32 ) ) ; if ( !bitmap ) { png_destroy_read_struct( &png_ptr, &info_ptr, &end_info ) ; free( rowpointers ) ; free( row ) ; file_close( png ) ; return NULL; } if ( color == PNG_COLOR_TYPE_GRAY ) { for ( n = 0 ; n < height ; n++ ) rowpointers[n] = (( uint8_t* )bitmap->data ) + n * bitmap->pitch ; png_read_image( png_ptr, rowpointers ) ; if ( depth == 8 ) { uint8_t colors[256 * 3]; uint8_t * p = colors; for ( n = 0; n < 256 ; n++ ) { * p++ = n; * p++ = n; * p++ = n; } bitmap->format->palette = pal_new_rgb(( uint8_t * )colors ); pal_refresh( bitmap->format->palette ); } // png_read_rows( png_ptr, rowpointers, 0, height ) ; } else if ( color == PNG_COLOR_TYPE_PALETTE ) { /* Read the color palette */ png_colorp png_palette = ( png_colorp ) png_malloc( png_ptr, 256 * sizeof( png_color ) ) ; if ( !png_palette ) { bitmap_destroy( bitmap ); png_destroy_read_struct( &png_ptr, &info_ptr, &end_info ) ; free( rowpointers ) ; free( row ) ; file_close( png ) ; return NULL; } png_get_PLTE( png_ptr, info_ptr, &png_palette, ( int * ) &n ) ; uint8_t colors[256 * 3]; uint8_t * p = colors; for ( n = 0; n < 256 ; n++ ) { * p++ = png_palette[n].red; * p++ = png_palette[n].green; * p++ = png_palette[n].blue; } bitmap->format->palette = pal_new_rgb(( uint8_t * )colors ); pal_refresh( bitmap->format->palette ); if ( !sys_pixel_format->palette ) { sys_pixel_format->palette = pal_new( bitmap->format->palette ); /* pal_use( bitmap->format->palette ); */ palette_changed = 1 ; } for ( n = 0 ; n < height ; n++ ) rowpointers[n] = (( uint8_t* )bitmap->data ) + n * bitmap->pitch ; png_read_image( png_ptr, rowpointers ) ; /* If the depth is less than 8, expand the pixel values */ if ( depth == 4 ) { for ( n = 0; n < height; n++ ) { char * orig, * dest; orig = ( char * ) ( rowpointers[n] ); dest = orig + width - 1; orig += ( width - 1 ) / 2; for ( x = width; x--; ) { *dest-- = ( *orig >> ((( 1 - ( x & 0x01 ) ) << 2 ) ) ) & 0x0F ; if ( !( x & 0x01 ) ) orig--; } } } else if ( depth == 2 )
int tricam_process(int argc, char *argv[]) { int i, j, w, h, bpp; bytemap_t *up_image, *mid_image, *dn_image; bytemap_t *gray, *se; bitmap_t *up_roi, *mid_roi, *dn_roi; bitmap_t *bin, *roi, *tmp; char *fn, *ptr; real_t value; FILE *fd; label_info_t *label_info; dwordmap_t *labelmap; point_t *centroid; int label, area; uint8_t vmin, vmax; real_t vmean; bytemap_t *op1, *op2, *op3; char *path; int next_option; char *token1, *token2, *token3; real_t cutup = -2550000, cutdown = -4748; program_name = argv[0]; do { next_option = getopt_long(argc, argv, short_options, long_options, NULL); switch (next_option) { case 'h': print_usage(stdout, 0); break; case 'o': token1 = strdup(optarg); break; case 's': token2 = strdup(optarg); break; case 'd': token3 = strdup(optarg); break; case 'f': cutup = strtod(optarg, NULL); break; case 't': cutdown = strtod(optarg, NULL); break; case 'v': verbose = 1; break; case 'n': path = strdup(optarg); break; case '?': print_usage(stderr, 1); break; case -1: break; default: abort(); } } while (next_option != -1); // printf("(%s - %s) / %s, %lf, %lf, %s\n", token1, token2, token3, cutup, cutdown, path); w = WIDTH; h = HEIGHT; bpp = BPP; initialize_screen(w, h, bpp); up_image = bytemap_new(w, h); mid_image = bytemap_new(w, h); dn_image = bytemap_new(w, h); gray = bytemap_new(w, h); up_roi = bitmap_new(w, h); mid_roi = bitmap_new(w, h); dn_roi = bitmap_new(w, h); bin = bitmap_new(w, h); tmp = bitmap_new(w, h); roi = bitmap_new(w, h); se = bytemap_new(3, 3); bytemap_fill(se, 0, 0, 3, 3, 1); labelmap = dwordmap_new(w, h); path = (char *)malloc(256 * sizeof(char)); // Up display image //////////////////// strcpy(path, argv[1]); strcat(path, "_up.bmp"); fn = strrchr(path, '/') + 1; printf("Filename: %s\n", fn); printf("Display image\n"); load_and_display_BMP(path); read_bytemap_in_screen(up_image, NULL, NULL); bytemap_clear(gray); bytemap_copy(gray, UP_DX, UP_DY, up_image, 0, 0, w, h); write_bytemap_to_screen(gray, gray, gray); wait_keyhit(); printf("Mean filtering \n"); mean_smooth(up_image, gray, 3); write_bytemap_to_screen(up_image, up_image, up_image); wait_keyhit(); //////////////////////////////////////// // MID display image /////////////////// strcpy(path, argv[1]); strcat(path, "_mid.bmp"); fn = strrchr(path, '/') + 1; printf("Filename: %s\n", fn); printf("Display image\n"); load_and_display_BMP(path); read_bytemap_in_screen(mid_image, NULL, NULL); bytemap_clear(gray); bytemap_copy(gray, MID_DX, MID_DY, mid_image, 0, 0, w, h); write_bytemap_to_screen(gray, gray, gray); wait_keyhit(); printf("Mean filtering \n"); mean_smooth(mid_image, gray, 3); write_bytemap_to_screen(mid_image, mid_image, mid_image); wait_keyhit(); ///////////////////////////////////////// // DN display image ///////////////////// strcpy(path, argv[1]); strcat(path, "_dn.bmp"); fn = strrchr(path, '/') + 1; printf("filename: %s\n", fn); printf("Display image\n"); load_and_display_BMP(path); read_bytemap_in_screen(dn_image, NULL, NULL); bytemap_clear(gray); bytemap_copy(gray, DN_DX, DN_DY, dn_image, 0, 0, w, h); write_bytemap_to_screen(gray, gray, gray); wait_keyhit(); printf("Mean filtering \n"); mean_smooth(dn_image, gray, 3); write_bytemap_to_screen(dn_image, dn_image, dn_image); wait_keyhit(); /////////////////////////////////////// printf("Up Image thresholding\n"); bytemap_threshold(bin, up_image, UP_FROM, UP_TO); write_bitmap_to_screen(bin, bin, bin); wait_keyhit(); printf("Big blobs greping\n"); bitmap_clear(roi); label_info = label_info_new(); labeling(labelmap, label_info, bin, NEIGHBOR_8); for (label = 0; label < label_info_get_count(label_info); label++) { label_info_glimpse(&area, label, label_info); //printf("area:%d\n", area); if (area > 3000) { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (dwordmap_get_value(labelmap, j, i) == label) { bitmap_set_value(roi, j, i); } } } } } label_info_destroy(label_info); write_bitmap_to_screen(roi, roi, roi); wait_keyhit(); printf("Fill holes\n"); bitmap_complement(bin, roi); labeling_grep_big_blob(roi, bin); bitmap_complement(bin, roi); write_bitmap_to_screen(bin, bin, bin); wait_keyhit(); printf("Image Morphology\n"); binary_closing(tmp, bin, se); binary_opening(up_roi, tmp, se); write_bitmap_to_screen(up_roi, up_roi, up_roi); wait_keyhit(); /////////////////////////////////////// printf("Mid Image thresholding\n"); bytemap_threshold(bin, mid_image, MID_FROM, MID_TO); write_bitmap_to_screen(bin, bin, bin); wait_keyhit(); printf("Big blobs greping\n"); bitmap_clear(roi); label_info = label_info_new(); labeling(labelmap, label_info, bin, NEIGHBOR_8); for (label = 0; label < label_info_get_count(label_info); label++) { label_info_glimpse(&area, label, label_info); //printf("area:%d\n", area); if (area > 3000) { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (dwordmap_get_value(labelmap, j, i) == label) { bitmap_set_value(roi, j, i); } } } } } label_info_destroy(label_info); write_bitmap_to_screen(roi, roi, roi); wait_keyhit(); printf("Fill holes\n"); bitmap_complement(bin, roi); labeling_grep_big_blob(roi, bin); bitmap_complement(bin, roi); write_bitmap_to_screen(bin, bin, bin); wait_keyhit(); printf("Image Morphology\n"); binary_closing(tmp, bin, se); binary_opening(mid_roi, tmp, se); write_bitmap_to_screen(mid_roi, mid_roi, mid_roi); wait_keyhit(); /////////////////////////////////////////////////// printf("Dn Image thresholding\n"); bytemap_threshold(bin, dn_image, DN_FROM, DN_TO); write_bitmap_to_screen(bin, bin, bin); wait_keyhit(); printf("Big blobs greping\n"); bitmap_clear(roi); label_info = label_info_new(); labeling(labelmap, label_info, bin, NEIGHBOR_8); for (label = 0; label < label_info_get_count(label_info); label++) { label_info_glimpse(&area, label, label_info); //printf("area:%d\n", area); if (area > 3000) { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (dwordmap_get_value(labelmap, j, i) == label) { bitmap_set_value(roi, j, i); } } } } } label_info_destroy(label_info); write_bitmap_to_screen(roi, roi, roi); wait_keyhit(); printf("Fill holes\n"); bitmap_complement(bin, roi); labeling_grep_big_blob(roi, bin); bitmap_complement(bin, roi); write_bitmap_to_screen(bin, bin, bin); wait_keyhit(); printf("Image Morphology\n"); binary_closing(tmp, bin, se); binary_opening(dn_roi, tmp, se); write_bitmap_to_screen(dn_roi, dn_roi, dn_roi); wait_keyhit(); /////////////////////////////////////////////// bitmap_clear(roi); bitmap_or(roi, up_roi); bitmap_or(roi, mid_roi); bitmap_or(roi, dn_roi); write_bitmap_to_screen(up_roi, mid_roi, dn_roi); wait_keyhit(); write_bitmap_to_screen(roi, roi, roi); wait_keyhit(); /* //write_bitmap_to_screen(up_roi, mid_roi, dn_roi); //read_bytemap_in_screen(up_image, mid_image, dn_image); strcpy(path, argv[1]); strcat(path, "_up_roi.bmp"); save_bytemap_as_BMP(up_image, path); strcpy(path, argv[1]); strcat(path, "_mid_roi.bmp"); save_bytemap_as_BMP(mid_image, path); strcpy(path, argv[1]); strcat(path, "_dn_roi.bmp"); save_bytemap_as_BMP(dn_image, path); read_bytemap_in_screen(gray, NULL, NULL); strcpy(path, argv[1]); strcat(path, "_roi.bmp"); save_bytemap_as_BMP(gray, path); */ #if 0 // up image statistic ///////////////////////// bytemap_get_min_max_on_roi(&vmin, &vmax, up_image, roi); bytemap_get_mean_on_roi(&vmean, up_image, roi); printf("Up image statistics are min: %d, mean: %lf, max: %d\n", vmin, vmean, vmax); fd = fopen("up_stat.txt", "a+"); fprintf(fd, "%d, %lf, %d\n", vmin, vmean, vmax); fclose(fd); //////////////////////////////////////////////// // mid image statistic ///////////////////////// bytemap_get_min_max_on_roi(&vmin, &vmax, mid_image, roi); bytemap_get_mean_on_roi(&vmean, mid_image, roi); printf("Mid image statistics are min: %d, mean: %lf, max: %d\n", vmin, vmean, vmax); fd = fopen("mid_stat.txt", "a+"); fprintf(fd, "%d, %lf, %d\n", vmin, vmean, vmax); fclose(fd); ///////////////////////////////////////////////// // dn image statistic /////////////////////////// bytemap_get_min_max_on_roi(&vmin, &vmax, dn_image, roi); bytemap_get_mean_on_roi(&vmean, dn_image, roi); printf("Dn image statistics are min: %d, mean: %lf, max: %d\n", vmin, vmean, vmax); fd = fopen("dn_stat.txt", "a+"); fprintf(fd, "%d, %lf, %d\n", vmin, vmean, vmax); fclose(fd); ///////////////////////////////////////////////// return 0; #endif #if 1 // Up image normalization printf("Up-Image global normalization\n"); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (bitmap_isset(roi, j, i)) { value = bytemap_get_value(up_image, j, i); if (value < UP_MEAN) { value = round(128.0 / (UP_MEAN - UP_MIN) * (value - UP_MIN)); } else { value = round(128.0 / (UP_MAX - UP_MEAN) * (value - UP_MEAN) + 128.0); } if (value < 0) value = 0; if (value > 255) value = 255; bytemap_put_value(value, up_image, j, i); } else { bytemap_put_value(0, up_image, j, i); } } } write_bytemap_to_screen(up_image, up_image, up_image); strcpy(path, argv[1]); strcat(path, "_up_normal.bmp"); save_bytemap_as_gray_BMP(up_image, path); wait_keyhit(); ////////////////////////////////////////// // Mid image normalization printf("MID-Image global normalization\n"); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (bitmap_isset(roi, j, i)) { value = bytemap_get_value(mid_image, j, i); if (value < MID_MEAN) { value = round(128.0 / (MID_MEAN - MID_MIN) * (value - MID_MIN)); } else { value = round(128.0 / (MID_MAX - MID_MEAN) * (value - MID_MEAN) + 128.0); } if (value < 0) value = 0; if (value > 255) value = 255; bytemap_put_value(value, mid_image, j, i); } else { bytemap_put_value(0, mid_image, j, i); } } } write_bytemap_to_screen(mid_image, mid_image, mid_image); strcpy(path, argv[1]); strcat(path, "_mid_normal.bmp"); save_bytemap_as_gray_BMP(mid_image, path); wait_keyhit(); /////////////////////////////////////////////// // Dn image normalization printf("Dn image global normalization\n"); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (bitmap_isset(roi, j, i)) { value = bytemap_get_value(dn_image, j, i); if (value < DN_MEAN) { value = round(128.0 / (DN_MEAN - DN_MIN) * (value - DN_MIN)); } else { value = round(128.0 / (DN_MAX - DN_MEAN) * (value - DN_MEAN) + 128.0); } if (value < 0) value = 0; if (value > 255) value = 255; bytemap_put_value(value, dn_image, j, i); } else { bytemap_put_value(0, dn_image, j, i); } } } write_bytemap_to_screen(dn_image, dn_image, dn_image); strcpy(path, argv[1]); strcat(path, "_dn_normal.bmp"); save_bytemap_as_gray_BMP(dn_image, path); wait_keyhit(); //////////////////////////////////////////// return 0; #endif #if 0 printf("Image subtraction between DN and MID for bruise-detection\n"); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (bitmap_isset(roi, j, i)) { value = ((real_t)bytemap_get_value(dn_image, j, i) - (real_t)bytemap_get_value(mid_image, j, i) + 255.0) / 2.0; if (value < 0) value = 0; if (value > 255) value = 255; bytemap_put_value(value, gray, j, i); } else { bytemap_put_value(0, gray, j, i); } } } write_bytemap_to_screen(gray, gray, gray); wait_keyhit(); bytemap_threshold(bin, gray, 142, 255); write_bitmap_to_screen(bin, bin, bin); wait_keyhit(); printf("Image subtraction between UP and MID for spot-detection\n"); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (bitmap_isset(roi, j, i)) { value = ((real_t)bytemap_get_value(up_image, j, i) - (real_t)bytemap_get_value(mid_imageb, j, i) + 255.0) / 2.0; if (value < 0) value = 0; if (value > 255) value = 255; bytemap_put_value(value, gray, j, i); } else { bytemap_put_value(0, gray, j, i); } } } write_bytemap_to_screen(gray, gray, gray); wait_keyhit(); bytemap_threshold(bin, gray, 1, 110); write_bitmap_to_screen(bin, bin, bin); wait_keyhit(); #endif dwordmap_destroy(labelmap); bytemap_destroy(se); return 0; bitmap_destroy(roi); bitmap_destroy(tmp); bitmap_destroy(bin); bitmap_destroy(dn_roi); bitmap_destroy(mid_roi); bitmap_destroy(up_roi); bytemap_destroy(gray); bytemap_destroy(dn_image); bytemap_destroy(mid_image); bytemap_destroy(up_image); return 0; }
static int sfs_do_mount(struct device *dev, struct fs **fs_store) { /* * Make sure SFS on-disk structures aren't messed up */ static_assert(SFS_BLKSIZE >= sizeof(struct sfs_super)); static_assert(SFS_BLKSIZE >= sizeof(struct sfs_disk_inode)); static_assert(SFS_BLKSIZE >= sizeof(struct sfs_disk_entry)); /* * We can't mount on devices with the wrong sector size. * * (Note: for all intents and purposes here, "sector" and * "block" are interchangeable terms. Technically a filesystem * block may be composed of several hardware sectors, but we * don't do that in sfs.) */ if (dev->d_blocksize != SFS_BLKSIZE) { return -E_NA_DEV; } /* allocate fs structure */ struct fs *fs; if ((fs = alloc_fs(sfs)) == NULL) { return -E_NO_MEM; } /* get sfs from fs.fs_info.__sfs_info */ struct sfs_fs *sfs = fsop_info(fs, sfs); sfs->dev = dev; int ret = -E_NO_MEM; void *sfs_buffer; if ((sfs->sfs_buffer = sfs_buffer = kmalloc(SFS_BLKSIZE)) == NULL) { goto failed_cleanup_fs; } /* load and check sfs's superblock */ if ((ret = sfs_init_read(dev, SFS_BLKN_SUPER, sfs_buffer)) != 0) { goto failed_cleanup_sfs_buffer; } ret = -E_INVAL; struct sfs_super *super = sfs_buffer; /* Make some simple sanity checks */ if (super->magic != SFS_MAGIC) { cprintf("sfs: wrong magic in superblock. (%08x should be %08x).\n", super->magic, SFS_MAGIC); goto failed_cleanup_sfs_buffer; } if (super->blocks > dev->d_blocks) { cprintf("sfs: fs has %u blocks, device has %u blocks.\n", super->blocks, dev->d_blocks); goto failed_cleanup_sfs_buffer; } super->info[SFS_MAX_INFO_LEN] = '\0'; sfs->super = *super; ret = -E_NO_MEM; uint32_t i; /* alloc and initialize hash list */ list_entry_t *hash_list; if ((sfs->hash_list = hash_list = kmalloc(sizeof(list_entry_t) * SFS_HLIST_SIZE)) == NULL) { goto failed_cleanup_sfs_buffer; } for (i = 0; i < SFS_HLIST_SIZE; i ++) { list_init(hash_list + i); } /* load and check freemap (free space bitmap in disk) */ struct bitmap *freemap; uint32_t freemap_size_nbits = sfs_freemap_bits(super); if ((sfs->freemap = freemap = bitmap_create(freemap_size_nbits)) == NULL) { goto failed_cleanup_hash_list; } uint32_t freemap_size_nblks = sfs_freemap_blocks(super); if ((ret = sfs_init_freemap(dev, freemap, SFS_BLKN_FREEMAP, freemap_size_nblks, sfs_buffer)) != 0) { goto failed_cleanup_freemap; } uint32_t blocks = sfs->super.blocks, unused_blocks = 0; for (i = 0; i < freemap_size_nbits; i ++) { if (bitmap_test(freemap, i)) { unused_blocks ++; } } assert(unused_blocks == sfs->super.unused_blocks); /* and other fields */ sfs->super_dirty = 0; sem_init(&(sfs->fs_sem), 1); sem_init(&(sfs->io_sem), 1); sem_init(&(sfs->mutex_sem), 1); list_init(&(sfs->inode_list)); cprintf("sfs: mount: '%s' (%d/%d/%d)\n", sfs->super.info, blocks - unused_blocks, unused_blocks, blocks); /* Set up abstract fs calls */ fs->fs_sync = sfs_sync; fs->fs_get_root = sfs_get_root; fs->fs_unmount = sfs_unmount; fs->fs_cleanup = sfs_cleanup; *fs_store = fs; return 0; failed_cleanup_freemap: bitmap_destroy(freemap); failed_cleanup_hash_list: kfree(hash_list); failed_cleanup_sfs_buffer: kfree(sfs_buffer); failed_cleanup_fs: kfree(fs); return ret; }
static struct bitmap * jpeg_cache_convert(struct content *c) { uint8_t *source_data; /* Jpeg source data */ unsigned long source_size; /* length of Jpeg source data */ struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; jmp_buf setjmp_buffer; unsigned int height; unsigned int width; struct bitmap * volatile bitmap = NULL; uint8_t * volatile pixels = NULL; size_t rowstride; struct jpeg_source_mgr source_mgr = { 0, 0, nsjpeg_init_source, nsjpeg_fill_input_buffer, nsjpeg_skip_input_data, jpeg_resync_to_restart, nsjpeg_term_source }; /* obtain jpeg source data and perfom minimal sanity checks */ source_data = (uint8_t *)content__get_source_data(c, &source_size); if ((source_data == NULL) || (source_size < MIN_JPEG_SIZE)) { return NULL; } /* setup a JPEG library error handler */ cinfo.err = jpeg_std_error(&jerr); jerr.error_exit = nsjpeg_error_exit; jerr.output_message = nsjpeg_error_log; /* handler for fatal errors during decompression */ if (setjmp(setjmp_buffer)) { jpeg_destroy_decompress(&cinfo); return bitmap; } jpeg_create_decompress(&cinfo); cinfo.client_data = &setjmp_buffer; /* setup data source */ source_mgr.next_input_byte = source_data; source_mgr.bytes_in_buffer = source_size; cinfo.src = &source_mgr; /* read JPEG header information */ jpeg_read_header(&cinfo, TRUE); /* set output processing parameters */ cinfo.out_color_space = JCS_RGB; cinfo.dct_method = JDCT_ISLOW; /* commence the decompression, output parameters now valid */ jpeg_start_decompress(&cinfo); width = cinfo.output_width; height = cinfo.output_height; /* create opaque bitmap (jpegs cannot be transparent) */ bitmap = bitmap_create(width, height, BITMAP_NEW | BITMAP_OPAQUE); if (bitmap == NULL) { /* empty bitmap could not be created */ jpeg_destroy_decompress(&cinfo); return NULL; } pixels = bitmap_get_buffer(bitmap); if (pixels == NULL) { /* bitmap with no buffer available */ bitmap_destroy(bitmap); jpeg_destroy_decompress(&cinfo); return NULL; } /* Convert scanlines from jpeg into bitmap */ rowstride = bitmap_get_rowstride(bitmap); do { JSAMPROW scanlines[1]; #if RGB_RED != 0 || RGB_GREEN != 1 || RGB_BLUE != 2 || RGB_PIXELSIZE != 4 int i; scanlines[0] = (JSAMPROW) (pixels + rowstride * cinfo.output_scanline); jpeg_read_scanlines(&cinfo, scanlines, 1); /* expand to RGBA */ for (i = width - 1; 0 <= i; i--) { int r = scanlines[0][i * RGB_PIXELSIZE + RGB_RED]; int g = scanlines[0][i * RGB_PIXELSIZE + RGB_GREEN]; int b = scanlines[0][i * RGB_PIXELSIZE + RGB_BLUE]; scanlines[0][i * 4 + 0] = r; scanlines[0][i * 4 + 1] = g; scanlines[0][i * 4 + 2] = b; scanlines[0][i * 4 + 3] = 0xff; } #else scanlines[0] = (JSAMPROW) (pixels + rowstride * cinfo.output_scanline); jpeg_read_scanlines(&cinfo, scanlines, 1); #endif } while (cinfo.output_scanline != cinfo.output_height); bitmap_modified(bitmap); jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); return bitmap; }
// mount 挂载sfs文件系统 static int sfs_do_mount(struct device *dev, struct fs **fs_store) { static_assert(SFS_BLKSIZE >= sizeof(struct sfs_super)); static_assert(SFS_BLKSIZE >= sizeof(struct sfs_disk_inode)); static_assert(SFS_BLKSIZE >= sizeof(struct sfs_disk_entry)); if (dev->d_blocksize != SFS_BLKSIZE) { return -E_NA_DEV; } /* allocate fs structure */ struct fs *fs; // 我要稍微说一下这里的sfs,alloc_fs以及fsop_info只是一个宏而已,展开之后就做了一系列的替换 // 所以sfs只是字符而已,不要大惊小怪 if ((fs = alloc_fs(sfs)) == NULL) { // 首先是分配一个fs结构,并且指定了类型 return -E_NO_MEM; } struct sfs_fs *sfs = fsop_info(fs, sfs); // 得到fs里面的__sfs_info结构的指针 sfs->dev = dev; // sfs主要是用于记录文件系统的一些信息 int ret = -E_NO_MEM; void *sfs_buffer; if ((sfs->sfs_buffer = sfs_buffer = kmalloc(SFS_BLKSIZE)) == NULL) { // 分配buffer goto failed_cleanup_fs; } /* load and check superblock */ // 加载和检查超级块 if ((ret = sfs_init_read(dev, SFS_BLKN_SUPER, sfs_buffer)) != 0) { goto failed_cleanup_sfs_buffer; } // 第一个扇区的东西就是超级块吗? ret = -E_INVAL; struct sfs_super *super = sfs_buffer; if (super->magic != SFS_MAGIC) { cprintf("sfs: wrong magic in superblock. (%08x should be %08x).\n", super->magic, SFS_MAGIC); goto failed_cleanup_sfs_buffer; } if (super->blocks > dev->d_blocks) { cprintf("sfs: fs has %u blocks, device has %u blocks.\n", super->blocks, dev->d_blocks); goto failed_cleanup_sfs_buffer; } super->info[SFS_MAX_INFO_LEN] = '\0'; sfs->super = *super; // 记录下超级块的信息 ret = -E_NO_MEM; uint32_t i; /* alloc and initialize hash list */ // 分配和初始化hash list list_entry_t *hash_list; if ((sfs->hash_list = hash_list = kmalloc(sizeof(list_entry_t) * SFS_HLIST_SIZE)) == NULL) { goto failed_cleanup_sfs_buffer; } for (i = 0; i < SFS_HLIST_SIZE; i ++) { // 为什么要分配那么多的hash_list? list_init(hash_list + i); // 都需要初始化 } /* load and check freemap */ // 加载和检查freemap struct bitmap *freemap; uint32_t freemap_size_nbits = sfs_freemap_bits(super); if ((sfs->freemap = freemap = bitmap_create(freemap_size_nbits)) == NULL) { goto failed_cleanup_hash_list; } uint32_t freemap_size_nblks = sfs_freemap_blocks(super); if ((ret = sfs_init_freemap(dev, freemap, SFS_BLKN_FREEMAP, freemap_size_nblks, sfs_buffer)) != 0) { goto failed_cleanup_freemap; } uint32_t blocks = sfs->super.blocks, unused_blocks = 0; for (i = 0; i < freemap_size_nbits; i ++) { if (bitmap_test(freemap, i)) { unused_blocks ++; } } assert(unused_blocks == sfs->super.unused_blocks); /* and other fields */ sfs->super_dirty = 0; sem_init(&(sfs->fs_sem), 1); sem_init(&(sfs->io_sem), 1); sem_init(&(sfs->mutex_sem), 1); list_init(&(sfs->inode_list)); cprintf("sfs: mount: '%s' (%d/%d/%d)\n", sfs->super.info, blocks - unused_blocks, unused_blocks, blocks); /* link addr of sync/get_root/unmount/cleanup funciton fs's function pointers*/ fs->fs_sync = sfs_sync; fs->fs_get_root = sfs_get_root; fs->fs_unmount = sfs_unmount; fs->fs_cleanup = sfs_cleanup; *fs_store = fs; return 0; failed_cleanup_freemap: bitmap_destroy(freemap); failed_cleanup_hash_list: kfree(hash_list); failed_cleanup_sfs_buffer: kfree(sfs_buffer); failed_cleanup_fs: kfree(fs); return ret; }
static int check_collision_with_mouse( INSTANCE * proc1, int colltype ) { REGION bbox1, bbox2 ; int x, y, mx, my ; static GRAPH * bmp = NULL; switch ( colltype ) { case COLLISION_BOX: case COLLISION_CIRCLE: if ( !get_bbox( &bbox2, proc1 ) ) return 0 ; case COLLISION_NORMAL: break; default: return 0; } mx = GLOINT32( mod_grproc, MOUSEX ) ; my = GLOINT32( mod_grproc, MOUSEY ) ; /* Checks the process's bounding box to optimize checking (only for screen-type objects) */ if ( LOCDWORD( mod_grproc, proc1, CTYPE ) == C_SCREEN ) { switch ( colltype ) { case COLLISION_NORMAL: if ( !get_bbox( &bbox2, proc1 ) ) return 0 ; if ( bbox2.x > mx || bbox2.x2 < mx || bbox2.y > my || bbox2.y2 < my ) return 0 ; break; case COLLISION_BOX: if ( bbox2.x <= mx && bbox2.x2 >= mx && bbox2.y <= my && bbox2.y2 >= my ) return 1; return 0; break; case COLLISION_CIRCLE: { int cx1, cy1, dx1, dy1; cx1 = bbox2.x + ( dx1 = ( bbox2.x2 - bbox2.x + 1 ) ) / 2 ; cy1 = bbox2.y + ( dy1 = ( bbox2.y2 - bbox2.y + 1 ) ) / 2 ; if ( get_distance( cx1, cy1, 0, mx, my, 0 ) < ( dx1 + dy1 ) / 4 ) return 1; return 0; break; } } } /* Creates a temporary bitmap (only once) */ if ( colltype == COLLISION_NORMAL ) { /* maybe must force this to 32 bits */ if ( bmp && bmp->format->depth != sys_pixel_format->depth ) { bitmap_destroy( bmp ); bmp = NULL; } if ( !bmp ) bmp = bitmap_new( 0, 2, 1, sys_pixel_format->depth ) ; if ( !bmp ) return 0 ; memset( bmp->data, 0, bmp->pitch * bmp->height ) ; } /* Retrieves process information */ bbox1.x = 0 ; bbox1.x2 = 1 ; bbox1.y = 0 ; bbox1.y2 = 0 ; x = LOCINT32( mod_grproc, proc1, COORDX ) ; y = LOCINT32( mod_grproc, proc1, COORDY ) ; RESOLXY( mod_grproc, proc1, x, y ); /* Scroll-type process: check for each region */ if ( LOCDWORD( mod_grproc, proc1, CTYPE ) == C_SCROLL ) { SCROLL_EXTRA_DATA * data; scrolldata * scroll; int i; if ( GLOEXISTS( mod_grproc, SCROLLS ) ) { int cnumber = LOCDWORD( mod_grproc, proc1, CNUMBER ); if ( !cnumber ) cnumber = 0xffffffff ; for ( i = 0 ; i < 10 ; i++ ) { data = &(( SCROLL_EXTRA_DATA * ) & GLODWORD( mod_grproc, SCROLLS ) )[i] ; scroll = ( scrolldata * ) data->reserved[0]; if ( scroll && scroll->active && ( cnumber & ( 1 << i ) ) ) { REGION * r = scroll->region; switch ( colltype ) { case COLLISION_NORMAL: if ( r->x > mx || r->x2 < mx || r->y > my || r->y2 < my ) continue; draw_at( bmp, x + r->x - mx - scroll->posx0, y + r->y - my - scroll->posy0, &bbox1, proc1 ); switch ( sys_pixel_format->depth ) { case 8: if ( *( uint8_t * )bmp->data ) return 1; break; case 16: if ( *( uint16_t * )bmp->data ) return 1; break; case 32: if ( *( uint32_t * )bmp->data ) return 1; break; } break; case COLLISION_BOX: if ( bbox2.x <= scroll->posx0 + r->x + mx && bbox2.x2 >= scroll->posx0 + r->x + mx && bbox2.y <= scroll->posy0 + r->y + my && bbox2.y2 >= scroll->posy0 + r->y + my ) return 1; break; case COLLISION_CIRCLE: { int cx1, cy1, dx1, dy1; cx1 = bbox2.x + ( dx1 = ( bbox2.x2 - bbox2.x + 1 ) ) / 2 ; cy1 = bbox2.y + ( dy1 = ( bbox2.y2 - bbox2.y + 1 ) ) / 2 ; if ( get_distance( cx1, cy1, 0, r->x + mx + scroll->posx0, r->y + my + scroll->posy0, 0 ) < ( dx1 + dy1 ) / 4 ) return 1; break; } } } } } return 0; } switch ( colltype ) { case COLLISION_NORMAL: /* Collision check (blits into temporary space and checks the resulting pixel) */ draw_at( bmp, x - mx, y - my, &bbox1, proc1 ) ; switch ( sys_pixel_format->depth ) { case 8: if ( *( uint8_t * )bmp->data ) return 1; break; case 16: if ( *( uint16_t * )bmp->data ) return 1; break; case 32: if ( *( uint32_t * )bmp->data ) return 1; break; } break; case COLLISION_BOX: if ( bbox2.x <= mx && bbox2.x2 >= mx && bbox2.y <= my && bbox2.y2 >= my ) return 1; break; case COLLISION_CIRCLE: { int cx1, cy1, dx1, dy1; cx1 = bbox2.x + ( dx1 = ( bbox2.x2 - bbox2.x + 1 ) ) / 2 ; cy1 = bbox2.y + ( dy1 = ( bbox2.y2 - bbox2.y + 1 ) ) / 2 ; if ( get_distance( cx1, cy1, 0, mx, my, 0 ) < ( dx1 + dy1 ) / 4 ) return 1; break; } } return 0 ; }
void b_malloc_cleanup() { bitmap_destroy(bm); free(heap); g_tree_destroy(heap_info); }
static int sfs_domount(void *options, struct device *dev, struct fs **ret) { int result; struct sfs_fs *sfs; vfs_biglock_acquire(); /* We don't pass any options through mount */ (void)options; /* * Make sure our on-disk structures aren't messed up */ KASSERT(sizeof(struct sfs_super)==SFS_BLOCKSIZE); KASSERT(sizeof(struct sfs_inode)==SFS_BLOCKSIZE); KASSERT(SFS_BLOCKSIZE % sizeof(struct sfs_dir) == 0); /* * We can't mount on devices with the wrong sector size. * * (Note: for all intents and purposes here, "sector" and * "block" are interchangeable terms. Technically a filesystem * block may be composed of several hardware sectors, but we * don't do that in sfs.) */ if (dev->d_blocksize != SFS_BLOCKSIZE) { vfs_biglock_release(); return ENXIO; } /* Allocate object */ sfs = kmalloc(sizeof(struct sfs_fs)); if (sfs==NULL) { vfs_biglock_release(); return ENOMEM; } /* Allocate array */ sfs->sfs_vnodes = vnodearray_create(); if (sfs->sfs_vnodes == NULL) { kfree(sfs); vfs_biglock_release(); return ENOMEM; } /* Set the device so we can use sfs_rblock() */ sfs->sfs_device = dev; /* Load superblock */ result = sfs_rblock(sfs, &sfs->sfs_super, SFS_SB_LOCATION); if (result) { vnodearray_destroy(sfs->sfs_vnodes); kfree(sfs); vfs_biglock_release(); return result; } /* Make some simple sanity checks */ if (sfs->sfs_super.sp_magic != SFS_MAGIC) { kprintf("sfs: Wrong magic number in superblock " "(0x%x, should be 0x%x)\n", sfs->sfs_super.sp_magic, SFS_MAGIC); vnodearray_destroy(sfs->sfs_vnodes); kfree(sfs); vfs_biglock_release(); return EINVAL; } if (sfs->sfs_super.sp_nblocks > dev->d_blocks) { kprintf("sfs: warning - fs has %u blocks, device has %u\n", sfs->sfs_super.sp_nblocks, dev->d_blocks); } /* Ensure null termination of the volume name */ sfs->sfs_super.sp_volname[sizeof(sfs->sfs_super.sp_volname)-1] = 0; /* Load free space bitmap */ sfs->sfs_freemap = bitmap_create(SFS_FS_BITMAPSIZE(sfs)); if (sfs->sfs_freemap == NULL) { vnodearray_destroy(sfs->sfs_vnodes); kfree(sfs); vfs_biglock_release(); return ENOMEM; } result = sfs_mapio(sfs, UIO_READ); if (result) { bitmap_destroy(sfs->sfs_freemap); vnodearray_destroy(sfs->sfs_vnodes); kfree(sfs); vfs_biglock_release(); return result; } /* Set up abstract fs calls */ sfs->sfs_absfs.fs_sync = sfs_sync; sfs->sfs_absfs.fs_getvolname = sfs_getvolname; sfs->sfs_absfs.fs_getroot = sfs_getroot; sfs->sfs_absfs.fs_unmount = sfs_unmount; sfs->sfs_absfs.fs_data = sfs; /* the other fields */ sfs->sfs_superdirty = false; sfs->sfs_freemapdirty = false; /* Hand back the abstract fs */ *ret = &sfs->sfs_absfs; vfs_biglock_release(); return 0; }
int main(int argc, char **argv) { char *filename1 = argc>=2 ? argv[1]:"out1.txt"; char *filename2 = argc>=3? argv[2]:"out2.txt"; char *outfile = argc>=4? argv[3]:"result.txt"; int fd, result_fd; int i = 0,j = 0; int repeat = 0, ret = 0; struct timespec start,end; #if USE_QUEUE ele_t *eitem; #endif printf("generataing data 1...\n"); START(); gen_data(filename1, GEN_LEN); END(); printf("generataing data 2...\n"); START(); gen_data(filename2, GEN_LEN); END(); printf("generate data over!\n"); printf("press ENTER key to continue <ENTER>\n"); getchar(); printf("reload two file data, then combine them\n"); START(); #if USE_BITMAP { /* load file1 to the data */ int fd=open(filename1, O_RDWR); char *data, *p, *wpos; unsigned long long tmp; result_fd = open(outfile, O_RDWR|O_CREAT|O_TRUNC, 0755); if( result_fd<0 ) { printf("Error : cannot creat file %s.\n", outfile); exit(0); } if( fd < 0 ) { printf("Error : reload file %s error.\n", filename1); exit(0); } data = (char *)malloc(GEN_LEN*12); if( data == NULL ) { printf("Error : cannnot alloc memory size %d \n", GEN_LEN*12); exit(0); } memset(data, 0, GEN_LEN*12); read(fd, data, GEN_LEN*12); /* copy the first file to the result file */ write(result_fd, data, GEN_LEN*12); /*18610670370*/ bitmap_creat((unsigned long long)10000000000); /* the data file 1 shoule not have the same data */ for(p=data, i=0;i<GEN_LEN;i++) { *(p+11)=0; ret = bitmap_setstr(p); if( ret == 0 ) { // printf("tmp %llu\n data[%d]=%s\n", tmp, i,data[i]); printf("Warn : this maybe error . %s repeat index %d\n", p, i); exit(0); repeat++; } p+=12; } memset(data, 0, GEN_LEN*12); close(fd); fd=open(filename2, O_RDWR); if( fd < 0 ) { printf("Error : reload file %s error.\n", filename1); exit(0); } read(fd, data, GEN_LEN*12); close(fd); printf("Result:\n"); for(wpos=data,p=data,i=0;i<GEN_LEN;i++) { *(p+11)=0; ret = bitmap_setstr(p); if( ret == 0 ) { printf("\t%s repeat index %d\n", p, i); *(p+11) = '\n'; repeat++; write(result_fd, wpos, p-wpos); wpos = p+12; } *(p+11) = '\n'; p+=12; if( p-wpos >= 4096 ) { write(result_fd, wpos, p-wpos); wpos = p; } } write(result_fd, wpos, p-wpos); close(result_fd); printf("Total:%d Repeat:%d\n", 2*GEN_LEN, repeat); } #endif END(); while(1) { char tmp; printf("Do you want write the result to file By order?<y/N>"); tmp = getc(stdin); if( tmp == 'N' || tmp == 'n' ) goto EXIT; if( tmp == 'Y' || tmp == 'y' ) break; } START(); #if USE_BITMAP { char *buf, *wpos; int ret; unsigned long long tmp_len; int order_fd = 0; order_fd = open("order_result.txt", O_RDWR|O_CREAT|O_TRUNC, 0766); buf=(char*)malloc(4500); if(buf == NULL) { printf("Error:can not allocate memory 4KB\n"); exit(0); } memset(buf, 0, 4150); for(tmp_len=3000000000UL,wpos=buf;tmp_len != 9000000000; tmp_len++) { ret = bitmap_get(tmp_len, 0); if(ret == 1) { // printf("\ntmp_len : %llu \n", tmp_len); sprintf(wpos, "1%010llu\n", tmp_len); wpos += 12; if(wpos-buf >= 4096) { write(order_fd, buf, wpos-buf); wpos=buf; memset(buf, 0, 4150); #if 0 printf("."); fflush(stdout); #endif } } if( tmp_len == 4000000000UL ) tmp_len = 4999999999; if( tmp_len == 6000000000UL ) tmp_len = 7999999999; } write(order_fd, buf, wpos-buf); printf("write over!\n"); close(order_fd); free(buf); } #endif END(); EXIT: #if USE_BITMAP bitmap_destroy(); #endif printf("process over!\n"); return 0; }
static int sfs_do_mount(struct device *dev, struct fs **fs_store) { static_assert(SFS_BLKSIZE >= sizeof(struct sfs_super)); static_assert(SFS_BLKSIZE >= sizeof(struct sfs_disk_inode)); static_assert(SFS_BLKSIZE >= sizeof(struct sfs_disk_entry)); if (dev->d_blocksize != SFS_BLKSIZE) { return -E_NA_DEV; } /* allocate fs structure */ struct fs *fs; if ((fs = alloc_fs(sfs)) == NULL) { return -E_NO_MEM; } struct sfs_fs *sfs = fsop_info(fs, sfs); sfs->dev = dev; int ret = -E_NO_MEM; void *sfs_buffer; if ((sfs->sfs_buffer = sfs_buffer = kmalloc(SFS_BLKSIZE)) == NULL) { goto failed_cleanup_fs; } /* load and check superblock */ if ((ret = sfs_init_read(dev, SFS_BLKN_SUPER, sfs_buffer)) != 0) { goto failed_cleanup_sfs_buffer; } ret = -E_INVAL; struct sfs_super *super = sfs_buffer; if (super->magic != SFS_MAGIC) { kprintf("sfs: wrong magic in superblock. (%08x should be %08x).\n", super->magic, SFS_MAGIC); goto failed_cleanup_sfs_buffer; } if (super->blocks > dev->d_blocks) { kprintf("sfs: fs has %u blocks, device has %u blocks.\n", super->blocks, dev->d_blocks); goto failed_cleanup_sfs_buffer; } super->info[SFS_MAX_INFO_LEN] = '\0'; sfs->super = *super; ret = -E_NO_MEM; uint32_t i; /* alloc and initialize hash list */ list_entry_t *hash_list; if ((sfs->hash_list = hash_list = kmalloc(sizeof(list_entry_t) * SFS_HLIST_SIZE)) == NULL) { goto failed_cleanup_sfs_buffer; } for (i = 0; i < SFS_HLIST_SIZE; i ++) { list_init(hash_list + i); } /* load and check freemap */ struct bitmap *freemap; uint32_t freemap_size_nbits = sfs_freemap_bits(super); if ((sfs->freemap = freemap = bitmap_create(freemap_size_nbits)) == NULL) { goto failed_cleanup_hash_list; } uint32_t freemap_size_nblks = sfs_freemap_blocks(super); if ((ret = sfs_init_freemap(dev, freemap, SFS_BLKN_FREEMAP, freemap_size_nblks, sfs_buffer)) != 0) { goto failed_cleanup_freemap; } uint32_t blocks = sfs->super.blocks, unused_blocks = 0; for (i = 0; i < freemap_size_nbits; i ++) { if (bitmap_test(freemap, i)) { unused_blocks ++; } } kprintf("unused_blocks is %d and super->unused_blocks is %d", \ unused_blocks, sfs->super.unused_blocks); // while (1); assert(unused_blocks == sfs->super.unused_blocks); /* and other fields */ sfs->super_dirty = 0; sem_init(&(sfs->fs_sem), 1); sem_init(&(sfs->io_sem), 1); sem_init(&(sfs->mutex_sem), 1); list_init(&(sfs->inode_list)); kprintf("sfs: mount: '%s' (%d/%d/%d)\n", sfs->super.info, blocks - unused_blocks, unused_blocks, blocks); fs->fs_sync = sfs_sync; fs->fs_get_root = sfs_get_root; fs->fs_unmount = sfs_unmount; fs->fs_cleanup = sfs_cleanup; *fs_store = fs; return 0; failed_cleanup_freemap: bitmap_destroy(freemap); failed_cleanup_hash_list: kfree(hash_list); failed_cleanup_sfs_buffer: kfree(sfs_buffer); failed_cleanup_fs: kfree(fs); return ret; }
static int check_collision( INSTANCE * proc1, GRAPH * bmp1, REGION * bbox3, INSTANCE * proc2 ) { REGION bbox1, bbox2 ; int x, y, w, h ; GRAPH * bmp2 ; bbox1 = *bbox3; bmp2 = instance_graph( proc2 ) ; if ( !bmp2 ) return 0 ; instance_get_bbox( proc2, bmp2, &bbox2 ); region_union( &bbox1, &bbox2 ) ; if ( region_is_empty( &bbox1 ) ) return 0 ; // Solo si las regiones de ambos bbox se superponen w = bbox1.x2 - bbox1.x + 1 ; h = bbox1.y2 - bbox1.y + 1 ; bbox2.x = bbox2.y = 0 ; bbox2.x2 = w - 1 ; bbox2.y2 = h - 1 ; bmp1 = bitmap_new( 0, w, h, sys_pixel_format->depth ) ; if ( !bmp1 ) return 0; bmp2 = bitmap_new( 0, w, h, sys_pixel_format->depth ) ; if ( !bmp2 ) { bitmap_destroy( bmp1 ) ; return 0; } memset( bmp1->data, 0, bmp1->pitch * h ) ; memset( bmp2->data, 0, bmp2->pitch * h ) ; x = LOCINT32( mod_grproc, proc1, COORDX ) ; y = LOCINT32( mod_grproc, proc1, COORDY ) ; RESOLXY( mod_grproc, proc1, x, y ); x -= bbox1.x ; y -= bbox1.y ; draw_at( bmp1, x, y, &bbox2, proc1 ) ; x = LOCINT32( mod_grproc, proc2, COORDX ) ; y = LOCINT32( mod_grproc, proc2, COORDY ) ; RESOLXY( mod_grproc, proc2, x, y ); x -= bbox1.x ; y -= bbox1.y ; draw_at( bmp2, x, y, &bbox2, proc2 ) ; if ( sys_pixel_format->depth == 32 ) { uint32_t * ptr1 = ( uint32_t * ) bmp1->data ; uint32_t * ptr2 = ( uint32_t * ) bmp2->data ; uint8_t * _ptr1 = ( uint8_t * ) ptr1 ; uint8_t * _ptr2 = ( uint8_t * ) ptr2 ; for ( y = 0 ; y < h ; y++ ) { for ( x = 0 ; x < w ; x++, ptr1++, ptr2++ ) { if ( *ptr1 && *ptr2 ) { bitmap_destroy( bmp1 ) ; bitmap_destroy( bmp2 ) ; return 1; } } ptr1 = ( uint32_t * )( _ptr1 += bmp1->pitch ); ptr2 = ( uint32_t * )( _ptr2 += bmp2->pitch ); } } else { if ( sys_pixel_format->depth == 16 ) { uint16_t * ptr1 = ( uint16_t * ) bmp1->data ; uint16_t * ptr2 = ( uint16_t * ) bmp2->data ; uint8_t * _ptr1 = ( uint8_t * ) ptr1 ; uint8_t * _ptr2 = ( uint8_t * ) ptr2 ; for ( y = 0 ; y < h ; y++ ) { for ( x = 0 ; x < w ; x++, ptr1++, ptr2++ ) { if ( *ptr1 && *ptr2 ) { bitmap_destroy( bmp1 ) ; bitmap_destroy( bmp2 ) ; return 1; } } ptr1 = ( uint16_t * )( _ptr1 += bmp1->pitch ); ptr2 = ( uint16_t * )( _ptr2 += bmp2->pitch ); } } else { uint8_t * ptr1 = ( uint8_t * )bmp1->data ; uint8_t * ptr2 = ( uint8_t * )bmp2->data ; uint8_t * _ptr1 = ptr1 ; uint8_t * _ptr2 = ptr2 ; for ( y = 0 ; y < h ; y++ ) { for ( x = 0 ; x < w ; x++, ptr1++, ptr2++ ) { if ( *ptr1 && *ptr2 ) { bitmap_destroy( bmp1 ) ; bitmap_destroy( bmp2 ) ; return 1; } } ptr1 = _ptr1 += bmp1->pitch; ptr2 = _ptr2 += bmp2->pitch; } } } bitmap_destroy( bmp1 ) ; bitmap_destroy( bmp2 ) ; return 0; }
GRAPH * gr_text_bitmap( int fontid, const char * text, int alignment ) { GRAPH * gr ; int x, y ; FONT * f ; // Splinter if ( !text || !*text ) return NULL; if ( fontid < 0 || fontid >= MAX_FONTS || !fonts[fontid] ) return NULL; // Incorrect font type f = fonts[fontid] ; /* Un refresco de paleta en mitad de gr_text_put puede provocar efectos * desagradables al modificar el tipo de letra del sistema */ if ( palette_changed ) gr_refresh_palette() ; gr = bitmap_new_syslib( gr_text_width( fontid, ( const unsigned char * ) text ), gr_text_height( fontid, ( const unsigned char * ) text ), sys_pixel_format->depth ) ; if ( !gr ) return NULL; gr_clear( gr ) ; if ( !gr_text_put( gr, 0, fontid, 0, -gr_text_margintop( fontid, ( const unsigned char * ) text ), ( const unsigned char * ) text ) ) { bitmap_destroy( gr ); return NULL; } switch ( alignment ) { case ALIGN_TOP_LEFT: // 0 case ALIGN_TOP: // 1 case ALIGN_TOP_RIGHT: // 2 y = 0 ; break ; case ALIGN_CENTER_LEFT: // 3 case ALIGN_CENTER: // 4 case ALIGN_CENTER_RIGHT:// 5 y = gr->height / 2 ; break ; default: y = gr->height - 1 ; break ; } switch ( alignment ) { case ALIGN_TOP_LEFT: // 0 case ALIGN_CENTER_LEFT: // 3 case ALIGN_BOTTOM_LEFT: // 6 x = 0 ; break ; case ALIGN_TOP: // 1 case ALIGN_CENTER: // 4 case ALIGN_BOTTOM: // 7 x = gr->width / 2 ; break ; default: x = gr->width - 1 ; break ; } bitmap_add_cpoint( gr, x, y ) ; return gr ; }
/* Static convenience function */ static int gr_read_lib( file * fp ) { char header[8] ; short int px, py ; int bpp, libid, code; uint32_t y ; unsigned c; GRLIB * lib ; GRAPH * gr ; PALETTE * pal = NULL ; int st = 0; libid = grlib_new() ; if ( libid < 0 ) return -1 ; lib = grlib_get( libid ); if ( !lib ) { grlib_destroy( libid ) ; return -1 ; } file_read( fp, header, 8 ) ; if ( strcmp( header, F32_MAGIC ) == 0 ) bpp = 32 ; else if ( strcmp( header, F16_MAGIC ) == 0 ) bpp = 16 ; else if ( strcmp( header, FPG_MAGIC ) == 0 ) bpp = 8 ; else if ( strcmp( header, F01_MAGIC ) == 0 ) bpp = 1 ; else { grlib_destroy( libid ) ; return -1 ; } if ( bpp == 8 && !( pal = gr_read_pal_with_gamma( fp ) ) ) { grlib_destroy( libid ) ; return -1 ; } while ( !file_eof( fp ) ) { if ( !file_read( fp, &chunk, 64 ) ) break ; ARRANGE_DWORD( &chunk.code ) ; ARRANGE_DWORD( &chunk.regsize ) ; ARRANGE_DWORD( &chunk.width ) ; ARRANGE_DWORD( &chunk.height ) ; ARRANGE_DWORD( &chunk.flags ) ; /* Cabecera del gráfico */ gr = bitmap_new( chunk.code, chunk.width, chunk.height, bpp ) ; if ( !gr ) { grlib_destroy( libid ) ; if ( bpp == 8 ) pal_destroy( pal ) ; // Elimino la instancia inicial return -1 ; } memcpy( gr->name, chunk.name, 32 ) ; gr->name[31] = 0 ; gr->ncpoints = chunk.flags ; gr->modified = 2 ; // bitmap_analize( gr ); /* Puntos de control */ if ( gr->ncpoints ) { gr->cpoints = ( CPOINT * ) malloc( gr->ncpoints * sizeof( CPOINT ) ) ; if ( !gr->cpoints ) { bitmap_destroy( gr ) ; grlib_destroy( libid ) ; if ( bpp == 8 ) pal_destroy( pal ) ; return -1 ; } for ( c = 0 ; c < gr->ncpoints ; c++ ) { file_readSint16( fp, &px ) ; file_readSint16( fp, &py ) ; if ( px == -1 && py == -1 ) { gr->cpoints[c].x = CPOINT_UNDEFINED ; gr->cpoints[c].y = CPOINT_UNDEFINED ; } else { gr->cpoints[c].x = px ; gr->cpoints[c].y = py ; } } } else gr->cpoints = 0 ; /* Datos del gráfico */ for ( y = 0 ; y < gr->height ; y++ ) { uint8_t * line = ( uint8_t * )gr->data + gr->pitch * y; switch ( bpp ) { case 32: st = file_readUint32A( fp, ( uint32_t * ) line, gr->width ); break; case 16: st = file_readUint16A( fp, ( uint16_t * ) line, gr->width ); break; case 8: case 1: st = file_read( fp, line, gr->widthb ); break; } if ( !st ) { bitmap_destroy( gr ); grlib_destroy( libid ) ; if ( bpp == 8 ) pal_destroy( pal ); return -1 ; } } code = grlib_add_map( libid, gr ) ; if ( bpp == 8 ) pal_map_assign( libid, code, pal ) ; } if ( bpp == 8 ) pal_destroy( pal ) ; // Elimino la instancia inicial return libid ; }