]> Creatis software - clitk.git/commitdiff
First githering option for animated gif using CxImage option
authorSimon Rit <simon.rit@creatis.insa-lyon.fr>
Thu, 19 Apr 2012 16:20:10 +0000 (18:20 +0200)
committerSimon Rit <simon.rit@creatis.insa-lyon.fr>
Thu, 19 Apr 2012 16:20:10 +0000 (18:20 +0200)
vv/vvAnimatedGIFWriter.cxx
vv/vvAnimatedGIFWriter.h
vv/vvMainWindow.cxx

index 934d7dd24e80fa797755082ed0259e94903542b8..8ba0f69062a3b0b2591c79ce409e3ddbcd1bbcf8 100644 (file)
@@ -18,6 +18,7 @@ vvAnimatedGIFWriter::vvAnimatedGIFWriter()
 {
   Rate = 5;
   Loops = 0;
+  Dither = false;
 }
 
 //---------------------------------------------------------------------------
@@ -77,10 +78,18 @@ void vvAnimatedGIFWriter::End()
   std::vector<CxImage*> cximages( RGBslices.size() );
   for(unsigned int i=0; i<RGBslices.size(); i++) {
     cximages[i] = new CxImage;
-    cximages[i]->CreateFromArray((BYTE *)cast->GetOutput()->GetScalarPointer(0,0,i),
-                                 width, height, 8, width, false);
     cximages[i]->SetFrameDelay(100/Rate);
-    cximages[i]->SetPalette(pal);
+    if(Dither) {
+      cximages[i]->CreateFromArray((BYTE *)RGBvolume->GetOutput()->GetScalarPointer(0,0,i),
+                                   width, height, 24, width*3, false);
+      cximages[i]->SwapRGB2BGR();
+      cximages[i]->DecreaseBpp(8, true, pal);
+    }
+    else {
+      cximages[i]->CreateFromArray((BYTE *)cast->GetOutput()->GetScalarPointer(0,0,i),
+                                   width, height, 8, width, false);
+      cximages[i]->SetPalette(pal);
+    }
   }
 
   // Create gif
index 82427791eb931ba944d87532cfe1eab214244a4c..2fde827b8e25c7457b35a7c834a5347d39075299 100644 (file)
@@ -32,12 +32,18 @@ public:
   vtkSetClampMacro(Loops, int, 0, 5000);
   vtkGetMacro(Loops, int);
 
+  // Description:
+  // Set/Get the dithering
+  vtkSetMacro(Dither, bool);
+  vtkGetMacro(Dither, bool);
+
 protected:
   vvAnimatedGIFWriter();
   ~vvAnimatedGIFWriter();
 
   int Rate;
   int Loops;
+  bool Dither;
 
   vtkSmartPointer<vtkImageAppend> RGBvolume;
   std::vector< vtkSmartPointer<vtkImageData> > RGBslices;
index c08462cd0ad6efc05236fdc9d9eefadd37d5eda0..46b0ecbb2fd9f2bb1a7656876978d531c734631c 100644 (file)
@@ -2822,6 +2822,13 @@ void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
                                      tr("Number of loops (0 means infinite):"), 0, 0, 1000000000, 1, &ok);
       if(ok)
         gif->SetLoops(loops);
+
+      // Dithering
+      QString msg = "Would you like to activate dithering?";
+      QMessageBox msgBox(QMessageBox::Question, tr("Dithering"),msg, 0, this);
+      msgBox.addButton(tr("Yes"), QMessageBox::AcceptRole);
+      msgBox.addButton(tr("No"), QMessageBox::RejectRole);
+      gif->SetDither(msgBox.exec() == QMessageBox::AcceptRole);
     }
 #endif
 #ifdef VTK_USE_VIDEO_FOR_WINDOWS