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

📄 yuv2rgb.c

📁 PocketMVP V0.8082503 source for Pocket 的程序源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
 
  "lbu $10,1($4);" 
  "lbu $18,1($17);" 
  "addi $4,$4,+1;" 
  "addi $17,$17,+1;"//sumamos al interpolado 
  "addi $16,$16,-1;"); 
 
__asm( "bucle_x2:add $14,$10,$11;" //r3 
  "sra $15,$14,31;"
  "srlv $15,$14,$15;"
  "add $24,$15,$0;" 
  "srl $24,$24,3;" 
 
  //g3 
 
  "addi $14,$10,-16;" 
  "sra $15,$14,31;"
  "srlv $15,$14,$15;"
  "andi $15,$15,0x00FC;" 
  "sll $14,$15,3;" 
  "or  $24,$24,$14;" 
 
  //b3 
 
  "add $14,$10,$12;" 
  "sra $15,$14,31;"
  "srlv $15,$14,$15;"
  "andi $15,$15,0x00F8;" 
  "sll $14,$15,8;" 
  "or  $24,$24,$14;" 
 
  //calculamos el punto interpolado 
 
  "srl $14,$13,1;"//div por 2 p1 
  "srl $15,$24,1;"//y p2 
 
  "andi $14,$14,0x7BEF;"//los enmascaramos 
  "andi $15,$15,0x7BEF;" 
 
  "addu $13,$14,$15;"
  "sll $15,$24,16;"
  "or  $13,$13,$15;"
  "sw  $13,0($25);" 
  );//y los sumamos 
 
  //re2 
__asm( "srl $10,$10,1;" 
  "srl $18,$18,1;" 
 
  "add $18,$18,$10;" 
 
  "add $14,$18,$11;" 
  "sra $15,$14,31;"
  "srlv $15,$14,$15;" 
  "srl $20,$15,3;" 
  
  //ge2 
  
  "addi $14,$18,-16;" 
  "sra $15,$14,31;"
  "srlv $15,$14,$15;" 
  "andi $14,$15,0x00FC;" 
  "sll $14,$14,3;" 
  "or  $20,$20,$14;" 
  
  //be2 
  
  "add $14,$18,$12;" 
  "sra $15,$14,31;"
  "srlv $15,$14,$15;" 
  "andi $14,$15,0x00F8;" 
  "sll $14,$14,8;" 
  "or  $20,$20,$14;" 
 
/// 
 
  "srl $14,$19,1;"//div por 2 p1 
  "srl $15,$20,1;"//y p2 
 
  "andi $14,$14,0x7BEF;"//los enmascaramos 
  "andi $15,$15,0x7BEF;" 
 
  "addu $19,$14,$15;"//y los sumamos 
 

  //guardamos puntos 
  
  "sll $15,$20,16;"
  "or  $19,$19,$15;"
 
  "sw  $19,0($21);" 
 
 
  //cambiamos de lugar ultimo punto 
 
  "add $13,$24,$0;" 
  "add $19,$20,$0;" 
); 
 
  //incrementamos punteros 
 
__asm( "lbu $10,0($4);"//cargamos nuevo puc_y 
  "lbu $18,0($17);" 
  "addi $4,$4,+1;" 
  "sll $14,$16,31;" 
  "addi $17,$17,+1;" 
  "addi $16,$16,-1;" 
  "addi $25,$25,+4;" 
  "addi $21,$21,+4;"
  "beq $14,$0,par_x1;" 
  "addi $6,$6,+1;" 
  "addi $7,$7,+1;" 
  "lbu $12,0($7);" 
  "lbu $11,0($6);" 
  "addi $12,$12,-144;" 
  "addi $11,$11,-144;" 
  "par_x1:bgtz $16,bucle_x2;"); 
 
__asm( //aumentamos strides: 
  "sll $14,$2,31;" 
  "add $4,$4,$5;" 
  "add $17,$17,$5;" 
  "srl $15,$3,1;" 
  "sub $6,$6,$15;" 
  "sub $7,$7,$15;" 
  "beq $14,$0,par_1;" 
  "add $6,$6,$8;" 
  "add $7,$7,$8;" 
  
  //aumentamos stride_dest 
  
  "par_1:addi $2,$2,-1;" 
  "sll $14,$3,1;"
  "sub $21,$21,$14;"
  "add $25,$21,$9;"
  "addi $25,$25,4;"
 
  "add $21,$25,$9;"
  "add $21,$21,$14;"
  "bgtz $2,bucle_y2;" 
 
  "lw  $16,0(sp);" 
  "lw  $17,4(sp);" 
  "lw  $18,8(sp);" 
  "lw  $19,12(sp);" 
  "lw  $20,16(sp);" 
  "lw  $21,20(sp);"
  "addiu sp,sp,+36;" ); 
} 

#else


#ifdef ARM
#ifndef ATI
void yuv2rgb_565D(uint8_t *puc_y, int stride_y, 
uint8_t *puc_u, uint8_t *puc_v, int stride_uv, 
uint8_t *puc_out, int width_y, int height_y,int stride_dest, int Dither,int Brightness, uint8_t *puc_yp,uint8_t *puc_up,uint8_t *puc_vp, int slowopt, int xStart, int xEnd, int xStep) 
{ 
//Floyd-Steinberg dithered version of the yuv2rgbHQ
	register int x,y; 
	register int temp_y,temp_Guv,temp_Guv1,temp_Guv2; 
	unsigned int *pus_out; 
	register unsigned int r,g,b; 
	register int quant_error_r=0,quant_error_g=0,quant_error_b=0;
//	unsigned char* LimitValue=&LimitValues[256];
	int r_adjust=(0x0F);
	int g_adjust=(0x0F);
	int b_adjust=(0x0F);
	if (Dither==1)
	{
		r_adjust=(0x07);
		g_adjust=(0x03);
		b_adjust=(0x07);
	}
	Brightness-=16;
	pus_out = (unsigned int *) (puc_out); 
	for (y=0; y<height_y; y+=2)
	{ 		
		//if (y==lastpel) width_y-=2;
		for (x=xStart;x!=xEnd;x+=(xStep<<1))
		{ 
			if ((!slowopt)||(puc_y[x]-puc_yp[x]||(puc_y[x+stride_y]-puc_yp[x+stride_y])||(puc_u[x>>1]-puc_up[x>>1])||(puc_v[x>>1]-puc_vp[x>>1])))
			{
				unsigned int hvalue;
				temp_y=9576*(puc_y[x]+Brightness);
				temp_Guv=-3218*(puc_u[x>>1]-128)-6686*(puc_v[x>>1]-128);
				temp_Guv2=16591*(puc_v[x>>1]-128);
				temp_Guv1=13123*(puc_u[x>>1]-128);
				r = _S(((temp_y+temp_Guv1)>>13)+ quant_error_r); 
				g = _S(((temp_y+temp_Guv)>>13)+quant_error_g); 
				b = _S(((temp_y+temp_Guv2)>>13)+ quant_error_b); 
				hvalue = (unsigned int) _Ps565(r,g,b); 
				quant_error_r=(r&r_adjust);
				quant_error_g=(g&g_adjust);
				quant_error_b=(b&b_adjust);
				temp_y=9576*(puc_y[x+xStep]+Brightness);
				r =  _S(((temp_y+temp_Guv1)>>13)+ quant_error_r); 
				g =  _S(((temp_y+temp_Guv)>>13)+quant_error_g); 
				b =  _S(((temp_y+temp_Guv2)>>13)+ quant_error_b); 

				quant_error_r=(r&r_adjust);
				quant_error_g=(g&g_adjust);
				quant_error_b=(b&b_adjust);
				pus_out[0] = hvalue|(((unsigned int) _Ps5652(r,g,b))); 
				temp_y=9576*(puc_y[x+stride_y]+Brightness);
				r =  _S(((temp_y+temp_Guv1)>>13)+ quant_error_r); 
				g =  _S(((temp_y+temp_Guv)>>13)+quant_error_g); 
				b =  _S(((temp_y+temp_Guv2)>>13)+ quant_error_b); 
				hvalue = (unsigned int) _Ps565(r,g,b); 
				quant_error_r=(r&r_adjust);
				quant_error_g=(g&g_adjust);
				quant_error_b=(b&b_adjust);
				temp_y=9576*(puc_y[x+stride_y+xStep]+Brightness);
				r =  _S(((temp_y+temp_Guv1)>>13)+ quant_error_r); 
				g =  _S(((temp_y+temp_Guv)>>13)+quant_error_g); 
				b =  _S(((temp_y+temp_Guv2)>>13)+ quant_error_b); 
				quant_error_r=(r&r_adjust);
				quant_error_g=(g&g_adjust);
				quant_error_b=(b&b_adjust);
				pus_out[(width_y+stride_dest)>>1] = hvalue|(((unsigned int) _Ps5652(r,g,b))); 
			}
			pus_out++; 
		} 
		puc_y += stride_y<<1; 
		puc_yp+=stride_y<<1;
		pus_out+=(width_y>>1)+stride_dest;
		puc_u += stride_uv; 
		puc_v += stride_uv; 
		puc_up += stride_uv; 
		puc_vp += stride_uv; 
	} 
} 


void yuv2rgb_565ZD(uint8_t *puc_y, int stride_y, 
uint8_t *puc_u, uint8_t *puc_v, int stride_uv, 
uint8_t *puc_out, int width_y, int height_y, int nExtra, int Dither,int Brightness,uint8_t *puc_yp,uint8_t *puc_up,uint8_t *puc_vp, int slowopt, int xStart, int xEnd, int xStep) 
{ 
//Floyd-Steinberg dithered version of the yuv2rgbHQ
	register int x,y; 
	register signed int temp_y,temp_Guv,next_y,next_Guv; 
	unsigned int *pus_out; 
	register unsigned int r,g,b; 
	register int quant_error_r,quant_error_g,quant_error_b;
	register int quant_error_r2,quant_error_g2,quant_error_b2;
	int we;
	int r_adjust=(0x0F);
	int g_adjust=(0x0F);
	int b_adjust=(0x0F);
	//unsigned char* LimitValue=&LimitValues[256];
	if (Dither==1)
	{
		r_adjust=(0x07);
		g_adjust=(0x03);
		b_adjust=(0x07);
	}
	Brightness-=16;
//	if ((height_y<<1)>VisibleHeight) height_y=VisibleHeight>>1;
//	if ((width_y<<1)>VisibleWidth) width_y=VisibleWidth>>1;
//	if (nExtra<0) nExtra=0;
	we=width_y+nExtra;
	pus_out = (unsigned int *) puc_out;	//I can磘 get it working with hold 
	quant_error_r=quant_error_g=quant_error_b=0;
	quant_error_r2=quant_error_g2=quant_error_b2=0;
	for (y=0; y<height_y; y++) 
	{ 
		quant_error_r2=quant_error_g2=quant_error_b2=6;
		//if (y==119) width_y-=1; //don't want to go outside the border.
		for (x=xStart;x!=xEnd;x+=xStep)
		{ 
			int x2=x>>1;//add tolerance of 1 
			if ((!slowopt)||(puc_y[x]!=puc_yp[x]||(puc_u[x2]!=puc_up[x2])||(puc_v[x2]!=puc_vp[x2])))
			{
				unsigned int hvalue,hvalue2,hvalue3,hvalue4;
				 
				temp_y=9576*(puc_y[x]+Brightness);
				temp_Guv=-3218*(puc_u[x2]-128)-6686*(puc_v[x2]-128);
				r = _S(((temp_y+13123*(puc_u[x2]-128))>>13)+ quant_error_r); 
				g = _S(((temp_y+temp_Guv)>>13)+quant_error_g); 
				b = _S(((temp_y+16591*(puc_v[x2]-128))>>13)+ quant_error_b); 
				quant_error_r=(r&r_adjust);
				quant_error_g=(g&g_adjust);
				quant_error_b=(b&b_adjust);
				hvalue=(unsigned short) _Ps565(r,g,b);
				
				temp_y=9576*(puc_y[x+stride_y]+Brightness);

				if (y<<31) 
				{ 
					temp_Guv=-3218*(puc_u[stride_uv+x2]-128)-6686*(puc_v[stride_uv+x2]-128);
					r+= _S(((temp_y+13123*(puc_u[stride_uv+x2]-128))>>13)+ quant_error_r2); 
					g+= _S(((temp_y+temp_Guv)>>13)+quant_error_g2); 
					b+= _S(((temp_y+16591*(puc_v[stride_uv+x2]-128))>>13)+ quant_error_b2); 
				}
				else
				{
					r+= _S(((temp_y+13123*(puc_u[x2]-128))>>13)+ quant_error_r2); 
					g+= _S(((temp_y+temp_Guv)>>13)+quant_error_g2); 
					b+= _S(((temp_y+16591*(puc_v[x2]-128))>>13)+ quant_error_b2); 
				}
				r = (r>>1);
				g = (g>>1);
				b = (b>>1);
				quant_error_r=(r&r_adjust);
				quant_error_g=(g&g_adjust);
				quant_error_b=(b&b_adjust);
				hvalue2=(unsigned short) _Ps565(r,g,b);

				if (x+xStep!=width_y)
				{
					temp_y=9576*(puc_y[x+xStep]+Brightness);
					temp_Guv=-3218*(puc_u[(x+xStep)>>1]-128)-6686*(puc_v[(x+xStep)>>1]-128);
					r += _S(((temp_y+13123*(puc_u[(x+xStep)>>1]-128))>>13)+ quant_error_r); 
					g += _S(((temp_y+temp_Guv)>>13)+quant_error_g); 
					b += _S(((temp_y+16591*(puc_v[(x+xStep)>>1]-128))>>13)+ quant_error_b); 
					r = (r>>1);
					g = (g>>1);
					b = (b>>1);
					quant_error_r=(r&r_adjust);
					quant_error_g=(g&g_adjust);
					quant_error_b=(b&b_adjust);
					hvalue3=(unsigned short)_Ps565(r,g,b);
					next_y=9576*(puc_y[x+xStep+stride_y]-16);

					if (y<<31) 
					{ 
						next_Guv=-3218*(puc_v[stride_uv+((x+xStep)>>1)]-128)-6686*(puc_u[stride_uv+((x+xStep)>>1)]-128);
						r += _S(((next_y+13123*(puc_u[stride_uv+((x+xStep)>>1)]-128))>>13)+ quant_error_r2); 
						g += _S(((next_y+next_Guv)>>13)+quant_error_g2); 
						b += _S(((next_y+16591*(puc_v[stride_uv+((x+xStep)>>1)]-128))>>13)+ quant_error_b2); 
					}
					else
					{
						r += _S(((next_y+13123*(puc_u[((x+xStep)>>1)]-128))>>13)+ quant_error_r2); 
						g += _S(((next_y+temp_Guv)>>13)+quant_error_g2); 
						b += _S(((next_y+16591*(puc_v[((x+xStep)>>1)]-128))>>13)+ quant_error_b2); 
					}
					r = (r>>1);
					g = (g>>1);
					b = (b>>1);
					quant_error_r=(r&r_adjust);
					quant_error_g=(g&g_adjust);
					quant_error_b=(b&b_adjust);
					hvalue4=(unsigned short) _Ps565(r,g,b);
				}
				else
				{
					hvalue2=hvalue;
				}
				pus_out[0] =hvalue|(hvalue3<<16);
				pus_out[we>>1]=hvalue2|(hvalue4<<16);
			}
			pus_out++;
		} 
		pus_out+=nExtra;
		puc_y += stride_y; 
		puc_yp += stride_y; 
		if (y<<31) 
		{ 
			puc_u += stride_uv; 
			puc_v += stride_uv; 
			puc_up += stride_uv; 
			puc_vp += stride_uv; 
		} 
	}
} 
#endif
#ifdef IPAQ //||(defined(MIPS))

void yuv2rgb_565(uint8_t *puc_y, int stride_y, 
uint8_t *puc_u, uint8_t *puc_v, int stride_uv, 
uint8_t *puc_out, int width_y, int height_y,int stride_dest, int Dither,int Brightness,uint8_t *puc_yp,uint8_t *puc_up,uint8_t *puc_vp, int slowopt, int invert) 
{ 
//Floyd-Steinberg dithered version of the yuv2rgbHQ
	register int x,y; 
	unsigned int *pus_out; 
	register unsigned int r,g,b; 
	//unsigned char* LimitValue=&LimitValues[256];
	int xStart=0,xEnd=width_y,xStep=1;
	if (stride_dest>=0)
	{
		if (height_y>VisibleHeight)
		{
			puc_y+=(height_y-VisibleHeight)*(stride_y>>1);
			puc_u+=(height_y-VisibleHeight)*(stride_uv>>2);
			puc_v+=(height_y-VisibleHeight)*(stride_uv>>2);
			puc_yp+=(height_y-VisibleHeight)*(stride_y>>1);
			puc_up+=(height_y-VisibleHeight)*(stride_uv>>2);
			puc_vp+=(height_y-VisibleHeight)*(stride_uv>>2);
			height_y=VisibleHeight;
		}
		if (width_y>VisibleWidth)
		{
			puc_y+=(width_y-VisibleWidth)>>1;
			puc_u+=(width_y-VisibleWidth)>>2;
			puc_v+=(width_y-VisibleWidth)>>2;
			puc_yp+=(width_y-VisibleWidth)>>1;
			puc_up+=(width_y-VisibleWidth)>>2;
			puc_vp+=(width_y-VisibleWidth)>>2;
			width_y=VisibleWidth;
		}
		if (invert)
		{
			puc_y += (height_y - 1) * stride_y ; 
			puc_u += (height_y/2 - 1) * stride_uv; 
			puc_v += (height_y/2 - 1) * stride_uv; 
			puc_yp += (height_y - 1) * stride_y ; 
			puc_up += (height_y/2 - 1) * stride_uv; 
			puc_vp += (height_y/2 - 1) * stride_uv; 
			stride_y = -stride_y; 
			stride_uv = -stride_uv; 
			xStart=width_y-1;
			xEnd=-1;
			//lastpel=238;
			xStep=-1;
		}
		else
		{
			xEnd=width_y;
		}
	}
	else
	{
		if (width_y>VisibleHeight)
		{
			puc_y+=(width_y-VisibleHeight)>>1;
			puc_u+=(width_y-VisibleHeight)>>2;
			puc_v+=(width_y-VisibleHeight)>>2;
			width_y=VisibleHeight;
		}
		if (height_y>VisibleWidth)
		{
			puc_y+=(height_y-VisibleWidth)*(stride_y>>1);
			puc_u+=(height_y-VisibleWidth)*(stride_uv>>2);
			puc_v+=(height_y-VisibleWidth)*(stride_uv>>2);
			height_y=VisibleWidth;
		}
		xEnd=width_y;
		stride_dest=0;
//		lastpel=318;
	}
	if (Dither) 
	{
		yuv2rgb_565D(puc_y, stride_y, puc_u, puc_v, stride_uv, puc_out, width_y, height_y,stride_dest, Dither,Brightness,puc_yp,puc_up,puc_vp,slowopt,xStart,xEnd,xStep);
		return;
	}
	Brightness-=16;
	pus_out = (unsigned int *) (puc_out); 
	for (y=height_y; y!=0; y-=2)
	{ 		
//		if (y==lastpel) width_y-=2;
		for (x=xStart;x!=xEnd;x+=(xStep<<1))
		{ 
			int x2=x>>1;
			if ((!slowopt)||(puc_y[x]-puc_yp[x]||(puc_y[x+stride_y]-puc_yp[x+stride_y])||(puc_u[x>>1]-puc_up[x>>1])||(puc_v[x>>1]-puc_vp[x>>1])))
			{
				unsigned int hvalue;
				int y,u,v;
				y = (puc_y[x] + Brightness)*0x2568;
				u = puc_u[x2] - 128;
				v = puc_v[x2] - 128;
				r = _S(_R(y,u,v));
				g= _S(_G(y,u,v));
				b=_S(_B(y,u,v));
				hvalue = (unsigned int) _Ps565(r,g,b); 
				y = (puc_y[x+xStep] + Brightness)*0x2568;
				r =_S(_R(y,u,v));
				g= _S(_G(y,u,v));
				b=_S(_B(y,u,v));
				pus_out[0] = hvalue|(((unsigned int) _Ps5652(r,g,b))); 
				y = (puc_y[x+stride_y] + Brightness)*0x2568;
				r =_S(_R(y,u,v));
				g= _S(_G(y,u,v));
				b=_S(_B(y,u,v));
				hvalue = (unsigned int) _Ps565(r,g,b); 
				y = (puc_y[x+stride_y+xStep] + Brightness)*0x2568;
				r = _S(_R(y,u,v));
				g= _S(_G(y,u,v));
				b=_S(_B(y,u,v));
				pus_out[(width_y+stride_dest)>>1] = hvalue|(((unsigned int) _Ps5652(r,g,b))); 
			}
			pus_out++; 
		} 
		puc_y += stride_y<<1; 
		puc_yp+=stride_y<<1;
		pus_out+=(width_y>>1)+stride_dest;
		puc_u += stride_uv; 
		puc_v += stride_uv; 
		puc_up += stride_uv; 
		puc_vp += stride_uv; 
	} 
} 


void yuv2rgb_565Z(uint8_t *puc_y, int stride_y, 
uint8_t *puc_u, uint8_t *puc_v, int stride_uv, 
uint8_t *puc_out, int width_y, int height_y, int nExtra, int Dither,int Brightness,uint8_t *puc_yp,uint8_t *puc_up,uint8_t *puc_vp, int slowopt, int invert) 
{ 

	register int x,y; 
	register signed int temp_y,temp_Guv,next_y,next_Guv; 
	register signed int temp,tempnextx,tempnexty,tempnextxy; 
	unsigned int *pus_out; 
	register unsigned int r,g,b; 

⌨️ 快捷键说明

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