]> git.ozlabs.org Git - yaboot.git/blob - second/gui/effects.c
afcd3745496077e790264094f9ca6d9f19618f99
[yaboot.git] / second / gui / effects.c
1 /* effects.c */
2 /* Adds splash screen and status bar effects for graphical yaboot */
3
4 #include "file.h"
5 #include "yaboot.h"
6 #include "stdlib.h"
7
8 #define SB_XSTART  170
9 #define SB_XEND    472
10 #define SB_YSTART  402
11
12 unsigned char bar_grad[] = { 228, 237, 246, 254, 207, 254, 246, 237, 228, 206 };
13
14 int scrOpen(void);
15 void scrSetEntireColorMap(unsigned char *);
16 void scrClear(unsigned char);
17 void pcxDisplay(unsigned char *, unsigned int);
18 void scrFadeColorMap(unsigned char *, unsigned char *, int);
19 unsigned char *pcxColormap(unsigned char *, int);
20 void scrPutPixel(int, int, unsigned char);
21
22 void fxDisplaySplash(struct boot_fspec_t *filespec)
23 {
24   void              *gfx_file;
25   int                gfx_len;
26   unsigned char     *grey_map;
27   int                start_time;
28   struct boot_file_t file;
29   int                result;
30   static int         been_here = 0;
31
32   if(!been_here)
33   {
34      been_here = 1;
35      gfx_file = (void *) malloc(1024 * 512);
36      if (gfx_file == NULL) {
37         prom_printf("malloc failed in fxDisplaySplash()\n");
38         return;
39      }
40
41      scrOpen();
42
43      result = open_file(filespec, &file);
44
45      if(result != FILE_ERR_OK)
46      {
47         prom_printf("Error loading splash screen\n");
48         return;
49      }
50
51      gfx_len = file.fs->read(&file, 1024 * 512 - 765, gfx_file);
52      file.fs->close(&file);
53      grey_map = gfx_file + gfx_len;
54      memset(grey_map, 0/*128*/, 765);
55   }
56
57   scrSetEntireColorMap(grey_map);
58   scrClear(0);
59
60   start_time = prom_getms();
61   while(prom_getms() < start_time + 2000);
62
63   pcxDisplay(gfx_file, gfx_len);
64   scrFadeColorMap(grey_map, pcxColormap( gfx_file, gfx_len ), 2);
65 }
66
67
68 void fxUpdateSB(unsigned number, unsigned total)
69 {
70   int x, y;
71
72   for(x = SB_XSTART; x < SB_XSTART + (SB_XEND - SB_XSTART) * number / total; ++x)
73   {
74      for(y = 0; y < 10; ++y)
75         scrPutPixel(x, SB_YSTART + y, bar_grad[y]);
76   }
77 }
78
79
80 #define BLOCK_INDEX (1024 * 64)
81
82 int fxReadImage(struct boot_file_t *file, unsigned int filesize, void *base)
83 {
84   unsigned int count, result = 0;
85
86   for(count = 0; count < filesize; count += result)
87   {
88      result = ((filesize - count) < BLOCK_INDEX) ? (filesize - count) : BLOCK_INDEX;
89      if ((result = file->fs->read(file, result, base + count)) != BLOCK_INDEX)
90         break;
91      fxUpdateSB(count + result, filesize);
92   }
93   fxUpdateSB(count + result, filesize);
94   return(count + result);
95 }