diff --git a/src/Gui/BitmapFactory.cpp b/src/Gui/BitmapFactory.cpp index cd15e586303b2..3054bd67b6c06 100644 --- a/src/Gui/BitmapFactory.cpp +++ b/src/Gui/BitmapFactory.cpp @@ -539,22 +539,33 @@ void BitmapFactoryInst::convert(const QImage& p, SoSFImage& img) const QVector table = p.colorTable(); if (!table.isEmpty()) { if (p.hasAlphaChannel()) { - if (p.allGray()) + if (p.allGray()) { numcomponents = 2; - else + } + else { numcomponents = 4; + } } else { - if (p.allGray()) + if (p.allGray()) { numcomponents = 1; - else + } + else { numcomponents = 3; + } } } else { numcomponents = buffersize / (size[0] * size[1]); } + int depth = numcomponents; + + // Coin3D only supports up to 32-bit images + if (numcomponents == 8) { + numcomponents = 4; + } + // allocate image data img.setValue(size, numcomponents, nullptr); @@ -568,29 +579,45 @@ void BitmapFactoryInst::convert(const QImage& p, SoSFImage& img) const unsigned char * line = &bytes[width*numcomponents*(height-(y+1))]; for (int x = 0; x < width; x++) { - QRgb rgb = p.pixel(x,y); - switch (numcomponents) + QColor col = p.pixelColor(x,y); + switch (depth) { default: break; case 1: + { + QRgb rgb = col.rgb(); line[0] = qGray( rgb ); - break; + } break; case 2: + { + QRgb rgb = col.rgb(); line[0] = qGray( rgb ); line[1] = qAlpha( rgb ); - break; + } break; case 3: + { + QRgb rgb = col.rgb(); line[0] = qRed( rgb ); line[1] = qGreen( rgb ); line[2] = qBlue( rgb ); - break; + } break; case 4: + { + QRgb rgb = col.rgb(); line[0] = qRed( rgb ); line[1] = qGreen( rgb ); line[2] = qBlue( rgb ); line[3] = qAlpha( rgb ); - break; + } break; + case 8: + { + QRgba64 rgb = col.rgba64(); + line[0] = qRed( rgb ); + line[1] = qGreen( rgb ); + line[2] = qBlue( rgb ); + line[3] = qAlpha( rgb ); + } break; } line += numcomponents;