qint64 SerialDevice::readData(char *data, qint64 maxSize)
{
    if(!isOpen())
    {
        setErrorString(m_errorStrings[0]); return 0;
    }

    qint64 size = qMin(m_readBuffer.size(), int(maxSize));
    qMemCopy(data, m_readBuffer.constData(), size);
    m_readBuffer.remove(0, size); return size;
}
/*!
    Returns the position of the edge of the baseline for each glyph in this set of glyph indexes.
*/
QVector<QPointF> QGlyphRun::positions() const
{
    if (d->glyphPositions.constData() == d->glyphPositionData) {
        return d->glyphPositions;
    } else {
        QVector<QPointF> glyphPositions(d->glyphPositionDataSize);
        qMemCopy(glyphPositions.data(), d->glyphPositionData,
                 d->glyphPositionDataSize * sizeof(QPointF));
        return glyphPositions;
    }
}
Esempio n. 3
0
qint64 KNetworkReply::readData(char *data, qint64 maxSize)
{
//     kDebug();
    qint64 length = qMin(qint64(d->m_data.length()), maxSize);
    if (length) {
        qMemCopy(data, d->m_data.constData(), length);
        d->m_data.remove(0, length);
    }

    return length;
}
qint64 SerialDevice::readDataExtern(char *data, qint64 maxSize)
{
    if(!m_port)
    {
        return 0;
    }

    qint64 size = qMin(m_writeBuffer.size(), int(maxSize));
    qMemCopy(data, m_writeBuffer.constData(), size);
    m_writeBuffer.remove(0, size); return size;
}
HRESULT VideoSurfaceFilter::QueryId(LPWSTR *Id)
{
    if (!Id) {
        return E_POINTER;
    } else {
        const int bytes = (m_pinId.length() + 1) * 2;

        *Id = static_cast<LPWSTR>(::CoTaskMemAlloc(bytes));

        qMemCopy(*Id, m_pinId.utf16(), bytes);

        return S_OK;
    }
}
static inline double QLongDoubleValidator_snan()
{
    const unsigned char *bytes;
#ifdef QT_ARMFPA
    bytes = qt_armfpa_snan_bytes;
#else
    bytes = (QSysInfo::ByteOrder == QSysInfo::BigEndian
        ? QLongDoubleValidator_be_snan_bytes
        : QLongDoubleValidator_le_snan_bytes);
#endif

    union { unsigned char c[8]; double d; } returnValue;
    qMemCopy(returnValue.c, bytes, sizeof(returnValue.c));
    return returnValue.d;
}
Esempio n. 7
0
              HRESULT read(LONGLONG pos, LONG length, BYTE *buffer, LONG *actual)
              {
                  QMutexLocker locker(&m_mutexRead);

                  if (m_mediaGraph->isStopping()) {
                      return VFW_E_WRONG_STATE;
                  }

                  if(streamSize() != 1 && pos + length > streamSize()) {
                      //it tries to read outside of the boundaries
                      return E_FAIL;
                  }

                  if (currentPos() - currentBufferSize() != pos) {
                      if (!streamSeekable()) {
                          return S_FALSE;
                      }
                      setCurrentPos(pos);
                  }

                  int oldSize = currentBufferSize();
                  while (currentBufferSize() < int(length)) {
                      needData();
                      if (m_mediaGraph->isStopping()) {
                          return VFW_E_WRONG_STATE;
                      }

                      if (oldSize == currentBufferSize()) {
                          break; //we didn't get any data
                      }
                      oldSize = currentBufferSize();
                  }

                  DWORD bytesRead = qMin(currentBufferSize(), int(length));
                  {
                      QWriteLocker locker(&m_lock);
                      qMemCopy(buffer, m_buffer.data(), bytesRead);
                      //truncate the buffer
                      m_buffer = m_buffer.mid(bytesRead);
                  }

                  if (actual) {
                      *actual = bytesRead; //initialization
                  }

                  return bytesRead == length ? S_OK : S_FALSE;
              }
HRESULT VideoSurfaceFilter::QueryPinInfo(PIN_INFO *pInfo)
{
    if (!pInfo) {
        return E_POINTER;
    } else {
        AddRef();

        pInfo->pFilter = this;
        pInfo->dir = PINDIR_INPUT;

        const int bytes = qMin(MAX_FILTER_NAME, (m_pinId.length() + 1) * 2);

        qMemCopy(pInfo->achName, m_pinId.utf16(), bytes);

        return S_OK;
    }
}
Esempio n. 9
0
//! Wrapper for QPainter::drawPolyline()
void QwtPainter::drawPolyline( QPainter *painter,
    const QPointF *points, int pointCount )
{
    QRectF clipRect;
    const bool deviceClipping = isClippingNeeded( painter, clipRect );

    if ( deviceClipping )
    {
        QPolygonF polygon( pointCount );
        qMemCopy( polygon.data(), points, pointCount * sizeof( QPointF ) );

        polygon = QwtClipper::clipPolygonF( clipRect, polygon );
        ::drawPolyline( painter,
            polygon.constData(), polygon.size(), d_polylineSplitting );
    }
    else
        ::drawPolyline( painter, points, pointCount, d_polylineSplitting );
}
        qint64 IOWrapper::readData(char * data, qint64 maxSize)
        {
            int oldSize = m_streamReader.currentBufferSize();
            while (m_streamReader.currentBufferSize() < maxSize) {
                m_streamReader.needData();
                if (oldSize == m_streamReader.currentBufferSize()) {
                    break; //we didn't get any data
                }
                oldSize = m_streamReader.currentBufferSize();
            }

            qint64 bytesRead = qMin(qint64(m_streamReader.currentBufferSize()), maxSize);
            {
                QWriteLocker locker(&m_streamReader.m_lock);
                qMemCopy(data, m_streamReader.m_buffer.data(), bytesRead);
                //truncate the buffer
                m_streamReader.m_buffer = m_streamReader.m_buffer.mid(bytesRead);
            }
            return bytesRead;
        }
Esempio n. 11
0
        QImage VideoRendererEVR::snapshot() const
        {
            // This will always capture black areas where no video is drawn, if any are present.
            // Due to the hack in notifyResize()
            ComPointer<IMFVideoDisplayControl> filterControl = getService<IMFVideoDisplayControl>(m_filter, MR_VIDEO_RENDER_SERVICE, IID_IMFVideoDisplayControl);
            if (filterControl) {
                BITMAPINFOHEADER bmi;
                BYTE *buffer = 0;
                DWORD bufferSize;
                LONGLONG timeStamp;

                bmi.biSize = sizeof(BITMAPINFOHEADER);

                HRESULT hr = filterControl->GetCurrentImage(&bmi, &buffer, &bufferSize, &timeStamp);
                if (SUCCEEDED(hr)) {

                    const int w = qAbs(bmi.biWidth),
                        h = qAbs(bmi.biHeight);

                    // Create image and copy data into image.
                    QImage ret(w, h, QImage::Format_RGB32);

                    if (!ret.isNull()) {
                        uchar *data = buffer;
                        const int bytes_per_line = w * sizeof(QRgb);
                        for (int y = h - 1; y >= 0; --y) {
                            qMemCopy(ret.scanLine(y), //destination
                                data,     //source
                                bytes_per_line);
                            data += bytes_per_line;
                        }
                    }
                    ::CoTaskMemFree(buffer);
                    return ret;
                }
            }
            return QImage();
        }
Esempio n. 12
0
static
void CALLBACK_CALL_TYPE iod_read_fn(png_structp png_ptr, png_bytep data, png_size_t length)
{
    QPngHandlerPrivate *d = (QPngHandlerPrivate *)png_get_io_ptr(png_ptr);
    QIODevice *in = d->q->device();

    if (d->state == QPngHandlerPrivate::ReadingEnd && !in->isSequential() && (in->size() - in->pos()) < 4 && length == 4) {
        // Workaround for certain malformed PNGs that lack the final crc bytes
        uchar endcrc[4] = { 0xae, 0x42, 0x60, 0x82 };
        qMemCopy(data, endcrc, 4);
        in->seek(in->size());
        return;
    }

    while (length) {
        int nr = in->read((char*)data, length);
        if (nr <= 0) {
            png_error(png_ptr, "Read Error");
            return;
        }
        length -= nr;
    }
}
        QImage VideoRendererDefault::snapshot() const
        {
            ComPointer<IBasicVideo> basic(m_filter, IID_IBasicVideo);
            if (basic) {
                LONG bufferSize = 0;
                //1st we get the buffer size
                basic->GetCurrentImage(&bufferSize, 0);

                QByteArray buffer;
                buffer.resize(bufferSize);
                HRESULT hr = basic->GetCurrentImage(&bufferSize, reinterpret_cast<long*>(buffer.data()));

                if (SUCCEEDED(hr)) {

                    const BITMAPINFOHEADER  *bmi = reinterpret_cast<const BITMAPINFOHEADER*>(buffer.constData());

                    const int w = qAbs(bmi->biWidth),
                        h = qAbs(bmi->biHeight);

                    // Create image and copy data into image.
                    QImage ret(w, h, QImage::Format_RGB32);

                    if (!ret.isNull()) {
                        const char *data = buffer.constData() + bmi->biSize;
                        const int bytes_per_line = w * sizeof(QRgb);
                        for (int y = h - 1; y >= 0; --y) {
                            qMemCopy(ret.scanLine(y), //destination
                                data,     //source
                                bytes_per_line);
                            data += bytes_per_line;
                        }
                    }
                    return ret;
                }
            }
            return QImage();
        }
Esempio n. 14
0
/*!
    Assigns the \a other byte array matcher to this byte array matcher.
*/
QByteArrayMatcher &QByteArrayMatcher::operator=(const QByteArrayMatcher &other)
{
    q_pattern = other.q_pattern;
    qMemCopy(&p, &other.p, sizeof(p));
    return *this;
}
Esempio n. 15
0
bool PointModel::dropMimeData(const QMimeData *data,
                              Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
    //qDebug() << action << row << column << parent << data->formats() << data->data(MIME_RAW_POINT_TYPE);
    if (!data->formats().contains(MIME_RAW_POINT_TYPE)) return false;
    quint16 cnt=0;
    qint64 aPid=0;
    QByteArray ba=data->data(MIME_RAW_POINT_TYPE);

    qMemCopy(&aPid, ba.constData(),sizeof(aPid));
    ba.remove(0,sizeof(aPid));

    qMemCopy(&cnt,ba.constData(),sizeof(cnt));
    ba.remove(0,sizeof(cnt));

    bool moveMode=true;
    if (aPid!=qApp->applicationPid()) moveMode=false;

    FavPointsList tmpPL;

    for (int i=0;i<cnt;i++) {
        favRecord_t favRawPoint;
        qMemCopy(&favRawPoint,ba.constData(), sizeof(favRecord_t));
        addRawPointToPointList(favRawPoint, tmpPL);
        ba.remove(0, sizeof(favRecord_t));
        int uuidLen;
        qMemCopy(&uuidLen,ba.constData(),sizeof(uuidLen));
        ba.remove(0,sizeof(uuidLen));

        QByteArray dsBa = ba.left(uuidLen);
        QUuid uuid = QUuid(QString(dsBa));
        favPoints_t * fp = &tmpPL[tmpPL.count()-1];
        fp->uuid = uuid;
        ba.remove(0,uuidLen);
    }

    if (moveMode) {
        //режим, когда записи перемещаются внутри одного приложения...
        if (!parent.isValid()) return false;
        else {
            QUuid parUUID = pointList.at(parent.row()).uuid;
            for (int i=0;i<tmpPL.count();i++) {
                for (int i2=0;i2<pointList.count();i2++) {
                    if (pointList.at(i2).uuid == tmpPL.at(i).uuid) {
                        removeRow(i2);
                        break;
                    }//if
                }//for i2
            }//for
            int pntInd=0;
            for (int i=0;i<pointList.count();i++) {
                if (parUUID==pointList.at(i).uuid) { pntInd = i; break; }
            }
            for (int i=0;i<tmpPL.count(); i++) {
                beginInsertRows(QModelIndex(), pntInd, pntInd);
                pointList.insert(pntInd,tmpPL.at(i));
                endInsertRows();
                pntInd+=1;
            }
        }//else if (!parent.isValid())
    } else {
        int pntInd=0;
        if (parent.isValid()) {
            QUuid parUUID = pointList.at(parent.row()).uuid;
            for (int i=0;i<pointList.count();i++) {
                if (parUUID==pointList.at(i).uuid) { pntInd = i; break; }
            }
        }//parent.isValid
        else pntInd = pointList.count();

        for (int i=0;i<tmpPL.count(); i++) {
            beginInsertRows(QModelIndex(), pntInd, pntInd);
            pointList.insert(pntInd,tmpPL.at(i));
            endInsertRows();
            pntInd+=1;
        }
    }//else moveMode
    emit dataChanged(index(0,0,QModelIndex()),index(pointList.count(),columnCount(QModelIndex())));
    return true;
}
void QSGDefaultRenderer::buildLists(QSGNode *node)
{
    if (node->isSubtreeBlocked())
        return;

    if (node->type() == QSGNode::GeometryNodeType) {
        QSGGeometryNode *geomNode = static_cast<QSGGeometryNode *>(node);
        qreal opacity = geomNode->inheritedOpacity();
        QSGMaterial *m = geomNode->activeMaterial();

#ifdef FORCE_NO_REORDER
        if (true) {
#else
        if ((m->flags() & QSGMaterial::Blending) || opacity < 1) {
#endif
            geomNode->setRenderOrder(m_currentRenderOrder - 1);
            m_transparentNodes.add(geomNode);
        } else {
            geomNode->setRenderOrder(m_currentRenderOrder);
            m_opaqueNodes.add(geomNode);
            m_currentRenderOrder += 2;
        }
    }

    if (!node->firstChild())
        return;

#ifdef FORCE_NO_REORDER
    static bool reorder = false;
#else
    static bool reorder = !qApp->arguments().contains(QLatin1String("--no-reorder"));
#endif

    if (reorder && node->firstChild() != node->lastChild() && (node->flags() & QSGNode::ChildrenDoNotOverlap)) {
        QVarLengthArray<int, 16> beginIndices;
        QVarLengthArray<int, 16> endIndices;
        int baseCount = m_transparentNodes.size();
        int count = 0;
        for (QSGNode *c = node->firstChild(); c; c = c->nextSibling()) {
            beginIndices.append(m_transparentNodes.size());
            buildLists(c);
            endIndices.append(m_transparentNodes.size());
            ++count;
        }

        int childNodeCount = m_transparentNodes.size() - baseCount;
        if (childNodeCount) {
            m_tempNodes.reset();
            m_tempNodes.reserve(childNodeCount);
            while (childNodeCount) {
                for (int i = 0; i < count; ++i) {
                    if (beginIndices[i] != endIndices[i])
                        m_heap.insert(IndexGeometryNodePair(i, m_transparentNodes.at(beginIndices[i]++)));
                }
                while (!m_heap.isEmpty()) {
                    IndexGeometryNodePair pair = m_heap.pop();
                    m_tempNodes.add(pair.second);
                    --childNodeCount;
                    int i = pair.first;
                    if (beginIndices[i] != endIndices[i] && !nodeLessThan(m_transparentNodes.at(beginIndices[i]), pair.second))
                        m_heap.insert(IndexGeometryNodePair(i, m_transparentNodes.at(beginIndices[i]++)));
                }
            }
            Q_ASSERT(m_tempNodes.size() == m_transparentNodes.size() - baseCount);

            qMemCopy(&m_transparentNodes.at(baseCount), &m_tempNodes.at(0), m_tempNodes.size() * sizeof(QSGGeometryNode *));
        }
    } else {
        for (QSGNode *c = node->firstChild(); c; c = c->nextSibling())
            buildLists(c);
    }
}

void QSGDefaultRenderer::renderNodes(const QDataBuffer<QSGGeometryNode *> &list)
{
    const float scale = 1.0f / m_currentRenderOrder;
    int count = list.size();
    int currentRenderOrder = 0x80000000;
    m_current_projection_matrix.setColumn(2, scale * projectionMatrix().column(2));

    //int clipChangeCount = 0;
    //int programChangeCount = 0;
    //int materialChangeCount = 0;

    for (int i = 0; i < count; ++i) {
        QSGGeometryNode *geomNode = list.at(i);

        QSGMaterialShader::RenderState::DirtyStates updates;

#if defined (QML_RUNTIME_TESTING)
        static bool dumpTree = qApp->arguments().contains(QLatin1String("--dump-tree"));
        if (dumpTree)
            qDebug() << geomNode;
#endif

        bool changeMatrix = m_currentMatrix != geomNode->matrix();

        if (changeMatrix) {
            m_currentMatrix = geomNode->matrix();
            if (m_currentMatrix)
                m_current_model_view_matrix = *m_currentMatrix;
            else
                m_current_model_view_matrix.setToIdentity();
            updates |= QSGMaterialShader::RenderState::DirtyMatrix;
        }

        bool changeOpacity = m_current_opacity != geomNode->inheritedOpacity();
        if (changeOpacity) {
            updates |= QSGMaterialShader::RenderState::DirtyOpacity;
            m_current_opacity = geomNode->inheritedOpacity();
        }

        Q_ASSERT(geomNode->activeMaterial());

        QSGMaterial *material = geomNode->activeMaterial();
        QSGMaterialShader *program = m_context->prepareMaterial(material);
        Q_ASSERT(program->program()->isLinked());

        bool changeClip = geomNode->clipList() != m_currentClip;
        QSGRenderer::ClipType clipType = QSGRenderer::NoClip;
        if (changeClip) {
            clipType = updateStencilClip(geomNode->clipList());
            m_currentClip = geomNode->clipList();
#ifdef FORCE_NO_REORDER
            glDepthMask(false);
#else
            glDepthMask((material->flags() & QSGMaterial::Blending) == 0 && m_current_opacity == 1);
#endif
            //++clipChangeCount;
        }

        bool changeProgram = (changeClip && clipType == QSGRenderer::StencilClip) || m_currentProgram != program;
        if (changeProgram) {
            if (m_currentProgram)
                m_currentProgram->deactivate();
            m_currentProgram = program;
            m_currentProgram->activate();
            //++programChangeCount;
            updates |= (QSGMaterialShader::RenderState::DirtyMatrix | QSGMaterialShader::RenderState::DirtyOpacity);

#ifdef RENDERER_DEBUG
            materialChanges++;
#endif
        }

        bool changeRenderOrder = currentRenderOrder != geomNode->renderOrder();
        if (changeRenderOrder) {
            currentRenderOrder = geomNode->renderOrder();
            m_current_projection_matrix.setColumn(3, projectionMatrix().column(3)
                                                  + currentRenderOrder
                                                  * m_current_projection_matrix.column(2));
            updates |= QSGMaterialShader::RenderState::DirtyMatrix;
        }

        if (changeProgram || m_currentMaterial != material) {
            program->updateState(state(updates), material, changeProgram ? 0 : m_currentMaterial);
            m_currentMaterial = material;
            //++materialChangeCount;
        }

        //glDepthRange((geomNode->renderOrder() + 0.1) * scale, (geomNode->renderOrder() + 0.9) * scale);

        const QSGGeometry *g = geomNode->geometry();
        bindGeometry(program, g);
        draw(geomNode);

#ifdef RENDERER_DEBUG
        geometryNodesDrawn++;
#endif
    }
    //qDebug("Clip: %i, shader program: %i, material: %i times changed while drawing %s items",
    //    clipChangeCount, programChangeCount, materialChangeCount,
    //    &list == &m_transparentNodes ? "transparent" : "opaque");
}

QT_END_NAMESPACE
Esempio n. 17
0
QwtPolygonFData::QwtPolygonFData(const QPolygonF &polygon):
#else
QwtPolygonFData::QwtPolygonFData(const QwtArray<QwtDoublePoint> &polygon):
#endif
    d_data(polygon)
{
}

//! Assignment 
QwtPolygonFData& QwtPolygonFData::operator=(
    const QwtPolygonFData &data)
{
    if (this != &data)
    {
        d_data = data.d_data;
    }
    return *this;
}

//! \return Size of the data set 
size_t QwtPolygonFData::size() const 
{ 
    return d_data.size(); 
}

/*!
  Return the x value of data point i

  \param i Index
  \return x X value of data point i
*/
double QwtPolygonFData::x(size_t i) const 
{ 
    return d_data[int(i)].x(); 
}

/*!
  Return the y value of data point i

  \param i Index
  \return y Y value of data point i
*/
double QwtPolygonFData::y(size_t i) const 
{ 
    return d_data[int(i)].y(); 
}

#if QT_VERSION >= 0x040000
const QPolygonF &QwtPolygonFData::data() const
#else
const QwtArray<QwtDoublePoint> &QwtPolygonFData::data() const
#endif
{
    return d_data;
}

/*!
  \return Pointer to a copy (virtual copy constructor)
*/
QwtData *QwtPolygonFData::copy() const 
{ 
    return new QwtPolygonFData(d_data); 
}

/*!
  Constructor

  \param x Array of x values
  \param y Array of y values
  
  \sa QwtPlotCurve::setData
*/
QwtArrayData::QwtArrayData(
        const QwtArray<double> &x, const QwtArray<double> &y): 
    d_x(x), 
    d_y(y)
{
}

/*!
  Constructor
  
  \param x Array of x values
  \param y Array of y values
  \param size Size of the x and y arrays
  \sa QwtPlotCurve::setData
*/
QwtArrayData::QwtArrayData(const double *x, const double *y, size_t size)
{
#if QT_VERSION >= 0x040000
    d_x.resize(size);
    qMemCopy(d_x.data(), x, size * sizeof(double));

    d_y.resize(size);
    qMemCopy(d_y.data(), y, size * sizeof(double));
#else
    d_x.detach();
    d_x.duplicate(x, size);

    d_y.detach();
    d_y.duplicate(y, size);
#endif
}
Esempio n. 18
0
void QPF::addGlyphs(QFontEngine *fe, const QList<CharacterRange> &ranges)
{
    const quint16 glyphCount = fe->glyphCount();

    QByteArray gmap;
    gmap.resize(glyphCount * sizeof(quint32));
    gmap.fill(char(0xff));
    //qDebug() << "glyphCount" << glyphCount;

    QByteArray glyphs;
    if (options & RenderGlyphs) {
        // this is only a rough estimation
        glyphs.reserve(glyphCount 
                * (sizeof(QFontEngineQPF::Glyph) 
                    + qRound(fe->maxCharWidth() * (fe->ascent() + fe->descent()).toReal())));

        QGlyphLayout layout[10];

        foreach (CharacterRange range, ranges) {
            if (debugVerbosity > 2)
                qDebug() << "rendering range from" << range.start << "to" << range.end;
            for (uint uc = range.start; uc < range.end; ++uc) {
                QChar ch(uc);
                int nglyphs = 10;
                if (!fe->stringToCMap(&ch, 1, &layout[0], &nglyphs, /*flags*/ 0))
                    continue;

                if (nglyphs != 1)
                    continue;

                const quint32 glyphIndex = layout[0].glyph;

                if (!glyphIndex)
                    continue;

                Q_ASSERT(glyphIndex < glyphCount);

                QImage img = fe->alphaMapForGlyph(glyphIndex).convertToFormat(QImage::Format_Indexed8);
                glyph_metrics_t metrics = fe->boundingBox(glyphIndex);

                const quint32 oldSize = glyphs.size();
                glyphs.resize(glyphs.size() + sizeof(QFontEngineQPF::Glyph) + img.numBytes());
                uchar *data = reinterpret_cast<uchar *>(glyphs.data() + oldSize);

                uchar *gmapPtr = reinterpret_cast<uchar *>(gmap.data() + glyphIndex * sizeof(quint32));
                qToBigEndian(oldSize, gmapPtr);

                QFontEngineQPF::Glyph *glyph = reinterpret_cast<QFontEngineQPF::Glyph *>(data);
                glyph->width = img.width();
                glyph->height = img.height();
                glyph->bytesPerLine = img.bytesPerLine();
                glyph->x = qRound(metrics.x);
                glyph->y = qRound(metrics.y);
                glyph->advance = qRound(metrics.xoff);
                data += sizeof(QFontEngineQPF::Glyph);

                if (debugVerbosity && uc >= 'A' && uc <= 'z' || debugVerbosity > 1) {
                    qDebug() << "adding glyph with index" << glyphIndex << " uc =" << char(uc) << ":\n"
                        << "    glyph->x =" << glyph->x << "rounded from" << metrics.x << "\n"
                        << "    glyph->y =" << glyph->y << "rounded from" << metrics.y << "\n"
                        << "    width =" << glyph->width << "height =" << glyph->height
                        << "    advance =" << glyph->advance << "rounded from" << metrics.xoff
                        ;
                }

                qMemCopy(data, img.bits(), img.numBytes());
            }
        }
    }
Esempio n. 19
0
void tst_QVolatileImage::bitmap()
{
#ifdef Q_OS_SYMBIAN
    CFbsBitmap *bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(100, 50), EColor64K) == KErrNone);
    QVolatileImage bmpimg(bmp);
    CFbsBitmap *dupbmp = static_cast<CFbsBitmap *>(bmpimg.duplicateNativeImage());
    QVERIFY(dupbmp);
    QVERIFY(dupbmp != bmp);
    QCOMPARE(dupbmp->DataAddress(), bmp->DataAddress());
    delete dupbmp;
    delete bmp;
    bmpimg.beginDataAccess();
    qMemSet(bmpimg.bits(), 0, bmpimg.byteCount());
    qMemSet(bmpimg.bits(), 1, bmpimg.bytesPerLine() * bmpimg.height());
    bmpimg.endDataAccess();

    // Test bgr->rgb conversion in case of EColor16M.
    bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(101, 89), EColor16M) == KErrNone);
    bmp->BeginDataAccess();
    TUint32 *addr = bmp->DataAddress();
    uint rgb = QColor(10, 20, 30).rgb();
    qMemCopy(bmp->DataAddress(), &rgb, 3);
    bmp->EndDataAccess();
    TRgb symrgb;
    bmp->GetPixel(symrgb, TPoint(0, 0));
    QVERIFY(symrgb.Red() == 10 && symrgb.Green() == 20 && symrgb.Blue() == 30);
    bmpimg = QVolatileImage(bmp);
    QVERIFY(bmpimg.toImage().pixel(0, 0) == rgb);
    // check if there really was a conversion
    bmp->BeginDataAccess();
    bmpimg.beginDataAccess();
    qMemCopy(&rgb, bmpimg.constBits(), 3);
    uint rgb2 = rgb;
    qMemCopy(&rgb2, bmp->DataAddress(), 3);
    QVERIFY(rgb != rgb2);
    bmpimg.endDataAccess(true);
    bmp->EndDataAccess(true);
    delete bmp;

    bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(101, 89), EGray2) == KErrNone);
    bmpimg = QVolatileImage(bmp); // inverts pixels, but should do it in place
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    QCOMPARE(bmpimg.format(), QImage::Format_MonoLSB);
    bmpimg.ensureFormat(QImage::Format_ARGB32_Premultiplied);
    QVERIFY(bmpimg.constBits() != (const uchar *) bmp->DataAddress());
    QCOMPARE(bmpimg.format(), QImage::Format_ARGB32_Premultiplied);
    delete bmp;

    // The following two formats must be optimal always.
    bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(101, 89), EColor16MAP) == KErrNone);
    bmpimg = QVolatileImage(bmp);
    QCOMPARE(bmpimg.format(), QImage::Format_ARGB32_Premultiplied);
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    bmpimg.ensureFormat(QImage::Format_ARGB32_Premultiplied);
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    delete bmp;
    bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(101, 89), EColor16MU) == KErrNone);
    bmpimg = QVolatileImage(bmp);
    QCOMPARE(bmpimg.format(), QImage::Format_RGB32);
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    bmpimg.ensureFormat(QImage::Format_RGB32);
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    delete bmp;

#else
    QSKIP("CFbsBitmap is only available on Symbian, skipping bitmap test", SkipSingle);
#endif
}
Esempio n. 20
0
void QCOMM::readtcppendingdatagrams()
{
    QDataStream in(tcpsocket);
    in.setByteOrder(QDataStream::LittleEndian);
    in.setVersion(QDataStream::Qt_4_7);
    unsigned short funcode;
    while(1){
        if(nexttcpblocksize==0){
            if(tcpsocket->bytesAvailable()<2)
                break;
            in>>nexttcpblocksize;
        }
        if(tcpsocket->bytesAvailable()<(nexttcpblocksize-2))
            break;
        int tcpblocksize = nexttcpblocksize;
        nexttcpblocksize = 0;

        in>>funcode;
        Q_ASSERT(sizeof(TCPHEARDER)==4);
        unsigned short  datasize= tcpblocksize-sizeof(TCPHEARDER);
        switch(funcode){
        case TCP_DOWNLOADFILE:{
            unsigned int filelen;
            in>>filelen;
            QByteArray filenameRaw =  tcpsocket->read(datasize-4);
            QString filename(filenameRaw);
            qDebug()<<"be required to receive file \""<<filename<<"\";"<<"filelen:"<<filelen;
            filetrans = QPointer<FileTrans>(new FileTrans(tcpsocket,filename,filelen));
            break;
        }

        case TCP_FILETRANSFER:{
            if(!filetrans.isNull())
                filetrans->receivData(datasize);
            else{
                in.skipRawData(datasize);
                qDebug("windowmanager:invalid file transmition task");
            }
            break;
        }
        case TCP_MACHINEINFO:

            break;
        case TCP_FILELIST:{
            QDir dir("./media");
            QStringList list = dir.entryList(QDir::NoDotAndDotDot|QDir::Files );
            QByteArray filenames = list.join(":").toUtf8();
            unsigned short lenofack = sizeof(TCPHEARDER)+filenames.size();
            FILELISTACK *ack = (FILELISTACK*)malloc(lenofack);
            ack->header.sizeofpack = sizeof(TCPHEARDER)+filenames.size();
            ack->header.funcode = TCP_FILELIST;
            qMemCopy(ack->filenamelist,filenames.data(),filenames.size());
            tcpsocket->write((char*)ack,lenofack);
            free(ack);
            break;
        }
        case TCP_STARTPLAY:{
            QByteArray rawfilename  = tcpsocket->read(datasize);
            QString filename(rawfilename);
            PLAYACK ack;
            ack.header.funcode = TCP_STARTPLAY;
            ack.header.sizeofpack = sizeof(ack);
            screensaver->setPlayFileName(filename);
            if(QWSServer::screenSaverActive())
                QWSServer::screenSaverActivate(FALSE);
            QWSServer::screenSaverActivate(TRUE);
            if(QWSServer::screenSaverActive())
                ack.ack = 0;
            else
                ack.ack = -EFILENOTEXIST
            tcpsocket->write((char*)&ack,sizeof(ack));
        }
        case TCP_STOPPLAY:{
            STOPPLAYACK ack;
            ack.header.funcode = TCP_STOPPLAY;
            ack.header.sizeofpack = sizeof(ack);
            ack.ack = 0;
            tcpsocket->write((char*)&ack,sizeof(ack));
            break;
        }
        default:
            break;
        }
    }
}
Esempio n. 21
0
/*!
    Assigns the \a other byte array matcher to this byte array matcher.
*/
QByteArrayMatcher &QByteArrayMatcher::operator=(const QByteArrayMatcher &other)
{
    q_pattern = other.q_pattern;
    qMemCopy(q_skiptable, other.q_skiptable, sizeof(q_skiptable));
    return *this;
}
Esempio n. 22
0
QwtDoublePointData::QwtDoublePointData(const QPolygonF &data):
#else
QwtDoublePointData::QwtDoublePointData(const QwtArray<QwtDoublePoint> &data):
#endif
    d_data(data)
{
}

//! Assignment 
QwtDoublePointData& QwtDoublePointData::operator=(
    const QwtDoublePointData &data)
{
    if (this != &data)
    {
        d_data = data.d_data;
    }
    return *this;
}

size_t QwtDoublePointData::size() const 
{ 
    return d_data.size(); 
}

double QwtDoublePointData::x(size_t i) const 
{ 
    return d_data[int(i)].x(); 
}

double QwtDoublePointData::y(size_t i) const 
{ 
    return d_data[int(i)].y(); 
}

#if QT_VERSION >= 0x040000
const QPolygonF &QwtDoublePointData::data() const
#else
const QwtArray<QwtDoublePoint> &QwtDoublePointData::data() const
#endif
{
    return d_data;
}

QwtData *QwtDoublePointData::copy() const 
{ 
    return new QwtDoublePointData(d_data); 
}

/*!
  Constructor
  
  \sa QwtCurve::setData and QwtPlot::setCurveData.
*/
QwtArrayData::QwtArrayData(
        const QwtArray<double> &x, const QwtArray<double> &y): 
    d_x(x), 
    d_y(y)
{
}

/*!
  Constructor
  
  \sa QwtCurve::setData and QwtPlot::setCurveData.
*/
QwtArrayData::QwtArrayData(const double *x, const double *y, size_t size)
{
#if QT_VERSION >= 0x040000
    d_x.resize(size);
    qMemCopy(d_x.data(), x, size * sizeof(double));

    d_y.resize(size);
    qMemCopy(d_y.data(), y, size * sizeof(double));
#else
    d_x.detach();
    d_x.duplicate(x, size);

    d_y.detach();
    d_y.duplicate(y, size);
#endif
}
Esempio n. 23
0
/*!
  Draw a tube

  Builds 2 curves from the upper and lower limits of the intervals
  and draws them with the pen(). The area between the curves is
  filled with the brush().

  \param painter Painter
  \param xMap Maps x-values into pixel coordinates.
  \param yMap Maps y-values into pixel coordinates.
  \param canvasRect Contents rect of the canvas
  \param from Index of the first sample to be painted
  \param to Index of the last sample to be painted. If to < 0 the
         series will be painted to its last sample.

  \sa drawSeries(), drawSymbols()
*/
void QwtPlotIntervalCurve::drawTube( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect, int from, int to ) const
{
    const bool doAlign = QwtPainter::roundingAlignment( painter );

    painter->save();

    const size_t size = to - from + 1;
    QPolygonF polygon( 2 * size );
    QPointF *points = polygon.data();

    for ( uint i = 0; i < size; i++ )
    {
        QPointF &minValue = points[i];
        QPointF &maxValue = points[2 * size - 1 - i];

        const QwtIntervalSample intervalSample = sample( from + i );
        if ( orientation() == Qt::Vertical )
        {
            double x = xMap.transform( intervalSample.value );
            double y1 = yMap.transform( intervalSample.interval.minValue() );
            double y2 = yMap.transform( intervalSample.interval.maxValue() );
            if ( doAlign )
            {
                x = qRound( x );
                y1 = qRound( y1 );
                y2 = qRound( y2 );
            }

            minValue.rx() = x;
            minValue.ry() = y1;
            maxValue.rx() = x;
            maxValue.ry() = y2;
        }
        else
        {
            double y = yMap.transform( intervalSample.value );
            double x1 = xMap.transform( intervalSample.interval.minValue() );
            double x2 = xMap.transform( intervalSample.interval.maxValue() );
            if ( doAlign )
            {
                y = qRound( y );
                x1 = qRound( x1 );
                x2 = qRound( x2 );
            }

            minValue.rx() = x1;
            minValue.ry() = y;
            maxValue.rx() = x2;
            maxValue.ry() = y;
        }
    }

    if ( d_data->brush.style() != Qt::NoBrush )
    {
        painter->setPen( QPen( Qt::NoPen ) );
        painter->setBrush( d_data->brush );

        if ( d_data->paintAttributes & ClipPolygons )
        {
            const qreal m = 1.0;
            const QPolygonF p = QwtClipper::clipPolygonF( 
                canvasRect.adjusted(-m, -m, m, m), polygon, true );

            QwtPainter::drawPolygon( painter, p );
        }
        else
        {
            QwtPainter::drawPolygon( painter, polygon );
        }
    }

    if ( d_data->pen.style() != Qt::NoPen )
    {
        painter->setPen( d_data->pen );
        painter->setBrush( Qt::NoBrush );

        if ( d_data->paintAttributes & ClipPolygons )
        {
            QPolygonF p;

            p.resize( size );
            qMemCopy( p.data(), points, size * sizeof( QPointF ) );
            p = QwtClipper::clipPolygonF( canvasRect, p );
            QwtPainter::drawPolyline( painter, p );

            p.resize( size );
            qMemCopy( p.data(), points + size, size * sizeof( QPointF ) );
            p = QwtClipper::clipPolygonF( canvasRect, p );
            QwtPainter::drawPolyline( painter, p );
        }
        else
        {
            QwtPainter::drawPolyline( painter, points, size );
            QwtPainter::drawPolyline( painter, points + size, size );
        }
    }

    painter->restore();
}
Esempio n. 24
0
        IMediaSample *QMemInputPin::duplicateSampleForOutput(IMediaSample *sample, IMemAllocator *alloc)
        {
            LONG length = sample->GetActualDataLength();

            HRESULT hr = alloc->Commit();
            if (hr == HRESULT(VFW_E_SIZENOTSET)) {
                ALLOCATOR_PROPERTIES prop = getDefaultAllocatorProperties();
                prop.cbBuffer = qMax(prop.cbBuffer, length);
                ALLOCATOR_PROPERTIES actual;
                //we just try to set the properties...
                alloc->SetProperties(&prop, &actual);
                hr = alloc->Commit();
            }

            Q_ASSERT(SUCCEEDED(hr));

            IMediaSample *out;
            hr = alloc->GetBuffer(&out, 0, 0, AM_GBF_NOTASYNCPOINT);
            Q_ASSERT(SUCCEEDED(hr));

            //let's copy the sample
            {
                REFERENCE_TIME start, end;
                sample->GetTime(&start, &end);
                out->SetTime(&start, &end);
            }

            hr = out->SetActualDataLength(length);
            Q_ASSERT(SUCCEEDED(hr));
            hr = out->SetDiscontinuity(sample->IsDiscontinuity());
            Q_ASSERT(SUCCEEDED(hr));

            {
                LONGLONG start, end;
                hr = sample->GetMediaTime(&start, &end);
                if (hr != HRESULT(VFW_E_MEDIA_TIME_NOT_SET)) {
                    hr = out->SetMediaTime(&start, &end);
                    Q_ASSERT(SUCCEEDED(hr));
                }
            }

            AM_MEDIA_TYPE *type = 0;
            hr = sample->GetMediaType(&type);
            Q_ASSERT(SUCCEEDED(hr));
            hr = out->SetMediaType(type);
            Q_ASSERT(SUCCEEDED(hr));

            hr = out->SetPreroll(sample->IsPreroll());
            Q_ASSERT(SUCCEEDED(hr));
            hr = out->SetSyncPoint(sample->IsSyncPoint());
            Q_ASSERT(SUCCEEDED(hr));

            BYTE *dest = 0, *src = 0;
            hr = out->GetPointer(&dest);
            Q_ASSERT(SUCCEEDED(hr));
            hr = sample->GetPointer(&src);
            Q_ASSERT(SUCCEEDED(hr));

            qMemCopy(dest, src, sample->GetActualDataLength());

            return out;
        }