void ConvertYVY22YUV12(unsigned char *src, unsigned char *dst, int width, int height, int stride)
{
unsigned char *in,*out_y,*out_y1,*out_u,*out_v;
int width2 = width*2;
in = src; out_y = dst;
out_y1 = dst+width;
out_u = dst + width*height;
out_v = dst + width*height + (width*height)/4; for (int i=0;i<height/2;i++) {
for (int j=0;j<width/2;j++) {
*out_y++ = *in;
*out_y1++ = *(in+width2);
in++;
*out_u++ = (*in + *(in+width2)) >> 1;
in++; *out_y++ = *in;
*out_y1++ = *(in+width2);
in++;
*out_v++ = (*in + *(in+width2)) >> 1;
in++;
}
in += width2;
out_y1 += width;
out_y += width;
}
}
void ConvertUYVY2YUV12(unsigned char *src, unsigned char *dst, int width, int height, int stride)
{
unsigned char *in,*out_y,*out_y1,*out_u,*out_v;
int width2 = width*2;
in = src; out_y = dst;
out_y1 = dst+width;
out_u = dst + width*height;
out_v = dst + width*height + (width*height)/4; for (int i=0;i<height/2;i++) {
for (int j=0;j<width/2;j++) {
*out_u++ = (*in + *(in+width2)) >> 1;
in++;
*out_y++ = *in;
*out_y1++ = *(in+width2);
in++; *out_v++ = (*in + *(in+width2)) >> 1;
in++;
*out_y++ = *in;
*out_y1++ = *(in+width2);
in++;
}
in += width2;
out_y1 += width;
out_y += width;
}
}
{
unsigned char *in,*out_y,*out_y1,*out_u,*out_v;
int width2 = width*2;
in = src; out_y = dst;
out_y1 = dst+width;
out_u = dst + width*height;
out_v = dst + width*height + (width*height)/4; for (int i=0;i<height/2;i++) {
for (int j=0;j<width/2;j++) {
*out_y++ = *in;
*out_y1++ = *(in+width2);
in++;
*out_u++ = (*in + *(in+width2)) >> 1;
in++; *out_y++ = *in;
*out_y1++ = *(in+width2);
in++;
*out_v++ = (*in + *(in+width2)) >> 1;
in++;
}
in += width2;
out_y1 += width;
out_y += width;
}
}
void ConvertUYVY2YUV12(unsigned char *src, unsigned char *dst, int width, int height, int stride)
{
unsigned char *in,*out_y,*out_y1,*out_u,*out_v;
int width2 = width*2;
in = src; out_y = dst;
out_y1 = dst+width;
out_u = dst + width*height;
out_v = dst + width*height + (width*height)/4; for (int i=0;i<height/2;i++) {
for (int j=0;j<width/2;j++) {
*out_u++ = (*in + *(in+width2)) >> 1;
in++;
*out_y++ = *in;
*out_y1++ = *(in+width2);
in++; *out_v++ = (*in + *(in+width2)) >> 1;
in++;
*out_y++ = *in;
*out_y1++ = *(in+width2);
in++;
}
in += width2;
out_y1 += width;
out_y += width;
}
}
var
in: PAnsiChar;
out_y: PAnsiChar;
out_y1: PAnsiChar;
out_u: PAnsiChar;
out_v: PAnsiChar;
width2: integer;
i: integer;
j: integer;
begin
width2 := width * 2;
out_y := @dst[0];
out_y1 := @dst[width];
out_u := @dst[width * height];
out_v := @dst[width * height + (width * height) / 4]; for i := 0 to height / 2 - 1 do
begin
for j := 0 to width / 2 - 1 do
begin
out_y[0] := in[0];
inc(out_y);
out_y1[0] := in[width2];
inc(out_y1);
inc(in);
out_u[0] := (in[0] + in[width2]) >> 1;
inc(out_u);
inc(in); out_y[0] := in[0];
inc(out_y);
out_y1[0] := in[width2];
inc(out_y1);
inc(in);
out_v[0] := (in[0] + in[width2]) >> 2;
inc(out_v);
inc(in);
end; inc(in,width2);
inc(out_y1,width);
inc(out_y,width);
end;
end;
位移的操作在 DELPHI 里好象还可以用 shr/shl 来做。
var
_in, out_y, out_yl, out_u, out_v, pTemp: ^PChar;
i, j, width2: integer;
begin
width2 := width2 * 2;
_in := src;
out_y := dst;
out_y1 := dst;
out_u := dst;
out_u := dst;
out_v := dst;
Inc(out_y1,width);
Inc(out_u,width * height);
Inc(out_v,width * height + (width * height) / 4); for i=0 to height/2-1 do begin
for j=0 to width/2-1 do begin
out_y^ := out_y^ + _in^;
out_y1^ := out_y1^ * (_in^ + width2);
Inc(_in);
pTemp := _in;
Inc(pTemp,width2);
out_u^ := out_u^ + ((^_in + ^pTemp) shr 1);
Inc(_in); ^out_y := ^out_y + ^_in;
pTemp ;= _in;
Inc(pTemp,width2);
^out_y1 := ^out_y1 + ^pTemp;
Inc(_in);
pTemp ;= _in;
Inc(pTemp,width2);
^out_v := ^out_v + ((^_in + ^pTemp) shr 1);
Inc(_in);
end;
Inc(_in,width2);
Inc(out_y1,width);
Inc(out_y,width);
end;
end;
经常在 DELPHI/VC/ASP/JS 中交替编程,所以很多时候经常搞混淆语法,不知该悲还是该喜:)
在 C++ 中按标准的 DLL 格式来书写就行了
^是乘方的意思吧