From 76fbe9e940881005bbbbfaffb9bb7b37db7594bf Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sun, 24 Feb 2019 01:43:06 +0100 Subject: [PATCH] import dual brush from abr --- src/abr.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 86 insertions(+), 17 deletions(-) diff --git a/src/abr.cpp b/src/abr.cpp index 2041118..13c8d4c 100644 --- a/src/abr.cpp +++ b/src/abr.cpp @@ -124,10 +124,10 @@ std::vector> ABR::compute_brushes(const std::string& path b->m_tip_size = samp->value("Dmtr"); b->m_tip_spacing = samp->value("Spcn") * 0.01f; b->m_tip_angle = samp->value("Angl") / 360.f + 0.5f; // [-180, 180] -> [0, 1] - //b->m_tip_mix = i.m_tip_mix; - //b->m_tip_stencil = i.m_tip_stencil; b->m_tip_wet = p->value("Wtdg"); - b->m_tip_noise = (float)samp->value("Nose"); + b->m_tip_noise = samp->value("Nose"); + b->m_tip_flipx = samp->value("flipX"); + b->m_tip_flipy = samp->value("flipY"); // brush sample if (samp->class_id == "sampledBrush") @@ -153,6 +153,20 @@ std::vector> ABR::compute_brushes(const std::string& path } } + std::vector modes = { + "normal", // normal (not in Photoshop) + "Mltp", // multiply + "Sbtr", // subtract + "Drkn", // darken + "Ovrl", // overlay + "CDdg", // color dodge + "CBrn", // color burn + "linearBurn", // linear burn + "hardMix", // hard mix + "linearHeight", // linear height + "Hght", // height + }; + // pattern if (auto patt = p->get("Txtr")) { @@ -171,25 +185,80 @@ std::vector> ABR::compute_brushes(const std::string& path // blending mode std::string blend_mode = p->value("textureBlendMode"); - std::vector modes = { - "normal", // normal (not in Photoshop) - "Mltp", // multiply - "Sbtr", // subtract - "Drkn", // darken - "Ovrl", // overlay - "CDdg", // color dodge - "CBrn", // color burn - "linearBurn", // linear burn - "hardMix", // hard mix - "linearHeight", // linear height - "Hght", // height - }; auto bm_it = std::find(modes.begin(), modes.end(), blend_mode); if (bm_it != modes.end()) b->m_pattern_blend_mode = std::distance(modes.begin(), bm_it); - b->m_pattern_enabled = true; + b->m_pattern_enabled = p->value("useTexture"); } + + // dual brush + if (auto db = p->get("dualBrush")) + { + auto samp = db->get("Brsh"); + if (samp->class_id != "sampledBrush" && samp->class_id != "computedBrush") + { + LOG("unsupported brush type %s", samp->class_id.c_str()); + continue; + } + //b->m_name = wstr2str(p->value("Nm ")); + + // default values + //b->m_tip_color = { 0, 0, 0, 1 }; + b->m_dual_flow = .90f; + b->m_dual_opacity = 1.f; + + //b->m_tip_aspect = (1.f - samp->value("Rndn") * 0.01) * 0.5f + 0.5f; + b->m_dual_size = samp->value("Dmtr"); + b->m_dual_spacing = samp->value("Spcn") * 0.01f; + //b->m_tip_angle = samp->value("Angl") / 360.f + 0.5f; // [-180, 180] -> [0, 1] + //b->m_tip_wet = p->value("Wtdg"); + //b->m_tip_noise = (float)samp->value("Nose"); + b->m_tip_flipx = samp->value("flipX"); + b->m_tip_flipy = samp->value("flipY"); + + b->m_dual_randflip = db->value("Flip"); + b->m_dual_scatter_axis = db->value("bothAxes"); + + if (db->value("useScatter")) + { + auto scatter = db->get("scatterDynamics"); + b->m_dual_scatter = scatter->value("jitter"); + } + + // brush sample + if (samp->class_id == "sampledBrush") + { + auto tip_uid = wstr2str(samp->value("sampledData")); + b->m_dual_path = path + "/brushes/" + tip_uid + ".png"; + b->m_dual_thumb_path = path + "/brushes/thumbs/" + tip_uid + ".png"; + + const auto& samp_img = m_samples[tip_uid]; + //b->m_tip_width = (float)samp_img->width / (float)samp_img->height; + } + else if (samp->class_id == "computedBrush") + { + if (samp->value("Hrdn") > 50.f) + { + b->m_dual_path = "data/brushes/Round-Hard.png"; + b->m_dual_thumb_path = "data/brushes/thumbs/Round-Hard.png"; + } + else + { + b->m_dual_path = "data/brushes/Round-Brush.png"; + b->m_dual_thumb_path = "data/brushes/thumbs/Round-Brush.png"; + } + } + + // blending mode + std::string blend_mode = db->value("BlnM"); + auto bm_it = std::find(modes.begin(), modes.end(), blend_mode); + if (bm_it != modes.end()) + b->m_dual_blend_mode = std::distance(modes.begin(), bm_it); + + b->m_dual_enabled = db->value("useDualBrush"); + } + ret.push_back(b); } return ret;