Example #1
0
void SnapshotAnimated::processFrames() {
    uint32_t width = SnapshotAnimated::snapshotAnimatedFrameVector[0].width();
    uint32_t height = SnapshotAnimated::snapshotAnimatedFrameVector[0].height();

    // Create the GIF from the temporary files
    // Write out the header and beginning of the GIF file
    GifBegin(
        &(SnapshotAnimated::snapshotAnimatedGifWriter),
        qPrintable(SnapshotAnimated::snapshotAnimatedPath),
        width,
        height,
        1); // "1" means "yes there is a delay" with this GifCreator library.
    for (int itr = 0; itr < SnapshotAnimated::snapshotAnimatedFrameVector.size(); itr++) {
        // Write each frame to the GIF
        GifWriteFrame(&(SnapshotAnimated::snapshotAnimatedGifWriter),
            (uint8_t*)SnapshotAnimated::snapshotAnimatedFrameVector[itr].convertToFormat(QImage::Format_RGBA8888).bits(),
            width,
            height,
            SnapshotAnimated::snapshotAnimatedFrameDelayVector[itr]);
    }
    // Write out the end of the GIF
    GifEnd(&(SnapshotAnimated::snapshotAnimatedGifWriter));

    // Clear out the frame and frame delay vectors.
    // Also release the memory not required to store the items.
    SnapshotAnimated::snapshotAnimatedFrameVector.clear();
    SnapshotAnimated::snapshotAnimatedFrameVector.squeeze();
    SnapshotAnimated::snapshotAnimatedFrameDelayVector.clear();
    SnapshotAnimated::snapshotAnimatedFrameDelayVector.squeeze();

    // Let the dependency manager know that the snapshots have been taken.
    emit SnapshotAnimated::snapshotAnimatedDM->snapshotTaken(SnapshotAnimated::snapshotStillPath, SnapshotAnimated::snapshotAnimatedPath, false);
}
Example #2
0
bool gif_stop_recording(void) {
    std::lock_guard<std::mutex> lock(gif_mutex);

    bool wasRecording = recording;
    recording = false;
    return wasRecording && GifEnd(&writer);
}
Example #3
0
bool
GIFOutput::close()
{
    if (m_pending_write) {
        finish_subimage();
        GifEnd(&m_gifwriter);
    }
    init();
    return true;
}
Example #4
0
void gif_new_frame() {
    std::lock_guard<std::mutex> lock(gif_mutex);

    if (!recording || (++frame % (frameskip + 1))) {
        return;
    }

    int lastGifTime = gifTime;
    gifTime = (frame * 100 + 32) / 64;

    if (!gif_write_frame(&writer, gifTime - lastGifTime)) {
        recording = false;
        GifEnd(&writer);
    }
}
Example #5
0
void GifSaver::save()
{
    std::vector< uint8_t* > bufferVector;
    GifWriter gifWriter;
    GifBegin( &gifWriter, _outputFilePath.toStdString().c_str(),
              _inputAnimatedGif[ 0 ]->getWidth() * _scaleFactor,
              _inputAnimatedGif[ 0 ]->getHeight() * _scaleFactor,
              10 );

    int i = 0;
    for( const auto& frame : _inputAnimatedGif )
    {
        _filter->setNewInputImage( frame );
        _filter->apply();

        Image* outputFrame = new Image( new QImage( *( _filter->getOutputImage()->getQImage() ) ) );

        const int rgbaSize = 4;
        uint8_t* outputFrameBuffer = new uint8_t[ outputFrame->getWidth() * outputFrame->getHeight() * rgbaSize ];

        outputFrame->getBufferRGBA8( outputFrameBuffer );

        bufferVector.push_back( outputFrameBuffer );

        GifWriteFrame( &gifWriter,
                       outputFrameBuffer,
                       outputFrame->getWidth(),
                       outputFrame->getHeight(), 10 );

        delete outputFrame;
        delete[] outputFrameBuffer;

        emit setProgress( ( float ) i++ * 100 / _inputAnimatedGif.size() );
    }

    GifEnd( &gifWriter );
}
Example #6
0
bool gif_single_frame(const char *filename) {
    GifWriter frameWriter;

    return GifBegin(&frameWriter, filename, 320, 240, 0) && gif_write_frame(&frameWriter, 0) && GifEnd(&frameWriter);
}