X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvAnimatedGIFWriter.cxx;h=d72f253ecfa4f4d397eef6207faead81fb82bd45;hb=738abae55fb33a7c77843a9d84bc14d5439bff1a;hp=7af2ca4ab26466a2e7f401c3f9837a86cb4aa3ca;hpb=01d3c1060300fd0f117709f6c2e5d39d16781c2f;p=clitk.git diff --git a/vv/vvAnimatedGIFWriter.cxx b/vv/vvAnimatedGIFWriter.cxx index 7af2ca4..d72f253 100644 --- a/vv/vvAnimatedGIFWriter.cxx +++ b/vv/vvAnimatedGIFWriter.cxx @@ -1,8 +1,9 @@ #include "vvAnimatedGIFWriter.h" #include "clitkDD.h" -#include "ximagif.h" - +#include +#include +#include #include #include #include @@ -10,6 +11,8 @@ #include #include +#include "ximagif.h" + //--------------------------------------------------------------------------- vtkStandardNewMacro(vvAnimatedGIFWriter); @@ -18,6 +21,7 @@ vvAnimatedGIFWriter::vvAnimatedGIFWriter() { Rate = 5; Loops = 0; + Dither = false; } //--------------------------------------------------------------------------- @@ -38,14 +42,30 @@ void vvAnimatedGIFWriter::Start() void vvAnimatedGIFWriter::Write() { // get the data +#if VTK_MAJOR_VERSION <= 5 this->GetInput()->UpdateInformation(); int *wExtent = this->GetInput()->GetWholeExtent(); this->GetInput()->SetUpdateExtent(wExtent); this->GetInput()->Update(); +#elif VTK_MAJOR_VERSION >= 8 || (VTK_MAJOR_VERSION == 7 && VTK_MINOR_VERSION >= 1) + this->UpdateInformation(); + int *wExtent = this->GetInput()->GetInformation()->Get(vtkDataObject::DATA_EXTENT()); + this->UpdateExtent(wExtent); + this->Update(); +#else + this->UpdateInformation(); + int *wExtent = this->GetInput()->GetInformation()->Get(vtkDataObject::DATA_EXTENT()); + this->SetUpdateExtent(wExtent); + this->Update(); +#endif RGBslices.push_back( vtkSmartPointer::New() ); RGBslices.back()->ShallowCopy(this->GetInput()); +#if VTK_MAJOR_VERSION <= 5 RGBvolume->AddInput(RGBslices.back()); +#else + RGBvolume->AddInputData(RGBslices.back()); +#endif } //--------------------------------------------------------------------------- @@ -56,29 +76,47 @@ void vvAnimatedGIFWriter::End() // Quantize to 8 bit colors vtkSmartPointer quant = vtkSmartPointer::New(); quant->SetNumberOfColors(256); +#if VTK_MAJOR_VERSION <= 5 quant->SetInput(RGBvolume->GetOutput()); +#else + quant->SetInputConnection(RGBvolume->GetOutputPort()); +#endif quant->Update(); // Convert to 8 bit image vtkSmartPointer cast = vtkSmartPointer::New(); +#if VTK_MAJOR_VERSION <= 5 cast->SetInput( quant->GetOutput() ); +#else + cast->SetInputConnection( quant->GetOutputPort() ); +#endif cast->SetOutputScalarTypeToUnsignedChar(); cast->Update(); + // Create palette for CxImage => Swap r and b in LUT + RGBQUAD pal[256]; + memcpy(pal, (RGBQUAD*)(quant->GetLookupTable()->GetPointer(0)), sizeof(RGBQUAD)*256); + for(unsigned int j=0; j<256; j++) + std::swap(pal[j].rgbBlue, pal[j].rgbRed); + // Create a stack of CxImages DWORD width = cast->GetOutput()->GetExtent()[1]-cast->GetOutput()->GetExtent()[0]+1; DWORD height = cast->GetOutput()->GetExtent()[3]-cast->GetOutput()->GetExtent()[2]+1; std::vector cximages( RGBslices.size() ); for(unsigned int i=0; iCreateFromArray((BYTE *)cast->GetOutput()->GetScalarPointer(0,0,i), - width, height, 8, width, false); cximages[i]->SetFrameDelay(100/Rate); - cximages[i]->SetPalette((RGBQUAD*)(quant->GetLookupTable()->GetPointer(0))); - // Swap r and b in LUT before setting it - RGBQUAD *pal = cximages[i]->GetPalette(); - for(unsigned int j=0; j<256; j++) - std::swap(pal[j].rgbBlue, pal[j].rgbRed); + 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