Qt 4.8
Classes | Macros | Functions | Variables
qpixmap_x11.cpp File Reference
#include "qplatformdefs.h"
#include "qdebug.h"
#include "qiodevice.h"
#include "qpixmap_x11_p.h"
#include "qbitmap.h"
#include "qcolormap.h"
#include "qimage.h"
#include "qmatrix.h"
#include "qapplication.h"
#include <private/qpaintengine_x11_p.h>
#include <private/qt_x11_p.h>
#include "qx11info_x11.h"
#include <private/qdrawhelper_p.h>
#include <private/qimage_p.h>
#include <private/qimagepixmapcleanuphooks_p.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

struct  QX11AlphaDetector
 
struct  QXImageWrapper
 

Macros

#define CYCLE(body)
 
#define GET_PIXEL
 
#define GET_PIXEL_DITHER_TC
 
#define GET_PIXEL_DITHER_TC_OPT(red_shift, green_shift, blue_shift, red_mask, green_mask, blue_mask, rbits, gbits, bbits)
 

Functions

static void build_scale_table (uint **table, uint nBits)
 
static void cleanup_scale_tables ()
 
static int highest_bit (uint v)
 
static int lowest_bit (uint v)
 
static uint n_bits (uint v)
 
static void qSafeXDestroyImage (XImage *x)
 
const ucharqt_get_bitflip_array ()
 
static XRenderPictFormat * qt_renderformat_for_depth (const QX11Info &xinfo, int depth)
 
QPixmap qt_toX11Pixmap (const QImage &image)
 
QPixmap qt_toX11Pixmap (const QPixmap &pixmap)
 

Variables

static uintblue_scale_table = 0
 
static int defaultScreen = -1
 
static uintgreen_scale_table = 0
 
QBasicAtomicInt qt_pixmap_serial = Q_BASIC_ATOMIC_INITIALIZER(0)
 
int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth = 0
 
static uintred_scale_table = 0
 

Macro Definition Documentation

◆ CYCLE

#define CYCLE (   body)
Value:
for (int y=0; y<h; y++) { \
const uchar* src = cimage.scanLine(y); \
uchar* dst = newbits + xi->bytes_per_line*y; \
const QRgb* p = (const QRgb *)src; \
body \
}
unsigned int QRgb
Definition: qrgb.h:53
unsigned char uchar
Definition: qglobal.h:994

Referenced by QX11PixmapData::fromImage().

◆ GET_PIXEL

#define GET_PIXEL
Value:
uint pixel; \
if (d8) pixel = pix[*src++]; \
else { \
int r = qRed (*p); \
int g = qGreen(*p); \
int b = qBlue (*p++); \
r = red_shift > 0 \
? r << red_shift : r >> -red_shift; \
g = green_shift > 0 \
? g << green_shift : g >> -green_shift; \
b = blue_shift > 0 \
? b << blue_shift : b >> -blue_shift; \
pixel = (r & red_mask)|(g & green_mask) | (b & blue_mask) \
| ~(blue_mask | green_mask | red_mask); \
}
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
unsigned int uint
Definition: qglobal.h:996
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63

Referenced by QX11PixmapData::fromImage().

◆ GET_PIXEL_DITHER_TC

#define GET_PIXEL_DITHER_TC
Value:
int r = qRed (*p); \
int g = qGreen(*p); \
int b = qBlue (*p++); \
const int thres = D[x%16][y%16]; \
if (r <= (255-(1<<(8-rbits))) && ((r<<rbits) & 255) \
> thres) \
r += (1<<(8-rbits)); \
if (g <= (255-(1<<(8-gbits))) && ((g<<gbits) & 255) \
> thres) \
g += (1<<(8-gbits)); \
if (b <= (255-(1<<(8-bbits))) && ((b<<bbits) & 255) \
> thres) \
b += (1<<(8-bbits)); \
r = red_shift > 0 \
? r << red_shift : r >> -red_shift; \
g = green_shift > 0 \
? g << green_shift : g >> -green_shift; \
b = blue_shift > 0 \
? b << blue_shift : b >> -blue_shift; \
uint pixel = (r & red_mask)|(g & green_mask) | (b & blue_mask);
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
#define D(arg)
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63

Referenced by QX11PixmapData::fromImage().

◆ GET_PIXEL_DITHER_TC_OPT

#define GET_PIXEL_DITHER_TC_OPT (   red_shift,
  green_shift,
  blue_shift,
  red_mask,
  green_mask,
  blue_mask,
  rbits,
  gbits,
  bbits 
)
Value:
const int thres = D[x%16][y%16]; \
int r = qRed (*p); \
if (r <= (255-(1<<(8-rbits))) && ((r<<rbits) & 255) \
> thres) \
r += (1<<(8-rbits)); \
int g = qGreen(*p); \
if (g <= (255-(1<<(8-gbits))) && ((g<<gbits) & 255) \
> thres) \
g += (1<<(8-gbits)); \
int b = qBlue (*p++); \
if (b <= (255-(1<<(8-bbits))) && ((b<<bbits) & 255) \
> thres) \
b += (1<<(8-bbits)); \
uint pixel = ((r red_shift) & red_mask) \
| ((g green_shift) & green_mask) \
| ((b blue_shift) & blue_mask);
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
#define D(arg)
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
Definition: qrgb.h:60
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
Definition: qrgb.h:63

Referenced by QX11PixmapData::fromImage().

Function Documentation

◆ build_scale_table()

static void build_scale_table ( uint **  table,
uint  nBits 
)
static

Definition at line 286 of file qpixmap_x11.cpp.

Referenced by QX11PixmapData::toImage().

287 {
288  if (nBits > 7) {
289  qWarning("build_scale_table: internal error, nBits = %i", nBits);
290  return;
291  }
292  if (!*table) {
293  static bool firstTable = true;
294  if (firstTable) {
296  firstTable = false;
297  }
298  *table = new uint[256];
299  }
300  int maxVal = (1 << nBits) - 1;
301  int valShift = 8 - nBits;
302  int i;
303  for(i = 0 ; i < maxVal + 1 ; i++)
304  (*table)[i << valShift] = i*255/maxVal;
305 }
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
void qAddPostRoutine(QtCleanUpFunction ptr)
Adds a global routine that will be called from the QApplication destructor.
static void cleanup_scale_tables()

◆ cleanup_scale_tables()

static void cleanup_scale_tables ( )
static

Definition at line 275 of file qpixmap_x11.cpp.

Referenced by build_scale_table().

276 {
277  delete[] red_scale_table;
278  delete[] green_scale_table;
279  delete[] blue_scale_table;
280 }
static uint * blue_scale_table
static uint * green_scale_table
static uint * red_scale_table

◆ highest_bit()

static int highest_bit ( uint  v)
static

Definition at line 241 of file qpixmap_x11.cpp.

Referenced by QX11PixmapData::fromImage(), and QX11PixmapData::toImage().

242 {
243  int i;
244  uint b = (uint)1 << 31;
245  for (i=31; ((b & v) == 0) && i>=0; i--)
246  b >>= 1;
247  return i;
248 }
unsigned int uint
Definition: qglobal.h:996

◆ lowest_bit()

static int lowest_bit ( uint  v)
static

Definition at line 251 of file qpixmap_x11.cpp.

Referenced by QX11PixmapData::fromImage().

252 {
253  int i;
254  ulong lb;
255  lb = 1;
256  for (i=0; ((v & lb) == 0) && i<32; i++, lb<<=1) {}
257  return i==32 ? -1 : i;
258 }
unsigned long ulong
Definition: qglobal.h:997

◆ n_bits()

static uint n_bits ( uint  v)
static

Definition at line 261 of file qpixmap_x11.cpp.

Referenced by QX11PixmapData::fromImage(), and QX11PixmapData::toImage().

262 {
263  int i = 0;
264  while (v) {
265  v = v & (v - 1);
266  i++;
267  }
268  return i;
269 }

◆ qSafeXDestroyImage()

static void qSafeXDestroyImage ( XImage *  x)
inlinestatic

Definition at line 107 of file qpixmap_x11.cpp.

Referenced by QX11PixmapData::bitmap_to_mask(), QX11PixmapData::fromImage(), QX11PixmapData::toImage(), and QX11PixmapData::transformed().

108 {
109  if (x->data) {
110  free(x->data);
111  x->data = 0;
112  }
113  XDestroyImage(x);
114 }

◆ qt_get_bitflip_array()

const uchar* qt_get_bitflip_array ( )

Definition at line 765 of file qimage.cpp.

Referenced by QX11PixmapData::bitmap_to_mask().

766 {
767  return bitflip;
768 }
static const uchar bitflip[256]
Definition: qimage.cpp:736

◆ qt_renderformat_for_depth()

static XRenderPictFormat* qt_renderformat_for_depth ( const QX11Info xinfo,
int  depth 
)
static

Definition at line 2189 of file qpixmap_x11.cpp.

Referenced by QX11PixmapData::convertToARGB32(), and QX11PixmapData::paintEngine().

2190 {
2191  if (depth == 1)
2192  return XRenderFindStandardFormat(X11->display, PictStandardA1);
2193  else if (depth == 32)
2194  return XRenderFindStandardFormat(X11->display, PictStandardARGB32);
2195  else
2196  return XRenderFindVisualFormat(X11->display, (Visual *)xinfo.visual());
2197 }
#define X11
Definition: qt_x11_p.h:724
void * visual() const
Returns the current visual.

◆ qt_toX11Pixmap() [1/2]

QPixmap qt_toX11Pixmap ( const QImage image)

Definition at line 81 of file qpixmap_x11.cpp.

Referenced by QWidgetPrivate::mapFromGlobal(), QCursor::QCursor(), qstring_to_xtp(), qt_toX11Pixmap(), and QX11PixmapData::transformed().

82 {
83  QPixmapData *data =
84  new QX11PixmapData(image.depth() == 1
87 
88  data->fromImage(image, Qt::AutoColor);
89 
90  return QPixmap(data);
91 }
virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags)=0
static const char * data(const QByteArray &arr)
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ qt_toX11Pixmap() [2/2]

QPixmap qt_toX11Pixmap ( const QPixmap pixmap)

Definition at line 93 of file qpixmap_x11.cpp.

Referenced by QX11PaintEngine::drawPixmap(), and QX11PaintEngine::updateBrush().

94 {
95  if (pixmap.isNull())
96  return QPixmap();
97 
98  if (QPixmap(pixmap).data_ptr()->classId() == QPixmapData::X11Class)
99  return pixmap;
100 
101  return qt_toX11Pixmap(pixmap.toImage());
102 }
DataPtr & data_ptr()
Definition: qpixmap.h:297
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
QPixmap qt_toX11Pixmap(const QImage &image)
Definition: qpixmap_x11.cpp:81
ClassId classId() const
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

Variable Documentation

◆ blue_scale_table

uint* blue_scale_table = 0
static

Definition at line 273 of file qpixmap_x11.cpp.

Referenced by cleanup_scale_tables(), and QX11PixmapData::toImage().

◆ defaultScreen

int defaultScreen = -1
static

◆ green_scale_table

uint* green_scale_table = 0
static

Definition at line 272 of file qpixmap_x11.cpp.

Referenced by cleanup_scale_tables(), and QX11PixmapData::toImage().

◆ qt_pixmap_serial

Definition at line 313 of file qpixmap_x11.cpp.

◆ qt_x11_preferred_pixmap_depth

int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth = 0

Definition at line 314 of file qpixmap_x11.cpp.

Referenced by QX11PixmapData::fromImage(), and QX11PixmapData::resize().

◆ red_scale_table

uint* red_scale_table = 0
static

Definition at line 271 of file qpixmap_x11.cpp.

Referenced by cleanup_scale_tables(), and QX11PixmapData::toImage().