1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SVTK_ImageWriter.h"
26 #include <vtkImageData.h>
27 #include <vtkImageClip.h>
28 #include <vtkJPEGWriter.h>
29 #include <vtkSmartPointer.h>
32 static int MYDEBUG = 0;
34 static int MYDEBUG = 0;
38 //----------------------------------------------------------------------------
40 ::SVTK_ImageWriter(QSemaphore* theSemaphore,
41 vtkImageData* theImageData,
42 const std::string& theName,
45 mySemaphore(theSemaphore),
46 myImageData(theImageData),
48 myProgressive(theProgressive),
49 myQuality(theQuality),
50 myConstraint16Flag(true)
53 //----------------------------------------------------------------------------
57 if(MYDEBUG) cout<<"SVTK_ImageWriter::~SVTK_ImageWriter - this = "<<this<<endl;
61 //----------------------------------------------------------------------------
66 vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
67 vtkImageData *anImageData = myImageData;
68 vtkSmartPointer<vtkImageClip> anImageClip;
70 if(myConstraint16Flag){
72 myImageData->UpdateInformation();
73 myImageData->GetUpdateExtent(uExtent);
74 unsigned int width = uExtent[1] - uExtent[0] + 1;
75 unsigned int height = uExtent[3] - uExtent[2] + 1;
76 width = (width / 16) * 16;
77 height= (height / 16) * 16;
78 uExtent[1] = uExtent[0] + width - 1;
79 uExtent[3] = uExtent[2] + height - 1;
81 anImageClip = vtkImageClip::New();
82 anImageClip->Delete();
84 anImageClip->SetInput(myImageData);
85 anImageClip->SetOutputWholeExtent(uExtent);
86 anImageClip->ClipDataOn();
87 anImageData = anImageClip->GetOutput();
90 aWriter->WriteToMemoryOff();
91 aWriter->SetFileName(myName.c_str());
92 aWriter->SetQuality(myQuality);
93 aWriter->SetProgressive(myProgressive);
94 aWriter->SetInput(anImageData);
98 myImageData->Delete();
100 if(MYDEBUG) cout<<"SVTK_ImageWriter::run "<<
102 //"; total = "<<mySemaphore->total()<<
103 "; available = "<<mySemaphore->available()<<endl;
104 mySemaphore->release();