From 18940a0aa41ab601714e71d2d08889dc33c33094 Mon Sep 17 00:00:00 2001
From: Michael Wild <themiwi@users.sourceforge.net>
Date: Fri, 17 Jul 2009 11:26:31 +0200
Subject: [PATCH 3/3] ENH: Integrated vtkOggTheoraWriter into ParaView

The Subsampling property is propagated to the
vtkSMAnimationSceneImageWriter, but so far there is no GUI control.

Signed-off-by: Michael Wild <themiwi@users.sourceforge.net>
---
 Applications/OverView/Core/AboutDialog.cxx         |    2 ++
 Qt/Components/pqAnimationManager.cxx               |    4 ++++
 Qt/Components/pqClientAboutDialog.cxx              |    2 ++
 Servers/Common/vtkPVServerInformation.cxx          |   13 +++++++++++++
 Servers/Common/vtkPVServerInformation.h            |    6 ++++++
 .../vtkSMAnimationSceneImageWriter.cxx             |   14 +++++++++++++-
 .../ServerManager/vtkSMAnimationSceneImageWriter.h |   11 ++++++++++-
 7 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/Applications/OverView/Core/AboutDialog.cxx b/Applications/OverView/Core/AboutDialog.cxx
index 00ba766..891eec7 100755
--- a/Applications/OverView/Core/AboutDialog.cxx
+++ b/Applications/OverView/Core/AboutDialog.cxx
@@ -218,6 +218,8 @@ void AboutDialog::AddServerInformation(pqServer* server, QTreeWidget* tree)
     ::addItem(tree, "Tile Display", "Off");
     }
 
+  ::addItem(tree, "Write Ogg/Theora Animations",
+    serverInfo->GetOGVSupport()? "On": "Off");
   ::addItem(tree, "Write AVI Animations",
     serverInfo->GetAVISupport()? "On": "Off");
 }
diff --git a/Qt/Components/pqAnimationManager.cxx b/Qt/Components/pqAnimationManager.cxx
index 76c40bc..30d1946 100644
--- a/Qt/Components/pqAnimationManager.cxx
+++ b/Qt/Components/pqAnimationManager.cxx
@@ -457,6 +457,10 @@ bool pqAnimationManager::saveAnimation()
     }
 
   QString filters = "";
+  if (serverInfo && serverInfo->GetOGVSupport())
+    {
+    filters += "Ogg/Theora files (*.ogv);;";
+    }
   if (serverInfo && serverInfo->GetAVISupport())
     {
     filters += "AVI files (*.avi);;";
diff --git a/Qt/Components/pqClientAboutDialog.cxx b/Qt/Components/pqClientAboutDialog.cxx
index 4beae0c..8d748e6 100644
--- a/Qt/Components/pqClientAboutDialog.cxx
+++ b/Qt/Components/pqClientAboutDialog.cxx
@@ -218,6 +218,8 @@ void pqClientAboutDialog::AddServerInformation(pqServer* server, QTreeWidget* tr
     ::addItem(tree, "Tile Display", "Off");
     }
 
+  ::addItem(tree, "Write Ogg/Theora Animations",
+    serverInfo->GetOGVSupport()? "On": "Off");
   ::addItem(tree, "Write AVI Animations",
     serverInfo->GetAVISupport()? "On": "Off");
 }
diff --git a/Servers/Common/vtkPVServerInformation.cxx b/Servers/Common/vtkPVServerInformation.cxx
index 7e42f98..ac64e6f 100755
--- a/Servers/Common/vtkPVServerInformation.cxx
+++ b/Servers/Common/vtkPVServerInformation.cxx
@@ -48,6 +48,7 @@ vtkPVServerInformation::vtkPVServerInformation()
   this->AVISupport = 1;
 # endif
 #endif
+  this->OGVSupport = 1;
 
   this->RenderModuleName = NULL;
   this->MachinesInternals = new vtkPVServerOptionsInternals;
@@ -73,6 +74,7 @@ void vtkPVServerInformation::PrintSelf(ostream& os, vtkIndent indent)
   os << indent << "UseIceT: " << this->UseIceT << endl;
   os << indent << "RenderModuleName: "
      << (this->RenderModuleName ? this->RenderModuleName : "(none)") << endl;
+  os << indent << "OGVSupport: " << this->OGVSupport << endl;
   os << indent << "AVISupport: " << this->AVISupport << endl;
   os << indent << "Timeout: " << this->Timeout << endl;
 }
@@ -167,6 +169,11 @@ void vtkPVServerInformation::AddInformation(vtkPVInformation* info)
       this->Timeout = serverInfo->GetTimeout();
       }
 
+    if (!serverInfo->GetOGVSupport())
+      {
+      this->OGVSupport = 0;
+      }
+
     if (!serverInfo->GetAVISupport())
       {
       this->AVISupport = 0;
@@ -199,6 +206,7 @@ void vtkPVServerInformation::CopyToStream(vtkClientServerStream* css)
   *css << this->Timeout;
   *css << this->UseIceT;
   *css << this->RenderModuleName;
+  *css << this->OGVSupport;
   *css << this->AVISupport;
   *css << this->GetNumberOfMachines();
   unsigned int idx;
@@ -257,6 +265,11 @@ void vtkPVServerInformation::CopyFromStream(const vtkClientServerStream* css)
     return;
     }
   this->SetRenderModuleName(rmName);
+  if (!css->GetArgument(0, 9, &this->OGVSupport))
+    {
+    vtkErrorMacro("Error parsing OGVSupport flag from message.");
+    return;
+    }
   if (!css->GetArgument(0, 9, &this->AVISupport))
     {
     vtkErrorMacro("Error parsing AVISupport flag from message.");
diff --git a/Servers/Common/vtkPVServerInformation.h b/Servers/Common/vtkPVServerInformation.h
index aafe6d6..cfc2fcd 100755
--- a/Servers/Common/vtkPVServerInformation.h
+++ b/Servers/Common/vtkPVServerInformation.h
@@ -80,6 +80,11 @@ public:
   vtkGetStringMacro(RenderModuleName);
 
   // Description:
+  // Get/Set if the server supports saving OGVs.
+  vtkSetMacro(OGVSupport, int);
+  vtkGetMacro(OGVSupport, int);
+
+  // Description:
   // Get/Set if the server supports saving AVIs.
   vtkSetMacro(AVISupport, int);
   vtkGetMacro(AVISupport, int);
@@ -120,6 +125,7 @@ protected:
   vtkPVServerInformation();
   ~vtkPVServerInformation();
 
+  int OGVSupport;
   int AVISupport;
   int RemoteRendering;
   int TileDimensions[2];
diff --git a/Servers/ServerManager/vtkSMAnimationSceneImageWriter.cxx b/Servers/ServerManager/vtkSMAnimationSceneImageWriter.cxx
index fde7ac2..5212697 100644
--- a/Servers/ServerManager/vtkSMAnimationSceneImageWriter.cxx
+++ b/Servers/ServerManager/vtkSMAnimationSceneImageWriter.cxx
@@ -45,6 +45,7 @@
 #   include "vtkFFMPEGWriter.h"
 # endif
 #endif
+#include "vtkOggTheoraWriter.h"
 
 vtkStandardNewMacro(vtkSMAnimationSceneImageWriter);
 vtkCxxRevisionMacro(vtkSMAnimationSceneImageWriter, "$Revision: 1.14 $");
@@ -57,7 +58,8 @@ vtkSMAnimationSceneImageWriter::vtkSMAnimationSceneImageWriter()
 {
   this->Magnification = 1;
   this->ErrorCode = 0;
-  this->Quality = 2; // 0 = low, 1 = medium, 2 = high
+  this->Quality = 2; // 0 = low, 1 = medium, 2 = hig
+  this->Subsampling = 0;
   this->ActualSize[0] = this->ActualSize[1] = 0;
 
   this->MovieWriter = 0;
@@ -377,6 +379,15 @@ bool vtkSMAnimationSceneImageWriter::CreateWriter()
     }
 # endif
 #endif
+  else if (extension == ".ogv" || extension == ".ogg")
+    {
+    vtkOggTheoraWriter *ogvwriter = vtkOggTheoraWriter::New();
+    ogvwriter->SetQuality(this->Quality);
+    ogvwriter->SetRate(
+      static_cast<int>(this->GetFrameRate()));
+    ogvwriter->SetSubsampling(this->GetSubsampling());
+    mwriter = ogvwriter;
+    }
   else
     {
     vtkErrorMacro("Unknown extension " << extension.c_str());
@@ -434,6 +445,7 @@ void vtkSMAnimationSceneImageWriter::PrintSelf(ostream& os, vtkIndent indent)
   this->Superclass::PrintSelf(os, indent);
   os << indent << "Quality: " << this->Quality << endl;
   os << indent << "Magnification: " << this->Magnification << endl;
+  os << indent << "Subsampling: " << this->Subsampling << endl;
   os << indent << "ErrorCode: " << this->ErrorCode << endl;
   os << indent << "FrameRate: " << this->FrameRate << endl;
   os << indent << "BackgroundColor: " << this->BackgroundColor[0]
diff --git a/Servers/ServerManager/vtkSMAnimationSceneImageWriter.h b/Servers/ServerManager/vtkSMAnimationSceneImageWriter.h
index 819510d..0b1c4a3 100644
--- a/Servers/ServerManager/vtkSMAnimationSceneImageWriter.h
+++ b/Servers/ServerManager/vtkSMAnimationSceneImageWriter.h
@@ -56,6 +56,15 @@ public:
   vtkGetMacro(Quality, int);
 
   // Description:
+  // Get/Set the setting whether the movie encoder should use subsampling of
+  // the chrome planes or not, if applicable. Since the human eye is more
+  // sensitive to brightness than color variations, subsampling can be
+  // useful to reduce the bitrate. Default value is 0.
+  vtkSetMacro(Subsampling, double);
+  vtkGetMacro(Subsampling, double);
+  vtkBooleanMacro(Subsampling, double);
+
+  // Description:
   // Get the error code which is set if there's an error while writing
   // the images.
   vtkGetMacro(ErrorCode, int);
@@ -76,7 +85,6 @@ public:
   vtkSetMacro(FrameRate, double);
   vtkGetMacro(FrameRate, double);
 
-
   // Description:
   // Convenience method used to merge a smaller image (\c src) into a 
   // larger one (\c dest). The location of the smaller image in the larger image
@@ -121,6 +129,7 @@ protected:
   int Magnification;
   int FileCount;
   int ErrorCode;
+  int Subsampling;
 
   char* Prefix;
   char* Suffix;
-- 
1.6.3.3

