Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QImageData Struct Reference

#include <qimage_p.h>

Public Functions

bool checkForAlphaPixels () const
 
bool convertInPlace (QImage::Format newFormat, Qt::ImageConversionFlags)
 
bool doImageIO (const QImage *image, QImageWriter *io, int quality) const
 
 QImageData ()
 
 ~QImageData ()
 

Static Public Functions

static QImageDatacreate (const QSize &size, QImage::Format format, int numColors=0)
 
static QImageDatacreate (uchar *data, int w, int h, int bpl, QImage::Format format, bool readOnly)
 

Public Variables

int bytes_per_line
 
QVector< QRgbcolortable
 
uchardata
 
int depth
 
int detach_no
 
qreal dpmx
 
qreal dpmy
 
QImage::Format format
 
uint has_alpha_clut: 1
 
int height
 
uint is_cached: 1
 
int nbytes
 
QPoint offset
 
uint own_data: 1
 
QPaintEnginepaintEngine
 
QAtomicInt ref
 
uint ro_data: 1
 
int ser_no
 
QMap< QString, QStringtext
 
int width
 

Detailed Description

Definition at line 68 of file qimage_p.h.

Constructors and Destructors

◆ QImageData()

QImageData::QImageData ( )

Definition at line 129 of file qimage.cpp.

130  : ref(0), width(0), height(0), depth(0), nbytes(0), data(0),
131 #ifdef QT3_SUPPORT
132  jumptable(0),
133 #endif
136  detach_no(0),
137  dpmx(qt_defaultDpiX() * 100 / qreal(2.54)),
138  dpmy(qt_defaultDpiY() * 100 / qreal(2.54)),
139  offset(0, 0), own_data(true), ro_data(false), has_alpha_clut(false),
140  is_cached(false), paintEngine(0)
141 {
142 }
int width
Definition: qimage_p.h:76
qreal dpmy
Definition: qimage_p.h:91
double qreal
Definition: qglobal.h:1193
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
uint has_alpha_clut
Definition: qimage_p.h:96
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
int detach_no
Definition: qimage_p.h:88
int height
Definition: qimage_p.h:77
qreal dpmx
Definition: qimage_p.h:90
int ser_no
Definition: qimage_p.h:87
QPaintEngine * paintEngine
Definition: qimage_p.h:110
QBasicAtomicInt qimage_serial_number
Definition: qimage.cpp:127
int nbytes
Definition: qimage_p.h:79
int bytes_per_line
Definition: qimage_p.h:86
uint own_data
Definition: qimage_p.h:94
QImage::Format format
Definition: qimage_p.h:85
uint ro_data
Definition: qimage_p.h:95
QPoint offset
Definition: qimage_p.h:92
int fetchAndAddRelaxed(int valueToAdd)
uchar * data
Definition: qimage_p.h:81
QAtomicInt ref
Definition: qimage_p.h:74
int depth
Definition: qimage_p.h:78
uint is_cached
Definition: qimage_p.h:97

◆ ~QImageData()

QImageData::~QImageData ( )

Definition at line 220 of file qimage.cpp.

221 {
222  if (is_cached)
224  delete paintEngine;
225  if (data && own_data)
226  free(data);
227 #ifdef QT3_SUPPORT
228  if (jumptable)
229  free(jumptable);
230  jumptable = 0;
231 #endif
232  data = 0;
233 }
static void executeImageHooks(qint64 key)
int detach_no
Definition: qimage_p.h:88
int ser_no
Definition: qimage_p.h:87
QPaintEngine * paintEngine
Definition: qimage_p.h:110
__int64 qint64
Definition: qglobal.h:942
uint own_data
Definition: qimage_p.h:94
uchar * data
Definition: qimage_p.h:81
uint is_cached
Definition: qimage_p.h:97

Functions

◆ checkForAlphaPixels()

bool QImageData::checkForAlphaPixels ( ) const

Definition at line 236 of file qimage.cpp.

Referenced by QVGPixmapData::idealFormat().

237 {
238  bool has_alpha_pixels = false;
239 
240  switch (format) {
241 
242  case QImage::Format_Mono:
245  has_alpha_pixels = has_alpha_clut;
246  break;
247 
250  uchar *bits = data;
251  for (int y=0; y<height && !has_alpha_pixels; ++y) {
252  for (int x=0; x<width; ++x)
253  has_alpha_pixels |= (((uint *)bits)[x] & 0xff000000) != 0xff000000;
254  bits += bytes_per_line;
255  }
256  } break;
257 
260  uchar *bits = data;
261  uchar *end_bits = data + bytes_per_line;
262 
263  for (int y=0; y<height && !has_alpha_pixels; ++y) {
264  while (bits < end_bits) {
265  has_alpha_pixels |= bits[0] != 0;
266  bits += 3;
267  }
268  bits = end_bits;
269  end_bits += bytes_per_line;
270  }
271  } break;
272 
274  uchar *bits = data;
275  uchar *end_bits = data + bytes_per_line;
276 
277  for (int y=0; y<height && !has_alpha_pixels; ++y) {
278  while (bits < end_bits) {
279  has_alpha_pixels |= (bits[0] & 0xfc) != 0;
280  bits += 3;
281  }
282  bits = end_bits;
283  end_bits += bytes_per_line;
284  }
285  } break;
286 
288  uchar *bits = data;
289  uchar *end_bits = data + bytes_per_line;
290 
291  for (int y=0; y<height && !has_alpha_pixels; ++y) {
292  while (bits < end_bits) {
293  has_alpha_pixels |= (bits[0] & 0xf0) != 0;
294  bits += 2;
295  }
296  bits = end_bits;
297  end_bits += bytes_per_line;
298  }
299  } break;
300 
301  default:
302  break;
303  }
304 
305  return has_alpha_pixels;
306 }
int width
Definition: qimage_p.h:76
uint has_alpha_clut
Definition: qimage_p.h:96
unsigned char uchar
Definition: qglobal.h:994
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

◆ convertInPlace()

bool QImageData::convertInPlace ( QImage::Format  newFormat,
Qt::ImageConversionFlags  flags 
)

Definition at line 6935 of file qimage.cpp.

Referenced by QRasterPixmapData::createPixmapForImage(), QVGPixmapData::createPixmapForImage(), and QGLPixmapData::createPixmapForImage().

6936 {
6937  if (format == newFormat)
6938  return true;
6939 
6940  // No in-place conversion if we have to detach
6941  if (ref > 1)
6942  return false;
6943 
6944  const InPlace_Image_Converter *const converterPtr = &inplace_converter_map[format][newFormat];
6945  InPlace_Image_Converter converter = *converterPtr;
6946  if (converter)
6947  return converter(this, flags);
6948  else
6949  return false;
6950 }
QImage::Format format
Definition: qimage_p.h:85
bool(* InPlace_Image_Converter)(QImageData *data, Qt::ImageConversionFlags)
Definition: qimage.cpp:2434
QAtomicInt ref
Definition: qimage_p.h:74
static InPlace_Image_Converter inplace_converter_map[QImage::NImageFormats][QImage::NImageFormats]
Definition: qimage.cpp:3812

◆ create() [1/2]

QImageData * QImageData::create ( const QSize size,
QImage::Format  format,
int  numColors = 0 
)
static
Warning
This function is not part of the public interface.

Creates a new image data. Returns 0 if invalid parameters are give or anything else failed.

Definition at line 151 of file qimage.cpp.

Referenced by convert_ARGB_PM_to_Indexed8(), convert_ARGB_PM_to_Mono(), convert_RGB_to_Indexed8(), QImage::format(), and QImage::QImage().

152 {
153  if (!size.isValid() || numColors < 0 || format == QImage::Format_Invalid)
154  return 0; // invalid parameter(s)
155 
156  if (!checkPixelSize(format)) {
157  qWarning("QImageData::create(): Invalid pixel size for format %i",
158  format);
159  return 0;
160  }
161 
162  uint width = size.width();
163  uint height = size.height();
165 
166  switch (format) {
167  case QImage::Format_Mono:
169  numColors = 2;
170  break;
172  numColors = qBound(0, numColors, 256);
173  break;
174  default:
175  numColors = 0;
176  break;
177  }
178 
179  const int bytes_per_line = ((width * depth + 31) >> 5) << 2; // bytes per scanline (must be multiple of 4)
180 
181  // sanity check for potential overflows
182  if (INT_MAX/depth < width
183  || bytes_per_line <= 0
184  || height <= 0
185  || INT_MAX/uint(bytes_per_line) < height
186  || INT_MAX/sizeof(uchar *) < uint(height))
187  return 0;
188 
190  d->colortable.resize(numColors);
191  if (depth == 1) {
192  d->colortable[0] = QColor(Qt::black).rgba();
193  d->colortable[1] = QColor(Qt::white).rgba();
194  } else {
195  for (int i = 0; i < numColors; ++i)
196  d->colortable[i] = 0;
197  }
198 
199  d->width = width;
200  d->height = height;
201  d->depth = depth;
202  d->format = format;
203  d->has_alpha_clut = false;
204  d->is_cached = false;
205 
206  d->bytes_per_line = bytes_per_line;
207 
208  d->nbytes = d->bytes_per_line*height;
209  d->data = (uchar *)malloc(d->nbytes);
210 
211  if (!d->data) {
212  return 0;
213  }
214 
215  d->ref.ref();
216  return d.take();
217 
218 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
int width
Definition: qimage_p.h:76
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
unsigned char uchar
Definition: qglobal.h:994
int width() const
Returns the width.
Definition: qsize.h:126
int height
Definition: qimage_p.h:77
static bool checkPixelSize(const QImage::Format format)
Definition: qimage.cpp:76
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
int bytes_per_line
Definition: qimage_p.h:86
QImage::Format format
Definition: qimage_p.h:85
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
int height() const
Returns the height.
Definition: qsize.h:129
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
int qt_depthForFormat(QImage::Format format)
Definition: qimage_p.h:116
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
int depth
Definition: qimage_p.h:78
#define INT_MAX

◆ create() [2/2]

QImageData * QImageData::create ( uchar data,
int  w,
int  h,
int  bpl,
QImage::Format  format,
bool  readOnly 
)
static

Definition at line 837 of file qimage.cpp.

838 {
839  QImageData *d = 0;
840 
842  return d;
843 
844  if (!checkPixelSize(format)) {
845  qWarning("QImageData::create(): Invalid pixel size for format %i",
846  format);
847  return 0;
848  }
849 
850  const int depth = qt_depthForFormat(format);
851  const int calc_bytes_per_line = ((width * depth + 31)/32) * 4;
852  const int min_bytes_per_line = (width * depth + 7)/8;
853 
854  if (bpl <= 0)
855  bpl = calc_bytes_per_line;
856 
857  if (width <= 0 || height <= 0 || !data
858  || INT_MAX/sizeof(uchar *) < uint(height)
859  || INT_MAX/uint(depth) < uint(width)
860  || bpl <= 0
861  || height <= 0
862  || bpl < min_bytes_per_line
863  || INT_MAX/uint(bpl) < uint(height))
864  return d; // invalid parameter(s)
865 
866  d = new QImageData;
867  d->ref.ref();
868 
869  d->own_data = false;
870  d->ro_data = readOnly;
871  d->data = data;
872  d->width = width;
873  d->height = height;
874  d->depth = depth;
875  d->format = format;
876 
877  d->bytes_per_line = bpl;
878  d->nbytes = d->bytes_per_line * height;
879 
880  return d;
881 }
double d
Definition: qnumeric_p.h:62
int width
Definition: qimage_p.h:76
bool ref()
Atomically increments the value of this QAtomicInt.
unsigned char uchar
Definition: qglobal.h:994
int height
Definition: qimage_p.h:77
static bool checkPixelSize(const QImage::Format format)
Definition: qimage.cpp:76
QImageData()
Definition: qimage.cpp:129
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
int nbytes
Definition: qimage_p.h:79
int bytes_per_line
Definition: qimage_p.h:86
uint own_data
Definition: qimage_p.h:94
QImage::Format format
Definition: qimage_p.h:85
uint ro_data
Definition: qimage_p.h:95
uchar * data
Definition: qimage_p.h:81
QAtomicInt ref
Definition: qimage_p.h:74
int qt_depthForFormat(QImage::Format format)
Definition: qimage_p.h:116
int depth
Definition: qimage_p.h:78
#define INT_MAX

◆ doImageIO()

bool QImageData::doImageIO ( const QImage image,
QImageWriter io,
int  quality 
) const

Definition at line 5379 of file qimage.cpp.

Referenced by QImage::save().

5380 {
5381  if (quality > 100 || quality < -1)
5382  qWarning("QPixmap::save: Quality out of range [-1, 100]");
5383  if (quality >= 0)
5384  writer->setQuality(qMin(quality,100));
5385  return writer->write(*image);
5386 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_CORE_EXPORT void qWarning(const char *,...)

Properties

◆ bytes_per_line

int QImageData::bytes_per_line

◆ colortable

QVector<QRgb> QImageData::colortable

◆ data

uchar* QImageData::data

◆ depth

int QImageData::depth

◆ detach_no

int QImageData::detach_no

Definition at line 88 of file qimage_p.h.

Referenced by QImage::detach(), and ~QImageData().

◆ dpmx

qreal QImageData::dpmx

Definition at line 90 of file qimage_p.h.

Referenced by QImage::copy(), and QImage::transformed().

◆ dpmy

qreal QImageData::dpmy

Definition at line 91 of file qimage_p.h.

Referenced by QImage::copy(), and QImage::transformed().

◆ format

QImage::Format QImageData::format

◆ has_alpha_clut

uint QImageData::has_alpha_clut

◆ height

int QImageData::height

◆ is_cached

uint QImageData::is_cached

Definition at line 97 of file qimage_p.h.

Referenced by create(), QImage::detach(), and ~QImageData().

◆ nbytes

int QImageData::nbytes

◆ offset

QPoint QImageData::offset

Definition at line 92 of file qimage_p.h.

Referenced by QImage::copy().

◆ own_data

uint QImageData::own_data

◆ paintEngine

QPaintEngine* QImageData::paintEngine

◆ ref

QAtomicInt QImageData::ref

◆ ro_data

uint QImageData::ro_data

Definition at line 95 of file qimage_p.h.

Referenced by create(), and QImage::detach().

◆ ser_no

int QImageData::ser_no

Definition at line 87 of file qimage_p.h.

Referenced by ~QImageData().

◆ text

QMap<QString, QString> QImageData::text

Definition at line 106 of file qimage_p.h.

Referenced by QImage::convertToFormat(), and QImage::copy().

◆ width

int QImageData::width

The documentation for this struct was generated from the following files: