Changeset 561 for trunk/src/gui/image/qpixmap_mac.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/image/qpixmap_mac.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** 40 40 ****************************************************************************/ 41 //#define QT_RASTER_PAINTENGINE42 41 43 42 #include "qpixmap.h" … … 53 52 #include <private/qpixmap_mac_p.h> 54 53 #include <private/qpixmap_raster_p.h> 55 #ifdef QT_RASTER_PAINTENGINE56 # include <private/qpaintengine_raster_p.h>57 #endif58 54 #include <private/qpaintengine_mac_p.h> 59 55 #include <private/qt_mac_p.h> … … 78 74 Q_GUI_EXPORT quint32 *qt_mac_pixmap_get_base(const QPixmap *pix) 79 75 { 80 return static_cast<QMacPixmapData*>(pix->data )->pixels;76 return static_cast<QMacPixmapData*>(pix->data.data())->pixels; 81 77 } 82 78 83 79 Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line(const QPixmap *pix) 84 80 { 85 return static_cast<QMacPixmapData*>(pix->data )->bytesPerRow;81 return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow; 86 82 } 87 83 … … 120 116 0); 121 117 122 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)123 118 uint cgflags = kCGImageAlphaPremultipliedFirst; 124 119 #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version 125 if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) 126 cgflags |= kCGBitmapByteOrder32Host; 127 #endif 128 #else 129 CGImageAlphaInfo cgflags = kCGImageAlphaPremultipliedFirst; 120 cgflags |= kCGBitmapByteOrder32Host; 130 121 #endif 131 122 … … 169 160 170 161 QMacPixmapData::QMacPixmapData(PixelType type) 171 : QPixmapData(type, MacClass), w(0), h(0), d(0), has_alpha(0), has_mask(0), 172 uninit(true), pixels(0), pixelsToFree(0), bytesPerRow(0), 173 cg_data(0), cg_dataBeingReleased(0), cg_mask(0), 174 #ifndef QT_MAC_NO_QUICKDRAW 175 qd_data(0), qd_alpha(0), 176 #endif 162 : QPixmapData(type, MacClass), has_alpha(0), has_mask(0), 163 uninit(true), pixels(0), pixelsSize(0), pixelsToFree(0), 164 bytesPerRow(0), cg_data(0), cg_dataBeingReleased(0), cg_mask(0), 177 165 pengine(0) 178 166 { 167 } 168 169 QPixmapData *QMacPixmapData::createCompatiblePixmapData() const 170 { 171 return new QMacPixmapData(pixelType()); 179 172 } 180 173 … … 189 182 w = width; 190 183 h = height; 184 is_null = (w <= 0 || h <= 0); 191 185 d = (pixelType() == BitmapType ? 1 : 32); 192 186 bool make_null = w <= 0 || h <= 0; // create null pixmap … … 194 188 w = 0; 195 189 h = 0; 190 is_null = true; 196 191 d = 0; 197 192 if (!make_null) … … 232 227 w = img.width(); 233 228 h = img.height(); 229 is_null = (w <= 0 || h <= 0); 234 230 d = (pixelType() == BitmapType ? 1 : img.depth()); 235 231 … … 253 249 conv8 = d == 1; // native depth wanted 254 250 } else if (d == 1) { 255 if (image. numColors() == 2) {251 if (image.colorCount() == 2) { 256 252 QRgb c0 = image.color(0); // Auto: convert to best 257 253 QRgb c1 = image.color(1); … … 310 306 break; 311 307 } 312 case QImage::Format_Indexed8: 313 for (int x = 0; x < w; ++x) { 314 *(drow+x) = PREMUL(image.color(*(srow + x))); 308 case QImage::Format_Indexed8: { 309 int numColors = image.numColors(); 310 if (numColors > 0) { 311 for (int x = 0; x < w; ++x) { 312 int index = *(srow + x); 313 *(drow+x) = PREMUL(image.color(qMin(index, numColors))); 314 } 315 315 } 316 316 } break; 317 317 case QImage::Format_RGB32: 318 318 for (int x = 0; x < w; ++x) … … 340 340 if (sfmt == QImage::Format_Indexed8) { 341 341 const QVector<QRgb> rgb = image.colorTable(); 342 for (int i = 0, count = image. numColors(); i < count; ++i) {342 for (int i = 0, count = image.colorCount(); i < count; ++i) { 343 343 const int alpha = qAlpha(rgb[i]); 344 344 if (alpha != 0xff) { … … 356 356 { 357 357 int loopc; 358 for(loopc=0;loopc<qi-> numColors();loopc++) {358 for(loopc=0;loopc<qi->colorCount();loopc++) { 359 359 if(qi->color(loopc)==mycol) 360 360 return loopc; 361 361 } 362 qi->set NumColors(qi->numColors()+1);363 qi->setColor(qi-> numColors(),mycol);364 return qi-> numColors();362 qi->setColorCount(qi->colorCount()+1); 363 qi->setColor(qi->colorCount(),mycol); 364 return qi->colorCount(); 365 365 } 366 366 … … 377 377 if (format == QImage::Format_MonoLSB) { 378 378 image.fill(0); 379 image.set NumColors(2);379 image.setColorCount(2); 380 380 image.setColor(0, QColor(Qt::color0).rgba()); 381 381 image.setColor(1, QColor(Qt::color1).rgba()); … … 431 431 { 432 432 has_mask = true; 433 QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data );433 QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data.data()); 434 434 macSetAlphaChannel(alphaData, false); 435 435 } … … 459 459 has_alpha = false; 460 460 has_mask = true; 461 QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data );461 QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data.data()); 462 462 macSetAlphaChannel(maskData, true); 463 463 } … … 497 497 { 498 498 validDataPointers.remove(this); 499 #ifndef QT_MAC_NO_QUICKDRAW500 macQDDisposeAlpha();501 if (qd_data) {502 DisposeGWorld(qd_data);503 qd_data = 0;504 }505 #endif506 499 if (cg_mask) { 507 500 CGImageRelease(cg_mask); … … 592 585 { 593 586 has_alpha = b; 594 #ifndef QT_MAC_NO_QUICKDRAW595 macQDDisposeAlpha(); //let it get created lazily596 #endif597 587 macReleaseCGImageRef(); 598 588 } 599 600 #ifndef QT_MAC_NO_QUICKDRAW601 void QMacPixmapData::macQDDisposeAlpha()602 {603 if (qd_alpha) {604 DisposeGWorld(qd_alpha);605 qd_alpha = 0;606 }607 }608 609 void QMacPixmapData::macQDUpdateAlpha()610 {611 macQDDisposeAlpha(); // get rid of alpha pixmap612 if (!has_alpha && !has_mask)613 return;614 615 //setup616 Rect rect;617 SetRect(&rect, 0, 0, w, h);618 const int params = alignPix | stretchPix | newDepth;619 NewGWorld(&qd_alpha, 32, &rect, 0, 0, params);620 int *dptr = (int *)GetPixBaseAddr(GetGWorldPixMap(qd_alpha)), *drow;621 unsigned short dbpr = GetPixRowBytes(GetGWorldPixMap(qd_alpha));622 const int *sptr = (int*)pixels, *srow;623 const uint sbpr = bytesPerRow;624 uchar clr;625 for (int y = 0; y < h; ++y) {626 drow = (int*)((char *)dptr + (y * dbpr));627 srow = (int*)((char *)sptr + (y * sbpr));628 for (int x=0; x < w; x++) {629 clr = qAlpha(*(srow + x));630 *(drow + x) = qRgba(~clr, ~clr, ~clr, 0);631 }632 }633 }634 #endif635 589 636 590 void QMacPixmapData::macCreateCGImageRef() … … 643 597 qt_mac_cgimage_data_free); 644 598 validDataPointers.insert(this); 645 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)646 599 uint cgflags = kCGImageAlphaPremultipliedFirst; 647 600 #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version 648 if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) 649 cgflags |= kCGBitmapByteOrder32Host; 650 #endif 651 #else 652 CGImageAlphaInfo cgflags = kCGImageAlphaPremultipliedFirst; 601 cgflags |= kCGBitmapByteOrder32Host; 653 602 #endif 654 603 cg_data = CGImageCreate(w, h, 8, 32, bytesPerRow, colorspace, … … 689 638 690 639 if (pixels) 691 memcpy(base_pixels, pixels, numBytes);640 memcpy(base_pixels, pixels, pixelsSize); 692 641 pixels = base_pixels; 642 pixelsSize = numBytes; 693 643 } 694 644 … … 891 841 } 892 842 893 static CGImageRef qt_mac_createImageFromBitmapContext(CGContextRef c)894 {895 void *rasterData = CGBitmapContextGetData(c);896 const int width = CGBitmapContextGetBytesPerRow(c),897 height = CGBitmapContextGetHeight(c);898 size_t imageDataSize = width*height;899 900 if(!rasterData)901 return 0;902 903 // Create the data provider from the image data, using904 // the image releaser function releaseBitmapContextImageData.905 CGDataProviderRef dataProvider = CGDataProviderCreateWithData(0, rasterData,906 imageDataSize,907 qt_mac_cgimage_data_free);908 909 if(!dataProvider)910 return 0;911 912 uint bitmapInfo = 0;913 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4914 if(CGBitmapContextGetBitmapInfo)915 bitmapInfo = CGBitmapContextGetBitmapInfo(c);916 else917 #endif918 bitmapInfo = CGBitmapContextGetAlphaInfo(c);919 return CGImageCreate(width, height, CGBitmapContextGetBitsPerComponent(c),920 CGBitmapContextGetBitsPerPixel(c), CGBitmapContextGetBytesPerRow(c),921 CGBitmapContextGetColorSpace(c), bitmapInfo, dataProvider,922 0, true, kCGRenderingIntentDefault);923 }924 925 843 // Returns a pixmap containing the screen contents at rect. 926 844 static QPixmap qt_mac_grabScreenRect(const QRect &rect) … … 956 874 QCoreGraphicsPaintEngine::macGenericColorSpace(), 957 875 kCGImageAlphaNoneSkipFirst); 958 959 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) 960 if(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { 961 QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap); 962 return QPixmap::fromMacCGImageRef(image); 963 } else 964 #endif 965 { 966 QCFType<CGImageRef> image = qt_mac_createImageFromBitmapContext(bitmap); 967 if (!image) 968 return QPixmap(); 969 return QPixmap::fromMacCGImageRef(image); 970 } 876 QCFType<CGImageRef> image = CGBitmapContextCreateImage(bitmap); 877 return QPixmap::fromMacCGImageRef(image); 971 878 } 972 879 … … 1030 937 1031 938 \warning This function is only available on Mac OS X. 939 \warning As of Qt 4.6, this function \e{always} returns zero. 1032 940 */ 1033 941 1034 942 Qt::HANDLE QPixmap::macQDHandle() const 1035 943 { 1036 #ifndef QT_MAC_NO_QUICKDRAW1037 QMacPixmapData *d = static_cast<QMacPixmapData*>(data);1038 if (!d->qd_data) { //create the qd data1039 Rect rect;1040 SetRect(&rect, 0, 0, d->w, d->h);1041 unsigned long qdformat = k32ARGBPixelFormat;1042 GWorldFlags qdflags = 0;1043 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)1044 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {1045 //we play such games so we can use the same buffer in CG as QD this1046 //makes our merge much simpler, at some point the hacks will go away1047 //because QD will be removed, but until that day this keeps them coexisting1048 if (QSysInfo::ByteOrder == QSysInfo::LittleEndian)1049 qdformat = k32BGRAPixelFormat;1050 #if 01051 qdflags |= kNativeEndianPixMap;1052 #endif1053 }1054 #endif1055 if(NewGWorldFromPtr(&d->qd_data, qdformat, &rect, 0, 0, qdflags,1056 (char*)d->pixels, d->bytesPerRow) != noErr)1057 qWarning("Qt: internal: QPixmap::init error (%d %d %d %d)", rect.left, rect.top, rect.right, rect.bottom);1058 }1059 return d->qd_data;1060 #else1061 944 return 0; 1062 #endif1063 945 } 1064 946 … … 1070 952 1071 953 \warning This function is only available on Mac OS X. 954 \warning As of Qt 4.6, this function \e{always} returns zero. 1072 955 */ 1073 956 1074 957 Qt::HANDLE QPixmap::macQDAlphaHandle() const 1075 958 { 1076 #ifndef QT_MAC_NO_QUICKDRAW1077 QMacPixmapData *d = static_cast<QMacPixmapData*>(data);1078 if (d->has_alpha || d->has_mask) {1079 if (!d->qd_alpha) //lazily created1080 d->macQDUpdateAlpha();1081 return d->qd_alpha;1082 }1083 #endif1084 959 return 0; 1085 960 } … … 1096 971 Qt::HANDLE QPixmap::macCGHandle() const 1097 972 { 973 if (isNull()) 974 return 0; 975 1098 976 if (data->classId() == QPixmapData::MacClass) { 1099 QMacPixmapData *d = static_cast<QMacPixmapData *>(data );977 QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data()); 1100 978 if (!d->cg_data) 1101 979 d->macCreateCGImageRef(); … … 1104 982 return ret; 1105 983 } else if (data->classId() == QPixmapData::RasterClass) { 1106 return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data )->image);984 return qt_mac_image_to_cgimage(static_cast<QRasterPixmapData *>(data.data())->image); 1107 985 } 1108 986 return 0; … … 1116 994 CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr) 1117 995 { 1118 QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data );996 QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data()); 1119 997 if (px->cg_mask) { 1120 998 if (px->cg_mask_rect == sr) { … … 1151 1029 return 0; 1152 1030 1153 QMacSavedPortInfo pi; //save the current state1154 1031 //create icon 1155 1032 IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0)); … … 1226 1103 #endif 1227 1104 1228 QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height)1229 {1230 QPixmap ret(width, height);1231 ret.fill(QColor(0, 0, 0, 0));1232 1233 CGRect rect = CGRectMake(0, 0, width, height);1234 1235 CGContextRef ctx = qt_mac_cg_context(&ret);1236 CGAffineTransform old_xform = CGContextGetCTM(ctx);1237 CGContextConcatCTM(ctx, CGAffineTransformInvert(old_xform));1238 CGContextConcatCTM(ctx, CGAffineTransformIdentity);1239 1240 ::RGBColor b;1241 b.blue = b.green = b.red = 255*255;1242 PlotIconRefInContext(ctx, &rect, kAlignNone, kTransformNone, &b, kPlotIconRefNormalFlags, icon);1243 CGContextRelease(ctx);1244 return ret;1245 }1246 1247 1105 /*! \internal */ 1248 1106 QPaintEngine* QMacPixmapData::paintEngine() const … … 1250 1108 if (!pengine) { 1251 1109 QMacPixmapData *that = const_cast<QMacPixmapData*>(this); 1252 #ifdef QT_RASTER_PAINTENGINE1253 if (qgetenv("QT_MAC_USE_COREGRAPHICS").isNull())1254 that->pengine = new QRasterPaintEngine();1255 else1256 that->pengine = new QCoreGraphicsPaintEngine();1257 #else1258 1110 that->pengine = new QCoreGraphicsPaintEngine(); 1259 #endif1260 1111 } 1261 1112 return pengine; … … 1291 1142 } 1292 1143 1144 bool QMacPixmapData::scroll(int dx, int dy, const QRect &rect) 1145 { 1146 Q_UNUSED(dx); 1147 Q_UNUSED(dy); 1148 Q_UNUSED(rect); 1149 return false; 1150 } 1151 1293 1152 /*! 1294 1153 \since 4.2 … … 1322 1181 h = CGImageGetHeight(image); 1323 1182 QPixmap ret(w, h); 1183 ret.fill(Qt::transparent); 1324 1184 CGRect rect = CGRectMake(0, 0, w, h); 1325 1185 CGContextRef ctx = qt_mac_cg_context(&ret);
Note:
See TracChangeset
for help on using the changeset viewer.