求在linux下framebuffer显示gif图片的代码,简单明了点的

 我来答
9827352
2012-07-18 · TA获得超过142个赞
知道答主
回答量:554
采纳率:0%
帮助的人:267万
展开全部
比如说图片旋转,散花等. 特效好者另加巨高分!!! (简称 fb )是帧缓冲的意思。一般都是用在 Linux 下面的图形显示方面,作为一种快速显示图形
追问
麻烦先给我个简单的显示gif图片的程序好不?静态的就可以啊,我不需要什么旋转,散花功能
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
sunyalin0523
推荐于2016-04-18
知道答主
回答量:6
采纳率:0%
帮助的人:6.1万
展开全部
syl_show.c文件中:
void show_gif(char *filename,char *x,char *y,char *z)
{
int x_size=0, y_size=0;
int x_offs=0, y_offs=0, z_offs=0;
int enlarge=0;
int screen_width, screen_height;
unsigned char * image = NULL;
struct image i;
x_offs=atoi(x);
y_offs=atoi(y);
z_offs=atoi(z);

syl_gif_getsize(filename, &x_size, &y_size);
image = (unsigned char*) malloc(x_size * y_size * 3);
syl_gif_load(filename, image, x_size, y_size);

int transform_enlarge = enlarge;
getCurrentRes(&screen_width, &screen_height);
do_enlarge(&i, screen_width, screen_height, 0);
}

syl_draw(i.rgb, i.width, i.height, x_offs, y_offs);
}

syl_gif.c 文件中:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <setjmp.h>
#include <gif_lib.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include "syl_show.h"

#define min(a,b) ((a) < (b) ? (a) : (b))
#define gflush return(syl_ERROR_FILE);
#define grflush { DGifCloseFile(gft); return(syl_ERROR_FORMAT); }
#define mgrflush { free(lb); free(slb); DGifCloseFile(gft); return(syl_ERROR_FORMAT); }
#define agflush return(syl_ERROR_FORMAT);
#define agrflush { DGifCloseFile(gft); return(syl_ERROR_FORMAT); }

/*int syl_gif_id(char *name)
{
int fd;
char id[4];
fd=open(name,O_RDONLY); if(fd==-1) return(0);
read(fd,id,4);
close(fd);
if(id[0]=='G' && id[1]=='I' && id[2]=='F') return(1);
return(0);
}*/

inline void m_rend_gif_decodecolormap(unsigned char *cmb,unsigned char *rgbb,ColorMapObject *cm,int s,int l, int transparency)
{

GifColorType *cmentry;
int i;
for(i=0;i<l;i++)
{
cmentry=&cm->Colors[cmb[i]];
*(rgbb++)=cmentry->Red;
*(rgbb++)=cmentry->Green;
*(rgbb++)=cmentry->Blue;
}
}

/* Thanks goes here to Mauro Meneghin, who implemented interlaced GIF files support */

int syl_gif_load(char *name,unsigned char *buffer, int x,int y)
{
int in_nextrow[4]={8,8,4,2}; //interlaced jump to the row current+in_nextrow
int in_beginrow[4]={0,4,2,1}; //begin pass j from that row number
int transparency=-1; //-1 means not transparency present
int px,py,i,ibxs;
int j;
char *fbptr;
char *lb;
char *slb;
char * alpha=NULL;
GifFileType *gft;
GifByteType *extension;
int extcode;
GifRecordType rt;
ColorMapObject *cmap;
int cmaps;

gft=DGifOpenFileName(name);
if(gft==NULL){printf("err5\n"); gflush;} //////////
do
{
if(DGifGetRecordType(gft,&rt) == GIF_ERROR) grflush;
switch(rt)
{
case IMAGE_DESC_RECORD_TYPE:
if(DGifGetImageDesc(gft)==GIF_ERROR) grflush;
px=gft->Image.Width;
py=gft->Image.Height;
lb=(char*)malloc(px*3);
slb=(char*) malloc(px);
// printf("reading...\n");
if(lb!=NULL && slb!=NULL)
{
unsigned char *alphaptr = NULL;

cmap=(gft->Image.ColorMap ? gft->Image.ColorMap : gft->SColorMap);
cmaps=cmap->ColorCount;

ibxs=ibxs*3;
fbptr=(char*)buffer;

if(transparency != -1)
{
alphaptr = malloc(px * py);
// *alpha = alphaptr;
}

if(!(gft->Image.Interlace))
{
for(i=0;i<py;i++,fbptr+=px*3)
{
int j;
if(DGifGetLine(gft,(GifPixelType*)slb,px)==GIF_ERROR) mgrflush;
m_rend_gif_decodecolormap((unsigned char*)slb,(unsigned char*)lb,cmap,cmaps,px,transparency);
memcpy(fbptr,lb,px*3);
if(alphaptr)
for(j = 0; j<px; j++) *(alphaptr++) = (((unsigned char*) slb)[j] == transparency) ? 0x00 : 0xff;
}
}
else
{
unsigned char * aptr = NULL;

for(j=0;j<4;j++)
{
int k;
if(alphaptr)
aptr = alphaptr + (in_beginrow[j] * px);

fbptr=(char*)buffer + (in_beginrow[j] * px * 3);

for(i = in_beginrow[j]; i<py; i += in_nextrow[j], fbptr += px * 3 * in_nextrow[j], aptr += px * in_nextrow[j])
{
if(DGifGetLine(gft,(GifPixelType*)slb,px)==GIF_ERROR) mgrflush; /////////////
m_rend_gif_decodecolormap((unsigned char*)slb,(unsigned char*)lb,cmap,cmaps,px,transparency);
memcpy(fbptr,lb,px*3);
if(alphaptr)
for(k = 0; k<px; k++) aptr[k] = (((unsigned char*) slb)[k] == transparency) ? 0x00 : 0xff;
}
}
}
}
if(lb) free(lb);
if(slb) free(slb);
break;
case EXTENSION_RECORD_TYPE:
if(DGifGetExtension(gft,&extcode,&extension)==GIF_ERROR) grflush; //////////
if(extcode==0xf9) //look image transparency in graph ctr extension
{
if(extension[1] & 1)
{
transparency = extension[4];

}
// tran_off=(int)*extension;
// transparency=(int)*(extension+tran_off);
// printf("transparency: %d\n", transparency);
}
while(extension!=NULL)
if(DGifGetExtensionNext(gft,&extension) == GIF_ERROR) grflush
break;
default:
break;
}
}
while( rt!= TERMINATE_RECORD_TYPE );
DGifCloseFile(gft);
return(syl_ERROR_OK);
}

int syl_gif_getsize(char *name,int *x,int *y)
{
int px,py;
GifFileType *gft;
GifByteType *extension;
int extcode;
GifRecordType rt;

gft=DGifOpenFileName(name);
if(gft==NULL) gflush;
do
{
if(DGifGetRecordType(gft,&rt) == GIF_ERROR) grflush;
switch(rt)
{
case IMAGE_DESC_RECORD_TYPE:

if(DGifGetImageDesc(gft)==GIF_ERROR) grflush;
px=gft->Image.Width;
py=gft->Image.Height;
*x=px; *y=py;
DGifCloseFile(gft);
return(syl_ERROR_OK);
break;
case EXTENSION_RECORD_TYPE:
if(DGifGetExtension(gft,&extcode,&extension)==GIF_ERROR) grflush;
while(extension!=NULL)
if(DGifGetExtensionNext(gft,&extension)==GIF_ERROR) grflush;
break;
default:
break;
}
}
while( rt!= TERMINATE_RECORD_TYPE );
DGifCloseFile(gft);
return(syl_ERROR_FORMAT);
}

publicvoid onWindowFocusChanged(boolean hasFocus) {

// TODO Auto-generated method stub

if(hasFocus) {

imageView.setBackgroundResource(R.anim.frame_animation);

animDrawable = (AnimationDrawable) imageView.getBackground();

animDrawable.start();

AlphaAnimation aas=new AlphaAnimation(0.1f,1.0f);

//设置动画时间长度

aas.setDuration(3500);

//启动动画

imageView.startAnimation(aas);

//设置动画监听

aas.setAnimationListener(new AnimationListener()

{

@Override

publicvoid onAnimationEnd(Animation arg0) {

//停止帧动画

imageView.setVisibility(View.GONE);

Log.i(TAG,"FY_stop");

animDrawable.stop();

}

publicvoid onAnimationRepeat(Animation animation) {

}

publicvoid onAnimationStart(Animation animation)
{

//将imageView的背景设置成动画

imageView.setBackgroundResource(R.anim.frame_animation);

animDrawable = (AnimationDrawable)imageView.getBackground();

//设置动画透明度

animDrawable.setAlpha(80);

//启动动画

animDrawable.start();

}

}

);

}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
候俨0iF
2012-07-19 · TA获得超过424个赞
知道答主
回答量:540
采纳率:0%
帮助的人:191万
展开全部
这个还真的不清楚。我还以为是c呢。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式