📄 yuv2yuv.c
字号:
__asm__ __volatile__ ( "emms" );
#endif
} else
#endif
#ifdef _MACINTOSH
/* check if we can use MMX-optimized code here: */
if (_AltiVec_Available)
{
/* process top line (if chroma is not pairable): */
if (dest_y & 1) {
AltiVec_lineI420toYUY2 (sy, su, sv, d, dest_dx);
sy += yPitch;
su += uPitch;
sv += vPitch;
d += dest_pitch;
dest_dy --;
}
/* the main loop (processes two lines a time): */
for (i = 0; i < dest_dy/2; i ++) {
AltiVec_lineI420toYUY2 (sy, su, sv, d, dest_dx);
sy += yPitch;
d += dest_pitch;
AltiVec_lineI420toYUY2 (sy, su, sv, d, dest_dx);
sy += yPitch;
su += uPitch;
sv += vPitch;
d += dest_pitch;
}
/* process the last line (if dy is odd): */
if (dest_dy & 1) {
AltiVec_lineI420toYUY2 (sy, su, sv, d, dest_dx);
}
/* end of MMX code */
} else
#endif
/* a generic "C" version: */
{
/* process top line (if chroma is not pairable): */
if (dest_y & 1) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(sy[j*2], su[j], sy[j*2+1], sv[j]);
sy += yPitch;
su += uPitch;
sv += vPitch;
d += dest_pitch;
dest_dy --;
}
/* the main loop (processes two lines a time): */
for (i = 0; i < dest_dy/2; i ++) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(sy[j*2], su[j], sy[j*2+1], sv[j]);
sy += yPitch;
d += dest_pitch;
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(sy[j*2], su[j], sy[j*2+1], sv[j]);
sy += yPitch;
su += uPitch;
sv += vPitch;
d += dest_pitch;
}
/* process the last line (if dy is odd): */
if (dest_dy & 1) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(sy[j*2], su[j], sy[j*2+1], sv[j]);
}
}
} else
/* check if no hue adjustment: */
if (!is_alpha) {
/* no chroma rotation: */
unsigned char *sy, *sv, *su, *d;
register int i, j;
/* get pointers: */
sy = pY + src_x + src_y * yPitch; /* luma offset */
su = pU + (src_x/2 + src_y/2 * uPitch);
sv = pV + (src_x/2 + src_y/2 * vPitch);
d = dest_ptr + dest_x * 2 + dest_y * dest_pitch; /* 2 bytes/pixel */
/* process top line (if chroma is not pairable): */
if (dest_y & 1) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], _uutab[su[j]], _yytab[sy[j*2+1]], _vvtab[sv[j]]);
sy += yPitch;
su += uPitch;
sv += vPitch;
d += dest_pitch;
dest_dy --;
}
/* the main loop (processes two lines a time): */
for (i = 0; i < dest_dy/2; i ++) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], _uutab[su[j]], _yytab[sy[j*2+1]], _vvtab[sv[j]]);
sy += yPitch;
d += dest_pitch;
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], _uutab[su[j]], _yytab[sy[j*2+1]], _vvtab[sv[j]]);
sy += yPitch;
su += uPitch;
sv += vPitch;
d += dest_pitch;
}
/* process the last line (if dy is odd): */
if (dest_dy & 1) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], _uutab[su[j]], _yytab[sy[j*2+1]], _vvtab[sv[j]]);
}
} else {
/* the most complex case (w. hue adjustment): */
unsigned char *sy, *sv, *su, *d;
register int i, j, u, v;
/* get pointers: */
sy = pY + src_x + src_y * yPitch; /* luma offset */
su = pU + (src_x/2 + src_y/2 * uPitch);
sv = pV + (src_x/2 + src_y/2 * vPitch);
d = dest_ptr + dest_x * 2 + dest_y * dest_pitch; /* 2 bytes/pixel */
/* process top line (if chroma is not pairable): */
if (dest_y & 1) {
for (j = 0; j < dest_dx/2; j ++) {
v = _CLIP(8,_vvtab[sv[j]] + _vutab[su[j]]);
u = _CLIP(8,_uutab[su[j]] + _uvtab[sv[j]]);
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], u, _yytab[sy[j*2+1]], v);
}
sy += yPitch;
su += uPitch;
sv += vPitch;
d += dest_pitch;
dest_dy --;
}
/* the main loop (processes two lines a time): */
for (i = 0; i < dest_dy/2; i ++) {
for (j = 0; j < dest_dx/2; j ++) {
v = _CLIP(8,_vvtab[sv[j]] + _vutab[su[j]]);
u = _CLIP(8,_uutab[su[j]] + _uvtab[sv[j]]);
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], u, _yytab[sy[j*2+1]], v);
*(unsigned int *)(d + j*4 + dest_pitch) = COMBINE(_yytab[sy[j*2 + yPitch]], u, _yytab[sy[j*2+1+yPitch]], v);
}
sy += yPitch*2;
su += uPitch;
sv += vPitch;
d += dest_pitch*2;
}
/* process the last line (if dy is odd): */
if (dest_dy & 1) {
for (j = 0; j < dest_dx/2; j ++) {
v = _CLIP(8,_vvtab[sv[j]] + _vutab[su[j]]);
u = _CLIP(8,_uutab[su[j]] + _uvtab[sv[j]]);
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], u, _yytab[sy[j*2+1]], v);
}
}
}
return 0;
}
/* conversion is not supported */
return -1;
}
/*
* I420toYUY2() converter:
*/
int I420toYUY2 (unsigned char *dest_ptr, int dest_width, int dest_height,
int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy,
unsigned char *src_ptr, int src_width, int src_height, int src_pitch,
int src_x, int src_y, int src_dx, int src_dy)
{
#if 1
unsigned char *pU = src_ptr+src_height*src_pitch,
*pV = pU + src_height*src_pitch/4;
return I420toYUY2x(dest_ptr, dest_width, dest_height, dest_pitch, dest_x, dest_y, dest_dx, dest_dy,
src_ptr, pU, pV,
src_width, src_height, src_pitch, src_pitch/2, src_pitch/2,
src_x, src_y, src_dx, src_dy);
#else
/* scale factors: */
int scale_x, scale_y;
/* check arguments: */
if (!chk_args (dest_ptr, dest_width, dest_height, dest_pitch,
dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height,
src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
return -1;
/* remove odd destination columns: */
if (!adjust_range (&dest_x, &dest_dx, &src_x, &src_dx, scale_x))
return 0;
/* check if we have misaligned input: */
if (src_x & 1)
return -1; /* can't shift chromas */
/* check if bottop-up images: */
if (dest_pitch < 0) dest_ptr -= (dest_height-1) * dest_pitch;
if (src_pitch <= 0) return -1; /* not supported */
/* check if 1:1 scale: */
if (scale_x == 1 && scale_y == 1) {
/* check if no color adjustments: */
if (!(is_alpha | is_beta | is_gamma | is_kappa)) {
/* no color adjustments: */
unsigned char *sy, *sv, *su, *d;
register int i, j;
/* get pointers: */
sy = src_ptr + src_x + src_y * src_pitch; /* luma offset */
su = src_ptr + src_height * src_pitch + (src_x/2 + src_y/2 * src_pitch);
sv = su + src_height * src_pitch / 4;
d = dest_ptr + dest_x * 2 + dest_y * dest_pitch; /* 2 bytes/pixel */
#if (defined(_M_IX86) || defined(_USE_MMX_BLENDERS)) && !defined(WINCE_EMULATOR)
/* check if we can use MMX-optimized code here: */
if (_x86_MMX_Available)
{
/* process top line (if chroma is not pairable): */
if (dest_y & 1) {
_MMX_lineI420toYUY2 (sy, su, sv, d, dest_dx);
sy += src_pitch;
su += src_pitch/2;
sv += src_pitch/2;
d += dest_pitch;
dest_dy --;
}
/* the main loop (processes two lines a time): */
for (i = 0; i < dest_dy/2; i ++) {
_MMX_lineI420toYUY2 (sy, su, sv, d, dest_dx);
sy += src_pitch;
d += dest_pitch;
_MMX_lineI420toYUY2 (sy, su, sv, d, dest_dx);
sy += src_pitch;
su += src_pitch/2;
sv += src_pitch/2;
d += dest_pitch;
}
/* process the last line (if dy is odd): */
if (dest_dy & 1) {
_MMX_lineI420toYUY2 (sy, su, sv, d, dest_dx);
}
/* end of MMX code */
#if defined(_M_IX86) && !defined(WINCE_EMULATOR)
__asm emms
#elif defined(_USE_MMX_BLENDERS) && !defined(WINCE_EMULATOR)
__asm__ __volatile__ ( "emms" );
#endif
} else
#endif
/* a generic "C" version: */
{
/* process top line (if chroma is not pairable): */
if (dest_y & 1) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(sy[j*2], su[j], sy[j*2+1], sv[j]);
sy += src_pitch;
su += src_pitch/2;
sv += src_pitch/2;
d += dest_pitch;
dest_dy --;
}
/* the main loop (processes two lines a time): */
for (i = 0; i < dest_dy/2; i ++) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(sy[j*2], su[j], sy[j*2+1], sv[j]);
sy += src_pitch;
d += dest_pitch;
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(sy[j*2], su[j], sy[j*2+1], sv[j]);
sy += src_pitch;
su += src_pitch/2;
sv += src_pitch/2;
d += dest_pitch;
}
/* process the last line (if dy is odd): */
if (dest_dy & 1) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(sy[j*2], su[j], sy[j*2+1], sv[j]);
}
}
} else
/* check if no hue adjustment: */
if (!is_alpha) {
/* no chroma rotation: */
unsigned char *sy, *sv, *su, *d;
register int i, j;
/* get pointers: */
sy = src_ptr + src_x + src_y * src_pitch; /* luma offset */
su = src_ptr + src_height * src_pitch + (src_x/2 + src_y/2 * src_pitch);
sv = su + src_height * src_pitch / 4;
d = dest_ptr + dest_x * 2 + dest_y * dest_pitch; /* 2 bytes/pixel */
/* process top line (if chroma is not pairable): */
if (dest_y & 1) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], _uutab[su[j]], _yytab[sy[j*2+1]], _vvtab[sv[j]]);
sy += src_pitch;
su += src_pitch/2;
sv += src_pitch/2;
d += dest_pitch;
dest_dy --;
}
/* the main loop (processes two lines a time): */
for (i = 0; i < dest_dy/2; i ++) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], _uutab[su[j]], _yytab[sy[j*2+1]], _vvtab[sv[j]]);
sy += src_pitch;
d += dest_pitch;
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], _uutab[su[j]], _yytab[sy[j*2+1]], _vvtab[sv[j]]);
sy += src_pitch;
su += src_pitch/2;
sv += src_pitch/2;
d += dest_pitch;
}
/* process the last line (if dy is odd): */
if (dest_dy & 1) {
for (j = 0; j < dest_dx/2; j ++)
*(unsigned int *)(d + j*4) = COMBINE(_yytab[sy[j*2]], _uutab[su[j]], _yytab[sy[j*2+1]], _vvtab[sv[j]]);
}
} else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -