extbmp_t *create_extensible_bitmap_params( gc_t *gc, gc_param_t *info, int leaf_bytes, int entries_per_node ) { /* Creates bitmap representing empty set of addresses */ extbmp_t *ebmp; int depth; int max_leaves; int leaf_words = CEILDIV(leaf_bytes, sizeof(word)); long long address_range_in_words; assert( (leaf_bytes % MIN_BYTES_PER_OBJECT) == 0 ); max_leaves = SHIFTED_ADDRESS_SPACE / (BITS_PER_WORD * leaf_words); assert( max_leaves > 0 ); { /* calculate max depth of tree */ int i = 0; long long tot = 1; long long addr_range = ADDRS_PER_WORD * leaf_words; while (tot < max_leaves) { i += 1; tot *= entries_per_node; addr_range *= entries_per_node; } depth = i; address_range_in_words = addr_range; } ebmp = (extbmp_t*)must_malloc( sizeof( extbmp_t )); ebmp->gc = gc; ebmp->leaf_words = CEILDIV(leaf_bytes,sizeof(word)); ebmp->entries_per_inode = entries_per_node; ebmp->depth = depth; ebmp->tree = alloc_inode( ebmp, address_range_in_words, 0, (((long long)SHIFTED_ADDRESS_SPACE) << BIT_IDX_SHIFT)); ebmp->mru_cache.leaf = NULL; ebmp->mru_cache.first_addr_for_leaf = 0; ebmp->gno_count = gc->gno_count; ebmp->gno_to_leaf = (leaf_t**)must_malloc( sizeof(leaf_t*) * ebmp->gno_count ); { int i; for (i = 0; i < ebmp->gno_count; i++) { ebmp->gno_to_leaf[i] = NULL; } } ebmp->leaf_count = 0; annoyingmsg( "ebmp{gc,leaf_words=%d,entries_per_inode=%d,depth=%d,tree} max_leaves:%d", ebmp->leaf_words, ebmp->entries_per_inode, ebmp->depth, max_leaves ); return ebmp; }
static tnode_t *alloc_inode( extbmp_t *ebmp, long long address_range_in_words, word start, long long limit ) { tnode_t *retval; assert( address_range_in_words > 0 ); retval = alloc_tnode( ebmp, tag_inode, (sizeof( inode_t ) + ebmp->entries_per_inode*sizeof( tnode_t* ))); retval->inode.address_range_in_words = address_range_in_words; retval->inode.address_words_per_child = CEILDIV( ((long long)address_range_in_words), ebmp->entries_per_inode ); assert( retval->inode.address_words_per_child > 0 ); assert((retval->inode.address_words_per_child * ebmp->entries_per_inode) >= retval->inode.address_range_in_words); #if INCLUDE_REDUNDANT_FIELDS retval->inode.start = start; retval->inode.limit = limit; #endif init_inode_fields_cleared( ebmp, &retval->inode ); dbmsg( "alloc_inode(ebmp,%8lld,start=0x%08x,limit=0x%08llx)" " ==> 0x%08x", address_range_in_words, start, limit, retval); return retval; }
/** * \brief Allocate new frame * \param pic picture pointer * \return picture pointer */ videoframe_t * kvz_videoframe_alloc(int32_t width, int32_t height, enum kvz_chroma_format chroma_format) { videoframe_t *frame = calloc(1, sizeof(videoframe_t)); if (!frame) return 0; frame->width = width; frame->height = height; frame->width_in_lcu = CEILDIV(frame->width, LCU_WIDTH); frame->height_in_lcu = CEILDIV(frame->height, LCU_WIDTH); frame->sao_luma = MALLOC(sao_info_t, frame->width_in_lcu * frame->height_in_lcu); if (chroma_format != KVZ_CSP_400) { frame->sao_chroma = MALLOC(sao_info_t, frame->width_in_lcu * frame->height_in_lcu); } return frame; }
static int select_owf_auto(const kvz_config *const cfg) { if (cfg->wpp) { // If wpp is on, select owf such that less than 15% of the // frame is covered by the are threads can not work at the same time. const int lcu_width = CEILDIV(cfg->width, LCU_WIDTH); const int lcu_height = CEILDIV(cfg->height, LCU_WIDTH); // Find the largest number of threads per frame that satifies the // the condition: wpp start/stop inefficiency takes up less than 15% // of frame area. int threads_per_frame = 1; const int wpp_treshold = lcu_width * lcu_height * 15 / 100; while ((threads_per_frame + 1) * 2 < lcu_width && threads_per_frame + 1 < lcu_height && size_of_wpp_ends(threads_per_frame + 1) < wpp_treshold) { ++threads_per_frame; } const int threads = MAX(cfg->threads, 1); const int frames = CEILDIV(threads, threads_per_frame); // Convert from number of parallel frames to number of additional frames. return CLIP(0, threads - 1, frames - 1); } else { // If wpp is not on, select owf such that there is enough // tiles for twice the number of threads. int tiles_per_frame= cfg->tiles_width_count * cfg->tiles_height_count; int threads = (cfg->threads > 1 ? cfg->threads : 1); int frames = CEILDIV(threads * 4, tiles_per_frame); // Limit number of frames to 1.25x the number of threads for the case // where there is only 1 tile per frame. frames = CLIP(1, threads * 4 / 3, frames); return frames - 1; } }
bool CxImageJ2K::Decode(CxFile *hFile) { if (hFile == NULL) return false; try { BYTE* src; long len; j2k_image_t *img=NULL; j2k_cp_t *cp=NULL; long i,x,y,w,h,max; len=hFile->Size(); src=(BYTE*)malloc(len); hFile->Read(src, len, 1); if (!j2k_decode(src, len, &img, &cp)) { free(src); throw "failed to decode J2K image!"; } free(src); if (img->numcomps==3 && img->comps[0].dx==img->comps[1].dx && img->comps[1].dx==img->comps[2].dx && img->comps[0].dy==img->comps[1].dy && img->comps[1].dy==img->comps[2].dy && img->comps[0].prec==img->comps[1].prec && img->comps[1].prec==img->comps[2].prec) { w=CEILDIV(img->x1-img->x0, img->comps[0].dx); h=CEILDIV(img->y1-img->y0, img->comps[0].dy); max=(1<<img->comps[0].prec)-1; Create(w,h,24,CXIMAGE_FORMAT_J2K); RGBQUAD c; for (i=0,y=0; y<h; y++) { for (x=0; x<w; x++,i++){ c.rgbRed = img->comps[0].data[i]; c.rgbGreen = img->comps[1].data[i]; c.rgbBlue = img->comps[2].data[i]; SetPixelColor(x,h-1-y,c); } } } else { int compno; info.nNumFrames = img->numcomps; if ((info.nFrame<0)||(info.nFrame>=info.nNumFrames)){ j2k_destroy(&img,&cp); throw "wrong frame!"; } for (compno=0; compno<=info.nFrame; compno++) { w=CEILDIV(img->x1-img->x0, img->comps[compno].dx); h=CEILDIV(img->y1-img->y0, img->comps[compno].dy); max=(1<<img->comps[compno].prec)-1; Create(w,h,8,CXIMAGE_FORMAT_J2K); SetGrayPalette(); for (i=0,y=0; y<h; y++) { for (x=0; x<w; x++,i++){ SetPixelIndex(x,h-1-y,img->comps[compno].data[i]); } } } } j2k_destroy(&img,&cp); } catch (char *message) { strncpy(info.szLastError,message,255); return FALSE; } return true; }