设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1558|回复: 5
打印 上一主题 下一主题

[有事请教] C++求优化。。

[复制链接]

Lv2.观梦者

傻♂逼

梦石
0
星屑
374
在线时间
1606 小时
注册时间
2007-3-13
帖子
6562

烫烫烫开拓者

跳转到指定楼层
1
发表于 2011-11-5 17:49:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 yangff 于 2011-11-5 17:49 编辑
  1. int __declspec(dllexport) NextFrame(int Bitmap,int playerHandle)
  2. {
  3.         int * pBitmap=(int *)Bitmap;
  4.         if (GetNextFrame(pFormatCtx, pCodecCtx, videoStream, pFrame))
  5.         {
  6.                 //struct SwsContext * img_convert_ctx;
  7.                 //img_convert_ctx=sws_getContext( pCodecCtx->width/12, pCodecCtx->height/12,PIX_FMT_RGB32,pCodecCtx->width,pCodecCtx->height,PIX_FMT_YUV420P,2,NULL,NULL,NULL);
  8.                 uint8_t *data = malloc (3*pCodecCtx->width*pCodecCtx->height);
  9.                 uint8_t *src[3]= {data, data+pCodecCtx->width*pCodecCtx->height, data+pCodecCtx->width*pCodecCtx->height+pCodecCtx->width*pCodecCtx->height};
  10.                 //int stride[3]={pCodecCtx->width, pCodecCtx->width, pCodecCtx->width};
  11.                 //sws_scale(img_convert_ctx,(const uint8_t*  const*)pFrame->data,pFrame->linesize,0,pCodecCtx->height,src,stride);
  12.                 int p=0;
  13.                 int r,g,b=0;
  14.                 double y,u,v;
  15.                 int off=pCodecCtx->width*pCodecCtx->height;
  16.                 int off1=pCodecCtx->width*pCodecCtx->height*1;
  17.                 frame(pCodecCtx->height,pCodecCtx->width,data,pFrame);
  18.                 //pBitmap[pCodecCtx->width*pCodecCtx->height-1]=0xffffaaff;
  19.             for (int i=pCodecCtx->height-1;i>=0;i--){
  20.                 for (int j=0;j<pCodecCtx->width;j++)
  21.                 {        //if (i*pCodecCtx->width+j<pCodecCtx->height*pCodecCtx->width)
  22.                         pBitmap[p]=0xff000000 ;
  23.                         y=(double)src[0][i*pCodecCtx->width+j];//pFrame->pp;//data[0][p+off];
  24.                     u=(double)src[1][(i/2*pCodecCtx->width+j)/2];//pFrame->pp;//data[0][p+off1];
  25.                         v=(double)src[2][(i/2*pCodecCtx->width+j)/2];//pFrame->pp//data[0][p+off1+off];
  26.                         r=(int)(1.164f*(y-16)+1.596f*(v-128));
  27.                         g=(int)(1.164f*(y-16)-0.813f*(v - 128) - 0.391f*(u - 128));
  28.                         b=(int)(1.164f*(y-16)+2.018f*(u - 128));
  29.                         if (r>255) r=255; if (r<0) r=0;
  30.                         if (g>255) g=255; if (g<0) g=0;
  31.                         if (b>255) b=255; if (b<0) b=0;
  32.                         pBitmap[p]|= b; //b
  33.                         pBitmap[p]|= g << 8; // g
  34.                         pBitmap[p]|= r << 16; // r
  35.                         // | data[((j+i*pCodecCtx->width+pCodecCtx->width*pCodecCtx->height) << 8)];// | data[((j+i*pCodecCtx->width+pCodecCtx->width*pCodecCtx->height*2) << 16)] | (0xff << 24);
  36.                         p++;
  37.                 }}
  38.                 free(data);
  39.                 return 1;        }
  40.                
  41.         return -1;
  42. }
复制代码
哎呀,蛋疼什么的最有爱了

Lv3.寻梦者

梦石
0
星屑
2391
在线时间
54 小时
注册时间
2011-11-23
帖子
4
2
发表于 2012-3-20 14:19:29 | 只看该作者
坑爹啊,C++发这里
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
32 小时
注册时间
2011-7-15
帖子
38
3
发表于 2012-3-20 14:22:03 | 只看该作者
就是啊, 这里不是让你发C++的地方

点评

水区可以发无误  发表于 2012-3-20 18:37
这个我也拿他没办法==  发表于 2012-3-20 16:06
水区,无所不能  发表于 2012-3-20 15:49
E
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
8055
在线时间
7346 小时
注册时间
2010-7-16
帖子
4915

开拓者

4
发表于 2012-3-20 19:53:43 | 只看该作者
那个frame是什么,为什么要建个临时data
还有Bitmap应该是个数组吧,不然怎么能转指针。楼主试着执行过这段代码吗?
回复 支持 反对

使用道具 举报

Lv2.观梦者

傻♂逼

梦石
0
星屑
374
在线时间
1606 小时
注册时间
2007-3-13
帖子
6562

烫烫烫开拓者

5
 楼主| 发表于 2012-3-20 20:21:38 | 只看该作者
熊的选民 发表于 2012-3-20 19:53
那个frame是什么,为什么要建个临时data
还有Bitmap应该是个数组吧,不然怎么能转指针。楼主试着执行过这段 ...

ffmpeg的解码代码。。具体可以看sample,主要是yuv到rgba32效率蛋疼啊
哎呀,蛋疼什么的最有爱了
回复 支持 反对

使用道具 举报

Lv1.梦旅人

风之塞尔达

梦石
0
星屑
50
在线时间
57 小时
注册时间
2005-10-22
帖子
2492

贵宾

6
发表于 2012-3-21 12:52:01 | 只看该作者
本帖最后由 link006007 于 2012-3-21 12:53 编辑

不知道该解码数学原理的,优化基本天方夜谭。。。。。。。。。
如果只是从语言语法上来优化,推荐intel或者其他编译器厂商自带的优化工具,优化库和优化选项,编译器知道的比大部分“可能是高手”程序员知道的要多的多。。。
intel有一个ipp库,以前写一个g729解码,效率很淡疼,后来找了个ipp版本的,立马感觉就不一样了。。
在程序里延续塞尔达的传说, 在画板上勾勒塞尔达的轮廓!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-2-23 05:24

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表