Changeset 262 for trunk/src/gui/image


Ignore:
Timestamp:
Oct 28, 2009, 9:48:50 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: QPixmap: A number of fixes to the HBITMAP/HPOINTER conversion code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/image/qpixmap_pm.cpp

    r260 r262  
    4646
    4747#include "qicon.h"
     48
    4849
    4950#include "qt_os2.h"
     
    121122    int h = d->image.height();
    122123
    123     HPS hps = qt_alloc_mem_ps(w, h);
     124    HPS hps = qt_alloc_mem_ps(w, h);
    124125    if (hps == NULLHANDLE)
    125126        return NULLHANDLE;
     
    149150        // since the former will dither while the latter will convert any
    150151        // non-zero alpha value to an opaque pixel
    151         QImage mask = image.createAlphaMask().mirrored();
    152 
    153         // create the mask bitmap (AND and XOR stripes)
     152#if 1
     153        QImage mask = image.createAlphaMask().convertToFormat(QImage::Format_Mono);
     154
     155        // note: for some strange reason, createAlphaMask() (as opposed to
     156        // mask().toImage()) returns an image already flipped top to bottom,
     157        // so take it into account
     158
     159        // create the AND mask
     160        mask.invertPixels();
     161        // add the XOR mask (and leave it zeroed)
     162        mask = mask.copy(0, -h, w, h * 2);
     163
     164#else
     165        QImage mask = this->mask().toImage().convertToFormat(QImage::Format_Mono);
     166
     167        // create the AND mask
     168        mask.invertPixels();
     169        // add the XOR mask (and leave it zeroed)
     170        mask = mask.copy(0, 0, w, h * 2);
     171        // flip the bitmap top to bottom for PM
     172        mask = mask.mirrored(false, true);
     173#endif
     174
     175        // create the mask bitmap
    154176        bmh.cbFix = sizeof(BITMAPINFOHEADER2);
    155177        bmh.cx = w;
    156         bmh.cy = h;
     178        bmh.cy = h;
    157179        bmh.cPlanes = 1;
    158180        bmh.cBitCount = 1;
     
    160182        pal[0] = 0;
    161183        pal[1] = 0x00FFFFFF;
    162         hbmMask = GpiCreateBitmap(hps, &bmh, 0, NULL, NULL);
    163 
    164         // create AND mask (XOR mask is left zeroed -- it's okay)
    165         GpiSetBitmap(hps, hbmMask);
     184        hbmMask = GpiCreateBitmap(hps, &bmh, CBM_INIT,
     185                                  (PBYTE)(const uchar *)mask.bits(),
     186                                  (PBITMAPINFO2)&bmi);
     187
     188        // prepare the bitmap for masking by setting transparent pixels to black
     189        GpiSetBitmap(hps, hbm);
    166190
    167191        POINTL ptls[] = {
    168             { 0, h }, { w - 1, h * 2 - 1 }, // dst: inclusive-inclusive
    169             { 0, 0 }, { w, h }, // src: inclusive-exclusive
     192            { 0, // dst: inclusive-inclusive
     193            { 0, // src: inclusive-exclusive
    170194        };
    171         GpiDrawBits(hps, (PBYTE)(const uchar *)mask.bits(), (PBITMAPINFO2)&bmi,
    172                     4, ptls, ROP_NOTSRCCOPY, BBO_IGNORE);
    173 
    174         // prepare the bitmap for masking by setting transparent pixels to black
    175         GpiSetBitmap(hps, hbmMask);
    176 
    177195        ptls[0].y -= h;
    178196        ptls[1].y -= h;
     
    234252    info.yHotspot = hotY;
    235253    info.hbmColor = pm.toPmHBITMAP(&info.hbmPointer);
    236     if (!pmMini.isNull())
    237     info.hbmMiniColor = pmMini.toPmHBITMAP(&info.hbmMiniPointer);
     254    if (!pmMini.isNull()) {
     255        info.hbmMiniColor = pmMini.toPmHBITMAP(&info.hbmMiniPointer);
     256    } else {
     257        info.hbmMiniPointer = NULLHANDLE;
     258        info.hbmMiniColor = NULLHANDLE;
     259    }
    238260
    239261    HPOINTER hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &info);
Note: See TracChangeset for help on using the changeset viewer.