6#include <private/qpixmap_win_p.h>
7#include <qpa/qplatformpixmap.h>
11#include <QScopedArrayPointer>
19template <
typename Int>
22 return (
v +
Int(3)) & ~Int(3);
25#ifndef QT_NO_DEBUG_STREAM
30 d <<
"BITMAPINFOHEADER(" << bih.biWidth <<
'x' <<
qAbs(bih.biHeight)
31 << (bih.biHeight < 0 ?
", top-down" :
", bottom-up")
32 <<
", planes=" << bih.biPlanes <<
", bitCount=" << bih.biBitCount
33 <<
", compression=" << bih.biCompression <<
", size="
34 << bih.biSizeImage <<
')';
40 DWORD compression, DWORD bitCount,
41 BITMAPINFOHEADER *bih)
43 memset(bih, 0,
sizeof(BITMAPINFOHEADER));
44 bih->biSize =
sizeof(BITMAPINFOHEADER);
48 bih->biBitCount = WORD(bitCount);
49 bih->biCompression = compression;
51 const DWORD bytesPerLine =
pad4(DWORD(
width) * bitCount / 8);
52 bih->biSizeImage = bytesPerLine * DWORD(
height);
62template <
class BITMAPINFO_T>
64 DWORD compression, DWORD bitCount,
68 memset(bmi->bmiColors, 0,
sizeof(bmi->bmiColors));
78 qErrnoWarning(
"%s: GetDIBits() failed to get bitmap bits.", __FUNCTION__);
95 if ((pixel & 0xff000000) == 0 && (pixel & 0x00ffffff) != 0)
96 dest[
x] = pixel | 0xff000000;
98 dest[
x] = pixel |
mask;
107 const int lineSize = 3 *
width;
108 const int linePad =
pad4(lineSize) - lineSize;
111 for ( ;
p <
end;
p += 3)
112 std::swap(*
p, *(
p + 2));
136 int colorTableSize = 0;
147 if (colorTableSize) {
150 colorTable.
reserve(colorTableSize);
151 std::transform(colorTableIn, colorTableIn + colorTableSize,
153 image.setColorTable(colorTable);
156 switch (
header.biBitCount) {
183 operator HDC()
const {
return m_displayDc; }
186 const HDC m_displayDc;
201 const int bpl = ((
w+15)/16)*2;
204 for (
int y = 0;
y <
h; ++
y)
206 HBITMAP hbm = CreateBitmap(
w,
h, 1, 1,
bits.data());
217 switch (hbitmapFormat) {
234 DWORD compression = 0;
239 switch (
image.format()) {
246 compression = BI_RGB;
249 if (targetFormat !=
image.format())
255 compression = BI_RGB;
266 switch (
image.format()) {
283 const int w =
image.width();
284 const int h =
image.height();
288 BITMAPINFO &bmi =
reinterpret_cast<BITMAPINFO &
>(bmiColorTable256);
289 switch (
image.format()) {
292 std::transform(
image.colorTable().constBegin(),
image.colorTable().constEnd(),
301 const HBITMAP
bitmap = CreateDIBSection(
nullptr, &bmi, DIB_RGB_COLORS,
302 reinterpret_cast<void **
>(&
pixels),
nullptr, 0);
304 qErrnoWarning(
"%s, failed to create dibsection", __FUNCTION__);
308 qErrnoWarning(
"%s, did not allocate pixel data", __FUNCTION__);
311 memcpy(
pixels,
image.constBits(), bmi.bmiHeader.biSizeImage);
341HBITMAP QImage::toHBITMAP()
const
373 switch (
header.biBitCount) {
398 DIBSECTION dibSection;
399 memset(&dibSection, 0,
sizeof(dibSection));
400 dibSection.dsBmih.biSize =
sizeof(dibSection.dsBmih);
402 if (!GetObject(
bitmap,
sizeof(dibSection), &dibSection)
403 || !dibSection.dsBm.bmBits
404 || dibSection.dsBmih.biBitCount <= 8
405 || dibSection.dsBmih.biCompression != BI_RGB) {
413 return copyImageData(dibSection.dsBmih,
nullptr, dibSection.dsBm.bmBits, imageFormat);
420 BITMAPINFO &
info =
reinterpret_cast<BITMAPINFO &
>(bmiColorTable256);
422 info.bmiHeader.biSize =
sizeof(
info.bmiHeader);
425 if (!GetDIBits(displayDc,
bitmap, 0, 1, 0, &
info, DIB_RGB_COLORS)) {
426 qErrnoWarning(
"%s: GetDIBits() failed to query data.", __FUNCTION__);
430 if (
info.bmiHeader.biHeight > 0)
431 info.bmiHeader.biHeight = -
info.bmiHeader.biHeight;
432 info.bmiHeader.biCompression = BI_RGB;
433 size_t allocSize =
info.bmiHeader.biSizeImage;
435 info.bmiHeader.biBitCount = 32;
436 allocSize =
info.bmiHeader.biWidth *
qAbs(
info.bmiHeader.biHeight) * 4;
441 qWarning().nospace() << __FUNCTION__ <<
": unsupported image format:" <<
info.bmiHeader;
446 if (!GetDIBits(displayDc,
bitmap, 0,
qAbs(
info.bmiHeader.biHeight),
data.data(), &
info, DIB_RGB_COLORS)) {
447 qErrnoWarning(
"%s: GetDIBits() failed to get data.", __FUNCTION__);
480QImage QImage::fromHBITMAP(HBITMAP hbitmap)
505HICON QImage::toHICON(
const QImage &
mask)
const
508 qWarning(
"QImage::toHICON(): Mask must be empty or have format Format_Mono");
515 auto effectiveMask =
mask;
516 if (effectiveMask.isNull()) {
528 HICON hIcon = CreateIconIndirect(&ii);
530 DeleteObject(ii.hbmColor);
531 DeleteObject(ii.hbmMask);
542 return p.toImage().toHICON(
mask);
571 const int w =
image.width();
572 const int h =
image.height();
573 for (
int y = 0;
y <
h; ++
y) {
574 const QRgb *scanLine =
reinterpret_cast<const QRgb *
>(
image.scanLine(
y));
575 for (
int x = 0;
x <
w; ++
x) {
594 HDC screenDevice = GetDC(
nullptr);
595 HDC hdc = CreateCompatibleDC(screenDevice);
596 ReleaseDC(
nullptr, screenDevice);
599 const bool result = GetIconInfo(
icon, &iconinfo);
601 qErrnoWarning(
"QPixmap::fromWinHICON(), failed to GetIconInfo()");
606 const int w = int(iconinfo.xHotspot) * 2;
607 const int h = int(iconinfo.yHotspot) * 2;
609 BITMAPINFOHEADER bitmapInfo;
613 HBITMAP winBitmap = CreateDIBSection(hdc,
reinterpret_cast<BITMAPINFO *
>(&bitmapInfo),
614 DIB_RGB_COLORS,
reinterpret_cast<VOID **
>(&
bits),
616 HGDIOBJ oldhdc =
static_cast<HBITMAP
>(SelectObject(hdc, winBitmap));
617 DrawIconEx(hdc, 0, 0,
icon,
w,
h, 0,
nullptr, DI_NORMAL);
621 DrawIconEx( hdc, 0, 0,
icon,
w,
h, 0,
nullptr, DI_MASK);
624 for (
int y = 0 ;
y <
h ;
y++){
625 QRgb *scanlineImage =
reinterpret_cast<QRgb *
>(
image.scanLine(
y));
627 for (
int x = 0;
x <
w ;
x++){
628 if (scanlineMask &&
qRed(scanlineMask[
x]) != 0)
629 scanlineImage[
x] = 0;
631 scanlineImage[
x] |= 0xff000000;
636 DeleteObject(iconinfo.hbmMask);
637 DeleteObject(iconinfo.hbmColor);
639 SelectObject(hdc, oldhdc);
640 DeleteObject(winBitmap);
QSize size() const
Returns the size of the image, i.e.
int width() const
Returns the width of the image.
uchar * bits()
Returns a pointer to the first pixel data.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
int height() const
Returns the height of the image.
Format
The following image formats are available in Qt.
@ Format_ARGB32_Premultiplied
QImage() noexcept
Constructs a null image.
Format format() const
Returns the format of the image.
const uchar * constScanLine(int) const
Returns a pointer to the pixel data at the scanline with index i.
void invertPixels(InvertMode=InvertRgb)
Inverts all pixel values in the image.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
void reserve(qsizetype size)
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
QImage toImage() const
Converts the pixmap to a QImage.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
QBitmap mask() const
Returns true if this pixmap has an alpha channel, or has a mask, otherwise returns false.
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
static QString header(const QString &name)
constexpr T qAbs(const T &t)
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum const void * pixels
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
HBITMAP qt_imageToWinHBITMAP(const QImage &imageIn, int hbitmapFormat)
static void flipRgb3(uchar *p, int width, int height)
static bool hasAlpha(const QImage &image)
static QImage imageFromWinHBITMAP_GetDiBits(HBITMAP bitmap, bool forceQuads, int hbitmapFormat)
static QImage qt_imageFromWinIconHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h)
static void initBitMapInfoHeader(int width, int height, bool topToBottom, DWORD compression, DWORD bitCount, BITMAPINFOHEADER *bih)
static QT_BEGIN_NAMESPACE Int pad4(Int v)
QPixmap qt_pixmapFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat)
static HBITMAP qt_createIconMask(QImage bm)
static RGBQUAD qRgbToRgbQuad(QRgb qrgb)
static QImage::Format format32(int hbitmapFormat)
@ HBitmapPremultipliedAlpha
static QImage copyImageData(const BITMAPINFOHEADER &header, const RGBQUAD *colorTableIn, const void *data, QImage::Format format)
QPixmap qt_pixmapFromWinHICON(HICON icon)
static QImage::Format imageFromWinHBITMAP_Format(const BITMAPINFOHEADER &header, int hbitmapFormat)
QImage qt_imageFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat)
static QImage imageFromWinHBITMAP_DibSection(HBITMAP bitmap, int hbitmapFormat)
HICON qt_pixmapToWinHICON(const QPixmap &p)
HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat)
QDebug operator<<(QDebug d, const BITMAPINFOHEADER &bih)
static uchar * getDiBits(HDC hdc, HBITMAP bitmap, int width, int height, bool topToBottom=true)
static void copyImageDataCreateAlpha(const uchar *data, QImage *target)
static QRgb rgbQuadToQRgb(RGBQUAD quad)
static void initBitMapInfo(int width, int height, bool topToBottom, DWORD compression, DWORD bitCount, BITMAPINFO_T *bmi)
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr int qBlue(QRgb rgb)
constexpr int qAlpha(QRgb rgb)
static const struct TessellationModeTab quad[]
static QWindowsDirect2DPlatformPixmap * platformPixmap(QPixmap *p)
QFileInfo info(fileName)
[8]
RGBQUAD bmiColors[Indexed8ColorTableSize]
BITMAPINFOHEADER bmiHeader