1 /* === S Y N F I G ========================================================= */
3 ** \brief ppm Target Module
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
36 #include <ETL/stringf>
39 #include <sys/types.h>
48 /* === M A C R O S ========================================================= */
50 using namespace synfig;
54 /* === G L O B A L S ======================================================= */
56 SYNFIG_TARGET_INIT(dv_trgt);
57 SYNFIG_TARGET_SET_NAME(dv_trgt,"dv");
58 SYNFIG_TARGET_SET_EXT(dv_trgt,"dv");
59 SYNFIG_TARGET_SET_VERSION(dv_trgt,"0.1");
60 SYNFIG_TARGET_SET_CVS_ID(dv_trgt,"$Id$");
62 /* === M E T H O D S ======================================================= */
65 dv_trgt::dv_trgt(const char *Filename)
82 waitpid(pid,&status,0);
86 delete [] color_buffer;
90 dv_trgt::set_rend_desc(RendDesc *given_desc)
92 // Set the aspect ratio
96 given_desc->set_wh(160,90);
98 // Widescreen should be progressive scan
99 given_desc->set_interlaced(false);
104 given_desc->set_wh(400,300);
106 // We should be interlaced
107 given_desc->set_interlaced(true);
110 // but the pixel res should be 720x480
111 given_desc->clear_flags(),given_desc->set_wh(720,480);
113 // NTSC Frame rate is 29.97
114 given_desc->set_frame_rate(29.97);
116 // The pipe to encodedv is PPM, which needs RGB data
117 //given_desc->set_pixel_format(PF_RGB);
119 // Set the description
128 imagecount=desc.get_frame_start();
133 synfig::error(_("Unable to open pipe to encodedv"));
140 synfig::error(_("Unable to open pipe to encodedv"));
146 // Close pipeout, not needed
148 // Dup pipeout to stdin
149 if( dup2( p[0], STDIN_FILENO ) == -1 ){
150 synfig::error(_("Unable to open pipe to encodedv"));
153 // Close the unneeded pipeout
155 // Open filename to stdout
156 FILE* outfile = fopen(filename.c_str(),"wb");
157 if( outfile == NULL ){
158 synfig::error(_("Unable to open pipe to encodedv"));
161 int outfilefd = fileno(outfile);
162 if( outfilefd == -1 ){
163 synfig::error(_("Unable to open pipe to encodedv"));
166 if( dup2( outfilefd, STDOUT_FILENO ) == -1 ){
167 synfig::error(_("Unable to open pipe to encodedv"));
172 execlp("encodedv", "encodedv", "-w", "1", "-", (const char *)NULL);
174 execlp("encodedv", "encodedv", "-", (const char *)NULL);
175 // We should never reach here unless the exec failed
176 synfig::error(_("Unable to open pipe to encodedv"));
180 // Close pipein, not needed
182 // Save pipeout to file handle, will write to it later
183 file = fdopen(p[1], "wb");
185 synfig::error(_("Unable to open pipe to encodedv"));
190 // Sleep for a moment to let the pipe catch up
191 etl::clock().sleep(0.25f);
205 dv_trgt::start_frame(synfig::ProgressCallback */*callback*/)
207 int w=desc.get_w(),h=desc.get_h();
212 fprintf(file, "P6\n");
213 fprintf(file, "%d %d\n", w, h);
214 fprintf(file, "%d\n", 255);
217 buffer=new unsigned char[3*w];
219 delete [] color_buffer;
220 color_buffer=new Color[w];
226 dv_trgt::start_scanline(int /*scanline*/)
232 dv_trgt::end_scanline()
237 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
239 if(!fwrite(buffer,1,desc.get_w()*3,file))