Example #1
0
void decode_and_reconstruct_block_inter (uint8_t *rec, int stride, int size, int qp, uint8_t *pblock,
    int16_t *coeffq,int tb_split, qmtx_t ** iwmatrix){

  int16_t *rcoeff = thor_alloc(2*MAX_TR_SIZE*MAX_TR_SIZE, 16);
  int16_t *rblock = thor_alloc(2*MAX_TR_SIZE*MAX_TR_SIZE, 16);
  int16_t *rblock2 = thor_alloc(2*MAX_TR_SIZE*MAX_TR_SIZE, 16);

  if (tb_split){
    int size2 = size/2;
    int i,j,k,index;
    for (i=0;i<size;i+=size2){
      for (j=0;j<size;j+=size2){
        index = 2*(i/size2) + (j/size2);
        dequantize (coeffq+index*size2*size2, rcoeff, qp, size2, iwmatrix ? iwmatrix[log2i(size2/4)] : NULL, MAX_QUANT_SIZE);
        inverse_transform (rcoeff, rblock2, size2);
        /* Copy from compact block of quarter size to full size */
        for (k=0;k<size2;k++){
          memcpy(rblock+(i+k)*size+j,rblock2+k*size2,size2*sizeof(int16_t));
        }
      }
    }
  }
  else{
    dequantize (coeffq, rcoeff, qp, size, iwmatrix ? iwmatrix[log2i(size/4)] : NULL, MAX_QUANT_SIZE);

    inverse_transform (rcoeff, rblock, size);
  }
  reconstruct_block(rblock,pblock,rec,size,stride);

  thor_free(rcoeff);
  thor_free(rblock);
  thor_free(rblock2);
}
Example #2
0
void
nv04_emit_tex_obj(struct gl_context *ctx, int emit)
{
	struct nv04_context *nv04 = to_nv04_context(ctx);
	const int i = emit - NOUVEAU_STATE_TEX_OBJ0;
	struct nouveau_surface *s;
	uint32_t format = 0xa0, filter = 0x1010;

	if (ctx->Texture.Unit[i]._ReallyEnabled) {
		struct gl_texture_object *t = ctx->Texture.Unit[i]._Current;
		struct gl_texture_image *ti = t->Image[0][t->BaseLevel];
		int lod_max = 1, lod_bias = 0;

		if (!nouveau_texture_validate(ctx, t))
			return;

		s = &to_nouveau_texture(t)->surfaces[t->BaseLevel];

		if (t->Sampler.MinFilter != GL_NEAREST &&
		    t->Sampler.MinFilter != GL_LINEAR) {
			lod_max = CLAMP(MIN2(t->Sampler.MaxLod, t->_MaxLambda),
					0, 15) + 1;

			lod_bias = CLAMP(ctx->Texture.Unit[i].LodBias +
					 t->Sampler.LodBias, -16, 15) * 8;
		}

		format |= nvgl_wrap_mode(t->Sampler.WrapT) << 28 |
			nvgl_wrap_mode(t->Sampler.WrapS) << 24 |
			ti->HeightLog2 << 20 |
			ti->WidthLog2 << 16 |
			lod_max << 12 |
			get_tex_format(ti);

		filter |= log2i(t->Sampler.MaxAnisotropy) << 31 |
			nvgl_filter_mode(t->Sampler.MagFilter) << 28 |
			log2i(t->Sampler.MaxAnisotropy) << 27 |
			nvgl_filter_mode(t->Sampler.MinFilter) << 24 |
			(lod_bias & 0xff) << 16;

	} else {
		s = &to_nv04_context(ctx)->dummy_texture;

		format |= NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSU_REPEAT |
			NV04_TEXTURED_TRIANGLE_FORMAT_ADDRESSV_REPEAT |
			1 << 12 |
			NV04_TEXTURED_TRIANGLE_FORMAT_COLOR_A8R8G8B8;

		filter |= NV04_TEXTURED_TRIANGLE_FILTER_MINIFY_NEAREST |
			NV04_TEXTURED_TRIANGLE_FILTER_MAGNIFY_NEAREST;
	}

	nv04->texture[i] = s;
	nv04->format[i] = format;
	nv04->filter[i] = filter;
}
Example #3
0
static Bool
setup_texture(NVPtr pNv, int unit, PicturePtr pict, PixmapPtr pixmap)
{
	struct nouveau_channel *chan = pNv->chan;
	struct nouveau_grobj *celsius = pNv->Nv3D;
	struct nouveau_bo *bo = nouveau_pixmap_bo(pixmap);
	unsigned tex_reloc = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD;
	long w = pict->pDrawable->width,
	     h = pict->pDrawable->height;
	unsigned int txfmt =
		NV10TCL_TX_FORMAT_WRAP_T_CLAMP_TO_EDGE |
		NV10TCL_TX_FORMAT_WRAP_S_CLAMP_TO_EDGE |
		log2i(w) << 20 | log2i(h) << 16 |
		1 << 12 | /* lod == 1 */
		get_tex_format(pict) |
		0x50 /* UNK */;

	BEGIN_RING(chan, celsius, NV10TCL_TX_OFFSET(unit), 1);
	if (OUT_RELOCl(chan, bo, 0, tex_reloc))
		return FALSE;

	if (pict->repeat == RepeatNone) {
		/* NPOT_SIZE expects an even number for width, we can
		 * round up uneven numbers here because EXA always
		 * gives 64 byte aligned pixmaps and for all formats
		 * we support 64 bytes represents an even number of
		 * pixels
		 */
		w = (w + 1) &~ 1;

		BEGIN_RING(chan, celsius, NV10TCL_TX_NPOT_PITCH(unit), 1);
		OUT_RING  (chan, exaGetPixmapPitch(pixmap) << 16);

		BEGIN_RING(chan, celsius, NV10TCL_TX_NPOT_SIZE(unit), 1);
		OUT_RING  (chan, w << 16 | h);
	}

	BEGIN_RING(chan, celsius, NV10TCL_TX_FORMAT(unit), 1 );
	if (OUT_RELOCd(chan, bo, txfmt, tex_reloc | NOUVEAU_BO_OR,
		       NV10TCL_TX_FORMAT_DMA0, NV10TCL_TX_FORMAT_DMA1))
		return FALSE;

	BEGIN_RING(chan, celsius, NV10TCL_TX_ENABLE(unit), 1 );
	OUT_RING  (chan, NV10TCL_TX_ENABLE_ENABLE);

	BEGIN_RING(chan, celsius, NV10TCL_TX_FILTER(unit), 1);
	if (pict->filter == PictFilterNearest)
		OUT_RING(chan, (NV10TCL_TX_FILTER_MAGNIFY_NEAREST |
				NV10TCL_TX_FILTER_MINIFY_NEAREST));
	else
		OUT_RING(chan, (NV10TCL_TX_FILTER_MAGNIFY_LINEAR |
				NV10TCL_TX_FILTER_MINIFY_LINEAR));

	return TRUE;
}
Example #4
0
File: convert.c Project: rlk/gigo
static TIFF *tifopenr(const char *tif,  // TIFF file name
                            bool *c,    // return is complex?
                             int *l,    // return log2 tile size
                             int *n,    // return log2 height
                             int *m,    // return log2 width
                             int *p)    // return pixel size
{
    TIFF *T;

    if ((T = TIFFOpen(tif, "r")))
    {
        uint32 W = 0;
        uint32 L = 0;
        uint32 S = 0;
        uint16 P = 0;
        uint16 B = 0;
        uint16 G = 0;
        uint16 F = 0;

        TIFFGetField(T, TIFFTAG_IMAGEWIDTH,      &W);
        TIFFGetField(T, TIFFTAG_IMAGELENGTH,     &L);
        TIFFGetField(T, TIFFTAG_TILEWIDTH,       &S);
        TIFFGetField(T, TIFFTAG_SAMPLESPERPIXEL, &P);
        TIFFGetField(T, TIFFTAG_BITSPERSAMPLE,   &B);
        TIFFGetField(T, TIFFTAG_PLANARCONFIG,    &G);
        TIFFGetField(T, TIFFTAG_SAMPLEFORMAT,    &F);

        if (G == PLANARCONFIG_CONTIG)
        {
            if (F == SAMPLEFORMAT_IEEEFP)
            {
                if (B == 32)
                {
                    if (ispow2(W) && ispow2(L))
                    {
                        *c = (P % 2) ? false : true;
                        *p = (P % 2) ? P     : P / 2;
                        *l = log2i(S);
                        *n = log2i(L);
                        *m = log2i(W);

                        return T;
                    }
                    else apperr("TIFF image size must be power of 2");
                }
                else apperr("TIFF must have 32 bits per sample");
            }
            else apperr("TIFF must have floating point sample format");
        }
        else apperr("TIFF must have contiguous planar configuration");
        TIFFClose(T);
    }
    return 0;
}
Example #5
0
static Bool
NV30EXATexture(ScrnInfoPtr pScrn, PixmapPtr pPix, PicturePtr pPict, int unit)
{
	NVPtr pNv = NVPTR(pScrn);
	struct nouveau_channel *chan = pNv->chan;
	struct nouveau_grobj *rankine = pNv->Nv3D;
	struct nouveau_bo *bo = nouveau_pixmap_bo(pPix);
	nv_pict_texture_format_t *fmt;
	uint32_t card_filter, card_repeat;
	uint32_t tex_reloc = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD;
	NV30EXA_STATE;

	fmt = NV30_GetPictTextureFormat(pPict->format);
	if (!fmt)
		return FALSE;

	card_repeat = 3; /* repeatNone */

	if (pPict->filter == PictFilterBilinear)
		card_filter = 2;
	else
		card_filter = 1;

	BEGIN_RING(chan, rankine, NV34TCL_TX_OFFSET(unit), 8);
	if (OUT_RELOCl(chan, bo, 0, tex_reloc) ||
	    OUT_RELOCd(chan, bo, NV34TCL_TX_FORMAT_DIMS_2D | (1 << 16) | 8 |
		       (fmt->card_fmt << NV34TCL_TX_FORMAT_FORMAT_SHIFT) |
		       (log2i(pPix->drawable.width) <<
			NV34TCL_TX_FORMAT_BASE_SIZE_U_SHIFT) |
		       (log2i(pPix->drawable.height) <<
			NV34TCL_TX_FORMAT_BASE_SIZE_V_SHIFT),
		       tex_reloc | NOUVEAU_BO_OR,
		       NV34TCL_TX_FORMAT_DMA0, NV34TCL_TX_FORMAT_DMA1))
		return FALSE;
	OUT_RING  (chan, (card_repeat << NV34TCL_TX_WRAP_S_SHIFT) |
			(card_repeat << NV34TCL_TX_WRAP_T_SHIFT) |
			(card_repeat << NV34TCL_TX_WRAP_R_SHIFT));
	OUT_RING  (chan, NV34TCL_TX_ENABLE_ENABLE);
	OUT_RING  (chan, (((uint32_t)exaGetPixmapPitch(pPix)) << NV34TCL_TX_SWIZZLE_RECT_PITCH_SHIFT ) | 
			fmt->card_swz);

	OUT_RING  (chan, (card_filter << NV34TCL_TX_FILTER_MINIFY_SHIFT) /* min */ |
			(card_filter << NV34TCL_TX_FILTER_MAGNIFY_SHIFT) /* mag */ |
			0x2000 /* engine lock */);
	OUT_RING  (chan, (pPix->drawable.width << NV34TCL_TX_NPOT_SIZE_W_SHIFT) | pPix->drawable.height);
	OUT_RING  (chan, 0); /* border ARGB */

	state->unit[unit].width		= (float)pPix->drawable.width;
	state->unit[unit].height	= (float)pPix->drawable.height;
	state->unit[unit].transform	= pPict->transform;

	return TRUE;
}
static int dm365_aew_open( AEW_WINDOW *window )
{
	int bytes;

	fd = open("/dev/dm365_aew", O_RDWR);
	assert(fd > 0);

	aew_config.window_config.hz_cnt = window->width / aew_config.window_config.width;
	aew_config.window_config.vt_cnt = window->height / aew_config.window_config.height;
	aew_config.window_config.hz_start = window->start_x;
	aew_config.window_config.vt_start = window->start_y;
	aew_config.blackwindow_config.height = window->start_y;
	
	// 使颜色值范围为0-255
	if(aew_config.alaw_enable == H3A_AEW_ENABLE)
	{
		aew_config.sum_shift = log2i(aew_config.window_config.width * aew_config.window_config.height / 4);
	}
	else
	{
		aew_config.sum_shift = log2i(aew_config.window_config.width * aew_config.window_config.height / 4) + 2;
	}
	
	bytes = ioctl(fd, AEW_S_PARAM, &aew_config);
	if(bytes < 0)
	{
		perror("dm365_aew set param failed");
		close(fd);
		return -1;
	}
	else
	{
		printf("dm365_aew buffer size = %d\n", bytes);
	}

	
	aew_stat_buf = (unsigned short *)malloc(bytes);
	
	if(aew_stat_buf == 0)
	{
		perror("dm365_aew malloc memory failed");
		close(fd);
		return -1;
	}
	
	aew_stat_buf_size = bytes;
	aew_paxel_cnt = aew_config.window_config.hz_cnt * (aew_config.window_config.vt_cnt + 1);
	
	return aew_paxel_cnt;
}
Example #7
0
static void
nv20_fragtex_build(struct nv20_context *nv20, int unit)
{
#if 0
	struct nv20_sampler_state *ps = nv20->tex_sampler[unit];
	struct nv20_miptree *nv20mt = nv20->tex_miptree[unit];
	struct pipe_texture *pt = &nv20mt->base;
	struct nv20_texture_format *tf;
	uint32_t txf, txs, txp;

	tf = nv20_fragtex_format(pt->format);
	if (!tf || !tf->defined) {
		NOUVEAU_ERR("Unsupported texture format: 0x%x\n", pt->format);
		return;
	}

	txf  = tf->format << 8;
	txf |= (pt->last_level + 1) << 16;
	txf |= log2i(pt->width[0]) << 20;
	txf |= log2i(pt->height[0]) << 24;
	txf |= log2i(pt->depth[0]) << 28;
	txf |= 8;

	switch (pt->target) {
	case PIPE_TEXTURE_CUBE:
		txf |= NV10TCL_TX_FORMAT_CUBE_MAP;
		/* fall-through */
	case PIPE_TEXTURE_2D:
		txf |= (2<<4);
		break;
	case PIPE_TEXTURE_1D:
		txf |= (1<<4);
		break;
	default:
		NOUVEAU_ERR("Unknown target %d\n", pt->target);
		return;
	}

	BEGIN_RING(kelvin, NV10TCL_TX_OFFSET(unit), 8);
	OUT_RELOCl(nv20mt->buffer, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD);
	OUT_RELOCd(nv20mt->buffer,txf,NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_OR | NOUVEAU_BO_RD, 1/*VRAM*/,2/*TT*/);
	OUT_RING  (ps->wrap);
	OUT_RING  (0x40000000); /* enable */
	OUT_RING  (txs);
	OUT_RING  (ps->filt | 0x2000 /* magic */);
	OUT_RING  ((pt->width[0] << 16) | pt->height[0]);
	OUT_RING  (ps->bcol);
#endif
}
Example #8
0
PageTable::PageTable()
    : numOSPages("MemoryOS:numOSPages"),
      numUsrPages("MemoryOS:numUsrPages")
{
    invertedPT = new IntlPTEntry[MemoryOS::numPhysicalPages];

    ulong tmp_numEntriesPage = GMemorySystem::getPageSize() / BytesPerEntry;

    maskEntriesPage = tmp_numEntriesPage - 1;
    log2EntriesPage = log2i(tmp_numEntriesPage);

    /* We assume a 32 bit virtual address */
    long numL1PTEntries = GMemorySystem::calcPage(0x80000000) >> (log2EntriesPage-1);

    L1PT = new L1IntlPTEntry[numL1PTEntries];

    // L1 Page Table
    invertedPT[0].status = SystemPageStatus | ValidPageStatus;

    for (ulong i = 1; i < MemoryOS::numPhysicalPages; i++)
        invertedPT[i].status = 0;

    for (long i = 0; i < numL1PTEntries; i++)
        L1PT[i].status = 0;
}
Example #9
0
MSHR<Addr_t, Cache_t>::MSHR(const char *name, int32_t size, int32_t lineSize, int32_t aPolicy)
  :nEntries(size)
  ,Log2LineSize(log2i(lineSize))
  ,nUse("%s_MSHR:nUse", name)
  ,nUseReads("%s_MSHR:nUseReads", name)
  ,nUseWrites("%s_MSHR:nUseWrites", name)
  ,nOverflows("%s_MSHR:nOverflows", name)
  ,maxUsedEntries("%s_MSHR_maxUsedEntries", name)
  ,nCanAccept("%s_MSHR:nCanAccept", name)
  ,nCanNotAccept("%s_MSHR:nCanNotAccept", name)
  ,nCanNotAcceptConv("%s_MSHR:nCanNotAcceptConv", name)
  ,blockingCycles("%s_MSHR:blockingCycles",name)
  ,allocPolicy(aPolicy)
  ,occStatsAttached(false)
  ,lowerCache(NULL)
{
  I(size>0 && size<1024*32);

#ifdef MSHR_BASICOCCSTATS
  occStats = new MSHRStats<Addr_t,Cache_t>(name);
  occStats->attach(this);
#endif

  nFreeEntries = size;
}
Example #10
0
static unsigned
get_swizzled_offset(struct nouveau_surface *s, unsigned x, unsigned y)
{
    unsigned k = log2i(MIN2(s->width, s->height));

    unsigned u = (x & 0x001) << 0 |
                 (x & 0x002) << 1 |
                 (x & 0x004) << 2 |
                 (x & 0x008) << 3 |
                 (x & 0x010) << 4 |
                 (x & 0x020) << 5 |
                 (x & 0x040) << 6 |
                 (x & 0x080) << 7 |
                 (x & 0x100) << 8 |
                 (x & 0x200) << 9 |
                 (x & 0x400) << 10 |
                 (x & 0x800) << 11;

    unsigned v = (y & 0x001) << 1 |
                 (y & 0x002) << 2 |
                 (y & 0x004) << 3 |
                 (y & 0x008) << 4 |
                 (y & 0x010) << 5 |
                 (y & 0x020) << 6 |
                 (y & 0x040) << 7 |
                 (y & 0x080) << 8 |
                 (y & 0x100) << 9 |
                 (y & 0x200) << 10 |
                 (y & 0x400) << 11 |
                 (y & 0x800) << 12;

    return s->cpp * (((u | v) & ~(~0 << 2*k)) |
                     (x & (~0 << k)) << k |
                     (y & (~0 << k)) << k);
}
Example #11
0
/* static */
int UIWizardNewVDPage3::sizeMBToSlider(qulonglong uValue, int iSliderScale)
{
    int iPower = log2i(uValue);
    qulonglong uTickMB = qulonglong (1) << iPower;
    qulonglong uTickMBNext = qulonglong (1) << (iPower + 1);
    int iStep = (uValue - uTickMB) * iSliderScale / (uTickMBNext - uTickMB);
    return iPower * iSliderScale + iStep;
}
Example #12
0
static void test_log2i(void) {
        assert_se(log2i(1) == 0);
        assert_se(log2i(2) == 1);
        assert_se(log2i(3) == 1);
        assert_se(log2i(4) == 2);
        assert_se(log2i(32) == 5);
        assert_se(log2i(33) == 5);
        assert_se(log2i(63) == 5);
        assert_se(log2i(INT_MAX) == sizeof(int)*8-2);
}
Example #13
0
static int reorder_frame_offset(int idx, int sub_gop)
{
#if DYADIC_CODING
  return dyadic_reorder_code_to_display[log2i(sub_gop)][idx]-sub_gop+1;
#else
  if (idx==0) return 0;
  else return idx-sub_gop;
#endif
}
Example #14
0
File: mainenc.c Project: cisco/thor
static int reorder_frame_offset(int idx, int sub_gop, int dyadic)
{
  if (dyadic && sub_gop>1) {
    return dyadic_reorder_code_to_display[log2i(sub_gop)][idx]-sub_gop+1;
  } else {
    if (idx==0) return 0;
    else return idx-sub_gop;
  }
}
Example #15
0
void inverse_transform (const int16_t * coeff, int16_t *block, int size)
{
  if (size < 32)
    inverse_transform_simd(coeff, block, size);
  else {
    int i,j;
    int out[MAX_TR_SIZE];
    int16_t tmp[MAX_TR_SIZE*MAX_TR_SIZE];
    int tr = log2i(size)-2;
    const int16_t * tr_matrix = transform_table[tr];
    const int shift_1 = 7;
    const int add_1 = 1 << (shift_1 - 1);
    const int shift_2 = 12;
    const int add_2 = 1 << (shift_2 -1);

    /* 1st dimension */
    for (i=0;i<MAX_QUANT_SIZE;i++){
#if 1
      /* Partial factorization */
      transform_1d_even_l0(coeff, tr_matrix, size, i, out);
#else
      /* Matrix multiplication */
      int k;
      for (j=0;j<size;j++){
        out[j] = 0;
        for (k=0;k<MAX_QUANT_SIZE;k++){
          out[j] += tr_matrix[k*size+j] * coeff[k*size+i];
        }
      }
#endif
      for (j=0;j<size;j++){
        tmp[i*size+j] = clip((out[j] + add_1) >> shift_1, -32768, 32767);
      }
    }

    /* 2nd dimension */
    for (i=0;i<size;i++){
#if 1
      /* Partial factorization */
      transform_1d_even_l0(tmp, tr_matrix, size, i, out);
#else
      /* Matrix multiplication */
      int k;
      for (j=0;j<size;j++){
        out[j] = 0;
        for (k=0;k<MAX_QUANT_SIZE;k++){
          out[j] += tr_matrix[k*size+j] * tmp[k*size+i];
        }
      }
#endif
      for (j=0;j<size;j++){
        block[i*size + j] = clip((out[j] + add_2) >> shift_2, -32768, 32767);
      }
    }
  }
}
Example #16
0
static void test_log2i(void) {
        log_info("/* %s */", __func__);

        assert_se(log2i(1) == 0);
        assert_se(log2i(2) == 1);
        assert_se(log2i(3) == 1);
        assert_se(log2i(4) == 2);
        assert_se(log2i(32) == 5);
        assert_se(log2i(33) == 5);
        assert_se(log2i(63) == 5);
        assert_se(log2i(INT_MAX) == sizeof(int)*8-2);
}
Example #17
0
LiveCache::LiveCache() {
  cacheBank = CacheType::create("LiveCache", "", "LL");
  lineSize  = cacheBank->getLineSize();
  lineSizeBits = log2i(lineSize);

  I(getLineSize() < 4096); // To avoid bank selection conflict (insane LiveCache line)

  lineCount = (uint64_t) cacheBank->getNumLines();
  maxOrder = 0;
}
Example #18
0
void decode_and_reconstruct_block_intra (uint8_t *rec, int stride, int size, int qp, uint8_t *pblock, int16_t *coeffq,
    int tb_split, int upright_available,int downleft_available, intra_mode_t intra_mode,int ypos,int xpos,int width,int comp, 
    qmtx_t ** iwmatrix){

  int16_t *rcoeff = thor_alloc(2*MAX_TR_SIZE*MAX_TR_SIZE, 16);
  int16_t *rblock = thor_alloc(2*MAX_TR_SIZE*MAX_TR_SIZE, 16);
  int16_t *rblock2 = thor_alloc(2*MAX_TR_SIZE*MAX_TR_SIZE, 16);

  uint8_t* left_data = (uint8_t*)thor_alloc(2*MAX_TR_SIZE+2,16)+1;
  uint8_t* top_data = (uint8_t*)thor_alloc(2*MAX_TR_SIZE+2,16)+1;
  uint8_t top_left;


  if (tb_split){
    int size2 = size/2;
    int i,j,index;
    for (i=0;i<size;i+=size2){
      for (j=0;j<size;j+=size2){
        make_top_and_left(left_data,top_data,&top_left,rec,stride,&rec[i*stride+j],stride,i,j,ypos,xpos,size2,upright_available,downleft_available,1);

        get_intra_prediction(left_data,top_data,top_left,ypos+i,xpos+j,size2,pblock,intra_mode);
        index = 2*(i/size2) + (j/size2);
        dequantize (coeffq+index*size2*size2, rcoeff, qp, size2, iwmatrix ? iwmatrix[log2i(size2/4)] : NULL, MAX_QUANT_SIZE);
        inverse_transform (rcoeff, rblock2, size2);
        reconstruct_block(rblock2,pblock,&rec[i*stride+j],size2,stride);
      }
    }
  }
  else{
    make_top_and_left(left_data,top_data,&top_left,rec,stride,NULL,0,0,0,ypos,xpos,size,upright_available,downleft_available,0);
    get_intra_prediction(left_data,top_data,top_left,ypos,xpos,size,pblock,intra_mode);
    dequantize (coeffq, rcoeff, qp, size, iwmatrix ? iwmatrix[log2i(size/4)] : NULL, MAX_QUANT_SIZE);
    inverse_transform (rcoeff, rblock, size);
    reconstruct_block(rblock,pblock,rec,size,stride);
  }

  thor_free(top_data - 1);
  thor_free(left_data - 1);
  thor_free(rcoeff);
  thor_free(rblock);
  thor_free(rblock2);
}
Example #19
0
void STree_Grow( STreeNode *pseudo, int nNodes ) {
   int nLeaves, nSpineNodes;

   nLeaves = nNodes + 1 - ( 1 << log2i( nNodes + 1 ) );
   STree_Compression( pseudo, nLeaves );
   nSpineNodes = nNodes - nLeaves;
   while ( nSpineNodes > 1 ) {
      nSpineNodes /= 2;
      STree_Compression( pseudo, nSpineNodes );
   }
}
Example #20
0
void check_parameters(enc_params *params)
{
  if(params->num_frames <= 0)
  {
    fatalerror("Number of frames must be positive");
  }
  if (params->width%8 || params->height%8)
  {
    fatalerror("Width and height must be a multiple of 8\n");
  }

  if (params->max_num_ref < 1 || params->max_num_ref > 4)
  {
    fatalerror("This number of max reference frames is not supported \n");
  }

  if(params->max_delta_qp >= 8)
  {
    fatalerror("max_delta_qp too large\n");
  }

  if(params->HQperiod >= MAX_REF_FRAMES)
  {
    fatalerror("HQperiod too large");
  }

  if (params->num_reorder_pics > 0 && params->HQperiod > 1 && (params->HQperiod % (params->num_reorder_pics+1))!=0) {
    fatalerror("Subgop length (num_reorder_pics+1) must divide HQperiod.\n");
  }

  if (params->dyadic_coding) {
    int nrp1 = params->num_reorder_pics+1;
    if (nrp1 != (1<<(log2i(nrp1)))) {
      fatalerror("num_reorder_pics+1 must be a power of 2 with dyadic coding.\n");
    }
  }

  if (params->num_reorder_pics > 0 && params->max_num_ref < 2) {
    fatalerror("More than one reference frame required for reordered pictures.\n");
  }

  if (params->intra_period % (params->num_reorder_pics+1)) {
    fatalerror("Intra period must be a multiple of the subgroup size (num_reorder_pics+1).\n");
  }

  if (params->sync && params->encoder_speed<2) {
    fatalerror("Sync requires encoder_speed=2\n");
  }

  if (params->bitrate > 0 && params->num_reorder_pics > 0){
    fatalerror("Current rate control doesn't work with frame reordering\n");
  }
}
Example #21
0
/*
 * Estimate the number of bisect steps left (after the current step)
 *
 * For any x between 0 included and 2^n excluded, the probability for
 * n - 1 steps left looks like:
 *
 * P(2^n + x) == (2^n - x) / (2^n + x)
 *
 * and P(2^n + x) < 0.5 means 2^n < 3x
 */
int estimate_bisect_steps(int all)
{
	int n, x, e;

	if (all < 3)
		return 0;

	n = log2i(all);
	e = exp2i(n);
	x = all - e;

	return (e < 3 * x) ? n : n - 1;
}
Example #22
0
IUnknown* DX11Engine::createTexture2D_SRV(IUnknown* pDeviceIn, const Texture& info, 
    const char* buffer, size_t size, const char* name) const
{
    auto pDevice = reinterpret_cast<ID3D11Device*>(pDeviceIn);

    HRESULT hr;
    D3D11_TEXTURE2D_DESC tex = {
        uint32_t(info.mWidth), uint32_t(info.mHeight),
        uint32_t(info.mMipCount), uint32_t(info.mArraySize), info.mFormat, { 1, 0 },
        D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE,
        0, 0
    };

    if(info.eMiscGenerateMipMaps) {
        tex.MipLevels = 0;
        tex.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
        tex.BindFlags |= D3D11_BIND_RENDER_TARGET;
    }

    uint32_t bpp = getBitsPerPixel(info.mFormat);

    int level = 1;
    if (info.eMiscGenerateMipMaps)
        level = log2i(std::max(info.mWidth, info.mHeight)) + 1;

    boost::container::small_vector<D3D11_SUBRESOURCE_DATA, 12> subres(level);

    int w = info.mWidth;
    int h = info.mHeight;

    for (int i = 0; i != level; ++i) {
        subres[i] = D3D11_SUBRESOURCE_DATA{ buffer, w * bpp / 8, 0 };
        buffer += mipmap_size<1>(w, h, bpp);
        w = next_mip_size(w);
        h = next_mip_size(h);        
    }

    std::unique_ptr<ID3D11Texture2D, COMDeleter> pTex;

    std::unique_ptr<ID3D11ShaderResourceView, COMDeleter> pSRV;
    CD3D11_SHADER_RESOURCE_VIEW_DESC srvDesc(D3D11_SRV_DIMENSION_TEXTURE2D);

    V(pDevice->CreateTexture2D(&tex, subres.data(), ref(pTex)));
    V(pDevice->CreateShaderResourceView(pTex.get(), &srvDesc, ref(pSRV)));

    STAR_SET_DEBUG_NAME(pSRV, size, name);

    return pSRV.release();
}
Example #23
0
/* static */
int UIWizardNewVDPage3::calculateSliderScale(qulonglong uMaximumMediumSize)
{
    /* Detect how many steps to recognize between adjacent powers of 2
     * to ensure that the last slider step is exactly that we need: */
    int iSliderScale = 0;
    int iPower = log2i(uMaximumMediumSize);
    qulonglong uTickMB = (qulonglong)1 << iPower;
    if (uTickMB < uMaximumMediumSize)
    {
        qulonglong uTickMBNext = (qulonglong)1 << (iPower + 1);
        qulonglong uGap = uTickMBNext - uMaximumMediumSize;
        iSliderScale = (int)((uTickMBNext - uTickMB) / uGap);
    }
    return qMax(iSliderScale, 8);
}
Example #24
0
    void configure() {
        if (m_nested == NULL)
            Log(EError, "A nested volume data source is needed!");
        m_aabb = m_nested->getAABB();
        if (!m_aabb.isValid())
            Log(EError, "Nested axis-aligned bounding box was invalid!");

        if (m_voxelWidth == -1)
            m_voxelWidth = m_nested->getStepSize();

        size_t memoryLimitPerCore = m_memoryLimit
                                    / std::max((size_t) 1, Scheduler::getInstance()->getLocalWorkerCount());

        Vector totalCells  = m_aabb.getExtents() / m_voxelWidth;
        for (int i=0; i<3; ++i)
            m_cellCount[i] = (int) std::ceil(totalCells[i]);

        if (m_nested->supportsFloatLookups())
            m_channels = 1;
        else if (m_nested->supportsVectorLookups())
            m_channels = 1;
        else if (m_nested->supportsSpectrumLookups())
            m_channels = SPECTRUM_SAMPLES;
        else
            Log(EError, "Nested volume offers no access methods!");

        m_blockRes = m_blockSize+1;
        int blockMemoryUsage = (int) std::pow((Float) m_blockRes, 3) * m_channels * sizeof(float);
        m_blocksPerCore = memoryLimitPerCore / blockMemoryUsage;

        m_worldToVolume = m_volumeToWorld.inverse();
        m_worldToGrid = Transform::scale(Vector(1/m_voxelWidth))
                        * Transform::translate(-Vector(m_aabb.min)) * m_worldToVolume;
        m_voxelMask = m_blockSize-1;
        m_blockMask = ~(m_blockSize-1);
        m_blockShift = log2i((uint32_t) m_blockSize);

        Log(EInfo, "Volume cache configuration");
        Log(EInfo, "   Block size in voxels      = %i", m_blockSize);
        Log(EInfo, "   Voxel width               = %f", m_voxelWidth);
        Log(EInfo, "   Memory usage of one block = %s", memString(blockMemoryUsage).c_str());
        Log(EInfo, "   Memory limit              = %s", memString(m_memoryLimit).c_str());
        Log(EInfo, "   Memory limit per core     = %s", memString(memoryLimitPerCore).c_str());
        Log(EInfo, "   Max. blocks per core      = %i", m_blocksPerCore);
        Log(EInfo, "   Effective resolution      = %s", totalCells.toString().c_str());
        Log(EInfo, "   Effective storage         = %s", memString((size_t)
                (totalCells[0]*totalCells[1]*totalCells[2]*sizeof(float)*m_channels)).c_str());
    }
Example #25
0
/*************************************************************************
* This function is the entry point for KWMETIS
**************************************************************************/
void METIS_WPartGraphKway(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, 
                          idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts, 
                          float *tpwgts, int *options, int *edgecut, idxtype *part)
{
  int i, j;
  GraphType graph;
  CtrlType ctrl;

  if (*numflag == 1)
    Change2CNumbering(*nvtxs, xadj, adjncy);

  SetUpGraph(&graph, OP_KMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, *wgtflag);

  if (options[0] == 0) {  /* Use the default parameters */
    ctrl.CType = KMETIS_CTYPE;
    ctrl.IType = KMETIS_ITYPE;
    ctrl.RType = KMETIS_RTYPE;
    ctrl.dbglvl = KMETIS_DBGLVL;
  }
  else {
    ctrl.CType = options[OPTION_CTYPE];
    ctrl.IType = options[OPTION_ITYPE];
    ctrl.RType = options[OPTION_RTYPE];
    ctrl.dbglvl = options[OPTION_DBGLVL];
  }
  ctrl.optype = OP_KMETIS;
  ctrl.CoarsenTo = amax((*nvtxs)/(40*log2i(*nparts)), 20*(*nparts));
  ctrl.maxvwgt = 1.5*((graph.vwgt ? idxsum(*nvtxs, graph.vwgt) : (*nvtxs))/ctrl.CoarsenTo);

  InitRandom(-1);

  AllocateWorkSpace(&ctrl, &graph, *nparts);

  IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl));
  IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr));

  *edgecut = MlevelKWayPartitioning(&ctrl, &graph, *nparts, part, tpwgts, 1.03);

  IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr));
  IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl));

  FreeWorkSpace(&ctrl, &graph);

  if (*numflag == 1)
    Change2FNumbering(*nvtxs, xadj, adjncy, part);
}
Example #26
0
void preproc_emit_line_info(int lineno, const char *fname, enum lineinfo lineinfo)
{
	unsigned lineinfobits = lineinfo;
	/* output PP info */
	if(no_output || !option_line_info)
		return;

	printf("# %d \"%s\"", lineno, fname);

	while(lineinfobits){
		unsigned bit = extractbottombit(&lineinfobits);
		int n = log2i(bit);

		printf(" %d", n);
	}

	putchar('\n');
}
Example #27
0
sexp sexp_write_bignum (sexp ctx, sexp a, sexp out, sexp_uint_t base) {
  int i, str_len, lg_base = log2i(base);
  char *data;
  sexp_gc_var2(b, str);
  sexp_gc_preserve2(ctx, b, str);
  b = sexp_copy_bignum(ctx, NULL, a, 0);
  sexp_bignum_sign(b) = 1;
  i = str_len = (sexp_bignum_length(b)*sizeof(sexp_uint_t)*8 + lg_base - 1)
    / lg_base + 1;
  str = sexp_make_string(ctx, sexp_make_fixnum(str_len),
                         sexp_make_character(' '));
  data = sexp_string_data(str);
  while (! sexp_bignum_zerop(b))
    data[--i] = hex_digit(sexp_bignum_fxdiv(ctx, b, base, 0));
  if (i == str_len)
    data[--i] = '0';
  else if (sexp_bignum_sign(a) == -1)
    data[--i] = '-';
  sexp_write_string(ctx, data + i, out);
  sexp_gc_release2(ctx);
  return SEXP_VOID;
}
Example #28
0
	void setFilmResolution(const Vector2i &res, bool blocked) {
		if (blocked) {
			/* Determine parameters of the space partition in the first two
			   dimensions. This is required to support blocked rendering. */
			for (int i=0; i<2; ++i)
				m_resolution[i] = std::min((uint32_t) MAX_RESOLUTION,
					roundToPowerOfTwo((uint32_t) res[i]));
			m_logHeight = log2i((uint32_t) m_resolution.y);

			m_samplesPerBatch = m_sampleCount;
			m_factor = (Float) 1.0f / (m_sampleCount *
				(size_t) m_resolution.x * (size_t) m_resolution.y);
			m_offset = 0;
			m_stride = m_resolution.y;
		} else {
			m_samplesPerBatch = m_sampleCount *
				(size_t) res.x * (size_t) res.y;
			m_factor = (Float) 1.0f / m_samplesPerBatch;
			m_resolution = Vector2i(1);
			m_offset = 0;
			m_stride = 1;
		}
		m_pixelPosition = Point2i(0);
	}
Example #29
0
static ALCenum oss_open_capture(ALCdevice *device, const ALCchar *deviceName)
{
    int numFragmentsLogSize;
    int log2FragmentSize;
    unsigned int periods;
    audio_buf_info info;
    ALuint frameSize;
    int numChannels;
    oss_data *data;
    int ossFormat;
    int ossSpeed;
    char *err;

    if(!deviceName)
        deviceName = oss_device;
    else if(strcmp(deviceName, oss_device) != 0)
        return ALC_INVALID_VALUE;

    data = (oss_data*)calloc(1, sizeof(oss_data));
    data->killNow = 0;

    data->fd = open(oss_capture, O_RDONLY);
    if(data->fd == -1)
    {
        free(data);
        ERR("Could not open %s: %s\n", oss_capture, strerror(errno));
        return ALC_INVALID_VALUE;
    }

    switch(device->FmtType)
    {
        case DevFmtByte:
            ossFormat = AFMT_S8;
            break;
        case DevFmtUByte:
            ossFormat = AFMT_U8;
            break;
        case DevFmtShort:
            ossFormat = AFMT_S16_NE;
            break;
        case DevFmtUShort:
        case DevFmtInt:
        case DevFmtUInt:
        case DevFmtFloat:
            free(data);
            ERR("%s capture samples not supported\n", DevFmtTypeString(device->FmtType));
            return ALC_INVALID_VALUE;
    }

    periods = 4;
    numChannels = ChannelsFromDevFmt(device->FmtChans);
    frameSize = numChannels * BytesFromDevFmt(device->FmtType);
    ossSpeed = device->Frequency;
    log2FragmentSize = log2i(device->UpdateSize * device->NumUpdates *
                             frameSize / periods);

    /* according to the OSS spec, 16 bytes are the minimum */
    if (log2FragmentSize < 4)
        log2FragmentSize = 4;
    numFragmentsLogSize = (periods << 16) | log2FragmentSize;

#define CHECKERR(func) if((func) < 0) {                                       \
    err = #func;                                                              \
    goto err;                                                                 \
}
    CHECKERR(ioctl(data->fd, SNDCTL_DSP_SETFRAGMENT, &numFragmentsLogSize));
    CHECKERR(ioctl(data->fd, SNDCTL_DSP_SETFMT, &ossFormat));
    CHECKERR(ioctl(data->fd, SNDCTL_DSP_CHANNELS, &numChannels));
    CHECKERR(ioctl(data->fd, SNDCTL_DSP_SPEED, &ossSpeed));
    CHECKERR(ioctl(data->fd, SNDCTL_DSP_GETISPACE, &info));
    if(0)
    {
    err:
        ERR("%s failed: %s\n", err, strerror(errno));
        close(data->fd);
        free(data);
        return ALC_INVALID_VALUE;
    }
#undef CHECKERR

    if((int)ChannelsFromDevFmt(device->FmtChans) != numChannels)
    {
        ERR("Failed to set %s, got %d channels instead\n", DevFmtChannelsString(device->FmtChans), numChannels);
        close(data->fd);
        free(data);
        return ALC_INVALID_VALUE;
    }

    if(!((ossFormat == AFMT_S8 && device->FmtType == DevFmtByte) ||
         (ossFormat == AFMT_U8 && device->FmtType == DevFmtUByte) ||
         (ossFormat == AFMT_S16_NE && device->FmtType == DevFmtShort)))
    {
        ERR("Failed to set %s samples, got OSS format %#x\n", DevFmtTypeString(device->FmtType), ossFormat);
        close(data->fd);
        free(data);
        return ALC_INVALID_VALUE;
    }

    data->ring = CreateRingBuffer(frameSize, device->UpdateSize * device->NumUpdates);
    if(!data->ring)
    {
        ERR("Ring buffer create failed\n");
        close(data->fd);
        free(data);
        return ALC_OUT_OF_MEMORY;
    }

    data->data_size = info.fragsize;
    data->mix_data = calloc(1, data->data_size);

    device->ExtraData = data;
    data->thread = StartThread(OSSCaptureProc, device);
    if(data->thread == NULL)
    {
        device->ExtraData = NULL;
        free(data->mix_data);
        free(data);
        return ALC_OUT_OF_MEMORY;
    }

    device->szDeviceName = strdup(deviceName);
    return ALC_NO_ERROR;
}
Example #30
0
static ALCboolean oss_reset_playback(ALCdevice *device)
{
    oss_data *data = (oss_data*)device->ExtraData;
    int numFragmentsLogSize;
    int log2FragmentSize;
    unsigned int periods;
    audio_buf_info info;
    ALuint frameSize;
    int numChannels;
    int ossFormat;
    int ossSpeed;
    char *err;

    switch(device->FmtType)
    {
        case DevFmtByte:
            ossFormat = AFMT_S8;
            break;
        case DevFmtUByte:
            ossFormat = AFMT_U8;
            break;
        case DevFmtUShort:
        case DevFmtInt:
        case DevFmtUInt:
        case DevFmtFloat:
            device->FmtType = DevFmtShort;
            /* fall-through */
        case DevFmtShort:
            ossFormat = AFMT_S16_NE;
            break;
    }

    periods = device->NumUpdates;
    numChannels = ChannelsFromDevFmt(device->FmtChans);
    frameSize = numChannels * BytesFromDevFmt(device->FmtType);

    ossSpeed = device->Frequency;
    log2FragmentSize = log2i(device->UpdateSize * frameSize);

    /* according to the OSS spec, 16 bytes are the minimum */
    if (log2FragmentSize < 4)
        log2FragmentSize = 4;
    /* Subtract one period since the temp mixing buffer counts as one. Still
     * need at least two on the card, though. */
    if(periods > 2) periods--;
    numFragmentsLogSize = (periods << 16) | log2FragmentSize;

#define CHECKERR(func) if((func) < 0) {                                       \
    err = #func;                                                              \
    goto err;                                                                 \
}
    /* Don't fail if SETFRAGMENT fails. We can handle just about anything
     * that's reported back via GETOSPACE */
    ioctl(data->fd, SNDCTL_DSP_SETFRAGMENT, &numFragmentsLogSize);
    CHECKERR(ioctl(data->fd, SNDCTL_DSP_SETFMT, &ossFormat));
    CHECKERR(ioctl(data->fd, SNDCTL_DSP_CHANNELS, &numChannels));
    CHECKERR(ioctl(data->fd, SNDCTL_DSP_SPEED, &ossSpeed));
    CHECKERR(ioctl(data->fd, SNDCTL_DSP_GETOSPACE, &info));
    if(0)
    {
    err:
        ERR("%s failed: %s\n", err, strerror(errno));
        return ALC_FALSE;
    }
#undef CHECKERR

    if((int)ChannelsFromDevFmt(device->FmtChans) != numChannels)
    {
        ERR("Failed to set %s, got %d channels instead\n", DevFmtChannelsString(device->FmtChans), numChannels);
        return ALC_FALSE;
    }

    if(!((ossFormat == AFMT_S8 && device->FmtType == DevFmtByte) ||
         (ossFormat == AFMT_U8 && device->FmtType == DevFmtUByte) ||
         (ossFormat == AFMT_S16_NE && device->FmtType == DevFmtShort)))
    {
        ERR("Failed to set %s samples, got OSS format %#x\n", DevFmtTypeString(device->FmtType), ossFormat);
        return ALC_FALSE;
    }

    device->Frequency = ossSpeed;
    device->UpdateSize = info.fragsize / frameSize;
    device->NumUpdates = info.fragments + 1;

    SetDefaultChannelOrder(device);

    return ALC_TRUE;
}