免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5290 | 回复: 9
打印 上一主题 下一主题

Linux下有什么库可以缩放bmp文件,轻量级的 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-03-11 17:12 |只看该作者 |倒序浏览
我程序里面要对一个Bmp文件缩放,比如从1024*768大小放大到1440*900,不知道linux下有什么现成的库可以用?
轻量级点的,不要OpenCV这种。
最好就是有这种

bitmap* resize (bitmap* src, int height, int width, int depth)

简单API的轻量级的库。

知道的兄弟请帮忙下哈

论坛徽章:
0
2 [报告]
发表于 2010-03-11 20:18 |只看该作者
imagemagick libgd sdl 等等

论坛徽章:
0
3 [报告]
发表于 2010-03-11 20:40 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
4 [报告]
发表于 2010-03-11 20:46 |只看该作者
我们图像是16位的,a:r:g:b = 1:5:5:5,如果是24位的,则要在r、g、b的分量处理上改动一下

  1.     unsigned int PtAR=0,PtBR=0,PtCR=0,PtDR=0,PixelValueR=0;//源A、B、C、D四点像素R值
  2.     unsigned int PtAG=0,PtBG=0,PtCG=0,PtDG=0,PixelValueG=0;//源A、B、C、D四点像素G值
  3.     unsigned int PtAB=0,PtBB=0,PtCB=0,PtDB=0,PixelValueB=0;//源A、B、C、D四点像素B值

  4.     register unsigned SpixelColNum=0,SpixelRowNum=0,DestCol=0,DestRow=0;
  5.     unsigned int SpixelColAddr=0,SpixelRowAddr=0;
  6.     unsigned int ColDelta=0,RowDelta=0,scaleV=0,scaleH=0;
  7.     unsigned int ContribAandBR=0,ContribCandDR=0;//ContribAandBR:源A、B两点像素R的插值,其他类似
  8.     unsigned int ContribAandBG=0,ContribCandDG=0;
  9.     unsigned int ContribAandBB=0,ContribCandDB=0;
  10.     unsigned short SColor, DColor; //源、目的像素

  11.     unsigned int _ContribTem[HOMESCREEN_WIDTH*3];
  12.     int i=0;
  13.     scaleH=(g_src_width<<8)/g_dsn_width;
  14.     scaleV=(g_src_height<<8)/g_dsn_height;
  15.          
  16.     //first line
  17.     for(DestCol=0;DestCol<g_dsn_width;DestCol++)
  18.     {
  19.         SpixelColAddr=DestCol*scaleH;
  20.         ColDelta=SpixelColAddr&255;
  21.         SpixelColNum=(SpixelColAddr-ColDelta)>>8;
  22.         SColor = *(unsigned short *)GET_SRC_BUFFER_PTR(SpixelRowNum,SpixelColNum);
  23.         PtAB=((SColor>>0)&0x1f);
  24.         PtAG=((SColor>>5)&0x1f);
  25.         PtAR=((SColor>>10)&0x1f);
  26.         if((SpixelColNum+1)<g_src_width)
  27.         {
  28.             SColor = *(unsigned short *)GET_SRC_BUFFER_PTR(SpixelColNum+1,SpixelRowNum);
  29.             PtBB=((SColor>>0)&0x1f);
  30.             PtBG=((SColor>>5)&0x1f);
  31.             PtBR=((SColor>>10)&0x1f);
  32.                           
  33.             SColor = *(unsigned short *)GET_SRC_BUFFER_PTR(SpixelColNum,SpixelRowNum+1);
  34.             PtCB=((SColor>>0)&0x1f);
  35.             PtCG=((SColor>>5)&0x1f);
  36.             PtCR=((SColor>>10)&0x1f);

  37.             SColor = *(unsigned short *)GET_SRC_BUFFER_PTR(SpixelColNum+1,SpixelRowNum+1);
  38.             PtDB=((SColor>>0)&0x1f);
  39.             PtDG=((SColor>>5)&0x1f);
  40.             PtDR=((SColor>>10)&0x1f);
  41.         }
  42.         else
  43.         {
  44.             PtBB=PtCB=PtDB=PtAB;
  45.             PtBG=PtCG=PtDG=PtAG;
  46.             PtBR=PtCR=PtDR=PtAR;
  47.         }

  48.         ContribAandBB=ColDelta*(PtBB-PtAB)+PtAB*256;
  49.         ContribCandDB=ColDelta*(PtDB-PtCB)+PtCB*256;
  50.         _ContribTem[i++]=ContribCandDB;
  51.         PixelValueB=(ContribAandBB*256+(ContribCandDB-ContribAandBB)*RowDelta)>>16;
  52.                      
  53.         ContribAandBG=ColDelta*(PtBG-PtAG)+PtAG*256;
  54.         ContribCandDG=ColDelta*(PtDG-PtCG)+PtCG*256;
  55.         _ContribTem[i++]=ContribCandDG;
  56.         PixelValueG=(ContribAandBG*256+(ContribCandDG-ContribAandBG)*RowDelta)>>16;
  57.                      
  58.         ContribAandBR=ColDelta*(PtBR-PtAR)+PtAR*256;
  59.         ContribCandDR=ColDelta*(PtDR-PtCR)+PtCR*256;
  60.         _ContribTem[i++]=ContribCandDR;
  61.         PixelValueR=(ContribAandBR*256+(ContribCandDR-ContribAandBR)*RowDelta)>>16;

  62.         DColor = (PixelValueR<<10) |(PixelValueG<<5) | (PixelValueB) | (0x8000);
  63.         dest = (unsigned short*)GET_FBBUFFER_PTR(_myfb, DestRow, DestCol);
  64.         *dest = DColor;

  65.     }

  66.     //////////other line//////////
  67.     for(DestRow=1;DestRow< g_dsn_height;DestRow++)
  68.     {
  69.         i=0;
  70.         SpixelRowAddr=DestRow*scaleV;
  71.         RowDelta=SpixelRowAddr&255;
  72.         SpixelRowNum=(SpixelRowAddr-RowDelta)>>8;
  73.                
  74.         for(DestCol=0;DestCol< g_dsn_width;DestCol++)
  75.         {
  76.             SpixelColAddr=DestCol*scaleH;
  77.             ColDelta=SpixelColAddr&255;
  78.             SpixelColNum=(SpixelColAddr-ColDelta)>>8;
  79.             SColor = *(unsigned short *)GET_SRC_BUFFER_PTR(SpixelColNum,SpixelRowNum);
  80.             PtAB=((SColor>>0)&0x1f);
  81.             PtAG=((SColor>>5)&0x1f);
  82.             PtAR=((SColor>>10)&0x1f);
  83.                      
  84.             if(((SpixelColNum+1)<g_src_width)&&((SpixelRowNum+1)<g_src_height))
  85.             {
  86.                 SColor = *(unsigned short *)GET_SRC_BUFFER_PTR(SpixelColNum,(SpixelRowNum+1));
  87.                 PtCB=((SColor>>0)&0x1f);
  88.                   PtCG=((SColor>>5)&0x1f);
  89.                 PtCR=((SColor>>10)&0x1f);
  90.                           
  91.                 SColor = *(unsigned short *)GET_SRC_BUFFER_PTR((SpixelColNum+1),SpixelRowNum+1);
  92.                 PtDB=((SColor>>0)&0x1f);
  93.                 PtDG=((SColor>>5)&0x1f);
  94.                 PtDR=((SColor>>10)&0x1f);
  95.             }
  96.             else
  97.             {
  98.                 PtBB=PtCB=PtDB=PtAB;
  99.                 PtBG=PtCG=PtDG=PtAG;
  100.                 PtBR=PtCR=PtDR=PtAR;
  101.             }
  102.                      
  103.                      
  104.             ContribAandBB=_ContribTem[i];
  105.             ContribCandDB=ColDelta*(PtDB-PtCB)+PtCB*256;
  106.             _ContribTem[i++]=ContribCandDB;
  107.             PixelValueB=(ContribAandBB*256+(ContribCandDB-ContribAandBB)*RowDelta)>>16;

  108.             ContribAandBG=_ContribTem[i];
  109.             ContribCandDG=ColDelta*(PtDG-PtCG)+PtCG*256;
  110.             _ContribTem[i++]=ContribCandDG;
  111.             PixelValueG=(ContribAandBG*256+(ContribCandDG-ContribAandBG)*RowDelta)>>16;

  112.             ContribAandBR=_ContribTem[i];
  113.          ContribCandDR=ColDelta*(PtDR-PtCR)+PtCR*256;
  114.             _ContribTem[i++]=ContribCandDR;
  115.             PixelValueR=(ContribAandBR*256+(ContribCandDR-ContribAandBR)*RowDelta)>>16;

  116.              DColor = (PixelValueR<<10) |(PixelValueG<<5) | (PixelValueB) | (0x8000);
  117.      dest = (unsigned short*)GET_FBBUFFER_PTR(_myfb, DestCol, DestRow);
  118.             *dest = DColor;
  119.         }
  120. }

复制代码

论坛徽章:
0
5 [报告]
发表于 2010-03-11 21:53 |只看该作者
libsdl我还得还算轻量吧. 使用起来非常方便, 不仅仅是bmp, jpg, png, gif处理起来也都很方便.

论坛徽章:
0
6 [报告]
发表于 2010-03-11 21:54 |只看该作者
gb库

论坛徽章:
0
7 [报告]
发表于 2010-03-12 09:32 |只看该作者
freeImage

论坛徽章:
0
8 [报告]
发表于 2010-03-12 10:17 |只看该作者
谢谢楼上诸位了!我去学习一下你们提到的。
以前一直不知道SDL还可以缩放图片,汗 ~~~

论坛徽章:
0
9 [报告]
发表于 2010-03-12 11:01 |只看该作者
再用libgd,感觉还行,你试试吧,sdl没用过,不知道合gd比哪个轻量级

论坛徽章:
1
水瓶座
日期:2014-03-20 18:21:14
10 [报告]
发表于 2010-03-12 15:38 |只看该作者
imagemagick直接用命令行就能搞定了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP