Skip to content

Commit

Permalink
Gui: Support of converting 64-bit images
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 28, 2024
1 parent 6860aab commit 9762098
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/Gui/BitmapFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,22 +539,33 @@ void BitmapFactoryInst::convert(const QImage& p, SoSFImage& img) const
QVector<QRgb> 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);

Expand All @@ -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;
Expand Down

0 comments on commit 9762098

Please sign in to comment.