11 #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;
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 (!strcmp(v[1], "-nosound")) {
47 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
49 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
59 /* Create a new rotated surface for drawing */
60 SDL_Surface *CreateRotatedSurface(SDL_Surface *s)
62 return(SDL_CreateRGBSurface(s->flags, s->h, s->w,
63 s->format->BitsPerPixel,
70 /* Used to copy the rotated scratch surface to the screen */
71 void BlitRotatedSurface(SDL_Surface *from, SDL_Surface *to)
74 int bpp = from->format->BytesPerPixel;
75 int w=from->w, h=from->h, pitch=to->pitch;
77 Uint8 *pfrom, *pto, *to0;
79 SDL_LockSurface(from);
81 pfrom=(Uint8 *)from->pixels;
82 to0=(Uint8 *) to->pixels+pitch*(w-1);
89 if (bpp==1) *pto=*pfrom;
90 else if (bpp==2) *(Uint16 *)pto=*(Uint16 *)pfrom;
91 else if (bpp==4) *(Uint32 *)pto=*(Uint32 *)pfrom;
102 SDL_UnlockSurface(from);
103 SDL_UnlockSurface(to);
108 static unsigned int fileRead(void *handle, void *buf, unsigned int count)
112 numread = fread(buf, 1, count, (FILE *)handle);
113 return (numread == count);
116 static void showFrame(unsigned char *buf, unsigned int bufw, unsigned int bufh,
117 unsigned int sx, unsigned int sy,
118 unsigned int w, unsigned int h,
119 unsigned int dstx, unsigned int dsty)
124 SDL_Rect srcRect, destRect;
126 assert(bufw == w && bufh == h);
129 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 16, 2 * bufw, 0x7C00, 0x03E0, 0x001F, 0);
132 sprite = SDL_CreateRGBSurfaceFrom(buf, bufw, bufh, 8, bufw, 0x7C00, 0x03E0, 0x001F, 0);
135 for(i = 0; i < 256; i++)
137 sprite->format->palette->colors[i].r = (*pal++) << 2;
138 sprite->format->palette->colors[i].g = (*pal++) << 2;
139 sprite->format->palette->colors[i].b = (*pal++) << 2;
140 sprite->format->palette->colors[i].unused = 0;
153 SDL_BlitSurface(sprite, &srcRect, g_screen, &destRect);
155 BlitRotatedSurface(g_screen, real_screen);
156 if ( (real_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF )
157 SDL_Flip(real_screen);
159 SDL_UpdateRect(real_screen, 0, 0, 0, 0);
161 if ( (g_screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF )
164 SDL_UpdateRects(g_screen, 1, &destRect);
166 SDL_FreeSurface(sprite);
169 static void setPalette(unsigned char *p, unsigned start, unsigned count)
171 //Set color 0 to be black
172 g_palette[0] = g_palette[1] = g_palette[2] = 0;
174 //Set color 255 to be our subtitle color
175 g_palette[765] = g_palette[766] = g_palette[767] = 50;
177 //movie libs palette into our array
178 memcpy(g_palette + start*3, p+start*3, count*3);
181 static int pollEvents()
185 while (SDL_PollEvent(&event))
190 case SDL_MOUSEBUTTONDOWN:
191 case SDL_MOUSEBUTTONUP:
194 switch (event.key.keysym.sym)
200 SDL_WM_ToggleFullScreen(g_screen);
214 static int doPlay(const char *filename)
222 mve = fopen(filename, "rb");
224 fprintf(stderr, "can't open MVE file\n");
228 memset(g_palette, 0, 768);
231 MVE_memCallbacks((mve_cb_Alloc)malloc, free);
232 MVE_ioCallbacks(fileRead);
233 MVE_sfCallbacks(showFrame);
234 MVE_palCallbacks(setPalette);
236 MVE_rmPrepMovie(mve, -1, -1, track);
238 MVE_getVideoSpec(&vSpec);
240 #ifndef _WIN32_WCE // doesn't like to change bpp?
241 bpp = vSpec.truecolor?16:8;
245 real_screen = SDL_SetVideoMode(vSpec.screenHeight, vSpec.screenWidth, bpp, SDL_FULLSCREEN);
246 g_screen = CreateRotatedSurface(real_screen);
248 g_screen = SDL_SetVideoMode(vSpec.screenWidth, vSpec.screenHeight, bpp, SDL_ANYFORMAT);
251 g_truecolor = vSpec.truecolor;
253 while (!done && (result = MVE_rmStepMovie()) == 0)