int main(int argc,char *argv[]) { char *txt={"Hello World"}; int wdt=400; int hgt=400; struct FrameBuffer *fb=NULL; struct FrameBufferFontDB *fontdb=NULL; struct FrameBufferFont *font; FILE *fontfp=NULL; char *fntdbfname=NULL; char *fontname="Times-Roman"; float fontsize=34.0; fntdbfname=getenv("FONTDB"); fontfp=fopen(fntdbfname,"r"); if (fontfp !=NULL) { fontdb=FrameBufferFontDBLoad(fontfp); fclose(fontfp); } if (fontdb==NULL) { fprintf(stderr,"Could not load fonts.\n"); exit(-1); } fb=FrameBufferMake("image",wdt,hgt,24); font=FrameBufferFontDBFind(fontdb,fontname,fontsize); FrameBufferText(fb,NULL,font,20,200,strlen(txt), txt,0xffffffff,0x0f,1,NULL); FrameBufferSavePPM(fb,stdout); FrameBufferFree(fb); FrameBufferFontDBFree(fontdb); return 0; }
int SplotPlotStart(struct Splot *ptr,char *name, float wdt,float hgt,int depth) { if (ptr==NULL) return -1; if (ptr->ps.ptr !=NULL) PostScriptPlotStart(ptr->ps.ptr); if (ptr->fb.ptr !=NULL) { struct FrameBuffer *img=NULL; img=*(ptr->fb.ptr); if (img !=NULL) FrameBufferFree(img); img=FrameBufferMake(name,wdt,hgt,depth); if (img==NULL) return -1; *(ptr->fb.ptr)=img; FrameBufferClear(img,ptr->fb.bgcolor,0x0f); } return 0; }
int main(int argc,char *argv[]) { struct XwinDisplay *dp; struct XwinWindow *win; int wdt=300,hgt=300; unsigned int border=0; int flg; char *display_name=NULL; char *progname; int status=0; struct timeval tmout; unsigned int cv; unsigned char *array=NULL; int x,y,i,imax; float ix,iy,cx,cy,tx,xmin,xmax,ymin,ymax; xmin=-2.25; xmax=-2.25+3; ymin=-1.5; ymax=1.5; imax=255; array=malloc(hgt); progname=argv[0]; dp=XwinOpenDisplay(display_name,&flg); win=XwinMakeWindow(0,0,wdt,hgt,border, dp,"Test Window", "Test Window","Test Window", "basic",argc,argv,&flg); if ((fbuf=FrameBufferMake("Test",wdt,hgt,24))==NULL) { fprintf(stderr,"failed to make frame buffer."); exit(-1); } XwinFrameBufferWindow(fbuf,win); XwinShowWindow(win); for (x=0;x<wdt;x++) { for (y=0;y<hgt;y++) { cx=xmin+(xmax-xmin)*x/wdt; cy=ymin+(ymax-ymin)*y/hgt; ix=0; iy=0; for (i=0;i<imax;i++) { tx=ix*ix-iy*iy+cx; iy=2*ix*iy+cy; ix=tx; if (sqrt(ix*ix+iy*iy)>2.0) break; } array[y]=i; } for (y=0;y<hgt;y++) { cv=FrameBufferColor(16*array[y],16*array[y],255-16*array[y],255); FrameBufferRectangle(fbuf,NULL,x,y,1,1,1,cv,0x0f,0,NULL,NULL); } XwinFrameBufferWindow(fbuf,win); tmout.tv_sec=0; tmout.tv_usec=0; status=XwinDisplayEvent(dp,1,&win,0,&tmout); if (status !=0) break; } XwinFreeWindow(win); XwinCloseDisplay(dp); return 0; }
int main(int argc,char *argv[]) { int arg=0; FILE *fp; struct FrameBuffer *src=NULL; struct FrameBuffer *dst=NULL; unsigned int bgcolor=0; char *bgtxt=NULL; unsigned alpha=0; unsigned char help=0; unsigned char option=0; OptionAdd(&opt,"-help",'x',&help); OptionAdd(&opt,"-option",'x',&option); OptionAdd(&opt,"bgcol",'t',&bgtxt); OptionAdd(&opt,"alpha",'x',&alpha); arg=OptionProcess(1,argc,argv,&opt,NULL); if (help==1) { OptionPrintInfo(stdout,hlpstr); exit(0); } if (option==1) { OptionDump(stdout,&opt); exit(0); } if (arg<argc) { fp=fopen(argv[arg],"r"); if (fp==NULL) { fprintf(stderr,"Error opening file.\n"); exit(-1); } } else fp=stdin; bgcolor=FrameBufferColor(0x00,0x00,0x00,0x00); if (bgtxt !=NULL) { sscanf(bgtxt,"%x",&bgcolor); } while ((src=FrameBufferLoadPNG(fp,"image")) !=NULL) { if (bgcolor !=0) { if (dst==NULL) { dst=FrameBufferMake(NULL,src->wdt,src->hgt,24); if (dst==NULL) { fprintf(stderr,"Error creating image.\n"); exit(-1); } } FrameBufferClear(dst,bgcolor,0x0f); FrameBufferImage(dst,NULL,src,0x0f,0,0,0,NULL); if (alpha==0) FrameBufferSavePPM(dst,stdout); else FrameBufferSavePPMAlpha(dst,stdout); } else { if (alpha==0) FrameBufferSavePPM(src,stdout); else FrameBufferSavePPMAlpha(src,stdout); } FrameBufferFree(src); src=NULL; } if (arg<argc) fclose(fp); return 0; }
int main(int argc,char *argv[]) { int arg=0; FILE *fp; struct FrameBuffer *src=NULL; struct FrameBuffer *dst=NULL; struct FrameBufferMatrix m; unsigned char sflg=0; float wdt=-1; float hgt=-1; float sf=1.0; unsigned char help=0; unsigned char option=0; OptionAdd(&opt,"-help",'x',&help); OptionAdd(&opt,"-option",'x',&option); OptionAdd(&opt,"smooth",'x',&sflg); OptionAdd(&opt,"wdt",'f',&wdt); OptionAdd(&opt,"hgt",'f',&hgt); OptionAdd(&opt,"sf",'f',&sf); arg=OptionProcess(1,argc,argv,&opt,NULL); if (help==1) { OptionPrintInfo(stdout,hlpstr); exit(0); } if (option==1) { OptionDump(stdout,&opt); exit(0); } if (arg<argc) { fp=fopen(argv[arg],"r"); if (fp==NULL) { fprintf(stderr,"Error opening file.\n"); exit(-1); } } else fp=stdin; while ((src=FrameBufferLoadPPMX(fp)) !=NULL) { if (dst==NULL) { if ((wdt==-1) && (hgt==-1)) { wdt=src->wdt*sf; hgt=src->hgt*sf; } else if (wdt==-1) { wdt=src->wdt*hgt/src->hgt; } else if (hgt==-1) { hgt=src->hgt*wdt/src->wdt; } if ((wdt==0) || (hgt==0)) { fprintf(stderr,"Invalid image size.\n"); exit(-1); } dst=FrameBufferMake(NULL,wdt,hgt,src->depth); } if ((wdt==src->wdt) && (hgt==src->hgt)) FrameBufferImage(dst,NULL,src,0xf0,0,0,0,NULL); else { float xsc=wdt/src->wdt; float ysc=hgt/src->hgt; m.a=xsc; m.b=0; m.c=0; m.d=ysc; FrameBufferImage(dst,&m,src,0xf0,0,0,sflg,NULL); } FrameBufferSavePPMX(dst,stdout); FrameBufferFree(src); src=NULL; } if (arg<argc) fclose(fp); return 0; }
int main(int argc,char *argv[]) { char lbuf[256]; int s=0; int arg=0; FILE *fp; struct FrameBuffer *src=NULL; struct FrameBuffer *dst=NULL; struct XMLdata *xmldata=NULL; struct FrameBufferXML xmlimg; unsigned int bgcolor=0; char *bgtxt=NULL; unsigned char alpha=0; unsigned char help=0; unsigned char option=0; OptionAdd(&opt,"-help",'x',&help); OptionAdd(&opt,"-option",'x',&option); OptionAdd(&opt,"bgcol",'t',&bgtxt); OptionAdd(&opt,"alpha",'x',&alpha); arg=OptionProcess(1,argc,argv,&opt,NULL); if (help==1) { OptionPrintInfo(stdout,hlpstr); exit(0); } if (option==1) { OptionDump(stdout,&opt); exit(0); } xmldata=XMLMake(); xmlimg.xml=xmldata; xmlimg.img=&src; XMLSetStart(xmldata,FrameBufferXMLStart,&xmlimg); XMLSetEnd(xmldata,FrameBufferXMLEnd,&xmlimg); if (arg<argc) { fp=fopen(argv[arg],"r"); if (fp==NULL) { fprintf(stderr,"Error opening file.\n"); exit(-1); } } else fp=stdin; while(fgets(lbuf,255,fp) !=NULL) { s=XMLDecode(xmldata,lbuf,strlen(lbuf)); if (s !=0) break; } if (s !=0) { fprintf(stderr,"Error decoding image.\n"); exit(-1); } if (arg<argc) fclose(fp); bgcolor=FrameBufferColor(0x00,0x00,0x00,0x00); if (bgtxt !=NULL) { sscanf(bgtxt,"%x",&bgcolor); } if (src==NULL) { fprintf(stderr,"Error decoding image.\n"); exit(-1); } if (bgcolor !=0) { dst=FrameBufferMake(NULL,src->wdt,src->hgt,24); if (dst==NULL) { fprintf(stderr,"Error creating image.\n"); exit(-1); } FrameBufferClear(dst,bgcolor,0x0f); FrameBufferImage(dst,NULL,src,0x0f,0,0,0,NULL); if (alpha==0) FrameBufferSavePPM(dst,stdout); else FrameBufferSavePPMAlpha(dst,stdout); } else { if (alpha==0) FrameBufferSavePPM(src,stdout); else FrameBufferSavePPMAlpha(src,stdout); } return 0; }
int main(int argc,char *argv[]) { #ifdef _XLIB_ char *name="ppmxd"; int xdf=0; struct XwinDisplay *dp; struct XwinWindow *win; char *display_name=NULL; int xdoff=-1; int ydoff=-1; #endif int arg=0; FILE *fp; unsigned int bgcolor=0; struct FrameBufferMatrix m; struct FrameBuffer *src=NULL; struct FrameBuffer *dst=NULL; char *bgtxt=NULL; unsigned char cflg=0; unsigned char sflg=0; float scale=100; float wdt=-1; float hgt=-1; unsigned char help=0; unsigned char option=0; OptionAdd(&opt,"-help",'x',&help); OptionAdd(&opt,"-option",'x',&option); OptionAdd(&opt,"smooth",'x',&sflg); OptionAdd(&opt,"scale",'f',&scale); OptionAdd(&opt,"check",'x',&cflg); OptionAdd(&opt,"bgcol",'t',&bgtxt); #ifdef _XLIB_ OptionAdd(&opt,"display",'t',&display_name); OptionAdd(&opt,"xoff",'i',&xdoff); OptionAdd(&opt,"yoff",'i',&ydoff); #endif arg=OptionProcess(1,argc,argv,&opt,NULL); if (help==1) { OptionPrintInfo(stdout,hlpstr); exit(0); } if (option==1) { OptionDump(stdout,&opt); exit(0); } if (arg<argc) { fp=fopen(argv[arg],"r"); if (fp==NULL) { fprintf(stderr,"Error opening file.\n"); exit(-1); } } else fp=stdin; src=FrameBufferLoadPPMX(fp); if (src==NULL) { fprintf(stderr,"Error decoding image.\n"); exit(-1); } if (arg<argc) fclose(fp); bgcolor=FrameBufferColor(0x00,0x00,0x00,0xff); if (bgtxt !=NULL) { sscanf(bgtxt,"%x",&bgcolor); bgcolor=bgcolor | 0xff000000; } if (scale<=0) scale=0.5; if (scale !=100) { wdt=src->wdt*scale/100.0; hgt=src->hgt*scale/100.0; } else { wdt=src->wdt; hgt=src->hgt; } if ((wdt==0) || (hgt==0)) { fprintf(stderr,"Invalid image size.\n"); exit(-1); } dst=FrameBufferMake(NULL,wdt,hgt,24); FrameBufferClear(dst,bgcolor,0x0f); if (cflg !=0) { /* plot checker board */ int x,y; int c=0,d=0; for (x=0;x<wdt;x+=8) { c=d; d=!d; for (y=0;y<hgt;y+=8) { c=!c; if (c==0) FrameBufferRectangle(dst,NULL,x,y,8,8,1, 0xffc0c0c0,0x0f,0,NULL,NULL); else FrameBufferRectangle(dst,NULL,x,y,8,8,1, 0xffffffff,0x0f,0,NULL,NULL); } } } if (scale==100) FrameBufferImage(dst,NULL,src,0x0f,0,0,0,NULL); else { m.a=scale/100.0; m.b=0; m.c=0; m.d=scale/100.0; FrameBufferImage(dst,&m,src,0x0f,0,0,sflg,NULL); } #ifdef _XLIB_ dp=XwinOpenDisplay(display_name,&xdf); if (dp==NULL) { fprintf(stderr,"Could not open display.\n"); exit(-1); } if (xdoff==-1) xdoff=(dp->wdt-dst->wdt)/2; if (ydoff==-1) ydoff=(dp->hgt-dst->hgt)/2; win=XwinMakeWindow(xdoff,ydoff,dst->wdt,dst->hgt,0, dp,name, name,argv[0],name,argc,argv,&xdf); if (win==NULL) { fprintf(stderr,"Could not create window.\n"); exit(-1); } XwinFrameBufferWindow(dst,win); XwinShowWindow(win); XwinDisplayEvent(dp,1,&win,1,NULL); XwinFreeWindow(win); XwinCloseDisplay(dp); #endif return 0; }
int GrplotRawKey(struct Plot *ptr, float ox,float oy,float wdt,float hgt, double min,double max, double tick_major,double tick_minor, float major_size,float minor_size, float txt_off,float ttl_off, int tick_flg,int txt_flg,int ttl_flg, int txt_or,int ttl_or, int or, int ttl_num,char *ttl_text, int (*text_box)(char *,float,int,char *,float *,void *), void *boxdata, char * (*make_text)(double,double,double,void *), void *textdata, char *fntname,float fntsze, unsigned int color,unsigned char mask,float width, int ksze,unsigned char *a, unsigned char *r,unsigned char *g,unsigned char *b) { int s=0; int i=0,j=0; int kwdt=0,khgt=0; struct FrameBuffer *img=NULL; if (ptr==NULL) return -1; if (text_box==NULL) return -1; if (fntname==NULL) return -1; if (fntsze==0) return -1; if (ksze==0) return -1; kwdt=ksze; khgt=ksze; if (or==0) img=FrameBufferMake(NULL,kwdt,ksze,24); else img=FrameBufferMake(NULL,ksze,khgt,24); if (img==NULL) return -1; if (or==0) { for (i=0;i<ksze;i++) { for (j=0;j<kwdt;j++) { if (a !=NULL) img->msk[(ksze-1-i)*kwdt+j]=a[i]; if (r !=NULL) img->img[(ksze-1-i)*kwdt+j]=r[i]; if (g !=NULL) img->img[ksze*kwdt+(ksze-1-i)*kwdt+j]=g[i]; if (b !=NULL) img->img[2*ksze*kwdt+(ksze-1-i)*kwdt+j]=b[i]; } } } else { for (i=0;i<ksze;i++) { for (j=0;j<khgt;j++) { if (a !=NULL) img->msk[j*ksze+i]=a[i]; if (r !=NULL) img->img[j*ksze+i]=r[i]; if (g !=NULL) img->img[ksze*khgt+j*ksze+i]=g[i]; if (b !=NULL) img->img[2*ksze*khgt+j*ksze+i]=b[i]; } } } s=GrplotRawFitImage(ptr,ox,oy,wdt,hgt,img,mask); if (s==0) s=GrplotRawPanel(ptr,ox,oy,wdt,hgt,color,mask,width); if (or==0) { if (s==0) s=GrplotRawYaxis(ptr,ox,oy,wdt,hgt, min,max,tick_major,tick_minor,major_size,minor_size, tick_flg,color,mask,width); if ((s==0) && (make_text !=NULL)) s=GrplotRawYaxisLabel(ptr,ox,oy,wdt,hgt,min,max,tick_major,txt_off, txt_flg,txt_or,text_box,boxdata, make_text,textdata,fntname,fntsze,color,mask); } else { if (s==0) s=GrplotRawXaxis(ptr,ox,oy,wdt,hgt, min,max,tick_major,tick_minor,major_size,minor_size, tick_flg,color,mask,width); if ((s==0) && (make_text !=NULL)) s=GrplotRawXaxisLabel(ptr,ox,oy,wdt,hgt,min,max,tick_major,txt_off, txt_flg,txt_or,text_box,boxdata, make_text,textdata,fntname,fntsze,color,mask); } if ((s==0) && (ttl_text !=NULL) && (ttl_num !=0)) s=GrplotRawYaxisTitle(ptr,ox,oy,wdt,hgt,ttl_off,ttl_flg,ttl_or, text_box,boxdata, ttl_num,ttl_text,fntname,fntsze,color,mask); FrameBufferFree(img); return s; }