Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/qpixmap_mac.cpp

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
    4040****************************************************************************/
    41 //#define QT_RASTER_PAINTENGINE
    4241
    4342#include "qpixmap.h"
     
    5352#include <private/qpixmap_mac_p.h>
    5453#include <private/qpixmap_raster_p.h>
    55 #ifdef QT_RASTER_PAINTENGINE
    56 #  include <private/qpaintengine_raster_p.h>
    57 #endif
    5854#include <private/qpaintengine_mac_p.h>
    5955#include <private/qt_mac_p.h>
     
    7874Q_GUI_EXPORT quint32 *qt_mac_pixmap_get_base(const QPixmap *pix)
    7975{
    80     return static_cast<QMacPixmapData*>(pix->data)->pixels;
     76    return static_cast<QMacPixmapData*>(pix->data.data())->pixels;
    8177}
    8278
    8379Q_GUI_EXPORT int qt_mac_pixmap_get_bytes_per_line(const QPixmap *pix)
    8480{
    85     return static_cast<QMacPixmapData*>(pix->data)->bytesPerRow;
     81    return static_cast<QMacPixmapData*>(pix->data.data())->bytesPerRow;
    8682}
    8783
     
    120116                                     0);
    121117
    122 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    123118    uint cgflags = kCGImageAlphaPremultipliedFirst;
    124119#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;
    130121#endif
    131122
     
    169160
    170161QMacPixmapData::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),
    177165      pengine(0)
    178166{
     167}
     168
     169QPixmapData *QMacPixmapData::createCompatiblePixmapData() const
     170{
     171    return new QMacPixmapData(pixelType());
    179172}
    180173
     
    189182    w = width;
    190183    h = height;
     184    is_null = (w <= 0 || h <= 0);
    191185    d = (pixelType() == BitmapType ? 1 : 32);
    192186    bool make_null = w <= 0 || h <= 0;                // create null pixmap
     
    194188        w = 0;
    195189        h = 0;
     190        is_null = true;
    196191        d = 0;
    197192        if (!make_null)
     
    232227    w = img.width();
    233228    h = img.height();
     229    is_null = (w <= 0 || h <= 0);
    234230    d = (pixelType() == BitmapType ? 1 : img.depth());
    235231
     
    253249            conv8 = d == 1;                     // native depth wanted
    254250        } else if (d == 1) {
    255             if (image.numColors() == 2) {
     251            if (image.colorCount() == 2) {
    256252                QRgb c0 = image.color(0);       // Auto: convert to best
    257253                QRgb c1 = image.color(1);
     
    310306            break;
    311307        }
    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                }
    315315            }
    316             break;
     316        } break;
    317317        case QImage::Format_RGB32:
    318318            for (int x = 0; x < w; ++x)
     
    340340        if (sfmt == QImage::Format_Indexed8) {
    341341            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) {
    343343                const int alpha = qAlpha(rgb[i]);
    344344                if (alpha != 0xff) {
     
    356356{
    357357    int loopc;
    358     for(loopc=0;loopc<qi->numColors();loopc++) {
     358    for(loopc=0;loopc<qi->colorCount();loopc++) {
    359359        if(qi->color(loopc)==mycol)
    360360            return loopc;
    361361    }
    362     qi->setNumColors(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();
    365365}
    366366
     
    377377    if (format == QImage::Format_MonoLSB) {
    378378        image.fill(0);
    379         image.setNumColors(2);
     379        image.setColorCount(2);
    380380        image.setColor(0, QColor(Qt::color0).rgba());
    381381        image.setColor(1, QColor(Qt::color1).rgba());
     
    431431{
    432432    has_mask = true;
    433     QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data);
     433    QMacPixmapData *alphaData = static_cast<QMacPixmapData*>(alpha.data.data());
    434434    macSetAlphaChannel(alphaData, false);
    435435}
     
    459459    has_alpha = false;
    460460    has_mask = true;
    461     QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data);
     461    QMacPixmapData *maskData = static_cast<QMacPixmapData*>(mask.data.data());
    462462    macSetAlphaChannel(maskData, true);
    463463}
     
    497497{
    498498    validDataPointers.remove(this);
    499 #ifndef QT_MAC_NO_QUICKDRAW
    500     macQDDisposeAlpha();
    501     if (qd_data) {
    502         DisposeGWorld(qd_data);
    503         qd_data = 0;
    504     }
    505 #endif
    506499    if (cg_mask) {
    507500        CGImageRelease(cg_mask);
     
    592585{
    593586    has_alpha = b;
    594 #ifndef QT_MAC_NO_QUICKDRAW
    595     macQDDisposeAlpha(); //let it get created lazily
    596 #endif
    597587    macReleaseCGImageRef();
    598588}
    599 
    600 #ifndef QT_MAC_NO_QUICKDRAW
    601 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 pixmap
    612     if (!has_alpha && !has_mask)
    613         return;
    614 
    615     //setup
    616     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 #endif
    635589
    636590void QMacPixmapData::macCreateCGImageRef()
     
    643597                                                              qt_mac_cgimage_data_free);
    644598    validDataPointers.insert(this);
    645 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    646599    uint cgflags = kCGImageAlphaPremultipliedFirst;
    647600#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;
    653602#endif
    654603    cg_data = CGImageCreate(w, h, 8, 32, bytesPerRow, colorspace,
     
    689638
    690639    if (pixels)
    691         memcpy(base_pixels, pixels, numBytes);
     640        memcpy(base_pixels, pixels, pixelsSize);
    692641    pixels = base_pixels;
     642    pixelsSize = numBytes;
    693643}
    694644
     
    891841}
    892842
    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, using
    904     // 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_4
    914     if(CGBitmapContextGetBitmapInfo)
    915         bitmapInfo = CGBitmapContextGetBitmapInfo(c);
    916     else
    917 #endif
    918         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 
    925843// Returns a pixmap containing the screen contents at rect.
    926844static QPixmap qt_mac_grabScreenRect(const QRect &rect)
     
    956874                                        QCoreGraphicsPaintEngine::macGenericColorSpace(),
    957875                                        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);
    971878}
    972879
     
    1030937
    1031938    \warning This function is only available on Mac OS X.
     939    \warning As of Qt 4.6, this function \e{always} returns zero.
    1032940*/
    1033941
    1034942Qt::HANDLE QPixmap::macQDHandle() const
    1035943{
    1036 #ifndef QT_MAC_NO_QUICKDRAW
    1037     QMacPixmapData *d = static_cast<QMacPixmapData*>(data);
    1038     if (!d->qd_data) { //create the qd data
    1039         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 this
    1046             //makes our merge much simpler, at some point the hacks will go away
    1047             //because QD will be removed, but until that day this keeps them coexisting
    1048             if (QSysInfo::ByteOrder == QSysInfo::LittleEndian)
    1049                 qdformat = k32BGRAPixelFormat;
    1050 #if 0
    1051             qdflags |= kNativeEndianPixMap;
    1052 #endif
    1053         }
    1054 #endif
    1055         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 #else
    1061944    return 0;
    1062 #endif
    1063945}
    1064946
     
    1070952
    1071953    \warning This function is only available on Mac OS X.
     954    \warning As of Qt 4.6, this function \e{always} returns zero.
    1072955*/
    1073956
    1074957Qt::HANDLE QPixmap::macQDAlphaHandle() const
    1075958{
    1076 #ifndef QT_MAC_NO_QUICKDRAW
    1077     QMacPixmapData *d = static_cast<QMacPixmapData*>(data);
    1078     if (d->has_alpha || d->has_mask) {
    1079         if (!d->qd_alpha) //lazily created
    1080             d->macQDUpdateAlpha();
    1081         return d->qd_alpha;
    1082     }
    1083 #endif
    1084959    return 0;
    1085960}
     
    1096971Qt::HANDLE QPixmap::macCGHandle() const
    1097972{
     973    if (isNull())
     974        return 0;
     975
    1098976    if (data->classId() == QPixmapData::MacClass) {
    1099         QMacPixmapData *d = static_cast<QMacPixmapData *>(data);
     977        QMacPixmapData *d = static_cast<QMacPixmapData *>(data.data());
    1100978        if (!d->cg_data)
    1101979            d->macCreateCGImageRef();
     
    1104982        return ret;
    1105983    } 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);
    1107985    }
    1108986    return 0;
     
    1116994CGImageRef qt_mac_create_imagemask(const QPixmap &pixmap, const QRectF &sr)
    1117995{
    1118     QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data);
     996    QMacPixmapData *px = static_cast<QMacPixmapData*>(pixmap.data.data());
    1119997    if (px->cg_mask) {
    1120998        if (px->cg_mask_rect == sr) {
     
    11511029        return 0;
    11521030
    1153     QMacSavedPortInfo pi; //save the current state
    11541031    //create icon
    11551032    IconFamilyHandle iconFamily = reinterpret_cast<IconFamilyHandle>(NewHandle(0));
     
    12261103#endif
    12271104
    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 
    12471105/*! \internal */
    12481106QPaintEngine* QMacPixmapData::paintEngine() const
     
    12501108    if (!pengine) {
    12511109        QMacPixmapData *that = const_cast<QMacPixmapData*>(this);
    1252 #ifdef QT_RASTER_PAINTENGINE
    1253         if (qgetenv("QT_MAC_USE_COREGRAPHICS").isNull())
    1254             that->pengine = new QRasterPaintEngine();
    1255         else
    1256             that->pengine = new QCoreGraphicsPaintEngine();
    1257 #else
    12581110        that->pengine = new QCoreGraphicsPaintEngine();
    1259 #endif
    12601111    }
    12611112    return pengine;
     
    12911142}
    12921143
     1144bool 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
    12931152/*!
    12941153    \since 4.2
     
    13221181                 h = CGImageGetHeight(image);
    13231182    QPixmap ret(w, h);
     1183    ret.fill(Qt::transparent);
    13241184    CGRect rect = CGRectMake(0, 0, w, h);
    13251185    CGContextRef ctx = qt_mac_cg_context(&ret);
Note: See TracChangeset for help on using the changeset viewer.