diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 9039ce9..acb2d75 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -31,6 +31,7 @@ add_library( ../libs/poly2tri/poly2tri/sweep/cdt.cc ../libs/poly2tri/poly2tri/sweep/sweep_context.cc ../libs/poly2tri/poly2tri/sweep/sweep.cc + ../libs/fmt/src/format.cc src/main/cpp/main.cpp ../src/pch.cpp ../src/util.cpp @@ -91,6 +92,7 @@ add_library( ../src/node_usermanual.cpp ../src/node_viewport.cpp ../src/node_scroll.cpp + ../src/abr.cpp ) target_include_directories(native-lib PRIVATE @@ -107,6 +109,8 @@ target_include_directories(native-lib PRIVATE ../libs/sqlite3 ../libs/nanort ../libs/native_app_glue + ../libs/hash-library + ../libs/fmt/include ) # add lib dependencies diff --git a/android/src/main/java/com/omixlab/panopainter/MainActivity.java b/android/src/main/java/com/omixlab/panopainter/MainActivity.java index 41715cf..4cb3ca8 100644 --- a/android/src/main/java/com/omixlab/panopainter/MainActivity.java +++ b/android/src/main/java/com/omixlab/panopainter/MainActivity.java @@ -94,7 +94,7 @@ public class MainActivity extends NativeActivity { } // patterns - File patterns = new File(pano_dir.getAbsolutePath(), "brushes"); + File patterns = new File(pano_dir.getAbsolutePath(), "patterns"); if (!patterns.exists()) { if (patterns.mkdirs()) diff --git a/src/abr.cpp b/src/abr.cpp index fc94439..ebb10a1 100644 --- a/src/abr.cpp +++ b/src/abr.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "abr.h" +#include "log.h" bool ABR::section_desc() { @@ -20,7 +21,11 @@ bool ABR::section_desc() m_presets.push_back(desc); } auto out = presets->str(0, ""); - std::cout << out << '\n'; + auto lines = split(out, '\n'); + for (const auto& l : lines) + { + LOG("%s", l.c_str()); + } } return true; } @@ -63,7 +68,7 @@ bool ABR::section_patt() auto image_mode = ru32(); if (!(image_mode == 1 || image_mode == 3)) { - printf("PATT: skip image mode %d\n", image_mode); + LOG("PATT: skip image mode %d\n", image_mode); skip(patt_length - 8); snap(); continue; @@ -83,7 +88,7 @@ bool ABR::section_patt() int nc = std::min((int)vm->channels.size(), 3); if (nc != image_mode) { - printf("PATT: image_mode (%d) and number of channels (%d) not matching\n", + LOG("PATT: image_mode (%d) and number of channels (%d) not matching\n", image_mode, vm->channels.size()); } if (auto img = vm->image(true)) @@ -135,12 +140,13 @@ std::vector> ABR::compute_brushes(const std::string& path //b->m_blend_mode = i.m_blend_mode; //b->m_name.resize(i.m_name_len); //b->m_stencil_path.resize(i.m_stencil_path_len); - auto& tip_uid = wstr2str(samp->value("sampledData")); + auto tip_uid = wstr2str(samp->value("sampledData")); + LOG("tip uid %d %s", tip_uid.size(), tip_uid.c_str()); b->m_brush_path = path + "/brushes/" + tip_uid + ".png"; b->m_brush_thumb_path = path + "/brushes/thumbs/" + tip_uid + ".png"; if (auto patt = p->get("Txtr")) { - auto& patt_uid = wstr2str(patt->value("Idnt")); + auto patt_uid = wstr2str(patt->value("Idnt")); b->m_stencil_path = path + "/patterns/" + patt_uid + ".png"; //b->m_brush_thumb_path = path + "/patterns/thumbs/" + patt_uid + ".png"; b->m_tip_stencil = p->value("textureDepth") * 0.01f; @@ -179,7 +185,7 @@ std::shared_ptr ABR::parse_vmem() auto compression = ru8(); // 1 = zip if (depth != 8) { - printf("unsupported depth %d bits\n", depth); + LOG("unsupported depth %d bits\n", depth); skip(length - 23); continue; } @@ -208,7 +214,7 @@ std::shared_ptr ABR::parse_vmem() } else { - printf("unsupported compression mode %d\n", compression); + LOG("unsupported compression mode %d\n", compression); skip(length - 23); continue; } @@ -257,7 +263,7 @@ std::shared_ptr ABR::parse_objc() if (!property) return nullptr; if (ret->props.find(key) != ret->props.end()) - printf("DUPLICATE prop %d\n", key.c_str()); + LOG("DUPLICATE prop %d\n", key.c_str()); ret->props[key] = property; } return ret; @@ -336,7 +342,7 @@ bool ABR::open(const std::string& path) init(asset.read_all(), asset.m_len, BinaryStream::ByteOrder::BigEndian); auto version_major = ru16(); auto version_minor = ru16(); - printf("ABR %d.%d\n", version_major, version_minor); + LOG("ABR %d.%d\n", version_major, version_minor); while (!eof()) { if (rstring(4) != "8BIM") @@ -356,7 +362,7 @@ bool ABR::open(const std::string& path) } else { - printf("skip section %s\n", t.c_str()); + LOG("skip section %s\n", t.c_str()); skip(align4(ru32())); } } diff --git a/src/abr.h b/src/abr.h index e6e91aa..d437572 100644 --- a/src/abr.h +++ b/src/abr.h @@ -5,6 +5,7 @@ #include "util.h" #include "image.h" #include "brush.h" +#include "log.h" class BinaryStream { @@ -19,7 +20,7 @@ public: return bint.c[0] == 1 ? ByteOrder::BigEndian : ByteOrder::LittleEndian; } - BinaryStream(const BinaryParam&) = delete; + BinaryStream(const BinaryStream&) = delete; BinaryStream() = default; ~BinaryStream() { @@ -66,13 +67,17 @@ public: std::wstring rwstring(size_t len) { auto ptr = advance(len * 2); - for (int i = 0; i < len; i++) - std::swap(ptr[i * 2], ptr[i * 2 + 1]); + //for (int i = 0; i < len; i++) + // std::swap(ptr[i * 2], ptr[i * 2 + 1]); + // right trim trailing zeroes - auto wptr = (wchar_t*)ptr; + auto wptr = (uint16_t*)ptr; for (int i = len - 1; i >= 0; i--) if (wptr[i] == 0) len--; - return std::wstring(wptr, len); + + // wide to UTF-16le + std::wstring_convert> converter; + return converter.from_bytes(ptr, ptr + len * 2); } std::string rpascal() { @@ -168,7 +173,7 @@ protected: return *reinterpret_cast(&y); } #else - auto p = reinterpret_cast(&x); + auto p = reinterpret_cast(&x); if (sizeof(T) == 2) { std::swap(p[0], p[1]); @@ -347,7 +352,7 @@ class ABR : private BinaryStream uint8_t compression; std::vector data; Channel() = default; - Channel(uint32_t depth, const Rectangle& rect, uint8_t compression, std::vector& data) : + Channel(uint32_t depth, Rectangle rect, uint8_t compression, std::vector data) : depth(depth), rect(rect), compression(compression), data(std::move(data)) { } }; struct VMArray : public Type diff --git a/src/app_events.cpp b/src/app_events.cpp index c5d71d4..befa88f 100644 --- a/src/app_events.cpp +++ b/src/app_events.cpp @@ -98,7 +98,7 @@ void App::pick_file(std::vector types, std::function(); if (!m_tip_texture->load(m_brush_path)) + { + LOG("failed to load %s", m_brush_path.c_str()); + m_tip_texture = nullptr; return false; + } m_tip_texture->create_mipmaps(); m_tip_texture->auto_destroy = true; } @@ -294,7 +298,12 @@ bool Brush::load() { m_stencil_texture = std::make_shared(); if (!m_stencil_texture->load(m_stencil_path)) + { + LOG("failed to load %s", m_stencil_path.c_str()); + m_tip_texture = nullptr; + m_stencil_texture = nullptr; return false; + } m_stencil_texture->create_mipmaps(); m_stencil_texture->auto_destroy = true; } diff --git a/src/image.cpp b/src/image.cpp index 298da79..897398b 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -41,7 +41,10 @@ bool Image::load_file(std::string filename) bool Image::save(const std::string& path) { - return stbi_write_png(path.c_str(), width, height, comp, data(), 0); + bool ret = stbi_write_png(path.c_str(), width, height, comp, data(), 0); + if (!ret) + LOG("failed Image::save %s", path.c_str()); + return ret; } void Image::flip() diff --git a/src/node_panel_brush.cpp b/src/node_panel_brush.cpp index ea5e6cf..b7af258 100644 --- a/src/node_panel_brush.cpp +++ b/src/node_panel_brush.cpp @@ -65,7 +65,14 @@ void NodePanelBrush::init() if (str_iequals(ext, "abr")) { ABR abr; - abr.open(path); + LOG("ABR detected"); + + if (!abr.open(path)) + { + LOG("ABR read failed"); + return; + } + for (const auto& samp : abr.m_samples) { std::string path_high = App::I.data_path + "/brushes/" + samp.first + ".png"; @@ -101,8 +108,13 @@ void NodePanelBrush::init() for (const auto& pr : brushes) { auto presets = App::I.stroke->m_presets_popup; + async_start(); if (pr->load()) + { + LOG("add preset %s", pr->m_name.c_str()); presets->add_brush(pr); + } + async_end(); } //save(); }