Compare commits
3 Commits
92346dc81e
...
c03c80d938
Author | SHA1 | Date | |
---|---|---|---|
c03c80d938 | |||
afd4abadbb | |||
8ed7df659d |
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,13 +1,18 @@
|
||||
## my ban
|
||||
# -------------------- Personal --------------------
|
||||
# Ignore all possible test used Virtools files
|
||||
*.nmo
|
||||
*.cmo
|
||||
*.nms
|
||||
*.vmo
|
||||
out/
|
||||
temp/
|
||||
|
||||
# Ignore temporary folders
|
||||
/out/
|
||||
/temp/
|
||||
|
||||
# -------------------- VSCode --------------------
|
||||
.vscode/
|
||||
|
||||
## CMake Banned
|
||||
# -------------------- CMake --------------------
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
@ -20,6 +25,7 @@ compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
# -------------------- Visual Studio --------------------
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
|
8
BMapBindings/PyBMap/.gitignore
vendored
8
BMapBindings/PyBMap/.gitignore
vendored
@ -1,12 +1,18 @@
|
||||
# my ban
|
||||
# -------------------- Personal --------------------
|
||||
# Ignore VSCode
|
||||
.vscode/
|
||||
|
||||
# Ignore binary BMap stuff
|
||||
*.dll
|
||||
*.pdb
|
||||
*.so
|
||||
*.dylib
|
||||
*.bin
|
||||
|
||||
# Ignore testbench file.
|
||||
testbench.py
|
||||
|
||||
# -------------------- Python --------------------
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
@ -1,4 +1,4 @@
|
||||
import ctypes, os, sys
|
||||
import ctypes, os, sys, typing
|
||||
|
||||
#region Type Defines
|
||||
|
||||
@ -89,15 +89,15 @@ except:
|
||||
def is_bmap_available() -> bool:
|
||||
return _g_BMapModule is not None
|
||||
|
||||
def _bmap_error_check(result: bm_bool, func, args):
|
||||
def _bmap_error_check(result: bool, func, args):
|
||||
if not result:
|
||||
raise BMapException("BMap operation failed.")
|
||||
return result
|
||||
|
||||
def _create_bmap_func(fct_name: str, fct_params: list[ctypes._SimpleCData]) -> ctypes._CFuncPtr:
|
||||
def _create_bmap_func(fct_name: str, fct_params: list[typing.Any]) -> typing.Callable[..., bm_bool]:
|
||||
if _g_BMapModule is None: return None
|
||||
|
||||
cache: ctypes._CFuncPtr = getattr(_g_BMapModule, fct_name)
|
||||
cache: typing.Callable[..., bm_bool] = getattr(_g_BMapModule, fct_name)
|
||||
cache.argtypes = fct_params
|
||||
cache.restype = bm_bool
|
||||
cache.errcheck = _bmap_error_check
|
||||
|
@ -188,7 +188,7 @@ class VX_PIXELFORMAT(enum.IntEnum):
|
||||
"""!
|
||||
Pixel format types.
|
||||
"""
|
||||
UNKNOWN_PF = 0 ##< Unknown pixel format
|
||||
#UNKNOWN_PF = 0 ##< Unknown pixel format
|
||||
_32_ARGB8888 = 1 ##< 32-bit ARGB pixel format with alpha
|
||||
_32_RGB888 = 2 ##< 32-bit RGB pixel format without alpha
|
||||
_24_RGB888 = 3 ##< 24-bit RGB pixel format
|
||||
|
@ -1,6 +1,5 @@
|
||||
# PyBMap
|
||||
|
||||
The real scripts are placed in sub PyBMap folder. This folder is served for testbench scripts placing.
|
||||
Place any testbench files (e.g. `testbench.py`) in there what you want and don't sumbit them.
|
||||
The native BMap library should be placed in sub PyBMap folder, and I have used gitignore file to filter them.
|
||||
The native BMap library must be named as `BMap.dll` (in Windows), `BMap.so` (in Linux or BSD), or `BMap.dylib` (in macOS). If you still can not load BMap or your system is not listed above, you should name it as `BMap.bin`.
|
||||
The real scripts are placed in sub PyBMap folder. This folder is served for testbench scripts placing. Place any testbench files (e.g. `testbench.py`) in there what you want and don't sumbit them (`testbench.py` is explicitly excluded by gitignore file).
|
||||
|
||||
The native BMap library should be placed in sub PyBMap folder, and I have used gitignore file to filter them. The native BMap library must be named as `BMap.dll` (in Windows), `BMap.so` (in Linux or BSD), or `BMap.dylib` (in macOS). If you still can not load BMap or your system is not listed above, you should name it as `BMap.bin`.
|
||||
|
@ -1,4 +1,4 @@
|
||||
import ctypes, os, sys
|
||||
import ctypes, os, sys, typing
|
||||
|
||||
#region Type Defines
|
||||
|
||||
@ -89,15 +89,15 @@ except:
|
||||
def is_bmap_available() -> bool:
|
||||
return _g_BMapModule is not None
|
||||
|
||||
def _bmap_error_check(result: bm_bool, func, args):
|
||||
def _bmap_error_check(result: bool, func, args):
|
||||
if not result:
|
||||
raise BMapException("BMap operation failed.")
|
||||
return result
|
||||
|
||||
def _create_bmap_func(fct_name: str, fct_params: list[ctypes._SimpleCData]) -> ctypes._CFuncPtr:
|
||||
def _create_bmap_func(fct_name: str, fct_params: list[typing.Any]) -> typing.Callable[..., bm_bool]:
|
||||
if _g_BMapModule is None: return None
|
||||
|
||||
cache: ctypes._CFuncPtr = getattr(_g_BMapModule, fct_name)
|
||||
cache: typing.Callable[..., bm_bool] = getattr(_g_BMapModule, fct_name)
|
||||
cache.argtypes = fct_params
|
||||
cache.restype = bm_bool
|
||||
cache.errcheck = _bmap_error_check
|
||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2022-2023 yyc12345
|
||||
Copyright (c) 2022-2024 yyc12345
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -368,18 +368,124 @@ namespace LibCmo::CK2::DataHandlers {
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region CKBitmapJPGHandler
|
||||
|
||||
// MARK: this GUID is gotten from Virtools 3.5 Plugins.
|
||||
static const CKBitmapProperties g_JPGProperties(CKGUID(0x4AE51AC4u, 0x04587D76u), "jpg");
|
||||
// MARK: this quality is gotten from default value of virtools.
|
||||
constexpr int g_JPGDefaultQuality = 75;
|
||||
|
||||
CKBitmapJPGHandler::CKBitmapJPGHandler() :
|
||||
CKBitmapHandler() {}
|
||||
|
||||
CKBitmapJPGHandler::~CKBitmapJPGHandler() {}
|
||||
|
||||
const CKBitmapProperties& CKBitmapJPGHandler::GetBitmapDefaultProperties() {
|
||||
return g_JPGProperties;
|
||||
}
|
||||
|
||||
bool CKBitmapJPGHandler::ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) {
|
||||
return StbReadFile(u8filename, read_image);
|
||||
}
|
||||
|
||||
bool CKBitmapJPGHandler::ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) {
|
||||
return StbReadMemory(memory, size, read_image);
|
||||
}
|
||||
|
||||
bool CKBitmapJPGHandler::SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) {
|
||||
return StbSaveFile(u8filename, write_image, false, // jpg do not support alpha
|
||||
[&codec_param](stbi_write_func* func, void* context, int w, int h, int comp, const void* data) -> int {
|
||||
return stbi_write_jpg_to_func(func, context, w, h, comp, data, g_JPGDefaultQuality);
|
||||
});
|
||||
}
|
||||
|
||||
CKDWORD CKBitmapJPGHandler::SaveMemory(void* memory, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) {
|
||||
return StbSaveMemory(memory, write_image, false, // jpg do not support alpha
|
||||
[&codec_param](stbi_write_func* func, void* context, int w, int h, int comp, const void* data) -> int {
|
||||
return stbi_write_jpg_to_func(func, context, w, h, comp, data, g_JPGDefaultQuality);
|
||||
});
|
||||
}
|
||||
|
||||
bool CKBitmapJPGHandler::CanSaveAlpha() {
|
||||
return false;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region CKBitmapPNGHandler
|
||||
|
||||
// MARK: this GUID is gotten from Virtools 3.5 Plugins.
|
||||
static const CKBitmapProperties g_PNGProperties(CKGUID(0x02D45C7Bu, 0x4AAC16ECu), "png");
|
||||
// MARK: this is compress level gotten from default value of virtools.
|
||||
constexpr int g_PNGDefaultCompressLevel = 3;
|
||||
|
||||
/**
|
||||
* @brief A helper function to get stride parameter passed to png writer.
|
||||
* @param width[in] The width given by general stb writer wrapper.
|
||||
* @param comp[in] The comp given by general stb writer wrapper.
|
||||
* @return The stride data passed to real stb writer.
|
||||
*/
|
||||
static int StbPngStrideGetter(int width, int comp) {
|
||||
return width * comp;
|
||||
}
|
||||
|
||||
CKBitmapPNGHandler::CKBitmapPNGHandler() :
|
||||
CKBitmapHandler() {}
|
||||
|
||||
CKBitmapPNGHandler::~CKBitmapPNGHandler() {}
|
||||
|
||||
const CKBitmapProperties& CKBitmapPNGHandler::GetBitmapDefaultProperties() {
|
||||
return g_PNGProperties;
|
||||
}
|
||||
|
||||
bool CKBitmapPNGHandler::ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) {
|
||||
return StbReadFile(u8filename, read_image);
|
||||
}
|
||||
|
||||
bool CKBitmapPNGHandler::ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) {
|
||||
return StbReadMemory(memory, size, read_image);
|
||||
}
|
||||
|
||||
bool CKBitmapPNGHandler::SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) {
|
||||
return StbSaveFile(u8filename, write_image, false, // png support alpha
|
||||
[&codec_param](stbi_write_func* func, void* context, int w, int h, int comp, const void* data) -> int {
|
||||
// set default compress level
|
||||
stbi_write_png_compression_level = g_PNGDefaultCompressLevel;
|
||||
// write data
|
||||
return stbi_write_png_to_func(func, context, w, h, comp, data, StbPngStrideGetter(w, comp));
|
||||
});
|
||||
}
|
||||
|
||||
CKDWORD CKBitmapPNGHandler::SaveMemory(void* memory, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) {
|
||||
return StbSaveMemory(memory, write_image, false, // png support alpha
|
||||
[&codec_param](stbi_write_func* func, void* context, int w, int h, int comp, const void* data) -> int {
|
||||
stbi_write_png_compression_level = g_PNGDefaultCompressLevel;
|
||||
return stbi_write_png_to_func(func, context, w, h, comp, data, StbPngStrideGetter(w, comp));
|
||||
});
|
||||
}
|
||||
|
||||
bool CKBitmapPNGHandler::CanSaveAlpha() {
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region General Getter Freer
|
||||
|
||||
static CKBitmapHandler* FindHandlerByExt(const CKFileExtension& ext) {
|
||||
if (ext == g_BMPProperties.m_Ext) return new CKBitmapBMPHandler();
|
||||
if (ext == g_TGAProperties.m_Ext) return new CKBitmapTGAHandler();
|
||||
if (ext == g_JPGProperties.m_Ext) return new CKBitmapJPGHandler();
|
||||
if (ext == g_PNGProperties.m_Ext) return new CKBitmapPNGHandler();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static CKBitmapHandler* FindHandlerByGuid(const CKGUID& guid) {
|
||||
if (guid == g_BMPProperties.m_ReaderGuid) return new CKBitmapBMPHandler();
|
||||
if (guid == g_TGAProperties.m_ReaderGuid) return new CKBitmapTGAHandler();
|
||||
if (guid == g_JPGProperties.m_ReaderGuid) return new CKBitmapJPGHandler();
|
||||
if (guid == g_PNGProperties.m_ReaderGuid) return new CKBitmapPNGHandler();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -129,5 +129,37 @@ namespace LibCmo::CK2::DataHandlers {
|
||||
virtual bool CanSaveAlpha() override;
|
||||
|
||||
};
|
||||
|
||||
class CKBitmapJPGHandler : public CKBitmapHandler {
|
||||
public:
|
||||
CKBitmapJPGHandler();
|
||||
virtual ~CKBitmapJPGHandler();
|
||||
LIBCMO_DISABLE_COPY_MOVE(CKBitmapJPGHandler);
|
||||
|
||||
static const CKBitmapProperties& GetBitmapDefaultProperties();
|
||||
|
||||
virtual bool ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) override;
|
||||
virtual bool ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) override;
|
||||
virtual bool SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) override;
|
||||
virtual CKDWORD SaveMemory(void* memory, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) override;
|
||||
virtual bool CanSaveAlpha() override;
|
||||
|
||||
};
|
||||
|
||||
class CKBitmapPNGHandler : public CKBitmapHandler {
|
||||
public:
|
||||
CKBitmapPNGHandler();
|
||||
virtual ~CKBitmapPNGHandler();
|
||||
LIBCMO_DISABLE_COPY_MOVE(CKBitmapPNGHandler);
|
||||
|
||||
static const CKBitmapProperties& GetBitmapDefaultProperties();
|
||||
|
||||
virtual bool ReadFile(CKSTRING u8filename, VxMath::VxImageDescEx* read_image) override;
|
||||
virtual bool ReadMemory(const void* memory, CKDWORD size, VxMath::VxImageDescEx* read_image) override;
|
||||
virtual bool SaveFile(CKSTRING u8filename, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) override;
|
||||
virtual CKDWORD SaveMemory(void* memory, const VxMath::VxImageDescEx* write_image, const CKBitmapProperties& codec_param) override;
|
||||
virtual bool CanSaveAlpha() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
7
Redist/.gitignore
vendored
Normal file
7
Redist/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# Disable all file and folder
|
||||
/*
|
||||
/*/
|
||||
|
||||
# Only upload specific files
|
||||
!/.gitignore
|
||||
!/README.md
|
43
Redist/README.md
Normal file
43
Redist/README.md
Normal file
@ -0,0 +1,43 @@
|
||||
# LibCmo21 Redist
|
||||
|
||||
This folder is served for LibCmo21 distribution and this page will introduce how to distribute a LibCmo21.
|
||||
|
||||
In this article, I assume:
|
||||
* This distribution is served for Windows user.
|
||||
* All Linux will use this project by compiling it on themselves.
|
||||
* You are using Visual Studio under Windows, not CMake.
|
||||
* User will only need x64 architecture, not Win32 (x86).
|
||||
|
||||
## Common
|
||||
|
||||
1. Copy project `LICENSE` into folder.
|
||||
|
||||
## Unvirt
|
||||
|
||||
1. Compile project with `x64 | Release` profile.
|
||||
1. Create folder `Unvirt` and enter it.
|
||||
1. Copy generated `Unvirt.exe` and `Unvirt.pdb` into folder.
|
||||
1. Copy zlib binary `zlibwapi.dll` into folder.
|
||||
|
||||
## BMap
|
||||
|
||||
1. Compile project with `x64 | Release` profile.
|
||||
1. Create folder `BMap` and enter it.
|
||||
1. Copy generated `BMap.dll` and `BMap.pdb` into folder.
|
||||
1. Copy zlib binary `zlibwapi.dll` into folder.
|
||||
|
||||
## PyBMap
|
||||
|
||||
1. Compile project with `x64 | Release` profile.
|
||||
1. Create folder `PyBMap` and enter it.
|
||||
1. Copy all files ending with `.py` and located in folder `BMapBindings/PyBMap/PyBMap` into folder.
|
||||
1. Copy generated `BMap.dll` and `BMap.pdb` into folder.
|
||||
1. Copy zlib binary `zlibwapi.dll` into folder.
|
||||
|
||||
## BMapSharp
|
||||
|
||||
This project is not ready for release.
|
||||
|
||||
## Ending
|
||||
|
||||
1. Pack all files and folders except `.gitignore` and `README.md` in this folder.
|
3
Tools/.gitignore
vendored
3
Tools/.gitignore
vendored
@ -1,5 +1,4 @@
|
||||
# Result
|
||||
|
||||
# Ignore test used 3d Object
|
||||
*.bin
|
||||
*.obj
|
||||
*.mtl
|
||||
|
Loading…
Reference in New Issue
Block a user