Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsnativeimage.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtGui/private/qpaintengine_p.h>
7#include <QtGui/private/qpaintengine_raster_p.h>
8
10
11typedef struct {
12 BITMAPINFOHEADER bmiHeader;
13 DWORD redMask;
14 DWORD greenMask;
15 DWORD blueMask;
17
29static inline HDC createDC()
30{
31 HDC display_dc = GetDC(0);
32 HDC hdc = CreateCompatibleDC(display_dc);
33 ReleaseDC(0, display_dc);
34 Q_ASSERT(hdc);
35 return hdc;
36}
37
38static inline HBITMAP createDIB(HDC hdc, int width, int height,
40 uchar **bitsIn)
41{
43 memset(&bmi, 0, sizeof(bmi));
44 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
45 bmi.bmiHeader.biWidth = width;
46 bmi.bmiHeader.biHeight = -height; // top-down.
47 bmi.bmiHeader.biPlanes = 1;
48 bmi.bmiHeader.biSizeImage = 0;
49
51 bmi.bmiHeader.biBitCount = 16;
52 bmi.bmiHeader.biCompression = BI_BITFIELDS;
53 bmi.redMask = 0xF800;
54 bmi.greenMask = 0x07E0;
55 bmi.blueMask = 0x001F;
56 } else {
57 bmi.bmiHeader.biBitCount = 32;
58 bmi.bmiHeader.biCompression = BI_RGB;
59 bmi.redMask = 0;
60 bmi.greenMask = 0;
61 bmi.blueMask = 0;
62 }
63
64 uchar *bits = nullptr;
65 HBITMAP bitmap = CreateDIBSection(hdc, reinterpret_cast<BITMAPINFO *>(&bmi),
66 DIB_RGB_COLORS, reinterpret_cast<void **>(&bits), 0, 0);
67 if (Q_UNLIKELY(!bitmap || !bits)) {
68 qFatal("%s: CreateDIBSection failed (%dx%d, format: %d)", __FUNCTION__,
69 width, height, int(format));
70 }
71
72 *bitsIn = bits;
73 return bitmap;
74}
75
78 m_hdc(createDC())
79{
80 if (width != 0 && height != 0) {
81 uchar *bits;
82 m_bitmap = createDIB(m_hdc, width, height, format, &bits);
83 m_null_bitmap = static_cast<HBITMAP>(SelectObject(m_hdc, m_bitmap));
84 m_image = QImage(bits, width, height, format);
86 static_cast<QRasterPaintEngine *>(m_image.paintEngine())->setDC(m_hdc);
87 } else {
88 m_image = QImage(width, height, format);
89 }
90
91 GdiFlush();
92}
93
95{
96 if (m_hdc) {
97 if (m_bitmap) {
98 if (m_null_bitmap)
99 SelectObject(m_hdc, m_null_bitmap);
100 DeleteObject(m_bitmap);
101 }
102 DeleteDC(m_hdc);
103 }
104}
105
107{
108 static int depth = -1;
109 if (depth == -1) {
110 if (HDC defaultDC = GetDC(0)) {
111 depth = GetDeviceCaps(defaultDC, BITSPIXEL);
112 ReleaseDC(0, defaultDC);
113 } else {
114 // FIXME Same remark as in QWindowsFontDatabase::defaultVerticalDPI()
115 // BONUS FIXME: Is 32 too generous/optimistic?
116 depth = 32;
117 }
118 }
120}
121
\inmodule QtGui
Definition qimage.h:37
QPaintEngine * paintEngine() const override
Definition qimage.cpp:4255
Format
The following image formats are available in Qt.
Definition qimage.h:41
@ Format_RGB32
Definition qimage.h:46
@ Format_RGB16
Definition qimage.h:49
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
static QImage::Format systemFormat()
QWindowsNativeImage(int width, int height, QImage::Format format)
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
#define qFatal
Definition qlogging.h:168
GLint GLenum GLsizei GLsizei GLsizei depth
GLint GLsizei GLsizei height
GLint GLsizei width
GLint GLsizei GLsizei GLenum format
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
unsigned char uchar
Definition qtypes.h:32
static HDC createDC()
static HBITMAP createDIB(HDC hdc, int width, int height, QImage::Format format, uchar **bitsIn)
BITMAPINFOHEADER bmiHeader