Example #1
0
    static AnimationFrames *LoadAnimatedImage(MythPainter *painter,
                                               // Must be a copy for thread safety
                                              ImageProperties imProps,
                                              ImageCacheMode cacheMode,
                                               // Included only to check address, could be
                                               // replaced by generating a unique value for
                                               // each MythUIImage object?
                                              const MythUIImage *parent,
                                              bool &aborted)
    {
        QString filename = QString("frame-%1-") + imProps.filename;
        QString frameFilename;
        int imageCount = 1;

        MythImageReader *imageReader = new MythImageReader(imProps.filename);

        AnimationFrames *images = new AnimationFrames();

        while (imageReader->canRead() && !aborted)
        {
            frameFilename = filename.arg(imageCount);

            ImageProperties frameProps = imProps;
            frameProps.filename = frameFilename;

            MythImage *im = LoadImage(painter, frameProps, cacheMode, parent,
                                      aborted, imageReader);

            if (!im)
                aborted = true;

            images->append(AnimationFrame(im, imageReader->nextImageDelay()));
            imageCount++;
        }

        delete imageReader;

        return images;
    }
Example #2
0
/**
*  \brief Load an animated image
*/
bool MythUIImage::LoadAnimatedImage(
    MythImageReader &imageReader, const QString &imFile,
    QSize bForceSize, int cacheMode)
{
    bool result = false;
    m_loadingImagesLock.lock();

    // Check to see if the image is being loaded by us in another thread
    if ((m_loadingImages.contains(imFile)) &&
        (m_loadingImages[imFile] == this))
    {
        VERBOSE(VB_GUI|VB_FILE|VB_EXTRA, LOC + QString(
                    "MythUIImage::LoadAnimatedImage(%1), this "
                    "file is already being loaded by this same MythUIImage in "
                    "another thread.").arg(imFile));
        m_loadingImagesLock.unlock();
        return result;
    }

    // Check to see if the exact same image is being loaded anywhere else
    while (m_loadingImages.contains(imFile))
        m_loadingImagesCond.wait(&m_loadingImagesLock);

    m_loadingImages[imFile] = this;
    m_loadingImagesLock.unlock();

    QString filename = QString("frame-%1-") + imFile;
    QString frameFilename;
    QVector<MythImage *> images;
    QVector<int> delays;
    int imageCount = 1;
    QString imageLabel;

    int w = -1;
    int h = -1;

    if (!bForceSize.isNull())
    {
        if (bForceSize.width() != -1)
            w = bForceSize.width();

        if (bForceSize.height() != -1)
            h = bForceSize.height();
    }

    while (imageReader.canRead())
    {
        frameFilename = filename.arg(imageCount);
        imageLabel = GenImageLabel(frameFilename, w, h);
        MythImage *im = LoadImage(
            imageReader, frameFilename,
            bForceSize, (ImageCacheMode) cacheMode);

        if (!im)
            break;

        images.append(im);
        delays.append(imageReader.nextImageDelay());
        imageCount++;
    }

    if (images.size())
    {
        m_animatedImage = true;
        SetImages(images);
        if ((m_Delay == -1) &&
            (imageReader.supportsAnimation()) &&
            (delays.size()))
        {
            SetDelays(delays);
        }
        result = true;
    }

    m_loadingImagesLock.lock();
    m_loadingImages.remove(imFile);
    m_loadingImagesCond.wakeAll();
    m_loadingImagesLock.unlock();

    return result;
}