Skip to content
Snippets Groups Projects
postprocess.c 31.6 KiB
Newer Older
  • Learn to ignore specific revisions
  • pp_context_t *pp_get_context(int width, int height, int cpuCaps){
    	PPContext *c= memalign(32, sizeof(PPContext));
    	int stride= (width+15)&(~15); //assumed / will realloc if needed
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed
    
    	memset(c, 0, sizeof(PPContext));
    	c->cpuCaps= cpuCaps;
    
    	if(cpuCaps&PP_FORMAT){
    		c->hChromaSubSample= cpuCaps&0x3;
    		c->vChromaSubSample= (cpuCaps>>4)&0x3;
    	}else{
    		c->hChromaSubSample= 1;
    		c->vChromaSubSample= 1;
    	}
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	reallocBuffers(c, width, height, stride, qpStride);
    
    	c->frameNum=-1;
    
    	return c;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    void pp_free_context(void *vc){
    
    	PPContext *c = (PPContext*)vc;
    	int i;
    	
    	for(i=0; i<3; i++) free(c->tempBlured[i]);
    	for(i=0; i<3; i++) free(c->tempBluredPast[i]);
    	
    	free(c->tempBlocks);
    	free(c->yHistogram);
    	free(c->tempDst);
    	free(c->tempSrc);
    	free(c->deintTemp);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	free(c->stdQPTable);
    
    	free(c->nonBQPTable);
    
    	free(c->forcedQPTable);
            
    	memset(c, 0, sizeof(PPContext));
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    void  pp_postprocess(uint8_t * src[3], int srcStride[3],
    
                     uint8_t * dst[3], int dstStride[3],
    
                     int width, int height,
    
                     QP_STORE_T *QP_store,  int QPStride,
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		 pp_mode_t *vm,  void *vc, int pict_type)
    
    	int mbWidth = (width+15)>>4;
    	int mbHeight= (height+15)>>4;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	PPMode *mode = (PPMode*)vm;
    
    	PPContext *c = (PPContext*)vc;
    
            int minStride= MAX(srcStride[0], dstStride[0]);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    	if(c->stride < minStride || c->qpStride < QPStride)
    		reallocBuffers(c, width, height, 
    				MAX(minStride, c->stride), 
    				MAX(c->qpStride, QPStride));
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	if(QP_store==NULL || (mode->lumMode & FORCE_QUANT)) 
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		int i;
    
    		QP_store= c->forcedQPTable;
    
    		QPStride= 0;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		if(mode->lumMode & FORCE_QUANT)
    
    			for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		else
    
    			for(i=0; i<mbWidth; i++) QP_store[i]= 1;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    //printf("pict_type:%d\n", pict_type);
    
    	if(pict_type & PP_PICT_TYPE_QP2){
    		int i;
    		const int count= mbHeight * QPStride;
    		for(i=0; i<(count>>2); i++){
    			((uint32_t*)c->stdQPTable)[i] = (((uint32_t*)QP_store)[i]>>1) & 0x7F7F7F7F;
    		}
    		for(i<<=2; i<count; i++){
    			c->stdQPTable[i] = QP_store[i]>>1;
    		}
                    QP_store= c->stdQPTable;
    	}
    
    
    if(0){
    int x,y;
    for(y=0; y<mbHeight; y++){
    	for(x=0; x<mbWidth; x++){
    		printf("%2d ", QP_store[x + y*QPStride]);
    	}
    	printf("\n");
    }
    	printf("\n");
    }
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	if((pict_type&7)!=3)
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		int i;
    		const int count= mbHeight * QPStride;
    		for(i=0; i<(count>>2); i++){
    
    			((uint32_t*)c->nonBQPTable)[i] = ((uint32_t*)QP_store)[i] & 0x3F3F3F3F;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    		}
    		for(i<<=2; i<count; i++){
    
    			c->nonBQPTable[i] = QP_store[i] & 0x3F;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    	if(verbose>2)
    
    	{
    		printf("using npp filters 0x%X/0x%X\n", mode->lumMode, mode->chromMode);
    	}
    
    
    	postProcess(src[0], srcStride[0], dst[0], dstStride[0],
    
    		width, height, QP_store, QPStride, 0, mode, c);
    
    	width  = (width )>>c->hChromaSubSample;
    	height = (height)>>c->vChromaSubSample;
    
    		postProcess(src[1], srcStride[1], dst[1], dstStride[1],
    
    			width, height, QP_store, QPStride, 1, mode, c);
    
    		postProcess(src[2], srcStride[2], dst[2], dstStride[2],
    
    			width, height, QP_store, QPStride, 2, mode, c);
    
    	else if(srcStride[1] == dstStride[1] && srcStride[2] == dstStride[2])
    
    		memcpy(dst[1], src[1], srcStride[1]*height);
    		memcpy(dst[2], src[2], srcStride[2]*height);
    
    		for(y=0; y<height; y++)
    
    			memcpy(&(dst[1][y*dstStride[1]]), &(src[1][y*srcStride[1]]), width);
    			memcpy(&(dst[2][y*dstStride[2]]), &(src[2][y*srcStride[2]]), width);