Persist FrameTags in .ase files

This commit is contained in:
David Capello 2015-02-17 18:05:34 -03:00
parent 9e734b2e8c
commit 9e67942235
4 changed files with 59 additions and 0 deletions

View File

@ -227,6 +227,17 @@ Path Chunk (0x2017)
Never used.
Frame Tags Chunk (0x2018)
----------------------------------------
WORD Number of tags
+ For each tag
WORD From frame
WORD To frame
BYTE[3] RGB values of the tag color
STRING Tag name
Notes
----------------------------------------

View File

@ -30,6 +30,7 @@
#define ASE_FILE_CHUNK_CEL 0x2005
#define ASE_FILE_CHUNK_MASK 0x2016
#define ASE_FILE_CHUNK_PATH 0x2017
#define ASE_FILE_CHUNK_FRAME_TAGS 0x2018
#define ASE_FILE_RAW_CEL 0
#define ASE_FILE_LINK_CEL 1
@ -100,6 +101,8 @@ static Mask* ase_file_read_mask_chunk(FILE* f);
#if 0
static void ase_file_write_mask_chunk(FILE* f, ASE_FrameHeader* frame_header, Mask* mask);
#endif
static void ase_file_read_frame_tags_chunk(FILE* f, FrameTags* frameTags);
static void ase_file_write_frame_tags_chunk(FILE* f, ASE_FrameHeader* frame_header, FrameTags* frameTags);
class ChunkWriter {
public:
@ -250,6 +253,10 @@ bool AseFormat::onLoad(FileOp* fop)
/* fop_error(fop, "Path chunk\n"); */
break;
case ASE_FILE_CHUNK_FRAME_TAGS:
ase_file_read_frame_tags_chunk(f, &sprite->frameTags());
break;
default:
fop_error(fop, "Warning: Unsupported chunk type %d (skipping)\n", chunk_type);
break;
@ -318,6 +325,10 @@ bool AseFormat::onSave(FileOp* fop)
// Write layer chunks
for (; it != end; ++it)
ase_file_write_layers(f, &frame_header, *it);
// Writer frame tags
if (sprite->frameTags().size() > 0)
ase_file_write_frame_tags_chunk(f, &frame_header, &sprite->frameTags());
}
// Write cel chunks
@ -1263,4 +1274,37 @@ static void ase_file_write_mask_chunk(FILE* f, ASE_FrameHeader* frame_header, Ma
}
#endif
static void ase_file_read_frame_tags_chunk(FILE* f, FrameTags* frameTags)
{
size_t tags = fgetw(f);
for (size_t c=0; c<tags; ++c) {
frame_t from = fgetw(f);
frame_t to = fgetw(f);
int r = fgetc(f);
int g = fgetc(f);
int b = fgetc(f);
std::string name = ase_file_read_string(f);
FrameTag* tag = new FrameTag(from, to);
tag->setColor(doc::rgba(r, g, b, 255));
tag->setName(name);
frameTags->add(tag);
}
}
static void ase_file_write_frame_tags_chunk(FILE* f, ASE_FrameHeader* frame_header, FrameTags* frameTags)
{
ChunkWriter chunk(f, frame_header, ASE_FILE_CHUNK_FRAME_TAGS);
fputw(frameTags->size(), f);
for (FrameTag* tag : *frameTags) {
fputw(tag->fromFrame(), f);
fputw(tag->toFrame(), f);
fputc(doc::rgba_getr(tag->color()), f);
fputc(doc::rgba_getg(tag->color()), f);
fputc(doc::rgba_getb(tag->color()), f);
ase_file_write_string(f, tag->name().c_str());
}
}
} // namespace app

View File

@ -15,6 +15,8 @@
#include "doc/color_scales.h"
#include "doc/document.h"
#include "doc/frame.h"
#include "doc/frame_tag.h"
#include "doc/frame_tags.h"
#include "doc/image.h"
#include "doc/image_bits.h"
#include "doc/layer.h"

View File

@ -33,6 +33,8 @@ namespace doc {
iterator begin() { return m_tags.begin(); }
iterator end() { return m_tags.end(); }
size_t size() { return m_tags.size(); }
private:
Sprite* m_sprite;
List m_tags;