Changeset 941

Timestamp:
Aug 5, 2011, 2:26:40 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

OS/2: Fixed creating HPOINTERs from QPixmaps with no mask.

HPOINTERs are used to assign the icon to the top-level window and
to create custom PM mouse pointer shapes. Prior to to this fix it was
impossible to e.g. set a PNG with no transparency as the window icon.

Author: Rudi Ihle.

File:
1 edited

Legend:

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

    r940 r941  
    108108    routines to do real alpha blending.
    109109
    110     Note that if the pixmap does neither have a mask nor the alpha channel but
    111     \a mask is not NULL, a NULLHANDLE value will be stored there.
     110    Note that if \a mask is not NULL but the pixmap does neither have a mask nor
     111    the alpha channel, an emptpy bitmap mask with no transparency (zeroed AND
     112    and XOR parts) will be created and returned.
    112113
    113114    It is the caller's responsibility to free both returned \c HBITMAP handes
     
    160161                          (PBITMAPINFO2)&bmi);
    161162
    162     if (mask && hasAlpha()) {
     163    if (mask) {
    163164        // get the mask
    164165        QImage mask;
    165         if (!embedRealAlpha) {
    166             // We prefer QImage::createAlphaMask() over QPixmap::mask()
    167             // since the former will dither while the latter will convert any
    168             // non-zero alpha value to an opaque pixel
    169             mask = image.createAlphaMask().convertToFormat(QImage::Format_Mono);
    170 
    171             // note: for some strange reason, createAlphaMask() (as opposed to
    172             // mask().toImage()) returns an image already flipped top to bottom,
    173             // so take it into account
    174 
    175             // create the AND mask
    176             mask.invertPixels();
    177             // add the XOR mask (and leave it zeroed)
    178             mask = mask.copy(0, -h, w, h * 2);
     166        if (hasAlpha()) {
     167            if (!embedRealAlpha) {
     168                // We prefer QImage::createAlphaMask() over QPixmap::mask()
     169                // since the former will dither while the latter will convert any
     170                // non-zero alpha value to an opaque pixel
     171                mask = image.createAlphaMask().convertToFormat(QImage::Format_Mono);
     172
     173                // note: for some strange reason, createAlphaMask() (as opposed to
     174                // mask().toImage()) returns an image already flipped top to bottom,
     175                // so take it into account
     176
     177                // create the AND mask
     178                mask.invertPixels();
     179                // add the XOR mask (and leave it zeroed)
     180                mask = mask.copy(0, -h, w, h * 2);
     181            } else {
     182                // if we embedded real alpha, we still need a mask if we are going
     183                // to create a pointer out of this pixmap (WinCreatePointerIndirect()
     184                // requirement), but we will use QPixmap::mask() because it won't be
     185                // able to destroy the alpha channel of non-fully transparent pixels
     186                // when preparing the color bitmap for masking later. We could also
     187                // skip this prepare step, but well, let's go this way, it won't hurt.
     188                mask = this->mask().toImage().convertToFormat(QImage::Format_Mono);
     189
     190                // create the AND mask
     191                mask.invertPixels();
     192                // add the XOR mask (and leave it zeroed)
     193                mask = mask.copy(0, 0, w, h * 2);
     194                // flip the bitmap top to bottom for PM
     195                mask = mask.mirrored(false, true);
     196            }
    179197        } else {
    180             // if we embedded real alpha, we still need a mask if we are going
    181             // to create a pointer out of this pixmap (WinCreatePointerIndirect()
    182             // requirement), but we will use QPixmap::mask() because it won't be
    183             // able to destroy the alpha channel of non-fully transparent pixels
    184             // when preparing the color bitmap for masking later. We could also
    185             // skip this prepare step, but well, let's go this way, it won't hurt.
    186             mask = this->mask().toImage().convertToFormat(QImage::Format_Mono);
    187 
    188             // create the AND mask
    189             mask.invertPixels();
    190             // add the XOR mask (and leave it zeroed)
    191             mask = mask.copy(0, 0, w, h * 2);
    192             // flip the bitmap top to bottom for PM
    193             mask = mask.mirrored(false, true);
     198            mask = QImage(w, h * 2, QImage::Format_Mono);
     199            mask.fill(0);
    194200        }
    195201
Note: See TracChangeset for help on using the changeset viewer.