1 /* $Id: mve_main.c,v 1.3 2003-06-10 04:46:16 btb Exp $ */
11 static SDL_Surface *g_screen;
12 static unsigned char g_palette[768];
13 static int g_truecolor;
15 static int doPlay(const char *filename);
17 static void usage(void)
19 fprintf(stderr, "usage: mveplay filename\n");
23 int main(int c, char **v)
28 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
30 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
38 static unsigned int fileRead(void *handle, void *buf, unsigned int count)
42 numread = fread(buf, 1, count, (FILE *)handle);
43 return (numread == count);
46 static void showFrame(unsigned char *buf, unsigned int bufw, unsigned int bufh,
47 unsigned int sx, unsigned int sy,
48 unsigned int w, unsigned int h,
49 unsigned int dstx, unsigned int dsty)
54 SDL_Rect srcRect, destRect;
56 assert(bufw == w && bufh == h);
59 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 16, 2 * bufw, 0x7C00, 0x03E0, 0x001F, 0);
62 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 8, bufw, 0x7C00, 0x03E0, 0x001F, 0);
65 for(i = 0; i < 256; i++)
67 sprite->format->palette->colors[i].r = (*pal++) << 2;
68 sprite->format->palette->colors[i].g = (*pal++) << 2;
69 sprite->format->palette->colors[i].b = (*pal++) << 2;
70 sprite->format->palette->colors[i].unused = 0;
83 SDL_BlitSurface(sprite, &srcRect, g_screen, &destRect);
84 if ( (g_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF )
87 SDL_UpdateRects(g_screen, 1, &destRect);
88 SDL_FreeSurface(sprite);
91 static void setPalette(unsigned char *p, unsigned start, unsigned count)
93 //Set color 0 to be black
94 g_palette[0] = g_palette[1] = g_palette[2] = 0;
96 //Set color 255 to be our subtitle color
97 g_palette[765] = g_palette[766] = g_palette[767] = 50;
99 //movie libs palette into our array
100 memcpy(g_palette + start*3, p+start*3, count*3);
103 static int pollEvents()
107 while (SDL_PollEvent(&event))
114 switch (event.key.keysym.sym)
120 SDL_WM_ToggleFullScreen(g_screen);
134 static int doPlay(const char *filename)
141 mve = fopen(filename, "rb");
143 fprintf(stderr, "can't open MVE file\n");
147 memset(g_palette, 0, 768);
150 MVE_memCallbacks(malloc, free);
151 MVE_ioCallbacks(fileRead);
152 MVE_sfCallbacks(showFrame);
153 MVE_palCallbacks(setPalette);
155 MVE_rmPrepMovie(mve, -1, -1, 1);
157 MVE_getVideoSpec(&vSpec);
159 g_screen = SDL_SetVideoMode(vSpec.screenWidth, vSpec.screenHeight, vSpec.truecolor?16:8, SDL_ANYFORMAT);
161 g_truecolor = vSpec.truecolor;
163 while (!done && (result = MVE_rmStepMovie()) == 0)