c++源码翻译为delphi

windyhero 2005-09-15 09:30:43
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;
}
}
...全文
130 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
windyhero 2006-07-04
  • 打赏
  • 举报
回复
怎么不能给分了
windyhero 2006-07-04
  • 打赏
  • 举报
回复
虽然问题没有解决我还是把分给大家了,代码还是不对
cumtbwxj 2005-09-16
  • 打赏
  • 举报
回复
位移的操作在 DELPHI 里用 shr/shl 来做。
^是乘方的意思吧
windyhero 2005-09-15
  • 打赏
  • 举报
回复
我没用过vc
有没有时间去慢慢调,节约时间呀
明天调试通过了就给分
谢谢大家了
布学无数 2005-09-15
  • 打赏
  • 举报
回复
楼主要封装成 DLL 的话其实比较简单啦
在 C++ 中按标准的 DLL 格式来书写就行了
布学无数 2005-09-15
  • 打赏
  • 举报
回复
汗颜,只是手头上没有 DELPHI ,一时间记不起怎么取字符才这样做的啦!!!
经常在 DELPHI/VC/ASP/JS 中交替编程,所以很多时候经常搞混淆语法,不知该悲还是该喜:)
SGP 2005-09-15
  • 打赏
  • 举报
回复
lonely001(独行客)用数组不错啊!
SGP 2005-09-15
  • 打赏
  • 举报
回复
没试过

procedure ConvertYVY22YUV12(src: ^PChar; dst: ^PChar; width: integer; hight: integer; stride: integer);
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;
windyhero 2005-09-15
  • 打赏
  • 举报
回复
另外,能不能告诉我怎么把他封装成动态连接库(在C++里面)
windyhero 2005-09-15
  • 打赏
  • 举报
回复
PAnsiChar为什么不是pChar 或 pByte类型呢?

明天我测试,正确了就给分

布学无数 2005-09-15
  • 打赏
  • 举报
回复
手头上没有 DELPHI ,没调试过哦:)
位移的操作在 DELPHI 里好象还可以用 shr/shl 来做。
布学无数 2005-09-15
  • 打赏
  • 举报
回复
procedure ConvertYVY22YUV12(src: PAnsiChar; dst: PAnsiChar; width: integer; height: integer; stride: integer);
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;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧