Ignore:
Timestamp:
May 19, 2009, 2:46:34 PM (14 years ago)
Author:
Pascal Terjan
Message:

Import/export dirty rectangles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/codec/import.c

    r3451 r3478  
    224224    uint8_t const *buf = (uint8_t const *)data;
    225225    size_t control_size, data_size, expected_size;
    226     unsigned int frames, f, n, offset;
     226    unsigned int frames, f, i, n, offset, ndirty;
    227227    uint16_t version, flags;
    228228    int32_t xmin = 0, ymin = 0, xmax = 0, ymax = 0;
    229 
    230     if(size < 20)
     229    int dirty_xmin, dirty_ymin, dirty_xmax, dirty_ymax;
     230
     231    if(size < 36)
    231232        return 0;
    232233
     
    240241    data_size = sscanu32(buf + 8);
    241242    version = sscanu16(buf + 12);
    242     frames = sscanu32(buf + 14);
    243     flags = sscanu16(buf + 18);
     243    ndirty = sscanu32(buf + 14);
     244    frames = sscanu32(buf + 18);
     245    flags = sscanu16(buf + 22);
     246
     247    if(version != 2)
     248    {
     249        debug("caca import error: only version 2 import is supported");
     250        goto invalid_caca;
     251    }
    244252
    245253    if(size < 4 + control_size + data_size)
    246254        return 0;
    247255
    248     if(control_size < 16 + frames * 32)
     256    if(control_size < 20 + ndirty * 16 + frames * 32)
    249257    {
    250258        debug("caca import error: control size %u < expected %u",
    251               (unsigned int)control_size, 16 + frames * 32);
     259              (unsigned int)control_size, 32 + frames * 32);
    252260        goto invalid_caca;
     261    }
     262
     263    /* dirty rectangles info */
     264    cv->ndirty = ndirty;
     265    for(i = 0; i < ndirty; i++)
     266    {
     267        dirty_xmin = sscanu32(buf + 4 + 20 + 16 * i);
     268        dirty_ymin = sscanu32(buf + 4 + 20 + 16 * i + 4);
     269        dirty_xmax = sscanu32(buf + 4 + 20 + 16 * i + 8);
     270        dirty_ymax = sscanu32(buf + 4 + 20 + 16 * i + 12);
    253271    }
    254272
     
    259277        int x, y, handlex, handley;
    260278
    261         width = sscanu32(buf + 4 + 16 + f * 32);
    262         height = sscanu32(buf + 4 + 16 + f * 32 + 4);
    263         duration = sscanu32(buf + 4 + 16 + f * 32 + 8);
    264         attr = sscanu32(buf + 4 + 16 + f * 32 + 12);
    265         x = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 16);
    266         y = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 20);
    267         handlex = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 24);
    268         handley = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 28);
     279        width = sscanu32(buf + 4 + 20 + 16 * ndirty + f * 32);
     280        height = sscanu32(buf + 4 + 20 + 16 * ndirty + f * 32 + 4);
     281        duration = sscanu32(buf + 4 + + f * 32 + 8);
     282        attr = sscanu32(buf + 4 + 20 + 16 * ndirty + f * 32 + 12);
     283        x = (int32_t)sscanu32(buf + 4 + 20 + 16 * ndirty + f * 32 + 16);
     284        y = (int32_t)sscanu32(buf + 4 + 20 + 16 * ndirty + f * 32 + 20);
     285        handlex = (int32_t)sscanu32(buf + 4 + 20 + 16 * ndirty + f * 32 + 24);
     286        handley = (int32_t)sscanu32(buf + 4 + 20 + 16 * ndirty + f * 32 + 28);
    269287        expected_size += width * height * 8;
    270288        if(-handlex < xmin)
     
    297315        unsigned int width, height;
    298316
    299         width = sscanu32(buf + 4 + 16 + f * 32);
    300         height = sscanu32(buf + 4 + 16 + f * 32 + 4);
     317        width = sscanu32(buf + 4 + 20 + ndirty * 16 + f * 32);
     318        height = sscanu32(buf + 4 + 20 + ndirty * 16 + f * 32 + 4);
    301319        caca_create_frame(cv, f);
    302320        caca_set_frame(cv, f);
    303321
    304         cv->curattr = sscanu32(buf + 4 + 16 + f * 32 + 12);
    305         cv->frames[f].x = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 16);
    306         cv->frames[f].y = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 20);
    307         cv->frames[f].handlex = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 24);
    308         cv->frames[f].handley = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 28);
     322        cv->curattr = sscanu32(buf + 4 + 20 + ndirty * 16 + f * 32 + 12);
     323        cv->frames[f].x = (int32_t)sscanu32(buf + 4 + 20 + ndirty * 16 + f * 32 + 16);
     324        cv->frames[f].y = (int32_t)sscanu32(buf + 4 + 20 + ndirty * 16 + f * 32 + 20);
     325        cv->frames[f].handlex = (int32_t)sscanu32(buf + 4 + 20 + ndirty * 16 + f * 32 + 24);
     326        cv->frames[f].handley = (int32_t)sscanu32(buf + 4 + 20 + ndirty * 16 + f * 32 + 28);
    309327
    310328        /* FIXME: check for return value */
Note: See TracChangeset for help on using the changeset viewer.