summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-02-22 12:09:48 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-02-22 15:27:26 +0000
commit7c5d5ab0d6ab20f0052dedddcd7df5eb1d5eaa3d (patch)
tree88b69f0965a15a6c197b6be422ecc1f38c7ee41e
parent1ce49a21e5991821f258f3cfe124ba7a987c29ad (diff)
Remove duplicated image conversion functions.
Replace qaxPixmapToWinHBITMAP(), qaxPixmapFromWinHBITMAP() by qt_pixmapToWinHBITMAP(), qt_pixmapFromWinHBITMAP() from QtGui. The code was duplicated in ActiveQt in the early days of Qt 5 when the image conversion functions were in the QPA plugin. They were later moved back to QtGui. Change-Id: I911ba543b27b9392d143e5dfab260def4241f477 Reviewed-by: Andy Shaw <andy.shaw@theqtcompany.com>
-rw-r--r--src/activeqt/container/qaxwidget.cpp6
-rw-r--r--src/activeqt/control/qaxserverbase.cpp4
-rw-r--r--src/activeqt/shared/qaxtypes.cpp7
-rw-r--r--src/activeqt/shared/qaxutils.cpp122
-rw-r--r--src/activeqt/shared/qaxutils_p.h9
5 files changed, 12 insertions, 136 deletions
diff --git a/src/activeqt/container/qaxwidget.cpp b/src/activeqt/container/qaxwidget.cpp
index 4da3871..631a01d 100644
--- a/src/activeqt/container/qaxwidget.cpp
+++ b/src/activeqt/container/qaxwidget.cpp
@@ -1779,6 +1779,8 @@ void QAxHostWidget::focusOutEvent(QFocusEvent *e)
axhost->m_spInPlaceObject->UIDeactivate();
}
+Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0);
+Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat = 0);
void QAxHostWidget::paintEvent(QPaintEvent*)
{
@@ -1797,7 +1799,7 @@ void QAxHostWidget::paintEvent(QPaintEvent*)
QPixmap pm(qaxNativeWidgetSize(this));
pm.fill();
- HBITMAP hBmp = qaxPixmapToWinHBITMAP(pm);
+ HBITMAP hBmp = qt_pixmapToWinHBITMAP(pm);
HDC hBmp_hdc = CreateCompatibleDC(qt_win_display_dc());
HGDIOBJ old_hBmp = SelectObject(hBmp_hdc, hBmp);
@@ -1811,7 +1813,7 @@ void QAxHostWidget::paintEvent(QPaintEvent*)
view->Release();
QPainter painter(this);
- QPixmap pixmap = qaxPixmapFromWinHBITMAP(hBmp);
+ QPixmap pixmap = qt_pixmapFromWinHBITMAP(hBmp);
pixmap.setDevicePixelRatio(devicePixelRatioF());
painter.drawPixmap(0, 0, pixmap);
diff --git a/src/activeqt/control/qaxserverbase.cpp b/src/activeqt/control/qaxserverbase.cpp
index d6af214..b131e76 100644
--- a/src/activeqt/control/qaxserverbase.cpp
+++ b/src/activeqt/control/qaxserverbase.cpp
@@ -3097,6 +3097,8 @@ HRESULT WINAPI QAxServerBase::Save(LPCOLESTR fileName, BOOL fRemember)
return E_FAIL;
}
+Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0);
+
//**** IViewObject
/*
Draws the widget into the provided device context.
@@ -3135,7 +3137,7 @@ HRESULT WINAPI QAxServerBase::Draw(DWORD dwAspect, LONG /* lindex */, void * /*
::LPtoDP(hicTargetDev, (LPPOINT)&rc, 2);
const QPixmap pm = qt.widget->grab();
- HBITMAP hbm = qaxPixmapToWinHBITMAP(pm);
+ HBITMAP hbm = qt_pixmapToWinHBITMAP(pm);
HDC hdc = CreateCompatibleDC(0);
SelectObject(hdc, hbm);
::StretchBlt(hdcDraw, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hdc, 0, 0,pm.width(), pm.height(), SRCCOPY);
diff --git a/src/activeqt/shared/qaxtypes.cpp b/src/activeqt/shared/qaxtypes.cpp
index ba11ac2..df3b655 100644
--- a/src/activeqt/shared/qaxtypes.cpp
+++ b/src/activeqt/shared/qaxtypes.cpp
@@ -128,6 +128,9 @@ static QFont IFontToQFont(IFont *f)
return font;
}
+Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0);
+Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat = 0);
+
static IPictureDisp *QPixmapToIPicture(const QPixmap &pixmap)
{
IPictureDisp *pic = 0;
@@ -140,7 +143,7 @@ static IPictureDisp *QPixmapToIPicture(const QPixmap &pixmap)
desc.bmp.hpal = 0;
if (!pixmap.isNull()) {
- desc.bmp.hbitmap = qaxPixmapToWinHBITMAP(pixmap);
+ desc.bmp.hbitmap = qt_pixmapToWinHBITMAP(pixmap);
Q_ASSERT(desc.bmp.hbitmap);
}
@@ -167,7 +170,7 @@ static QPixmap IPictureToQPixmap(IPicture *ipic)
if (!hbm)
return QPixmap();
- return qaxPixmapFromWinHBITMAP(hbm);
+ return qt_pixmapFromWinHBITMAP(hbm);
}
static QDateTime DATEToQDateTime(DATE ole)
diff --git a/src/activeqt/shared/qaxutils.cpp b/src/activeqt/shared/qaxutils.cpp
index 7c7e967..51c0a1b 100644
--- a/src/activeqt/shared/qaxutils.cpp
+++ b/src/activeqt/shared/qaxutils.cpp
@@ -72,128 +72,6 @@ HWND hwndForWidget(QWidget *widget)
return 0;
}
-// Code courtesy of the Windows platform plugin (see pixmaputils.cpp/h).
-HBITMAP qaxPixmapToWinHBITMAP(const QPixmap &p, HBitmapFormat format)
-{
- if (p.isNull())
- return 0;
-
- HBITMAP bitmap = 0;
- if (p.handle()->classId() != QPlatformPixmap::RasterClass) {
- QRasterPlatformPixmap *data = new QRasterPlatformPixmap(p.depth() == 1 ?
- QRasterPlatformPixmap::BitmapType : QRasterPlatformPixmap::PixmapType);
- data->fromImage(p.toImage(), Qt::AutoColor);
- return qaxPixmapToWinHBITMAP(QPixmap(data), format);
- }
-
- QRasterPlatformPixmap *d = static_cast<QRasterPlatformPixmap*>(p.handle());
- const QImage *rasterImage = d->buffer();
- const int w = rasterImage->width();
- const int h = rasterImage->height();
-
- HDC display_dc = GetDC(0);
-
- // Define the header
- BITMAPINFO bmi;
- memset(&bmi, 0, sizeof(bmi));
- bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = w;
- bmi.bmiHeader.biHeight = -h;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = 32;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biSizeImage = w * h * 4;
-
- // Create the pixmap
- uchar *pixels = 0;
- bitmap = CreateDIBSection(display_dc, &bmi, DIB_RGB_COLORS, (void **) &pixels, 0, 0);
- ReleaseDC(0, display_dc);
- if (!bitmap) {
- qErrnoWarning("%s, failed to create dibsection", __FUNCTION__);
- return 0;
- }
- if (!pixels) {
- qErrnoWarning("%s, did not allocate pixel data", __FUNCTION__);
- return 0;
- }
-
- // Copy over the data
- QImage::Format imageFormat = QImage::Format_ARGB32;
- if (format == HBitmapAlpha)
- imageFormat = QImage::Format_RGB32;
- else if (format == HBitmapPremultipliedAlpha)
- imageFormat = QImage::Format_ARGB32_Premultiplied;
- const QImage image = rasterImage->convertToFormat(imageFormat);
- const int bytes_per_line = w * 4;
- for (int y=0; y < h; ++y)
- memcpy(pixels + y * bytes_per_line, image.scanLine(y), bytes_per_line);
-
- return bitmap;
-}
-
-QPixmap qaxPixmapFromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
-{
- // Verify size
- BITMAP bitmap_info;
- memset(&bitmap_info, 0, sizeof(BITMAP));
-
- const int res = GetObject(bitmap, sizeof(BITMAP), &bitmap_info);
- if (!res) {
- qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info");
- return QPixmap();
- }
- const int w = bitmap_info.bmWidth;
- const int h = bitmap_info.bmHeight;
-
- BITMAPINFO bmi;
- memset(&bmi, 0, sizeof(bmi));
- bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = w;
- bmi.bmiHeader.biHeight = -h;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = 32;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biSizeImage = w * h * 4;
-
- // Get bitmap bits
- QScopedArrayPointer<uchar> data(new uchar[bmi.bmiHeader.biSizeImage]);
- HDC display_dc = GetDC(0);
- if (!GetDIBits(display_dc, bitmap, 0, h, data.data(), &bmi, DIB_RGB_COLORS)) {
- ReleaseDC(0, display_dc);
- qWarning("%s, failed to get bitmap bits", __FUNCTION__);
- return QPixmap();
- }
-
- QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied;
- uint mask = 0;
- if (format == HBitmapNoAlpha) {
- imageFormat = QImage::Format_RGB32;
- mask = 0xff000000;
- }
-
- // Create image and copy data into image.
- QImage image(w, h, imageFormat);
- if (image.isNull()) { // failed to alloc?
- ReleaseDC(0, display_dc);
- qWarning("%s, failed create image of %dx%d", __FUNCTION__, w, h);
- return QPixmap();
- }
- const int bytes_per_line = w * sizeof(QRgb);
- for (int y = 0; y < h; ++y) {
- QRgb *dest = (QRgb *) image.scanLine(y);
- const QRgb *src = (const QRgb *) (data.data() + y * bytes_per_line);
- for (int x = 0; x < w; ++x) {
- const uint pixel = src[x];
- if ((pixel & 0xff000000) == 0 && (pixel & 0x00ffffff) != 0)
- dest[x] = pixel | 0xff000000;
- else
- dest[x] = pixel | mask;
- }
- }
- ReleaseDC(0, display_dc);
- return QPixmap::fromImage(image);
-}
-
// Code courtesy of QWindowsXPStyle
static void addRectToHrgn(HRGN &winRegion, const QRect &r)
{
diff --git a/src/activeqt/shared/qaxutils_p.h b/src/activeqt/shared/qaxutils_p.h
index f2576c1..bb73c16 100644
--- a/src/activeqt/shared/qaxutils_p.h
+++ b/src/activeqt/shared/qaxutils_p.h
@@ -65,16 +65,7 @@ class QRect;
class QRegion;
class QWindow;
-enum HBitmapFormat
-{
- HBitmapNoAlpha,
- HBitmapPremultipliedAlpha,
- HBitmapAlpha
-};
-
HWND hwndForWidget(QWidget *widget);
-HBITMAP qaxPixmapToWinHBITMAP(const QPixmap &p, HBitmapFormat format = HBitmapNoAlpha);
-QPixmap qaxPixmapFromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format = HBitmapNoAlpha);
HRGN qaxHrgnFromQRegion(QRegion region, const QWindow *window);
typedef QPair<qreal, qreal> QDpi;