68af40134d288c52a0f97c65ff9e94db15dd9dc8
[my-code/dfb-photoshow.git] / dfb-photoshow.c
1 /*
2  * dfb-photoshow.c
3  *
4  * author: hackbard
5  *
6  */
7
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <directfb.h>
11
12 IDirectFB *dfb = NULL;
13 IDirectFBSurface *primary = NULL;
14 int screen_width  = 0;
15 int screen_height = 0;
16
17 #define DFBCHECK(x...) \
18 { \
19  DFBResult err=x; \
20  if(err!=DFB_OK) { \
21   fprintf(stderr,"file: %s , line: %d !\n\t",__FILE__,__LINE__); \
22   DirectFBErrorFatal( #x, err ); \
23  } \
24 }
25
26 IDirectFBSurface *logo = NULL;
27 IDirectFBFont *font = NULL;
28 char *text = "directfb photoshow (written by hackbard 2003)";
29
30 int main(int argc,char **argv) {
31  int i;
32  DFBSurfaceDescription dsc;
33  DFBFontDescription font_dsc;
34  IDirectFBImageProvider *img_prov;
35
36  DFBCHECK(DirectFBInit (&argc, &argv));
37
38  DFBCHECK(DirectFBCreate(&dfb));
39  DFBCHECK(dfb->SetCooperativeLevel(dfb,DFSCL_FULLSCREEN));
40
41  dsc.flags=DSDESC_CAPS;
42  dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING;
43  DFBCHECK(dfb->CreateSurface(dfb,&dsc,&primary));
44
45  font_dsc.flags = DFDESC_HEIGHT;
46  font_dsc.height = 20;
47  DFBCHECK(dfb->CreateFont(dfb,"./decker.ttf",&font_dsc,&font));
48  DFBCHECK(primary->SetFont(primary,font));
49
50  DFBCHECK(primary->GetSize(primary,&screen_width,&screen_height));
51  fprintf(stdout,"dimensions: %dx%d\n",screen_width,screen_height);
52
53  /* welcome */
54  DFBCHECK(primary->SetColor(primary,0x00,0x00,0x00,0x00));
55  DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
56  DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff));
57  DFBCHECK(primary->DrawString(primary,text,-1,5,screen_height/2,DSTF_LEFT));
58  DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
59  sleep(10);
60  font->Release(font);
61  
62  for(i=2;i<argc;i++) {
63   DFBCHECK(dfb->CreateImageProvider(dfb,argv[i],&img_prov));
64   DFBCHECK(img_prov->GetSurfaceDescription(img_prov,&dsc));
65   DFBCHECK(dfb->CreateSurface(dfb,&dsc,&logo ));
66   DFBCHECK(img_prov->RenderTo(img_prov,logo,NULL));
67   img_prov->Release(img_prov);
68   DFBCHECK (primary->SetColor(primary,0x00,0x00,0x00,0x00));
69   DFBCHECK(primary->FillRectangle(primary,0,0,screen_width,screen_height));
70   DFBCHECK(primary->SetColor(primary,0x80,0x80,0xff,0xff));
71   DFBCHECK(primary->DrawLine(primary,0,0,screen_width-1,screen_height-1));
72   if((screen_width>=dsc.width)&&(screen_height>=dsc.height)) {
73    DFBCHECK(primary->Blit(primary,logo,NULL,(screen_width-dsc.width)/2,(screen_height-dsc.height)/2));
74   }
75   else {
76    DFBCHECK(primary->StretchBlit(primary,logo,NULL,NULL));
77   }
78   DFBCHECK(primary->Flip(primary,NULL,DSFLIP_WAITFORSYNC));
79   sleep(atoi(argv[1]));
80   logo->Release(logo);
81  }
82
83  primary->Release(logo);
84  primary->Release(primary);
85  dfb->Release(dfb);
86
87  return 23; /* ;) */
88 }
89