summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qbmphandler.cpp
diff options
context:
space:
mode:
authorCamille Viot <viot.camille@outlook.com>2020-11-30 18:30:56 +0100
committerCamille Viot <viot.camille@outlook.com>2021-01-06 21:53:44 +0100
commit8fa91c75ad0cb0b1905c6775b62f734bc610fb60 (patch)
tree6135be5f6453cc115c4ba319161d52a0d3c445c4 /src/gui/image/qbmphandler.cpp
parente7370d0583ea8a50b0d5c15bb2b1afee2efc6a7e (diff)
Clean up code that handle clipboard image conversion on Windows
This commit remove old legacy code that try to deal with clipboard image conversion in the qwindowsmime class. It now uses qbmphandler under the hood which is much more complete. It also add a small fix for the conversion of BI_RGB clipboard image with an explicit alpha layer (which Firefox use on Windows). Change-Id: Iae026378831799dc676e1aba7d5bd6a0d1c01e7f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/image/qbmphandler.cpp')
-rw-r--r--src/gui/image/qbmphandler.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/gui/image/qbmphandler.cpp b/src/gui/image/qbmphandler.cpp
index 74df9820e4..6d265ded67 100644
--- a/src/gui/image/qbmphandler.cpp
+++ b/src/gui/image/qbmphandler.cpp
@@ -147,6 +147,26 @@ static QDataStream &operator<<(QDataStream &s, const BMP_INFOHDR &bi)
s << bi.biSizeImage;
s << bi.biXPelsPerMeter << bi.biYPelsPerMeter;
s << bi.biClrUsed << bi.biClrImportant;
+
+ if (bi.biSize >= BMP_WIN4) {
+ s << bi.biRedMask << bi.biGreenMask << bi.biBlueMask << bi.biAlphaMask;
+ s << bi.biCSType;
+
+ for (int i = 0; i < 9; i++)
+ s << bi.biEndpoints[i];
+
+ s << bi.biGammaRed;
+ s << bi.biGammaGreen;
+ s << bi.biGammaBlue;
+ }
+
+ if (bi.biSize >= BMP_WIN5) {
+ s << bi.biIntent;
+ s << bi.biProfileData;
+ s << bi.biProfileSize;
+ s << bi.biReserved;
+ }
+
return s;
}
@@ -248,7 +268,9 @@ static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, qint64 offset,
return false;
}
- bool transp = (comp == BMP_BITFIELDS) && alpha_mask;
+ bool transp = comp == BMP_BITFIELDS || (comp == BMP_RGB && nbits == 32 && alpha_mask == 0xff000000);
+ transp = transp && alpha_mask;
+
int ncols = 0;
int depth = 0;
QImage::Format format;
@@ -320,6 +342,12 @@ static bool read_dib_body(QDataStream &s, const BMP_INFOHDR &bi, qint64 offset,
green_shift = 8;
red_shift = 16;
blue_scale = green_scale = red_scale = 1;
+ if (transp) {
+ alpha_shift = calc_shift(alpha_mask);
+ if (((alpha_mask >> alpha_shift) + 1) == 0)
+ return false;
+ alpha_scale = 256 / ((alpha_mask >> alpha_shift) + 1);
+ }
} else if (comp == BMP_RGB && nbits == 16) {
blue_mask = 0x001f;
green_mask = 0x03e0;