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 ======================================================= */
37 #include <ETL/stringf>
40 #include <sys/types.h>
60 /* === M A C R O S ========================================================= */
62 using namespace synfig;
66 #if defined(HAVE_FORK) && defined(HAVE_PIPE) && defined(HAVE_WAITPID)
67 #define UNIX_PIPE_TO_PROCESSES
69 #define WIN32_PIPE_TO_PROCESSES
72 /* === G L O B A L S ======================================================= */
74 SYNFIG_TARGET_INIT(dv_trgt);
75 SYNFIG_TARGET_SET_NAME(dv_trgt,"dv");
76 SYNFIG_TARGET_SET_EXT(dv_trgt,"dv");
77 SYNFIG_TARGET_SET_VERSION(dv_trgt,"0.1");
78 SYNFIG_TARGET_SET_CVS_ID(dv_trgt,"$Id$");
80 /* === M E T H O D S ======================================================= */
83 dv_trgt::dv_trgt(const char *Filename,
84 const synfig::TargetParam& /* params */)
99 #if defined(WIN32_PIPE_TO_PROCESSES)
101 #elif defined(UNIX_PIPE_TO_PROCESSES)
104 waitpid(pid,&status,0);
109 delete [] color_buffer;
113 dv_trgt::set_rend_desc(RendDesc *given_desc)
115 // Set the aspect ratio
119 given_desc->set_wh(160,90);
121 // Widescreen should be progressive scan
122 given_desc->set_interlaced(false);
127 given_desc->set_wh(400,300);
129 // We should be interlaced
130 given_desc->set_interlaced(true);
133 // but the pixel res should be 720x480
134 given_desc->clear_flags(),given_desc->set_wh(720,480);
136 // NTSC Frame rate is 29.97
137 given_desc->set_frame_rate(29.97);
139 // The pipe to encodedv is PPM, which needs RGB data
140 //given_desc->set_pixel_format(PF_RGB);
142 // Set the description
151 imagecount=desc.get_frame_start();
153 #if defined(WIN32_PIPE_TO_PROCESSES)
158 command=strprintf("encodedv -w 1 - > \"%s\"\n",filename.c_str());
160 command=strprintf("encodedv - > \"%s\"\n",filename.c_str());
162 // Open the pipe to encodedv
163 file=popen(command.c_str(),POPEN_BINARY_WRITE_TYPE);
167 synfig::error(_("Unable to open pipe to encodedv"));
171 #elif defined(UNIX_PIPE_TO_PROCESSES)
176 synfig::error(_("Unable to open pipe to encodedv"));
183 synfig::error(_("Unable to open pipe to encodedv"));
189 // Close pipeout, not needed
191 // Dup pipeout to stdin
192 if( dup2( p[0], STDIN_FILENO ) == -1 ){
193 synfig::error(_("Unable to open pipe to encodedv"));
196 // Close the unneeded pipeout
198 // Open filename to stdout
199 FILE* outfile = fopen(filename.c_str(),"wb");
200 if( outfile == NULL ){
201 synfig::error(_("Unable to open pipe to encodedv"));
204 int outfilefd = fileno(outfile);
205 if( outfilefd == -1 ){
206 synfig::error(_("Unable to open pipe to encodedv"));
209 if( dup2( outfilefd, STDOUT_FILENO ) == -1 ){
210 synfig::error(_("Unable to open pipe to encodedv"));
215 execlp("encodedv", "encodedv", "-w", "1", "-", (const char *)NULL);
217 execlp("encodedv", "encodedv", "-", (const char *)NULL);
218 // We should never reach here unless the exec failed
219 synfig::error(_("Unable to open pipe to encodedv"));
223 // Close pipein, not needed
225 // Save pipeout to file handle, will write to it later
226 file = fdopen(p[1], "wb");
228 synfig::error(_("Unable to open pipe to encodedv"));
234 #error There are no known APIs for creating child processes
238 // Sleep for a moment to let the pipe catch up
239 etl::clock().sleep(0.25f);
253 dv_trgt::start_frame(synfig::ProgressCallback */*callback*/)
255 int w=desc.get_w(),h=desc.get_h();
260 fprintf(file, "P6\n");
261 fprintf(file, "%d %d\n", w, h);
262 fprintf(file, "%d\n", 255);
265 buffer=new unsigned char[3*w];
267 delete [] color_buffer;
268 color_buffer=new Color[w];
274 dv_trgt::start_scanline(int /*scanline*/)
280 dv_trgt::end_scanline()
285 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
287 if(!fwrite(buffer,1,desc.get_w()*3,file))