24 #include "ctkLogger.h"
28 #include <QStringList>
33 static ctkLogger logger (
"org.commontk.dicom.DICOMThumbnailGenerator" );
71 Q_UNUSED(parentValue);
83 EI_Status result = dcmImage->getStatus();
84 if (result != EIS_Normal)
86 logger.error(QString(
"Rendering of DICOM image failed for thumbnail failed: ") + DicomImage::getString(result));
91 if (dcmImage->isMonochrome())
93 if (dcmImage->getWindowCount() > 0)
95 dcmImage->setWindow(0);
99 dcmImage->setMinMaxWindow(OFTrue );
103 const unsigned long width = dcmImage->getWidth();
104 const unsigned long height = dcmImage->getHeight();
105 const unsigned long frameCount = dcmImage->getFrameCount();
106 unsigned long offset = 0;
110 if (dcmImage->isMonochrome())
113 header = QString(
"P5 %1 %2 255\n").arg(width).arg(height);
114 offset = header.length();
115 length = width * height + offset;
120 header = QString(
"P6 %1 %2 255\n").arg(width).arg(height);
121 offset = header.length();
122 length = width * height * 3 + offset;
127 buffer.append(header);
130 for (
int i=0; i<frameCount; ++i)
133 if (dcmImage->getOutputData(
static_cast<void *
>(buffer.data() + offset),
length - offset, 8, i))
135 if (!image.loadFromData( buffer ))
137 logger.error(
"QImage couldn't created");
142 QString savePath = path;
145 QStringList splitPath = path.split(
".");
146 splitPath.back() = QString(
"frame_%1.png").arg(i);
147 savePath = splitPath.join(
".");
151 image.scaled(128,128,Qt::KeepAspectRatio).save(path,
"PNG");
155 image.scaled(128,128,Qt::KeepAspectRatio).save(savePath,
"PNG");