android 平台跑通中文路径
@@ -0,0 +1,20 @@
|
||||
package com.hmwl.face_sdk;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class InitArg {
|
||||
public int action_fps;
|
||||
public float zoom;
|
||||
public Motion motion;
|
||||
public String toJson() {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("action_fps", action_fps);
|
||||
jsonObject.put("zoom", zoom);
|
||||
jsonObject.put("motion", motion.toJsonObject());
|
||||
return jsonObject.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.hmwl.face_sdk;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Motion {
|
||||
public String type;
|
||||
public String technique;
|
||||
public String step;
|
||||
public String show_type;
|
||||
public String png_name;
|
||||
public int png_num;
|
||||
|
||||
public JSONObject toJsonObject() {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type", type);
|
||||
jsonObject.put("technique", technique);
|
||||
jsonObject.put("step", step);
|
||||
jsonObject.put("show_type", show_type);
|
||||
jsonObject.put("png_name", png_name);
|
||||
jsonObject.put("png_num", png_num);
|
||||
return jsonObject;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
try {
|
||||
return toJsonObject().toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 15 KiB |
@@ -2,16 +2,30 @@ package com.hmwl.example;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.hmwl.face_sdk.InitArg;
|
||||
import com.hmwl.face_sdk.Motion;
|
||||
|
||||
|
||||
import com.hmwl.face_sdk.FaceActivity;
|
||||
public class MainActivity extends FaceActivity{
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
SetInitArg("{\"action_fps\":3,\"motion\":{\"png_name\":\"test\",\"png_num\":1,\"show_type\":\"direction\",\"step\":\"press2\",\"technique\":\"base_makeup\",\"type\":\"bottom_makeup\"},\"zoom\":1.5}");
|
||||
Motion motion = new Motion();
|
||||
motion.type = "底妆";
|
||||
motion.technique = "基础上妆";
|
||||
motion.step = "2按压";
|
||||
motion.show_type = "方向示意图";
|
||||
motion.png_name = "test";
|
||||
motion.png_num = 1;
|
||||
|
||||
InitArg initArg = new InitArg();
|
||||
initArg.action_fps = 3;
|
||||
initArg.zoom = 1.5f;
|
||||
initArg.motion = motion;
|
||||
SetInitArg(initArg.toJson());
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//这个是设置接口的参数,采用json传递,可以保证接口灵活性
|
||||
//比如设置对应的化妆步骤为
|
||||
ChangeState("{\"step\":\"0\"}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,34 @@ void VK_CHECK(VkResult ret)
|
||||
//#endif
|
||||
// return path;
|
||||
//}
|
||||
#ifdef _WIN32
|
||||
std::vector<unsigned char> AppBase::readFileUnsignedCharWin32(const std::wstring path, bool example)
|
||||
{
|
||||
std::vector<unsigned char> buffer;
|
||||
|
||||
std::wstring enginePath = L"app/src/main/assets/" + path;
|
||||
if (example)
|
||||
{
|
||||
enginePath = L"example/src/main/assets/" + path;
|
||||
}
|
||||
std::ifstream file{ enginePath, std::ios::ate | std::ios::binary };
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
throw std::runtime_error("failed to open file: ");
|
||||
}
|
||||
|
||||
size_t fileSize = static_cast<size_t>(file.tellg());
|
||||
buffer.resize(fileSize);
|
||||
|
||||
file.seekg(0);
|
||||
file.read((char*)buffer.data(), fileSize);
|
||||
file.close();
|
||||
|
||||
|
||||
return buffer;
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
std::vector<unsigned char> AppBase::readFileUnsignedChar(const std::string& path, bool example)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define logOut std::cout
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../app/src/main/cpp/AndroidOut.h"
|
||||
#define logOut aout
|
||||
@@ -69,7 +70,7 @@ public:
|
||||
//std::string getPath(const std::string path);
|
||||
VkShaderModule createShaderModule(VkDevice& device, const std::vector<char>& code);
|
||||
const std::vector<const char*> validationLayers = {"VK_LAYER_KHRONOS_validation"};
|
||||
protected:
|
||||
|
||||
long long getCurrentTimeMillis() {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto duration = now.time_since_epoch();
|
||||
@@ -87,6 +88,23 @@ protected:
|
||||
void pickPhysicalDevice(VkPhysicalDevice& physicalDevice, VkSurfaceKHR& surface);
|
||||
#ifdef _WIN32
|
||||
GLFWwindow *window;
|
||||
std::vector<unsigned char> readFileUnsignedCharWin32(const std::wstring path, bool example);
|
||||
static std::wstring UTF8ToWideString(const std::string& utf8str)
|
||||
{
|
||||
if (utf8str.empty()) return L"";
|
||||
|
||||
int wideLen = MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(),
|
||||
-1, nullptr, 0);
|
||||
if (wideLen == 0) {
|
||||
throw std::runtime_error("UTF-8转换失败");
|
||||
}
|
||||
|
||||
std::vector<wchar_t> buffer(wideLen);
|
||||
MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), -1,
|
||||
buffer.data(), wideLen);
|
||||
|
||||
return std::wstring(buffer.data());
|
||||
}
|
||||
#endif
|
||||
|
||||
bool enableValidationLayers = true;
|
||||
|
||||
@@ -639,10 +639,10 @@ Texture Application::loadTexture(std::string path, Texture& tex, bool srgb)
|
||||
processWithVulkan(image.data(), w, h, w * 4, image.size(), tex, srgb);
|
||||
return tex;
|
||||
}
|
||||
|
||||
Texture Application::loadTextureExample(std::string path, Texture& tex, bool srgb)
|
||||
#ifdef _WIN32
|
||||
Texture Application::loadTextureExample(std::wstring path, Texture& tex, bool srgb)
|
||||
{
|
||||
std::vector<unsigned char> data = readFileUnsignedChar(path, true);
|
||||
std::vector<unsigned char> data = readFileUnsignedCharWin32(path, true);
|
||||
std::vector<unsigned char> image;
|
||||
unsigned w, h;
|
||||
unsigned error = lodepng::decode(image, w, h, data, LCT_RGBA, 8);
|
||||
@@ -650,6 +650,10 @@ Texture Application::loadTextureExample(std::string path, Texture& tex, bool srg
|
||||
return tex;
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
|
||||
|
||||
void Application::createTexture(VkDevice device, VkPhysicalDevice physicalDevice, int width, int height, Texture& texture, bool srgb)
|
||||
{
|
||||
|
||||
@@ -75,7 +75,9 @@ protected:
|
||||
|
||||
protected:
|
||||
Texture loadTexture(std::string path, Texture& tex, bool srgb);
|
||||
Texture loadTextureExample(std::string path, Texture& tex, bool srgb);
|
||||
#ifdef _WIN32
|
||||
Texture loadTextureExample(std::wstring path, Texture& tex, bool srgb);
|
||||
#endif
|
||||
|
||||
uint32_t findMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter,
|
||||
VkMemoryPropertyFlags properties);
|
||||
|
||||
@@ -1146,16 +1146,19 @@ void FaceApp::changeMotion(Motion& motion)
|
||||
_curMotion = _initArg.motion;
|
||||
for (int i = 0; i < _curMotion.png_num; ++i)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
|
||||
string path_name = path + "/" + _curMotion.png_name + std::to_string(i) + ".png";
|
||||
#ifdef _WIN32
|
||||
loadTextureExample(path_name, m_texs[i], true);
|
||||
loadTextureExample(UTF8ToWideString(path_name), m_texs[i], true);
|
||||
if (kThick)
|
||||
{
|
||||
string path_name_ex = path + "/" + _curMotion.png_name + std::to_string(i) + "_thick.png";
|
||||
loadTextureExample(path_name_ex, m_texs_ex[i], true);
|
||||
loadTextureExample(UTF8ToWideString(path_name_ex), m_texs_ex[i], true);
|
||||
}
|
||||
#else
|
||||
string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
|
||||
string path_name = path + "/" + _curMotion.png_name + std::to_string(i) + ".png";
|
||||
loadTexture(path_name, m_texs[i], true);
|
||||
if (kThick)
|
||||
{
|
||||
|
||||
@@ -1,23 +1,8 @@
|
||||
|
||||
#include "FaceApp.h"
|
||||
#include <windows.h>
|
||||
|
||||
std::wstring UTF8ToWideString(const std::string& utf8str)
|
||||
{
|
||||
if (utf8str.empty()) return L"";
|
||||
|
||||
int wideLen = MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(),
|
||||
-1, nullptr, 0);
|
||||
if (wideLen == 0) {
|
||||
throw std::runtime_error("UTF-8转换失败");
|
||||
}
|
||||
|
||||
std::vector<wchar_t> buffer(wideLen);
|
||||
MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), -1,
|
||||
buffer.data(), wideLen);
|
||||
|
||||
return std::wstring(buffer.data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::wstring ReadUTF8File(const std::string& filePath)
|
||||
{
|
||||
@@ -32,7 +17,7 @@ std::wstring ReadUTF8File(const std::string& filePath)
|
||||
file.close();
|
||||
|
||||
// 将UTF-8字符串转换为宽字符串
|
||||
return UTF8ToWideString(content);
|
||||
return AppBase::UTF8ToWideString(content);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,23 +36,23 @@ std::wstring ReadFileWithChinesePath(const std::wstring& filePath) {
|
||||
file.seekg(0, std::ios::beg);
|
||||
file.read(&context[0], context.size());
|
||||
file.close();
|
||||
return UTF8ToWideString(context);
|
||||
return AppBase::UTF8ToWideString(context);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
std::string path = "chinese.txt";
|
||||
std::wstring chinese = ReadUTF8File(path);
|
||||
std::wstring chinese_path = UTF8ToWideString("d:/测试目录/中文文件.txt");
|
||||
std::wstring content = ReadFileWithChinesePath(chinese_path);
|
||||
//std::string path = "chinese.txt";
|
||||
//std::wstring chinese = ReadUTF8File(path);
|
||||
//std::wstring chinese_path = AppBase::UTF8ToWideString("d:/测试目录/中文文件.txt");
|
||||
//std::wstring content = ReadFileWithChinesePath(chinese_path);
|
||||
|
||||
InitArg init_arg;
|
||||
Motion motion;
|
||||
motion.type = "bottom_makeup";
|
||||
motion.technique = "base_makeup";
|
||||
motion.step = "press2";
|
||||
motion.show_type = "direction";
|
||||
motion.type = "底妆";
|
||||
motion.technique = "基础上妆";
|
||||
motion.step = "2按压";
|
||||
motion.show_type = "方向示意图";
|
||||
motion.png_name = "test";
|
||||
motion.png_num = 1;
|
||||
#
|
||||
|
||||