new parameter addspacechars
[swftools.git] / avi2swf / videoreader_dummy.cc
1 /* videoreader_dummy.cc
2    Simple example for a videoreader.
3
4    Part of the swftools package.
5    
6    Copyright (c) 2004 Matthias Kramm <kramm@quiss.org>
7  
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <memory.h>
25 #include "videoreader.h"
26
27 typedef struct _my_internal
28 {
29     int pos;
30     int len; //frames
31 } my_internal;
32
33 typedef struct _RGBA
34 { unsigned char a;
35   unsigned char r;
36   unsigned char g;
37   unsigned char b;
38 } RGBA;
39
40 int my_getsamples(videoreader_t* v, void*buffer, int num)
41 {
42     /* generate audio data */
43     my_internal*i = (my_internal*)v->internal;
44     // printf("request for %d samples\n", num);
45     
46     return 0; // no audio
47 }
48
49 int my_getimage(videoreader_t* v, void*buffer)
50 {
51     /* generate video frame */
52     my_internal*i = (my_internal*)v->internal;
53     RGBA*buf = (RGBA*)buffer;
54
55     if(i->pos>=i->len)
56         return 0; /* end of video */
57
58     i->pos++; // next frame
59     
60     int x,y;
61     /* generate a simple color gradient */
62     for(y=0;y<v->height;y++)
63     for(x=0;x<v->width;x++) {
64         int r,g,b;
65         r = x;
66         g = y;
67         b = x+y;
68         buf[y*v->width + x].r = r; 
69         buf[y*v->width + x].g = g;
70         buf[y*v->width + x].b = b;
71         buf[y*v->width + x].a = 255;
72     }
73     return v->width*v->height*4;
74 }
75 void my_close(videoreader_t* v)
76 {
77     my_internal*i = (my_internal*)v->internal;
78     free(v->internal);v->internal = 0;
79 }
80 void my_setparameter(videoreader_t*v, char*name, char*value)
81 {
82 }
83 int videoreader_dummy_open(videoreader_t* v, char* filename)
84 {
85     my_internal* i;
86     i = (my_internal*)malloc(sizeof(my_internal));
87     memset(i, 0, sizeof(my_internal));
88     v->internal = i;
89     v->getsamples = my_getsamples;
90     v->close = my_close;
91     v->getimage = my_getimage;
92     v->getsamples = my_getsamples;
93     v->setparameter = my_setparameter;
94
95     i->len = 2000; //number of frames
96
97     v->width = 320; // video
98     v->height = 200;
99     v->fps = 15;
100     
101     v->channels = 0; // no audio
102     v->samplerate = 0;
103     
104     return 0;
105 }