uint8_t ADMVideoEq2::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { ADMImage *mysrc=NULL; if(frame>=_info.nb_frames) return 0; mysrc=vidCache->getImage(frame); if(!mysrc) return 0; uint32_t w,h; w=_info.width; h=_info.height; #ifdef ADM_CPU_X86 if(CpuCaps::hasMMX()) { affine_1d_MMX(&(settings.param[0]),YPLANE(data),YPLANE(mysrc),w,h); w>>=1; h>>=1; affine_1d_MMX(&(settings.param[2]),UPLANE(data),UPLANE(mysrc),w,h); affine_1d_MMX(&(settings.param[1]),VPLANE(data),VPLANE(mysrc),w,h); } else #endif {
// // Remove y and v just keep U and expand it // uint8_t ADMVideoDenoise::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { //uint32_t x,w; uint32_t page; ADM_assert(_param); if(frame>= _info.nb_frames) return 0; if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; page=_info.width*_info.height; *len=(page*3)>>1; if((_lastFrame+1)!=frame) // async jump { // just copy it memcpy(YPLANE(data),YPLANE(_uncompressed),page); memcpy(UPLANE(data),UPLANE(_uncompressed),page>>2); memcpy(VPLANE(data),VPLANE(_uncompressed),page>>2); memcpy(YPLANE(_locked),YPLANE(_uncompressed),page); memcpy(UPLANE(_locked),UPLANE(_uncompressed),page>>2); memcpy(VPLANE(_locked),VPLANE(_uncompressed),page>>2); _lastFrame=frame; return 1; }
uint8_t ADMVideoDeinterlace::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { //uint8_t *dst,*dstu,*dstv,*srcu,*srcv; uint32_t uvlen; if(frame>=_info.nb_frames) return 0; // read uncompressed frame if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; uvlen= _info.width*_info.height; *len= (uvlen*3)>>1; // No interleaving detected if(!hasMotion(_uncompressed)) { data->duplicate(_uncompressed); } else { //printf("Blending\n"); doBlend(_uncompressed,data); memcpy(UPLANE(data),UPLANE(_uncompressed),uvlen>>2); memcpy(VPLANE(data),VPLANE(_uncompressed),uvlen>>2); data->copyInfo(_uncompressed); } return 1; }
uint8_t ADMVideoMosaic::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { if(frame>=_info.nb_frames) { printf("Filter : out of bound!\n"); return 0; } ADM_assert(_param); ADMImage *curImage; char txt[256]; for(int y=0;y<_param->vz;y++) for(int x=0;x<_param->hz;x++) { curImage=vidCache->getImage(frame+y*_param->hz+x); if(!curImage) continue; if(_param->show) { sprintf(txt," %02d",frame+x+y*_param->hz); drawString(curImage,2,0,txt); } uint8_t *src[3]; uint8_t *dst[3]; int ssrc[3]; int ddst[3]; uint32_t page; page=_in->getInfo()->width*_in->getInfo()->height; src[0]=YPLANE(curImage); src[1]=UPLANE(curImage); src[2]=VPLANE(curImage); ssrc[0]=_in->getInfo()->width; ssrc[1]=ssrc[2]=_in->getInfo()->width>>1; page=_info.width*tinyH; dst[0]=YPLANE(data)+page*y+tinyW*x; dst[1]=UPLANE(data)+((page*y)/4)+((tinyW*x)/2); dst[2]=VPLANE(data)+((page*y)/4)+((tinyW*x)/2); ddst[0]=_info.width; ddst[1]=ddst[2]=_info.width>>1; sws_scale(_context,src,ssrc,0,_in->getInfo()->height,dst,ddst); } vidCache->unlockAll(); return 1; }
//************************************************************* uint8_t ADMVideoLavPPDeint::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { if(frame>= _info.nb_frames) return 0; // read uncompressed frame if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; // const uint8_t *iBuff[3]; uint8_t *oBuff[3]; int strideTab[3],strideTab2[3]; oBuff[0]=YPLANE(data); oBuff[1]=UPLANE(data); oBuff[2]=VPLANE(data); iBuff[0]=YPLANE(_uncompressed); iBuff[1]=UPLANE(_uncompressed); iBuff[2]=VPLANE(_uncompressed); strideTab[0]=strideTab2[0]=_info.width; strideTab[1]=strideTab2[1]=_info.width>>1; strideTab[2]=strideTab2[2]=_info.width>>1; int type; if(_uncompressed->flags&AVI_KEY_FRAME) type=1; else if(_uncompressed->flags & AVI_B_FRAME) type=3; else type=2; pp_postprocess( iBuff, strideTab, oBuff, strideTab2, _info.width, _info.height, NULL, 0, ppmode, ppcontext, type); // I ? data->copyInfo(_uncompressed); return 1; }
uint8_t ADMVideoFlipV::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { if(frame>= _info.nb_frames) return 0; // read uncompressed frame if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; uint8_t *in,*out; uint32_t stride=_info.width; uint32_t h=_info.height; uint32_t page,qpage; page=stride*h; qpage=page>>2; in=YPLANE(_uncompressed); out=YPLANE(data)+(h-1)*stride; // flip y for(uint32_t y=h;y>0;y--) { memcpy(out,in,stride); in+=stride; out-=stride; } // Flip U & V stride>>=1; in=UPLANE(_uncompressed); out=UPLANE(data)+qpage-stride; // flip u for(uint32_t y=h>>1;y>0;y--) { memcpy(out,in,stride); in+=stride; out-=stride; } in=VPLANE(_uncompressed); out=VPLANE(data)+qpage-stride; // flip u for(uint32_t y=h>>1;y>0;y--) { memcpy(out,in,stride); in+=stride; out-=stride; } data->copyInfo(_uncompressed); return 1; }
uint8_t AVDM_Fade::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data,uint32_t *flags) { uint32_t num_frames,tgt; ADMImage *src; num_frames=_info.nb_frames; // ?? tgt=frame+_info.orgFrame; if(frame>=num_frames) { printf("[Fade] out of bound\n"); return 0; } src=vidCache->getImage(tgt); if(!src) return 0; if(tgt>_param->endFade || tgt <_param->startFade ||_param->endFade==_param->startFade ) { data->duplicate(src); vidCache->unlockAll(); return 1; } uint8_t *s,*d,*index; uint32_t count=_info.width*_info.height,w; float num,den; den=_param->endFade-_param->startFade; num=tgt-_param->startFade; num=num/den; num*=255.; w=(uint32_t)floor(num+0.4); s=src->data; d=data->data; index=lookup[w]; for(int i=0;i<count;i++) { *d++=index[*s++]; } memcpy(UPLANE(data),UPLANE(src),count>>2); memcpy(VPLANE(data),VPLANE(src),count>>2); vidCache->unlockAll(); return 1; }
static uint8_t unblend(ADMImage *tgt,ADMImage *src,ADMImage *srcP) { int delta; uint32_t ww,hh; uint8_t *s1,*s2,*d1; int a1,a2,t1; tinyUnblend(YPLANE(tgt),YPLANE(src),YPLANE(srcP),tgt->_width,tgt->_height); tinyUnblend(UPLANE(tgt),UPLANE(src),UPLANE(srcP),tgt->_width>>1,tgt->_height>>1); tinyUnblend(VPLANE(tgt),VPLANE(src),VPLANE(srcP),tgt->_width>>1,tgt->_height>>1); return 1; }
static uint8_t restore(ADMImage *tgt,ADMImage *srcP,ADMImage *src,ADMImage *srcN,ADMImage *srcNN) { int delta; uint32_t ww,hh; uint8_t *s1,*s2,*d1; int a1,a2,t1; tinyRestore(YPLANE(tgt),YPLANE(srcP),YPLANE(src),YPLANE(srcN),YPLANE(srcNN),tgt->_width,tgt->_height); tinyRestore(UPLANE(tgt),UPLANE(srcP),UPLANE(src),UPLANE(srcN),UPLANE(srcNN),tgt->_width>>1,tgt->_height>>1); tinyRestore(VPLANE(tgt),VPLANE(srcP),VPLANE(src),VPLANE(srcN),VPLANE(srcNN),tgt->_width>>1,tgt->_height>>1); return 1; }
ADMVideoDenoise::ADMVideoDenoise( AVDMGenericVideoStream *in,CONFcouple *couples) { if(distMatrixDone==false) { buildDistMatrix(); distMatrixDone=true; } _in=in; memcpy(&_info,_in->getInfo(),sizeof(_info)); uint32_t page; _info.encoding=1; page= _in->getInfo()->width*_in->getInfo()->height; // _uncompressed=new uint8_t [page]; _uncompressed=new ADMImage(_in->getInfo()->width,_in->getInfo()->height); ADM_assert(_uncompressed); // _locked=new uint8_t [page]; _locked=new ADMImage(_in->getInfo()->width,_in->getInfo()->height); ADM_assert(_locked); // _lockcount=new uint8_t [page]; _lockcount=new ADMImage(_in->getInfo()->width,_in->getInfo()->height); memset(YPLANE(_lockcount),0,page); memset(UPLANE(_lockcount),0,page>>2); memset(VPLANE(_lockcount),0,page>>2); _param=NULL; if(couples) { _param=NEW(NOISE_PARAM); GET(lumaLock); GET(lumaThreshold); GET(chromaLock); GET(chromaThreshold); GET(sceneChange); } else { #define XXX 1 _param=NEW(NOISE_PARAM); _param->lumaLock= 4*XXX; _param->lumaThreshold= 10*XXX; _param->chromaLock= 8*XXX; _param->chromaThreshold= 16*XXX; _param->sceneChange= 30*XXX; } _lastFrame=0xfffffff0; }
uint8_t flyEq2::process(void) { Eq2Settings mySettings; #if 0 printf("Contrast :%f\n",param.contrast); printf("brightness :%f\n",param.brightness); printf("saturation :%f\n",param.saturation); printf("gamma_weight :%f\n",param.gamma_weight); printf("gamma :%f\n",param.gamma); printf("rgamma :%f\n",param.rgamma); printf("bgamma :%f\n",param.bgamma); printf("ggamma :%f\n",param.ggamma); printf("******************\n"); #endif update_lut(&mySettings,¶m); typedef void lutMeType(oneSetting *par, unsigned char *dst, unsigned char *src, unsigned int w, unsigned int h); lutMeType *lutMe=apply_lut; #ifdef ADM_CPU_X86 if(CpuCaps::hasMMX()) { lutMe=affine_1d_MMX; } #endif lutMe(&(mySettings.param[0]),YPLANE(_yuvBufferOut),YPLANE(_yuvBuffer),_w,_h); lutMe(&(mySettings.param[2]),UPLANE(_yuvBufferOut),UPLANE(_yuvBuffer),_w>>1,_h>>1); lutMe(&(mySettings.param[1]),VPLANE(_yuvBufferOut),VPLANE(_yuvBuffer),_w>>1,_h>>1); #if 1 _yuvBuffer->copyLeftSideTo(_yuvBufferOut); #endif return 1; }
uint8_t AVDMVideoHzStackField::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { uint32_t ref,ref2; ADMImage *ptr1,*ptr2; if(frame>=_info.nb_frames) return 0; if(!_in->getFrameNumberNoAlloc(frame, len, _uncompressed, flags)) return 0; uint32_t pg=_info.width*_info.height; // Duplicate _uncompressed memcpy(YPLANE(data),YPLANE(_uncompressed),pg); memcpy(UPLANE(data),UPLANE(_uncompressed),pg>>2); memcpy(VPLANE(data),VPLANE(_uncompressed),pg>>2); return 1; }
uint8_t AVDMVideoSwapField::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { //static Image in,out; if(frame>=_info.nb_frames) return 0; // read uncompressed frame if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; uint32_t w=_info.width; uint32_t h=_info.height; uint32_t page=w*h; uint32_t stride; // copy u & v memcpy(UPLANE(data),UPLANE(_uncompressed),page>>2); memcpy(VPLANE(data),VPLANE(_uncompressed),page>>2); uint8_t *odd,*even,*target,*target2; even=YPLANE(_uncompressed); odd=even+w; target=YPLANE(data); target2=YPLANE(data)+w; stride=2*w; h>>=1; for(;h--;h>0) { memcpy(target,odd,w); memcpy(target2,even,w); target+=stride; target2+=stride; odd+=stride; even+=stride; } data->copyInfo(_uncompressed); return 1; }
uint8_t AVDMVideoStreamMPResize::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { if(frame>=_info.nb_frames) { printf("Filter : out of bound!\n"); return 0; } ADM_assert(_param); if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; uint8_t *src[3]; uint8_t *dst[3]; int ssrc[3]; int ddst[3]; uint32_t page; page=_in->getInfo()->width*_in->getInfo()->height; src[0]=YPLANE(_uncompressed); src[1]=UPLANE(_uncompressed); src[2]=VPLANE(_uncompressed); ssrc[0]=_in->getInfo()->width; ssrc[1]=ssrc[2]=_in->getInfo()->width>>1; page=_info.width*_info.height; dst[0]=YPLANE(data); dst[1]=UPLANE(data); dst[2]=VPLANE(data); ddst[0]=_info.width; ddst[1]=ddst[2]=_info.width>>1; sws_scale(_context,src,ssrc,0,_in->getInfo()->height,dst,ddst); data->copyInfo(_uncompressed); return 1; }
// // Remove y and v just keep U and expand it // uint8_t ADMVideoChromaV::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { uint32_t w,x; uint32_t page; if(frame>= _info.nb_frames) return 0; if(!_in->getFrameNumberNoAlloc(frame, len,data,flags)) return 0; page= _info.width*_info.height; *len=(page*3)>>1; // now expand u uint8_t *y,*v,*y2; y=YPLANE(data); y2=y+_info.width; v=VPLANE(data); for(w= _info.height>>1;w>0;w--) { for(x= _info.width>>1;x>0;x--) { *y=*v; *y2=*v; *(y+1)=*v; *(y2+1)=*v; v++; y+=2; y2+=2; } y+=_info.width; y2+=_info.width; } // Remove chroma u & v memset(UPLANE(data),0x80,page>>2); memset(VPLANE(data),0x80,page>>2); }
/** * \fn copyLeftSideTo * \brief Copy half the image (left part) to dest * @param dest : Image to copy to */ uint8_t ADMImage::copyLeftSideTo(ADMImage *dest) { uint8_t *src,*dst; uint32_t stride; ADM_assert(_width==dest->_width); ADM_assert(_height==dest->_height); dst=YPLANE(dest); src=YPLANE(this); stride=_width; for(uint32_t y=0;y<_height;y++) // We do both u & v! { memcpy(dst,src,stride>>1); dst+=stride; src+=stride; } // U dst=UPLANE(dest); src=UPLANE(this); stride=_width>>1; uint32_t h2=_height>>1; for(uint32_t y=0;y<h2;y++) // We do both u & v! { memcpy(dst,src,stride>>1); dst+=stride; src+=stride; } // V dst=VPLANE(dest); src=VPLANE(this); for(uint32_t y=0;y<h2;y++) // We do both u & v! { memcpy(dst,src,stride>>1); dst+=stride; src+=stride; } return 1; }
uint8_t ADMVideoPullDown::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { //static Image in,out; if(frame>=_info.nb_frames) { printf("out of bound frame (%lu / %lu)\n",frame,_info.nb_frames); return 0; } uint32_t w=_info.width; uint32_t h=_info.height; uint32_t page=w*h; uint32_t i; uint32_t target; uint32_t loop=0; *len=(page*3)>>1; cont: target=frame-((frame)%5); // got it ? if(_cacheStart==target) { uint32_t index; aprintf("Filter: It is in cache...(cachestart=%lu)\n",_cacheStart); index=frame%5; aprintf("getting %lu)\n",index); memcpy(YPLANE(data),YPLANE(_uncompressed[index]),page); memcpy(UPLANE(data),UPLANE(_uncompressed[index]),page>>2); memcpy(VPLANE(data),VPLANE(_uncompressed[index]),page>>2); *flags=0; return 1; }
static uint8_t restore(ADMImage *tgt,ADMImage *srcP,ADMImage *src,ADMImage *srcN,ADMImage *srcNN) { int delta; uint32_t ww,hh; uint8_t *s1,*s2,*d1; int a1,a2,t1; #if defined (ARCH_X86 ) || defined (ARCH_X86_64 ) if(CpuCaps::hasMMX()) { tinyRestoreMMX(YPLANE(tgt),YPLANE(srcP),YPLANE(src),YPLANE(srcN),YPLANE(srcNN),tgt->_width,tgt->_height); tinyRestoreMMX(UPLANE(tgt),UPLANE(srcP),UPLANE(src),UPLANE(srcN),UPLANE(srcNN),tgt->_width>>1,tgt->_height>>1); tinyRestoreMMX(VPLANE(tgt),VPLANE(srcP),VPLANE(src),VPLANE(srcN),VPLANE(srcNN),tgt->_width>>1,tgt->_height>>1); return 1; } #endif tinyRestore(YPLANE(tgt),YPLANE(srcP),YPLANE(src),YPLANE(srcN),YPLANE(srcNN),tgt->_width,tgt->_height); tinyRestore(UPLANE(tgt),UPLANE(srcP),UPLANE(src),UPLANE(srcN),UPLANE(srcNN),tgt->_width>>1,tgt->_height>>1); tinyRestore(VPLANE(tgt),VPLANE(srcP),VPLANE(src),VPLANE(srcN),VPLANE(srcNN),tgt->_width>>1,tgt->_height>>1); return 1; }
/** \fn preAmble \fn prepare a frame to be encoded */ bool x264Encoder::preAmble (ADMImage * in) { MMSET(pic); pic.img.i_csp = X264_CSP_I420; pic.img.i_plane = 3; pic.img.plane[0] = YPLANE(in); pic.img.plane[2] = UPLANE(in); pic.img.plane[1] = VPLANE(in); pic.img.i_stride[0] = in->GetPitch(PLANAR_Y); pic.img.i_stride[1] = in->GetPitch(PLANAR_U); pic.img.i_stride[2] = in->GetPitch(PLANAR_V); pic.i_type = X264_TYPE_AUTO; pic.i_pts = in->Pts; return true; }
uint8_t ADMVideoHue::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { ADMImage *mysrc=NULL; if(frame>=_info.nb_frames) return 0; mysrc=vidCache->getImage(frame); if(!mysrc) return 0; memcpy(YPLANE(data),YPLANE(mysrc),_info.width*_info.height); HueProcess_C(VPLANE(data), UPLANE(data), VPLANE(mysrc), UPLANE(mysrc), _info.width>>1,_info.width>>1, _info.width>>1,_info.height>>1, _hue, _saturation); vidCache->unlockAll(); return 1; }
//______________________________________________________________ uint8_t vidDelta::getFrameNumberNoAlloc (uint32_t frame, uint32_t * len, ADMImage * data, uint32_t * flags) { int w,h,page; ADMImage *cur,*prev,*next; w=_info.width; h=_info.height; page=w*h; if(frame>= _info.nb_frames) return 0; if(!frame || frame>=_info.nb_frames-1) { memset(YPLANE(data),0,page); memset(UPLANE(data),128,page>>2); memset(VPLANE(data),128,page>>2); return 1; }
uint8_t ADMVideoLuma::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { ADM_assert(frame<_info.nb_frames); // read uncompressed frame if(!_in->getFrameNumberNoAlloc(frame, len,data,flags)) return 0; uint32_t sz; sz=_info.width*_info.height; memset(UPLANE(data),128,sz>>2); memset(VPLANE(data),128,sz>>2); return 1; }
/** \fn getFrame \brief Get a processed frame */ bool verticalFlipFilter::getNextFrame(uint32_t *fn,ADMImage *image) { // since we do nothing, just get the output of previous filter if(false==previousFilter->getNextFrame(fn,image)) { ADM_warning("FlipFilter : Cannot get frame\n"); return false; } // do in place flip int w=info.width; int h=info.height; int stride=image->GetPitch(PLANAR_Y); flipMe(YPLANE(image),w,h,stride); stride=image->GetPitch(PLANAR_U); flipMe(UPLANE(image),w>>1,h>>1,stride); stride=image->GetPitch(PLANAR_V); flipMe(VPLANE(image),w>>1,h>>1,stride); return true; }
uint8_t ADMVideoKernelDeint::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { uint32_t frame_prev; uint32_t page=_info.width*_info.height; ADMImage *mysrc=NULL, *myprev=NULL; if(frame>_info.nb_frames-1) return 0; frame_prev=frame; if(frame_prev) frame_prev--; mysrc=vidCache->getImage(frame); myprev=vidCache->getImage(frame_prev); ADM_assert(mysrc); ADM_assert(myprev); // Now go to kernel deint code const uint8_t *srcp, *prvp,*prvp_saved, *prvpp, *prvpn, *prvppp, *prvpnn, *prvp4p, *prvp4n; const uint8_t *srcp_saved; const uint8_t *srcpp, *srcppp, *srcpn, *srcpnn, *srcp3p, *srcp3n, *srcp4p, *srcp4n; uint8_t *dstp; uint8_t *dstp_saved; int plane; int src_pitch; int dst_pitch; int w; int h; int x, y, z; int val, hi, lo; double valf; unsigned int hint; char buf[80]; uint32_t pitch; uint32_t offset; uint32_t order, threshold; uint8_t sharp, twoway, map; order=_param->order; threshold=_param->threshold; sharp=_param->sharp; twoway=_param->twoway; map=_param->map; for (z = 0; z < 3; z++) { pitch=_info.width; switch(z) { case 0: offset=0; srcp=srcp_saved= YPLANE(mysrc); dstp = dstp_saved=YPLANE(data); prvp_saved=prvp=YPLANE(myprev); break; case 1: offset=page; pitch>>=1; srcp=srcp_saved=UPLANE(mysrc); dstp = dstp_saved=UPLANE(data); prvp_saved=prvp=UPLANE(myprev); break; case 2: offset=((page*5)>>2); pitch>>=1; srcp=srcp_saved=VPLANE(mysrc); dstp = dstp_saved=VPLANE(data); prvp_saved=prvp=VPLANE(myprev); break; } if (z==0 && (GetHintingData((uint8_t *) srcp, &hint) == false) && (hint & PROGRESSIVE)) { if (debug ==true) { printf( "KernelDeint: frame %d: progressive\n", frame); } memcpy(YPLANE(data),YPLANE(mysrc),page); memcpy(UPLANE(data),UPLANE(mysrc),page>>2); memcpy(VPLANE(data),VPLANE(mysrc),page>>2); vidCache->unlockAll(); data->copyInfo(mysrc); return 1; } else { if (debug == true) { printf( "KernelDeint: frame %d: interkaced\n", frame); } } src_pitch = pitch; dst_pitch = pitch; w = pitch; //dst->GetRowSize(plane); h=_info.height; if(z) h>>=1; //h = dst->GetHeight(plane); srcp = srcp_saved + (1-order) * src_pitch; dstp = dstp_saved + (1-order) * dst_pitch; for (y = 0; y < h; y+=2) { memcpy(dstp, srcp, w); srcp += 2*src_pitch; dstp += 2*dst_pitch; } // Copy through the lines that will be missed below. memcpy(dstp_saved + order*dst_pitch, srcp_saved + (1-order)*src_pitch, w); memcpy(dstp_saved + (2+order)*dst_pitch, srcp_saved + (3-order)*src_pitch, w); memcpy(dstp_saved + (h-2+order)*dst_pitch, srcp_saved + (h-1-order)*src_pitch, w); memcpy(dstp_saved + (h-4+order)*dst_pitch, srcp_saved + (h-3-order)*src_pitch, w); /* For the other field choose adaptively between using the previous field or the interpolant from the current field. */ //prvp = prv->GetReadPtr(plane) + 5*src_pitch - (1-order)*src_pitch; prvp = prvp_saved + 5*src_pitch - (1-order)*src_pitch; prvpp = prvp - src_pitch; prvppp = prvp - 2*src_pitch; prvp4p = prvp - 4*src_pitch; prvpn = prvp + src_pitch; prvpnn = prvp + 2*src_pitch; prvp4n = prvp + 4*src_pitch; srcp = srcp_saved + 5*src_pitch - (1-order)*src_pitch; srcpp = srcp - src_pitch; srcppp = srcp - 2*src_pitch; srcp3p = srcp - 3*src_pitch; srcp4p = srcp - 4*src_pitch; srcpn = srcp + src_pitch; srcpnn = srcp + 2*src_pitch; srcp3n = srcp + 3*src_pitch; srcp4n = srcp + 4*src_pitch; dstp = dstp_saved + 5*dst_pitch - (1-order)*dst_pitch; for (y = 5 - (1-order); y <= h - 5 - (1-order); y+=2) { for (x = 0; x < w; x++) { if ((threshold == 0) || (frame == 0) || (abs((int)prvp[x] - (int)srcp[x]) > threshold) || (abs((int)prvpp[x] - (int)srcpp[x]) > threshold) || (abs((int)prvpn[x] - (int)srcpn[x]) > threshold)) { if (map == true) { int g = x & ~3; { if (z == 0) dstp[x] = 235; else dstp[x] = 128; } } else { { hi = (z == 0) ? 235 : 240; lo = 16; } if (sharp == true) { if (twoway == true) valf = + 0.526*((int)srcpp[x] + (int)srcpn[x]) + 0.170*((int)srcp[x] + (int)prvp[x]) - 0.116*((int)srcppp[x] + (int)srcpnn[x] + (int)prvppp[x] + (int)prvpnn[x]) - 0.026*((int)srcp3p[x] + (int)srcp3n[x]) + 0.031*((int)srcp4p[x] + (int)srcp4n[x] + (int)prvp4p[x] + (int)prvp4n[x]); else valf = + 0.526*((int)srcpp[x] + (int)srcpn[x]) + 0.170*((int)prvp[x]) - 0.116*((int)prvppp[x] + (int)prvpnn[x]) - 0.026*((int)srcp3p[x] + (int)srcp3n[x]) + 0.031*((int)prvp4p[x] + (int)prvp4p[x]); if (valf > hi) valf = hi; else if (valf < lo) valf = lo; dstp[x] = (int) valf; } else { if (twoway == true) val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)srcp[x] + (int)prvp[x]) - (int)(srcppp[x]) - (int)(srcpnn[x]) - (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4; else val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)prvp[x]) - (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4; if (val > hi) val = hi; else if (val < lo) val = lo; dstp[x] = (int) val; } } } else { dstp[x] = srcp[x]; } }
uint8_t ADMVideoMaskedSoften::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { uint32_t page=_info.width*_info.height; int32_t radius=_param->radius; uint32_t offset; int blockx,blocky; *len=(page*3)>>1; if(frame>=_info.nb_frames) return 0; if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; // do luma only ATM // copy chroma memcpy(UPLANE(data),UPLANE(_uncompressed),page>>2); memcpy(VPLANE(data),VPLANE(_uncompressed),page>>2); // for luma, the radius first lines /last lines are unchanged memcpy(YPLANE(data),YPLANE(_uncompressed),radius*_info.width); offset=page-_info.width*radius-1; memcpy(YPLANE(data)+offset, YPLANE(_uncompressed)+offset, radius*_info.width); uint8_t *src,*dst; uint32_t val,cur,coef; // data->copyInfo(_uncompressed); // optimized one if(radius==2) return radius5(YPLANE(_uncompressed),YPLANE(data)); if(radius==1) return radius3(YPLANE(_uncompressed),YPLANE(data)); for(uint32_t y=radius;y<_info.height-radius;y++) { src=YPLANE(_uncompressed)+y*_info.width; dst=YPLANE(data)+y*_info.width; memcpy(dst,src,radius); src+=radius; dst+=radius; for(uint32_t x=radius;x<_info.width-radius;x++) { coef=0; val=0; for( blocky=-radius;blocky<=radius;blocky++) { for( blockx=-radius;blockx<=radius;blockx++) { cur=*(src+blockx+blocky*_info.width); if( distMatrix[cur][*src]<=_param->luma) { coef++; val+=cur; } } } ADM_assert(coef); if(coef!=1) val=(val+(coef>>1)-1)/coef; *dst++=val; src++; //*dst++=*src++; } memcpy(dst,src,radius); } return 1; }
uint8_t ADMVideoForcedPP::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { uint32_t page=_info.width*_info.height; *len=(page*3)>>1; if(frame>=_info.nb_frames) return 0; if(!(_postproc.postProcType && _postproc.postProcStrength) ) { // disabled if(!_in->getFrameNumberNoAlloc(frame, len,data,flags)) return 0; return 1; } // we do postproc ! // keep uint8_t *iBuff[3],*oBuff[3]; int strideTab[3],strideTab2[3]; if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; oBuff[0]=YPLANE(data); oBuff[1]=VPLANE(data); oBuff[2]=UPLANE(data); iBuff[0]=YPLANE(_uncompressed); iBuff[1]=VPLANE(_uncompressed); iBuff[2]=UPLANE(_uncompressed); strideTab[0]=strideTab2[0]=_info.width; strideTab[1]=strideTab2[1]=_info.width>>1; strideTab[2]=strideTab2[2]=_info.width>>1; int type; if(_uncompressed->flags&AVI_KEY_FRAME) type=1; else if(_uncompressed->flags & AVI_B_FRAME) type=3; else type=2; pp_postprocess( iBuff, strideTab, oBuff, strideTab2, _info.width, _info.height, NULL, 0, _postproc.ppMode, _postproc.ppContext, type); // I ? data->copyInfo(_uncompressed); //printf("Type:%d\n",type); return 1; }
uint8_t DGbob::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data,uint32_t *flags) { ADMImage *src,*prv,*prvprv,*nxt,*nxtnxt,*dst; uint32_t n,num_frames; if(frame>=_info.nb_frames) return 0; num_frames=_in->getInfo()->nb_frames; // ?? if (_param->mode == 0) n = frame; else n = frame/2; src=vidCache->getImage(n); prv=vidCache->getImage(n > 0 ? n - 1 :0 ); prvprv=vidCache->getImage(n > 1 ? n - 2 : 0); nxt=vidCache->getImage(n < num_frames - 1 ? n + 1 : num_frames - 1); nxtnxt=vidCache->getImage(n < num_frames - 2 ? n + 2 : num_frames - 1); /* PVideoFrame src = child->GetFrame(n, env); PVideoFrame prv = child->GetFrame(n > 0 ? n - 1 : 0, env); PVideoFrame prvprv = child->GetFrame(n > 1 ? n - 2 : 0, env); PVideoFrame nxt = child->GetFrame(n < vi.num_frames - 1 ? n + 1 : vi.num_frames - 1, env); PVideoFrame nxtnxt = child->GetFrame(n < vi.num_frames - 2 ? n + 2 : vi.num_frames - 1, env); PVideoFrame dst = env->NewVideoFrame(vi); */ const unsigned char *srcp, *srcp_saved, *srcpp, *srcpn; const unsigned char *prvp, *prvpp, *prvpn, *prvprvp, *prvprvpp, *prvprvpn; const unsigned char *nxtp, *nxtpp, *nxtpn, *nxtnxtp, *nxtnxtpp, *nxtnxtpn; unsigned char *dstp, *dstp_saved; int src_pitch, dst_pitch, w, h; int x, y, z, v1, v2, D = _param->thresh, T = 6, AP = 30; int plane; uint32_t ww,hh; // Try making D a function of the average value of the comparands in // order to make the margin larger in darker areas, where we can't see as // much combing. // Force deinterlacing of the first and last frames. if (n == 0 || n == num_frames - 1) D = 0; dst=data; for (z = 0; z < 3; z++) { /* if (z == 0) plane = PLANAR_Y; else if (z == 1) plane = PLANAR_U; else plane = PLANAR_V; */ switch(z) { case 0: ww=_info.width; hh=_info.height; srcp_saved = srcp = YPLANE(src); dstp_saved = dstp = YPLANE(dst); src_pitch = ww; dst_pitch = ww; w = ww; h = hh; break; case 1: case 2: ww=_info.width>>1; hh=_info.height>>1; if(z==1) { srcp_saved = srcp = UPLANE(src); dstp_saved = dstp = UPLANE(dst); } else { srcp_saved = srcp = VPLANE(src); dstp_saved = dstp = VPLANE(dst); } src_pitch = ww; dst_pitch = ww; w = ww; h = hh; break; } /* srcp_saved = srcp = src->GetReadPtr(plane); src_pitch = src->GetPitch(plane); dstp_saved = dstp = dst->GetWritePtr(plane); dst_pitch = dst->GetPitch(plane); w = dst->GetRowSize(plane); h = dst->GetHeight(plane); */ if ((_param->mode > 0) && (frame & 1)) { // Process odd-numbered frames. // Copy field from current frame. srcp = srcp_saved +_param->order * src_pitch; dstp = dstp_saved +_param->order * dst_pitch; for (y = 0; y < h; y+=2) { memcpy(dstp, srcp, w); srcp += 2*src_pitch; dstp += 2*dst_pitch; } // Copy through the line that will be missed below. memcpy(dstp_saved + (1-_param->order)*(h-1)*dst_pitch, srcp_saved + (1-_param->order)*(h-1)*src_pitch, w); /* For the other field choose adaptively between using the previous field or the interpolant from the current field. */ //prvp = prv->GetReadPtr(plane) + src_pitch + order*src_pitch; switch(z) { case 0:prvp = YPLANE(prv) + src_pitch + _param->order*src_pitch;break; case 1:prvp = UPLANE(prv) + src_pitch + _param->order*src_pitch;break; case 2:prvp = VPLANE(prv) + src_pitch + _param->order*src_pitch;break; } prvpp = prvp - src_pitch; prvpn = prvp + src_pitch; //prvprvp = prvprv->GetReadPtr(plane) + src_pitch + order*src_pitch; switch(z) { case 0:prvprvp = YPLANE(prvprv) + src_pitch + _param->order*src_pitch;break; case 1:prvprvp = UPLANE(prvprv) + src_pitch + _param->order*src_pitch;break; case 2:prvprvp = VPLANE(prvprv) + src_pitch + _param->order*src_pitch;break; } prvprvpp = prvprvp - src_pitch; prvprvpn = prvprvp + src_pitch; //nxtp = nxt->GetReadPtr(plane) + src_pitch + order*src_pitch; switch(z) { case 0:nxtp = YPLANE(nxt) + src_pitch + _param->order*src_pitch;break; case 1:nxtp = UPLANE(nxt) + src_pitch + _param->order*src_pitch;break; case 2:nxtp = VPLANE(nxt) + src_pitch + _param->order*src_pitch;break; } nxtpp = nxtp - src_pitch; nxtpn = nxtp + src_pitch; //nxtnxtp = nxtnxt->GetReadPtr(plane) + src_pitch + order*src_pitch; switch(z) { case 0:nxtnxtp = YPLANE(nxtnxt) + src_pitch + _param->order*src_pitch;break; case 1:nxtnxtp = UPLANE(nxtnxt) + src_pitch + _param->order*src_pitch;break; case 2:nxtnxtp = VPLANE(nxtnxt) + src_pitch + _param->order*src_pitch;break; } nxtnxtpp = nxtnxtp - src_pitch; nxtnxtpn = nxtnxtp + src_pitch; srcp = srcp_saved + src_pitch + _param->order*src_pitch; srcpp = srcp - src_pitch; srcpn = srcp + src_pitch; dstp = dstp_saved + dst_pitch + _param->order*dst_pitch; for (y = 0; y < h - 2; y+=2) { for (x = 0; x < w; x++) { if ( abs(srcp[x] - nxtp[x]) < D // && abs(srcp[x] - nxtnxtp[x]) < D // && abs(prvp[x] - nxtp[x]) < D && abs(srcpn[x] - prvprvpn[x]) < D && abs(srcpp[x] - prvprvpp[x]) < D && abs(srcpn[x] - nxtnxtpn[x]) < D && abs(srcpp[x] - nxtnxtpp[x]) < D && abs(srcpn[x] - prvpn[x]) < D && abs(srcpp[x] - prvpp[x]) < D && abs(srcpn[x] - nxtpn[x]) < D && abs(srcpp[x] - nxtpp[x]) < D ) { if (_param->ap == true) { v1 = (int) srcp[x] - AP; if (v1 < 0) v1 = 0; v2 = (int) srcp[x] + AP; if (v2 > 235) v2 = 235; if ((v1 > srcpp[x] && v1 > srcpn[x]) || (v2 < srcpp[x] && v2 < srcpn[x])) { dstp[x] = ((int)srcpp[x] + srcpn[x]) >> 1; // if (x & 1) dstp[x] = 100; else dstp[x] = 235; } else { dstp[x] = srcp[x]; // if (x & 1) dstp[x] = 100; else dstp[x] = 235; } } else { dstp[x] = srcp[x]; // if (x & 1) dstp[x] = 100; else dstp[x] = 235; } }
uint8_t ADMVideoLargeMedian::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { //uint8_t *dst,*dstu,*dstv,*srcu,*srcv; uint8_t *x1,*x2,*x3,*x4,*x5,*o1; uint32_t stride,page; if(frame>= _info.nb_frames) return 0; ADM_assert(_uncompressed); stride=_info.width; page=(stride*_info.height)>>2; // read uncompressed frame if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; if(!_param->luma) { memcpy(YPLANE(data),YPLANE(_uncompressed),page*4); } else { memcpy(YPLANE(data),YPLANE(_uncompressed),stride*2); memcpy(YPLANE(data)+page*4-stride*2,YPLANE(_uncompressed)+page*4-2*stride,2*stride); o1=YPLANE(data)+stride*2;; x1=YPLANE(_uncompressed); x2=x1+stride; x3=x2+stride; x4=x3+stride; x5=x4+stride; // Luma for(int32_t y=2;y<(int32_t)(_info.height)-2;y++) { doLine(x1,x2,x3,x4,x5,o1,stride); x1=x2; x2=x3; x3=x4; x4=x5; x5+=stride; o1+=stride; } } stride>>=1; if(!_param->chroma) { memcpy(UPLANE(data),UPLANE(_uncompressed),page*2); } else { // first and last line memcpy(UPLANE(data),UPLANE(_uncompressed),stride*2); memcpy(UPLANE(data)+page-stride*2,UPLANE(_uncompressed)+page-2*stride,2*stride); // chroma u o1=UPLANE(data)+stride*2; x1=UPLANE(_uncompressed); x2=x1+stride; x3=x2+stride; x4=x3+stride; x5=x4+stride; for(int32_t y=2;y<(int32_t)(_info.height>>1)-2;y++) { doLine(x1,x2,x3,x4,x5,o1,stride); x1=x2; x2=x3; x3=x4; x4=x5; x5+=stride; o1+=stride; } // chroma V // first and last line memcpy(VPLANE(data),VPLANE(_uncompressed),stride*2); memcpy(VPLANE(data)+page-2*stride,VPLANE(_uncompressed)+page-2*stride,2*stride); o1=VPLANE(data)+stride*2; x1=VPLANE(_uncompressed); x2=x1+stride; x3=x2+stride; x4=x3+stride; x5=x4+stride; for(int32_t y=2;y<(int32_t)(_info.height>>1)-2;y++) { doLine(x1,x2,x3,x4,x5,o1,stride); x1=x2; x2=x3; x3=x4; x4=x5; x5+=stride; o1+=stride; } } data->copyInfo(_uncompressed); return 1; }
uint8_t ADMVideoTelecide::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { uint32_t uvlen; uint32_t dummylen; uint8_t motion; uint32_t cmatch,nmatch,n2match; ADMImage *cur,*next; if(frame>=_info.nb_frames) return 0; uvlen= _info.width*_info.height; *len=uvlen+(uvlen>>1); cur=vidCache->getImage(frame); if(!cur) return 0; data->copyInfo(cur); if(!frame || frame==_info.nb_frames-1) { data->duplicate(cur); vidCache->unlockAll(); return 1; } next=vidCache->getImage(frame-1); if(!next) { vidCache->unlockAll(); return 0; } // for u & v , no action -> copy it as is memcpy(UPLANE(data),UPLANE(cur),uvlen>>2); memcpy(VPLANE(data),VPLANE(cur),uvlen>>2); data->copyInfo(cur); // No interleaving detected if(!(motion=hasMotion(data)) ) { printf("\n Not interlaced !\n"); memcpy(YPLANE(data),YPLANE(cur),uvlen); vidCache->unlockAll(); return 1; // over ! } // else cmatch is the current match cmatch=getMatch(cur); /* ------------------------------------------------------------------------------------ Try to complete with next frame fields ----------------------------------------------------------------------------------- */ // Interleav next in even field interleave(cur,_uncompressed,1); interleave(next,_uncompressed,0); nmatch=getMatch(_uncompressed); interleave(cur,_uncompressed,0); interleave(next,_uncompressed,1); n2match=getMatch(_uncompressed); printf(" Cur : %lu \n",cmatch); printf(" Next : %lu \n",nmatch); printf(" NextP: %lu \n",n2match); if((cmatch<nmatch)&&(cmatch<n2match)) { printf("\n __ pure interlaced __\n"); interleave(cur,_uncompressed,0); interleave(cur,_uncompressed,1); hasMotion(_uncompressed); doBlend(_uncompressed,data); vidCache->unlockAll(); return 1; } if( nmatch > n2match) { printf("\n -------Shifted-P is better \n"); if(hasMotion(_uncompressed)) { doBlend(_uncompressed,data); printf(" but there is still motion \n"); } else data->duplicate(_uncompressed); } else { printf("\n -------Shifted-O is better \n"); interleave(cur,_uncompressed,1); interleave(next,_uncompressed,0); if(hasMotion(_uncompressed)) { doBlend(_uncompressed,data); printf(" but there is still motion \n"); } else data->duplicate(_uncompressed); } // which chroma is better ? from current or from next ? // search for a transition and see if there is also one ? vidCache->unlockAll(); return 1; }
uint8_t AVDMVideoSmooth::getFrameNumberNoAlloc(uint32_t frame, uint32_t *len, ADMImage *data, uint32_t *flags) { uint8_t *dst,*dstu,*dstv,*src,*srcu,*srcv; int16_t l,u=0,v=0; int16_t nb; int16_t fl,fu,fv; int16_t ldelta,udelta,vdelta; int16_t threshold=10,su=0,sv=0; if(frame>=_info.nb_frames) return 0; ADM_assert(_uncompressed); // read uncompressed frame if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0; src=YPLANE(_uncompressed); srcu=UPLANE(_uncompressed);; srcv=VPLANE(_uncompressed);; dst=YPLANE(data); dstu=UPLANE(data); dstv=VPLANE(data); int16_t radius=_param->radius; for(int32_t y=0;y<(int32_t)(_info.height );y++) { for(int32_t x=0;x<(int32_t)(_info.width );x++) { // for each pixel we take the surrounding one // if threshold is not met l=getPixel(x,y,_uncompressed->data); if(!(x&1)) { u=getPixelU(x,y,srcu); v=getPixelU(x,y,srcv); } nb=0; fl=0;fu=0;fv=0; //------------------------ for(int16_t yy=-radius+1;yy<radius;yy++) { for(int16_t xx=-radius+1;xx<radius;xx++) { if( (xx*xx+yy*yy)<radius*radius) { ldelta =getPixel(x+xx,y+yy,_uncompressed->data)-l; udelta=getPixelU(x+xx,y+yy,srcu)-u; vdelta=getPixelU(x+xx,y+yy,srcv)-v; if((udelta*udelta<threshold*threshold)&& (vdelta*vdelta<threshold*threshold) && (ldelta*ldelta<threshold*threshold)) { nb++; fl=fl+ldelta+l; fu=fu+udelta+u; fv=fv+vdelta+v; } } } } //---------------------------------- // // average value fl=fl/nb; fu=fu/nb; fv=fv/nb; // now melt it // 50/50 /* fl=(fl+l)>>1; fu=(fu+u)>>1; fv=(fv+v)>>1;*/ *dst++=fl; if(y&1) if(x&1) { setPixelU( (su+fu)>>1,x,y,dstu); setPixelU( (sv+fv)>>1,x,y,dstv); } else { su=fu; sv=fv; } } // end for x