diff options
author | Krow Savcik <krow@savcik.xyz> | 2024-07-20 00:54:59 +0300 |
---|---|---|
committer | Krow Savcik <krow@savcik.xyz> | 2024-07-20 00:56:41 +0300 |
commit | a583c78de168b761db4a4f87004108b142a9c1a2 (patch) | |
tree | d754c8797d9a6a8d59458cda3a75408d05ea1261 /src | |
parent | b486d1f47e0bbc1a0e3414df1f4f9193a3997300 (diff) |
feature: cdr v3 added
Diffstat (limited to 'src')
-rw-r--r-- | src/canvas.c | 39 | ||||
-rw-r--r-- | src/canvas.h | 2 |
2 files changed, 36 insertions, 5 deletions
diff --git a/src/canvas.c b/src/canvas.c index 9c860ae..7dd7ea4 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -31,6 +31,7 @@ static void action_remove(Action *); static void action_pixcols_redo(Canvas *, Action *); static Canvas *canvas_open1(FILE *, void *); static Canvas *canvas_open2(FILE *, void *); +static Canvas *canvas_open3(FILE *, void *); static uint8 canvas_coord_get(Canvas *c, long int tx, long int ty, long int *x, long int *y) @@ -163,6 +164,7 @@ canvas_open(const char *path, void *ren) switch (ver) { case 1: c = canvas_open1(fp, ren); break; case 2: c = canvas_open2(fp, ren); break; + case 3: c = canvas_open3(fp, ren); break; default: fprintf(stderr, "Error opening file. Unkown version %u.", ver); break; @@ -195,7 +197,6 @@ canvas_open2(FILE *fp, void *ren) unsigned int w, h, lc, i; Canvas *c; fscanf(fp, "%u;%u;%u;", &w, &h, &lc); - puts("READING DATA"); c = canvas_init(w, h, ren); for (i = 1; i < lc; i++) canvas_add_layer(c, lc); @@ -211,6 +212,34 @@ canvas_open2(FILE *fp, void *ren) return c; } +static Canvas * +canvas_open3(FILE *fp, void *ren) +{ + unsigned int w, h, lc, fc, i; + Canvas *c; + fscanf(fp, "%u;%u;%u;%u;", &w, &h, &lc, &fc); + c = canvas_init(w, h, ren); + puts("TEST"); + for (i = 1; i < lc; i++) + canvas_add_layer(c, lc); + for (i = 1; i < fc; i++) + canvas_add_frame(c, fc); + + for (i = 0; i < lc; i++) { + fread(c->layers[i].name, sizeof *(c->layers[i].name), LAYERNAMELEN, fp); + c->layers[i].name[LAYERNAMELEN] = '\0'; + fscanf(fp, ";%c;", &c->layers[i].visible); + } + + for (i = 0; i < fc; i++) + fscanf(fp, "%c;", &c->frames[i].state); + + for (i = 0; i < lc * fc; i++) + fread(c->cells[i], sizeof *(c->cells[i]), c->w*c->h, fp); + + return c; +} + Canvas * canvas_import_png(const char *path, void *ren) { @@ -450,12 +479,14 @@ canvas_save(Canvas *c, const char *path, short int s) return 1; } - fprintf(fp, "2;%u;%u;%u;", c->w, c->h, c->layer_arr_cnt); + fprintf(fp, "3;%u;%u;%u;%u;", c->w, c->h, c->layer_arr_cnt, c->frame_arr_cnt); for (i = 0; i < c->layer_arr_cnt; i++) { fwrite(c->layers[i].name, sizeof *(c->layers[i].name), LAYERNAMELEN, fp); - fprintf(fp, ";"); + fprintf(fp, ";%c;", c->layers[i].visible); } - for (i = 0; i < c->layer_arr_cnt; i++) + for (i = 0; i < c->frame_arr_cnt; i++) + fprintf(fp, "%c;", c->frames[i].state); + for (i = 0; i < c->layer_arr_cnt * c->frame_arr_cnt; i++) fwrite(c->cells[i], sizeof *(c->cells[i]), c->w*c->h, fp); fclose(fp); if (s) diff --git a/src/canvas.h b/src/canvas.h index f76f0a1..dbda7cf 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -5,7 +5,7 @@ #define LAYERNAMELEN 30 struct Layer { - unsigned int visible; + unsigned char visible; char name[LAYERNAMELEN+1]; }; |