add export layers, export png, import brush padding
This commit is contained in:
104
src/canvas.cpp
104
src/canvas.cpp
@@ -1334,7 +1334,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
|
||||
face.bind();
|
||||
// copy the framebuffer before clearing to white
|
||||
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_width, m_height);
|
||||
m_tmp[i].clear({ 1, 1, 1, 1 });
|
||||
m_tmp[i].clear({ 1, 1, 1, 0 });
|
||||
m_plane.draw_fill();
|
||||
face.unbind();
|
||||
|
||||
@@ -1402,10 +1402,10 @@ void Canvas::export_equirectangular_thread(std::string file_path)
|
||||
}
|
||||
|
||||
LOG("writing %s", file_path.c_str());
|
||||
jpge::params params;
|
||||
params.m_quality = 100;
|
||||
bool saved = jpge::compress_image_to_jpeg_file(file_path.c_str(), m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), params);
|
||||
inject_xmp(file_path.c_str());
|
||||
if (file_path.substr(file_path.size() - 4) == ".jpg")
|
||||
stbi_write_jpg(file_path.c_str(), m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), 100);
|
||||
else if (file_path.substr(file_path.size() - 4) == ".png")
|
||||
stbi_write_png(file_path.c_str(), m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), 0);
|
||||
|
||||
{
|
||||
progress++;
|
||||
@@ -1503,10 +1503,21 @@ void Canvas::inject_xmp(std::string jpg_path)
|
||||
|
||||
}
|
||||
|
||||
void Canvas::export_anim()
|
||||
void Canvas::export_layers(std::string file_name, std::function<void()> on_complete)
|
||||
{
|
||||
if (App::I.check_license())
|
||||
{
|
||||
std::thread t([=] {
|
||||
export_layers_thread(file_name);
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::export_layers_thread(std::string file_name)
|
||||
{
|
||||
if (!App::I.check_license())
|
||||
return;
|
||||
// save viewport and clear color states
|
||||
GLint vp[4];
|
||||
GLfloat cc[4];
|
||||
@@ -1514,6 +1525,24 @@ void Canvas::export_anim()
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
|
||||
GLboolean blend = glIsEnabled(GL_BLEND);
|
||||
|
||||
gl_state gl;
|
||||
App::I.async_start();
|
||||
std::shared_ptr<NodeProgressBar> pb;
|
||||
if (App::I.layout.m_loaded)
|
||||
{
|
||||
pb = std::make_shared<NodeProgressBar>();
|
||||
pb->m_manager = &App::I.layout;
|
||||
pb->init();
|
||||
pb->create();
|
||||
pb->loaded();
|
||||
pb->m_progress->SetWidthP(0);
|
||||
pb->m_title->set_text("Export Pano Layers");
|
||||
App::I.layout[App::I.main_id]->add_child(pb);
|
||||
App::I.async_update();
|
||||
}
|
||||
int progress = 0;
|
||||
int total = (m_order.size() + 1) * 6;
|
||||
|
||||
// prepare common states
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
|
||||
@@ -1540,20 +1569,21 @@ void Canvas::export_anim()
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
m_tmp[i].bindFramebuffer();
|
||||
|
||||
if (seq == 0)
|
||||
{
|
||||
m_tmp[i].clear({ 1, 1, 1, 1 });
|
||||
ShaderManager::use(kShader::Checkerboard);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
|
||||
m_plane.draw_fill();
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
else
|
||||
//if (seq == 0)
|
||||
//{
|
||||
// m_tmp[i].clear({ 1, 1, 1, 1 });
|
||||
// ShaderManager::use(kShader::Checkerboard);
|
||||
// ShaderManager::u_mat4(kShaderUniform::MVP, glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f));
|
||||
// m_plane.draw_fill();
|
||||
// glEnable(GL_BLEND);
|
||||
//}
|
||||
//else
|
||||
{
|
||||
m_tmp[i].clear({ 1, 1, 1, 0 });
|
||||
glDisable(GL_BLEND);
|
||||
//glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
@@ -1575,6 +1605,18 @@ void Canvas::export_anim()
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
|
||||
m_tmp[i].unbindFramebuffer();
|
||||
|
||||
progress++;
|
||||
float p = (float)progress / total * 100.f;
|
||||
LOG("progress: %f", p);
|
||||
|
||||
if (App::I.layout.m_loaded)
|
||||
{
|
||||
pb->m_progress->SetWidthP(p);
|
||||
gl.save();
|
||||
App::I.async_update();
|
||||
gl.restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1596,19 +1638,37 @@ void Canvas::export_anim()
|
||||
auto latlong_data = std::make_unique<uint8_t[]>(m_latlong.bytes());
|
||||
m_latlong.readTextureData(latlong_data.get());
|
||||
static char name[128];
|
||||
sprintf(name, "%s/latlong-frame%02d.png", App::I.work_path.c_str(), seq);
|
||||
sprintf(name, "%s/%s-layer-%02d.png", App::I.work_path.c_str(), file_name.c_str(), seq);
|
||||
seq++;
|
||||
LOG("writing %s", name);
|
||||
App::I.async_end();
|
||||
int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
|
||||
//jpge::params params;
|
||||
//params.m_quality = 100;
|
||||
//bool saved = jpge::compress_image_to_jpeg_file(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), params);
|
||||
App::I.async_start();
|
||||
}
|
||||
|
||||
progress++;
|
||||
float p = (float)progress / total * 100.f;
|
||||
LOG("progress: %f", p);
|
||||
|
||||
if (App::I.layout.m_loaded)
|
||||
{
|
||||
pb->m_progress->SetWidthP(p);
|
||||
gl.save();
|
||||
App::I.async_update();
|
||||
gl.restore();
|
||||
}
|
||||
}
|
||||
|
||||
glDeleteTextures(1, &cube_id);
|
||||
m_latlong.destroy();
|
||||
|
||||
if (App::I.layout.m_loaded)
|
||||
{
|
||||
pb->destroy();
|
||||
App::I.async_update();
|
||||
}
|
||||
App::I.async_end();
|
||||
|
||||
// restore viewport and clear color states
|
||||
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
|
||||
glViewport(vp[0], vp[1], vp[2], vp[3]);
|
||||
|
||||
Reference in New Issue
Block a user