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;
27 static int doPlay(const char *filename);
29 static void usage(void)
31 fprintf(stderr, "usage: mveplay filename\n");
35 int main(int c, char **v)
40 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
42 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
52 /* Create a new rotated surface for drawing */
53 SDL_Surface *CreateRotatedSurface(SDL_Surface *s)
55 return(SDL_CreateRGBSurface(s->flags, s->h, s->w,
56 s->format->BitsPerPixel,
63 /* Used to copy the rotated scratch surface to the screen */
64 void BlitRotatedSurface(SDL_Surface *from, SDL_Surface *to)
67 int bpp = from->format->BytesPerPixel;
68 int w=from->w, h=from->h, pitch=to->pitch;
70 Uint8 *pfrom, *pto, *to0;
72 SDL_LockSurface(from);
74 pfrom=(Uint8 *)from->pixels;
75 to0=(Uint8 *) to->pixels+pitch*(w-1);
82 if (bpp==1) *pto=*pfrom;
83 else if (bpp==2) *(Uint16 *)pto=*(Uint16 *)pfrom;
84 else if (bpp==4) *(Uint32 *)pto=*(Uint32 *)pfrom;
95 SDL_UnlockSurface(from);
96 SDL_UnlockSurface(to);
101 static unsigned int fileRead(void *handle, void *buf, unsigned int count)
105 numread = fread(buf, 1, count, (FILE *)handle);
106 return (numread == count);
109 static void showFrame(unsigned char *buf, unsigned int bufw, unsigned int bufh,
110 unsigned int sx, unsigned int sy,
111 unsigned int w, unsigned int h,
112 unsigned int dstx, unsigned int dsty)
117 SDL_Rect srcRect, destRect;
119 assert(bufw == w && bufh == h);
122 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 16, 2 * bufw, 0x7C00, 0x03E0, 0x001F, 0);
125 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 8, bufw, 0x7C00, 0x03E0, 0x001F, 0);
128 for(i = 0; i < 256; i++)
130 sprite->format->palette->colors[i].r = (*pal++) << 2;
131 sprite->format->palette->colors[i].g = (*pal++) << 2;
132 sprite->format->palette->colors[i].b = (*pal++) << 2;
133 sprite->format->palette->colors[i].unused = 0;
146 SDL_BlitSurface(sprite, &srcRect, g_screen, &destRect);
148 BlitRotatedSurface(g_screen, real_screen);
149 if ( (real_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF )
150 SDL_Flip(real_screen);
152 SDL_UpdateRect(real_screen, 0, 0, 0, 0);
154 if ( (g_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF )
157 SDL_UpdateRects(g_screen, 1, &destRect);
159 SDL_FreeSurface(sprite);
162 static void setPalette(unsigned char *p, unsigned start, unsigned count)
164 //Set color 0 to be black
165 g_palette[0] = g_palette[1] = g_palette[2] = 0;
167 //Set color 255 to be our subtitle color
168 g_palette[765] = g_palette[766] = g_palette[767] = 50;
170 //movie libs palette into our array
171 memcpy(g_palette + start*3, p+start*3, count*3);
174 static int pollEvents()
178 while (SDL_PollEvent(&event))
183 case SDL_MOUSEBUTTONDOWN:
184 case SDL_MOUSEBUTTONUP:
187 switch (event.key.keysym.sym)
193 SDL_WM_ToggleFullScreen(g_screen);
207 static int doPlay(const char *filename)
215 mve = fopen(filename, "rb");
217 fprintf(stderr, "can't open MVE file\n");
221 memset(g_palette, 0, 768);
224 MVE_memCallbacks((mve_cb_Alloc)malloc, free);
225 MVE_ioCallbacks(fileRead);
226 MVE_sfCallbacks(showFrame);
227 MVE_palCallbacks(setPalette);
229 MVE_rmPrepMovie(mve, -1, -1, 1);
231 MVE_getVideoSpec(&vSpec);
233 #ifndef _WIN32_WCE // doesn't like to change bpp?
234 bpp = vSpec.truecolor?16:8;
238 real_screen = SDL_SetVideoMode(vSpec.screenHeight, vSpec.screenWidth, bpp, SDL_FULLSCREEN);
239 g_screen = CreateRotatedSurface(real_screen);
241 g_screen = SDL_SetVideoMode(vSpec.screenWidth, vSpec.screenHeight, bpp, SDL_ANYFORMAT);
244 g_truecolor = vSpec.truecolor;
246 while (!done && (result = MVE_rmStepMovie()) == 0)