Compare commits

..

No commits in common. "c03c80d938dbb989163a94b1707704afac73d624" and "92346dc81ead75d7f40d359f45e93f774f5901cf" have entirely different histories.

12 changed files with 21 additions and 219 deletions

14
.gitignore vendored
View File

@ -1,18 +1,13 @@
# -------------------- Personal -------------------- ## my ban
# Ignore all possible test used Virtools files
*.nmo *.nmo
*.cmo *.cmo
*.nms *.nms
*.vmo *.vmo
out/
# Ignore temporary folders temp/
/out/
/temp/
# -------------------- VSCode --------------------
.vscode/ .vscode/
# -------------------- CMake -------------------- ## CMake Banned
CMakeLists.txt.user CMakeLists.txt.user
CMakeCache.txt CMakeCache.txt
CMakeFiles CMakeFiles
@ -25,7 +20,6 @@ compile_commands.json
CTestTestfile.cmake CTestTestfile.cmake
_deps _deps
# -------------------- Visual Studio --------------------
## Ignore Visual Studio temporary files, build results, and ## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
## ##

View File

@ -1,18 +1,12 @@
# -------------------- Personal -------------------- # my ban
# Ignore VSCode
.vscode/ .vscode/
# Ignore binary BMap stuff
*.dll *.dll
*.pdb *.pdb
*.so *.so
*.dylib *.dylib
*.bin *.bin
# Ignore testbench file.
testbench.py testbench.py
# -------------------- Python --------------------
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]

View File

@ -1,4 +1,4 @@
import ctypes, os, sys, typing import ctypes, os, sys
#region Type Defines #region Type Defines
@ -89,15 +89,15 @@ except:
def is_bmap_available() -> bool: def is_bmap_available() -> bool:
return _g_BMapModule is not None return _g_BMapModule is not None
def _bmap_error_check(result: bool, func, args): def _bmap_error_check(result: bm_bool, func, args):
if not result: if not result:
raise BMapException("BMap operation failed.") raise BMapException("BMap operation failed.")
return result return result
def _create_bmap_func(fct_name: str, fct_params: list[typing.Any]) -> typing.Callable[..., bm_bool]: def _create_bmap_func(fct_name: str, fct_params: list[ctypes._SimpleCData]) -> ctypes._CFuncPtr:
if _g_BMapModule is None: return None if _g_BMapModule is None: return None
cache: typing.Callable[..., bm_bool] = getattr(_g_BMapModule, fct_name) cache: ctypes._CFuncPtr = getattr(_g_BMapModule, fct_name)
cache.argtypes = fct_params cache.argtypes = fct_params
cache.restype = bm_bool cache.restype = bm_bool
cache.errcheck = _bmap_error_check cache.errcheck = _bmap_error_check

View File

@ -188,7 +188,7 @@ class VX_PIXELFORMAT(enum.IntEnum):
"""! """!
Pixel format types. 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_ARGB8888 = 1 ##< 32-bit ARGB pixel format with alpha
_32_RGB888 = 2 ##< 32-bit RGB pixel format without alpha _32_RGB888 = 2 ##< 32-bit RGB pixel format without alpha
_24_RGB888 = 3 ##< 24-bit RGB pixel format _24_RGB888 = 3 ##< 24-bit RGB pixel format

View File

@ -1,5 +1,6 @@
# PyBMap # 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 (`testbench.py` is explicitly excluded by gitignore file). 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 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`.

View File

@ -1,4 +1,4 @@
import ctypes, os, sys, typing import ctypes, os, sys
#region Type Defines #region Type Defines
@ -89,15 +89,15 @@ except:
def is_bmap_available() -> bool: def is_bmap_available() -> bool:
return _g_BMapModule is not None return _g_BMapModule is not None
def _bmap_error_check(result: bool, func, args): def _bmap_error_check(result: bm_bool, func, args):
if not result: if not result:
raise BMapException("BMap operation failed.") raise BMapException("BMap operation failed.")
return result return result
def _create_bmap_func(fct_name: str, fct_params: list[typing.Any]) -> typing.Callable[..., bm_bool]: def _create_bmap_func(fct_name: str, fct_params: list[ctypes._SimpleCData]) -> ctypes._CFuncPtr:
if _g_BMapModule is None: return None if _g_BMapModule is None: return None
cache: typing.Callable[..., bm_bool] = getattr(_g_BMapModule, fct_name) cache: ctypes._CFuncPtr = getattr(_g_BMapModule, fct_name)
cache.argtypes = fct_params cache.argtypes = fct_params
cache.restype = bm_bool cache.restype = bm_bool
cache.errcheck = _bmap_error_check cache.errcheck = _bmap_error_check

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2022-2024 yyc12345 Copyright (c) 2022-2023 yyc12345
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -369,123 +369,17 @@ namespace LibCmo::CK2::DataHandlers {
#pragma endregion #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 #pragma region General Getter Freer
static CKBitmapHandler* FindHandlerByExt(const CKFileExtension& ext) { static CKBitmapHandler* FindHandlerByExt(const CKFileExtension& ext) {
if (ext == g_BMPProperties.m_Ext) return new CKBitmapBMPHandler(); if (ext == g_BMPProperties.m_Ext) return new CKBitmapBMPHandler();
if (ext == g_TGAProperties.m_Ext) return new CKBitmapTGAHandler(); 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; return nullptr;
} }
static CKBitmapHandler* FindHandlerByGuid(const CKGUID& guid) { static CKBitmapHandler* FindHandlerByGuid(const CKGUID& guid) {
if (guid == g_BMPProperties.m_ReaderGuid) return new CKBitmapBMPHandler(); if (guid == g_BMPProperties.m_ReaderGuid) return new CKBitmapBMPHandler();
if (guid == g_TGAProperties.m_ReaderGuid) return new CKBitmapTGAHandler(); 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; return nullptr;
} }

View File

@ -130,36 +130,4 @@ namespace LibCmo::CK2::DataHandlers {
}; };
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
View File

@ -1,7 +0,0 @@
# Disable all file and folder
/*
/*/
# Only upload specific files
!/.gitignore
!/README.md

View File

@ -1,43 +0,0 @@
# 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
View File

@ -1,4 +1,5 @@
# Ignore test used 3d Object # Result
*.bin *.bin
*.obj *.obj
*.mtl *.mtl