1 /* === S Y N F I G ========================================================= */
3 ** \brief ppm Target Module
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 ** === N O T E S ===========================================================
24 ** ========================================================================= */
26 /* === H E A D E R S ======================================================= */
35 #include <ETL/stringf>
38 #include <sys/types.h>
58 /* === M A C R O S ========================================================= */
60 using namespace synfig;
64 #if defined(HAVE_FORK) && defined(HAVE_PIPE) && defined(HAVE_WAITPID)
65 #define UNIX_PIPE_TO_PROCESSES
67 #define WIN32_PIPE_TO_PROCESSES
70 /* === G L O B A L S ======================================================= */
72 SYNFIG_TARGET_INIT(dv_trgt);
73 SYNFIG_TARGET_SET_NAME(dv_trgt,"dv");
74 SYNFIG_TARGET_SET_EXT(dv_trgt,"dv");
75 SYNFIG_TARGET_SET_VERSION(dv_trgt,"0.1");
76 SYNFIG_TARGET_SET_CVS_ID(dv_trgt,"$Id$");
78 /* === M E T H O D S ======================================================= */
81 dv_trgt::dv_trgt(const char *Filename,
82 const synfig::TargetParam& /* params */)
97 #if defined(WIN32_PIPE_TO_PROCESSES)
99 #elif defined(UNIX_PIPE_TO_PROCESSES)
102 waitpid(pid,&status,0);
107 delete [] color_buffer;
111 dv_trgt::set_rend_desc(RendDesc *given_desc)
113 // Set the aspect ratio
117 given_desc->set_wh(160,90);
119 // Widescreen should be progressive scan
120 given_desc->set_interlaced(false);
125 given_desc->set_wh(400,300);
127 // We should be interlaced
128 given_desc->set_interlaced(true);
131 // but the pixel res should be 720x480
132 given_desc->clear_flags(),given_desc->set_wh(720,480);
134 // NTSC Frame rate is 29.97
135 given_desc->set_frame_rate(29.97);
137 // The pipe to encodedv is PPM, which needs RGB data
138 //given_desc->set_pixel_format(PF_RGB);
140 // Set the description
149 imagecount=desc.get_frame_start();
151 #if defined(WIN32_PIPE_TO_PROCESSES)
156 command=strprintf("encodedv -w 1 - > \"%s\"\n",filename.c_str());
158 command=strprintf("encodedv - > \"%s\"\n",filename.c_str());
160 // Open the pipe to encodedv
161 file=popen(command.c_str(),POPEN_BINARY_WRITE_TYPE);
165 synfig::error(_("Unable to open pipe to encodedv"));
169 #elif defined(UNIX_PIPE_TO_PROCESSES)
174 synfig::error(_("Unable to open pipe to encodedv"));
181 synfig::error(_("Unable to open pipe to encodedv"));
187 // Close pipeout, not needed
189 // Dup pipeout to stdin
190 if( dup2( p[0], STDIN_FILENO ) == -1 ){
191 synfig::error(_("Unable to open pipe to encodedv"));
194 // Close the unneeded pipeout
196 // Open filename to stdout
197 FILE* outfile = fopen(filename.c_str(),"wb");
198 if( outfile == NULL ){
199 synfig::error(_("Unable to open pipe to encodedv"));
202 int outfilefd = fileno(outfile);
203 if( outfilefd == -1 ){
204 synfig::error(_("Unable to open pipe to encodedv"));
207 if( dup2( outfilefd, STDOUT_FILENO ) == -1 ){
208 synfig::error(_("Unable to open pipe to encodedv"));
213 execlp("encodedv", "encodedv", "-w", "1", "-", (const char *)NULL);
215 execlp("encodedv", "encodedv", "-", (const char *)NULL);
216 // We should never reach here unless the exec failed
217 synfig::error(_("Unable to open pipe to encodedv"));
221 // Close pipein, not needed
223 // Save pipeout to file handle, will write to it later
224 file = fdopen(p[1], "wb");
226 synfig::error(_("Unable to open pipe to encodedv"));
232 #error There are no known APIs for creating child processes
236 // Sleep for a moment to let the pipe catch up
237 etl::clock().sleep(0.25f);
251 dv_trgt::start_frame(synfig::ProgressCallback */*callback*/)
253 int w=desc.get_w(),h=desc.get_h();
258 fprintf(file, "P6\n");
259 fprintf(file, "%d %d\n", w, h);
260 fprintf(file, "%d\n", 255);
263 buffer=new unsigned char[3*w];
265 delete [] color_buffer;
266 color_buffer=new Color[w];
272 dv_trgt::start_scanline(int /*scanline*/)
278 dv_trgt::end_scanline()
283 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
285 if(!fwrite(buffer,1,desc.get_w()*3,file))