Changeset 3491


Ignore:
Timestamp:
May 20, 2009, 4:44:47 PM (11 years ago)
Author:
Pascal Terjan
Message:

Revert r3478

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

Legend:

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

    r3478 r3491  
    163163{
    164164    char *data, *cur;
    165     int f, i, n;
    166 
    167     /* at least 72 bytes for the header:
     165    int f, n;
     166
     167    /* 52 bytes for the header:
    168168     *  - 4 bytes for "\xCA\xCA" + "CV"
    169      *  - 20 bytes for the canvas header
    170      *  - 16 bytes for each dirty rectangle info
    171      *  - 32 bytes for each frame info
     169     *  - 16 bytes for the canvas header
     170     *  - 32 bytes for the frame info
    172171     * 8 bytes for each character cell */
    173     *bytes = 24 + 16 * cv->ndirty + (32 + 8 * cv->width * cv->height) * cv->framecount;
     172    *bytes = 20 + (32 + 8 * cv->width * cv->height) * cv->framecount;
    174173    cur = data = malloc(*bytes);
    175174
     
    178177
    179178    /* canvas_header */
    180     cur += sprintu32(cur, 20 + 16 * cv->ndirty + 32 * cv->framecount);
     179    cur += sprintu32(cur, 16 + 32 * cv->framecount);
    181180    cur += sprintu32(cur, cv->width * cv->height * 8 * cv->framecount);
    182     cur += sprintu16(cur, 0x0002);
    183     cur += sprintu32(cur, cv->ndirty);
     181    cur += sprintu16(cur, 0x0001);
    184182    cur += sprintu32(cur, cv->framecount);
    185183    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     }
    195184
    196185    /* frame_info */
  • libcaca/trunk/caca/codec/import.c

    r3478 r3491  
    224224    uint8_t const *buf = (uint8_t const *)data;
    225225    size_t control_size, data_size, expected_size;
    226     unsigned int frames, f, i, n, offset, ndirty;
     226    unsigned int frames, f, n, offset;
    227227    uint16_t version, flags;
    228228    int32_t xmin = 0, ymin = 0, xmax = 0, ymax = 0;
    229     int dirty_xmin, dirty_ymin, dirty_xmax, dirty_ymax;
    230 
    231     if(size < 36)
     229
     230    if(size < 20)
    232231        return 0;
    233232
     
    241240    data_size = sscanu32(buf + 8);
    242241    version = sscanu16(buf + 12);
    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     }
     242    frames = sscanu32(buf + 14);
     243    flags = sscanu16(buf + 18);
    252244
    253245    if(size < 4 + control_size + data_size)
    254246        return 0;
    255247
    256     if(control_size < 20 + ndirty * 16 + frames * 32)
     248    if(control_size < 16 + frames * 32)
    257249    {
    258250        debug("caca import error: control size %u < expected %u",
    259               (unsigned int)control_size, 32 + frames * 32);
     251              (unsigned int)control_size, 16 + frames * 32);
    260252        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);
    271253    }
    272254
     
    277259        int x, y, handlex, handley;
    278260
    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);
     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);
    287269        expected_size += width * height * 8;
    288270        if(-handlex < xmin)
     
    315297        unsigned int width, height;
    316298
    317         width = sscanu32(buf + 4 + 20 + ndirty * 16 + f * 32);
    318         height = sscanu32(buf + 4 + 20 + ndirty * 16 + f * 32 + 4);
     299        width = sscanu32(buf + 4 + 16 + f * 32);
     300        height = sscanu32(buf + 4 + 16 + f * 32 + 4);
    319301        caca_create_frame(cv, f);
    320302        caca_set_frame(cv, f);
    321303
    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);
     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);
    327309
    328310        /* FIXME: check for return value */
Note: See TracChangeset for help on using the changeset viewer.