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

📄 readpic.c

📁 JPEG-MPEG編解碼技術書集的代碼
💻 C
📖 第 1 页 / 共 3 页
字号:
					memset(lpframeY, 0, rblank);
					memset(lpframeU, 128, rblank);
					memset(lpframeV, 128, rblank);
					lpframeY += rblank;
					lpframeU += rblank;
					lpframeV += rblank;
				}

				lpcurscanl -= bpscanl;
			} while(--h);
			break;

		case 24:
			lpcurscanl = (unsigned char *)(lpbitmp + ((lpbi->biHeight - 1 - (vcrop/2)) * bpscanl) + ((hcrop/2) * 3));
			lpframeU = Ubuffer+(hblank/2)+topblank*width;
			lpframeV = Vbuffer+(hblank/2)+topblank*width;

			h = lpbi->biHeight - (int) vcrop;
			lblank = hblank/2;
			rblank = hblank - lblank;

			do
			{
				// take care of any blank pixels on the left
				if(lblank > 0)
				{
					memset(lpframeY, 0, lblank);
					memset(lpframeU, 128, lblank);
					memset(lpframeV, 128, lblank);
					lpframeY += lblank;
					lpframeU += lblank;
					lpframeV += lblank;
				}

				if(cpu_MMX)
				{

					w = (lpbi->biWidth-(int)hcrop) >> 1;

					// assume that width is a multiple of 2 !
					_asm
					{
						mov esi, lpcurscanl			;// esi = lpcurscanl
						mov ecx, lpframeY			;// ecx = lpframeY
						mov edx, lpframeU			;// edx = lpframeU
						mov edi, lpframeV			;// edi = lpframeV
						movq mm6, PACKED_128L		;// mm6 = (128, 128)
						pxor mm7, mm7				;// mm7 = 0
readframe__l2:
						movd mm0, [esi]				;// lower 4 bytes into mm0 = esi[0..3]
						movd mm3, [esi+3]			;// lower 4 bytes into mm3 = esi[4..7]
						punpcklbw mm0, mm7			;// unpack the lower 4 bytes into mm0
						punpcklbw mm3, mm7			;// unpack the lower 4 bytes into mm3
						movq mm1, mm0
						movq mm2, mm0
						movq mm4, mm3
						movq mm5, mm3
						pmaddwd mm0, PACKED_Y		;// multiply each word in mm0 by PACKED_Y and add them to make only two dwords
						pmaddwd mm1, PACKED_U		;// multiply each word in mm1 by PACKED_U and add them to make only two dwords
						pmaddwd mm2, PACKED_V		;// multiply each word in mm2 by PACKED_V and add them to make only two dwords
						pmaddwd mm3, PACKED_Y		;// multiply each word in mm3 by PACKED_Y and add them to make only two dwords
						pmaddwd mm4, PACKED_U		;// multiply each word in mm4 by PACKED_U and add them to make only two dwords
						pmaddwd mm5, PACKED_V		;// multiply each word in mm5 by PACKED_V and add them to make only two dwords
						paddd mm0, mm6				;// mm0 += (128, 128)
						paddd mm1, mm6				;// mm1 += (128, 128)
						paddd mm2, mm6				;// mm2 += (128, 128)
						paddd mm3, mm6				;// mm3 += (128, 128)
						paddd mm4, mm6				;// mm4 += (128, 128)
						paddd mm5, mm6				;// mm5 += (128, 128)
						psrad mm0, 8				;// shift mm0 and round to lower
						psrad mm1, 8				;// shift mm1 and round to lower
						psrad mm2, 8				;// shift mm2 and round to lower
						psrad mm3, 8				;// shift mm3 and round to lower
						psrad mm4, 8				;// shift mm4 and round to lower
						psrad mm5, 8				;// shift mm5 and round to lower
						movd eax, mm0				;// load lower dword of mm0 into eax
						psrlq mm0, 32				;// shift mm0 to get upper dword
						movd ebx, mm0				;// load lower dword of mm0 into ebx
						add eax, ebx				;// eax += ebx
						mov [ecx], al				;// store result into [ecx]
						movd eax, mm1				;// load lower dword of mm1 into eax
						psrlq mm1, 32				;// shift mm1 to get upper dword
						movd ebx, mm1				;// load lower dword of mm1 into ebx
						add eax, ebx
						add eax, 128				;// eax += ebx + 128
						mov [edx], al				;// store result into [edx]
						movd eax, mm2				;// load lower dword of mm2 into eax
						psrlq mm2, 32				;// shift mm2 to get upper dword
						movd ebx, mm2				;// load lower dword of mm2 into ebx
						add eax, ebx
						add eax, 128				;// eax += ebx + 128
						mov [edi], al				;// store result into [edi]
						movd eax, mm3				;// load lower dword of mm3 into eax
						psrlq mm3, 32				;// shift mm2 to get upper dword
						movd ebx, mm3				;// load lower dword of mm3 into ebx
						add eax, ebx				;// eax += ebx
						mov [ecx+1], al				;// store result into [ecx+1]
						movd eax, mm4				;// load lower dword of mm4 into eax
						psrlq mm4, 32				;// shift mm4 to get upper dword
						movd ebx, mm4				;// load lower dword of mm4 into ebx
						add eax, ebx
						add eax, 128				;// eax += ebx + 128
						mov [edx+1], al				;// store result into [edx+1]
						movd eax, mm5				;// load lower dword of mm5 into eax
						psrlq mm5, 32				;// shift mm5 to get upper dword
						movd ebx, mm5				;// load lower dword of mm5 into ebx
						add eax, ebx
						add eax, 128				;// eax += ebx + 128
						mov [edi+1], al				;// store result into [edi+1]
						add esi, 6					;// esi += 6
						add ecx, 2					;// ecx += 2
						add edx, 2					;// edx += 2
						add edi, 2					;// edi += 2
						dec dword ptr w				;// decrement w
						jnz readframe__l2			;// loop while not zero
						mov lpframeY, ecx			;//	update lpframeY
						mov lpframeU, edx			;// update lpframeU
						mov lpframeV, edi			;// update lpframeV
						emms						;// empty MMX state
					}
				}
				else
				{
					w = lpbi->biWidth - (int) hcrop;
					lpcurpix = lpcurscanl;

					do
					{
						B = *lpcurpix++;
						G = *lpcurpix++;
						R = *lpcurpix++;

						*lpframeY++ = (int)(RY*R + GY*G + BY*B);
						*lpframeU++ = (int)(RU*R + GU*G + BU*B + 128);
						*lpframeV++ = (int)(RV*R + GV*G + BV*B + 128);
					} while(--w);
				}

				// take care of any blank pixels on the right
				if(rblank > 0)
				{
					memset(lpframeY, 0, rblank);
					memset(lpframeU, 128, rblank);
					memset(lpframeV, 128, rblank);
					lpframeY += rblank;
					lpframeU += rblank;
					lpframeV += rblank;
				}

				lpcurscanl -= bpscanl;
			} while(--h);
			break;

		case 32:
			lpcurscanl = (unsigned char *)(lpbitmp + ((lpbi->biHeight - 1 - (vcrop/2)) * bpscanl) + ((hcrop/2) * 4));
			lpframeU = Ubuffer+(hblank/2)+topblank*width;
			lpframeV = Vbuffer+(hblank/2)+topblank*width;

			h = lpbi->biHeight - (int) vcrop;
			lblank = hblank/2;
			rblank = hblank - lblank;

			do
			{
				// take care of any blank pixels on the left
				if(lblank > 0)
				{
					memset(lpframeY, 0, lblank);
					memset(lpframeU, 128, lblank);
					memset(lpframeV, 128, lblank);
					lpframeY += lblank;
					lpframeU += lblank;
					lpframeV += lblank;
				}

				if(cpu_MMX)
				{

					w = (lpbi->biWidth-(int)hcrop) >> 1;

					// assume that width is a multiple of 2 !
					_asm
					{
						mov esi, lpcurscanl			;// esi = lpcurscanl
						mov ecx, lpframeY			;// ecx = lpframeY
						mov edx, lpframeU			;// edx = lpframeU
						mov edi, lpframeV			;// edi = lpframeV
						movq mm6, PACKED_128L		;// mm6 = (128, 128)
						pxor mm7, mm7				;// mm7 = 0
readframe__l3:
						movd mm0, [esi]				;// lower 4 bytes into mm0 = esi[0..3]
						movd mm3, [esi+3]			;// lower 4 bytes into mm3 = esi[4..7]
						punpcklbw mm0, mm7			;// unpack the lower 4 bytes into mm0
						punpcklbw mm3, mm7			;// unpack the lower 4 bytes into mm3
						movq mm1, mm0
						movq mm2, mm0
						movq mm4, mm3
						movq mm5, mm3
						pmaddwd mm0, PACKED_Y		;// multiply each word in mm0 by PACKED_Y and add them to make only two dwords
						pmaddwd mm1, PACKED_U		;// multiply each word in mm1 by PACKED_U and add them to make only two dwords
						pmaddwd mm2, PACKED_V		;// multiply each word in mm2 by PACKED_V and add them to make only two dwords
						pmaddwd mm3, PACKED_Y		;// multiply each word in mm3 by PACKED_Y and add them to make only two dwords
						pmaddwd mm4, PACKED_U		;// multiply each word in mm4 by PACKED_U and add them to make only two dwords
						pmaddwd mm5, PACKED_V		;// multiply each word in mm5 by PACKED_V and add them to make only two dwords
						paddd mm0, mm6				;// mm0 += (128, 128)
						paddd mm1, mm6				;// mm1 += (128, 128)
						paddd mm2, mm6				;// mm2 += (128, 128)
						paddd mm3, mm6				;// mm3 += (128, 128)
						paddd mm4, mm6				;// mm4 += (128, 128)
						paddd mm5, mm6				;// mm5 += (128, 128)
						psrad mm0, 8				;// shift mm0 and round to lower
						psrad mm1, 8				;// shift mm1 and round to lower
						psrad mm2, 8				;// shift mm2 and round to lower
						psrad mm3, 8				;// shift mm3 and round to lower
						psrad mm4, 8				;// shift mm4 and round to lower
						psrad mm5, 8				;// shift mm5 and round to lower
						movd eax, mm0				;// load lower dword of mm0 into eax
						psrlq mm0, 32				;// shift mm0 to get upper dword
						movd ebx, mm0				;// load lower dword of mm0 into ebx
						add eax, ebx				;// eax += ebx
						mov [ecx], al				;// store result into [ecx]
						movd eax, mm1				;// load lower dword of mm1 into eax
						psrlq mm1, 32				;// shift mm1 to get upper dword
						movd ebx, mm1				;// load lower dword of mm1 into ebx
						add eax, ebx
						add eax, 128				;// eax += ebx + 128
						mov [edx], al				;// store result into [edx]
						movd eax, mm2				;// load lower dword of mm2 into eax
						psrlq mm2, 32				;// shift mm2 to get upper dword
						movd ebx, mm2				;// load lower dword of mm2 into ebx
						add eax, ebx
						add eax, 128				;// eax += ebx + 128
						mov [edi], al				;// store result into [edi]
						movd eax, mm3				;// load lower dword of mm3 into eax
						psrlq mm3, 32				;// shift mm2 to get upper dword
						movd ebx, mm3				;// load lower dword of mm3 into ebx
						add eax, ebx				;// eax += ebx
						mov [ecx+1], al				;// store result into [ecx+1]
						movd eax, mm4				;// load lower dword of mm4 into eax
						psrlq mm4, 32				;// shift mm4 to get upper dword
						movd ebx, mm4				;// load lower dword of mm4 into ebx
						add eax, ebx
						add eax, 128				;// eax += ebx + 128
						mov [edx+1], al				;// store result into [edx+1]
						movd eax, mm5				;// load lower dword of mm5 into eax
						psrlq mm5, 32				;// shift mm5 to get upper dword
						movd ebx, mm5				;// load lower dword of mm5 into ebx
						add eax, ebx
						add eax, 128				;// eax += ebx + 128
						mov [edi+1], al				;// store result into [edi+1]
						add esi, 8					;// esi += 8
						add ecx, 2					;// ecx += 2
						add edx, 2					;// edx += 2
						add edi, 2					;// edi += 2
						dec dword ptr w				;// decrement w
						jnz readframe__l3			;// loop while not zero
						mov lpframeY, ecx			;//	update lpframeY
						mov lpframeU, edx			;// update lpframeU
						mov lpframeV, edi			;// update lpframeV
						emms						;// empty MMX state
					}
				}
				else
				{
					w = lpbi->biWidth - (int) hcrop;
					lpcurpix = lpcurscanl;

					do
					{
						B = *lpcurpix++;
						G = *lpcurpix++;
						R = *lpcurpix++;
						lpcurpix++;

						*lpframeY++ = (int)(RY*R + GY*G + BY*B);
						*lpframeU++ = (int)(RU*R + GU*G + BU*B + 128);
						*lpframeV++ = (int)(RV*R + GV*G + BV*B + 128);
					} while(--w);
				}

				if(rblank > 0)
				{
					memset(lpframeY, 0, rblank);
					memset(lpframeU, 128, rblank);
					memset(lpframeV, 128, rblank);
					lpframeY += rblank;
					lpframeU += rblank;
					lpframeV += rblank;
				}

				lpcurscanl -= bpscanl;
			} while(--h);
			break;

		default:
			fprintf(stderr, "\ninternal error: illegal pixsz value\n");
			exit(29); 
	}

	j = vblank - topblank;
	while(j > 0)
	{
		for(x = 0; x < width; x++)
		{
			*lpframeY++ = 0;
			Ubuffer[x + (topblank+lpbi->biHeight + j - 1)*width] = 128;
			Vbuffer[x + (topblank+lpbi->biHeight + j - 1)*width] = 128;
		}
	j--;
	}



	conv444to422(Ubuffer, Ubuffer422);
	conv444to422(Vbuffer, Vbuffer422);

	conv422to420(Ubuffer422, frame[1]);
	conv422to420(Vbuffer422, frame[2]);

    if (use_image_noise_reduction)
    {
        lpframeY = (unsigned char *)frame[0];
        softfilter(TempFilterBuffer, lpframeY, width, height);
        memcpy(lpframeY, TempFilterBuffer, width*height);

        lpframeU = (unsigned char *)frame[1];
        softfilter(TempFilterBuffer, lpframeU, width/2, height/2);
        memcpy(lpframeU, TempFilterBuffer, width*height/4);

        lpframeV = (unsigned char *)frame[2];
        softfilter(TempFilterBuffer, lpframeV, width/2, height/2);
        memcpy(lpframeV, TempFilterBuffer, width*height/4);
    }
}

// 水平滤波和2:1子采样
static void conv444to422(src,dst)
unsigned char *src, *dst;
{
	int i, j, im5, im4, im3, im2, im1, ip1, ip2, ip3, ip4, ip5, ip6;
	int width_div8;
	int h;

	if(cpu_MMX && width > 16 && (width & 15) == 0)
	{
		h = height;
		width_div8 = width >> 3;

		do
		{
			// prologue

			*dst++ = clp[(int)(228*(src[0]+src[1])
							   +70*(src[0]+src[2])
							   -37*(src[0]+src[3])
							   -21*(src[0]+src[4])
							   +11*(src[0]+src[5])
							   + 5*(src[0]+src[6])+256)>>9];
			*dst++ = clp[(int)(228*(src[2]+src[3])
							   +70*(src[1]+src[4])
							   -37*(src[0]+src[5])
							   -21*(src[0]+src[6])
							   +11*(src[0]+src[7])
							   + 5*(src[0]+src[8])+256)>>9];
			*dst++ = clp[(int)(228*(src[4]+src[5])
							   +70*(src[3]+src[6])
							   -37*(src[2]+src[7])
							   -21*(src[1]+src[8])
							   +11*(src[0]+src[9])
							   + 5*(src[0]+src[10])+256)>>9];
			*dst++ = clp[(int)(228*(src[6]+src[7])
							   +70*(src[5]+src[8])
							   -37*(src[4]+src[9])
							   -21*(src[3]+src[10])
							   +11*(src[2]+src[11])
							   + 5*(src[1]+src[12])+256)>>9];

			src += 8;

			_asm
			{
				mov esi, src				;// esi = src
				mov edi, dst				;// edi = dst
				mov ecx, width_div8
				sub ecx, 2					;// ecx = (width >> 3) - 2
conv444to422__l1:
				movq mm7, PACKED_255		;// mm7 = (255, 255, 255, 255)
				movq mm5, [esi-1]			;// mm5 = 4 words into esi[-1..6]
				movq mm4, [esi]				;// mm4 = 4 words into esi[0..7]
				movq mm1, [esi+1]			;// mm1 = 4 words into esi[1..8]
				movq mm3, [esi+2]			;// mm3 = 4 words into esi[2..9]
				pand mm5, mm7				;// keep only LSB of mm5
				pand mm4, mm7				;// keep only LSB of mm4
				pand mm1, mm7				;// keep only LSB of mm1
				pand mm3, mm7				;// keep only LSB of mm3
				paddw mm4, mm1				;// mm4 += mm1

⌨️ 快捷键说明

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