static QImage qt_fromWinHBITMAP(HDC hdc, HBITMAP bitmap, int w, int h) { BITMAPINFO bmi; memset(&bmi, 0, sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = w; bmi.bmiHeader.biHeight = -h; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = w * h * 4; QImage image(w, h, QImage::Format_ARGB32_Premultiplied); if (image.isNull()) return image; // Get bitmap bits uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage); if (GetDIBits(hdc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) { // Create image and copy data into image. for (int y=0; y<h; ++y) { void *dest = (void *) image.scanLine(y); void *src = data + y * image.bytesPerLine(); memcpy(dest, src, image.bytesPerLine()); } } else { qWarning("qt_fromWinHBITMAP(), failed to get bitmap bits"); } qFree(data); return image; }
AudioDataOutputXT::AudioDataOutputXT(AudioDataOutput *output) : SinkNodeXT("AudioDataOutput"), SourceNodeXT("AudioDataOutput"), m_frontend(output), m_audioPort(0), m_postOutput(0) { m_xine = Backend::xine(); m_firstVpts = -1; // Dummy audio port, until we get the proper one xine_audio_port_t *port = xine_open_audio_driver(m_xine, "none", 0); // Allocate a new scope plugin m_plugin = (scope_plugin_t*)qMalloc(sizeof(scope_plugin_t)); // It is also a post plugin post_plugin_t *post_plugin = (post_plugin_t*)m_plugin; //1 audio input, 0 video inputs _x_post_init(post_plugin, 1, 0); // Intercept the null audio port (until we get the proper one) intercept(port, true); /* code is straight from xine_init_post() can't use that function as it only dlopens the plugins and our plugin is statically linked in */ post_plugin->running_ticket = (*m_xine).port_ticket; post_plugin->xine = m_xine; // Store a reference to our own object in the post plugin struct m_plugin->audioDataOutput = this; }
QMapData::Node *QMapData::node_create(Node *update[], int offset) { int level = 0; uint mask = (1 << Sparseness) - 1; while ((randomBits & mask) == mask && level < LastLevel) { ++level; mask <<= Sparseness; } ++randomBits; if (level == 3 && !insertInOrder) randomBits = qrand(); if (level > topLevel) { Node *e = reinterpret_cast<Node *>(this); level = ++topLevel; e->forward[level] = e; update[level] = e; } void *concreteNode = qMalloc(offset + sizeof(Node) + level * sizeof(Node *)); Node *abstractNode = reinterpret_cast<Node *>(reinterpret_cast<char *>(concreteNode) + offset); abstractNode->backward = update[0]; update[0]->forward[0]->backward = abstractNode; for (int i = level; i >= 0; i--) { abstractNode->forward[i] = update[i]->forward[i]; update[i]->forward[i] = abstractNode; update[i] = abstractNode; } ++size; return abstractNode; }
void QSGGeometry::allocate(int vertexCount, int indexCount) { if (vertexCount == m_vertex_count && indexCount == m_index_count) return; m_vertex_count = vertexCount; m_index_count = indexCount; bool canUsePrealloc = m_index_count <= 0; int vertexByteSize = m_attributes.stride * m_vertex_count; if (m_owns_data) qFree(m_data); if (canUsePrealloc && vertexByteSize <= (int) sizeof(m_prealloc)) { m_data = (void *) &m_prealloc[0]; m_index_data_offset = -1; m_owns_data = false; } else { Q_ASSERT(m_index_type == GL_UNSIGNED_INT || m_index_type == GL_UNSIGNED_SHORT); int indexByteSize = indexCount * (m_index_type == GL_UNSIGNED_SHORT ? sizeof(quint16) : sizeof(quint32)); m_data = (void *) qMalloc(vertexByteSize + indexByteSize); m_index_data_offset = vertexByteSize; m_owns_data = true; } }
QVectorData *QVectorData::malloc(int sizeofTypedData, int size, int sizeofT, QVectorData *init) { QVectorData* p = (QVectorData *)qMalloc(sizeofTypedData + (size - 1) * sizeofT); Q_CHECK_PTR(p); ::memcpy(p, init, sizeofTypedData + (qMin(size, init->alloc) - 1) * sizeofT); return p; }
/*! Returns the connection types associated with a signal or slot \a member specification. The array of types is returned from this function, and the number of arguments is returned in \a nargs. Returns null if \a member is invalid. The return value must be freed with qFree(). */ int *QSignalIntercepter::connectionTypes( const QByteArray& member, int& nargs ) { // Based on Qt's internal queuedConnectionTypes function. nargs = 0; int *types = 0; const char *s = member.constData(); while (*s != '\0' && *s != '(') { ++s; } if ( *s == '\0' ) return 0; ++s; const char *e = s; while (*e != ')') { ++e; if (*e == ')' || *e == ',') ++nargs; } types = (int *) qMalloc((nargs+1)*sizeof(int)); types[nargs] = 0; for (int n = 0; n < nargs; ++n) { e = s; while (*s != ',' && *s != ')') ++s; QByteArray type(e, s-e); ++s; types[n] = typeFromName(type); if (!types[n]) { qWarning("QSignalIntercepter::connectionTypes: Cannot marshal arguments of type '%s'", type.data()); qFree(types); return 0; } } return types; }
QListData::Data *QListData::detach() { Q_ASSERT(d->ref != 1); Data *x = static_cast<Data *>(qMalloc(DataHeaderSize + d->alloc * sizeof(void *))); ::memcpy(x, d, DataHeaderSize + d->alloc * sizeof(void *)); x->alloc = d->alloc; x->ref.init(1); x->sharable = true; if (!x->alloc) x->begin = x->end = 0; x = qAtomicSetPtr(&d, x); if (!x->ref.deref()) return x; return 0; }
// Returns the old (shared) data, it is up to the caller to deref() and free() QListData::Data *QListData::detach2() { Data *x = d; d = static_cast<Data *>(qMalloc(DataHeaderSize + x->alloc * sizeof(void *))); if (!d) qFatal("QList: Out of memory"); ::memcpy(d, x, DataHeaderSize + x->alloc * sizeof(void *)); d->alloc = x->alloc; d->ref = 1; d->sharable = true; if (!d->alloc) d->begin = d->end = 0; return x; }
QListData::Data *QListData::detach() { Data *x = static_cast<Data *>(qMalloc(DataHeaderSize + d->alloc * sizeof(void *))); if (!x) qFatal("QList: Out of memory"); ::memcpy(x, d, DataHeaderSize + d->alloc * sizeof(void *)); x->alloc = d->alloc; x->ref = 1; x->sharable = true; if (!x->alloc) x->begin = x->end = 0; qSwap(d, x); if (!x->ref.deref()) return x; return 0; }
const char *SettingsWidget::lookForWidgetState(QWidget *widget, const char *property, const char *signal) { const QMetaObject *meta = widget->metaObject(); WidgetInfo info = { widget, NULL, QVariant(), false }; bool free_signal = false; // Firstly try to search this widget in predefined classes if (!signal && !property) { for (int i = 0, size = sizeof(widget_infos) / sizeof(AbstractWidgetInfo*); i < size; i++) { if (widget_infos[i]->handle(widget)) { info.property = widget_infos[i]->property; signal = widget_infos[i]->signal; break; } } } // Then try to find "User" property with signal or signal by property if (!signal) { for (int i = 0, size = meta->propertyCount(); i < size; i++) { QMetaProperty prop = meta->property(i); if (prop.hasNotifySignal() && ((property && !qstrcmp(prop.name(), property)) || (!property && prop.isUser()))) { info.property = prop.name(); const char *sig = prop.notifySignal().signature(); int len = strlen(sig); char *str = (char *)qMalloc(sizeof(char) * (len + 2)); str[0] = QSIGNAL_CODE; qstrcpy(str + 1, sig); signal = str; free_signal = true; break; } } } bool result(signal); if (result) { p->mapper->setMapping(widget, p->infos.size()); connect(widget, signal, p->mapper, SLOT(map())); p->infos << info; } if (free_signal) qFree((void *)signal); return result ? info.property : 0; }
QList<int> QAudioDeviceInfoInternal::supportedChannelCounts() { QList<int> rc; // Can mix down to 1 channel rc << 1; UInt32 propSize = 0; int channels = 0; if (AudioDeviceGetPropertyInfo(deviceId, 0, mode == QAudio::AudioInput, kAudioDevicePropertyStreamConfiguration, &propSize, 0) == noErr) { AudioBufferList* audioBufferList = static_cast<AudioBufferList*>(qMalloc(propSize)); if (audioBufferList != 0) { if (AudioDeviceGetProperty(deviceId, 0, mode == QAudio::AudioInput, kAudioDevicePropertyStreamConfiguration, &propSize, audioBufferList) == noErr) { for (int i = 0; i < int(audioBufferList->mNumberBuffers); ++i) { channels += audioBufferList->mBuffers[i].mNumberChannels; rc << channels; } } qFree(audioBufferList); } } return rc; }
QString andrq::getString(QDataStream &in, int key) { qint32 len; in >> len; char *data = (char *)qMalloc(len); in.readRawData(data, len); int dh = 0, dl = 0; int temp = key; dl |= temp & 0x000000FF; temp >>= 20; dh |= temp & 0x000000FF; /* if (!ans) return false;*/ int ah = 184; //10111000b; for (int i = 0; i < len; ++i) { int al = uchar(data[i]); al ^= ah; al=(al%32)*8+al/32; //циклический сдвиг al на 3 бита влево al ^= dh; al -= dl; data[i] = char(al); ah=(ah%8)*32+ah/8; //циклический сдвиг ah вправо на 3 бита } static QTextCodec *ansii_codec = QTextCodec::codecForName("cp1251"); static QTextCodec *utf8_codec = QTextCodec::codecForName("utf-8"); QTextCodec *codec = isValidUtf8(QByteArray::fromRawData(data, len)) ? utf8_codec : ansii_codec; QString result = codec->toUnicode(data, len); qFree(data); return result; }
QString QHostInfo::localDomainName() { #if !defined(Q_OS_VXWORKS) resolveLibrary(); if (local_res_ninit) { // using thread-safe version res_state_ptr state = res_state_ptr(qMalloc(sizeof(*state))); Q_CHECK_PTR(state); memset(state, 0, sizeof(*state)); local_res_ninit(state); QString domainName = QUrl::fromAce(state->defdname); if (domainName.isEmpty()) domainName = QUrl::fromAce(state->dnsrch[0]); local_res_nclose(state); qFree(state); return domainName; } if (local_res_init && local_res) { // using thread-unsafe version #if defined(QT_NO_GETADDRINFO) // We have to call res_init to be sure that _res was initialized // So, for systems without getaddrinfo (which is thread-safe), we lock the mutex too QMutexLocker locker(::getHostByNameMutex()); #endif local_res_init(); QString domainName = QUrl::fromAce(local_res->defdname); if (domainName.isEmpty()) domainName = QUrl::fromAce(local_res->dnsrch[0]); return domainName; } #endif // nothing worked, try doing it by ourselves: QFile resolvconf; #if defined(_PATH_RESCONF) resolvconf.setFileName(QFile::decodeName(_PATH_RESCONF)); #else resolvconf.setFileName(QLatin1String("/etc/resolv.conf")); #endif if (!resolvconf.open(QIODevice::ReadOnly)) return QString(); // failure QString domainName; while (!resolvconf.atEnd()) { QByteArray line = resolvconf.readLine().trimmed(); if (line.startsWith("domain ")) return QUrl::fromAce(line.mid(sizeof "domain " - 1).trimmed()); // in case there's no "domain" line, fall back to the first "search" entry if (domainName.isEmpty() && line.startsWith("search ")) { QByteArray searchDomain = line.mid(sizeof "search " - 1).trimmed(); int pos = searchDomain.indexOf(' '); if (pos != -1) searchDomain.truncate(pos); domainName = QUrl::fromAce(searchDomain); } } // return the fallen-back-to searched domain return domainName; }
QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format) { // Verify size BITMAP bitmap_info; memset(&bitmap_info, 0, sizeof(BITMAP)); int res = GetObject(bitmap, sizeof(BITMAP), &bitmap_info); if (!res) { qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info"); return QPixmap(); } int w = bitmap_info.bmWidth; int h = bitmap_info.bmHeight; BITMAPINFO bmi; memset(&bmi, 0, sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = w; bmi.bmiHeader.biHeight = -h; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = w * h * 4; QImage result; // Get bitmap bits uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage); HDC display_dc = GetDC(0); if (GetDIBits(display_dc, bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) { QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied; uint mask = 0; if (format == NoAlpha) { imageFormat = QImage::Format_RGB32; mask = 0xff000000; } // Create image and copy data into image. QImage image(w, h, imageFormat); if (!image.isNull()) { // failed to alloc? int bytes_per_line = w * sizeof(QRgb); for (int y=0; y<h; ++y) { QRgb *dest = (QRgb *) image.scanLine(y); const QRgb *src = (const QRgb *) (data + y * bytes_per_line); for (int x=0; x<w; ++x) { const uint pixel = src[x]; if ((pixel & 0xff000000) == 0 && (pixel & 0x00ffffff) != 0) dest[x] = pixel | 0xff000000; else dest[x] = pixel | mask; } } } result = image; } else { qWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap bits"); } ReleaseDC(0, display_dc); qFree(data); return fromImage(result); }
QVectorData *QVectorData::allocate(int size, int alignment) { return static_cast<QVectorData *>(alignment > alignmentThreshold() ? qMallocAligned(size, alignment) : qMalloc(size)); }
qStack *qCreateStack(void(*free)(void *value)) { qStack *p = qMalloc(sizeof(qStack)); p->list = qCreateLinkList(free, NULL); return p; }