Fixing warnings from doxygen:
[synfig.git] / synfig-core / trunk / src / modules / mptr_mplayer / mptr_mplayer.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file mptr_mplayer.cpp
3 **      \brief ppm Target Module
4 **
5 **      \legal
6 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
7 **
8 **      This package is free software; you can redistribute it and/or
9 **      modify it under the terms of the GNU General Public License as
10 **      published by the Free Software Foundation; either version 2 of
11 **      the License, or (at your option) any later version.
12 **
13 **      This package 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 GNU
16 **      General Public License for more details.
17 **      \endlegal
18 **
19 ** === N O T E S ===========================================================
20 **
21 ** ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include <synfig/synfig.h>
33 #include <ETL/stringf>
34 #include "mptr_mplayer.h"
35 #include <stdio.h>
36 #include <iostream>
37 #include <algorithm>
38 #include <functional>
39 #include <ETL/stringf>
40 #endif
41
42 /* === M A C R O S ========================================================= */
43
44 using namespace synfig;
45 using namespace std;
46 using namespace etl;
47
48 /* === G L O B A L S ======================================================= */
49
50 const char mplayer_mptr::Name[]="avi";
51 const char mplayer_mptr::Ext[]="avi";
52
53 /* === M E T H O D S ======================================================= */
54
55 Importer *
56 mplayer_mptr::New(const char *file)
57 {
58         return new mplayer_mptr(file);
59 }
60
61 mplayer_mptr::mplayer_mptr(const char *file)
62 {
63         filename=file;
64 }
65
66 mplayer_mptr::~mplayer_mptr()
67 {
68 }
69
70 bool
71 mplayer_mptr::GetFrame(Time time, synfig::Surface &surface, synfig::ProgressCallback *)
72 {
73         int ret;
74         ret=system(
75                 strprintf("/usr/local/bin/mencoder \"%s\" -ovc rawrgb -ss %f -endpos 0 -nosound -o /tmp/tmp.synfig.rgbdata | grep \"VIDEO\" > /tmp/tmp.synfig.size",
76                         filename.c_str(),
77                         time
78                 ).c_str()
79         );
80         /*
81         if(ret!=0)
82         {
83                 cerr<<"mencoder execution failed."<<endl;
84                 return false;
85         }
86 */
87         FILE *sizefile=fopen("/tmp/tmp.synfig.size","rt");
88         FILE *rgbfile=fopen("/tmp/tmp.synfig.rgbdata","rb");
89         if(!rgbfile)
90         {
91                 cerr<<"unable to open /tmp/tmp.synfig.rgbdata"<<endl;
92                 return false;
93         }
94         if(!sizefile)
95         {
96                 cerr<<"unable to open /tmp/tmp.synfig.size"<<endl;
97                 return false;
98         }
99
100         int w=4,h=4,x,y;
101         char bleh[500];
102
103         fscanf(sizefile,"%s %s %dx%d",bleh,bleh,&w,&h);
104
105         cerr<<strprintf("w:%d, h:%d, time:%f",w,h,time)<<endl;
106         fseek(rgbfile,2047+3*8,SEEK_CUR);
107         surface.set_wh(w,h);
108         for(y=0;y<h;y++)
109                 for(x=0;x<w;x++)
110                 {
111                         unsigned char
112                                 b=(unsigned char)fgetc(rgbfile),
113                                 g=(unsigned char)fgetc(rgbfile),
114                                 r=(unsigned char)fgetc(rgbfile);
115
116                         surface[h-y-1][x]=Color(
117                                 (float)r/255.0,
118                                 (float)g/255.0,
119                                 (float)b/255.0,
120                                 1.0
121                         );
122                 }
123
124         fclose(rgbfile);
125         fclose(sizefile);
126
127         return true;
128 }