diff --git a/src/osgPlugins/dicom/ReaderWriterDICOM.cpp b/src/osgPlugins/dicom/ReaderWriterDICOM.cpp index 97ea0bf3a..5f548f7e8 100644 --- a/src/osgPlugins/dicom/ReaderWriterDICOM.cpp +++ b/src/osgPlugins/dicom/ReaderWriterDICOM.cpp @@ -28,6 +28,9 @@ #include #include #include + #include + #include + #include "dcmtk/dcmimage/diregist.h" #endif #ifdef USE_ITK @@ -519,8 +522,6 @@ class ReaderWriterDICOM : public osgDB::ReaderWriter virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) const { - info()<<"Reading DICOM file "< details = new osgVolume::ImageDetails; details->setMatrix(new osg::RefMatrix); @@ -791,6 +799,12 @@ class ReaderWriterDICOM : public osgDB::ReaderWriter if (dcmImage->getStatus()==EIS_Normal) { + EP_Representation curr_pixelRep; + int curr_numPlanes; + GLenum curr_pixelFormat; + GLenum curr_dataType; + unsigned int curr_pixelSize; + // get the pixel data const DiPixel* pixelData = dcmImage->getInterData(); if(!pixelData) @@ -799,25 +813,45 @@ class ReaderWriterDICOM : public osgDB::ReaderWriter return ReadResult::ERROR_IN_READING_FILE; } - osg::ref_ptr imageAdapter = new osg::Image; - - EP_Representation curr_pixelRep; - int curr_numPlanes; - GLenum curr_pixelFormat; - GLenum curr_dataType; - unsigned int curr_pixelSize; - // create the new image convertPixelTypes(pixelData, curr_pixelRep, curr_numPlanes, curr_dataType, curr_pixelFormat, curr_pixelSize); - imageAdapter->setImage(dcmImage->getWidth(), dcmImage->getHeight(), dcmImage->getFrameCount(), - curr_pixelFormat, - curr_pixelFormat, - curr_dataType, - (unsigned char*)(pixelData->getData()), - osg::Image::NO_DELETE); + // dcmImage->getFrameCount() + + osg::ref_ptr imageAdapter = new osg::Image; + + if (dcmImage->isMonochrome()) + { + imageAdapter->setImage(dcmImage->getWidth(), dcmImage->getHeight(), dcmImage->getFrameCount(), + curr_pixelFormat, + curr_pixelFormat, + curr_dataType, + (unsigned char*)(pixelData->getData()), + osg::Image::NO_DELETE); + + } + else + { + imageAdapter->allocateImage(dcmImage->getWidth(), dcmImage->getHeight(), dcmImage->getFrameCount(), + curr_pixelFormat, curr_dataType); + + void* data = imageAdapter->data(0,0,0); + unsigned long size = dcmImage->createWindowsDIB( data, + imageAdapter->getTotalDataSize(), + 0, + imageAdapter->getPixelSizeInBits(), + 0, + 0); + + if (size==0) + { + info()<<" dcmImage->createWindowsDIB() failed to create required imagery."<getPhotometricInterpretation()="<getPhotometricInterpretation())<width="<getWidth()<<", height="<getHeight()<<" FrameCount="<< dcmImage->getFrameCount()<