1 /* $Id: mve_main.c,v 1.8 2004-06-01 07:49:07 btb Exp $ */
12 #ifdef _WIN32_WCE // should really be checking for "Pocket PC" somehow
20 static SDL_Surface *g_screen;
22 static SDL_Surface *real_screen;
24 static unsigned char g_palette[768];
25 static int g_truecolor;
28 static int doPlay(const char *filename);
30 static void usage(void)
32 fprintf(stderr, "usage: mveplay filename\n");
36 int main(int c, char **v)
41 if (!strcmp(v[1], "-nosound")) {
48 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
50 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
60 /* Create a new rotated surface for drawing */
61 SDL_Surface *CreateRotatedSurface(SDL_Surface *s)
63 return(SDL_CreateRGBSurface(s->flags, s->h, s->w,
64 s->format->BitsPerPixel,
71 /* Used to copy the rotated scratch surface to the screen */
72 void BlitRotatedSurface(SDL_Surface *from, SDL_Surface *to)
75 int bpp = from->format->BytesPerPixel;
76 int w=from->w, h=from->h, pitch=to->pitch;
78 Uint8 *pfrom, *pto, *to0;
80 SDL_LockSurface(from);
82 pfrom=(Uint8 *)from->pixels;
83 to0=(Uint8 *) to->pixels+pitch*(w-1);
90 if (bpp==1) *pto=*pfrom;
91 else if (bpp==2) *(Uint16 *)pto=*(Uint16 *)pfrom;
92 else if (bpp==4) *(Uint32 *)pto=*(Uint32 *)pfrom;
103 SDL_UnlockSurface(from);
104 SDL_UnlockSurface(to);
109 static unsigned int fileRead(void *handle, void *buf, unsigned int count)
113 numread = fread(buf, 1, count, (FILE *)handle);
114 return (numread == count);
117 static void showFrame(unsigned char *buf, unsigned int bufw, unsigned int bufh,
118 unsigned int sx, unsigned int sy,
119 unsigned int w, unsigned int h,
120 unsigned int dstx, unsigned int dsty)
125 SDL_Rect srcRect, destRect;
127 assert(bufw == w && bufh == h);
130 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 16, 2 * bufw, 0x7C00, 0x03E0, 0x001F, 0);
133 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 8, bufw, 0x7C00, 0x03E0, 0x001F, 0);
136 for(i = 0; i < 256; i++)
138 sprite->format->palette->colors[i].r = (*pal++) << 2;
139 sprite->format->palette->colors[i].g = (*pal++) << 2;
140 sprite->format->palette->colors[i].b = (*pal++) << 2;
141 sprite->format->palette->colors[i].unused = 0;
154 SDL_BlitSurface(sprite, &srcRect, g_screen, &destRect);
156 BlitRotatedSurface(g_screen, real_screen);
157 if ( (real_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF )
158 SDL_Flip(real_screen);
160 SDL_UpdateRect(real_screen, 0, 0, 0, 0);
162 if ( (g_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF )
165 SDL_UpdateRects(g_screen, 1, &destRect);
167 SDL_FreeSurface(sprite);
170 static void setPalette(unsigned char *p, unsigned start, unsigned count)
172 //Set color 0 to be black
173 g_palette[0] = g_palette[1] = g_palette[2] = 0;
175 //Set color 255 to be our subtitle color
176 g_palette[765] = g_palette[766] = g_palette[767] = 50;
178 //movie libs palette into our array
179 memcpy(g_palette + start*3, p+start*3, count*3);
182 static int pollEvents()
186 while (SDL_PollEvent(&event))
191 case SDL_MOUSEBUTTONDOWN:
192 case SDL_MOUSEBUTTONUP:
195 switch (event.key.keysym.sym)
201 SDL_WM_ToggleFullScreen(g_screen);
215 static int doPlay(const char *filename)
223 mve = fopen(filename, "rb");
225 fprintf(stderr, "can't open MVE file\n");
229 memset(g_palette, 0, 768);
232 MVE_memCallbacks((mve_cb_Alloc)malloc, free);
233 MVE_ioCallbacks(fileRead);
234 MVE_sfCallbacks(showFrame);
235 MVE_palCallbacks(setPalette);
237 MVE_rmPrepMovie(mve, -1, -1, track);
239 MVE_getVideoSpec(&vSpec);
241 #ifndef _WIN32_WCE // doesn't like to change bpp?
242 bpp = vSpec.truecolor?16:8;
246 real_screen = SDL_SetVideoMode(vSpec.screenHeight, vSpec.screenWidth, bpp, SDL_FULLSCREEN);
247 g_screen = CreateRotatedSurface(real_screen);
249 g_screen = SDL_SetVideoMode(vSpec.screenWidth, vSpec.screenHeight, bpp, SDL_ANYFORMAT);
252 g_truecolor = vSpec.truecolor;
254 while (!done && (result = MVE_rmStepMovie()) == 0)