File size: 6,223 Bytes
17f5b5c 6ef0bb6 17f5b5c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | #pragma once
#include <filesystem>
extern std::filesystem::path g_currPath; // 注意:这是工作目录
extern std::pair<std::filesystem::path, std::filesystem::path> get_img_json_pth(const std::string& m5);
#include <string>
#include <vector>
extern std::vector<unsigned char> base64_decode(const std::string& input);
#include <fstream>
#include <sstream>
#include <string>
extern std::string readFileToString(const std::string& filePath);
typedef const char* (_cdecl* FunctionPtr) (const char* pth_img);
extern FunctionPtr rec;
extern std::string base64_encode(std::string pth_img);
//#include "../imgui/backends/imgui_impl_win32.h"
//#include "../imgui/backends/imgui_impl_dx11.h"
//#include <memory>
//#include <mutex>
//
//
//// Data
//static ID3D11Device* g_pd3dDevice = nullptr;
//static ID3D11DeviceContext* g_pd3dDeviceContext = nullptr;
//static IDXGISwapChain* g_pSwapChain = nullptr;
//static bool g_SwapChainOccluded = false;
//static UINT g_ResizeWidth = 0, g_ResizeHeight = 0;
//static ID3D11RenderTargetView* g_mainRenderTargetView = nullptr;
//
//// Forward declarations of helper functions
////bool CreateDeviceD3D(HWND hWnd);
////void CleanupDeviceD3D();
////void CreateRenderTarget();
////void CleanupRenderTarget();
//
//#include <wincodec.h>
//#pragma comment(lib, "windowscodecs.lib")
//
//// DX11加载图片到纹理(从内存)
//ImTextureID LoadTextureFromMemoryDX11(const void* data, size_t data_size, ID3D11Device* device, int* out_width, int* out_height)
//{
// if (!device || !data) return 0;
// ID3D11ShaderResourceView* out_srv;
// if (out_width) *out_width = 0;
// if (out_height) *out_height = 0;
//
// IWICImagingFactory* wicFactory = nullptr;
// IWICStream* wicStream = nullptr;
// IWICBitmapDecoder* wicDecoder = nullptr;
// IWICBitmapFrameDecode* wicFrame = nullptr;
// IWICFormatConverter* wicConverter = nullptr;
// bool result = false;
//
// // 创建WIC工厂
// if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) {
// return 0;
// }
// if (FAILED(CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&wicFactory)))) {
// return 0;
// }
//
// // 创建WIC流
// if (FAILED(wicFactory->CreateStream(&wicStream))) {
// return 0;
// }
// if (FAILED(wicStream->InitializeFromMemory((BYTE*)data, (DWORD)data_size))) {
// return 0;
// }
//
// // 创建解码器
// if (FAILED(wicFactory->CreateDecoderFromStream(wicStream, nullptr, WICDecodeMetadataCacheOnLoad, &wicDecoder))) {
// return 0;
// }
//
// // 获取第一帧
// if (FAILED(wicDecoder->GetFrame(0, &wicFrame))) {
// return 0;
// }
//
// // 转换为32位RGBA格式
// if (FAILED(wicFactory->CreateFormatConverter(&wicConverter))) {
// return 0;
// }
// if (FAILED(wicConverter->Initialize(wicFrame, GUID_WICPixelFormat32bppRGBA, WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom))) {
// return 0;
// }
//
// UINT width = 0, height = 0;
// if (FAILED(wicConverter->GetSize(&width, &height))) {
// return 0;
// }
//
// std::vector<BYTE> imageData(width * height * 4);
// if (FAILED(wicConverter->CopyPixels(nullptr, width * 4, (UINT)imageData.size(), imageData.data()))) {
// return 0;
// }
//
// // 创建DX11纹理
// D3D11_TEXTURE2D_DESC desc = {};
// desc.Width = width;
// desc.Height = height;
// desc.MipLevels = 1;
// desc.ArraySize = 1;
// desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
// desc.SampleDesc.Count = 1;
// desc.Usage = D3D11_USAGE_DEFAULT;
// desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
//
// D3D11_SUBRESOURCE_DATA subResource = {};
// subResource.pSysMem = imageData.data();
// subResource.SysMemPitch = width * 4;
//
// ID3D11Texture2D* texture = nullptr;
// if (FAILED(device->CreateTexture2D(&desc, &subResource, &texture))) {
// if (wicConverter) wicConverter->Release();
// if (wicFrame) wicFrame->Release();
// if (wicDecoder) wicDecoder->Release();
// if (wicStream) wicStream->Release();
// if (wicFactory) wicFactory->Release();
// return 0;
// }
//
// // 创建SRV
// D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
// srvDesc.Format = desc.Format;
// srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
// srvDesc.Texture2D.MipLevels = 1;
// if (FAILED(device->CreateShaderResourceView(texture, &srvDesc, &out_srv))) {
// texture->Release();
// if (wicConverter) wicConverter->Release();
// if (wicFrame) wicFrame->Release();
// if (wicDecoder) wicDecoder->Release();
// if (wicStream) wicStream->Release();
// if (wicFactory) wicFactory->Release();
// return 0;
// }
//
//
// ImTextureID texture_id = (ImTextureID)(intptr_t)out_srv;
//
// texture->Release();
// if (out_width) *out_width = (int)width;
// if (out_height) *out_height = (int)height;
//
// if (wicConverter) wicConverter->Release();
// if (wicFrame) wicFrame->Release();
// if (wicDecoder) wicDecoder->Release();
// if (wicStream) wicStream->Release();
// if (wicFactory) wicFactory->Release();
// // CoUninitialize(); // 如果你在主程序中全局初始化COM,这里不要uninit
// return texture_id;
//}
//
//// DX11释放纹理(替代stbi_image_free)
//void DX11FreeTexture(ID3D11ShaderResourceView* srv)
//{
// if (srv) srv->Release();
//}
//
//// Open and read a file, then forward to LoadTextureFromMemory()
//ImTextureID LoadTextureFromFile(const char* file_name, ID3D11Device* device, int* out_width, int* out_height)
//{
// FILE* f = fopen(file_name, "rb");
// if (f == NULL)
// return 0;
// fseek(f, 0, SEEK_END);
// size_t file_size = (size_t)ftell(f);
// if (file_size == -1)
// return 0;
// fseek(f, 0, SEEK_SET);
// void* file_data = IM_ALLOC(file_size);
// fread(file_data, 1, file_size, f);
// fclose(f);
// ImTextureID texture_id = LoadTextureFromMemoryDX11(file_data, file_size, device, out_width, out_height);
// IM_FREE(file_data);
// return texture_id;
//}
//
|