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)
98 #if defined(WIN32_PIPE_TO_PROCESSES)
100 #elif defined(UNIX_PIPE_TO_PROCESSES)
103 waitpid(pid,&status,0);
108 delete [] color_buffer;
112 dv_trgt::set_rend_desc(RendDesc *given_desc)
114 // Set the aspect ratio
118 given_desc->set_wh(160,90);
120 // Widescreen should be progressive scan
121 given_desc->set_interlaced(false);
126 given_desc->set_wh(400,300);
128 // We should be interlaced
129 given_desc->set_interlaced(true);
132 // but the pixel res should be 720x480
133 given_desc->clear_flags(),given_desc->set_wh(720,480);
135 // NTSC Frame rate is 29.97
136 given_desc->set_frame_rate(29.97);
138 // The pipe to encodedv is PPM, which needs RGB data
139 //given_desc->set_pixel_format(PF_RGB);
141 // Set the description
150 imagecount=desc.get_frame_start();
152 #if defined(WIN32_PIPE_TO_PROCESSES)
157 command=strprintf("encodedv -w 1 - > \"%s\"\n",filename.c_str());
159 command=strprintf("encodedv - > \"%s\"\n",filename.c_str());
161 // Open the pipe to encodedv
162 file=popen(command.c_str(),POPEN_BINARY_WRITE_TYPE);
166 synfig::error(_("Unable to open pipe to encodedv"));
170 #elif defined(UNIX_PIPE_TO_PROCESSES)
175 synfig::error(_("Unable to open pipe to encodedv"));
182 synfig::error(_("Unable to open pipe to encodedv"));
188 // Close pipeout, not needed
190 // Dup pipeout to stdin
191 if( dup2( p[0], STDIN_FILENO ) == -1 ){
192 synfig::error(_("Unable to open pipe to encodedv"));
195 // Close the unneeded pipeout
197 // Open filename to stdout
198 FILE* outfile = fopen(filename.c_str(),"wb");
199 if( outfile == NULL ){
200 synfig::error(_("Unable to open pipe to encodedv"));
203 int outfilefd = fileno(outfile);
204 if( outfilefd == -1 ){
205 synfig::error(_("Unable to open pipe to encodedv"));
208 if( dup2( outfilefd, STDOUT_FILENO ) == -1 ){
209 synfig::error(_("Unable to open pipe to encodedv"));
214 execlp("encodedv", "encodedv", "-w", "1", "-", (const char *)NULL);
216 execlp("encodedv", "encodedv", "-", (const char *)NULL);
217 // We should never reach here unless the exec failed
218 synfig::error(_("Unable to open pipe to encodedv"));
222 // Close pipein, not needed
224 // Save pipeout to file handle, will write to it later
225 file = fdopen(p[1], "wb");
227 synfig::error(_("Unable to open pipe to encodedv"));
233 #error There are no known APIs for creating child processes
237 // Sleep for a moment to let the pipe catch up
238 etl::clock().sleep(0.25f);
252 dv_trgt::start_frame(synfig::ProgressCallback */*callback*/)
254 int w=desc.get_w(),h=desc.get_h();
259 fprintf(file, "P6\n");
260 fprintf(file, "%d %d\n", w, h);
261 fprintf(file, "%d\n", 255);
264 buffer=new unsigned char[3*w];
266 delete [] color_buffer;
267 color_buffer=new Color[w];
273 dv_trgt::start_scanline(int /*scanline*/)
279 dv_trgt::end_scanline()
284 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
286 if(!fwrite(buffer,1,desc.get_w()*3,file))