fixed off-by-one bug
[swftools.git] / avi2swf / videoreader_dummy.cc
blobaf92b4e707b4fced72551aaf5d64b0ce7dd05ab7
1 /* videoreader_dummy.cc
2 Simple example for a videoreader.
4 Part of the swftools package.
6 Copyright (c) 2004 Matthias Kramm <kramm@quiss.org>
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.
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.
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 */
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <memory.h>
25 #include "videoreader.h"
27 typedef struct _my_internal
29 int pos;
30 int len; //frames
31 } my_internal;
33 typedef struct _RGBA
34 { unsigned char a;
35 unsigned char r;
36 unsigned char g;
37 unsigned char b;
38 } RGBA;
40 int my_getsamples(videoreader_t* v, void*buffer, int num)
42 /* generate audio data */
43 my_internal*i = (my_internal*)v->internal;
44 // printf("request for %d samples\n", num);
46 return 0; // no audio
49 int my_getimage(videoreader_t* v, void*buffer)
51 /* generate video frame */
52 my_internal*i = (my_internal*)v->internal;
53 RGBA*buf = (RGBA*)buffer;
55 if(i->pos>=i->len)
56 return 0; /* end of video */
58 i->pos++; // next frame
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;
73 return v->width*v->height*4;
75 void my_close(videoreader_t* v)
77 my_internal*i = (my_internal*)v->internal;
78 free(v->internal);v->internal = 0;
80 void my_setparameter(videoreader_t*v, char*name, char*value)
83 int videoreader_dummy_open(videoreader_t* v, char* filename)
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;
95 i->len = 2000; //number of frames
97 v->width = 320; // video
98 v->height = 200;
99 v->fps = 15;
101 v->channels = 0; // no audio
102 v->samplerate = 0;
104 return 0;