@@ -194,34 +194,20 @@ bool QtOIIOHandler::read(QImage *image)
194194 // perceptually uniform: "inferno", "viridis", "magma", "plasma" -- others: "blue-red", "spectrum", "heat"
195195 const char * colorMapEnv = std::getenv (" QTOIIO_COLORMAP" );
196196 const std::string colorMapType = colorMapEnv ? colorMapEnv : " plasma" ;
197+
198+ // detect AliceVision special files that require a jetColorMap based conversion
199+ const bool isDepthMap = d->fileName ().contains (" depthMap" );
200+ const bool isNmodMap = d->fileName ().contains (" nmodMap" );
201+
197202 if (colorMapEnv)
198203 {
199204 qDebug () << " [QtOIIO] compute colormap \" " << colorMapType.c_str () << " \" " ;
200205 oiio::ImageBufAlgo::color_map (tmpBuf, inBuf, 0 , colorMapType);
201206 }
202- else if (d->fileName ().contains (" depthMap" ))
203- {
204- oiio::ImageBufAlgo::PixelStats stats;
205- oiio::ImageBufAlgo::computePixelStats (stats, inBuf);
206-
207- #pragma omp parallel for
208- for (int y = 0 ; y < inSpec.height ; ++y)
209- {
210- for (int x = 0 ; x < inSpec.width ; ++x)
211- {
212- float depthValue = 0 .0f ;
213- inBuf.getpixel (x, y, &depthValue, 1 );
214- float normalizedDepthValue = (depthValue - stats.min [0 ]) / (stats.max [0 ] - stats.min [0 ]);
215- Color32f color = getColor32fFromJetColorMap (normalizedDepthValue);
216- tmpBuf.setpixel (x, y, color.m , 3 ); // set only 3 channels (RGB)
217- }
218- }
219- }
220- else if (d->fileName ().contains (" nmodMap" ))
207+ else if (isDepthMap || isNmodMap)
221208 {
222209 oiio::ImageBufAlgo::PixelStats stats;
223210 oiio::ImageBufAlgo::computePixelStats (stats, inBuf);
224- // oiio::ImageBufAlgo::color_map(dst, src, srcchannel, int(knots.size()/3), 3, knots);
225211
226212#pragma omp parallel for
227213 for (int y = 0 ; y < inSpec.height ; ++y)
@@ -230,8 +216,13 @@ bool QtOIIOHandler::read(QImage *image)
230216 {
231217 float depthValue = 0 .0f ;
232218 inBuf.getpixel (x, y, &depthValue, 1 );
233- float normalizedDepthValue = (depthValue - stats.min [0 ]) / (stats.max [0 ] - stats.min [0 ]);
234- Color32f color = getColor32fFromJetColorMapClamp (normalizedDepthValue);
219+ const float range = stats.max [0 ] - stats.min [0 ];
220+ const float normalizedDepthValue = range != 0 .0f ? (depthValue - stats.min [0 ]) / range : 1 .0f ;
221+ Color32f color;
222+ if (isDepthMap)
223+ color = getColor32fFromJetColorMap (normalizedDepthValue);
224+ else if (isNmodMap)
225+ color = getColor32fFromJetColorMapClamp (normalizedDepthValue);
235226 tmpBuf.setpixel (x, y, color.m , 3 ); // set only 3 channels (RGB)
236227 }
237228 }
0 commit comments