5#include <QtCore/QtEndian>
7#include <QtGui/private/qimage_p.h>
8#include <QtGui/private/qdrawhelper_p.h>
10#include <xcb/render.h>
11#include <xcb/xcb_renderutil.h>
18QImage::Format imageFormatForMasks(
int depth,
int bits_per_pixel,
int red_mask,
int blue_mask)
20 if (bits_per_pixel == 32) {
23 if (red_mask == 0xff0000 && blue_mask == 0xff)
25#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
26 if (red_mask == 0xff && blue_mask == 0xff0000)
29 if (
unsigned(red_mask) ==
unsigned(0xff000000) && blue_mask == 0xff00)
32 if (red_mask == 0x3ff && blue_mask == 0x3ff00000)
34 if (red_mask == 0x3ff00000 && blue_mask == 0x3ff)
38 if (red_mask == 0x3ff && blue_mask == 0x3ff00000)
40 if (blue_mask == 0x3ff && red_mask == 0x3ff00000)
44 if (red_mask == 0xff0000 && blue_mask == 0xff)
46#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
47 if (red_mask == 0xff && blue_mask == 0xff0000)
50 if (
unsigned(red_mask) ==
unsigned(0xff000000) && blue_mask == 0xff00)
55 }
else if (bits_per_pixel == 16) {
56 if (
depth == 16 && red_mask == 0xf800 && blue_mask == 0x1f)
58 if (
depth == 15 && red_mask == 0x7c00 && blue_mask == 0x1f)
74 *needsRgbSwap =
false;
78 if (visual->_class == XCB_VISUAL_CLASS_GRAY_SCALE) {
82#if QT_CONFIG(xcb_native_painting)
95 const bool connectionEndianSwap =
connection->imageNeedsEndianSwap();
97 const quint32 red_mask = connectionEndianSwap ?
qbswap(visual->red_mask) : visual->red_mask;
98 const quint32 blue_mask = connectionEndianSwap ?
qbswap(visual->blue_mask) : visual->blue_mask;
100 *imageFormat = imageFormatForMasks(
depth,
format->bits_per_pixel, red_mask, blue_mask);
105 *imageFormat = imageFormatForMasks(
depth,
format->bits_per_pixel, blue_mask, red_mask);
107 *needsRgbSwap =
true;
112 qWarning(
"Unsupported screen format: depth: %d, bits_per_pixel: %d, red_mask: %x, blue_mask: %x",
depth,
format->bits_per_pixel, red_mask, blue_mask);
119 const xcb_visualtype_t *visual)
121 xcb_connection_t *conn =
connection->xcb_connection();
129 uint8_t *
data = xcb_get_image_data(image_reply.get());
130 uint32_t
length = xcb_get_image_data_length(image_reply.get());
149 p += bytes_per_line / 4;
156 p += bytes_per_line / 4;
168 xcb_connection_t *conn =
screen->xcb_connection();
180 int destLineSize =
width / 8;
184 uint8_t *
buf =
new uint8_t[
height * destLineSize];
186 memcpy(
buf + (destLineSize *
i),
map + (bytesPerLine *
i), destLineSize);
187 xcb_pixmap_t pm = xcb_create_pixmap_from_bitmap_data(conn,
screen->root(),
buf,
196 xcb_connection_t *conn =
screen->xcb_connection();
197 const int w =
image.width();
198 const int h =
image.height();
201 qWarning(
"qt_xcb_createCursorXRender: query_pict_formats failed");
204 xcb_render_pictforminfo_t *
fmt = xcb_render_util_find_standard_format(
formats.get(),
205 XCB_PICT_STANDARD_ARGB_32);
207 qWarning(
"qt_xcb_createCursorXRender: Failed to find format PICT_STANDARD_ARGB_32");
212 xcb_image_t *xi = xcb_image_create(
w,
h, XCB_IMAGE_FORMAT_Z_PIXMAP,
215 XCB_IMAGE_ORDER_MSB_FIRST,
216 nullptr, 0,
nullptr);
218 qWarning(
"qt_xcb_createCursorXRender: xcb_image_create failed");
221 xi->data = (uint8_t *) malloc(xi->stride *
h);
223 qWarning(
"qt_xcb_createCursorXRender: Failed to malloc() image data");
224 xcb_image_destroy(xi);
227 memcpy(xi->data,
img.constBits(),
img.sizeInBytes());
229 xcb_pixmap_t
pix = xcb_generate_id(conn);
230 xcb_create_pixmap(conn, 32,
pix,
screen->root(),
w,
h);
232 xcb_render_picture_t pic = xcb_generate_id(conn);
233 xcb_render_create_picture(conn, pic,
pix,
fmt->id, 0,
nullptr);
235 xcb_gcontext_t gc = xcb_generate_id(conn);
236 xcb_create_gc(conn, gc,
pix, 0,
nullptr);
237 xcb_image_put(conn,
pix, gc, xi, 0, 0, 0);
238 xcb_free_gc(conn, gc);
240 xcb_cursor_t
cursor = xcb_generate_id(conn);
241 xcb_render_create_cursor(conn,
cursor, pic, spot.
x(), spot.
y());
244 xcb_image_destroy(xi);
245 xcb_render_free_picture(conn, pic);
246 xcb_free_pixmap(conn,
pix);
The QColor class provides colors based on RGB, HSV or CMYK values.
QRgb rgb() const noexcept
Returns the RGB value of the color.
Format
The following image formats are available in Qt.
@ Format_RGBA8888_Premultiplied
@ Format_A2BGR30_Premultiplied
@ Format_ARGB32_Premultiplied
@ Format_A2RGB30_Premultiplied
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
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.
\inmodule QtCore\reentrant
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
static QXcbIntegration * instance()
QMap< QString, QString > map
[6]
Combined button and popup list for selecting options.
DBusConnection * connection
constexpr T qbswap(T source)
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLenum GLsizei length
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
QVideoFrameFormat::PixelFormat fmt
#define Q_XCB_REPLY(call,...)
#define Q_XCB_REPLY_UNCHECKED(call,...)
xcb_pixmap_t qt_xcb_XPixmapFromBitmap(QXcbScreen *screen, const QImage &image)
QT_BEGIN_NAMESPACE bool qt_xcb_imageFormatForVisual(QXcbConnection *connection, uint8_t depth, const xcb_visualtype_t *visual, QImage::Format *imageFormat, bool *needsRgbSwap)
xcb_cursor_t qt_xcb_createCursorXRender(QXcbScreen *screen, const QImage &image, const QPoint &spot)
QPixmap qt_xcb_pixmapFromXPixmap(QXcbConnection *connection, xcb_pixmap_t pixmap, int width, int height, int depth, const xcb_visualtype_t *visual)