~ubuntu-branches/ubuntu/oneiric/libmng/oneiric

« back to all changes in this revision

Viewing changes to contrib/gcc/fbmngplay/fbmngplay.c

  • Committer: Bazaar Package Importer
  • Author(s): Shiju p. Nair
  • Date: 2006-04-07 09:49:11 UTC
  • mfrom: (0.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060407094911-ay3179o63gvlh4ll
Tags: 1.0.9-1
* New upstream release. (closes: #303968, #271979)
* Patch from Aurelien Jarno <aurel32@debian.org> to support GNU/kFreeBSD.
  Closes: #314696)
* Patch from Christopher Bodenstein <cb@physicman.net> to support
  hurd-i386. (closes: #361103)
* README.Debian provide information on what options are compiled in to
  libmng.(closes: #174523)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
        fbmngplay - fb console MNG player.
3
 
        (c) 2001 by Stefan Reinauer, <stepan :at: suse.de>
4
 
 
5
 
        This program is based on mngplay, part of libmng, written and (C) by
6
 
        Ralph Giles <giles :at: ashlu.bc.ca>
7
 
 
8
 
        This program my be redistributed under the terms of the
9
 
        GNU General Public Licence, version 2, or at your preference,
10
 
        any later version.
11
 
*/
12
 
 
13
 
#include <unistd.h>
14
 
#include <fcntl.h>
15
 
#include <signal.h>
16
 
#include <getopt.h>
17
 
#include <sys/mman.h>
18
 
#include <sys/ioctl.h>
19
 
#include <linux/fb.h>
20
 
 
21
 
#include "fbmngplay.h"
22
 
#include "messages.h"
23
 
#include "console.h"
24
 
#include "mng.h"
25
 
 
26
 
volatile int run = 1;
27
 
int verbose = 0;
28
 
int buffered = 0;
29
 
int dynpos = 0;
30
 
int waitsignal = 0;
31
 
int delta = 16;
32
 
int sconly=0;
33
 
 
34
 
void sigint_handler(int signal);
35
 
void sigterm_handler(int signal);
36
 
void sigusr1_handler(int signal);
37
 
 
38
 
void sigint_handler(int signal)
39
 
{
40
 
        run = 2;
41
 
}
42
 
 
43
 
void sigterm_handler(int signal)
44
 
{
45
 
        restore_area();
46
 
        run = 0;
47
 
}
48
 
 
49
 
void sigusr1_handler(int signal)
50
 
{
51
 
        run = 0;
52
 
}
53
 
 
54
 
int main(int argc, char *argv[])
55
 
{
56
 
        int fbdev,c,option_index;
57
 
        unsigned int alpha;
58
 
        struct fb_var_screeninfo var;
59
 
 
60
 
        /* Check which console we're running on */
61
 
        init_consoles();
62
 
                
63
 
        /* allocate our stream data structure */
64
 
        mng = (mngstuff *) calloc(1, sizeof(*mng));
65
 
        if (mng == NULL) {
66
 
                fprintf(stderr, "could not allocate stream structure.\n");
67
 
                exit(0);
68
 
        }
69
 
        alpha = 100;
70
 
        mng->alpha = 100;
71
 
        mng->fbx = 15;
72
 
        mng->fby = 15;
73
 
        mng->background = NULL;
74
 
 
75
 
        while (1) {
76
 
                static struct option long_options[] = {
77
 
                        {"help", 0, 0, 'h'},
78
 
                        {"verbose", 0, 0, 'v'},
79
 
                        {"alpha", 1, 0, 'a'},
80
 
                        {"buffered", 0, 0, 'b'},
81
 
                        {"signal", 0, 0, 's'},
82
 
                        {"delta", 0, 0, 'd'},
83
 
                        {"position", 0, 0, 'p'},
84
 
                        {"version", 0, 0, 'V'},
85
 
                        {"start-console",0,0,'S'},
86
 
                        {"console",1,0,'c'},
87
 
                        {0, 0, 0, 0}
88
 
                };
89
 
 
90
 
                c = getopt_long(argc, argv, "a:x:y:bh?vsd:pVSc:",
91
 
                                long_options, &option_index);
92
 
 
93
 
                if (c == -1)
94
 
                        break;
95
 
 
96
 
                switch (c) {
97
 
                case 'a':
98
 
                        alpha = atoi(optarg);
99
 
                        if (alpha > 100)
100
 
                                alpha = 100;
101
 
                        mng->alpha = alpha;
102
 
                        break;
103
 
                case 'x':
104
 
                        mng->fbx = atoi(optarg);
105
 
                        break;
106
 
                case 'y':
107
 
                        mng->fby = atoi(optarg);
108
 
                        break;
109
 
                case 'd':
110
 
                        delta = atoi(optarg);
111
 
                        break;
112
 
                case '?':
113
 
                case 'h':
114
 
                        usage(argv[0]);
115
 
                        exit(0);
116
 
                case 'v':
117
 
                        verbose = 1;
118
 
                        break;
119
 
                case 's':
120
 
                        waitsignal = 1;
121
 
                        break;
122
 
                case 'b':
123
 
                        buffered = 1;
124
 
                        break;
125
 
                case 'p':
126
 
                        dynpos = 1;
127
 
                        break;
128
 
                case 'V':
129
 
                        version();
130
 
                        exit(0);
131
 
                case 'c':
132
 
                        start_console=atoi(optarg);
133
 
                case 'S':
134
 
                        sconly=1;
135
 
                        break;
136
 
                default:
137
 
                        break;
138
 
                }
139
 
        }
140
 
 
141
 
        if (optind >= argc) {
142
 
                printf("Which files do you want to play?\n");
143
 
                exit(0);
144
 
        }
145
 
 
146
 
        //init_consoles();
147
 
        
148
 
        /* Initialize framebuffer */
149
 
        fbdev = open("/dev/fb0", O_RDWR);
150
 
        if (fbdev < 0) {
151
 
                fprintf(stderr, "error while opening framebuffer.\n");
152
 
                exit(fbdev);
153
 
        }
154
 
 
155
 
        ioctl(fbdev, FBIOGET_VSCREENINFO, &var);
156
 
        mng->fbwidth = var.xres;
157
 
        mng->fbheight = var.yres;
158
 
        mng->fbbpp = var.bits_per_pixel;
159
 
 
160
 
        mng->display =
161
 
            mmap(NULL, var.xres * var.yres * (var.bits_per_pixel >> 3),
162
 
                 PROT_WRITE | PROT_READ, MAP_SHARED, fbdev, 0);
163
 
 
164
 
        /* arrange to call the shutdown routine before we exit */
165
 
        atexit(&cleanup);
166
 
 
167
 
        while (optind < argc) {
168
 
                // leftover arguements are filenames.
169
 
                mng->filename = argv[optind++];
170
 
 
171
 
                /* set up the mng decoder for our stream */
172
 
                mng->mng = mng_initialize(mng, mngalloc, mngfree, MNG_NULL);
173
 
                if (mng->mng == MNG_NULL) {
174
 
                        fprintf(stderr, "could not initialize libmng.\n");
175
 
                        exit(1);
176
 
                }
177
 
 
178
 
                /* set the callbacks */
179
 
                mng_setcb_errorproc(mng->mng, mngerror);
180
 
                mng_setcb_openstream(mng->mng, mngopenstream);
181
 
                mng_setcb_closestream(mng->mng, mngclosestream);
182
 
                mng_setcb_readdata(mng->mng, mngreadstream);
183
 
                mng_setcb_gettickcount(mng->mng, mnggetticks);
184
 
                mng_setcb_settimer(mng->mng, mngsettimer);
185
 
                mng_setcb_processheader(mng->mng, mngprocessheader);
186
 
                mng_setcb_getcanvasline(mng->mng, mnggetcanvasline);
187
 
                mng_setcb_refresh(mng->mng, mngrefresh);
188
 
                /* FIXME: should check for errors here */
189
 
 
190
 
                signal(SIGINT, sigint_handler);
191
 
                signal(SIGTERM, sigterm_handler);
192
 
 
193
 
                mng_readdisplay(mng->mng);
194
 
 
195
 
                /* loop though the frames */
196
 
                while (mng->delay && run) {
197
 
                        mdelay(mng->delay);
198
 
                        mng->delay = 0;
199
 
                        mng_display_resume(mng->mng);
200
 
                        if (run == 2) {
201
 
                                if (mng->alpha == 0)
202
 
                                        run = 0;
203
 
                                mng->alpha -= delta;
204
 
                                if (mng->alpha < 0)
205
 
                                        mng->alpha = 0;
206
 
                        }
207
 
                }
208
 
 
209
 
                if (waitsignal && optind < argc) {
210
 
                        signal(SIGUSR1, sigusr1_handler);
211
 
                        run = 1;
212
 
                        while (run) {
213
 
                                sleep(2);
214
 
                        }
215
 
                }
216
 
 
217
 
                memset(mng->copybuffer, 0,
218
 
                       4 * mng->width * mng->height);
219
 
                run = 1;
220
 
                mng->alpha = alpha;
221
 
                if (optind == argc) {   /* last file */
222
 
                        restore_area();
223
 
                }
224
 
        }
225
 
 
226
 
        /* cleanup and quit */
227
 
        return mngquit(mng->mng);
228
 
}
 
1
/*
 
2
        fbmngplay - fb console MNG player.
 
3
        (c) 2001 by Stefan Reinauer, <stepan :at: suse.de>
 
4
 
 
5
        This program is based on mngplay, part of libmng, written and (C) by
 
6
        Ralph Giles <giles :at: ashlu.bc.ca>
 
7
 
 
8
        This program my be redistributed under the terms of the
 
9
        GNU General Public Licence, version 2, or at your preference,
 
10
        any later version.
 
11
*/
 
12
 
 
13
#include <unistd.h>
 
14
#include <fcntl.h>
 
15
#include <signal.h>
 
16
#include <getopt.h>
 
17
#include <sys/mman.h>
 
18
#include <sys/ioctl.h>
 
19
#include <linux/fb.h>
 
20
 
 
21
#include "fbmngplay.h"
 
22
#include "messages.h"
 
23
#include "console.h"
 
24
#include "mng.h"
 
25
 
 
26
volatile int run = 1;
 
27
int verbose = 0;
 
28
int buffered = 0;
 
29
int dynpos = 0;
 
30
int waitsignal = 0;
 
31
int delta = 16;
 
32
int sconly=0;
 
33
 
 
34
void sigint_handler(int signal);
 
35
void sigterm_handler(int signal);
 
36
void sigusr1_handler(int signal);
 
37
 
 
38
void sigint_handler(int signal)
 
39
{
 
40
        run = 2;
 
41
}
 
42
 
 
43
void sigterm_handler(int signal)
 
44
{
 
45
        restore_area();
 
46
        run = 0;
 
47
}
 
48
 
 
49
void sigusr1_handler(int signal)
 
50
{
 
51
        run = 0;
 
52
}
 
53
 
 
54
int main(int argc, char *argv[])
 
55
{
 
56
        int fbdev,c,option_index;
 
57
        unsigned int alpha;
 
58
        struct fb_var_screeninfo var;
 
59
 
 
60
        /* Check which console we're running on */
 
61
        init_consoles();
 
62
                
 
63
        /* allocate our stream data structure */
 
64
        mng = (mngstuff *) calloc(1, sizeof(*mng));
 
65
        if (mng == NULL) {
 
66
                fprintf(stderr, "could not allocate stream structure.\n");
 
67
                exit(0);
 
68
        }
 
69
        alpha = 100;
 
70
        mng->alpha = 100;
 
71
        mng->fbx = 15;
 
72
        mng->fby = 15;
 
73
        mng->background = NULL;
 
74
 
 
75
        while (1) {
 
76
                static struct option long_options[] = {
 
77
                        {"help", 0, 0, 'h'},
 
78
                        {"verbose", 0, 0, 'v'},
 
79
                        {"alpha", 1, 0, 'a'},
 
80
                        {"buffered", 0, 0, 'b'},
 
81
                        {"signal", 0, 0, 's'},
 
82
                        {"delta", 0, 0, 'd'},
 
83
                        {"position", 0, 0, 'p'},
 
84
                        {"version", 0, 0, 'V'},
 
85
                        {"start-console",0,0,'S'},
 
86
                        {"console",1,0,'c'},
 
87
                        {0, 0, 0, 0}
 
88
                };
 
89
 
 
90
                c = getopt_long(argc, argv, "a:x:y:bh?vsd:pVSc:",
 
91
                                long_options, &option_index);
 
92
 
 
93
                if (c == -1)
 
94
                        break;
 
95
 
 
96
                switch (c) {
 
97
                case 'a':
 
98
                        alpha = atoi(optarg);
 
99
                        if (alpha > 100)
 
100
                                alpha = 100;
 
101
                        mng->alpha = alpha;
 
102
                        break;
 
103
                case 'x':
 
104
                        mng->fbx = atoi(optarg);
 
105
                        break;
 
106
                case 'y':
 
107
                        mng->fby = atoi(optarg);
 
108
                        break;
 
109
                case 'd':
 
110
                        delta = atoi(optarg);
 
111
                        break;
 
112
                case '?':
 
113
                case 'h':
 
114
                        usage(argv[0]);
 
115
                        exit(0);
 
116
                case 'v':
 
117
                        verbose = 1;
 
118
                        break;
 
119
                case 's':
 
120
                        waitsignal = 1;
 
121
                        break;
 
122
                case 'b':
 
123
                        buffered = 1;
 
124
                        break;
 
125
                case 'p':
 
126
                        dynpos = 1;
 
127
                        break;
 
128
                case 'V':
 
129
                        version();
 
130
                        exit(0);
 
131
                case 'c':
 
132
                        start_console=atoi(optarg);
 
133
                case 'S':
 
134
                        sconly=1;
 
135
                        break;
 
136
                default:
 
137
                        break;
 
138
                }
 
139
        }
 
140
 
 
141
        if (optind >= argc) {
 
142
                printf("Which files do you want to play?\n");
 
143
                exit(0);
 
144
        }
 
145
 
 
146
        //init_consoles();
 
147
        
 
148
        /* Initialize framebuffer */
 
149
        fbdev = open("/dev/fb0", O_RDWR);
 
150
        if (fbdev < 0) {
 
151
                fprintf(stderr, "error while opening framebuffer.\n");
 
152
                exit(fbdev);
 
153
        }
 
154
 
 
155
        ioctl(fbdev, FBIOGET_VSCREENINFO, &var);
 
156
        mng->fbwidth = var.xres;
 
157
        mng->fbheight = var.yres;
 
158
        mng->fbbpp = var.bits_per_pixel;
 
159
 
 
160
        mng->display =
 
161
            mmap(NULL, var.xres * var.yres * (var.bits_per_pixel >> 3),
 
162
                 PROT_WRITE | PROT_READ, MAP_SHARED, fbdev, 0);
 
163
 
 
164
        /* arrange to call the shutdown routine before we exit */
 
165
        atexit(&cleanup);
 
166
 
 
167
        while (optind < argc) {
 
168
                // leftover arguements are filenames.
 
169
                mng->filename = argv[optind++];
 
170
 
 
171
                /* set up the mng decoder for our stream */
 
172
                mng->mng = mng_initialize(mng, mngalloc, mngfree, MNG_NULL);
 
173
                if (mng->mng == MNG_NULL) {
 
174
                        fprintf(stderr, "could not initialize libmng.\n");
 
175
                        exit(1);
 
176
                }
 
177
 
 
178
                /* set the callbacks */
 
179
                mng_setcb_errorproc(mng->mng, mngerror);
 
180
                mng_setcb_openstream(mng->mng, mngopenstream);
 
181
                mng_setcb_closestream(mng->mng, mngclosestream);
 
182
                mng_setcb_readdata(mng->mng, mngreadstream);
 
183
                mng_setcb_gettickcount(mng->mng, mnggetticks);
 
184
                mng_setcb_settimer(mng->mng, mngsettimer);
 
185
                mng_setcb_processheader(mng->mng, mngprocessheader);
 
186
                mng_setcb_getcanvasline(mng->mng, mnggetcanvasline);
 
187
                mng_setcb_refresh(mng->mng, mngrefresh);
 
188
                /* FIXME: should check for errors here */
 
189
 
 
190
                signal(SIGINT, sigint_handler);
 
191
                signal(SIGTERM, sigterm_handler);
 
192
 
 
193
                mng_readdisplay(mng->mng);
 
194
 
 
195
                /* loop though the frames */
 
196
                while (mng->delay && run) {
 
197
                        mdelay(mng->delay);
 
198
                        mng->delay = 0;
 
199
                        mng_display_resume(mng->mng);
 
200
                        if (run == 2) {
 
201
                                if (mng->alpha == 0)
 
202
                                        run = 0;
 
203
                                mng->alpha -= delta;
 
204
                                if (mng->alpha < 0)
 
205
                                        mng->alpha = 0;
 
206
                        }
 
207
                }
 
208
 
 
209
                if (waitsignal && optind < argc) {
 
210
                        signal(SIGUSR1, sigusr1_handler);
 
211
                        run = 1;
 
212
                        while (run) {
 
213
                                sleep(2);
 
214
                        }
 
215
                }
 
216
 
 
217
                memset(mng->copybuffer, 0,
 
218
                       4 * mng->width * mng->height);
 
219
                run = 1;
 
220
                mng->alpha = alpha;
 
221
                if (optind == argc) {   /* last file */
 
222
                        restore_area();
 
223
                }
 
224
        }
 
225
 
 
226
        /* cleanup and quit */
 
227
        return mngquit(mng->mng);
 
228
}