new file format with versioning and layer opacity
This commit is contained in:
@@ -1532,9 +1532,12 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
return;
|
||||
}
|
||||
|
||||
PPIHeader ppi_header;
|
||||
fwrite(&ppi_header, sizeof(PPIHeader), 1, fp);
|
||||
|
||||
// load thumbnail
|
||||
App::I.async_start();
|
||||
Image thumb = thumbnail_generate(128, 128);
|
||||
Image thumb = thumbnail_generate(ppi_header.thumb_header.width, ppi_header.thumb_header.height);
|
||||
auto pb = std::make_shared<NodeProgressBar>();
|
||||
pb->m_manager = &App::I.layout;
|
||||
pb->init();
|
||||
@@ -1547,9 +1550,6 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
App::I.async_end();
|
||||
|
||||
thumb.flip();
|
||||
fwrite(&thumb.width, sizeof(int), 1, fp);
|
||||
fwrite(&thumb.height, sizeof(int), 1, fp);
|
||||
fwrite(&thumb.comp, sizeof(int), 1, fp);
|
||||
fwrite(thumb.data(), thumb.size(), 1, fp);
|
||||
|
||||
fwrite(&m_width, sizeof(int), 1, fp);
|
||||
@@ -1561,11 +1561,14 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
int progress = 0;
|
||||
int total = (int)m_layers.size() * 6;
|
||||
|
||||
for (int i = 0; i < (int)m_layers.size(); i++)
|
||||
for (int i = 0; i < (int)m_layers.size(); i++)
|
||||
{
|
||||
int n_order = m_order[i];
|
||||
fwrite(&n_order, sizeof(int), 1, fp);
|
||||
|
||||
float layer_alpha = m_layers[i].m_opacity;
|
||||
fwrite(&layer_alpha, sizeof(float), 1, fp);
|
||||
|
||||
int name_len = (int)m_layers[i].m_name.size();
|
||||
fwrite(&name_len, sizeof(int), 1, fp);
|
||||
fwrite(m_layers[i].m_name.data(), name_len, 1, fp);
|
||||
@@ -1642,6 +1645,12 @@ void ui::Canvas::project_open_thread(std::string file_path)
|
||||
return; // should probably return a bool
|
||||
}
|
||||
|
||||
PPIHeader ppi_header;
|
||||
fread(&ppi_header, sizeof(PPIHeader), 1, fp);
|
||||
|
||||
if (!ppi_header.valid())
|
||||
return;
|
||||
|
||||
gl_state gl;
|
||||
std::shared_ptr<NodeProgressBar> pb;
|
||||
if (App::I.layout.m_loaded)
|
||||
@@ -1661,12 +1670,11 @@ void ui::Canvas::project_open_thread(std::string file_path)
|
||||
App::I.async_end();
|
||||
}
|
||||
|
||||
LOG("skip thumb");
|
||||
// skip thumbnail
|
||||
Image thumb;
|
||||
fread(&thumb.width, sizeof(int), 1, fp);
|
||||
fread(&thumb.height, sizeof(int), 1, fp);
|
||||
fread(&thumb.comp, sizeof(int), 1, fp);
|
||||
thumb.width = ppi_header.thumb_header.width;
|
||||
thumb.height = ppi_header.thumb_header.height;
|
||||
thumb.comp = ppi_header.thumb_header.comp;
|
||||
fseek(fp, thumb.size(), SEEK_CUR);
|
||||
|
||||
fread(&m_width, sizeof(int), 1, fp);
|
||||
@@ -1698,6 +1706,9 @@ void ui::Canvas::project_open_thread(std::string file_path)
|
||||
int n_order;
|
||||
fread(&n_order, sizeof(int), 1, fp);
|
||||
|
||||
float layer_opacity;
|
||||
fread(&layer_opacity, sizeof(float), 1, fp);
|
||||
|
||||
int name_len;
|
||||
fread(&name_len, sizeof(int), 1, fp);
|
||||
std::string name(name_len, '\0');
|
||||
@@ -1745,6 +1756,7 @@ void ui::Canvas::project_open_thread(std::string file_path)
|
||||
|
||||
App::I.async_start();
|
||||
tmp_layers.emplace_back();
|
||||
tmp_layers.back().m_opacity = layer_opacity;
|
||||
tmp_layers.back().create(m_width, m_height, name.c_str());
|
||||
tmp_layers.back().restore(snap);
|
||||
tmp_order.push_back(n_order);
|
||||
@@ -1844,10 +1856,16 @@ ui::Image ui::Canvas::thumbnail_read(std::string data_path)
|
||||
LOG("cannot read project %s", data_path.c_str());
|
||||
return {}; // return empty image
|
||||
}
|
||||
PPIHeader ppi_header;
|
||||
fread(&ppi_header, sizeof(PPIHeader), 1, fp);
|
||||
|
||||
if (!ppi_header.valid())
|
||||
return {};
|
||||
|
||||
Image thumb;
|
||||
fread(&thumb.width, sizeof(int), 1, fp);
|
||||
fread(&thumb.height, sizeof(int), 1, fp);
|
||||
fread(&thumb.comp, sizeof(int), 1, fp);
|
||||
thumb.width = ppi_header.thumb_header.width;
|
||||
thumb.height = ppi_header.thumb_header.height;
|
||||
thumb.comp = ppi_header.thumb_header.comp;
|
||||
thumb.create();
|
||||
fread((uint8_t*)thumb.data(), thumb.size(), 1, fp);
|
||||
fclose(fp);
|
||||
|
||||
Reference in New Issue
Block a user