Browse Source

* Implemented cucul_load() to reload a file that was saved with the

raw driver. I know it is inconsistent to have the loader in libcucul
    and the exporter in libcaca but I'll find a way to harmonise that.
tags/v0.99.beta14
Sam Hocevar sam 19 years ago
parent
commit
41db7b066a
2 changed files with 42 additions and 1 deletions
  1. +41
    -1
      cucul/cucul.c
  2. +1
    -0
      cucul/cucul.h

+ 41
- 1
cucul/cucul.c View File

@@ -77,7 +77,47 @@ cucul_t * cucul_create(unsigned int width, unsigned int height)
return qq;
}

/** \brief Set the canvas size.
cucul_t *cucul_load(void *data, unsigned int size)
{
cucul_t *qq;
uint8_t *buf = (uint8_t *)data;
unsigned int width, height, n;

if(size < 12)
return NULL;

if(buf[0] != 'C' || buf[1] != 'A' || buf[2] != 'C' || buf[3] != 'A')
return NULL;

width = ((uint32_t)buf[4] << 24) | ((uint32_t)buf[5] << 16)
| ((uint32_t)buf[6] << 8) | (uint32_t)buf[7];
height = ((uint32_t)buf[8] << 24) | ((uint32_t)buf[9] << 16)
| ((uint32_t)buf[10] << 8) | (uint32_t)buf[11];

if(!width || !height)
return NULL;

if(size != 12 + width * height * 5 + 4)
return NULL;

qq = cucul_create(width, height);

if(!qq)
return NULL;

for(n = height * width; n--; )
{
qq->chars[n] = ((uint32_t)buf[12 + 5 * n] << 24)
| ((uint32_t)buf[13 + 5 * n] << 16)
| ((uint32_t)buf[14 + 5 * n] << 8)
| (uint32_t)buf[15 + 5 * n];
qq->attr[n] = buf[16 + 5 * n];
}

return qq;
}

/** \brief Resize a canvas.
*
* This function sets the canvas width and height, in character cells.
*


+ 1
- 0
cucul/cucul.h View File

@@ -119,6 +119,7 @@ typedef struct cucul_context cucul_t;
*
* @{ */
cucul_t * cucul_create(unsigned int, unsigned int);
cucul_t * cucul_load(void *, unsigned int);
void cucul_set_size(cucul_t *, unsigned int, unsigned int);
unsigned int cucul_get_width(cucul_t *);
unsigned int cucul_get_height(cucul_t *);


Loading…
Cancel
Save