1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SVTK_ImageWriter.h"
24 #include <vtkImageData.h>
25 #include <vtkImageClip.h>
26 #include <vtkJPEGWriter.h>
27 #include <vtkSmartPointer.h>
30 static int MYDEBUG = 0;
32 static int MYDEBUG = 0;
36 //----------------------------------------------------------------------------
38 ::SVTK_ImageWriter(QSemaphore* theSemaphore,
39 vtkImageData* theImageData,
40 const std::string& theName,
43 mySemaphore(theSemaphore),
44 myImageData(theImageData),
46 myProgressive(theProgressive),
47 myQuality(theQuality),
48 myConstraint16Flag(true)
51 //----------------------------------------------------------------------------
55 if(MYDEBUG) cout<<"SVTK_ImageWriter::~SVTK_ImageWriter - this = "<<this<<endl;
59 //----------------------------------------------------------------------------
64 vtkJPEGWriter *aWriter = vtkJPEGWriter::New();
65 vtkImageData *anImageData = myImageData;
66 vtkSmartPointer<vtkImageClip> anImageClip;
68 if(myConstraint16Flag){
70 myImageData->UpdateInformation();
71 myImageData->GetUpdateExtent(uExtent);
72 unsigned int width = uExtent[1] - uExtent[0] + 1;
73 unsigned int height = uExtent[3] - uExtent[2] + 1;
74 width = (width / 16) * 16;
75 height= (height / 16) * 16;
76 uExtent[1] = uExtent[0] + width - 1;
77 uExtent[3] = uExtent[2] + height - 1;
79 anImageClip = vtkImageClip::New();
80 anImageClip->Delete();
82 anImageClip->SetInput(myImageData);
83 anImageClip->SetOutputWholeExtent(uExtent);
84 anImageClip->ClipDataOn();
85 anImageData = anImageClip->GetOutput();
88 aWriter->WriteToMemoryOff();
89 aWriter->SetFileName(myName.c_str());
90 aWriter->SetQuality(myQuality);
91 aWriter->SetProgressive(myProgressive);
92 aWriter->SetInput(anImageData);
96 myImageData->Delete();
98 if(MYDEBUG) cout<<"SVTK_ImageWriter::run "<<
100 //"; total = "<<mySemaphore->total()<<
101 "; available = "<<mySemaphore->available()<<endl;
102 mySemaphore->release();