浏览代码

* Fix canvas export for the caca format. We now export all frames.

* Fix the sprite import/export example.
tags/v0.99.beta14
Sam Hocevar sam 17 年前
父节点
当前提交
b8d3f71ae8
共有 2 个文件被更改,包括 26 次插入19 次删除
  1. +25
    -18
      cucul/export.c
  2. +1
    -1
      examples/spritedit.c

+ 25
- 18
cucul/export.c 查看文件

@@ -162,44 +162,51 @@ char const * const * cucul_get_export_list(void)
/* Generate a native libcaca canvas file. */
static void *export_caca(cucul_canvas_t const *cv, unsigned long int *bytes)
{
uint32_t *attrs = cv->attrs;
uint32_t *chars = cv->chars;
char *data, *cur;
unsigned int n;
unsigned int f, n;

/* 52 bytes for the header:
* - 4 bytes for "\xCA\xCA" + "CV"
* - 16 bytes for the canvas header
* - 32 bytes for the frame info
* 8 bytes for each character cell */
*bytes = 52 + 8 * cv->width * cv->height;
*bytes = 20 + (32 + 8 * cv->width * cv->height) * cv->framecount;
cur = data = malloc(*bytes);

/* magic */
cur += sprintf(cur, "%s", "\xCA\xCA" "CV");

/* canvas_header */
cur += sprintu32(cur, 16 + 32 * 1);
cur += sprintu32(cur, cv->width * cv->height * 8);
cur += sprintu32(cur, 16 + 32 * cv->framecount);
cur += sprintu32(cur, cv->width * cv->height * 8 * cv->framecount);
cur += sprintu16(cur, 0x0001);
cur += sprintu32(cur, 1);
cur += sprintu32(cur, cv->framecount);
cur += sprintu16(cur, 0x0000);

/* frame_info */
cur += sprintu32(cur, cv->width);
cur += sprintu32(cur, cv->height);
cur += sprintu32(cur, 0);
cur += sprintu32(cur, cv->curattr);
cur += sprintu32(cur, cv->frames[0].x);
cur += sprintu32(cur, cv->frames[0].y);
cur += sprintu32(cur, cv->frames[0].handlex);
cur += sprintu32(cur, cv->frames[0].handley);
for(f = 0; f < cv->framecount; f++)
{
cur += sprintu32(cur, cv->width);
cur += sprintu32(cur, cv->height);
cur += sprintu32(cur, 0);
cur += sprintu32(cur, cv->curattr);
cur += sprintu32(cur, cv->frames[f].x);
cur += sprintu32(cur, cv->frames[f].y);
cur += sprintu32(cur, cv->frames[f].handlex);
cur += sprintu32(cur, cv->frames[f].handley);
}

/* canvas_data */
for(n = cv->height * cv->width; n--; )
for(f = 0; f < cv->framecount; f++)
{
cur += sprintu32(cur, *chars++);
cur += sprintu32(cur, *attrs++);
uint32_t *attrs = cv->frames[f].attrs;
uint32_t *chars = cv->frames[f].chars;

for(n = cv->height * cv->width; n--; )
{
cur += sprintu32(cur, *chars++);
cur += sprintu32(cur, *attrs++);
}
}

return data;


+ 1
- 1
examples/spritedit.c 查看文件

@@ -63,7 +63,7 @@ int main(int argc, char **argv)
for(i = 0; i < 4; i++)
{
cucul_set_frame(sprite, i);
cucul_import_memory(sprite, guy[i], strlen(guy[i]), "text");
cucul_import_memory(sprite, guy[i], strlen(guy[i]), "utf8");
}

/* Export our sprite in a memory buffer. We could save this to


正在加载...
取消
保存