MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / write_layer

Function write_layer

src/doc/layer_io.cpp:37–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35// Serialized Layer data:
36
37void write_layer(std::ostream& os, const Layer* layer)
38{
39 write32(os, layer->id());
40 write_string(os, layer->name());
41
42 write32(os, static_cast<int>(layer->flags())); // Flags
43 write16(os, static_cast<int>(layer->type())); // Type
44
45 switch (layer->type()) {
46
47 case ObjectType::LayerImage: {
48 const LayerImage* imgLayer = static_cast<const LayerImage*>(layer);
49 CelConstIterator it, begin = imgLayer->getCelBegin();
50 CelConstIterator end = imgLayer->getCelEnd();
51
52 // Blend mode & opacity
53 write16(os, (int)imgLayer->blendMode());
54 write8(os, imgLayer->opacity());
55
56 // Images
57 int images = 0;
58 int celdatas = 0;
59 for (it=begin; it != end; ++it) {
60 auto cel = *it;
61 if (!cel->link()) {
62 ++images;
63 ++celdatas;
64 }
65 }
66
67 write16(os, images);
68 for (it=begin; it != end; ++it) {
69 auto cel = *it;
70 if (!cel->link())
71 write_image(os, cel->image());
72 }
73
74 write16(os, celdatas);
75 for (it=begin; it != end; ++it) {
76 auto cel = *it;
77 if (!cel->link())
78 write_celdata(os, cel->dataRef().get());
79 }
80
81 // Cels
82 write16(os, imgLayer->getCelsCount());
83 for (it=begin; it != end; ++it) {
84 write_cel(os, it->get());
85 }
86 break;
87 }
88
89 case ObjectType::LayerFolder: {
90 LayerConstIterator it = static_cast<const LayerFolder*>(layer)->getLayerBegin();
91 LayerConstIterator end = static_cast<const LayerFolder*>(layer)->getLayerEnd();
92
93 // Number of sub-layers
94 write16(os, static_cast<const LayerFolder*>(layer)->getLayersCount());

Callers 1

onUndoMethod · 0.85

Calls 15

write_stringFunction · 0.85
write_imageFunction · 0.85
write_celdataFunction · 0.85
write_celFunction · 0.85
write_user_dataFunction · 0.85
getCelBeginMethod · 0.80
getCelEndMethod · 0.80
linkMethod · 0.80
dataRefMethod · 0.80
getCelsCountMethod · 0.80
getLayerBeginMethod · 0.80
getLayerEndMethod · 0.80

Tested by

no test coverage detected