Esempio n. 1
0
void GfxImageLoaderEngine::runOp(const Op &op)
{
    QImage img;
    bool found = false;
    for(int ii = 0; ii < cache.count(); ++ii) {
        if(cache.at(ii).first == op.filename) {
            QPair<QString, QImage> p = cache.at(ii);
            cache.removeAt(ii);
            cache.append(p);
            img = p.second;
            found = true;
            break;
        }
    }
    if(!found) {
        img = QImage(op.filename);
        int contrib = img.height() * img.bytesPerLine();
        if(contrib <= maxCacheSize) {
            cacheSize += contrib;
            cache.append(qMakePair(op.filename, img));
        } 

        while(cacheSize > maxCacheSize) {
            int c = cache.first().second.bytesPerLine() * cache.first().second.height();
            cacheSize -= c;
            cache.removeFirst();
        }
    }

    QList<QImage> imgs;
    if(img.isNull()) {
        for(int ii = 0; ii < op.sizes.count(); ++ii)
            imgs << img;
    } else {
        for(int ii = 0; ii < op.sizes.count(); ++ii)
            imgs << img.scaled(op.sizes.at(ii), Qt::IgnoreAspectRatio, 
                               Qt::SmoothTransformation);
    }

    lock.lock();
    Ops::Iterator iter = ops.find(op.out);
    bool exists = iter != ops.end() && iter->id == op.id;
    if(exists) {
        op.out->filter(imgs);
        completedops.insert(op.out, op);
        ops.erase(iter);

        GfxImageLoaderEvent *e = new GfxImageLoaderEvent();
        e->out = op.out;
        e->id = op.id;
        e->imgs = imgs;
        QCoreApplication::instance()->postEvent(proxy, e);
    }
    lock.unlock();
}
Esempio n. 2
0
void QDeclarativeTimeLinePrivate::add(QDeclarativeTimeLineObject &g, const Op &o)
{
    if (g._t && g._t != q) {
        qWarning() << "QDeclarativeTimeLine: Cannot modify a QDeclarativeTimeLineValue owned by"
                   << "another timeline.";
        return;
    }
    g._t = q;

    Ops::Iterator iter = ops.find(&g);
    if (iter == ops.end()) {
        iter = ops.insert(&g, TimeLine());
        if (syncPoint > 0)
            q->pause(g, syncPoint);
    }
    if (!iter->ops.isEmpty() &&
       o.type == Op::Pause &&
       iter->ops.last().type == Op::Pause) {
        iter->ops.last().length += o.length;
        iter->length += o.length;
    } else {
        iter->ops.append(o);
        iter->length += o.length;
    }

    if (iter->length > length)
        length = iter->length;

    if (!clockRunning) {
        q->stop();
        prevTime = 0;
        clockRunning = true;

        if (syncMode == QDeclarativeTimeLine::LocalSync)  {
            syncAdj = -1;
        } else {
            syncAdj = 0;
        }
        q->start();
/*        q->tick(0);
        if (syncMode == QDeclarativeTimeLine::LocalSync)  {
            syncAdj = -1;
        } else {
            syncAdj = 0;
        }
        */
    }
}
Esempio n. 3
0
void GfxImageLoaderEngine::load(GfxImageLoader *out, const QString &filename, 
                                const QList<QSize> &sizes)
{
    lock.lock();

    bool wasEmpty = ops.isEmpty();
    Op op;
    op.filename = filename;
    op.sizes = sizes;
    op.id = id++;
    op.out = out;
    ops.insert(out, op);

    if(wasEmpty)
        wait.wakeAll();
    lock.unlock();
}