Qt 4.8
qpixmap_mac.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qpixmap.h"
43 #include "qimage.h"
44 #include "qapplication.h"
45 #include "qbitmap.h"
46 #include "qmatrix.h"
47 #include "qtransform.h"
48 #include "qlibrary.h"
49 #include "qvarlengtharray.h"
50 #include "qdebug.h"
51 #include <private/qdrawhelper_p.h>
52 #include <private/qpixmap_mac_p.h>
53 #include <private/qpixmap_raster_p.h>
54 #include <private/qpaintengine_mac_p.h>
55 #include <private/qt_mac_p.h>
56 #include <private/qt_cocoa_helpers_mac_p.h>
57 #include <private/qapplication_p.h>
58 
59 #include <limits.h>
60 #include <string.h>
61 
63 
64 /*****************************************************************************
65  Externals
66  *****************************************************************************/
67 extern const uchar *qt_get_bitflip_array(); //qimage.cpp
68 extern CGContextRef qt_mac_cg_context(const QPaintDevice *pdev); //qpaintdevice_mac.cpp
69 extern RgnHandle qt_mac_get_rgn(); //qregion_mac.cpp
70 extern void qt_mac_dispose_rgn(RgnHandle r); //qregion_mac.cpp
71 extern QRegion qt_mac_convert_mac_region(RgnHandle rgn); //qregion_mac.cpp
72 
73 static int qt_pixmap_serial = 0;
74 
76 {
78  return reinterpret_cast<quint32 *>(static_cast<QRasterPixmapData*>(pix->data.data())->buffer()->bits());
79  else
80  return static_cast<QMacPixmapData*>(pix->data.data())->pixels;
81 }
82 
84 {
86  return static_cast<QRasterPixmapData*>(pix->data.data())->buffer()->bytesPerLine();
87  else
88  return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow;
89 }
90 
91 void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t)
92 {
93  QMacPixmapData *pmdata = static_cast<QMacPixmapData *>(info);
94  if (!pmdata) {
95  free(const_cast<void *>(memoryToFree));
96  } else {
97  if (QMacPixmapData::validDataPointers.contains(pmdata) == false) {
98  free(const_cast<void *>(memoryToFree));
99  // mark data as freed
100  if (pmdata->pixels == memoryToFree)
101  pmdata->pixels = 0;
102  if (pmdata->pixelsToFree == memoryToFree)
103  pmdata->pixelsToFree = 0;
104  return;
105  }
106  if (pmdata->pixels == pmdata->pixelsToFree) {
107  // something we aren't expecting, just free it.
108  Q_ASSERT(memoryToFree != pmdata->pixelsToFree);
109  free(const_cast<void *>(memoryToFree));
110  } else {
111  free(pmdata->pixelsToFree);
112  pmdata->pixelsToFree = static_cast<quint32 *>(const_cast<void *>(memoryToFree));
113  }
114  pmdata->cg_dataBeingReleased = 0;
115  }
116 }
117 
119 {
120  int bitsPerColor = 8;
121  int bitsPerPixel = 32;
122  if (image.depth() == 1) {
123  bitsPerColor = 1;
124  bitsPerPixel = 1;
125  }
126  QCFType<CGDataProviderRef> provider =
127  CGDataProviderCreateWithData(0, image.bits(), image.bytesPerLine() * image.height(),
128  0);
129 
130  uint cgflags = kCGImageAlphaPremultipliedFirst;
131 #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
132  cgflags |= kCGBitmapByteOrder32Host;
133 #endif
134 
135  CGImageRef cgImage = CGImageCreate(image.width(), image.height(), bitsPerColor, bitsPerPixel,
136  image.bytesPerLine(),
138  cgflags, provider,
139  0,
140  0,
141  kCGRenderingIntentDefault);
142 
143  return cgImage;
144 }
145 
146 /*****************************************************************************
147  QPixmap member functions
148  *****************************************************************************/
149 
150 static inline QRgb qt_conv16ToRgb(ushort c) {
151  static const int qt_rbits = (565/100);
152  static const int qt_gbits = (565/10%10);
153  static const int qt_bbits = (565%10);
154  static const int qt_red_shift = qt_bbits+qt_gbits-(8-qt_rbits);
155  static const int qt_green_shift = qt_bbits-(8-qt_gbits);
156  static const int qt_neg_blue_shift = 8-qt_bbits;
157  static const int qt_blue_mask = (1<<qt_bbits)-1;
158  static const int qt_green_mask = (1<<(qt_gbits+qt_bbits))-((1<<qt_bbits)-1);
159  static const int qt_red_mask = (1<<(qt_rbits+qt_gbits+qt_bbits))-(1<<(qt_gbits+qt_bbits));
160 
161  const int r=(c & qt_red_mask);
162  const int g=(c & qt_green_mask);
163  const int b=(c & qt_blue_mask);
164  const int tr = r >> qt_red_shift;
165  const int tg = g >> qt_green_shift;
166  const int tb = b << qt_neg_blue_shift;
167 
168  return qRgb(tr,tg,tb);
169 }
170 
172 
174  : QPixmapData(type, MacClass), has_alpha(0), has_mask(0),
175  uninit(true), pixels(0), pixelsSize(0), pixelsToFree(0),
176  bytesPerRow(0), cg_data(0), cg_dataBeingReleased(0), cg_mask(0),
177  pengine(0)
178 {
179 }
180 
182 {
183  return new QMacPixmapData(pixelType());
184 }
185 
186 #define BEST_BYTE_ALIGNMENT 16
187 #define COMPTUE_BEST_BYTES_PER_ROW(bpr) \
188  (((bpr) + (BEST_BYTE_ALIGNMENT - 1)) & ~(BEST_BYTE_ALIGNMENT - 1))
189 
191 {
193 
194  w = width;
195  h = height;
196  is_null = (w <= 0 || h <= 0);
197  d = (pixelType() == BitmapType ? 1 : 32);
198  bool make_null = w <= 0 || h <= 0; // create null pixmap
199  if (make_null || d == 0) {
200  w = 0;
201  h = 0;
202  is_null = true;
203  d = 0;
204  if (!make_null)
205  qWarning("Qt: QPixmap: Invalid pixmap parameters");
206  return;
207  }
208 
209  if (w < 1 || h < 1)
210  return;
211 
212  //create the pixels
213  bytesPerRow = w * sizeof(quint32); // Minimum bytes per row.
214 
215  // Quartz2D likes things as a multple of 16 (for now).
217  macCreatePixels();
218 }
219 
220 #undef COMPUTE_BEST_BYTES_PER_ROW
221 
223  Qt::ImageConversionFlags flags)
224 {
226 
227  // the conversion code only handles format >=
228  // Format_ARGB32_Premultiplied at the moment..
230  QImage image;
231  if (img.hasAlphaChannel())
233  else
235  fromImage(image, flags);
236  return;
237  }
238 
239  w = img.width();
240  h = img.height();
241  is_null = (w <= 0 || h <= 0);
242  d = (pixelType() == BitmapType ? 1 : img.depth());
243 
244  QImage image = img;
245  int dd = QPixmap::defaultDepth();
246  bool force_mono = (dd == 1 ||
247  (flags & Qt::ColorMode_Mask)==Qt::MonoOnly);
248  if (force_mono) { // must be monochrome
249  if (d != 1) {
250  image = image.convertToFormat(QImage::Format_MonoLSB, flags); // dither
251  d = 1;
252  }
253  } else { // can be both
254  bool conv8 = false;
255  if(d > 8 && dd <= 8) { // convert to 8 bit
256  if ((flags & Qt::DitherMode_Mask) == Qt::AutoDither)
257  flags = (flags & ~Qt::DitherMode_Mask)
259  conv8 = true;
260  } else if ((flags & Qt::ColorMode_Mask) == Qt::ColorOnly) {
261  conv8 = d == 1; // native depth wanted
262  } else if (d == 1) {
263  if (image.colorCount() == 2) {
264  QRgb c0 = image.color(0); // Auto: convert to best
265  QRgb c1 = image.color(1);
266  conv8 = qMin(c0,c1) != qRgb(0,0,0) || qMax(c0,c1) != qRgb(255,255,255);
267  } else {
268  // eg. 1-color monochrome images (they do exist).
269  conv8 = true;
270  }
271  }
272  if (conv8) {
273  image = image.convertToFormat(QImage::Format_Indexed8, flags);
274  d = 8;
275  }
276  }
277 
278  if (image.depth()==1) {
279  image.setColor(0, QColor(Qt::color0).rgba());
280  image.setColor(1, QColor(Qt::color1).rgba());
281  }
282 
283  if (d == 16 || d == 24) {
284  image = image.convertToFormat(QImage::Format_RGB32, flags);
285  fromImage(image, flags);
286  return;
287  }
288 
289  // different size or depth, make a new pixmap
290  resize(w, h);
291 
292  // exit if resize failed
293  if (is_null)
294  return;
295 
296  quint32 *dptr = pixels, *drow;
297  const uint dbpr = bytesPerRow;
298 
299  const QImage::Format sfmt = image.format();
300  const unsigned short sbpr = image.bytesPerLine();
301 
302  // use const_cast to prevent a detach
303  const uchar *sptr = const_cast<const QImage &>(image).bits(), *srow;
304 
305  for (int y = 0; y < h; ++y) {
306  drow = dptr + (y * (dbpr / 4));
307  srow = sptr + (y * sbpr);
308  switch(sfmt) {
310  case QImage::Format_Mono:{
311  for (int x = 0; x < w; ++x) {
312  char one_bit = *(srow + (x / 8));
313  if (sfmt == QImage::Format_Mono)
314  one_bit = one_bit >> (7 - (x % 8));
315  else
316  one_bit = one_bit >> (x % 8);
317  if ((one_bit & 0x01))
318  *(drow+x) = 0xFF000000;
319  else
320  *(drow+x) = 0xFFFFFFFF;
321  }
322  break;
323  }
325  int numColors = image.numColors();
326  if (numColors > 0) {
327  for (int x = 0; x < w; ++x) {
328  int index = *(srow + x);
329  *(drow+x) = PREMUL(image.color(qMin(index, numColors)));
330  }
331  }
332  } break;
334  for (int x = 0; x < w; ++x)
335  *(drow+x) = *(((quint32*)srow) + x) | 0xFF000000;
336  break;
339  for (int x = 0; x < w; ++x) {
340  if(sfmt == QImage::Format_RGB32)
341  *(drow+x) = 0xFF000000 | (*(((quint32*)srow) + x) & 0x00FFFFFF);
342  else if(sfmt == QImage::Format_ARGB32_Premultiplied)
343  *(drow+x) = *(((quint32*)srow) + x);
344  else
345  *(drow+x) = PREMUL(*(((quint32*)srow) + x));
346  }
347  break;
348  default:
349  qWarning("Qt: internal: Oops: Forgot a format [%d] %s:%d", sfmt,
350  __FILE__, __LINE__);
351  break;
352  }
353  }
354  if (sfmt != QImage::Format_RGB32) { //setup the alpha
355  bool alphamap = image.depth() == 32;
356  if (sfmt == QImage::Format_Indexed8) {
357  const QVector<QRgb> rgb = image.colorTable();
358  for (int i = 0, count = image.colorCount(); i < count; ++i) {
359  const int alpha = qAlpha(rgb[i]);
360  if (alpha != 0xff) {
361  alphamap = true;
362  break;
363  }
364  }
365  }
366  macSetHasAlpha(alphamap);
367  }
368  uninit = false;
369 }
370 
371 int get_index(QImage * qi,QRgb mycol)
372 {
373  int loopc;
374  for(loopc=0;loopc<qi->colorCount();loopc++) {
375  if(qi->color(loopc)==mycol)
376  return loopc;
377  }
378  qi->setColorCount(qi->colorCount()+1);
379  qi->setColor(qi->colorCount(),mycol);
380  return qi->colorCount();
381 }
382 
384 {
386  if (d != 1) //Doesn't support index color modes
389 
390  QImage image(w, h, format);
391  // exit if image was not created (out of memory)
392  if (image.isNull())
393  return image;
394  quint32 *sptr = pixels, *srow;
395  const uint sbpr = bytesPerRow;
396  if (format == QImage::Format_MonoLSB) {
397  image.fill(0);
398  image.setColorCount(2);
399  image.setColor(0, QColor(Qt::color0).rgba());
400  image.setColor(1, QColor(Qt::color1).rgba());
401  for (int y = 0; y < h; ++y) {
402  uchar *scanLine = image.scanLine(y);
403  srow = sptr + (y * (sbpr/4));
404  for (int x = 0; x < w; ++x) {
405  if (!(*(srow + x) & RGB_MASK))
406  scanLine[x >> 3] |= (1 << (x & 7));
407  }
408  }
409  } else {
410  for (int y = 0; y < h; ++y) {
411  srow = sptr + (y * (sbpr / 4));
412  memcpy(image.scanLine(y), srow, w * 4);
413  }
414 
415  }
416 
417  return image;
418 }
419 
420 void QMacPixmapData::fill(const QColor &fillColor)
421 
422 {
423  { //we don't know what backend to use so we cannot paint here
424  quint32 *dptr = pixels;
425  Q_ASSERT_X(dptr, "QPixmap::fill", "No dptr");
426  const quint32 colr = PREMUL(fillColor.rgba());
427  const int nbytes = bytesPerRow * h;
428  if (!colr) {
429  memset(dptr, 0, nbytes);
430  } else {
431  for (uint i = 0; i < nbytes / sizeof(quint32); ++i)
432  *(dptr + i) = colr;
433  }
434  }
435 
436  // If we had an alpha channel from before, don't
437  // switch it off. Only go from no alpha to alpha:
438  if (fillColor.alpha() != 255)
439  macSetHasAlpha(true);
440 }
441 
443 {
444  if (!has_alpha)
445  return QPixmap();
446 
448  alpha->resize(w, h);
449  macGetAlphaChannel(alpha, false);
450  return QPixmap(alpha);
451 }
452 
454 {
455  has_mask = true;
456  QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data.data());
457  macSetAlphaChannel(alphaData, false);
458 }
459 
461 {
462  if (!has_mask && !has_alpha)
463  return QBitmap();
464 
466  mask->resize(w, h);
467  macGetAlphaChannel(mask, true);
468  return QPixmap(mask);
469 }
470 
472 {
473  if (mask.isNull()) {
474  QMacPixmapData opaque(PixmapType);
475  opaque.resize(w, h);
476  opaque.fill(QColor(255, 255, 255, 255));
477  macSetAlphaChannel(&opaque, true);
478  has_alpha = has_mask = false;
479  return;
480  }
481 
482  has_alpha = false;
483  has_mask = true;
484  QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data.data());
485  macSetAlphaChannel(maskData, true);
486 }
487 
489 {
490  switch (theMetric) {
492  return w;
494  return h;
500  return 1 << d;
503  extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp
504  return int(qt_mac_defaultDpi_x());
505  }
508  extern float qt_mac_defaultDpi_y(); //qpaintdevice_mac.cpp
509  return int(qt_mac_defaultDpi_y());
510  }
512  return d;
513  default:
514  qWarning("QPixmap::metric: Invalid metric command");
515  }
516  return 0;
517 }
518 
520 {
522  if (cg_mask) {
523  CGImageRelease(cg_mask);
524  cg_mask = 0;
525  }
526 
527  delete pengine; // Make sure we aren't drawing on the context anymore.
528  if (cg_data) {
529  CGImageRelease(cg_data);
530  }
531  else if (pixels && (pixels != pixelsToFree))
532  free(pixels);
533  if (pixelsToFree)
534  free(pixelsToFree);
535 }
536 
538 {
539  if (!pixels || !h || !w || pix->w != w || pix->h != h)
540  return;
541 
542  quint32 *dptr = pixels, *drow;
543  const uint dbpr = bytesPerRow;
544  const unsigned short sbpr = pix->bytesPerRow;
545  quint32 *sptr = pix->pixels, *srow;
546  for (int y=0; y < h; ++y) {
547  drow = dptr + (y * (dbpr/4));
548  srow = sptr + (y * (sbpr/4));
549  if(d == 1) {
550  for (int x=0; x < w; ++x) {
551  if((*(srow+x) & RGB_MASK))
552  *(drow+x) = 0xFFFFFFFF;
553  }
554  } else if(d == 8) {
555  for (int x=0; x < w; ++x)
556  *(drow+x) = (*(drow+x) & RGB_MASK) | (*(srow+x) << 24);
557  } else if(asMask) {
558  for (int x=0; x < w; ++x) {
559  if(*(srow+x) & RGB_MASK)
560  *(drow+x) = (*(drow+x) & RGB_MASK);
561  else
562  *(drow+x) = (*(drow+x) & RGB_MASK) | 0xFF000000;
563  *(drow+x) = PREMUL(*(drow+x));
564  }
565  } else {
566  for (int x=0; x < w; ++x) {
567  const uchar alpha = qGray(qRed(*(srow+x)), qGreen(*(srow+x)), qBlue(*(srow+x)));
568  const uchar destAlpha = qt_div_255(alpha * qAlpha(*(drow+x)));
569 #if 1
570  *(drow+x) = (*(drow+x) & RGB_MASK) | (destAlpha << 24);
571 #else
572  *(drow+x) = qRgba(qt_div_255(qRed(*(drow+x) * alpha)),
573  qt_div_255(qGreen(*(drow+x) * alpha)),
574  qt_div_255(qBlue(*(drow+x) * alpha)), destAlpha);
575 #endif
576  *(drow+x) = PREMUL(*(drow+x));
577  }
578  }
579  }
580  macSetHasAlpha(true);
581 }
582 
584 {
585  quint32 *dptr = pix->pixels, *drow;
586  const uint dbpr = pix->bytesPerRow;
587  const unsigned short sbpr = bytesPerRow;
588  quint32 *sptr = pixels, *srow;
589  for(int y=0; y < h; ++y) {
590  drow = dptr + (y * (dbpr/4));
591  srow = sptr + (y * (sbpr/4));
592  if(asMask) {
593  for (int x = 0; x < w; ++x) {
594  if (*(srow + x) & qRgba(0, 0, 0, 255))
595  *(drow + x) = 0x00000000;
596  else
597  *(drow + x) = 0xFFFFFFFF;
598  }
599  } else {
600  for (int x = 0; x < w; ++x) {
601  const int alpha = qAlpha(*(srow + x));
602  *(drow + x) = qRgb(alpha, alpha, alpha);
603  }
604  }
605  }
606 }
607 
609 {
610  has_alpha = b;
612 }
613 
615 {
616  Q_ASSERT(cg_data == 0);
617  //create the cg data
619  QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(this,
620  pixels, bytesPerRow * h,
623  uint cgflags = kCGImageAlphaPremultipliedFirst;
624 #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version
625  cgflags |= kCGBitmapByteOrder32Host;
626 #endif
627  cg_data = CGImageCreate(w, h, 8, 32, bytesPerRow, colorspace,
628  cgflags, provider, 0, 0, kCGRenderingIntentDefault);
629 }
630 
632 {
633  if (!cg_data)
634  return; // There's nothing we need to do
635 
637  CGImageRelease(cg_data);
638  cg_data = 0;
639 
640  if (pixels != pixelsToFree) {
641  macCreatePixels();
642  } else {
643  pixelsToFree = 0;
644  }
645 }
646 
647 
648 // We create our space in memory to paint on here. If we already have existing pixels
649 // copy them over. This is to preserve the fact that CGImageRef's are immutable.
651 {
652  int numBytes = bytesPerRow * h;
653  quint32 *base_pixels;
654  if (pixelsToFree && pixelsToFree != pixels) {
655  // Reuse unused block of memory lying around from a previous callback.
656  base_pixels = pixelsToFree;
657  pixelsToFree = 0;
658  } else {
659  // We need a block of memory to do stuff with.
660  base_pixels = static_cast<quint32 *>(malloc(numBytes));
661  if (!base_pixels) {
662  qWarning("Failed to allocate memory for pixmap data, setting to NULL");
663  numBytes = 0;
664  w = 0;
665  h = 0;
666  is_null = 0;
667  bytesPerRow=0;
668  }
669  }
670 
671  // only copy when both buffers exist
672  if (pixels && base_pixels)
673  memcpy(base_pixels, pixels, qMin(pixelsSize, (uint) numBytes));
674 
675  // free pixels before assigning new memory
676  if (pixels)
677  free(pixels);
678 
679  pixels = base_pixels;
680  pixelsSize = numBytes;
681 }
682 
683 #if 0
685  Qt::TransformationMode mode) const
686 {
687  int w, h; // size of target pixmap
688  const int ws = width();
689  const int hs = height();
690 
691  QTransform mat(transform.m11(), transform.m12(),
692  transform.m21(), transform.m22(), 0., 0.);
693  if (transform.m12() == 0.0F && transform.m21() == 0.0F &&
694  transform.m11() >= 0.0F && transform.m22() >= 0.0F)
695  {
696  h = int(qAbs(mat.m22()) * hs + 0.9999);
697  w = int(qAbs(mat.m11()) * ws + 0.9999);
698  h = qAbs(h);
699  w = qAbs(w);
700  } else { // rotation or shearing
701  QPolygonF a(QRectF(0,0,ws+1,hs+1));
702  a = mat.map(a);
703  QRectF r = a.boundingRect().normalized();
704  w = int(r.width() + 0.9999);
705  h = int(r.height() + 0.9999);
706  }
707  mat = QPixmap::trueMatrix(mat, ws, hs);
708  if (!h || !w)
709  return QPixmap();
710 
711  // create destination
712  QMacPixmapData *pm = new QMacPixmapData(pixelType(), w, h);
713  const quint32 *sptr = pixels;
714  quint32 *dptr = pm->pixels;
715  memset(dptr, 0, (pm->bytesPerRow * pm->h));
716 
717  // do the transform
718  if (mode == Qt::SmoothTransformation) {
719 #warning QMacPixmapData::transformed not properly implemented
720  qWarning("QMacPixmapData::transformed not properly implemented");
721 #if 0
722  QPainter p(&pm);
725  p.setTransform(mat);
726  p.drawPixmap(0, 0, *this);
727 #endif
728  } else {
729  bool invertible;
730  mat = mat.inverted(&invertible);
731  if (!invertible)
732  return QPixmap();
733 
734  const int bpp = 32;
735  const int xbpl = (w * bpp) / 8;
736  if (!qt_xForm_helper(mat, 0, QT_XFORM_TYPE_MSBFIRST, bpp,
737  (uchar*)dptr, xbpl, (pm->bytesPerRow) - xbpl,
738  h, (uchar*)sptr, (bytesPerRow), ws, hs)) {
739  qWarning("QMacPixmapData::transform(): failure");
740  return QPixmap();
741  }
742  }
743 
744  // update the alpha
745  pm->macSetHasAlpha(true);
746  return QPixmap(pm);
747 }
748 #endif
749 
751 #include <OpenGL/OpenGL.h>
752 #include <OpenGL/gl.h>
754 
755 // Load and resolve the symbols we need from OpenGL manually so QtGui doesn't have to link against the OpenGL framework.
756 typedef CGLError (*PtrCGLChoosePixelFormat)(const CGLPixelFormatAttribute *, CGLPixelFormatObj *, long *);
757 typedef CGLError (*PtrCGLClearDrawable)(CGLContextObj);
758 typedef CGLError (*PtrCGLCreateContext)(CGLPixelFormatObj, CGLContextObj, CGLContextObj *);
759 typedef CGLError (*PtrCGLDestroyContext)(CGLContextObj);
760 typedef CGLError (*PtrCGLDestroyPixelFormat)(CGLPixelFormatObj);
761 typedef CGLError (*PtrCGLSetCurrentContext)(CGLContextObj);
762 typedef CGLError (*PtrCGLSetFullScreen)(CGLContextObj);
763 typedef void (*PtrglFinish)();
764 typedef void (*PtrglPixelStorei)(GLenum, GLint);
765 typedef void (*PtrglReadBuffer)(GLenum);
766 typedef void (*PtrglReadPixels)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *);
767 
779 
780 static bool resolveOpenGLSymbols()
781 {
782  static bool triedResolve = false;
783  if (!triedResolve) {
784  QLibrary library(QLatin1String("/System/Library/Frameworks/OpenGL.framework/OpenGL"));
785  ptrCGLChoosePixelFormat = (PtrCGLChoosePixelFormat)(library.resolve("CGLChoosePixelFormat"));
786  ptrCGLClearDrawable = (PtrCGLClearDrawable)(library.resolve("CGLClearDrawable"));
787  ptrCGLCreateContext = (PtrCGLCreateContext)(library.resolve("CGLCreateContext"));
788  ptrCGLDestroyContext = (PtrCGLDestroyContext)(library.resolve("CGLDestroyContext"));
789  ptrCGLDestroyPixelFormat = (PtrCGLDestroyPixelFormat)(library.resolve("CGLDestroyPixelFormat"));
790  ptrCGLSetCurrentContext = (PtrCGLSetCurrentContext)(library.resolve("CGLSetCurrentContext"));
791  ptrCGLSetFullScreen = (PtrCGLSetFullScreen)(library.resolve("CGLSetFullScreen"));
792  ptrglFinish = (PtrglFinish)(library.resolve("glFinish"));
793  ptrglPixelStorei = (PtrglPixelStorei)(library.resolve("glPixelStorei"));
794  ptrglReadBuffer = (PtrglReadBuffer)(library.resolve("glReadBuffer"));
795  ptrglReadPixels = (PtrglReadPixels)(library.resolve("glReadPixels"));
796  triedResolve = true;
797  }
802 }
803 
804 // Inverts the given pixmap in the y direction.
805 static void qt_mac_flipPixmap(void *data, int rowBytes, int height)
806 {
807  int bottom = height - 1;
808  void *base = data;
809  void *buffer = malloc(rowBytes);
810 
811  int top = 0;
812  while ( top < bottom )
813  {
814  void *topP = (void *)((top * rowBytes) + (intptr_t)base);
815  void *bottomP = (void *)((bottom * rowBytes) + (intptr_t)base);
816 
817  bcopy( topP, buffer, rowBytes );
818  bcopy( bottomP, topP, rowBytes );
819  bcopy( buffer, bottomP, rowBytes );
820 
821  ++top;
822  --bottom;
823  }
824  free(buffer);
825 }
826 
827 // Grabs displayRect from display and places it into buffer.
828 static void qt_mac_grabDisplayRect(CGDirectDisplayID display, const QRect &displayRect, void *buffer)
829 {
830  if (display == kCGNullDirectDisplay)
831  return;
832 
833  CGLPixelFormatAttribute attribs[] = {
834  kCGLPFAFullScreen,
835  kCGLPFADisplayMask,
836  (CGLPixelFormatAttribute)0, /* Display mask bit goes here */
837  (CGLPixelFormatAttribute)0
838  };
839 
840  attribs[2] = (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display);
841 
842  // Build a full-screen GL context
843  CGLPixelFormatObj pixelFormatObj;
844  long numPixelFormats;
845 
846  ptrCGLChoosePixelFormat( attribs, &pixelFormatObj, &numPixelFormats );
847 
848  if (!pixelFormatObj) // No full screen context support
849  return;
850 
851  CGLContextObj glContextObj;
852  ptrCGLCreateContext(pixelFormatObj, 0, &glContextObj);
853  ptrCGLDestroyPixelFormat(pixelFormatObj) ;
854  if (!glContextObj)
855  return;
856 
857  ptrCGLSetCurrentContext(glContextObj);
858  ptrCGLSetFullScreen(glContextObj) ;
859 
861 
862  ptrglFinish(); // Finish all OpenGL commands
863  ptrglPixelStorei(GL_PACK_ALIGNMENT, 4); // Force 4-byte alignment
864  ptrglPixelStorei(GL_PACK_ROW_LENGTH, 0);
865  ptrglPixelStorei(GL_PACK_SKIP_ROWS, 0);
866  ptrglPixelStorei(GL_PACK_SKIP_PIXELS, 0);
867 
868  // Fetch the data in XRGB format, matching the bitmap context.
869  ptrglReadPixels(GLint(displayRect.x()), GLint(displayRect.y()),
870  GLint(displayRect.width()), GLint(displayRect.height()),
871 #ifdef __BIG_ENDIAN__
873 #else
874  GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, buffer
875 #endif
876  );
877 
879  ptrCGLClearDrawable(glContextObj); // disassociate from full screen
880  ptrCGLDestroyContext(glContextObj); // and destroy the context
881 }
882 
883 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
884 // Returns a pixmap containing the screen contents at rect.
885 static QPixmap qt_mac_grabScreenRect_10_6(const QRect &rect)
886 {
887  const int maxDisplays = 128; // 128 displays should be enough for everyone.
888  CGDirectDisplayID displays[maxDisplays];
889  CGDisplayCount displayCount;
890  const CGRect cgRect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
891  const CGDisplayErr err = CGGetDisplaysWithRect(cgRect, maxDisplays, displays, &displayCount);
892 
894  QRect scaledRect = QRect(rect.topLeft(), rect.size() * qt_mac_get_scalefactor());
895 
896  if (err && displayCount == 0)
897  return QPixmap();
898  QPixmap windowPixmap(scaledRect.size());
899  for (uint i = 0; i < displayCount; ++i) {
900  const CGRect bounds = CGDisplayBounds(displays[i]);
901  // Translate to display-local coordinates
902  QRect displayRect = rect.translated(qRound(-bounds.origin.x), qRound(-bounds.origin.y));
903  QCFType<CGImageRef> image = CGDisplayCreateImageForRect(displays[i],
904  CGRectMake(displayRect.x(), displayRect.y(), displayRect.width(), displayRect.height()));
905  QPixmap pix = QPixmap::fromMacCGImageRef(image);
906  QPainter painter(&windowPixmap);
907  painter.drawPixmap(-bounds.origin.x, -bounds.origin.y, pix);
908  }
909  return windowPixmap;
910 }
911 #endif
912 
914 {
915  if (!resolveOpenGLSymbols())
916  return QPixmap();
917 
918  const int maxDisplays = 128; // 128 displays should be enough for everyone.
919  CGDirectDisplayID displays[maxDisplays];
920  CGDisplayCount displayCount;
921  const CGRect cgRect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
922  const CGDisplayErr err = CGGetDisplaysWithRect(cgRect, maxDisplays, displays, &displayCount);
923 
924  if (err && displayCount == 0)
925  return QPixmap();
926 
927  long bytewidth = rect.width() * 4; // Assume 4 bytes/pixel for now
928  bytewidth = (bytewidth + 3) & ~3; // Align to 4 bytes
929  QVarLengthArray<char> buffer(rect.height() * bytewidth);
930 
931  for (uint i = 0; i < displayCount; ++i) {
932  const CGRect bounds = CGDisplayBounds(displays[i]);
933  // Translate to display-local coordinates
934  QRect displayRect = rect.translated(qRound(-bounds.origin.x), qRound(-bounds.origin.y));
935  // Adjust for inverted y axis.
936  displayRect.moveTop(qRound(bounds.size.height) - displayRect.y() - rect.height());
937  qt_mac_grabDisplayRect(displays[i], displayRect, buffer.data());
938  }
939 
940  qt_mac_flipPixmap(buffer.data(), bytewidth, rect.height());
941  QCFType<CGContextRef> bitmap = CGBitmapContextCreate(buffer.data(), rect.width(),
942  rect.height(), 8, bytewidth,
944  kCGImageAlphaNoneSkipFirst);
945  QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap);
946  return QPixmap::fromMacCGImageRef(image);
947 }
948 
949 #ifndef QT_MAC_USE_COCOA // no QuickDraw in 64-bit mode
950 static QPixmap qt_mac_grabScreenRect_10_3(int x, int y, int w, int h, QWidget *widget)
951 {
952  QPixmap pm = QPixmap(w, h);
953  extern WindowPtr qt_mac_window_for(const QWidget *); // qwidget_mac.cpp
954  const BitMap *windowPort = 0;
955  if((widget->windowType() == Qt::Desktop)) {
956  GDHandle gdh;
957  if(!(gdh=GetMainDevice()))
958  qDebug("Qt: internal: Unexpected condition reached: %s:%d", __FILE__, __LINE__);
959  windowPort = (BitMap*)(*(*gdh)->gdPMap);
960  } else {
961  windowPort = GetPortBitMapForCopyBits(GetWindowPort(qt_mac_window_for(widget)));
962  }
963  const BitMap *pixmapPort = GetPortBitMapForCopyBits(static_cast<GWorldPtr>(pm.macQDHandle()));
964  Rect macSrcRect, macDstRect;
965  SetRect(&macSrcRect, x, y, x + w, y + h);
966  SetRect(&macDstRect, 0, 0, w, h);
967  CopyBits(windowPort, pixmapPort, &macSrcRect, &macDstRect, srcCopy, 0);
968  return pm;
969 }
970 #endif
971 
972 QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
973 {
974  QWidget *widget = QWidget::find(window);
975  if (widget == 0)
976  return QPixmap();
977 
978  if(w == -1)
979  w = widget->width() - x;
980  if(h == -1)
981  h = widget->height() - y;
982 
983  QPoint globalCoord(0, 0);
984  globalCoord = widget->mapToGlobal(globalCoord);
985  QRect rect(globalCoord.x() + x, globalCoord.y() + y, w, h);
986 
987 #ifdef QT_MAC_USE_COCOA
988 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
990  return qt_mac_grabScreenRect_10_6(rect);
991  else
992 #endif
993  return qt_mac_grabScreenRect(rect);
994 #else
995 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
997  return qt_mac_grabScreenRect(rect);
998  } else
999 #endif
1000  {
1001  return qt_mac_grabScreenRect_10_3(x, y, w, h, widget);
1002  }
1003 #endif // ifdef Q_WS_MAC64
1004 }
1005 
1019 Qt::HANDLE QPixmap::macQDHandle() const
1020 {
1021  return 0;
1022 }
1023 
1037 Qt::HANDLE QPixmap::macQDAlphaHandle() const
1038 {
1039  return 0;
1040 }
1041 
1054 Qt::HANDLE QPixmap::macCGHandle() const
1055 {
1056  if (isNull())
1057  return 0;
1058 
1059  if (data->classId() == QPixmapData::MacClass) {
1060  QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data());
1061  if (!d->cg_data)
1062  d->macCreateCGImageRef();
1063  CGImageRef ret = d->cg_data;
1064  CGImageRetain(ret);
1065  return ret;
1066  } else if (data->classId() == QPixmapData::RasterClass) {
1067  return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data.data())->image);
1068  }
1069  return 0;
1070 }
1071 
1073 {
1074  return has_alpha;
1075 }
1076 
1078 {
1079  QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data());
1080  if (px->cg_mask) {
1081  if (px->cg_mask_rect == sr) {
1082  CGImageRetain(px->cg_mask); //reference for the caller
1083  return px->cg_mask;
1084  }
1085  CGImageRelease(px->cg_mask);
1086  px->cg_mask = 0;
1087  }
1088 
1089  const int sx = qRound(sr.x()), sy = qRound(sr.y()), sw = qRound(sr.width()), sh = qRound(sr.height());
1090  const int sbpr = px->bytesPerRow;
1091  const uint nbytes = sw * sh;
1092  // alpha is always 255 for bitmaps, ignore it in this case.
1093  const quint32 mask = px->depth() == 1 ? 0x00ffffff : 0xffffffff;
1094  quint8 *dptr = static_cast<quint8 *>(malloc(nbytes));
1095  quint32 *sptr = px->pixels, *srow;
1096  for(int y = sy, offset=0; y < sh; ++y) {
1097  srow = sptr + (y * (sbpr / 4));
1098  for(int x = sx; x < sw; ++x)
1099  *(dptr+(offset++)) = (*(srow+x) & mask) ? 255 : 0;
1100  }
1101  QCFType<CGDataProviderRef> provider = CGDataProviderCreateWithData(0, dptr, nbytes, qt_mac_cgimage_data_free);
1102  px->cg_mask = CGImageMaskCreate(sw, sh, 8, 8, nbytes / sh, provider, 0, 0);
1103  px->cg_mask_rect = sr;
1104  CGImageRetain(px->cg_mask); //reference for the caller
1105  return px->cg_mask;
1106 }
1107 
1108 #ifndef QT_MAC_USE_COCOA
1110 {
1111  if (px.isNull())
1112  return 0;
1113 
1114  //create icon
1115  IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0));
1116  //create data
1117  {
1118  struct {
1119  OSType mac_type;
1120  int width, height, depth;
1121  bool mask;
1122  } images[] = {
1123  { kThumbnail32BitData, 128, 128, 32, false },
1124  { kThumbnail8BitMask, 128, 128, 8, true },
1125  { 0, 0, 0, 0, false } //end marker
1126  };
1127  for(int i = 0; images[i].mac_type; i++) {
1128  //get QPixmap data
1129  QImage scaled_px = px.toImage().scaled(images[i].width, images[i].height);
1130 
1131  quint32 *sptr = (quint32 *) scaled_px.bits();
1132  quint32 *srow;
1133  uint sbpr = scaled_px.bytesPerLine();
1134 
1135  //get Handle data
1136  const int dbpr = images[i].width * (images[i].depth/8);
1137  Handle hdl = NewHandle(dbpr*images[i].height);
1138  if(!sptr) { //handle null pixmap
1139  memset((*hdl), '\0', dbpr*images[i].height);
1140  } else if(images[i].mask) {
1141  if(images[i].mac_type == kThumbnail8BitMask) {
1142  for(int y = 0, hindex = 0; y < images[i].height; ++y) {
1143  srow = sptr + (y * (sbpr/4));
1144  for(int x = 0; x < images[i].width; ++x)
1145  *((*hdl)+(hindex++)) = qAlpha(*(srow+x));
1146  }
1147  }
1148  } else {
1149  char *dest = (*hdl);
1150 #if defined(__i386__)
1151  if(images[i].depth == 32) {
1152  for(int y = 0; y < images[i].height; ++y) {
1153  uint *source = (uint*)((const uchar*)sptr+(sbpr*y));
1154  for(int x = 0; x < images[i].width; ++x, dest += 4)
1155  *((uint*)dest) = CFSwapInt32(*(source + x));
1156  }
1157  } else
1158 #endif
1159  {
1160  for(int y = 0; y < images[i].height; ++y)
1161  memcpy(dest+(y*dbpr), ((const uchar*)sptr+(sbpr*y)), dbpr);
1162  }
1163  }
1164 
1165  //set the family data to the Handle
1166  OSStatus set = SetIconFamilyData(iconFamily, images[i].mac_type, hdl);
1167  if(set != noErr)
1168  qWarning("%s: %d -- Unable to create icon data[%d]!! %ld",
1169  __FILE__, __LINE__, i, long(set));
1170  DisposeHandle(hdl);
1171  }
1172  }
1173 
1174  //acquire and cleanup
1175  IconRef ret;
1176  static int counter = 0;
1177  const OSType kQtCreator = 'CUTE';
1178  RegisterIconRefFromIconFamily(kQtCreator, (OSType)counter, iconFamily, &ret);
1179  AcquireIconRef(ret);
1180  UnregisterIconRef(kQtCreator, (OSType)counter);
1181  DisposeHandle(reinterpret_cast<Handle>(iconFamily));
1182  counter++;
1183  return ret;
1184 
1185 }
1186 #endif
1187 
1190 {
1191  if (!pengine) {
1192  QMacPixmapData *that = const_cast<QMacPixmapData*>(this);
1193  that->pengine = new QCoreGraphicsPaintEngine();
1194  }
1195  return pengine;
1196 }
1197 
1198 void QMacPixmapData::copy(const QPixmapData *data, const QRect &rect)
1199 {
1200  if (data->pixelType() == BitmapType) {
1201  QBitmap::fromImage(toImage().copy(rect));
1202  return;
1203  }
1204 
1205  const QMacPixmapData *macData = static_cast<const QMacPixmapData*>(data);
1206 
1207  resize(rect.width(), rect.height());
1208 
1209  has_alpha = macData->has_alpha;
1210  has_mask = macData->has_mask;
1211  uninit = false;
1212 
1213  const int x = rect.x();
1214  const int y = rect.y();
1215  char *dest = reinterpret_cast<char*>(pixels);
1216 
1217  // only copy data buffer if destination buffer exists (resize might have failed)
1218  if (dest) {
1219  const char *src = reinterpret_cast<const char*>(macData->pixels + x) + y * macData->bytesPerRow;
1220  for (int i = 0; i < h; ++i) {
1221  memcpy(dest, src, w * 4);
1222  dest += bytesPerRow;
1223  src += macData->bytesPerRow;
1224  }
1225 
1226  has_alpha = macData->has_alpha;
1227  has_mask = macData->has_mask;
1228  }
1229 }
1230 
1231 bool QMacPixmapData::scroll(int dx, int dy, const QRect &rect)
1232 {
1233  Q_UNUSED(dx);
1234  Q_UNUSED(dy);
1235  Q_UNUSED(rect);
1236  return false;
1237 }
1238 
1255 {
1256  return (CGImageRef)macCGHandle();
1257 }
1258 
1272 {
1273  const size_t w = CGImageGetWidth(image),
1274  h = CGImageGetHeight(image);
1275  QPixmap ret(w, h);
1276  ret.fill(Qt::transparent);
1277  CGRect rect = CGRectMake(0, 0, w, h);
1279  qt_mac_drawCGImage(ctx, &rect, image);
1280  CGContextRelease(ctx);
1281  return ret;
1282 }
1283 
void fill(const QColor &color)
void setTransform(const QTransform &transform, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9547
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
static CGColorSpaceRef macDisplayColorSpace(const QWidget *widget=0)
virtual QPixmap transformed(const QTransform &matrix, Qt::TransformationMode mode) const
static CGColorSpaceRef macGenericColorSpace()
#define GL_BGRA
Definition: glfunctions.h:63
Format
The following image formats are available in Qt.
Definition: qimage.h:91
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
QPixmap alphaChannel() const
static int defaultDepth()
Returns the default pixmap depth used by the application.
Definition: qpixmap.cpp:2092
unsigned int QRgb
Definition: qrgb.h:53
unsigned long WId
Definition: qwindowdefs.h:119
CGLError(* PtrCGLDestroyPixelFormat)(CGLPixelFormatObj)
int type
Definition: qmetatype.cpp:239
friend IconRef qt_mac_create_iconref(const QPixmap &)
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
Definition: qimage.cpp:1850
double qreal
Definition: qglobal.h:1193
static mach_timebase_info_data_t info
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static QMatrix trueMatrix(const QMatrix &m, int w, int h)
This convenience function loads the matrix m into a QTransform and calls the overloaded function with...
Definition: qpixmap.cpp:584
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
QPointer< QWidget > widget
Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line(const QPixmap *pix)
Definition: qpixmap_mac.cpp:83
static PtrglReadPixels ptrglReadPixels
static PtrglFinish ptrglFinish
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
static PtrCGLDestroyContext ptrCGLDestroyContext
void setAlphaChannel(const QPixmap &alphaChannel)
friend void qt_mac_cgimage_data_free(void *, const void *, size_t)
Definition: qpixmap_mac.cpp:91
static void qt_mac_grabDisplayRect(CGDirectDisplayID display, const QRect &displayRect, void *buffer)
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
QExplicitlySharedDataPointer< QPixmapData > data
Definition: qpixmap.h:252
static PtrCGLSetFullScreen ptrCGLSetFullScreen
void macCreatePixels()
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
bool hasAlphaChannel() const
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
bool remove(const T &value)
Definition: qset.h:89
static const int qt_bbits
Definition: qscreen_qws.h:73
static PtrCGLClearDrawable ptrCGLClearDrawable
void macSetHasAlpha(bool b)
CGFloat qt_mac_get_scalefactor()
#define GL_UNSIGNED_INT_8_8_8_8_REV
static PtrglPixelStorei ptrglPixelStorei
void macReleaseCGImageRef()
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
int width() const
#define GL_PACK_ALIGNMENT
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QBitmap mask() const
CGImageRef cg_data
QRegion qt_mac_convert_mac_region(RgnHandle rgn)
struct CGImage * CGImageRef
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
Definition: qimage.cpp:6495
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
long ASN1_INTEGER_get ASN1_INTEGER * a
unsigned char quint8
Definition: qglobal.h:934
void * resolve(const char *symbol)
Returns the address of the exported symbol symbol.
Definition: qlibrary.cpp:1155
static const int qt_blue_mask
Definition: qscreen_qws.h:77
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
CGImageRef cg_mask
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QRectF boundingRect() const
Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0) if the polygon is empty...
Definition: qpolygon.cpp:742
float qt_mac_defaultDpi_y()
static const uint base
Definition: qurl.cpp:268
static const int qt_red_mask
Definition: qscreen_qws.h:79
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
friend class QCoreGraphicsPaintEngine
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static QPixmap fromMacCGImageRef(CGImageRef image)
Returns a QPixmap that is equivalent to the given image.
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
OSWindowRef qt_mac_window_for(const QWidget *)
Definition: qwidget_mac.mm:484
RgnHandle qt_mac_get_rgn()
void macSetAlphaChannel(const QMacPixmapData *, bool asMask)
Q_CORE_EXPORT void qDebug(const char *,...)
PixelType pixelType() const
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
for(int ii=mo->methodOffset();ii< mo->methodCount();++ii)
unsigned char uchar
Definition: qglobal.h:994
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
NSWindow * window
void(* PtrglFinish)()
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const QRgb RGB_MASK
Definition: qrgb.h:55
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
Definition: qrgb.h:72
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
QMacPixmapData(PixelType type)
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
QPaintEngine * paintEngine() const
CGContextRef qt_mac_cg_context(const QPaintDevice *pdev)
Returns the CoreGraphics CGContextRef of the paint device.
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
CGLError(* PtrCGLSetCurrentContext)(CGLContextObj)
static QWidget * find(WId)
Returns a pointer to the widget with window identifer/handle id.
Definition: qwidget.cpp:2517
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
const uchar * qt_get_bitflip_array()
Definition: qimage.cpp:765
TransformationMode
Definition: qnamespace.h:1510
static const int qt_gbits
Definition: qscreen_qws.h:72
static PtrCGLSetCurrentContext ptrCGLSetCurrentContext
Q_CORE_EXPORT void qWarning(const char *,...)
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
const_iterator insert(const T &value)
Definition: qset.h:179
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void resize(int width, int height)
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
QT_DEPRECATED int numColors() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1636
#define QT_XFORM_TYPE_MSBFIRST
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
static QPixmap qt_mac_grabScreenRect_10_3(int x, int y, int w, int h, QWidget *widget)
void * HANDLE
Definition: qnamespace.h:1671
friend CGImageRef qt_mac_create_imagemask(const QPixmap &, const QRectF &)
signed long OSStatus
static const int qt_green_shift
Definition: qscreen_qws.h:75
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
struct OpaqueRgnHandle * RgnHandle
static QString graphics_system_name
#define GL_FRONT
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
static const int qt_green_mask
Definition: qscreen_qws.h:78
void macGetAlphaChannel(QMacPixmapData *, bool asMask) const
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
Definition: qrgb.h:69
static const int qt_rbits
Definition: qscreen_qws.h:71
struct CGRect CGRect
static int qt_pixmap_serial
Definition: qpixmap_mac.cpp:73
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
Definition: qrgb.h:75
CGLError(* PtrCGLSetFullScreen)(CGLContextObj)
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
void macCreateCGImageRef()
static QRgb qt_conv16ToRgb(ushort c)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
void(* PtrglReadBuffer)(GLenum)
QT_DEPRECATED int numColors() const
struct CGColorSpace * CGColorSpaceRef
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
int depth() const
CGLError(* PtrCGLDestroyContext)(CGLContextObj)
unsigned int GLenum
Definition: main.cpp:50
static void qt_mac_flipPixmap(void *data, int rowBytes, int height)
ushort alpha
Returns the alpha color component of this color.
Definition: qcolor.h:242
static bool resolveOpenGLSymbols()
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656
static const int qt_neg_blue_shift
Definition: qscreen_qws.h:76
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
unsigned short ushort
Definition: qglobal.h:995
static QPixmap qt_mac_grabScreenRect(const QRect &rect)
static PtrCGLCreateContext ptrCGLCreateContext
float qt_mac_defaultDpi_x()
void copy(const QPixmapData *data, const QRect &rect)
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
void setMask(const QBitmap &mask)
#define ctx
Definition: qgl.cpp:6094
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
Definition: qrgb.h:69
#define COMPTUE_BEST_BYTES_PER_ROW(bpr)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void qt_mac_cgimage_data_free(void *info, const void *memoryToFree, size_t)
Definition: qpixmap_mac.cpp:91
unsigned int quint32
Definition: qglobal.h:938
OSStatus qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage)
static const int qt_red_shift
Definition: qscreen_qws.h:74
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: qimage.cpp:6100
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
QPaintEngine * pengine
CGImageRef qt_mac_image_to_cgimage(const QImage &image)
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
Q_GUI_EXPORT quint32 * qt_mac_pixmap_get_base(const QPixmap *pix)
Definition: qpixmap_mac.cpp:75
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
quint16 index
int GLsizei
Definition: main.cpp:49
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
typedef GLint
Definition: glfunctions.h:67
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
virtual QImage * buffer()
Q_STATIC_INLINE_FUNCTION int qt_div_255(int x)
bool scroll(int dx, int dy, const QRect &rect)
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281
int height() const
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646
bool isNull() const
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition: qwidget.h:937
static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1)
Creates and returns a pixmap constructed by grabbing the contents of the given window restricted by Q...
quint32 * pixelsToFree
static PtrCGLChoosePixelFormat ptrCGLChoosePixelFormat
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
struct CGContext * CGContextRef
static PtrCGLDestroyPixelFormat ptrCGLDestroyPixelFormat
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
QImage toImage() const
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
Definition: qimage.h:232
void setSerialNumber(int serNo)
CGImageRef toMacCGImageRef() const
Creates a CGImageRef equivalent to the QPixmap.
QRectF normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:1822
quint32 * pixels
static PtrglReadBuffer ptrglReadBuffer
static QSet< QMacPixmapData * > validDataPointers
CGLError(* PtrCGLCreateContext)(CGLPixelFormatObj, CGLContextObj, CGLContextObj *)
friend CGContextRef qt_mac_cg_context(const QPaintDevice *)
Returns the CoreGraphics CGContextRef of the paint device.
QPixmapData * createCompatiblePixmapData() const
int metric(QPaintDevice::PaintDeviceMetric metric) const
#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
CGLError(* PtrCGLClearDrawable)(CGLContextObj)
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
QVector< QRgb > colorTable() const
Returns a list of the colors contained in the image&#39;s color table, or an empty list if the image does...
Definition: qimage.cpp:1770
CGImageRef cg_dataBeingReleased
QRgb color(int i) const
Returns the color in the color table at index i.
Definition: qimage.cpp:1829
void(* PtrglPixelStorei)(GLenum, GLint)
GDPtr * GDHandle
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62
void(* PtrglReadPixels)(GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid *)
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
CGLError(* PtrCGLChoosePixelFormat)(const CGLPixelFormatAttribute *, CGLPixelFormatObj *, long *)
struct OpaqueIconRef * IconRef
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
void qt_mac_dispose_rgn(RgnHandle r)
float CGFloat
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
int get_index(QImage *qi, QRgb mycol)
INT_PTR intptr_t
friend class QPixmap