new file format with versioning and layer opacity

This commit is contained in:
2018-09-20 21:12:48 +02:00
parent 3a81d337d4
commit 9ea1ca4fae
8 changed files with 94 additions and 15 deletions

View File

@@ -13,11 +13,17 @@ config = sys.argv[1].lower()
version = "%s.%d (%s-%s-%s)" % (tag, revcount, shorthash, branch, config)
version_number = "%s.%d" % (tag, revcount)
version_parts = version_number.split('.')
print("Compiling version: %s" % version)
version_gen_h = '// AUTO GENERATED FILE - DON\'T MODIFY\n'
version_gen_h += '#define PP_VERSION_NUMBER_STRING "%s"\n' % version_number
version_gen_h += '#define PP_VERSION_STRING "%s"\n' % version
version_gen_h += '#define PP_VERSION_MAJOR %s\n' % version_parts[0]
version_gen_h += '#define PP_VERSION_MINOR %s\n' % version_parts[1]
version_gen_h += '#define PP_VERSION_FIX %s\n' % version_parts[2]
version_gen_h += '#define PP_VERSION_BUILD %s\n' % version_parts[3]
version_gen_h += '#define PP_RC_BUILD_VERSION %s\n' % version_number.replace('.',',')
version_gen_h += '#define PP_RC_BUILD_VERSION_STRING "%s\\0"\n' % version
version_gen_h += '#define PP_RC_PRODUCT_VERSION %s,0\n' % tag.replace('.',',')

View File

@@ -200,7 +200,10 @@ void App::dialog_browse()
async_start();
title_update();
for (auto& i : canvas->m_canvas->m_order)
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
{
auto* l = layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
l->m_opacity->m_value.x = canvas->m_canvas->m_layers[i].m_opacity;
}
async_end();
});
dialog->destroy();

View File

@@ -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);

View File

@@ -42,6 +42,49 @@ public:
void destroy();
};
struct PPIThumb
{
int width = 128;
int height = 128;
int comp = 4;
bool valid() const
{
return (width == 128 && height == 128 && comp == 4);
}
};
struct PPIDocVersion
{
int major = 0;
int minor = 1;
};
struct PPISoftVersion
{
int major = g_version_major;
int minor = g_version_minor;
int fix = g_version_fix;
int build = g_version_build;
};
struct PPIHeader
{
char magic[4]{ 'P', 'P', 'I', 0 };
PPIDocVersion doc_version;
PPISoftVersion soft_version;
PPIThumb thumb_header;
bool valid()
{
if (strcmp(magic, "PPI") != 0)
return false;
if (doc_version.major != 0 || doc_version.minor != 1)
return false;
if (!thumb_header.valid())
return false;
return true;
}
};
class Canvas
{
public:

View File

@@ -162,7 +162,7 @@ void NodePanelLayer::init()
LOG("done init");
}
void NodePanelLayer::add_layer(const char* name)
NodeLayer* NodePanelLayer::add_layer(const char* name)
{
NodeLayer* l = new NodeLayer;
m_layers_container->add_child(l);
@@ -179,6 +179,7 @@ void NodePanelLayer::add_layer(const char* name)
m_current_layer = l;
m_current_layer->m_selected = true;
m_layers.push_back(l);
return l;
}
void NodePanelLayer::add_layer()

View File

@@ -52,7 +52,7 @@ public:
virtual Node* clone_instantiate() const override;
virtual void init() override;
void add_layer();
void add_layer(const char* name);
NodeLayer* add_layer(const char* name);
NodeLayer* get_layer_at(int index);
void remove_layer(NodeLayer* layer);
void handle_layer_opacity(NodeLayer* target, float value);

View File

@@ -4,6 +4,10 @@
const char* g_version = PP_VERSION_STRING;
const char* g_version_number = PP_VERSION_NUMBER_STRING;
const char* g_window_title = "PanoPainter " PP_VERSION_NUMBER_STRING;
const int g_version_major = PP_VERSION_MAJOR;
const int g_version_minor = PP_VERSION_MINOR;
const int g_version_fix = PP_VERSION_FIX;
const int g_version_build = PP_VERSION_BUILD;
#ifdef _WIN32
#include "windows.h"

View File

@@ -3,6 +3,10 @@
extern const char* g_version;
extern const char* g_version_number;
extern const char* g_window_title;
extern const int g_version_major;
extern const int g_version_minor;
extern const int g_version_fix;
extern const int g_version_build;
#ifdef _WIN32
extern const wchar_t* g_version_w;