Ticket #216: qpixmap_pm.diff

File qpixmap_pm.diff, 3.7 KB (added by rudi, 13 years ago)

Fix for the above problem

  • qpixmap_pm.cpp

     
    159159    hbm = GpiCreateBitmap(hps, bmh, CBM_INIT, (PBYTE)(const uchar *)image.bits(),
    160160                          (PBITMAPINFO2)&bmi);
    161161
    162     if (mask && hasAlpha()) {
     162    if (mask ) {
    163163        // get the mask
    164164        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);
     165        if (hasAlpha()) {
     166            if (!embedRealAlpha) {
     167                // We prefer QImage::createAlphaMask() over QPixmap::mask()
     168                // since the former will dither while the latter will convert any
     169                // non-zero alpha value to an opaque pixel
     170                mask = image.createAlphaMask().convertToFormat(QImage::Format_Mono);
    170171
    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
     172                // note: for some strange reason, createAlphaMask() (as opposed to
     173                // mask().toImage()) returns an image already flipped top to bottom,
     174                // so take it into account
    174175
    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);
     176                // create the AND mask
     177                mask.invertPixels();
     178                // add the XOR mask (and leave it zeroed)
     179                mask = mask.copy(0, -h, w, h * 2);
     180            } else {
     181                // if we embedded real alpha, we still need a mask if we are going
     182                // to create a pointer out of this pixmap (WinCreatePointerIndirect()
     183                // requirement), but we will use QPixmap::mask() because it won't be
     184                // able to destroy the alpha channel of non-fully transparent pixels
     185                // when preparing the color bitmap for masking later. We could also
     186                // skip this prepare step, but well, let's go this way, it won't hurt.
     187                mask = this->mask().toImage().convertToFormat(QImage::Format_Mono);
     188
     189                // create the AND mask
     190                mask.invertPixels();
     191                // add the XOR mask (and leave it zeroed)
     192                mask = mask.copy(0, 0, w, h * 2);
     193                // flip the bitmap top to bottom for PM
     194                mask = mask.mirrored(false, true);
     195            }
    179196        } 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);
     197            mask = QImage(w, h * 2, QImage::Format_Mono);
     198            mask.fill(0);
    194199        }
    195200
    196201        // create the mask bitmap