X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=vv%2FvvAnimatedGIFWriter.cxx;h=1efd50dcc1cc5f27be12899c980d41815be88587;hb=abdae5f22ecae40608e0279729108b428c9dbc62;hp=75352acacc0f05b33f48540b97b9ad52649fddaa;hpb=bbb9427a59a56c9e9f3a139814adb104031eae2b;p=clitk.git diff --git a/vv/vvAnimatedGIFWriter.cxx b/vv/vvAnimatedGIFWriter.cxx index 75352ac..1efd50d 100644 --- a/vv/vvAnimatedGIFWriter.cxx +++ b/vv/vvAnimatedGIFWriter.cxx @@ -1,8 +1,6 @@ #include "vvAnimatedGIFWriter.h" #include "clitkDD.h" -#include "ximagif.h" - #include #include #include @@ -10,6 +8,8 @@ #include #include +#include "ximagif.h" + //--------------------------------------------------------------------------- vtkStandardNewMacro(vvAnimatedGIFWriter); @@ -18,6 +18,7 @@ vvAnimatedGIFWriter::vvAnimatedGIFWriter() { Rate = 5; Loops = 0; + Dither = false; } //--------------------------------------------------------------------------- @@ -65,21 +66,39 @@ void vvAnimatedGIFWriter::End() 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))); + 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 FILE * pFile; pFile = fopen (this->FileName, "wb"); + if(pFile==NULL) { + vtkErrorMacro("Error in vvAnimatedGIFWriter::End: could not open " << this->FileName ); + return; + } CxImageGIF cximagegif; cximagegif.SetLoops(Loops); bool result = cximagegif.Encode(pFile,&(cximages[0]), (int)RGBslices.size(), true);