On this page

capri.h

capri is the Lottie player. It parses a Lottie JSON once and records each frame into an elba scene.

#include "capri/capri.h". The guide starts at Lottie.

Model and stats

Explained in Lottie.

capri::infocapri::statscapri::anim

Loading

Explained in Lottie.

capri::loadcapri::releasecapri::info_ofcapri::stats_of

Playing

Explained in Lottie.

capri::seekcapri::drawcapri::dirty

Lent font

Explained in Lottie.

capri::atlas_glyphcapri::atlas_fontcapri::wants_fontcapri::lend_font

Example

offline.cpp
#include "capri/capri.h"
#include "elba/elba.h"

#include <math.h>
#include <stdint.h>
#include <string.h>

// capri with no device, each frame lands in an rgba buffer and only the
// box that changed is rasterised again
struct offline_render {
    capri::anim* a;
    elba_context* ctx;
    elba_scene* scene;
    uint8_t* rgba;
    uint32_t w;
    uint32_t h;
};

static bool offline_frame(offline_render* o, float frame, bool first)
{
    if (!capri::seek(o->a, frame) && !first) {
        return false;
    }
    const capri::info* in = capri::info_of(o->a);
    const elba_affine view = elba_scale(float(o->w) / in->width, float(o->h) / in->height);
    elba_scene_reset(o->scene);
    capri::draw(o->a, o->scene, &view);

    elba_render r = elba_render_default();
    r.flags |= elba_render_clear;
    float box[4];
    if (!first && capri::dirty(o->a, box)) {
        // a pixel of margin for antialiasing, kept inside the target
        const int32_t x0 = int32_t(floorf(box[0])) - 1;
        const int32_t y0 = int32_t(floorf(box[1])) - 1;
        const int32_t x1 = int32_t(ceilf(box[0] + box[2])) + 1;
        const int32_t y1 = int32_t(ceilf(box[1] + box[3])) + 1;
        r.area[0] = x0 > 0 ? x0 : 0;
        r.area[1] = y0 > 0 ? y0 : 0;
        r.area[2] = (x1 < int32_t(o->w) ? x1 : int32_t(o->w)) - r.area[0];
        r.area[3] = (y1 < int32_t(o->h) ? y1 : int32_t(o->h)) - r.area[1];
    }
    const elba_target t = { o->rgba, o->w, o->h, o->w * 4u, elba_format_rgba8 };
    return elba_render_cpu(o->ctx, o->scene, &t, &r) == elba_ok;
}

static bool offline_open(offline_render* o, const uint8_t* json, size_t n, uint8_t* rgba,
                         uint32_t w, uint32_t h)
{
    memset(o, 0, sizeof(*o));
    o->a = capri::load(json, n, nullptr);
    if (!o->a) {
        return false;
    }
    const elba_desc d = elba_desc_default();
    o->ctx = elba_context_create(&d);
    o->scene = elba_scene_create();
    o->rgba = rgba;
    o->w = w;
    o->h = h;
    return o->ctx && o->scene && offline_frame(o, capri::info_of(o->a)->in, true);
}

static void offline_close(offline_render* o)
{
    elba_scene_destroy(o->scene);
    elba_context_destroy(o->ctx);
    capri::release(o->a);
}

Last updated 23 October 2026