⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tdeinterlaceyuy2.cpp

📁 the De-interlace video processing developed with C++ enviroment in Motion adaptive in 3D and Bi-indi
💻 CPP
📖 第 1 页 / 共 5 页
字号:
					else dstp[x] = temp;
				}
				else if (y>1 && y<Height-2)
				{
					temp = (((srcpp[x]+srcpn[x])<<3)+
							(kerc[x]<<1)-(kerp[x]+kern[x])+8) >> 4;
					if (temp > 255) dstp[x] = 255;
					else if (temp < 0) dstp[x] = 0;
					else dstp[x] = temp;
				}
				else dstp[x] = (srcpn[x]+srcpp[x]+1)>>1;
			}
		}
		prvp += prv_pitch;
		srcppp += src_pitch;
		srcpp += src_pitch;
		srcp += src_pitch;
		srcpn += src_pitch;
		srcpnn += src_pitch;
		kerpp += ker_pitch;
		kerp += ker_pitch;
		kerc += ker_pitch;
		kern += ker_pitch;
		kernn += ker_pitch;
		nxtp += nxt_pitch;
		maskp += mask_pitch;
		dstp += dst_pitch;
	}
}

void TDeinterlace::smartELADeintYUY2(PVideoFrame &dst, PVideoFrame &mask, 
		PVideoFrame &prv, PVideoFrame &src, PVideoFrame &nxt)
{
	const unsigned char *prvp = prv->GetReadPtr();
	int prv_pitch = prv->GetPitch();
	const unsigned char *srcp = src->GetReadPtr();
	int src_pitch = src->GetPitch();
	int src_pitch2 = src_pitch<<1;
	int Width = src->GetRowSize();
	int Height = src->GetHeight();
	const unsigned char *nxtp = nxt->GetReadPtr();
	int nxt_pitch = nxt->GetPitch();
	unsigned char *dstp = dst->GetWritePtr();
	int dst_pitch = dst->GetPitch();
	const unsigned char *maskp = mask->GetReadPtr();
	int mask_pitch = mask->GetPitch();
	const unsigned char *srcpp = srcp - src_pitch;
	const unsigned char *srcppp = srcpp - src_pitch2;
	const unsigned char *srcpn = srcp + src_pitch;
	const unsigned char *srcpnn = srcpn + src_pitch2;
	int x, y, Iy1, Iy2, Iye, Ix1, Ix2, edgeS1, edgeS2;
	int sum, sumsq, temp, temp1, temp2, minN, maxN;
	double dir1, dir2, dir, dirF;
	for (y=0; y<Height; ++y)
	{
		for (x=0; x<Width; ++x)
		{
			if (maskp[x] == 10 || maskp[x] == 110) dstp[x] = srcp[x];
			else if (maskp[x] == 20 || maskp[x] == 120) dstp[x] = prvp[x];
			else if (maskp[x] == 30 || maskp[x] == 130) dstp[x] = nxtp[x];
			else if (maskp[x] == 40) dstp[x] = (srcp[x]+nxtp[x]+1)>>1;
			else if (maskp[x] == 50) dstp[x] = (srcp[x]+prvp[x]+1)>>1;
			else if (maskp[x] == 60)
			{
				if (y>2 && y<Height-3 && x>7 && x<Width-8)
				{
					Iy1 = srcppp[x-2]+srcppp[x]+srcppp[x]+srcppp[x+2]-srcpn[x-2]-srcpn[x]-srcpn[x]-srcpn[x+2];
					Iy2 = srcpp[x-2]+srcpp[x]+srcpp[x]+srcpp[x+2]-srcpnn[x-2]-srcpnn[x]-srcpnn[x]-srcpnn[x+2];
					Ix1 = srcppp[x+2]+srcpp[x+2]+srcpp[x+2]+srcpn[x+2]-srcppp[x-2]-srcpp[x-2]-srcpp[x-2]-srcpn[x-2];
					Ix2 = srcpp[x+2]+srcpn[x+2]+srcpn[x+2]+srcpnn[x+2]-srcpp[x-2]-srcpn[x-2]-srcpn[x-2]-srcpnn[x-2];
					edgeS1 = Ix1*Ix1 + Iy1*Iy1;
					edgeS2 = Ix2*Ix2 + Iy2*Iy2;
					if (edgeS1 < 1600 && edgeS2 < 1600) 
					{
						dstp[x] = (srcpp[x]+srcpn[x]+1)>>1;
						goto chromajump;
					}
					if (abs(srcpp[x]-srcpn[x]) < 10 && (edgeS1 < 1600 || edgeS2 < 1600))
					{
						dstp[x] = (srcpp[x]+srcpn[x]+1)>>1;
						goto chromajump;
					}
					sum = srcpp[x-2] + srcpp[x] + srcpp[x+2] + srcpn[x-2] + srcpn[x] + srcpn[x+2];
					sumsq = srcpp[x-2]*srcpp[x-2] + srcpp[x]*srcpp[x] + srcpp[x+2]*srcpp[x+2] +
							srcpn[x-2]*srcpn[x-2] + srcpn[x]*srcpn[x] + srcpn[x+2]*srcpn[x+2];
					if ((6*sumsq - sum*sum) < 432)
					{
						dstp[x] = (srcpp[x]+srcpn[x]+1)>>1;
						goto chromajump;
					}
					if (Ix1 == 0) dir1 = 3.1415926;
					else
					{
						dir1 = atan(Iy1/(Ix1*2.0f)) + 1.5707963;
						if (Iy1 >= 0) { if (Ix1 < 0) dir1 += 3.1415927; }
						else { if (Ix1 >= 0) dir1 += 3.1415927; }
						if (dir1 >= 3.1415927) dir1 -= 3.1415927;
					}
					if (Ix2 == 0) dir2 = 3.1415926;
					else 
					{
						dir2 = atan(Iy2/(Ix2*2.0f)) + 1.5707963;
						if (Iy2 >= 0) { if (Ix2 < 0) dir2 += 3.1415927; }
						else { if (Ix2 >= 0) dir2 += 3.1415927; }
						if (dir2 >= 3.1415927) dir2 -= 3.1415927;
					}
					if (fabs(dir1-dir2) < 0.5)
					{
						if (edgeS1 >= 3600 && edgeS2 >= 3600) dir = (dir1 + dir2) * 0.5f;
						else dir = edgeS1 >= edgeS2 ? dir1 : dir2;
					}
					else 
					{
						if (edgeS1 >= 5000 && edgeS2 >= 5000)
						{
							Iye = srcpp[x-2]+srcpp[x]+srcpp[x]+srcpp[x+2]-srcpn[x-2]-srcpn[x]-srcpn[x]-srcpn[x+2];
							if ((Iy1*Iye > 0) && (Iy2*Iye < 0)) dir = dir1;
							else if ((Iy1*Iye < 0) && (Iy2*Iye > 0)) dir = dir2;
							else 
							{
								if (abs(Iye-Iy1) <= abs(Iye-Iy2)) dir = dir1;
								else dir = dir2;
							}
						}
						else dir = edgeS1 >= edgeS2 ? dir1 : dir2;
					}
					dirF = 0.5f/tan(dir);
					if (dirF >= 0.0f)
					{
						if (dirF >= 0.5f)
						{
							if (dirF >= 1.0f)
							{
								if (dirF >= 1.5f)
								{
									if (dirF >= 2.0f)
									{
										if (dirF <= 2.50f)
										{
											temp1 = srcpp[x+8];
											temp2 = srcpn[x-8];
											temp = (srcpp[x+8]+srcpn[x-8]+1)>>1;
										}
										else 
										{
											temp1 = temp2 = srcpn[x];
											temp = cubicInt(srcppp[x],srcpp[x],srcpn[x],srcpnn[x]);
										}
									}
									else 
									{
										temp1 = (int)((dirF-1.5f)*(srcpp[x+8]) + (2.0f-dirF)*(srcpp[x+6]) + 0.5f);
										temp2 = (int)((dirF-1.5f)*(srcpn[x-8]) + (2.0f-dirF)*(srcpn[x-6]) + 0.5f);
										temp = (int)((dirF-1.5f)*(srcpp[x+8]+srcpn[x-8]) + (2.0f-dirF)*(srcpp[x+6]+srcpn[x-6]) + 0.5f);
									}
								}
								else 
								{
									temp1 = (int)((dirF-1.0f)*(srcpp[x+6]) + (1.5f-dirF)*(srcpp[x+4]) + 0.5f);
									temp2 = (int)((dirF-1.0f)*(srcpn[x-6]) + (1.5f-dirF)*(srcpn[x-4]) + 0.5f);
									temp = (int)((dirF-1.0f)*(srcpp[x+6]+srcpn[x-6]) + (1.5f-dirF)*(srcpp[x+4]+srcpn[x-4]) + 0.5f);
								}
							}
							else 
							{
								temp1 = (int)((dirF-0.5f)*(srcpp[x+4]) + (1.0f-dirF)*(srcpp[x+2]) + 0.5f);
								temp2 = (int)((dirF-0.5f)*(srcpn[x-4]) + (1.0f-dirF)*(srcpn[x-2]) + 0.5f);
								temp = (int)((dirF-0.5f)*(srcpp[x+4]+srcpn[x-4]) + (1.0f-dirF)*(srcpp[x+2]+srcpn[x-2]) + 0.5f);
							}
						}
						else 
						{
							temp1 = (int)(dirF*(srcpp[x+2]) + (0.5f-dirF)*(srcpp[x]) + 0.5f);
							temp2 = (int)(dirF*(srcpn[x-2]) + (0.5f-dirF)*(srcpn[x]) + 0.5f);
							temp = (int)(dirF*(srcpp[x+2]+srcpn[x-2]) + (0.5f-dirF)*(srcpp[x]+srcpn[x]) + 0.5f);
						}
					}
					else
					{
						if (dirF <= -0.5f)
						{
							if (dirF <= -1.0f)
							{
								if (dirF <= -1.5f)
								{
									if (dirF <= -2.0f)
									{
										if (dirF >= -2.50f) 
										{
											temp1 = srcpp[x-8];
											temp2 = srcpn[x+8];
											temp = (srcpp[x-8]+srcpn[x+8]+1)>>1;
										}
										else 
										{
											temp1 = temp2 = srcpn[x];
											temp = cubicInt(srcppp[x],srcpp[x],srcpn[x],srcpnn[x]);
										}
									}
									else
									{
										temp1 = (int)((-dirF-1.5f)*(srcpp[x-8]) + (2.0f+dirF)*(srcpp[x-6]) + 0.5f);
										temp2 = (int)((-dirF-1.5f)*(srcpn[x+8]) + (2.0f+dirF)*(srcpn[x+6]) + 0.5f);
										temp = (int)((-dirF-1.5f)*(srcpp[x-8]+srcpn[x+8]) + (2.0f+dirF)*(srcpp[x-6]+srcpn[x+6]) + 0.5f);
									}
								}
								else 
								{
									temp1 = (int)((-dirF-1.0f)*(srcpp[x-6]) + (1.5f+dirF)*(srcpp[x-4]) + 0.5f);
									temp2 = (int)((-dirF-1.0f)*(srcpn[x+6]) + (1.5f+dirF)*(srcpn[x+4]) + 0.5f);
									temp = (int)((-dirF-1.0f)*(srcpp[x-6]+srcpn[x+6]) + (1.5f+dirF)*(srcpp[x-4]+srcpn[x+4]) + 0.5f);
								}
							}
							else 
							{
								temp1 = (int)((-dirF-0.5f)*(srcpp[x-4]) + (1.0f+dirF)*(srcpp[x-2]) + 0.5f);
								temp2 = (int)((-dirF-0.5f)*(srcpn[x+4]) + (1.0f+dirF)*(srcpn[x+2]) + 0.5f);
								temp = (int)((-dirF-0.5f)*(srcpp[x-4]+srcpn[x+4]) + (1.0f+dirF)*(srcpp[x-2]+srcpn[x+2]) + 0.5f);
							}
						}
						else 
						{
							temp1 = (int)((-dirF)*(srcpp[x-2]) + (0.5f+dirF)*(srcpp[x]) + 0.5f);
							temp2 = (int)((-dirF)*(srcpn[x+2]) + (0.5f+dirF)*(srcpn[x]) + 0.5f);
							temp = (int)((-dirF)*(srcpp[x-2]+srcpn[x+2]) + (0.5f+dirF)*(srcpp[x]+srcpn[x]) + 0.5f);
						}
					}
					maxN = max(srcpp[x],srcpn[x]) + 25;
					minN = min(srcpp[x],srcpn[x]) - 25;
					if (abs(temp1-temp2) > 20 || abs(srcpp[x]+srcpn[x]-temp-temp) > 60 || temp < minN || temp > maxN)
					{
						temp = cubicInt(srcppp[x],srcpp[x],srcpn[x],srcpnn[x]);
					}
					if (temp > 255) temp = 255;
					else if (temp < 0) temp = 0;
					dstp[x] = temp;
				}
				else
				{
					if (y<3 || y>Height-4) dstp[x] = (srcpn[x]+srcpp[x]+1)>>1;
					else dstp[x] = cubicInt(srcppp[x],srcpp[x],srcpn[x],srcpnn[x]);
				}
			}
chromajump:
			++x;
			if (maskp[x] == 10 || maskp[x] == 110) dstp[x] = srcp[x];
			else if (maskp[x] == 20 || maskp[x] == 120) dstp[x] = prvp[x];
			else if (maskp[x] == 30 || maskp[x] == 130) dstp[x] = nxtp[x];
			else if (maskp[x] == 40) dstp[x] = (srcp[x]+nxtp[x]+1)>>1;
			else if (maskp[x] == 50) dstp[x] = (srcp[x]+prvp[x]+1)>>1;
			else if (maskp[x] == 60)
			{
				if (y<3 || y>Height-4) dstp[x] = (srcpn[x]+srcpp[x]+1)>>1;
				else dstp[x] = cubicInt(srcppp[x],srcpp[x],srcpn[x],srcpnn[x]);
			}
		}
		prvp += prv_pitch;
		srcppp += src_pitch;
		srcpp += src_pitch;
		srcp += src_pitch;
		srcpn += src_pitch;
		srcpnn += src_pitch;
		nxtp += nxt_pitch;
		maskp += mask_pitch;
		dstp += dst_pitch;
	}
}

void TDeinterlace::apPostCheck(PVideoFrame &dst, PVideoFrame &mask, IScriptEnvironment *env)
{
	PVideoFrame maskt;
	if (APType > 0)
	{
		maskt = env->NewVideoFrame(vi);
		copyFrame(maskt, mask, env);
	}
	unsigned char *maskw;
	const unsigned char *dstp, *dstpp, *dstpn, *dstppp, *dstpnn, *maskp, *maskpT;
	int dst_pitch, dst_pitch2, mask_pitch, mask_pitch2, Width, Height;
	int x, y, b, stop = vi.IsYV12() ? 3 : 1, count = 0, maskp_pitch, maskp_pitch2;
	int sFirst, sSecond, AP6 = AP*6, plane, moving, neighbors, u, v;
	int starty, stopy, startx, stopx, inc;
	for (b=0; b<stop; ++b)
	{
		if (b == 0) plane = PLANAR_Y;
		else if (b == 1) plane = PLANAR_U;
		else plane = PLANAR_V;
		dstp = dst->GetReadPtr(plane);
		dst_pitch = dst->GetPitch(plane);
		dst_pitch2 = dst_pitch<<1;
		Width = dst->GetRowSize(plane);
		Height = dst->GetHeight(plane);
		dstp += (2-field)*dst_pitch;
		dstppp = dstp - dst_pitch2;
		dstpp = dstp - dst_pitch;
		dstpn = dstp + dst_pitch;
		dstpnn = dstp + dst_pitch2;
		maskw = mask->GetWritePtr(plane);
		mask_pitch = mask->GetPitch(plane);
		mask_pitch2 = mask_pitch<<1;
		if (APType > 0)
		{
			maskp = maskt->GetReadPtr(plane);
			maskp_pitch = maskt->GetPitch(plane);
			maskp_pitch2 = maskp_pitch<<1;
		}
		maskw += (2-field)*mask_pitch;
		y = 2-field;
		for (x=0; x<Width; ++x)
		{
			if (maskw[x] == 60) { maskw[x] = 10; continue; };
			maskw[x] = 10;
			sFirst = dstp[x] - dstpp[x];
			sSecond = dstp[x] - dstpn[x];
			if ((sFirst > AP && sSecond > AP) || (sFirst < -AP && sSecond < -AP))
			{
				sFirst = abs(dstpnn[x]+(dstp[x]<<2)+dstpnn[x]-(3*(dstpp[x]+dstpn[x])));
				if (sFirst > AP6) 
				{
					if (APType > 0)
					{
						inc = stop > 1 ? 1 : x&1 ? 4 : 2;
						startx = x-(inc<<1) < 0 ? x-inc < 0 ? x : x-inc : x-(inc<<1);
						stopx = x+(inc<<1) > Width-1 ? x+inc > Width-1 ? x : x+inc : x+(inc<<1);
						starty = y-4 < 0 ? y-2 < 0 ? y : y-2 : y-4;
						stopy = y+4 > Height-1 ? y+2 > Height-1 ? y : y+2 : y+4;
						neighbors = moving = 0;
						maskpT = maskp + starty*maskp_pitch;
						for (u=starty; u<=stopy; u+=2)
						{
							for (v=startx; v<=stopx; v+=inc)
							{
								if (maskpT[v] >= 60) ++moving;
								++neighbors;
							}
							maskpT += maskp_pitch2;
						}
						if ((APType == 1 && (moving<<1) >= neighbors) ||
							(APType == 2 && (moving*3)  >= neighbors))
						{
							maskw[x] = 60;
							++count;
						}
					}
					else
					{
						maskw[x] = 60;
						++count;
					}
				}
			}
		}
		dstppp += dst_pitch2;
		dstpp += dst_pitch2;
		dstp += dst_pitch2;
		dstpn += dst_pitch2;
		dstpnn += dst_pitch2;
		maskw += mask_pitch2;
		y += 2;
		for 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -