Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TCap v0.1
- // (C) Thomas Hargrove
- // http://toonarchive.com/tcap
- /***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/ioctl.h>
- #include <sys/mman.h>
- #include <errno.h>
- #include "SDL/SDL.h"
- //#define WIDTH 960
- //#define HEIGHT 720
- #define p(x) printf("%s",x);
- static char *map;
- SDL_Surface *screen;
- SDL_Surface *offscreen;
- SDL_Event event;
- /* Copies map to screen, then updates the screen */
- void copytoscreen(char* tmap) {
- offscreen = SDL_CreateRGBSurfaceFrom((void *) tmap, WIDTH, HEIGHT, 24, WIDTH*3, 0xFF0000, 0x00FF00, 0x0000FF, 0x000000);
- SDL_BlitSurface(offscreen, NULL, screen, NULL);
- SDL_UpdateRect(screen, 0, 0, 0, 0);
- SDL_FreeSurface(offscreen);
- }
- int main(int argc, char *argv[])
- {
- int done = 0;
- FILE *video;
- if (argv[1] == NULL) { argv[1] = "output"; }
- if ((video=fopen(argv[1],"r")) == NULL) printf("File did not open"); exit;
- // --------------------------------------------------------------------------
- // Set up out video output
- // --------------------------------------------------------------------------
- SDL_Init(SDL_INIT_VIDEO);
- screen = SDL_SetVideoMode(WIDTH, HEIGHT, 16, SDL_SWSURFACE);
- if ( screen == NULL ) {
- printf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
- SDL_GetError());
- exit(1);
- }
- SDL_WM_SetCaption("", NULL);
- map=malloc(WIDTH*HEIGHT*3);
- while ( ! done ) {
- while (SDL_PollEvent(&event))
- {
- switch(event.type)
- {
- case SDL_KEYDOWN: done =1; break;
- case SDL_QUIT: done = 1; break;
- }
- }
- // read each frame from file
- if ( ! feof(video) )
- {
- fread(map, WIDTH*HEIGHT*3, 1, video);
- copytoscreen(map);
- }else{
- done=1;
- }
- }
- // Return screen to text mode.
- fclose(video);
- SDL_Quit();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment