QBitmap basicSegmentation::xand(QBitmap am, QBitmap bm) { int x, y, ap, bp; QImage a = am.toImage(); QImage b = bm.toImage(); QImage r = QImage(am.width(), am.height(), QImage::Format_Mono); for(x=0; x < am.width(); x++) { for(y=0;y < am.height(); y++) { ap=qRed(a.pixel(x,y)); bp=qRed(b.pixel(x,y)); if(ap == 0 && bp == 0){ r.setPixel(x, y, Qt::color0); } else { r.setPixel(x, y, Qt::color1); } } } return(QBitmap::fromImage(r)); }
void PixmapEditor::setValue(const QBitmap &aValue) { mValue=QPixmap::fromImage(aValue.toImage()); ui->valueEdit->setText(bitmapToString(aValue)); setIcon(iconForPixmap(mValue)); mDataType=BITMAP; }
HBITMAP qt_createIconMask(const QBitmap &bitmap) { QImage bm = bitmap.toImage().convertToFormat(QImage::Format_Mono); int w = bm.width(); int h = bm.height(); int bpl = ((w+15)/16)*2; // bpl, 16 bit alignment uchar *bits = new uchar[bpl*h]; bm.invertPixels(); for (int y=0; y<h; y++) memcpy(bits+y*bpl, bm.scanLine(y), bpl); HBITMAP hbm = CreateBitmap(w, h, 1, 1, bits); delete [] bits; return hbm; }
QBitmap basicSegmentation::erode(QBitmap mm, int count) { int x, y, p, p1, p2, p3, p4, n; QImage m = mm.toImage(); p=qRed(m.pixel(1,1)); for(n=0; n < count; n++) { QImage gm = QImage(m.width(), m.height(), QImage::Format_Mono); for(x=0; x < m.width(); x++) { gm.setPixel(x, 0, Qt::color1); gm.setPixel(x, m.width()-1, Qt::color1); } for(y=1;y < (m.height()-1); y++) { gm.setPixel(0, y, Qt::color1); gm.setPixel(m.height()-1, y, Qt::color1); } for(x=1; x < (m.width()-1); x++) { for(y=1;y < (m.height()-1); y++) { p=qRed(m.pixel(x,y)); if(p == 0){ p1 = qRed(m.pixel(x-1, y)); p2 = qRed(m.pixel(x+1, y)); p3 = qRed(m.pixel(x, y-1)); p4 = qRed(m.pixel(x, y+1)); if(p1 == 255 || p2 == 255 || p3 == 255 || p4 == 255) { gm.setPixel(x,y, Qt::color1); } else { gm.setPixel(x,y, Qt::color0); } } else { gm.setPixel(x,y, Qt::color1); } } } m = gm; } return(QBitmap::fromImage(m)); }
QIntMatrix basicSegmentation::find(QBitmap mask, int minsize) { int y, x, a, l, t, eqI, eqTI, eqV, w, h, eqMaxI=1, newID = 2; bool done; QIntMatrix r(mask.width(), mask.height()); QImage im = mask.toImage(); QVector<int> u, eq, counts; w = mask.width(); h = mask.height(); for(y = 0; y < h; y++) { for(x = 0; x < w; x++) { a = qRed(im.pixel(x, y)); if(a == 0) { r.set(x, y, 1); } else { r.set(x, y, 0); } } } eq = QVector<int>(2); counts = QVector<int>(2); for(y = 1; y < (h - 1); y++) { for(x = 1; x < (w - 1); x++) { a = r.at(x, y-1); l = r.at(x-1, y); t = r.at(x, y); if (t == 1) { if (a == l && a > 1) { r.set(x, y, a); if(a > (counts.size()-1)) { counts.resize(a+1); } counts[a]++; } else if (a != l && a > 1 && l > 1) { r.set(x, y, mathmin(a, l)); if(mathmin(a, l) > (counts.size()-1)) { counts.resize(mathmin(a, l)+1); } counts[mathmin(a, l)]++; eqI = mathmax(a,l); eqV = mathmin(a,l); done = false; while (!done) { if (eqI > eqMaxI) { eq.resize(eqI+1); eqMaxI = eqI; } if ((eq.at(eqI) > 1)) { if (eqV != eq.at(eqI)) { eqTI = eqI; eqI = mathmax(eqV, eq.at(eqTI)); eqV = mathmin(eqV, eq.at(eqTI)); eq[eqTI] = eqV; } else { eq[eqI] = eqV; done = true; } } else { eq[eqI] = eqV; done = true; } } } else if (mathmax(a,l) > 1) { r.set(x, y, mathmax(a, l)); if(mathmax(a, l) > (counts.size()-1)) { counts.resize(mathmax(a, l)+1); } counts[mathmax(a, l)]++; } else { r.set(x, y, newID++); counts.resize(newID+1); counts[newID]=1; } } else { r.set(x, y, 0); } } } //clean up edges r.replace(1, 0); //resolve equivalent ids if(eqMaxI > 1) { resolveEq(&r, eq, counts, minsize); } return(r); }
void QCursorData::update() { if (!QCursorData::initialized) QCursorData::initialize(); if (hcurs) return; if (cshape == Qt::BitmapCursor && !pixmap.isNull()) { hcurs = create32BitCursor(pixmap, hx, hy); if (hcurs) return; } // Non-standard Windows cursors are created from bitmaps static const uchar vsplit_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar vsplitm_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar hsplit_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x41, 0x82, 0x00, 0x80, 0x41, 0x82, 0x01, 0xc0, 0x7f, 0xfe, 0x03, 0x80, 0x41, 0x82, 0x01, 0x00, 0x41, 0x82, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar hsplitm_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe3, 0xc7, 0x00, 0x80, 0xe3, 0xc7, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07, 0xc0, 0xff, 0xff, 0x03, 0x80, 0xe3, 0xc7, 0x01, 0x00, 0xe3, 0xc7, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar phand_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x80, 0x1c, 0x00, 0x00, 0x80, 0xe4, 0x00, 0x00, 0x80, 0x24, 0x03, 0x00, 0x80, 0x24, 0x05, 0x00, 0xb8, 0x24, 0x09, 0x00, 0xc8, 0x00, 0x09, 0x00, 0x88, 0x00, 0x08, 0x00, 0x90, 0x00, 0x08, 0x00, 0xa0, 0x00, 0x08, 0x00, 0x20, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x04, 0x00, 0x80, 0x00, 0x04, 0x00, 0x80, 0x00, 0x04, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar phandm_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x80, 0xff, 0x03, 0x00, 0x80, 0xff, 0x07, 0x00, 0xb8, 0xff, 0x0f, 0x00, 0xf8, 0xff, 0x0f, 0x00, 0xf8, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0x0f, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0xc0, 0xff, 0x0f, 0x00, 0xc0, 0xff, 0x07, 0x00, 0x80, 0xff, 0x07, 0x00, 0x80, 0xff, 0x07, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar openhand_bits[] = { 0x80,0x01,0x58,0x0e,0x64,0x12,0x64,0x52,0x48,0xb2,0x48,0x92, 0x16,0x90,0x19,0x80,0x11,0x40,0x02,0x40,0x04,0x40,0x04,0x20, 0x08,0x20,0x10,0x10,0x20,0x10,0x00,0x00}; static const uchar openhandm_bits[] = { 0x80,0x01,0xd8,0x0f,0xfc,0x1f,0xfc,0x5f,0xf8,0xff,0xf8,0xff, 0xf6,0xff,0xff,0xff,0xff,0x7f,0xfe,0x7f,0xfc,0x7f,0xfc,0x3f, 0xf8,0x3f,0xf0,0x1f,0xe0,0x1f,0x00,0x00}; static const uchar closedhand_bits[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0x48,0x32,0x08,0x50, 0x10,0x40,0x18,0x40,0x04,0x40,0x04,0x20,0x08,0x20,0x10,0x10, 0x20,0x10,0x20,0x10,0x00,0x00,0x00,0x00}; static const uchar closedhandm_bits[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0xf8,0x3f,0xf8,0x7f, 0xf0,0x7f,0xf8,0x7f,0xfc,0x7f,0xfc,0x3f,0xf8,0x3f,0xf0,0x1f, 0xe0,0x1f,0xe0,0x1f,0x00,0x00,0x00,0x00}; static const uchar * const cursor_bits32[] = { vsplit_bits, vsplitm_bits, hsplit_bits, hsplitm_bits, phand_bits, phandm_bits }; wchar_t *sh = 0; switch (cshape) { // map to windows cursor case Qt::ArrowCursor: sh = IDC_ARROW; break; case Qt::UpArrowCursor: sh = IDC_UPARROW; break; case Qt::CrossCursor: sh = IDC_CROSS; break; case Qt::WaitCursor: sh = IDC_WAIT; break; case Qt::IBeamCursor: sh = IDC_IBEAM; break; case Qt::SizeVerCursor: sh = IDC_SIZENS; break; case Qt::SizeHorCursor: sh = IDC_SIZEWE; break; case Qt::SizeBDiagCursor: sh = IDC_SIZENESW; break; case Qt::SizeFDiagCursor: sh = IDC_SIZENWSE; break; case Qt::SizeAllCursor: sh = IDC_SIZEALL; break; case Qt::ForbiddenCursor: sh = IDC_NO; break; case Qt::WhatsThisCursor: sh = IDC_HELP; break; case Qt::BusyCursor: sh = IDC_APPSTARTING; break; case Qt::PointingHandCursor: sh = IDC_HAND; break; case Qt::BlankCursor: case Qt::SplitVCursor: case Qt::SplitHCursor: case Qt::OpenHandCursor: case Qt::ClosedHandCursor: case Qt::BitmapCursor: { QImage bbits, mbits; bool invb, invm; if (cshape == Qt::BlankCursor) { bbits = QImage(32, 32, QImage::Format_Mono); bbits.fill(0); // ignore color table mbits = bbits.copy(); hx = hy = 16; invb = invm = false; } else if (cshape == Qt::OpenHandCursor || cshape == Qt::ClosedHandCursor) { bool open = cshape == Qt::OpenHandCursor; QBitmap cb = QBitmap::fromData(QSize(16, 16), open ? openhand_bits : closedhand_bits); QBitmap cm = QBitmap::fromData(QSize(16, 16), open ? openhandm_bits : closedhandm_bits); bbits = cb.toImage().convertToFormat(QImage::Format_Mono); mbits = cm.toImage().convertToFormat(QImage::Format_Mono); hx = hy = 8; invb = invm = false; } else if (cshape != Qt::BitmapCursor) { int i = cshape - Qt::SplitVCursor; QBitmap cb = QBitmap::fromData(QSize(32, 32), cursor_bits32[i * 2]); QBitmap cm = QBitmap::fromData(QSize(32, 32), cursor_bits32[i * 2 + 1]); bbits = cb.toImage().convertToFormat(QImage::Format_Mono); mbits = cm.toImage().convertToFormat(QImage::Format_Mono); if (cshape == Qt::PointingHandCursor) { hx = 7; hy = 0; } else hx = hy = 16; invb = invm = false; } else { bbits = bm->toImage().convertToFormat(QImage::Format_Mono); mbits = bmm->toImage().convertToFormat(QImage::Format_Mono); invb = bbits.colorCount() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1)); invm = mbits.colorCount() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1)); } int n = qMax(1, bbits.width() / 8); int h = bbits.height(); #if !defined(Q_WS_WINCE) uchar* xBits = new uchar[h * n]; uchar* xMask = new uchar[h * n]; int x = 0; for (int i = 0; i < h; ++i) { uchar *bits = bbits.scanLine(i); uchar *mask = mbits.scanLine(i); for (int j = 0; j < n; ++j) { uchar b = bits[j]; uchar m = mask[j]; if (invb) b ^= 0xff; if (invm) m ^= 0xff; xBits[x] = ~m; xMask[x] = b ^ m; ++x; } } hcurs = CreateCursor(qWinAppInst(), hx, hy, bbits.width(), bbits.height(), xBits, xMask); delete [] xBits; delete [] xMask; #elif defined(GWES_ICONCURS) // Q_WS_WINCE // Windows CE only supports fixed cursor size. int sysW = GetSystemMetrics(SM_CXCURSOR); int sysH = GetSystemMetrics(SM_CYCURSOR); int sysN = qMax(1, sysW / 8); uchar* xBits = new uchar[sysH * sysN]; uchar* xMask = new uchar[sysH * sysN]; int x = 0; for (int i = 0; i < sysH; ++i) { if (i >= h) { memset(&xBits[x] , 255, sysN); memset(&xMask[x] , 0, sysN); x += sysN; } else { int fillWidth = n > sysN ? sysN : n; uchar *bits = bbits.scanLine(i); uchar *mask = mbits.scanLine(i); for (int j = 0; j < fillWidth; ++j) { uchar b = bits[j]; uchar m = mask[j]; if (invb) b ^= 0xFF; if (invm) m ^= 0xFF; xBits[x] = ~m; xMask[x] = b ^ m; ++x; } for (int j = fillWidth; j < sysN; ++j ) { xBits[x] = 255; xMask[x] = 0; ++x; } } } hcurs = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH, xBits, xMask); delete [] xBits; delete [] xMask; #else Q_UNUSED(n); Q_UNUSED(h); #endif return; } default: qWarning("QCursor::update: Invalid cursor shape %d", cshape); return; } #ifdef Q_WS_WINCE hcurs = LoadCursor(0, sh); #else hcurs = (HCURSOR)LoadImage(0, sh, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED); #endif }
HCURSOR QWindowsCursor::createSystemCursor(const QCursor &c) { int hx = c.hotSpot().x(); int hy = c.hotSpot().y(); const Qt::CursorShape cshape = c.shape(); if (cshape == Qt::BitmapCursor) { const QPixmap pixmap = c.pixmap(); if (!pixmap.isNull()) if (const HCURSOR hc = createPixmapCursor(pixmap, hx, hy)) return hc; } // Non-standard Windows cursors are created from bitmaps static const uchar vsplit_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar vsplitm_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar hsplit_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x41, 0x82, 0x00, 0x80, 0x41, 0x82, 0x01, 0xc0, 0x7f, 0xfe, 0x03, 0x80, 0x41, 0x82, 0x01, 0x00, 0x41, 0x82, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar hsplitm_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe3, 0xc7, 0x00, 0x80, 0xe3, 0xc7, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07, 0xc0, 0xff, 0xff, 0x03, 0x80, 0xe3, 0xc7, 0x01, 0x00, 0xe3, 0xc7, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uchar openhand_bits[] = { 0x80,0x01,0x58,0x0e,0x64,0x12,0x64,0x52,0x48,0xb2,0x48,0x92, 0x16,0x90,0x19,0x80,0x11,0x40,0x02,0x40,0x04,0x40,0x04,0x20, 0x08,0x20,0x10,0x10,0x20,0x10,0x00,0x00}; static const uchar openhandm_bits[] = { 0x80,0x01,0xd8,0x0f,0xfc,0x1f,0xfc,0x5f,0xf8,0xff,0xf8,0xff, 0xf6,0xff,0xff,0xff,0xff,0x7f,0xfe,0x7f,0xfc,0x7f,0xfc,0x3f, 0xf8,0x3f,0xf0,0x1f,0xe0,0x1f,0x00,0x00}; static const uchar closedhand_bits[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0x48,0x32,0x08,0x50, 0x10,0x40,0x18,0x40,0x04,0x40,0x04,0x20,0x08,0x20,0x10,0x10, 0x20,0x10,0x20,0x10,0x00,0x00,0x00,0x00}; static const uchar closedhandm_bits[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0xf8,0x3f,0xf8,0x7f, 0xf0,0x7f,0xf8,0x7f,0xfc,0x7f,0xfc,0x3f,0xf8,0x3f,0xf0,0x1f, 0xe0,0x1f,0xe0,0x1f,0x00,0x00,0x00,0x00}; wchar_t *sh = 0; switch (c.shape()) { // map to windows cursor case Qt::ArrowCursor: sh = IDC_ARROW; break; case Qt::UpArrowCursor: sh = IDC_UPARROW; break; case Qt::CrossCursor: sh = IDC_CROSS; break; case Qt::WaitCursor: sh = IDC_WAIT; break; case Qt::IBeamCursor: sh = IDC_IBEAM; break; case Qt::SizeVerCursor: sh = IDC_SIZENS; break; case Qt::SizeHorCursor: sh = IDC_SIZEWE; break; case Qt::SizeBDiagCursor: sh = IDC_SIZENESW; break; case Qt::SizeFDiagCursor: sh = IDC_SIZENWSE; break; case Qt::SizeAllCursor: sh = IDC_SIZEALL; break; case Qt::ForbiddenCursor: sh = IDC_NO; break; case Qt::WhatsThisCursor: sh = IDC_HELP; break; case Qt::BusyCursor: sh = IDC_APPSTARTING; break; case Qt::PointingHandCursor: sh = IDC_HAND; break; case Qt::BlankCursor: case Qt::SplitVCursor: case Qt::SplitHCursor: case Qt::OpenHandCursor: case Qt::ClosedHandCursor: case Qt::BitmapCursor: { QImage bbits, mbits; bool invb, invm; if (cshape == Qt::BlankCursor) { bbits = QImage(32, 32, QImage::Format_Mono); bbits.fill(0); // ignore color table mbits = bbits.copy(); hx = hy = 16; invb = invm = false; } else if (cshape == Qt::OpenHandCursor || cshape == Qt::ClosedHandCursor) { bool open = cshape == Qt::OpenHandCursor; QBitmap cb = QBitmap::fromData(QSize(16, 16), open ? openhand_bits : closedhand_bits); QBitmap cm = QBitmap::fromData(QSize(16, 16), open ? openhandm_bits : closedhandm_bits); bbits = cb.toImage().convertToFormat(QImage::Format_Mono); mbits = cm.toImage().convertToFormat(QImage::Format_Mono); hx = hy = 8; invb = invm = false; } else if (cshape == Qt::BitmapCursor) { bbits = c.bitmap()->toImage().convertToFormat(QImage::Format_Mono); mbits = c.mask()->toImage().convertToFormat(QImage::Format_Mono); invb = bbits.colorCount() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1)); invm = mbits.colorCount() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1)); } else { // Qt::SplitVCursor, Qt::SplitHCursor const QBitmap cb = QBitmap::fromData(QSize(32, 32), cshape == Qt::SplitVCursor ? vsplit_bits : hsplit_bits); const QBitmap cm = QBitmap::fromData(QSize(32, 32), cshape == Qt::SplitVCursor ? vsplitm_bits : hsplitm_bits); bbits = cb.toImage().convertToFormat(QImage::Format_Mono); mbits = cm.toImage().convertToFormat(QImage::Format_Mono); hx = hy = 16; invb = invm = false; } const int n = qMax(1, bbits.width() / 8); const int h = bbits.height(); #if !defined(Q_OS_WINCE) QScopedArrayPointer<uchar> xBits(new uchar[h * n]); QScopedArrayPointer<uchar> xMask(new uchar[h * n]); int x = 0; for (int i = 0; i < h; ++i) { uchar *bits = bbits.scanLine(i); uchar *mask = mbits.scanLine(i); for (int j = 0; j < n; ++j) { uchar b = bits[j]; uchar m = mask[j]; if (invb) b ^= 0xff; if (invm) m ^= 0xff; xBits[x] = ~m; xMask[x] = b ^ m; ++x; } } return CreateCursor(GetModuleHandle(0), hx, hy, bbits.width(), bbits.height(), xBits.data(), xMask.data()); #elif defined(GWES_ICONCURS) // Q_WS_WINCE // Windows CE only supports fixed cursor size. int sysW = GetSystemMetrics(SM_CXCURSOR); int sysH = GetSystemMetrics(SM_CYCURSOR); int sysN = qMax(1, sysW / 8); uchar* xBits = new uchar[sysH * sysN]; uchar* xMask = new uchar[sysH * sysN]; int x = 0; for (int i = 0; i < sysH; ++i) { if (i >= h) { memset(&xBits[x] , 255, sysN); memset(&xMask[x] , 0, sysN); x += sysN; } else { int fillWidth = n > sysN ? sysN : n; uchar *bits = bbits.scanLine(i); uchar *mask = mbits.scanLine(i); for (int j = 0; j < fillWidth; ++j) { uchar b = bits[j]; uchar m = mask[j]; if (invb) b ^= 0xFF; if (invm) m ^= 0xFF; xBits[x] = ~m; xMask[x] = b ^ m; ++x; } for (int j = fillWidth; j < sysN; ++j ) { xBits[x] = 255; xMask[x] = 0; ++x; } } } HCURSOR hcurs = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH, xBits, xMask); delete [] xBits; delete [] xMask; return hcurs; #else Q_UNUSED(n); Q_UNUSED(h); return 0; #endif } case Qt::DragCopyCursor: case Qt::DragMoveCursor: case Qt::DragLinkCursor: { const QPixmap pixmap = QGuiApplicationPrivate::instance()->getPixmapCursor(cshape); return createPixmapCursor(pixmap, hx, hy); } default: qWarning("%s: Invalid cursor shape %d", __FUNCTION__, cshape); return 0; } #ifdef Q_OS_WINCE return LoadCursor(0, sh); #else return (HCURSOR)LoadImage(0, sh, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED); #endif }
HRGN qt_win_bitmapToRegion(const QBitmap& bitmap) { HRGN region=0; QImage image = bitmap.toImage(); const int MAXRECT = 256; struct RData { RGNDATAHEADER header; RECT rect[MAXRECT]; }; RData data; #define FlushSpans \ { \ data.header.dwSize = sizeof(RGNDATAHEADER); \ data.header.iType = RDH_RECTANGLES; \ data.header.nCount = n; \ data.header.nRgnSize = 0; \ data.header.rcBound.bottom = y; \ HRGN r = ExtCreateRegion(0, \ sizeof(RGNDATAHEADER)+n*sizeof(RECT),(RGNDATA*)&data); \ if (region) { \ CombineRgn(region, region, r, RGN_OR); \ DeleteObject(r); \ } else { \ region = r; \ } \ data.header.rcBound.top = y; \ } #define AddSpan \ { \ data.rect[n].left=prev1; \ data.rect[n].top=y; \ data.rect[n].right=x-1+1; \ data.rect[n].bottom=y+1; \ n++; \ if (n == MAXRECT) { \ FlushSpans \ n=0; \ } \ } data.header.rcBound.top = 0; data.header.rcBound.left = 0; data.header.rcBound.right = image.width()-1; int n = 0; int zero = 0x00; int x, y; for (y = 0; y < image.height(); ++y) { uchar *line = image.scanLine(y); int w = image.width(); uchar all=zero; int prev1 = -1; for (x = 0; x < w;) { uchar byte = line[x/8]; if (x > w - 8 || byte != all) { for (int b = 8; b > 0 && x < w; --b) { if (!(byte & 0x01) == !all) { // More of the same } else { // A change. if (all != zero) { AddSpan; all = zero; } else { prev1 = x; all = ~zero; } } byte >>= 1; ++x; } } else { x += 8; } } if (all != zero) { AddSpan; } }