imradv3 / src /global.h
fasdfsa's picture
wechat ocr 用于编辑器
6ef0bb6
#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;
//}
//