Vkeyboard typing mode
[jpcrr.git] / streamtools / frameshow.c
blobe892db030cbb46cfda600297452bb1613bc51710
1 /*
2 JPC-RR: A x86 PC Hardware Emulator
3 Release 1
5 Copyright (C) 2009 H. Ilari Liusvaara
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as published by
9 the Free Software Foundation.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 Based on JPC x86 PC Hardware emulator,
21 A project from the Physics Dept, The University of Oxford
23 Details about original JPC can be found at:
25 www-jpc.physics.ox.ac.uk
29 #include "frame.h"
30 #include <stdio.h>
31 #include "SDL.h"
33 int main(int argc, char** argv)
35 if(argc < 2) {
36 fprintf(stderr, "usage: %s <filename>\n", argv[0]);
37 fprintf(stderr, "Show video contained in stream <filename> in window.\n");
38 return 1;
40 struct frame_input_stream* in = fis_open(argv[1]);
41 struct frame* frame;
42 int prev_width = -1;
43 int prev_height = -1;
45 if(SDL_Init(SDL_INIT_VIDEO) < 0) {
46 fprintf(stderr, "Can't initialize SDL.\n");
47 return 1;
50 int rbyte, gbyte, bbyte;
52 SDL_Surface* surf;
54 while((frame = fis_next_frame(in))) {
55 if(prev_width != frame->f_width || prev_height != frame->f_height)
56 surf = SDL_SetVideoMode(frame->f_width, frame->f_height, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);
57 prev_width = frame->f_width;
58 prev_height = frame->f_height;
59 SDL_LockSurface(surf);
60 uint32_t* data = surf->pixels;
61 for(uint32_t y = 0; y < frame->f_height; y++) {
62 for(uint32_t x = 0; x < frame->f_width; x++) {
63 uint32_t v = 0;
64 v += (((frame->f_framedata[y * frame->f_width + x] >> 16) & 0xFF)
65 << surf->format->Rshift);
66 v += (((frame->f_framedata[y * frame->f_width + x] >> 8) & 0xFF)
67 << surf->format->Gshift);
68 v += (((frame->f_framedata[y * frame->f_width + x]) & 0xFF)
69 << surf->format->Bshift);
71 data[y * surf->pitch / 4 + x] = v;
74 SDL_UnlockSurface(surf);
75 SDL_Flip(surf);
76 frame_release(frame);
79 fis_close(in);
80 SDL_Quit();
81 return 0;