Changeset 3478 for libcaca/trunk


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

Import/export dirty rectangles

Location:
libcaca/trunk/caca/codec
Files:
2 edited

Legend:

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

    r3451 r3478  
    163163{
    164164    char *data, *cur;
    165     int f, n;
    166 
    167     /* 52 bytes for the header:
     165    int f, i, n;
     166
     167    /* at least 72 bytes for the header:
    168168     *  - 4 bytes for "\xCA\xCA" + "CV"
    169      *  - 16 bytes for the canvas header
    170      *  - 32 bytes for the frame info
     169     *  - 20 bytes for the canvas header
     170     *  - 16 bytes for each dirty rectangle info
     171     *  - 32 bytes for each frame info
    171172     * 8 bytes for each character cell */
    172     *bytes = 20 + (32 + 8 * cv->width * cv->height) * cv->framecount;
     173    *bytes = 24 + 16 * cv->ndirty + (32 + 8 * cv->width * cv->height) * cv->framecount;
    173174    cur = data = malloc(*bytes);
    174175
     
    177178
    178179    /* canvas_header */
    179     cur += sprintu32(cur, 16 + 32 * cv->framecount);
     180    cur += sprintu32(cur, 20 + 16 * cv->ndirty + 32 * cv->framecount);
    180181    cur += sprintu32(cur, cv->width * cv->height * 8 * cv->framecount);
    181     cur += sprintu16(cur, 0x0001);
     182    cur += sprintu16(cur, 0x0002);
     183    cur += sprintu32(cur, cv->ndirty);
    182184    cur += sprintu32(cur, cv->framecount);
    183185    cur += sprintu16(cur, 0x0000);
     186
     187    /* dirty rectangles info */
     188    for(i = 0; i < cv->ndirty; i++)
     189    {
     190        cur += sprintu32(cur, cv->dirty_xmin);
     191        cur += sprintu32(cur, cv->dirty_ymin);
     192        cur += sprintu32(cur, cv->dirty_xmax);
     193        cur += sprintu32(cur, cv->dirty_ymax);
     194    }
    184195
    185196    /* frame_info */
  • 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.