Qt 4.8
Classes | Macros | Typedefs | Functions | Variables
qimage.cpp File Reference
#include "qimage.h"
#include "qdatastream.h"
#include "qbuffer.h"
#include "qmap.h"
#include "qmatrix.h"
#include "qtransform.h"
#include "qimagereader.h"
#include "qimagewriter.h"
#include "qstringlist.h"
#include "qvariant.h"
#include "qimagepixmapcleanuphooks_p.h"
#include <ctype.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <private/qdrawhelper_p.h>
#include <private/qmemrotate_p.h>
#include <private/qpixmapdata_p.h>
#include <private/qimagescale_p.h>
#include <private/qsimd_p.h>
#include <qhash.h>
#include <private/qpaintengine_raster_p.h>
#include <private/qimage_p.h>
#include <private/qfont_p.h>

Go to the source code of this file.

Classes

struct  QRgbMap
 

Macros

#define CONVERT_DECL(DST, SRC)
 
#define CONVERT_PTR(DST, SRC)   convert_##SRC##_to_##DST
 
#define DITHER(p, m)   ((uchar) ((p * (m) + 127) / 255))
 
#define DITHER(p, d, m)   ((uchar) ((((256 * (m) + (m) + 1)) * (p) + (d)) >> 16))
 
#define INDEXOF(r, g, b)   (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b))
 
#define IWX_LSB(b)
 
#define IWX_MSB(b)
 
#define IWX_PIX(b)
 
#define MAX_B   5
 
#define MAX_G   5
 
#define MAX_R   5
 
#define PIX(x, y)   (*((QRgb*)scanLine(y)+x) & 0x00ffffff)
 
#define QIMAGE_SANITYCHECK_MEMORY(image)
 

Typedefs

typedef void(* Image_Converter) (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
 
typedef bool(* InPlace_Image_Converter) (QImageData *data, Qt::ImageConversionFlags)
 

Functions

static bool checkPixelSize (const QImage::Format format)
 
static int closestMatch (QRgb pixel, const QVector< QRgb > &clut)
 
static void convert_ARGB_PM_to_ARGB (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
 
static void convert_ARGB_PM_to_Indexed8 (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
 
static void convert_ARGB_PM_to_Mono (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
 
static void convert_ARGB_PM_to_RGB (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
 
static void convert_ARGB_to_ARGB_PM (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
 
static bool convert_ARGB_to_ARGB_PM_inplace (QImageData *data, Qt::ImageConversionFlags)
 
static void convert_ARGB_to_Indexed8 (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
 
static bool convert_indexed8_to_ARGB_PM_inplace (QImageData *data, Qt::ImageConversionFlags)
 
static bool convert_indexed8_to_RGB16_inplace (QImageData *data, Qt::ImageConversionFlags)
 
static bool convert_indexed8_to_RGB_inplace (QImageData *data, Qt::ImageConversionFlags)
 
static void convert_Indexed8_to_X32 (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
 
static void convert_Mono_to_Indexed8 (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
 
static void convert_Mono_to_X32 (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
 
static void convert_RGB_to_Indexed8 (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
 
static bool convert_RGB_to_RGB16_inplace (QImageData *data, Qt::ImageConversionFlags)
 
static void convert_X_to_Mono (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
 
static QImage convertWithPalette (const QImage &src, QImage::Format format, const QVector< QRgb > &clut)
 
static void dither_to_Mono (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags, bool fromalpha)
 
static QVector< QRgbfix_color_table (const QVector< QRgb > &ctbl, QImage::Format format)
 
static void mask_alpha_converter (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
 
QDataStreamoperator<< (QDataStream &s, const QImage &image)
 
QDataStreamoperator>> (QDataStream &s, QImage &image)
 
static int pixel_distance (QRgb p1, QRgb p2)
 
void qGamma_correct_back_to_linear_cs (QImage *image)
 
void qInitImageConversions ()
 
const ucharqt_get_bitflip_array ()
 
const QVector< QRgb > * qt_image_colortable (const QImage &image)
 
Q_GUI_EXPORT qint64 qt_image_id (const QImage &image)
 
bool qt_read_xpm_image_or_array (QIODevice *device, const char *const *source, QImage &image)
 
bool qt_xForm_helper (const QTransform &trueMat, int xoffset, int type, int depth, uchar *dptr, int dbpl, int p_inc, int dHeight, const uchar *sptr, int sbpl, int sWidth, int sHeight)
 
static QImage rotated180 (const QImage &src)
 
static QImage rotated270 (const QImage &src)
 
static QImage rotated90 (const QImage &src)
 
static QImage smoothScaled (const QImage &source, int w, int h)
 
static void swap_bit_order (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
 

Variables

static const uchar bitflip [256]
 
static Image_Converter converter_map [QImage::NImageFormats][QImage::NImageFormats]
 
static InPlace_Image_Converter inplace_converter_map [QImage::NImageFormats][QImage::NImageFormats]
 
QBasicAtomicInt qimage_serial_number = Q_BASIC_ATOMIC_INITIALIZER(1)
 

Macro Definition Documentation

◆ CONVERT_DECL

#define CONVERT_DECL (   DST,
  SRC 
)
Value:
static void convert_##SRC##_to_##DST(QImageData *dest, \
const QImageData *src, \
Qt::ImageConversionFlags) \
{ \
qt_rectconvert<DST, SRC>(reinterpret_cast<DST*>(dest->data), \
reinterpret_cast<const SRC*>(src->data), \
0, 0, src->width, src->height, \
dest->bytes_per_line, src->bytes_per_line); \
}

Definition at line 3456 of file qimage.cpp.

◆ CONVERT_PTR

#define CONVERT_PTR (   DST,
  SRC 
)    convert_##SRC##_to_##DST

Definition at line 3490 of file qimage.cpp.

◆ DITHER [1/2]

#define DITHER (   p,
 
)    ((uchar) ((p * (m) + 127) / 255))

Referenced by convert_RGB_to_Indexed8().

◆ DITHER [2/2]

#define DITHER (   p,
  d,
 
)    ((uchar) ((((256 * (m) + (m) + 1)) * (p) + (d)) >> 16))

◆ INDEXOF

#define INDEXOF (   r,
  g,
 
)    (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b))

Referenced by convert_RGB_to_Indexed8().

◆ IWX_LSB

#define IWX_LSB (   b)
Value:
if (trigx < maxws && trigy < maxhs) { \
if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & \
(1 << ((trigx>>12)&7))) \
*dptr |= b; \
} \
trigx += m11; \
trigy += m12;

Definition at line 6083 of file qimage.cpp.

Referenced by qt_xForm_helper().

◆ IWX_MSB

#define IWX_MSB (   b)
Value:
if (trigx < maxws && trigy < maxhs) { \
if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & \
(1 << (7-((trigx>>12)&7)))) \
*dptr |= b; \
} \
trigx += m11; \
trigy += m12;

Definition at line 6074 of file qimage.cpp.

Referenced by qt_xForm_helper().

◆ IWX_PIX

#define IWX_PIX (   b)
Value:
if (trigx < maxws && trigy < maxhs) { \
if ((*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & \
(1 << (7-((trigx>>12)&7)))) == 0) \
*dptr &= ~b; \
} \
trigx += m11; \
trigy += m12;

Definition at line 6092 of file qimage.cpp.

Referenced by qt_xForm_helper().

◆ MAX_B

#define MAX_B   5

Referenced by convert_RGB_to_Indexed8().

◆ MAX_G

#define MAX_G   5

Referenced by convert_RGB_to_Indexed8().

◆ MAX_R

#define MAX_R   5

Referenced by convert_RGB_to_Indexed8().

◆ PIX

#define PIX (   x,
 
)    (*((QRgb*)scanLine(y)+x) & 0x00ffffff)

◆ QIMAGE_SANITYCHECK_MEMORY

#define QIMAGE_SANITYCHECK_MEMORY (   image)
Value:
if ((image).isNull()) { \
qWarning("QImage: out of memory, returning null image"); \
return QImage(); \
}
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

Definition at line 105 of file qimage.cpp.

Referenced by QImage::alphaChannel(), QImage::convertToFormat(), convertWithPalette(), QImage::createHeuristicMask(), QImage::createMaskFromColor(), QImage::mirrored(), QImage::rgbSwapped(), rotated270(), rotated90(), QImage::setPixel(), and QImage::transformed().

Typedef Documentation

◆ Image_Converter

typedef void(* Image_Converter) (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)

Definition at line 2432 of file qimage.cpp.

◆ InPlace_Image_Converter

typedef bool(* InPlace_Image_Converter) (QImageData *data, Qt::ImageConversionFlags)

Definition at line 2434 of file qimage.cpp.

Function Documentation

◆ checkPixelSize()

static bool checkPixelSize ( const QImage::Format  format)
inlinestatic

Definition at line 76 of file qimage.cpp.

Referenced by QImageData::create().

77 {
78  switch (format) {
80  return (sizeof(qargb8565) == 3);
82  return (sizeof(qrgb666) == 3);
84  return (sizeof(qargb6666) == 3);
86  return (sizeof(qrgb555) == 2);
88  return (sizeof(qargb8555) == 3);
90  return (sizeof(qrgb888) == 3);
92  return (sizeof(qrgb444) == 2);
94  return (sizeof(qargb4444) == 2);
95  default:
96  return true;
97  }
98 }

◆ closestMatch()

static int closestMatch ( QRgb  pixel,
const QVector< QRgb > &  clut 
)
inlinestatic

Definition at line 4015 of file qimage.cpp.

Referenced by convertWithPalette(), QIconLoaderEngine::entryForSize(), and QNetworkAuthenticationCache::insert().

4015  {
4016  int idx = 0;
4017  int current_distance = INT_MAX;
4018  for (int i=0; i<clut.size(); ++i) {
4019  int dist = pixel_distance(pixel, clut.at(i));
4020  if (dist < current_distance) {
4021  current_distance = dist;
4022  idx = i;
4023  }
4024  }
4025  return idx;
4026 }
static int pixel_distance(QRgb p1, QRgb p2)
Definition: qimage.cpp:4001
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
#define INT_MAX

◆ convert_ARGB_PM_to_ARGB()

static void convert_ARGB_PM_to_ARGB ( QImageData dest,
const QImageData src,
Qt::ImageConversionFlags   
)
static

Definition at line 2663 of file qimage.cpp.

Referenced by convert_ARGB_PM_to_Indexed8(), and convert_ARGB_PM_to_Mono().

2664 {
2667  Q_ASSERT(src->width == dest->width);
2668  Q_ASSERT(src->height == dest->height);
2669 
2670  const int src_pad = (src->bytes_per_line >> 2) - src->width;
2671  const int dest_pad = (dest->bytes_per_line >> 2) - dest->width;
2672  const QRgb *src_data = (QRgb *) src->data;
2673  QRgb *dest_data = (QRgb *) dest->data;
2674 
2675  for (int i = 0; i < src->height; ++i) {
2676  const QRgb *end = src_data + src->width;
2677  while (src_data < end) {
2678  *dest_data = INV_PREMUL(*src_data);
2679  ++src_data;
2680  ++dest_data;
2681  }
2682  src_data += src_pad;
2683  dest_data += dest_pad;
2684  }
2685 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int height
Definition: qimage_p.h:77
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
#define INV_PREMUL(p)
static const KeyPair *const end

◆ convert_ARGB_PM_to_Indexed8()

static void convert_ARGB_PM_to_Indexed8 ( QImageData dst,
const QImageData src,
Qt::ImageConversionFlags  flags 
)
static

Definition at line 3329 of file qimage.cpp.

3330 {
3332  convert_ARGB_PM_to_ARGB(tmp.data(), src, flags);
3333  convert_RGB_to_Indexed8(dst, tmp.data(), flags);
3334 }
int width
Definition: qimage_p.h:76
static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
Definition: qimage.cpp:3071
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
static QImageData * create(const QSize &size, QImage::Format format, int numColors=0)
Definition: qimage.cpp:151
static void convert_ARGB_PM_to_ARGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
Definition: qimage.cpp:2663
int height
Definition: qimage_p.h:77
uchar * data
Definition: qimage_p.h:81
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ convert_ARGB_PM_to_Mono()

static void convert_ARGB_PM_to_Mono ( QImageData dst,
const QImageData src,
Qt::ImageConversionFlags  flags 
)
static

Definition at line 3049 of file qimage.cpp.

3050 {
3052  convert_ARGB_PM_to_ARGB(tmp.data(), src, flags);
3053  dither_to_Mono(dst, tmp.data(), flags, false);
3054 }
int width
Definition: qimage_p.h:76
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
static QImageData * create(const QSize &size, QImage::Format format, int numColors=0)
Definition: qimage.cpp:151
static void dither_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags, bool fromalpha)
Definition: qimage.cpp:2774
static void convert_ARGB_PM_to_ARGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
Definition: qimage.cpp:2663
int height
Definition: qimage_p.h:77
uchar * data
Definition: qimage_p.h:81
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ convert_ARGB_PM_to_RGB()

static void convert_ARGB_PM_to_RGB ( QImageData dest,
const QImageData src,
Qt::ImageConversionFlags   
)
static

Definition at line 2687 of file qimage.cpp.

2688 {
2691  Q_ASSERT(src->width == dest->width);
2692  Q_ASSERT(src->height == dest->height);
2693 
2694  const int src_pad = (src->bytes_per_line >> 2) - src->width;
2695  const int dest_pad = (dest->bytes_per_line >> 2) - dest->width;
2696  const QRgb *src_data = (QRgb *) src->data;
2697  QRgb *dest_data = (QRgb *) dest->data;
2698 
2699  for (int i = 0; i < src->height; ++i) {
2700  const QRgb *end = src_data + src->width;
2701  while (src_data < end) {
2702  *dest_data = 0xff000000 | INV_PREMUL(*src_data);
2703  ++src_data;
2704  ++dest_data;
2705  }
2706  src_data += src_pad;
2707  dest_data += dest_pad;
2708  }
2709 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int height
Definition: qimage_p.h:77
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
#define INV_PREMUL(p)
static const KeyPair *const end

◆ convert_ARGB_to_ARGB_PM()

static void convert_ARGB_to_ARGB_PM ( QImageData dest,
const QImageData src,
Qt::ImageConversionFlags   
)
static

Definition at line 2436 of file qimage.cpp.

2437 {
2440  Q_ASSERT(src->width == dest->width);
2441  Q_ASSERT(src->height == dest->height);
2442 
2443  const int src_pad = (src->bytes_per_line >> 2) - src->width;
2444  const int dest_pad = (dest->bytes_per_line >> 2) - dest->width;
2445  const QRgb *src_data = (QRgb *) src->data;
2446  QRgb *dest_data = (QRgb *) dest->data;
2447 
2448  for (int i = 0; i < src->height; ++i) {
2449  const QRgb *end = src_data + src->width;
2450  while (src_data < end) {
2451  *dest_data = PREMUL(*src_data);
2452  ++src_data;
2453  ++dest_data;
2454  }
2455  src_data += src_pad;
2456  dest_data += dest_pad;
2457  }
2458 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int height
Definition: qimage_p.h:77
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
static const KeyPair *const end

◆ convert_ARGB_to_ARGB_PM_inplace()

static bool convert_ARGB_to_ARGB_PM_inplace ( QImageData data,
Qt::ImageConversionFlags   
)
static

Definition at line 2460 of file qimage.cpp.

2461 {
2463 
2464  const int pad = (data->bytes_per_line >> 2) - data->width;
2465  QRgb *rgb_data = (QRgb *) data->data;
2466 
2467  for (int i = 0; i < data->height; ++i) {
2468  const QRgb *end = rgb_data + data->width;
2469  while (rgb_data < end) {
2470  *rgb_data = PREMUL(*rgb_data);
2471  ++rgb_data;
2472  }
2473  rgb_data += pad;
2474  }
2476  return true;
2477 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int height
Definition: qimage_p.h:77
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
static const KeyPair *const end

◆ convert_ARGB_to_Indexed8()

static void convert_ARGB_to_Indexed8 ( QImageData dst,
const QImageData src,
Qt::ImageConversionFlags  flags 
)
static

Definition at line 3336 of file qimage.cpp.

3337 {
3338  convert_RGB_to_Indexed8(dst, src, flags);
3339 }
static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags)
Definition: qimage.cpp:3071

◆ convert_indexed8_to_ARGB_PM_inplace()

static bool convert_indexed8_to_ARGB_PM_inplace ( QImageData data,
Qt::ImageConversionFlags   
)
static

Definition at line 2479 of file qimage.cpp.

2480 {
2482  const int depth = 32;
2483 
2484  const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2;
2485  const int nbytes = dst_bytes_per_line * data->height;
2486  uchar *const newData = (uchar *)realloc(data->data, nbytes);
2487  if (!newData)
2488  return false;
2489 
2490  data->data = newData;
2491 
2492  // start converting from the end because the end image is bigger than the source
2493  uchar *src_data = newData + data->nbytes; // end of src
2494  quint32 *dest_data = (quint32 *) (newData + nbytes); // end of dest > end of src
2495  const int width = data->width;
2496  const int src_pad = data->bytes_per_line - width;
2497  const int dest_pad = (dst_bytes_per_line >> 2) - width;
2498  if (data->colortable.size() == 0) {
2499  data->colortable.resize(256);
2500  for (int i = 0; i < 256; ++i)
2501  data->colortable[i] = qRgb(i, i, i);
2502  } else {
2503  for (int i = 0; i < data->colortable.size(); ++i)
2504  data->colortable[i] = PREMUL(data->colortable.at(i));
2505 
2506  // Fill the rest of the table in case src_data > colortable.size()
2507  const int oldSize = data->colortable.size();
2508  const QRgb lastColor = data->colortable.at(oldSize - 1);
2509  data->colortable.insert(oldSize, 256 - oldSize, lastColor);
2510  }
2511 
2512  for (int i = 0; i < data->height; ++i) {
2513  src_data -= src_pad;
2514  dest_data -= dest_pad;
2515  for (int pixI = 0; pixI < width; ++pixI) {
2516  --src_data;
2517  --dest_data;
2518  *dest_data = data->colortable.at(*src_data);
2519  }
2520  }
2521 
2522  data->colortable = QVector<QRgb>();
2524  data->bytes_per_line = dst_bytes_per_line;
2525  data->depth = depth;
2526  data->nbytes = nbytes;
2527 
2528  return true;
2529 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
int nbytes
Definition: qimage_p.h:79
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
int bytes_per_line
Definition: qimage_p.h:86
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
QImage::Format format
Definition: qimage_p.h:85
unsigned int quint32
Definition: qglobal.h:938
uchar * data
Definition: qimage_p.h:81
int depth
Definition: qimage_p.h:78
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ convert_indexed8_to_RGB16_inplace()

static bool convert_indexed8_to_RGB16_inplace ( QImageData data,
Qt::ImageConversionFlags   
)
static

Definition at line 2580 of file qimage.cpp.

2581 {
2583  const int depth = 16;
2584 
2585  const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2;
2586  const int nbytes = dst_bytes_per_line * data->height;
2587  uchar *const newData = (uchar *)realloc(data->data, nbytes);
2588  if (!newData)
2589  return false;
2590 
2591  data->data = newData;
2592 
2593  // start converting from the end because the end image is bigger than the source
2594  uchar *src_data = newData + data->nbytes;
2595  quint16 *dest_data = (quint16 *) (newData + nbytes);
2596  const int width = data->width;
2597  const int src_pad = data->bytes_per_line - width;
2598  const int dest_pad = (dst_bytes_per_line >> 1) - width;
2599 
2600  quint16 colorTableRGB16[256];
2601  if (data->colortable.isEmpty()) {
2602  for (int i = 0; i < 256; ++i)
2603  colorTableRGB16[i] = qt_colorConvert<quint16, quint32>(qRgb(i, i, i), 0);
2604  } else {
2605  // 1) convert the existing colors to RGB16
2606  const int tableSize = data->colortable.size();
2607  for (int i = 0; i < tableSize; ++i)
2608  colorTableRGB16[i] = qt_colorConvert<quint16, quint32>(data->colortable.at(i), 0);
2609  data->colortable = QVector<QRgb>();
2610 
2611  // 2) fill the rest of the table in case src_data > colortable.size()
2612  const quint16 lastColor = colorTableRGB16[tableSize - 1];
2613  for (int i = tableSize; i < 256; ++i)
2614  colorTableRGB16[i] = lastColor;
2615  }
2616 
2617  for (int i = 0; i < data->height; ++i) {
2618  src_data -= src_pad;
2619  dest_data -= dest_pad;
2620  for (int pixI = 0; pixI < width; ++pixI) {
2621  --src_data;
2622  --dest_data;
2623  *dest_data = colorTableRGB16[*src_data];
2624  }
2625  }
2626 
2627  data->format = QImage::Format_RGB16;
2628  data->bytes_per_line = dst_bytes_per_line;
2629  data->depth = depth;
2630  data->nbytes = nbytes;
2631 
2632  return true;
2633 }
int width
Definition: qimage_p.h:76
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
unsigned short quint16
Definition: qglobal.h:936
int nbytes
Definition: qimage_p.h:79
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
int depth
Definition: qimage_p.h:78
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ convert_indexed8_to_RGB_inplace()

static bool convert_indexed8_to_RGB_inplace ( QImageData data,
Qt::ImageConversionFlags   
)
static

Definition at line 2531 of file qimage.cpp.

2532 {
2534  const int depth = 32;
2535 
2536  const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2;
2537  const int nbytes = dst_bytes_per_line * data->height;
2538  uchar *const newData = (uchar *)realloc(data->data, nbytes);
2539  if (!newData)
2540  return false;
2541 
2542  data->data = newData;
2543 
2544  // start converting from the end because the end image is bigger than the source
2545  uchar *src_data = newData + data->nbytes;
2546  quint32 *dest_data = (quint32 *) (newData + nbytes);
2547  const int width = data->width;
2548  const int src_pad = data->bytes_per_line - width;
2549  const int dest_pad = (dst_bytes_per_line >> 2) - width;
2550  if (data->colortable.size() == 0) {
2551  data->colortable.resize(256);
2552  for (int i = 0; i < 256; ++i)
2553  data->colortable[i] = qRgb(i, i, i);
2554  } else {
2555  // Fill the rest of the table in case src_data > colortable.size()
2556  const int oldSize = data->colortable.size();
2557  const QRgb lastColor = data->colortable.at(oldSize - 1);
2558  data->colortable.insert(oldSize, 256 - oldSize, lastColor);
2559  }
2560 
2561  for (int i = 0; i < data->height; ++i) {
2562  src_data -= src_pad;
2563  dest_data -= dest_pad;
2564  for (int pixI = 0; pixI < width; ++pixI) {
2565  --src_data;
2566  --dest_data;
2567  *dest_data = (quint32) data->colortable.at(*src_data);
2568  }
2569  }
2570 
2571  data->colortable = QVector<QRgb>();
2572  data->format = QImage::Format_RGB32;
2573  data->bytes_per_line = dst_bytes_per_line;
2574  data->depth = depth;
2575  data->nbytes = nbytes;
2576 
2577  return true;
2578 }
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
int nbytes
Definition: qimage_p.h:79
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
int bytes_per_line
Definition: qimage_p.h:86
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
QImage::Format format
Definition: qimage_p.h:85
unsigned int quint32
Definition: qglobal.h:938
uchar * data
Definition: qimage_p.h:81
int depth
Definition: qimage_p.h:78
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ convert_Indexed8_to_X32()

static void convert_Indexed8_to_X32 ( QImageData dest,
const QImageData src,
Qt::ImageConversionFlags   
)
static

Definition at line 3341 of file qimage.cpp.

3342 {
3345  || dest->format == QImage::Format_ARGB32
3347  Q_ASSERT(src->width == dest->width);
3348  Q_ASSERT(src->height == dest->height);
3349 
3350  QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format);
3351  if (colorTable.size() == 0) {
3352  colorTable.resize(256);
3353  for (int i=0; i<256; ++i)
3354  colorTable[i] = qRgb(i, i, i);
3355  }
3356 
3357  int w = src->width;
3358  const uchar *src_data = src->data;
3359  uchar *dest_data = dest->data;
3360  int tableSize = colorTable.size() - 1;
3361  for (int y = 0; y < src->height; y++) {
3362  uint *p = (uint *)dest_data;
3363  const uchar *b = src_data;
3364  uint *end = p + w;
3365 
3366  while (p < end)
3367  *p++ = colorTable.at(qMin<int>(tableSize, *b++));
3368 
3369  src_data += src->bytes_per_line;
3370  dest_data += dest->bytes_per_line;
3371  }
3372 }
int width
Definition: qimage_p.h:76
static QVector< QRgb > fix_color_table(const QVector< QRgb > &ctbl, QImage::Format format)
Definition: qimage.cpp:2754
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
unsigned int uint
Definition: qglobal.h:996
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int bytes_per_line
Definition: qimage_p.h:86
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ convert_Mono_to_Indexed8()

static void convert_Mono_to_Indexed8 ( QImageData dest,
const QImageData src,
Qt::ImageConversionFlags   
)
static

Definition at line 3416 of file qimage.cpp.

3417 {
3420  Q_ASSERT(src->width == dest->width);
3421  Q_ASSERT(src->height == dest->height);
3422 
3423  QVector<QRgb> ctbl = src->colortable;
3424  if (ctbl.size() > 2) {
3425  ctbl.resize(2);
3426  } else if (ctbl.size() < 2) {
3427  if (ctbl.size() == 0)
3428  ctbl << 0xff000000;
3429  ctbl << 0xffffffff;
3430  }
3431  dest->colortable = ctbl;
3432  dest->has_alpha_clut = src->has_alpha_clut;
3433 
3434 
3435  const uchar *src_data = src->data;
3436  uchar *dest_data = dest->data;
3437  if (src->format == QImage::Format_Mono) {
3438  for (int y = 0; y < dest->height; y++) {
3439  register uchar *p = dest_data;
3440  for (int x = 0; x < dest->width; x++)
3441  *p++ = (src_data[x>>3] >> (7 - (x & 7))) & 1;
3442  src_data += src->bytes_per_line;
3443  dest_data += dest->bytes_per_line;
3444  }
3445  } else {
3446  for (int y = 0; y < dest->height; y++) {
3447  register uchar *p = dest_data;
3448  for (int x = 0; x < dest->width; x++)
3449  *p++ = (src_data[x>>3] >> (x & 7)) & 1;
3450  src_data += src->bytes_per_line;
3451  dest_data += dest->bytes_per_line;
3452  }
3453  }
3454 }
int width
Definition: qimage_p.h:76
uint has_alpha_clut
Definition: qimage_p.h:96
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ convert_Mono_to_X32()

static void convert_Mono_to_X32 ( QImageData dest,
const QImageData src,
Qt::ImageConversionFlags   
)
static

Definition at line 3374 of file qimage.cpp.

3375 {
3378  || dest->format == QImage::Format_ARGB32
3380  Q_ASSERT(src->width == dest->width);
3381  Q_ASSERT(src->height == dest->height);
3382 
3383  QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format);
3384 
3385  // Default to black / white colors
3386  if (colorTable.size() < 2) {
3387  if (colorTable.size() == 0)
3388  colorTable << 0xff000000;
3389  colorTable << 0xffffffff;
3390  }
3391 
3392  const uchar *src_data = src->data;
3393  uchar *dest_data = dest->data;
3394  if (src->format == QImage::Format_Mono) {
3395  for (int y = 0; y < dest->height; y++) {
3396  register uint *p = (uint *)dest_data;
3397  for (int x = 0; x < dest->width; x++)
3398  *p++ = colorTable.at((src_data[x>>3] >> (7 - (x & 7))) & 1);
3399 
3400  src_data += src->bytes_per_line;
3401  dest_data += dest->bytes_per_line;
3402  }
3403  } else {
3404  for (int y = 0; y < dest->height; y++) {
3405  register uint *p = (uint *)dest_data;
3406  for (int x = 0; x < dest->width; x++)
3407  *p++ = colorTable.at((src_data[x>>3] >> (x & 7)) & 1);
3408 
3409  src_data += src->bytes_per_line;
3410  dest_data += dest->bytes_per_line;
3411  }
3412  }
3413 }
int width
Definition: qimage_p.h:76
static QVector< QRgb > fix_color_table(const QVector< QRgb > &ctbl, QImage::Format format)
Definition: qimage.cpp:2754
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
unsigned int uint
Definition: qglobal.h:996
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ convert_RGB_to_Indexed8()

static void convert_RGB_to_Indexed8 ( QImageData dst,
const QImageData src,
Qt::ImageConversionFlags  flags 
)
static

Definition at line 3071 of file qimage.cpp.

Referenced by convert_ARGB_PM_to_Indexed8(), and convert_ARGB_to_Indexed8().

3072 {
3075  Q_ASSERT(src->width == dst->width);
3076  Q_ASSERT(src->height == dst->height);
3077 
3078  bool do_quant = (flags & Qt::DitherMode_Mask) == Qt::PreferDither
3079  || src->format == QImage::Format_ARGB32;
3080  uint alpha_mask = src->format == QImage::Format_RGB32 ? 0xff000000 : 0;
3081 
3082  const int tablesize = 997; // prime
3083  QRgbMap table[tablesize];
3084  int pix=0;
3085 
3086  if (!dst->colortable.isEmpty()) {
3087  QVector<QRgb> ctbl = dst->colortable;
3088  dst->colortable.resize(256);
3089  // Preload palette into table.
3090  // Almost same code as pixel insertion below
3091  for (int i = 0; i < dst->colortable.size(); ++i) {
3092  // Find in table...
3093  QRgb p = ctbl.at(i) | alpha_mask;
3094  int hash = p % tablesize;
3095  for (;;) {
3096  if (table[hash].used) {
3097  if (table[hash].rgb == p) {
3098  // Found previous insertion - use it
3099  break;
3100  } else {
3101  // Keep searching...
3102  if (++hash == tablesize) hash = 0;
3103  }
3104  } else {
3105  // Cannot be in table
3106  Q_ASSERT (pix != 256); // too many colors
3107  // Insert into table at this unused position
3108  dst->colortable[pix] = p;
3109  table[hash].pix = pix++;
3110  table[hash].rgb = p;
3111  table[hash].used = 1;
3112  break;
3113  }
3114  }
3115  }
3116  }
3117 
3118  if ((flags & Qt::DitherMode_Mask) != Qt::PreferDither) {
3119  dst->colortable.resize(256);
3120  const uchar *src_data = src->data;
3121  uchar *dest_data = dst->data;
3122  for (int y = 0; y < src->height; y++) { // check if <= 256 colors
3123  const QRgb *s = (const QRgb *)src_data;
3124  uchar *b = dest_data;
3125  for (int x = 0; x < src->width; ++x) {
3126  QRgb p = s[x] | alpha_mask;
3127  int hash = p % tablesize;
3128  for (;;) {
3129  if (table[hash].used) {
3130  if (table[hash].rgb == (p)) {
3131  // Found previous insertion - use it
3132  break;
3133  } else {
3134  // Keep searching...
3135  if (++hash == tablesize) hash = 0;
3136  }
3137  } else {
3138  // Cannot be in table
3139  if (pix == 256) { // too many colors
3140  do_quant = true;
3141  // Break right out
3142  x = src->width;
3143  y = src->height;
3144  } else {
3145  // Insert into table at this unused position
3146  dst->colortable[pix] = p;
3147  table[hash].pix = pix++;
3148  table[hash].rgb = p;
3149  table[hash].used = 1;
3150  }
3151  break;
3152  }
3153  }
3154  *b++ = table[hash].pix; // May occur once incorrectly
3155  }
3156  src_data += src->bytes_per_line;
3157  dest_data += dst->bytes_per_line;
3158  }
3159  }
3160  int numColors = do_quant ? 256 : pix;
3161 
3162  dst->colortable.resize(numColors);
3163 
3164  if (do_quant) { // quantization needed
3165 
3166 #define MAX_R 5
3167 #define MAX_G 5
3168 #define MAX_B 5
3169 #define INDEXOF(r,g,b) (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b))
3170 
3171  for (int rc=0; rc<=MAX_R; rc++) // build 6x6x6 color cube
3172  for (int gc=0; gc<=MAX_G; gc++)
3173  for (int bc=0; bc<=MAX_B; bc++)
3174  dst->colortable[INDEXOF(rc,gc,bc)] = 0xff000000 | qRgb(rc*255/MAX_R, gc*255/MAX_G, bc*255/MAX_B);
3175 
3176  const uchar *src_data = src->data;
3177  uchar *dest_data = dst->data;
3178  if ((flags & Qt::Dither_Mask) == Qt::ThresholdDither) {
3179  for (int y = 0; y < src->height; y++) {
3180  const QRgb *p = (const QRgb *)src_data;
3181  const QRgb *end = p + src->width;
3182  uchar *b = dest_data;
3183 
3184  while (p < end) {
3185 #define DITHER(p,m) ((uchar) ((p * (m) + 127) / 255))
3186  *b++ =
3187  INDEXOF(
3188  DITHER(qRed(*p), MAX_R),
3189  DITHER(qGreen(*p), MAX_G),
3190  DITHER(qBlue(*p), MAX_B)
3191  );
3192 #undef DITHER
3193  p++;
3194  }
3195  src_data += src->bytes_per_line;
3196  dest_data += dst->bytes_per_line;
3197  }
3198  } else if ((flags & Qt::Dither_Mask) == Qt::DiffuseDither) {
3199  int* line1[3];
3200  int* line2[3];
3201  int* pv[3];
3202  QScopedArrayPointer<int> lineBuffer(new int[src->width * 9]);
3203  line1[0] = lineBuffer.data();
3204  line2[0] = lineBuffer.data() + src->width;
3205  line1[1] = lineBuffer.data() + src->width * 2;
3206  line2[1] = lineBuffer.data() + src->width * 3;
3207  line1[2] = lineBuffer.data() + src->width * 4;
3208  line2[2] = lineBuffer.data() + src->width * 5;
3209  pv[0] = lineBuffer.data() + src->width * 6;
3210  pv[1] = lineBuffer.data() + src->width * 7;
3211  pv[2] = lineBuffer.data() + src->width * 8;
3212 
3213  int endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian);
3214  for (int y = 0; y < src->height; y++) {
3215  const uchar* q = src_data;
3216  const uchar* q2 = y < src->height - 1 ? q + src->bytes_per_line : src->data;
3217  uchar *b = dest_data;
3218  for (int chan = 0; chan < 3; chan++) {
3219  int *l1 = (y&1) ? line2[chan] : line1[chan];
3220  int *l2 = (y&1) ? line1[chan] : line2[chan];
3221  if (y == 0) {
3222  for (int i = 0; i < src->width; i++)
3223  l1[i] = q[i*4+chan+endian];
3224  }
3225  if (y+1 < src->height) {
3226  for (int i = 0; i < src->width; i++)
3227  l2[i] = q2[i*4+chan+endian];
3228  }
3229  // Bi-directional error diffusion
3230  if (y&1) {
3231  for (int x = 0; x < src->width; x++) {
3232  int pix = qMax(qMin(5, (l1[x] * 5 + 128)/ 255), 0);
3233  int err = l1[x] - pix * 255 / 5;
3234  pv[chan][x] = pix;
3235 
3236  // Spread the error around...
3237  if (x + 1< src->width) {
3238  l1[x+1] += (err*7)>>4;
3239  l2[x+1] += err>>4;
3240  }
3241  l2[x]+=(err*5)>>4;
3242  if (x>1)
3243  l2[x-1]+=(err*3)>>4;
3244  }
3245  } else {
3246  for (int x = src->width; x-- > 0;) {
3247  int pix = qMax(qMin(5, (l1[x] * 5 + 128)/ 255), 0);
3248  int err = l1[x] - pix * 255 / 5;
3249  pv[chan][x] = pix;
3250 
3251  // Spread the error around...
3252  if (x > 0) {
3253  l1[x-1] += (err*7)>>4;
3254  l2[x-1] += err>>4;
3255  }
3256  l2[x]+=(err*5)>>4;
3257  if (x + 1 < src->width)
3258  l2[x+1]+=(err*3)>>4;
3259  }
3260  }
3261  }
3262  if (endian) {
3263  for (int x = 0; x < src->width; x++) {
3264  *b++ = INDEXOF(pv[0][x],pv[1][x],pv[2][x]);
3265  }
3266  } else {
3267  for (int x = 0; x < src->width; x++) {
3268  *b++ = INDEXOF(pv[2][x],pv[1][x],pv[0][x]);
3269  }
3270  }
3271  src_data += src->bytes_per_line;
3272  dest_data += dst->bytes_per_line;
3273  }
3274  } else { // OrderedDither
3275  for (int y = 0; y < src->height; y++) {
3276  const QRgb *p = (const QRgb *)src_data;
3277  const QRgb *end = p + src->width;
3278  uchar *b = dest_data;
3279 
3280  int x = 0;
3281  while (p < end) {
3282  uint d = qt_bayer_matrix[y & 15][x & 15] << 8;
3283 
3284 #define DITHER(p, d, m) ((uchar) ((((256 * (m) + (m) + 1)) * (p) + (d)) >> 16))
3285  *b++ =
3286  INDEXOF(
3287  DITHER(qRed(*p), d, MAX_R),
3288  DITHER(qGreen(*p), d, MAX_G),
3289  DITHER(qBlue(*p), d, MAX_B)
3290  );
3291 #undef DITHER
3292 
3293  p++;
3294  x++;
3295  }
3296  src_data += src->bytes_per_line;
3297  dest_data += dst->bytes_per_line;
3298  }
3299  }
3300 
3301  if (src->format != QImage::Format_RGB32
3302  && src->format != QImage::Format_RGB16) {
3303  const int trans = 216;
3304  Q_ASSERT(dst->colortable.size() > trans);
3305  dst->colortable[trans] = 0;
3307  dither_to_Mono(mask.data(), src, flags, true);
3308  uchar *dst_data = dst->data;
3309  const uchar *mask_data = mask->data;
3310  for (int y = 0; y < src->height; y++) {
3311  for (int x = 0; x < src->width ; x++) {
3312  if (!(mask_data[x>>3] & (0x80 >> (x & 7))))
3313  dst_data[x] = trans;
3314  }
3315  mask_data += mask->bytes_per_line;
3316  dst_data += dst->bytes_per_line;
3317  }
3318  dst->has_alpha_clut = true;
3319  }
3320 
3321 #undef MAX_R
3322 #undef MAX_G
3323 #undef MAX_B
3324 #undef INDEXOF
3325 
3326  }
3327 }
double d
Definition: qnumeric_p.h:62
#define MAX_B
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
int width
Definition: qimage_p.h:76
unsigned int QRgb
Definition: qrgb.h:53
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
uint has_alpha_clut
Definition: qimage_p.h:96
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
#define MAX_R
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
static QImageData * create(const QSize &size, QImage::Format format, int numColors=0)
Definition: qimage.cpp:151
static void dither_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags, bool fromalpha)
Definition: qimage.cpp:2774
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
unsigned int uint
Definition: qglobal.h:996
The QScopedArrayPointer class stores a pointer to a dynamically allocated array of objects...
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
int bytes_per_line
Definition: qimage_p.h:86
const uint qt_bayer_matrix[16][16]
#define DITHER(p, m)
QImage::Format format
Definition: qimage_p.h:85
if(void) toggleToolbarShown
uchar * data
Definition: qimage_p.h:81
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
#define INDEXOF(r, g, b)
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
static const KeyPair *const end
#define MAX_G
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ convert_RGB_to_RGB16_inplace()

static bool convert_RGB_to_RGB16_inplace ( QImageData data,
Qt::ImageConversionFlags   
)
static

Definition at line 2635 of file qimage.cpp.

2636 {
2638  const int depth = 16;
2639 
2640  const int dst_bytes_per_line = ((data->width * depth + 31) >> 5) << 2;
2641  const int src_bytes_per_line = data->bytes_per_line;
2642  quint32 *src_data = (quint32 *) data->data;
2643  quint16 *dst_data = (quint16 *) data->data;
2644 
2645  for (int i = 0; i < data->height; ++i) {
2646  qt_memconvert(dst_data, src_data, data->width);
2647  src_data = (quint32 *) (((char*)src_data) + src_bytes_per_line);
2648  dst_data = (quint16 *) (((char*)dst_data) + dst_bytes_per_line);
2649  }
2650  data->format = QImage::Format_RGB16;
2651  data->bytes_per_line = dst_bytes_per_line;
2652  data->depth = depth;
2653  data->nbytes = dst_bytes_per_line * data->height;
2654  uchar *const newData = (uchar *)realloc(data->data, data->nbytes);
2655  if (newData) {
2656  data->data = newData;
2657  return true;
2658  } else {
2659  return false;
2660  }
2661 }
int width
Definition: qimage_p.h:76
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
unsigned short quint16
Definition: qglobal.h:936
int nbytes
Definition: qimage_p.h:79
int bytes_per_line
Definition: qimage_p.h:86
void qt_memconvert(DST *dest, const SRC *src, int count)
QImage::Format format
Definition: qimage_p.h:85
unsigned int quint32
Definition: qglobal.h:938
uchar * data
Definition: qimage_p.h:81
int depth
Definition: qimage_p.h:78

◆ convert_X_to_Mono()

static void convert_X_to_Mono ( QImageData dst,
const QImageData src,
Qt::ImageConversionFlags  flags 
)
static

Definition at line 3044 of file qimage.cpp.

3045 {
3046  dither_to_Mono(dst, src, flags, false);
3047 }
static void dither_to_Mono(QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags, bool fromalpha)
Definition: qimage.cpp:2774

◆ convertWithPalette()

static QImage convertWithPalette ( const QImage src,
QImage::Format  format,
const QVector< QRgb > &  clut 
)
static

Definition at line 4028 of file qimage.cpp.

Referenced by QImage::convertToFormat().

4029  {
4030  QImage dest(src.size(), format);
4032  dest.setColorTable(clut);
4033 
4034 #if !defined(QT_NO_IMAGE_TEXT)
4035  QString textsKeys = src.text();
4036  QStringList textKeyList = textsKeys.split(QLatin1Char('\n'), QString::SkipEmptyParts);
4037  foreach (const QString &textKey, textKeyList) {
4038  QStringList textKeySplitted = textKey.split(QLatin1String(": "));
4039  dest.setText(textKeySplitted[0], textKeySplitted[1]);
4040  }
4041 #endif // !QT_NO_IMAGE_TEXT
4042 
4043  int h = src.height();
4044  int w = src.width();
4045 
4046  QHash<QRgb, int> cache;
4047 
4049  for (int y=0; y<h; ++y) {
4050  QRgb *src_pixels = (QRgb *) src.scanLine(y);
4051  uchar *dest_pixels = (uchar *) dest.scanLine(y);
4052  for (int x=0; x<w; ++x) {
4053  int src_pixel = src_pixels[x];
4054  int value = cache.value(src_pixel, -1);
4055  if (value == -1) {
4056  value = closestMatch(src_pixel, clut);
4057  cache.insert(src_pixel, value);
4058  }
4059  dest_pixels[x] = (uchar) value;
4060  }
4061  }
4062  } else {
4063  QVector<QRgb> table = clut;
4064  table.resize(2);
4065  for (int y=0; y<h; ++y) {
4066  QRgb *src_pixels = (QRgb *) src.scanLine(y);
4067  for (int x=0; x<w; ++x) {
4068  int src_pixel = src_pixels[x];
4069  int value = cache.value(src_pixel, -1);
4070  if (value == -1) {
4071  value = closestMatch(src_pixel, table);
4072  cache.insert(src_pixel, value);
4073  }
4074  dest.setPixel(x, y, value);
4075  }
4076  }
4077  }
4078 
4079  return dest;
4080 }
unsigned int QRgb
Definition: qrgb.h:53
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
unsigned char uchar
Definition: qglobal.h:994
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString text(const QString &key=QString()) const
Returns the image text associated with the given key.
Definition: qimage.cpp:5736
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
static int closestMatch(QRgb pixel, const QVector< QRgb > &clut)
Definition: qimage.cpp:4015
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ dither_to_Mono()

static void dither_to_Mono ( QImageData dst,
const QImageData src,
Qt::ImageConversionFlags  flags,
bool  fromalpha 
)
static

Definition at line 2774 of file qimage.cpp.

Referenced by convert_ARGB_PM_to_Mono(), convert_RGB_to_Indexed8(), convert_X_to_Mono(), and QImage::createAlphaMask().

2776 {
2777  Q_ASSERT(src->width == dst->width);
2778  Q_ASSERT(src->height == dst->height);
2780 
2781  dst->colortable.clear();
2782  dst->colortable.append(0xffffffff);
2783  dst->colortable.append(0xff000000);
2784 
2785  enum { Threshold, Ordered, Diffuse } dithermode;
2786 
2787  if (fromalpha) {
2789  dithermode = Diffuse;
2790  else if ((flags & Qt::AlphaDither_Mask) == Qt::OrderedAlphaDither)
2791  dithermode = Ordered;
2792  else
2793  dithermode = Threshold;
2794  } else {
2795  if ((flags & Qt::Dither_Mask) == Qt::ThresholdDither)
2796  dithermode = Threshold;
2797  else if ((flags & Qt::Dither_Mask) == Qt::OrderedDither)
2798  dithermode = Ordered;
2799  else
2800  dithermode = Diffuse;
2801  }
2802 
2803  int w = src->width;
2804  int h = src->height;
2805  int d = src->depth;
2806  uchar gray[256]; // gray map for 8 bit images
2807  bool use_gray = (d == 8);
2808  if (use_gray) { // make gray map
2809  if (fromalpha) {
2810  // Alpha 0x00 -> 0 pixels (white)
2811  // Alpha 0xFF -> 1 pixels (black)
2812  for (int i = 0; i < src->colortable.size(); i++)
2813  gray[i] = (255 - (src->colortable.at(i) >> 24));
2814  } else {
2815  // Pixel 0x00 -> 1 pixels (black)
2816  // Pixel 0xFF -> 0 pixels (white)
2817  for (int i = 0; i < src->colortable.size(); i++)
2818  gray[i] = qGray(src->colortable.at(i));
2819  }
2820  }
2821 
2822  uchar *dst_data = dst->data;
2823  int dst_bpl = dst->bytes_per_line;
2824  const uchar *src_data = src->data;
2825  int src_bpl = src->bytes_per_line;
2826 
2827  switch (dithermode) {
2828  case Diffuse: {
2829  QScopedArrayPointer<int> lineBuffer(new int[w * 2]);
2830  int *line1 = lineBuffer.data();
2831  int *line2 = lineBuffer.data() + w;
2832  int bmwidth = (w+7)/8;
2833 
2834  int *b1, *b2;
2835  int wbytes = w * (d/8);
2836  register const uchar *p = src->data;
2837  const uchar *end = p + wbytes;
2838  b2 = line2;
2839  if (use_gray) { // 8 bit image
2840  while (p < end)
2841  *b2++ = gray[*p++];
2842  } else { // 32 bit image
2843  if (fromalpha) {
2844  while (p < end) {
2845  *b2++ = 255 - (*(uint*)p >> 24);
2846  p += 4;
2847  }
2848  } else {
2849  while (p < end) {
2850  *b2++ = qGray(*(uint*)p);
2851  p += 4;
2852  }
2853  }
2854  }
2855  for (int y=0; y<h; y++) { // for each scan line...
2856  int *tmp = line1; line1 = line2; line2 = tmp;
2857  bool not_last_line = y < h - 1;
2858  if (not_last_line) { // calc. grayvals for next line
2859  p = src->data + (y+1)*src->bytes_per_line;
2860  end = p + wbytes;
2861  b2 = line2;
2862  if (use_gray) { // 8 bit image
2863  while (p < end)
2864  *b2++ = gray[*p++];
2865  } else { // 24 bit image
2866  if (fromalpha) {
2867  while (p < end) {
2868  *b2++ = 255 - (*(uint*)p >> 24);
2869  p += 4;
2870  }
2871  } else {
2872  while (p < end) {
2873  *b2++ = qGray(*(uint*)p);
2874  p += 4;
2875  }
2876  }
2877  }
2878  }
2879 
2880  int err;
2881  uchar *p = dst->data + y*dst->bytes_per_line;
2882  memset(p, 0, bmwidth);
2883  b1 = line1;
2884  b2 = line2;
2885  int bit = 7;
2886  for (int x=1; x<=w; x++) {
2887  if (*b1 < 128) { // black pixel
2888  err = *b1++;
2889  *p |= 1 << bit;
2890  } else { // white pixel
2891  err = *b1++ - 255;
2892  }
2893  if (bit == 0) {
2894  p++;
2895  bit = 7;
2896  } else {
2897  bit--;
2898  }
2899  if (x < w)
2900  *b1 += (err*7)>>4; // spread error to right pixel
2901  if (not_last_line) {
2902  b2[0] += (err*5)>>4; // pixel below
2903  if (x > 1)
2904  b2[-1] += (err*3)>>4; // pixel below left
2905  if (x < w)
2906  b2[1] += err>>4; // pixel below right
2907  }
2908  b2++;
2909  }
2910  }
2911  } break;
2912  case Ordered: {
2913 
2914  memset(dst->data, 0, dst->nbytes);
2915  if (d == 32) {
2916  for (int i=0; i<h; i++) {
2917  const uint *p = (const uint *)src_data;
2918  const uint *end = p + w;
2919  uchar *m = dst_data;
2920  int bit = 7;
2921  int j = 0;
2922  if (fromalpha) {
2923  while (p < end) {
2924  if ((*p++ >> 24) >= qt_bayer_matrix[j++&15][i&15])
2925  *m |= 1 << bit;
2926  if (bit == 0) {
2927  m++;
2928  bit = 7;
2929  } else {
2930  bit--;
2931  }
2932  }
2933  } else {
2934  while (p < end) {
2935  if ((uint)qGray(*p++) < qt_bayer_matrix[j++&15][i&15])
2936  *m |= 1 << bit;
2937  if (bit == 0) {
2938  m++;
2939  bit = 7;
2940  } else {
2941  bit--;
2942  }
2943  }
2944  }
2945  dst_data += dst_bpl;
2946  src_data += src_bpl;
2947  }
2948  } else
2949  /* (d == 8) */ {
2950  for (int i=0; i<h; i++) {
2951  const uchar *p = src_data;
2952  const uchar *end = p + w;
2953  uchar *m = dst_data;
2954  int bit = 7;
2955  int j = 0;
2956  while (p < end) {
2957  if ((uint)gray[*p++] < qt_bayer_matrix[j++&15][i&15])
2958  *m |= 1 << bit;
2959  if (bit == 0) {
2960  m++;
2961  bit = 7;
2962  } else {
2963  bit--;
2964  }
2965  }
2966  dst_data += dst_bpl;
2967  src_data += src_bpl;
2968  }
2969  }
2970  } break;
2971  default: { // Threshold:
2972  memset(dst->data, 0, dst->nbytes);
2973  if (d == 32) {
2974  for (int i=0; i<h; i++) {
2975  const uint *p = (const uint *)src_data;
2976  const uint *end = p + w;
2977  uchar *m = dst_data;
2978  int bit = 7;
2979  if (fromalpha) {
2980  while (p < end) {
2981  if ((*p++ >> 24) >= 128)
2982  *m |= 1 << bit; // Set mask "on"
2983  if (bit == 0) {
2984  m++;
2985  bit = 7;
2986  } else {
2987  bit--;
2988  }
2989  }
2990  } else {
2991  while (p < end) {
2992  if (qGray(*p++) < 128)
2993  *m |= 1 << bit; // Set pixel "black"
2994  if (bit == 0) {
2995  m++;
2996  bit = 7;
2997  } else {
2998  bit--;
2999  }
3000  }
3001  }
3002  dst_data += dst_bpl;
3003  src_data += src_bpl;
3004  }
3005  } else
3006  if (d == 8) {
3007  for (int i=0; i<h; i++) {
3008  const uchar *p = src_data;
3009  const uchar *end = p + w;
3010  uchar *m = dst_data;
3011  int bit = 7;
3012  while (p < end) {
3013  if (gray[*p++] < 128)
3014  *m |= 1 << bit; // Set mask "on"/ pixel "black"
3015  if (bit == 0) {
3016  m++;
3017  bit = 7;
3018  } else {
3019  bit--;
3020  }
3021  }
3022  dst_data += dst_bpl;
3023  src_data += src_bpl;
3024  }
3025  }
3026  }
3027  }
3028 
3029  if (dst->format == QImage::Format_MonoLSB) {
3030  // need to swap bit order
3031  uchar *sl = dst->data;
3032  int bpl = (dst->width + 7) * dst->depth / 8;
3033  int pad = dst->bytes_per_line - bpl;
3034  for (int y=0; y<dst->height; ++y) {
3035  for (int x=0; x<bpl; ++x) {
3036  *sl = bitflip[*sl];
3037  ++sl;
3038  }
3039  sl += pad;
3040  }
3041  }
3042 }
double d
Definition: qnumeric_p.h:62
int width
Definition: qimage_p.h:76
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
for(int ii=mo->methodOffset();ii< mo->methodCount();++ii)
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
unsigned int uint
Definition: qglobal.h:996
int qGray(int r, int g, int b)
Definition: qrgb.h:75
The QScopedArrayPointer class stores a pointer to a dynamically allocated array of objects...
int nbytes
Definition: qimage_p.h:79
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int bytes_per_line
Definition: qimage_p.h:86
const uint qt_bayer_matrix[16][16]
static const uchar bitflip[256]
Definition: qimage.cpp:736
QImage::Format format
Definition: qimage_p.h:85
if(void) toggleToolbarShown
uchar * data
Definition: qimage_p.h:81
int depth
Definition: qimage_p.h:78
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ fix_color_table()

static QVector<QRgb> fix_color_table ( const QVector< QRgb > &  ctbl,
QImage::Format  format 
)
static

Definition at line 2754 of file qimage.cpp.

Referenced by convert_Indexed8_to_X32(), and convert_Mono_to_X32().

2755 {
2756  QVector<QRgb> colorTable = ctbl;
2757  if (format == QImage::Format_RGB32) {
2758  // check if the color table has alpha
2759  for (int i = 0; i < colorTable.size(); ++i)
2760  if (qAlpha(colorTable.at(i) != 0xff))
2761  colorTable[i] = colorTable.at(i) | 0xff000000;
2763  // check if the color table has alpha
2764  for (int i = 0; i < colorTable.size(); ++i)
2765  colorTable[i] = PREMUL(colorTable.at(i));
2766  }
2767  return colorTable;
2768 }
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ mask_alpha_converter()

static void mask_alpha_converter ( QImageData dest,
const QImageData src,
Qt::ImageConversionFlags   
)
static

Definition at line 2732 of file qimage.cpp.

2733 {
2734  Q_ASSERT(src->width == dest->width);
2735  Q_ASSERT(src->height == dest->height);
2736 
2737  const int src_pad = (src->bytes_per_line >> 2) - src->width;
2738  const int dest_pad = (dest->bytes_per_line >> 2) - dest->width;
2739  const uint *src_data = (const uint *)src->data;
2740  uint *dest_data = (uint *)dest->data;
2741 
2742  for (int i = 0; i < src->height; ++i) {
2743  const uint *end = src_data + src->width;
2744  while (src_data < end) {
2745  *dest_data = *src_data | 0xff000000;
2746  ++src_data;
2747  ++dest_data;
2748  }
2749  src_data += src_pad;
2750  dest_data += dest_pad;
2751  }
2752 }
int width
Definition: qimage_p.h:76
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int height
Definition: qimage_p.h:77
unsigned int uint
Definition: qglobal.h:996
int bytes_per_line
Definition: qimage_p.h:86
uchar * data
Definition: qimage_p.h:81
static const KeyPair *const end

◆ operator<<()

QDataStream& operator<< ( QDataStream s,
const QImage image 
)
related

Definition at line 5406 of file qimage.cpp.

Referenced by QImage::setPixel().

5407 {
5408  if (s.version() >= 5) {
5409  if (image.isNull()) {
5410  s << (qint32) 0; // null image marker
5411  return s;
5412  } else {
5413  s << (qint32) 1;
5414  // continue ...
5415  }
5416  }
5417  QImageWriter writer(s.device(), s.version() == 1 ? "bmp" : "png");
5418  writer.write(image);
5419  return s;
5420 }
int qint32
Definition: qglobal.h:937
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QImageWriter class provides a format independent interface for writing images to files or other d...
Definition: qimagewriter.h:59
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
QIODevice * device() const
Returns the I/O device currently set, or 0 if no device is currently set.
Definition: qdatastream.h:206
bool write(const QImage &image)
Writes the image image to the assigned device or file name.

◆ operator>>()

QDataStream& operator>> ( QDataStream s,
QImage image 
)
related

Definition at line 5435 of file qimage.cpp.

Referenced by QImage::setPixel().

5436 {
5437  if (s.version() >= 5) {
5438  qint32 nullMarker;
5439  s >> nullMarker;
5440  if (!nullMarker) {
5441  image = QImage(); // null image
5442  return s;
5443  }
5444  }
5445  image = QImageReader(s.device(), 0).read();
5446  return s;
5447 }
int qint32
Definition: qglobal.h:937
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QImageReader class provides a format independent interface for reading images from files or other...
Definition: qimagereader.h:62
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
QIODevice * device() const
Returns the I/O device currently set, or 0 if no device is currently set.
Definition: qdatastream.h:206

◆ pixel_distance()

static int pixel_distance ( QRgb  p1,
QRgb  p2 
)
inlinestatic

Definition at line 4001 of file qimage.cpp.

Referenced by closestMatch().

4001  {
4002  int r1 = qRed(p1);
4003  int g1 = qGreen(p1);
4004  int b1 = qBlue(p1);
4005  int a1 = qAlpha(p1);
4006 
4007  int r2 = qRed(p2);
4008  int g2 = qGreen(p2);
4009  int b2 = qBlue(p2);
4010  int a2 = qAlpha(p2);
4011 
4012  return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2) + abs(a1 - a2);
4013 }
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
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

◆ qGamma_correct_back_to_linear_cs()

void qGamma_correct_back_to_linear_cs ( QImage image)

Definition at line 3938 of file qimage.cpp.

Referenced by QFontEngineMac::alphaRGBMapForGlyph().

3939 {
3940  extern uchar qt_pow_rgb_gamma[256];
3941 
3942  // gamma correct the pixels back to linear color space...
3943  int h = image->height();
3944  int w = image->width();
3945 
3946  for (int y=0; y<h; ++y) {
3947  uint *pixels = (uint *) image->scanLine(y);
3948  for (int x=0; x<w; ++x) {
3949  uint p = pixels[x];
3950  uint r = qt_pow_rgb_gamma[qRed(p)];
3951  uint g = qt_pow_rgb_gamma[qGreen(p)];
3952  uint b = qt_pow_rgb_gamma[qBlue(p)];
3953  pixels[x] = (r << 16) | (g << 8) | b | 0xff000000;
3954  }
3955  }
3956 }
uchar qt_pow_rgb_gamma[256]
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Definition: qrgb.h:57
unsigned char uchar
Definition: qglobal.h:994
unsigned int uint
Definition: qglobal.h:996
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
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
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ qInitImageConversions()

void qInitImageConversions ( )

Definition at line 3909 of file qimage.cpp.

Referenced by QApplication::QApplication().

3910 {
3911  const uint features = qDetectCPUFeatures();
3912  Q_UNUSED(features);
3913 
3914 #ifdef QT_HAVE_SSE2
3915  if (features & SSE2) {
3916  extern bool convert_ARGB_to_ARGB_PM_inplace_sse2(QImageData *data, Qt::ImageConversionFlags);
3917  inplace_converter_map[QImage::Format_ARGB32][QImage::Format_ARGB32_Premultiplied] = convert_ARGB_to_ARGB_PM_inplace_sse2;
3918  }
3919 #endif
3920 #ifdef QT_HAVE_SSSE3
3921  if (features & SSSE3) {
3922  extern void convert_RGB888_to_RGB32_ssse3(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags);
3923  converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_ssse3;
3924  converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_ssse3;
3926  }
3927 #endif
3928 #ifdef QT_HAVE_NEON
3929  if (features & NEON) {
3930  extern void convert_RGB888_to_RGB32_neon(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags);
3931  converter_map[QImage::Format_RGB888][QImage::Format_RGB32] = convert_RGB888_to_RGB32_neon;
3932  converter_map[QImage::Format_RGB888][QImage::Format_ARGB32] = convert_RGB888_to_RGB32_neon;
3934  }
3935 #endif
3936 }
Definition: qsimd_p.h:217
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
uint qDetectCPUFeatures()
Definition: qsimd.cpp:382
Definition: qsimd_p.h:222
static InPlace_Image_Converter inplace_converter_map[QImage::NImageFormats][QImage::NImageFormats]
Definition: qimage.cpp:3812
Definition: qsimd_p.h:220
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static Image_Converter converter_map[QImage::NImageFormats][QImage::NImageFormats]
Definition: qimage.cpp:3513

◆ 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_image_colortable()

const QVector<QRgb>* qt_image_colortable ( const QImage image)

Definition at line 122 of file qimage.cpp.

Referenced by QSpanData::setupMatrix().

123 {
124  return &image.d->colortable;
125 }
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80

◆ qt_image_id()

Q_GUI_EXPORT qint64 qt_image_id ( const QImage image)

Definition at line 117 of file qimage.cpp.

118 {
119  return image.cacheKey();
120 }
qint64 cacheKey() const
Returns a number that identifies the contents of this QImage object.
Definition: qimage.cpp:6282

◆ qt_read_xpm_image_or_array()

bool qt_read_xpm_image_or_array ( QIODevice device,
const char *const *  source,
QImage image 
)

Definition at line 1025 of file qxpmhandler.cpp.

Referenced by QImage::QImage().

1026 {
1027  if (!source)
1028  return true;
1029 
1030  QByteArray buf(200, 0);
1031  QByteArray state;
1032 
1033  int cpp, ncols, w, h, index = 0;
1034 
1035  if (device) {
1036  // "/* XPM */"
1037  int readBytes;
1038  if ((readBytes = device->readLine(buf.data(), buf.size())) < 0)
1039  return false;
1040 
1041  if (buf.indexOf("/* XPM") != 0) {
1042  while (readBytes > 0) {
1043  device->ungetChar(buf.at(readBytes - 1));
1044  --readBytes;
1045  }
1046  return false;
1047  }// bad magic
1048  }
1049 
1050  if (!read_xpm_header(device, source, index, state, &cpp, &ncols, &w, &h))
1051  return false;
1052 
1053  return read_xpm_body(device, source, index, state, cpp, ncols, w, h, image);
1054 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void ungetChar(char c)
Puts the character c back into the device, and decrements the current position unless the position is...
Definition: qiodevice.cpp:1462
static bool read_xpm_body(QIODevice *device, const char *const *source, int &index, QByteArray &state, int cpp, int ncols, int w, int h, QImage &image)
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes...
Definition: qiodevice.cpp:1110
quint16 index
static bool read_xpm_header(QIODevice *device, const char *const *source, int &index, QByteArray &state, int *cpp, int *ncols, int *w, int *h)

◆ qt_xForm_helper()

bool qt_xForm_helper ( const QTransform trueMat,
int  xoffset,
int  type,
int  depth,
uchar dptr,
int  dbpl,
int  p_inc,
int  dHeight,
const uchar sptr,
int  sbpl,
int  sWidth,
int  sHeight 
)

Definition at line 6100 of file qimage.cpp.

Referenced by QMacPixmapData::macCreatePixels(), QX11PixmapData::transformed(), and QImage::transformed().

6103 {
6104  int m11 = int(trueMat.m11()*qreal(4096.0));
6105  int m12 = int(trueMat.m12()*qreal(4096.0));
6106  int m21 = int(trueMat.m21()*qreal(4096.0));
6107  int m22 = int(trueMat.m22()*qreal(4096.0));
6108  int dx = qRound(trueMat.dx()*qreal(4096.0));
6109  int dy = qRound(trueMat.dy()*qreal(4096.0));
6110 
6111  int m21ydx = dx + (xoffset<<16) + (m11 + m21) / 2;
6112  int m22ydy = dy + (m12 + m22) / 2;
6113  uint trigx;
6114  uint trigy;
6115  uint maxws = sWidth<<12;
6116  uint maxhs = sHeight<<12;
6117 
6118  for (int y=0; y<dHeight; y++) { // for each target scanline
6119  trigx = m21ydx;
6120  trigy = m22ydy;
6121  uchar *maxp = dptr + dbpl;
6122  if (depth != 1) {
6123  switch (depth) {
6124  case 8: // 8 bpp transform
6125  while (dptr < maxp) {
6126  if (trigx < maxws && trigy < maxhs)
6127  *dptr = *(sptr+sbpl*(trigy>>12)+(trigx>>12));
6128  trigx += m11;
6129  trigy += m12;
6130  dptr++;
6131  }
6132  break;
6133 
6134  case 16: // 16 bpp transform
6135  while (dptr < maxp) {
6136  if (trigx < maxws && trigy < maxhs)
6137  *((ushort*)dptr) = *((ushort *)(sptr+sbpl*(trigy>>12) +
6138  ((trigx>>12)<<1)));
6139  trigx += m11;
6140  trigy += m12;
6141  dptr++;
6142  dptr++;
6143  }
6144  break;
6145 
6146  case 24: // 24 bpp transform
6147  while (dptr < maxp) {
6148  if (trigx < maxws && trigy < maxhs) {
6149  const uchar *p2 = sptr+sbpl*(trigy>>12) + ((trigx>>12)*3);
6150  dptr[0] = p2[0];
6151  dptr[1] = p2[1];
6152  dptr[2] = p2[2];
6153  }
6154  trigx += m11;
6155  trigy += m12;
6156  dptr += 3;
6157  }
6158  break;
6159 
6160  case 32: // 32 bpp transform
6161  while (dptr < maxp) {
6162  if (trigx < maxws && trigy < maxhs)
6163  *((uint*)dptr) = *((uint *)(sptr+sbpl*(trigy>>12) +
6164  ((trigx>>12)<<2)));
6165  trigx += m11;
6166  trigy += m12;
6167  dptr += 4;
6168  }
6169  break;
6170 
6171  default: {
6172  return false;
6173  }
6174  }
6175  } else {
6176  switch (type) {
6178  while (dptr < maxp) {
6179  IWX_MSB(128);
6180  IWX_MSB(64);
6181  IWX_MSB(32);
6182  IWX_MSB(16);
6183  IWX_MSB(8);
6184  IWX_MSB(4);
6185  IWX_MSB(2);
6186  IWX_MSB(1);
6187  dptr++;
6188  }
6189  break;
6191  while (dptr < maxp) {
6192  IWX_LSB(1);
6193  IWX_LSB(2);
6194  IWX_LSB(4);
6195  IWX_LSB(8);
6196  IWX_LSB(16);
6197  IWX_LSB(32);
6198  IWX_LSB(64);
6199  IWX_LSB(128);
6200  dptr++;
6201  }
6202  break;
6203 # if defined(Q_WS_WIN)
6205  while (dptr < maxp) {
6206  IWX_PIX(128);
6207  IWX_PIX(64);
6208  IWX_PIX(32);
6209  IWX_PIX(16);
6210  IWX_PIX(8);
6211  IWX_PIX(4);
6212  IWX_PIX(2);
6213  IWX_PIX(1);
6214  dptr++;
6215  }
6216  break;
6217 # endif
6218  }
6219  }
6220  m21ydx += m21;
6221  m22ydy += m22;
6222  dptr += p_inc;
6223  }
6224  return true;
6225 }
#define IWX_PIX(b)
Definition: qimage.cpp:6092
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
unsigned char uchar
Definition: qglobal.h:994
unsigned int uint
Definition: qglobal.h:996
#define QT_XFORM_TYPE_MSBFIRST
#define QT_XFORM_TYPE_LSBFIRST
#define IWX_MSB(b)
Definition: qimage.cpp:6074
unsigned short ushort
Definition: qglobal.h:995
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
#define QT_XFORM_TYPE_WINDOWSPIXMAP
#define IWX_LSB(b)
Definition: qimage.cpp:6083
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237

◆ rotated180()

static QImage rotated180 ( const QImage src)
static

Definition at line 6681 of file qimage.cpp.

Referenced by QImage::transformed().

6681  {
6682  return image.mirrored(true, true);
6683 }

◆ rotated270()

static QImage rotated270 ( const QImage src)
static

Definition at line 6686 of file qimage.cpp.

Referenced by QImage::transformed().

6686  {
6687  QImage out(image.height(), image.width(), image.format());
6689  if (image.colorCount() > 0)
6690  out.setColorTable(image.colorTable());
6691  int w = image.width();
6692  int h = image.height();
6693  switch (image.format()) {
6694  case QImage::Format_RGB32:
6695  case QImage::Format_ARGB32:
6697  qt_memrotate90(reinterpret_cast<const quint32*>(image.bits()),
6698  w, h, image.bytesPerLine(),
6699  reinterpret_cast<quint32*>(out.bits()),
6700  out.bytesPerLine());
6701  break;
6702  case QImage::Format_RGB666:
6706  case QImage::Format_RGB888:
6707  qt_memrotate90(reinterpret_cast<const quint24*>(image.bits()),
6708  w, h, image.bytesPerLine(),
6709  reinterpret_cast<quint24*>(out.bits()),
6710  out.bytesPerLine());
6711  break;
6712  case QImage::Format_RGB555:
6713  case QImage::Format_RGB16:
6715  qt_memrotate90(reinterpret_cast<const quint16*>(image.bits()),
6716  w, h, image.bytesPerLine(),
6717  reinterpret_cast<quint16*>(out.bits()),
6718  out.bytesPerLine());
6719  break;
6721  qt_memrotate90(reinterpret_cast<const quint8*>(image.bits()),
6722  w, h, image.bytesPerLine(),
6723  reinterpret_cast<quint8*>(out.bits()),
6724  out.bytesPerLine());
6725  break;
6726  default:
6727  for (int y=0; y<h; ++y) {
6728  if (image.colorCount())
6729  for (int x=0; x<w; ++x)
6730  out.setPixel(y, w-x-1, image.pixelIndex(x, y));
6731  else
6732  for (int x=0; x<w; ++x)
6733  out.setPixel(y, w-x-1, image.pixel(x, y));
6734  }
6735  break;
6736  }
6737  return out;
6738 }
unsigned char quint8
Definition: qglobal.h:934
void Q_GUI_EXPORT qt_memrotate90(const quint32 *, int, int, int, quint32 *, int)
unsigned short quint16
Definition: qglobal.h:936
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int quint32
Definition: qglobal.h:938
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105

◆ rotated90()

static QImage rotated90 ( const QImage src)
static

Definition at line 6626 of file qimage.cpp.

Referenced by QImage::transformed().

6626  {
6627  QImage out(image.height(), image.width(), image.format());
6629  if (image.colorCount() > 0)
6630  out.setColorTable(image.colorTable());
6631  int w = image.width();
6632  int h = image.height();
6633  switch (image.format()) {
6634  case QImage::Format_RGB32:
6635  case QImage::Format_ARGB32:
6637  qt_memrotate270(reinterpret_cast<const quint32*>(image.bits()),
6638  w, h, image.bytesPerLine(),
6639  reinterpret_cast<quint32*>(out.bits()),
6640  out.bytesPerLine());
6641  break;
6642  case QImage::Format_RGB666:
6646  case QImage::Format_RGB888:
6647  qt_memrotate270(reinterpret_cast<const quint24*>(image.bits()),
6648  w, h, image.bytesPerLine(),
6649  reinterpret_cast<quint24*>(out.bits()),
6650  out.bytesPerLine());
6651  break;
6652  case QImage::Format_RGB555:
6653  case QImage::Format_RGB16:
6655  qt_memrotate270(reinterpret_cast<const quint16*>(image.bits()),
6656  w, h, image.bytesPerLine(),
6657  reinterpret_cast<quint16*>(out.bits()),
6658  out.bytesPerLine());
6659  break;
6661  qt_memrotate270(reinterpret_cast<const quint8*>(image.bits()),
6662  w, h, image.bytesPerLine(),
6663  reinterpret_cast<quint8*>(out.bits()),
6664  out.bytesPerLine());
6665  break;
6666  default:
6667  for (int y=0; y<h; ++y) {
6668  if (image.colorCount())
6669  for (int x=0; x<w; ++x)
6670  out.setPixel(h-y-1, x, image.pixelIndex(x, y));
6671  else
6672  for (int x=0; x<w; ++x)
6673  out.setPixel(h-y-1, x, image.pixel(x, y));
6674  }
6675  break;
6676  }
6677  return out;
6678 }
unsigned char quint8
Definition: qglobal.h:934
unsigned short quint16
Definition: qglobal.h:936
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void Q_GUI_QWS_EXPORT qt_memrotate270(const quint32 *, int, int, int, quint32 *, int)
unsigned int quint32
Definition: qglobal.h:938
#define QIMAGE_SANITYCHECK_MEMORY(image)
Definition: qimage.cpp:105

◆ smoothScaled()

static QImage smoothScaled ( const QImage source,
int  w,
int  h 
)
static

Definition at line 6611 of file qimage.cpp.

Referenced by QImage::transformed().

6611  {
6612  QImage src = source;
6613  if (src.format() == QImage::Format_ARGB32)
6615  else if (src.depth() < 32) {
6616  if (src.hasAlphaChannel())
6618  else
6620  }
6621 
6622  return qSmoothScaleImage(src, w, h);
6623 }
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
QImage qSmoothScaleImage(const QImage &src, int dw, int dh)

◆ swap_bit_order()

static void swap_bit_order ( QImageData dest,
const QImageData src,
Qt::ImageConversionFlags   
)
static

Definition at line 2711 of file qimage.cpp.

2712 {
2715  Q_ASSERT(src->width == dest->width);
2716  Q_ASSERT(src->height == dest->height);
2717  Q_ASSERT(src->nbytes == dest->nbytes);
2718  Q_ASSERT(src->bytes_per_line == dest->bytes_per_line);
2719 
2720  dest->colortable = src->colortable;
2721 
2722  const uchar *src_data = src->data;
2723  const uchar *end = src->data + src->nbytes;
2724  uchar *dest_data = dest->data;
2725  while (src_data < end) {
2726  *dest_data = bitflip[*src_data];
2727  ++src_data;
2728  ++dest_data;
2729  }
2730 }
int width
Definition: qimage_p.h:76
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVector< QRgb > colortable
Definition: qimage_p.h:80
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
int nbytes
Definition: qimage_p.h:79
int bytes_per_line
Definition: qimage_p.h:86
static const uchar bitflip[256]
Definition: qimage.cpp:736
QImage::Format format
Definition: qimage_p.h:85
uchar * data
Definition: qimage_p.h:81
static const KeyPair *const end

Variable Documentation

◆ bitflip

const uchar bitflip[256]
static
Initial value:
= {
0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
}

Definition at line 736 of file qimage.cpp.

Referenced by dither_to_Mono(), QImage::mirrored(), qt_get_bitflip_array(), QImage::setPixel(), and swap_bit_order().

◆ converter_map

Image_Converter converter_map[QImage::NImageFormats][QImage::NImageFormats]
static

Definition at line 3513 of file qimage.cpp.

◆ inplace_converter_map

InPlace_Image_Converter inplace_converter_map[QImage::NImageFormats][QImage::NImageFormats]
static

Definition at line 3812 of file qimage.cpp.

◆ qimage_serial_number

QBasicAtomicInt qimage_serial_number = Q_BASIC_ATOMIC_INITIALIZER(1)

Definition at line 127 of file qimage.cpp.