1 /* $Id: mve_main.c,v 1.4 2003-11-25 04:36:25 btb Exp $ */
10 #ifdef _WIN32_WCE // should really be checking for "Pocket PC" somehow
19 static SDL_Surface *g_screen;
21 static SDL_Surface *real_screen;
23 static unsigned char g_palette[768];
24 static int g_truecolor;
26 static int doPlay(const char *filename);
28 static void usage(void)
30 fprintf(stderr, "usage: mveplay filename\n");
34 int main(int c, char **v)
39 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
41 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
51 /* Create a new rotated surface for drawing */
52 SDL_Surface *CreateRotatedSurface(SDL_Surface *s)
54 return(SDL_CreateRGBSurface(s->flags, s->h, s->w,
55 s->format->BitsPerPixel,
62 /* Used to copy the rotated scratch surface to the screen */
63 void BlitRotatedSurface(SDL_Surface *from, SDL_Surface *to)
66 int bpp = from->format->BytesPerPixel;
67 int w=from->w, h=from->h, pitch=to->pitch;
69 Uint8 *pfrom, *pto, *to0;
71 SDL_LockSurface(from);
73 pfrom=(Uint8 *)from->pixels;
74 to0=(Uint8 *) to->pixels+pitch*(w-1);
81 if (bpp==1) *pto=*pfrom;
82 else if (bpp==2) *(Uint16 *)pto=*(Uint16 *)pfrom;
83 else if (bpp==4) *(Uint32 *)pto=*(Uint32 *)pfrom;
94 SDL_UnlockSurface(from);
95 SDL_UnlockSurface(to);
100 static unsigned int fileRead(void *handle, void *buf, unsigned int count)
104 numread = fread(buf, 1, count, (FILE *)handle);
105 return (numread == count);
108 static void showFrame(unsigned char *buf, unsigned int bufw, unsigned int bufh,
109 unsigned int sx, unsigned int sy,
110 unsigned int w, unsigned int h,
111 unsigned int dstx, unsigned int dsty)
116 SDL_Rect srcRect, destRect;
118 assert(bufw == w && bufh == h);
121 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 16, 2 * bufw, 0x7C00, 0x03E0, 0x001F, 0);
124 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 8, bufw, 0x7C00, 0x03E0, 0x001F, 0);
127 for(i = 0; i < 256; i++)
129 sprite->format->palette->colors[i].r = (*pal++) << 2;
130 sprite->format->palette->colors[i].g = (*pal++) << 2;
131 sprite->format->palette->colors[i].b = (*pal++) << 2;
132 sprite->format->palette->colors[i].unused = 0;
145 SDL_BlitSurface(sprite, &srcRect, g_screen, &destRect);
147 BlitRotatedSurface(g_screen, real_screen);
148 if ( (real_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF )
149 SDL_Flip(real_screen);
151 SDL_UpdateRect(real_screen, 0, 0, 0, 0);
153 if ( (g_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF )
156 SDL_UpdateRects(g_screen, 1, &destRect);
158 SDL_FreeSurface(sprite);
161 static void setPalette(unsigned char *p, unsigned start, unsigned count)
163 //Set color 0 to be black
164 g_palette[0] = g_palette[1] = g_palette[2] = 0;
166 //Set color 255 to be our subtitle color
167 g_palette[765] = g_palette[766] = g_palette[767] = 50;
169 //movie libs palette into our array
170 memcpy(g_palette + start*3, p+start*3, count*3);
173 static int pollEvents()
177 while (SDL_PollEvent(&event))
184 switch (event.key.keysym.sym)
190 SDL_WM_ToggleFullScreen(g_screen);
204 static int doPlay(const char *filename)
212 mve = fopen(filename, "rb");
214 fprintf(stderr, "can't open MVE file\n");
218 memset(g_palette, 0, 768);
221 MVE_memCallbacks(malloc, free);
222 MVE_ioCallbacks(fileRead);
223 MVE_sfCallbacks(showFrame);
224 MVE_palCallbacks(setPalette);
226 MVE_rmPrepMovie(mve, -1, -1, 1);
228 MVE_getVideoSpec(&vSpec);
230 #ifndef _WIN32_WCE // doesn't like to change bpp?
231 bpp = vSpec.truecolor?16:8;
235 real_screen = SDL_SetVideoMode(vSpec.screenHeight, vSpec.screenWidth, bpp, SDL_FULLSCREEN);
236 g_screen = CreateRotatedSurface(real_screen);
238 g_screen = SDL_SetVideoMode(vSpec.screenWidth, vSpec.screenHeight, bpp, SDL_ANYFORMAT);
241 g_truecolor = vSpec.truecolor;
243 while (!done && (result = MVE_rmStepMovie()) == 0)