Remove .gitignore do nothing is ignored.
[synfig.git] / synfig-core / trunk / src / modules / mod_yuv420p / trgt_yuv.cpp
index 22ad4d8..bad2dca 100644 (file)
@@ -1,27 +1,29 @@
-/* === S I N F G =========================================================== */
+/* === S Y N F I G ========================================================= */
 /*!    \file trgt_yuv.cpp
 **     \brief Template File
 **
-**     $Id: trgt_yuv.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
+**     $Id$
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007 Chris Moore
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **     \endlegal
 */
 /* ========================================================================= */
 
 /* === H E A D E R S ======================================================= */
 
-#define SINFG_TARGET
+#define SYNFIG_TARGET
 
 #ifdef USING_PCH
 #      include "pch.h"
@@ -37,7 +39,7 @@
 #include <functional>
 #endif
 
-using namespace sinfg;
+using namespace synfig;
 using namespace std;
 using namespace etl;
 
@@ -53,17 +55,17 @@ using namespace etl;
 
 /* === G L O B A L S ======================================================= */
 
-SINFG_TARGET_INIT(yuv);
-SINFG_TARGET_SET_NAME(yuv,"yuv420p");
-SINFG_TARGET_SET_EXT(yuv,"yuv");
-SINFG_TARGET_SET_VERSION(yuv,"0.1");
-SINFG_TARGET_SET_CVS_ID(yuv,"$Id: trgt_yuv.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
+SYNFIG_TARGET_INIT(yuv);
+SYNFIG_TARGET_SET_NAME(yuv,"yuv420p");
+SYNFIG_TARGET_SET_EXT(yuv,"yuv");
+SYNFIG_TARGET_SET_VERSION(yuv,"0.1");
+SYNFIG_TARGET_SET_CVS_ID(yuv,"$Id$");
 
 /* === M E T H O D S ======================================================= */
 
 yuv::yuv(const char *FILENAME):
        filename(FILENAME),
-       file( (filename=="-")?stdout:fopen(filename.c_str(),"wb") ),
+       file( (filename=="-")?stdout:fopen(filename.c_str(),POPEN_BINARY_WRITE_TYPE) ),
        dithering(true)
 {
        // YUV420P doesn't have an alpha channel
@@ -75,6 +77,18 @@ yuv::~yuv()
 }
 
 bool
+yuv::init()
+{
+       if (!file)
+               return false;
+
+       fprintf(file.get(), "YUV4MPEG2 W%d H%d F%d:1 Ip\n",
+                       desc.get_w(), desc.get_h(),
+                       round_to_int(desc.get_frame_rate()));
+       return true;
+}
+
+bool
 yuv::set_rend_desc(RendDesc *given_desc)
 {
        given_desc->clear_flags();
@@ -87,13 +101,14 @@ yuv::set_rend_desc(RendDesc *given_desc)
 
        // Set up our surface
        surface.set_wh(desc.get_w(),desc.get_h());
-       
+
        return true;
 }
 
 bool
-yuv::start_frame(sinfg::ProgressCallback *callback)
+yuv::start_frame(synfig::ProgressCallback */*callback*/)
 {
+       fprintf(file.get(), "FRAME\n");
        return static_cast<bool>(file);
 }
 
@@ -145,11 +160,11 @@ yuv::end_frame()
                                if(surface.get_w()>x+1)
                                        surface[y][x+1]+=error * ((float)7/(float)16);
                        }
-                       
+
                        fputc(i,file.get());
                }
-       
-               
+
+
        // Create new super-sampled surface
        Surface sm_surface(w/2,h/2);
        for(y=0;y<h;y+=2)
@@ -189,7 +204,7 @@ yuv::end_frame()
                        }
                        fputc(i,file.get());
                }
-                               
+
        // Output V channel
        for(y=0;y<sm_surface.get_h();y++)
                for(x=0;x<sm_surface.get_w();x++)
@@ -215,7 +230,7 @@ yuv::end_frame()
                        }
                        fputc(i,file.get());
                }
-       
+
        // Flush out the frame
        fflush(file.get());
 }