Begin new lib structure
This commit is contained in:
parent
8ce721fd9c
commit
151769a2d3
3
.gitignore
vendored
3
.gitignore
vendored
@ -15,7 +15,8 @@
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
src/config.h
|
||||
RSPTerrainLib/src/config.h
|
||||
RSETerrain/src/config.h
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
|
111
CMakeLists.txt
111
CMakeLists.txt
@ -1,67 +1,78 @@
|
||||
# CMakeLists.txt
|
||||
|
||||
# Written by JackCarterSmith, 2021
|
||||
####################################################
|
||||
# Written by JackCarterSmith, 2022
|
||||
# This code is released under the RSE license.
|
||||
####################################################
|
||||
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
cmake_policy(VERSION 3.1)
|
||||
|
||||
# CMake requirement and general configuration
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
cmake_policy(VERSION 3.12)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
|
||||
|
||||
# define project
|
||||
#add_definitions(-DCONF_NO_GL)
|
||||
if(DEFINED ENV{CI})
|
||||
project(rse-texture VERSION 1.0.1.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C)
|
||||
set(RSE_TEX_NAME $ENV{CI_OUTPUT_NAME}-${PROJECT_VERSION})
|
||||
else()
|
||||
project(rse-texture VERSION 1.0.1 DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C)
|
||||
set(RSE_TEX_NAME RSE_Texture-${PROJECT_VERSION})
|
||||
if(DEFINED ENV{MS_COMPATIBLE})
|
||||
set(CMAKE_GNUtoMS ON) # Enable compatibility level to exported libraries
|
||||
endif()
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h @ONLY)
|
||||
|
||||
include(CheckIncludeFile)
|
||||
include(CheckCSourceCompiles)
|
||||
#include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
#conan_basic_setup()
|
||||
|
||||
# needed packages
|
||||
|
||||
find_package(ZLIB 1.2.11 EXACT REQUIRED)
|
||||
include_directories(${ZLIB_INCLUDE_DIR})
|
||||
find_package(PNG 1.6.37 EXACT REQUIRED)
|
||||
include_directories(${PNG_INCLUDE_DIR})
|
||||
|
||||
# define src/headers files
|
||||
|
||||
FILE(GLOB_RECURSE RSE_TEX_SRCS src/*.c)
|
||||
FILE(GLOB_RECURSE RSE_TEX_HRDS src/*.h)
|
||||
SOURCE_GROUP("Source Files" FILES ${RSE_TEX_SRCS})
|
||||
SOURCE_GROUP("Header Files" FILES ${RSE_TEX_HRDS})
|
||||
|
||||
# begin building RSE-Texture
|
||||
|
||||
#set(CMAKE_BUILD_TYPE Debug)
|
||||
#include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_executable(rse-texture ${RSE_TEX_SRCS} ${RSE_TEX_HRDS})
|
||||
#set_property(TARGET rse-texture PROPERTY C_STANDARD 99)
|
||||
set_target_properties(rse-texture PROPERTIES OUTPUT_NAME ${RSE_TEX_NAME})
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
#set_target_properties(rse-texture PROPERTIES PREFIX "lib")
|
||||
set_target_properties(rse-texture PROPERTIES IMPORT_PREFIX "lib")
|
||||
# Project definition
|
||||
if(DEFINED ENV{CI}) # Jenkins CI integration mode
|
||||
project(rse-texture VERSION $ENV{CI_VERSION}.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C)
|
||||
set(RSE_TEXTURE_NAME $ENV{CI_OUTPUT_NAME})
|
||||
else() # Standalone project mode, should not be used for release.
|
||||
project(rse-texture VERSION 2.0.0 DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C)
|
||||
set(RSE_TEXTURE_NAME RSETexture)
|
||||
endif()
|
||||
target_link_libraries(rse-texture ${ZLIB_LIBRARIES} ${PNG_LIBRARIES})
|
||||
set(RSP_TEXTURE_LIB_NAME RSPTexture${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR})
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
||||
|
||||
# add GPG signature command
|
||||
# Compilation option
|
||||
option(RSPTEXTURE_SHARED "Build shared lib" ON)
|
||||
|
||||
# Push compile infos to source
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSPTextureLib/src/config.h @ONLY)
|
||||
#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSETexture/src/config.h @ONLY)
|
||||
|
||||
|
||||
# The project is divided in two parts:
|
||||
# - RSPTextureLib is the parser library for textures data, it's take HMT file as input and output extracted datas.
|
||||
# It is intended to be used by others apps like rendering engine or others.
|
||||
# - RSETexture is the standalone application of the library, take HMT file in argument and output PNG file.
|
||||
# Artists or users can directly use this program to retrieve data in common datas format.
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
||||
add_subdirectory(RSPTextureLib)
|
||||
add_subdirectory(RSETexture)
|
||||
|
||||
|
||||
# GPG signature custom command
|
||||
#add_custom_command(
|
||||
# OUTPUT ""
|
||||
# COMMAND gpg --batch --detach-sign
|
||||
# -o ${RSE_TEX_NAME}_${CI_SYS_TARGET}.gpg
|
||||
# ${RSE_TEX_NAME}
|
||||
# DEPENDS ${RSE_TEX_NAME}
|
||||
# -o ${RSE_MOD_NAME}_${CI_SYS_TARGET}.gpg
|
||||
# ${RSE_MOD_NAME}
|
||||
# DEPENDS ${RSE_MOD_NAME}
|
||||
# VERBATIM
|
||||
#)
|
||||
|
||||
# install executable
|
||||
install(TARGETS rse-texture
|
||||
RUNTIME DESTINATION bin
|
||||
|
||||
# Install project executable
|
||||
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
|
||||
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
|
||||
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
|
||||
if(RSPTEXTURE_SHARED)
|
||||
set(RSE_TEXTURE_TARGETS_LIST rse-texture rsp-texture-lib rsp-texture-libstatic)
|
||||
else()
|
||||
set(RSE_TEXTURE_TARGETS_LIST rse-texture rsp-texture-libstatic)
|
||||
endif()
|
||||
install(TARGETS ${RSE_TEXTURE_TARGETS_LIST}
|
||||
RUNTIME DESTINATION ${INSTALL_BIN_DIR}
|
||||
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
|
||||
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
|
||||
)
|
||||
# Install library includes
|
||||
install(FILES ${RSP_PUBLIC_HRDS} DESTINATION ${INSTALL_INC_DIR})
|
||||
# Install dependancies
|
||||
install(FILES ${PROJECT_BINARY_DIR}/bin/libpng16.dll
|
||||
DESTINATION ${INSTALL_BIN_DIR})
|
||||
|
152
Jenkinsfile
vendored
152
Jenkinsfile
vendored
@ -1,77 +1,79 @@
|
||||
pipeline {
|
||||
agent any
|
||||
options {
|
||||
skipDefaultCheckout(true)
|
||||
}
|
||||
environment {
|
||||
CI_OUTPUT_NAME = "RSE_Texture"
|
||||
CI_BUILD_NUMBER = "$BUILD_NUMBER"
|
||||
}
|
||||
stages {
|
||||
stage('Prepare') {
|
||||
steps {
|
||||
cleanWs()
|
||||
rtConanClient(id: "conan", userHome: "/home/jackcartersmith")
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
parallel(
|
||||
linux: {
|
||||
dir("linux") {
|
||||
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Texture'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]])
|
||||
dir("build") {
|
||||
rtConanRun(clientId: "conan", command: "install .. --build missing")
|
||||
}
|
||||
cmakeBuild buildDir: 'build', installation: 'latest', steps: [[args: 'all']]
|
||||
}
|
||||
},
|
||||
windows: {
|
||||
dir("windows") {
|
||||
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Texture'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]])
|
||||
dir("build") {
|
||||
rtConanRun(clientId: "conan", command: "install .. --profile windows --build missing")
|
||||
}
|
||||
cmakeBuild buildDir: 'build', cmakeArgs: '-DGNU_HOST=x86_64-w64-mingw32 -DCMAKE_TOOLCHAIN_FILE=../mingw_cross_toolchain.cmake', installation: 'latest', steps: [[args: 'all']]
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
dir("zip_linux") {
|
||||
sh 'cp ../linux/build/${CI_OUTPUT_NAME}-1.0.1.${BUILD_NUMBER}* .'
|
||||
}
|
||||
dir("zip_win") {
|
||||
sh 'cp ../windows/build/${CI_OUTPUT_NAME}-1.0.1.${BUILD_NUMBER}* ../windows/build/*.dll .'
|
||||
}
|
||||
zip archive: false, dir: 'zip_linux', exclude: '', glob: '', zipFile: 'x64.zip'
|
||||
sh 'mv x64.zip ${CI_OUTPUT_NAME}-1.0.1.${BUILD_NUMBER}_x64.zip'
|
||||
zip archive: false, dir: 'zip_win', exclude: '', glob: '', zipFile: 'mingw64.zip'
|
||||
sh 'mv mingw64.zip ${CI_OUTPUT_NAME}-1.0.1.${BUILD_NUMBER}_mingw64.zip'
|
||||
archiveArtifacts(artifacts: '*.zip')
|
||||
fingerprint(targets: '*.zip')
|
||||
}
|
||||
}
|
||||
stage('Sign') {
|
||||
steps {
|
||||
sh 'ls -l'
|
||||
sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}-1.0.1.${BUILD_NUMBER}_x64.zip.gpg ${CI_OUTPUT_NAME}-1.0.1.${BUILD_NUMBER}_x64.zip'
|
||||
sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}-1.0.1.${BUILD_NUMBER}_mingw64.zip.gpg ${CI_OUTPUT_NAME}-1.0.1.${BUILD_NUMBER}_mingw64.zip'
|
||||
archiveArtifacts(artifacts: '*.gpg')
|
||||
fingerprint(targets: '*.gpg')
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
post {
|
||||
always {
|
||||
cleanWs(cleanWhenNotBuilt: false,
|
||||
deleteDirs: true,
|
||||
disableDeferredWipeout: true,
|
||||
notFailBuild: true)
|
||||
}
|
||||
}
|
||||
*/
|
||||
agent any
|
||||
options {
|
||||
skipDefaultCheckout(true)
|
||||
}
|
||||
environment {
|
||||
CI_OUTPUT_NAME = "RSETexture"
|
||||
CI_VERSION = "2.0.0"
|
||||
CI_BUILD_NUMBER = "$BUILD_NUMBER"
|
||||
}
|
||||
stages {
|
||||
stage('Prepare') {
|
||||
steps {
|
||||
cleanWs()
|
||||
rtConanClient(id: "conan", userHome: "/home/jackcartersmith")
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
parallel(
|
||||
linux: {
|
||||
dir("linux") {
|
||||
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Texture'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]])
|
||||
sh 'git submodule update --init --recursive'
|
||||
dir("build") {
|
||||
rtConanRun(clientId: "conan", command: "install .. --build=missing")
|
||||
}
|
||||
cmakeBuild buildDir: 'build', installation: 'latest', steps: [[args: 'all']]
|
||||
}
|
||||
},
|
||||
windows: {
|
||||
dir("windows") {
|
||||
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Terrain'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]])
|
||||
sh 'git submodule update --init --recursive'
|
||||
dir("build") {
|
||||
rtConanRun(clientId: "conan", command: "install .. --profile=windows --build=missing")
|
||||
}
|
||||
cmakeBuild buildDir: 'build', cmakeArgs: '-DGNU_HOST=x86_64-w64-mingw32 -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_cross_toolchain.cmake', installation: 'latest', steps: [[args: 'all']]
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
dir("zip_linux") {
|
||||
sh 'cp -R ../linux/build/bin ../linux/build/lib ../linux/RSPTextureLib/include .'
|
||||
}
|
||||
dir("zip_win") {
|
||||
sh 'cp -R ../windows/build/bin ../windows/build/lib ../windows/RSPTextureLib/include .'
|
||||
}
|
||||
zip archive: false, dir: 'zip_linux', exclude: '', glob: '', zipFile: 'linux_x64.zip'
|
||||
sh 'mv linux_x64.zip ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip'
|
||||
zip archive: false, dir: 'zip_win', exclude: '', glob: '', zipFile: 'mingw64.zip'
|
||||
sh 'mv mingw64.zip ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip'
|
||||
archiveArtifacts(artifacts: '*.zip')
|
||||
fingerprint(targets: '*.zip')
|
||||
}
|
||||
}
|
||||
stage('Sign') {
|
||||
steps {
|
||||
sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip.gpg ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip'
|
||||
sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip.gpg ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip'
|
||||
archiveArtifacts(artifacts: '*.gpg')
|
||||
fingerprint(targets: '*.gpg')
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
post {
|
||||
always {
|
||||
cleanWs(cleanWhenNotBuilt: false,
|
||||
deleteDirs: true,
|
||||
disableDeferredWipeout: true,
|
||||
notFailBuild: true)
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
21
LICENSE-zlib
21
LICENSE-zlib
@ -1,21 +0,0 @@
|
||||
|
||||
Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Jean-loup Gailly Mark Adler
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
13
README.md
13
README.md
@ -7,7 +7,7 @@ The collection consist of few independants modules, each of them deals with spec
|
||||
|
||||
All modules are independants. This is the **'TEXTURE'** module.
|
||||
|
||||
:exclamation: **Master branch is ugly for now and should not be used, please take only released versions.** :exclamation:
|
||||
[](https://ci.jcsmith.fr/job/JCS-Prod/job/RSE-Texture/job/master/)
|
||||
|
||||
## TEXTURE MODULE
|
||||
|
||||
@ -20,9 +20,13 @@ This module can do:
|
||||
- Manage transparent textures,
|
||||
- Fixed some errored RGB color encoding.
|
||||
|
||||
## TODO
|
||||
|
||||
- Discover all last unknowns fields, etc.
|
||||
|
||||
### Using
|
||||
|
||||
`RSE-Texture_"version" [options] <hmt files...>` or you can simply drag&drop hmt files on it.
|
||||
`RSETexture [options] <hmt files...>` or you can simply drag&drop hmt files on it.
|
||||
|
||||
A futur main program can extract all HMT files directly from DAT file.
|
||||
Due to issue with copyrights, I can't provide samples... You need to extract HMT files yourself.
|
||||
@ -32,20 +36,19 @@ Due to issue with copyrights, I can't provide samples... You need to extract HMT
|
||||
### Options
|
||||
|
||||
- -h Print this message
|
||||
- -v Activate verbose output
|
||||
- -v,-vv Activate verbose/debug output mode respectively
|
||||
- -no-subdir Extract textures directly inside current folder
|
||||
|
||||
### Dependencies
|
||||
|
||||
Necessary libs (provided only in windows release) for running and for compiling.
|
||||
|
||||
- zlib (1.2.11)
|
||||
- libpng (1.6.37)
|
||||
|
||||
### Compiling
|
||||
|
||||
You can compile on both Windows (MinGW) or native Linux system thanks to CMake, you only need to adjust your dependencies on Windows or use Conan packages manager (https://conan.io).
|
||||
zlib-dev (zlib1g-dev) and libpng16-dev distrib packages can be used on debian/ubuntu.
|
||||
libpng16-dev distrib package can be used on debian/ubuntu.
|
||||
|
||||
To compile, just clone and launch cmake:
|
||||
|
||||
|
43
RSETexture/CMakeLists.txt
Normal file
43
RSETexture/CMakeLists.txt
Normal file
@ -0,0 +1,43 @@
|
||||
# CMakeLists.txt
|
||||
|
||||
####################################################
|
||||
# Written by JackCarterSmith, 2022
|
||||
# This code is released under the RSE license.
|
||||
####################################################
|
||||
|
||||
|
||||
# General configuration
|
||||
include(CheckIncludeFile)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
# Import needed packages and references their include path
|
||||
find_package(PNG 1.6.37 REQUIRED)
|
||||
include_directories(${PNG_INCLUDE_DIR})
|
||||
|
||||
|
||||
# Define src/headers files
|
||||
file(GLOB_RECURSE RSE_TEXTURE_SOURCES ./src/*.c)
|
||||
source_group("Source Files" FILES ${RSE_TEXTURE_SOURCES})
|
||||
|
||||
|
||||
# Building instructions for RSE-Texture
|
||||
if(DEFINED ENV{CI})
|
||||
set(CMAKE_BUILD_TYPE RELEASE)
|
||||
endif()
|
||||
|
||||
|
||||
# Declare standalone application
|
||||
add_executable(rse-texture ${RSE_TEXTURE_SOURCES})
|
||||
set_property(TARGET rse-texture PROPERTY C_STANDARD 90)
|
||||
|
||||
#target_include_directories(rse-texture PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
set_target_properties(rse-texture PROPERTIES OUTPUT_NAME ${RSE_TEXTURE_NAME})
|
||||
|
||||
# Link externals libraries to the linker
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
set_target_properties(rse-texture PROPERTIES IMPORT_PREFIX "lib")
|
||||
target_link_libraries(rse-texture PRIVATE rsp-texture-libstatic ${PNG_LIBRARIES})
|
||||
else()
|
||||
target_link_libraries(rse-texture PRIVATE rsp-texture-libstatic ${PNG_LIBRARIES})
|
||||
endif()
|
67
RSPTextureLib/CMakeLists.txt
Normal file
67
RSPTextureLib/CMakeLists.txt
Normal file
@ -0,0 +1,67 @@
|
||||
# CMakeLists.txt
|
||||
|
||||
####################################################
|
||||
# Written by JackCarterSmith, 2022
|
||||
# This code is released under the RSE license.
|
||||
####################################################
|
||||
|
||||
|
||||
# General library configuration
|
||||
if(DEFINED ENV{MS_COMPATIBLE})
|
||||
set(CMAKE_GNUtoMS ON) # Enable compatibility level to exported libraries
|
||||
endif()
|
||||
|
||||
include(CheckIncludeFile)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
|
||||
# Define src/headers files
|
||||
file(GLOB_RECURSE RSP_TEXTURE_SOURCES ./src/*.c)
|
||||
source_group("Source Files" FILES ${RSP_TEXTURE_SOURCES})
|
||||
file(GLOB RSP_PUBLIC_HRDS ./include/*.h)
|
||||
set(RSP_PUBLIC_HRDS ${RSP_PUBLIC_HRDS} PARENT_SCOPE)
|
||||
|
||||
|
||||
# Building instructions for RSP-Texture library
|
||||
if(DEFINED ENV{CI})
|
||||
set(CMAKE_BUILD_TYPE RELEASE)
|
||||
endif()
|
||||
|
||||
|
||||
# Declare the shared library instance
|
||||
if(RSPTEXTURE_SHARED)
|
||||
add_library(rsp-texture-lib SHARED ${RSP_TEXTURE_SOURCES})
|
||||
set_property(TARGET rsp-texture-lib PROPERTY C_STANDARD 90)
|
||||
|
||||
target_include_directories(rsp-texture-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
set_target_properties(rsp-texture-lib PROPERTIES OUTPUT_NAME ${RSP_TEXTURE_LIB_NAME})
|
||||
set_target_properties(rsp-texture-lib PROPERTIES DEFINE_SYMBOL RSPTEXTURE_DLL)
|
||||
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
set_target_properties(rsp-texture-lib PROPERTIES PREFIX "lib")
|
||||
set_target_properties(rsp-texture-lib PROPERTIES IMPORT_PREFIX "lib")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# Declare the static library instance
|
||||
add_library(rsp-texture-libstatic STATIC ${RSP_TEXTURE_SOURCES})
|
||||
set_property(TARGET rsp-texture-libstatic PROPERTY C_STANDARD 90)
|
||||
|
||||
target_include_directories(rsp-texture-libstatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
if(NOT MSVC)
|
||||
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}")
|
||||
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
else()
|
||||
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}_static")
|
||||
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
set_target_properties(rsp-texture-libstatic PROPERTIES PREFIX "lib")
|
||||
set_target_properties(rsp-texture-libstatic PROPERTIES IMPORT_PREFIX "lib")
|
||||
endif()
|
101
RSPTextureLib/include/RSPTexture.h
Normal file
101
RSPTextureLib/include/RSPTexture.h
Normal file
@ -0,0 +1,101 @@
|
||||
/**
|
||||
* @file RSPTexture.h
|
||||
* @date 25/08/2022
|
||||
* @author JackCarterSmith
|
||||
* @copyright GPL-v3.0
|
||||
* @brief Rogue Squadron Parser texture library, used to decode HMT datas
|
||||
* from original game file and access them through public interface.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "RSPTexture_datatypes.h"
|
||||
|
||||
#ifndef RSPTEXTURELIB_H_
|
||||
#define RSPTEXTURELIB_H_
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# define RSPTEXTURE_ABI_EXPORT __declspec(dllexport)
|
||||
# define RSPTEXTURE_ABI_IMPORT __declspec(dllimport)
|
||||
#elif __GNUC__ >= 4
|
||||
# define RSPTEXTURE_ABI_EXPORT __attribute__ ((visibility("default")))
|
||||
# define RSPTEXTURE_ABI_IMPORT __attribute__ ((visibility("default")))
|
||||
#else
|
||||
# define RSPTEXTURE_ABI_EXPORT
|
||||
# define RSPTEXTURE_ABI_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(RSPTEXTURE_DLL)
|
||||
# if defined(WIN32)
|
||||
# if defined(RSPTEXTURE_DLLBUILD)
|
||||
# define RSPTEXTURE_EXTERN extern RSPTEXTURE_ABI_EXPORT
|
||||
# else
|
||||
# define RSPTEXTURE_EXTERN extern RSPTEXTURE_ABI_IMPORT
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef RSPTEXTURE_EXTERN
|
||||
# define RSPTEXTURE_EXTERN extern
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Library's functions declaration
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* @brief Get the current library version.
|
||||
* @return Char array of the version, escape char included.
|
||||
*/
|
||||
RSPTEXTURE_EXTERN char* RSPTexture_getVersion( void );
|
||||
|
||||
/**
|
||||
* @brief Run texture parser for the specified file in file system.
|
||||
* @details Texture library can process HMT file from file system. It's a easy
|
||||
* approach using this library for debugging purpose.
|
||||
*
|
||||
* @param[out] hmtStruct HMT texture structure to be filled with parsed datas.
|
||||
* @param[in] filePath Path to the HMT file in system.
|
||||
* @param[in] params Parser options. See RSPTEXTURE_PARAMETERS.
|
||||
*
|
||||
* @return Error status, return RSPLIB_SUCCESS in nominal case.
|
||||
*/
|
||||
RSPTEXTURE_EXTERN unsigned short RSPTexture_processHMTFile(
|
||||
T_RSPTEXTURE_HMT* hmtStruct, const char* const filePath,
|
||||
const RSPTEXTURE_PARAMETERS params
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Run texture parser for the specified file in memory.
|
||||
* @details Texture library can process HMT file directly stored in RAM memory,
|
||||
* you must load the file beforehand through a malloc/memcpy call.
|
||||
* @warning No controls routines are implemented to verify file length!
|
||||
*
|
||||
* @param[out] hmtStruct HMT texture structure to be filled with parsed datas.
|
||||
* @param[in] memFilePtr Pointer to the beginning of the file in memory.
|
||||
* @param[in] memFileSize Size of the file in bytes.
|
||||
* @param[in] params Parser options. See RSPTEXTURE_PARAMETERS.
|
||||
*
|
||||
* @return Error status, return RSPLIB_SUCCESS in nominal case.
|
||||
*/
|
||||
RSPTEXTURE_EXTERN unsigned short RSPTexture_processHMTFileMemory(
|
||||
T_RSPTEXTURE_HMT* hmtStruct, const void* const memFilePtr, const long memFileSize,
|
||||
const RSPTEXTURE_PARAMETERS params
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Clean HMT object and it's childrens from memory.
|
||||
* @param[in] hmtStruct Pointer to data to be cleaned up.
|
||||
*/
|
||||
RSPTEXTURE_EXTERN void RSPTexture_freeHMT( T_RSPTEXTURE_HMT* hmtStruct );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RSPTEXTURELIB_H_ */
|
88
RSPTextureLib/include/RSPTexture_datatypes.h
Normal file
88
RSPTextureLib/include/RSPTexture_datatypes.h
Normal file
@ -0,0 +1,88 @@
|
||||
/**
|
||||
* @file RSPTexture_datatypes.h
|
||||
* @date 25/08/2022
|
||||
* @author JackCarterSmith
|
||||
* @copyright GPL-v3.0
|
||||
* @brief RSP Texture workflow structures definitions
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RSPTEXTURELIB_DATATYPES_H_
|
||||
#define RSPTEXTURELIB_DATATYPES_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Configuration structure
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef union u_rsptexture_parameters {
|
||||
struct {
|
||||
unsigned char verbose_mode:1; //!< Output simple details about ID and other "light" things.
|
||||
unsigned char debug_mode:1; //!< Output all values of faces, indices and vertices and others "heavy" things.
|
||||
unsigned char god_mode:1; //!< Dev only. Output experimental values.
|
||||
|
||||
unsigned char reserved0:5; //!< For future use.
|
||||
};
|
||||
unsigned char raw; //!< Raw options access for bit-masking or memory copy/compare.
|
||||
} RSPTEXTURE_PARAMETERS ;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Lib's structure definitions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MEMFILE
|
||||
typedef char* MEMFILE;
|
||||
#endif
|
||||
#ifndef HEIGHTMAP_T
|
||||
typedef unsigned char** HEIGHTMAP_T;
|
||||
#endif
|
||||
#ifndef T_VECTOR3
|
||||
typedef struct vector3 { float x,y,z; } T_VECTOR3;
|
||||
#endif
|
||||
#ifndef T_VERTEX
|
||||
typedef T_VECTOR3 T_VERTEX;
|
||||
#endif
|
||||
|
||||
typedef struct rspterrain_heightmap {
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
|
||||
HEIGHTMAP_T heightmap;
|
||||
} T_RSPTERRAIN_HEIGHTMAP ;
|
||||
|
||||
typedef struct rspterrain_mesh {
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
|
||||
unsigned int vertices_count;
|
||||
T_VERTEX* verticesmap;
|
||||
} T_RSPTERRAIN_MESH ;
|
||||
|
||||
typedef struct rspterrain_tile {
|
||||
unsigned short texmap_id;
|
||||
|
||||
unsigned char low_height;
|
||||
unsigned char high_height;
|
||||
|
||||
unsigned char height_values[5][5];
|
||||
} T_RSPTERRAIN_TILE;
|
||||
|
||||
typedef struct rspterrain_obj {
|
||||
unsigned short width;
|
||||
unsigned short height;
|
||||
|
||||
float height_scale;
|
||||
|
||||
unsigned short tiles_count;
|
||||
T_RSPTERRAIN_TILE* tilesmap;
|
||||
} T_RSPTERRAIN_HMP ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RSPTEXTURELIB_DATATYPES_H_ */
|
45
RSPTextureLib/include/RSPTexture_errordefs.h
Normal file
45
RSPTextureLib/include/RSPTexture_errordefs.h
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @file RSPTerrain_errordefs.h
|
||||
* @date 22/08/2022
|
||||
* @author JackCarterSmith
|
||||
* @copyright GPL-v3.0
|
||||
* @brief Errors type definition file. Used mostly by methods in this project.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#ifndef RSPLIB_ERRORS_H_
|
||||
#define RSPLIB_ERRORS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Errors types definitions
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef NO_ERROR
|
||||
#define NO_ERROR 0 // In case of dual declaration by GCC
|
||||
#endif
|
||||
#define RSPLIB_SUCCESS NO_ERROR //!< All is running good!
|
||||
|
||||
#define RSPLIB_ERROR_GENERIC 1 //!< Misuse of the program
|
||||
#define RSPLIB_ERROR_MEMORY 2 //!< Memory de/allocation failure
|
||||
#define RSPLIB_ERROR_IO 3 //!< File system access failure
|
||||
#define RSPLIB_ERROR_PROCESS 4 //!< Internal processing failure
|
||||
|
||||
#define RSPLIB_ERROR_ARGS_NULL 16 //!< Method not NULL input expected
|
||||
#define RSPLIB_ERROR_ARGS_RANGE 17 //!< Method input out of expected range
|
||||
|
||||
#define RSPLIB_ERROR_MOD_DISABLED 64 //!< A necessary module hasn't been activated during compilation time
|
||||
|
||||
#define RSPLIB_ERROR_REALITY_BRK -1 //!< This error can only appear in alternate reality
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RSPLIB_ERRORS_H_ */
|
40
RSPTextureLib/src/RSPTexture.c
Normal file
40
RSPTextureLib/src/RSPTexture.c
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @file RSPTexture.c
|
||||
* @date 25/08/2022
|
||||
* @author JackCarterSmith
|
||||
* @copyright GPL-v3.0
|
||||
* @brief HMT textures datas parser and export to PNG format.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
#include "RSPTexture_errordefs.h"
|
||||
#include "RSPTexture_datatypes.h"
|
||||
#include "hmt_parser.h"
|
||||
#include "data_builders.h"
|
||||
#include "RSPTexture.h"
|
||||
|
||||
|
||||
inline char* RSPTexture_getVersion( void ) {
|
||||
return PRG_VERSION;
|
||||
}
|
||||
|
||||
unsigned short RSPTexture_processHMPFile( T_RSPTEXTURE_HMT* hmtStruct, const char* const filePath,
|
||||
const RSPTEXTURE_PARAMETERS params ) {
|
||||
|
||||
if ( hmtStruct == NULL || filePath == NULL ) return RSPLIB_ERROR_ARGS_NULL;
|
||||
|
||||
return RSP_TextureLib_ParseHMTFile(filePath, hmtStruct, ¶ms);
|
||||
}
|
||||
|
||||
unsigned short RSPTexture_processHMPFileMemory( T_RSPTEXTURE_HMT* hmtStruct, const void* const memFilePtr,
|
||||
const long memFileSize, const RSPTEXTURE_PARAMETERS params ) {
|
||||
|
||||
if ( hmtStruct == NULL || memFilePtr == NULL ) return RSPLIB_ERROR_ARGS_NULL;
|
||||
|
||||
return RSP_TextureLib_ParseHMTMemFile((MEMFILE)memFilePtr, hmtStruct, ¶ms);
|
||||
}
|
||||
|
152
RSPTextureLib/src/RS_images.c
Normal file
152
RSPTextureLib/src/RS_images.c
Normal file
@ -0,0 +1,152 @@
|
||||
#include "RS_images.h"
|
||||
|
||||
|
||||
//extern int _options; // Global options settings variable
|
||||
|
||||
void decodePixels(RS_IMAGE *img) {
|
||||
int size;
|
||||
|
||||
//img->pixels = NULL;
|
||||
if (!(img->type_ == 0 ||
|
||||
img->type_ == 1 ||
|
||||
img->type_ == 2 ||
|
||||
img->type_ == 3 ||
|
||||
img->type_ == 4 ||
|
||||
img->type_ == 5)) return;
|
||||
|
||||
size = img->height * img->width;
|
||||
switch (img->sampleBits) {
|
||||
case 32:
|
||||
img->pixels = calloc(1, size * sizeof(PIXEL_A));
|
||||
memcpy(img->pixels, img->samples, size * sizeof(PIXEL_A));
|
||||
break;
|
||||
case 4:
|
||||
img->pixels = calloc(1, size * sizeof(PIXEL_A));
|
||||
if (img->paletteEntries == 0) {
|
||||
convert4bitsGreyTo32bitsRGBA(img->samples, img->pixels, size, &(img->alpha_color));
|
||||
} else if (img->paletteEntries == 16) {
|
||||
convert4bitsTo32bitsRGBA(img->samples, img->pixels, size, img->palette, &(img->alpha_color));
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if (img->paletteEntries == 0) {
|
||||
img->pixels = calloc(1, size);
|
||||
memcpy(img->pixels, img->samples, size);
|
||||
} else if (img->paletteEntries == 256) {
|
||||
img->pixels = calloc(1, size * sizeof(PIXEL_A));
|
||||
convert8bitsTo32bitsRGBA(img->samples, img->pixels, size, img->palette, &(img->alpha_color));
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
img->pixels = calloc(1, size);
|
||||
useOddBytes(img->samples, img->pixels, size);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int isTransparentColor(PIXEL_A *testColor, PIXEL_A *transp_color) {
|
||||
if (transp_color == NULL || testColor == NULL) return -2;
|
||||
|
||||
if (!(testColor->_red == transp_color->_red)) return -1;
|
||||
if (!(testColor->_green == transp_color->_green)) return -1;
|
||||
if (!(testColor->_blue == transp_color->_blue)) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void convert4bitsGreyTo32bitsRGBA(unsigned char *samples_tab, PIXEL_A *pixels_tab, int sampling, PIXEL_A *transp_color) {
|
||||
int i;
|
||||
unsigned char v;
|
||||
|
||||
for(i=0; i<div(sampling,2).quot; i++) {
|
||||
v = samples_tab[i];
|
||||
pixels_tab[i*2]._red = div((v >> 4 & 0xF) * 256, 16).quot;
|
||||
pixels_tab[i*2]._green = div((v >> 4 & 0xF) * 256, 16).quot;
|
||||
pixels_tab[i*2]._blue = div((v >> 4 & 0xF) * 256, 16).quot;
|
||||
if (isTransparentColor(&(pixels_tab[i*2]), transp_color) == 0) pixels_tab[i*2]._alpha = 0xFF - transp_color->_alpha; else pixels_tab[i*2]._alpha = 0xFF; // Test if color is a transparent color and adjust alpha layer
|
||||
pixels_tab[i*2+1]._red = div((v & 0xF) * 256, 16).quot;
|
||||
pixels_tab[i*2+1]._green = div((v & 0xF) * 256, 16).quot;
|
||||
pixels_tab[i*2+1]._blue = div((v & 0xF) * 256, 16).quot;
|
||||
if (isTransparentColor(&(pixels_tab[i*2+1]), transp_color) == 0) pixels_tab[i*2+1]._alpha = 0xFF - transp_color->_alpha; else pixels_tab[i*2+1]._alpha = 0xFF; // Test if color is a transparent color and adjust alpha layer
|
||||
}
|
||||
}
|
||||
|
||||
void convert4bitsTo32bitsRGBA(unsigned char *samples_tab, PIXEL_A *pixels_tab, int size, PIXEL *pal, PIXEL_A *transp_color) {
|
||||
int i,index;
|
||||
|
||||
for(i=0; i<div(size,2).quot; i++) {
|
||||
index = samples_tab[i];
|
||||
pixels_tab[i*2]._red = pal[(index >> 4) & 0xF]._red;
|
||||
pixels_tab[i*2]._green = pal[(index >> 4) & 0xF]._green;
|
||||
pixels_tab[i*2]._blue = pal[(index >> 4) & 0xF]._blue;
|
||||
if (isTransparentColor(&(pixels_tab[i*2]), transp_color) == 0) pixels_tab[i*2]._alpha = 0xFF - transp_color->_alpha; else pixels_tab[i*2]._alpha = 0xFF; // Test if color is a transparent color and adjust alpha layer
|
||||
pixels_tab[i*2+1]._red = pal[index & 0xF]._red;
|
||||
pixels_tab[i*2+1]._green = pal[index & 0xF]._green;
|
||||
pixels_tab[i*2+1]._blue = pal[index & 0xF]._blue;
|
||||
if (isTransparentColor(&(pixels_tab[i*2+1]), transp_color) == 0) pixels_tab[i*2]._alpha = 0xFF - transp_color->_alpha; else pixels_tab[i*2+1]._alpha = 0xFF; // Test if color is a transparent color and adjust alpha layer
|
||||
}
|
||||
}
|
||||
|
||||
void convert8bitsTo32bitsRGBA(unsigned char *samples_tab, PIXEL_A *pixels_tab, int size, PIXEL *pal, PIXEL_A *transp_color) {
|
||||
int i,index;
|
||||
|
||||
for(i=0; i<size; i++) {
|
||||
index = samples_tab[i];
|
||||
pixels_tab[i]._red = pal[index]._red;
|
||||
pixels_tab[i]._green = pal[index]._green;
|
||||
pixels_tab[i]._blue = pal[index]._blue;
|
||||
if (isTransparentColor(&(pixels_tab[i]), transp_color) == 0) pixels_tab[i]._alpha = 0xFF - transp_color->_alpha; else pixels_tab[i]._alpha = 0xFF; // Test if color is a transparent color and adjust alpha layer
|
||||
}
|
||||
}
|
||||
|
||||
void useOddBytes(unsigned char *src, PIXEL_A *dst, int size) {
|
||||
int i;
|
||||
|
||||
for(i=0; i<(size-1); i++) {
|
||||
//dst[i] = src[i*2+1]; //FIXME: Implement optimized byte shifting
|
||||
//dst[i]._red = src[i*2+1];
|
||||
//dst[i]._green = src[i*2+1];
|
||||
//dst[i]._blue = src[i*2+1];
|
||||
}
|
||||
}
|
||||
|
||||
PIXEL_A *pixelAt(RS_IMAGE *img, int posX , int posY) {
|
||||
return img->pixels + img->width * posY + posX;
|
||||
}
|
||||
|
||||
RS_IMAGE_DESC getImageDescFromType(unsigned char type) {
|
||||
RS_IMAGE_DESC desc;
|
||||
|
||||
switch(type) {
|
||||
case 0:
|
||||
desc.palette_entries = 16;
|
||||
desc.sample_bits = 4;
|
||||
break;
|
||||
case 1:
|
||||
desc.palette_entries = 256;
|
||||
desc.sample_bits = 8;
|
||||
break;
|
||||
case 2:
|
||||
desc.palette_entries = 0;
|
||||
desc.sample_bits = 16;
|
||||
break;
|
||||
case 3:
|
||||
desc.palette_entries = 0;
|
||||
desc.sample_bits = 32;
|
||||
break;
|
||||
case 4:
|
||||
desc.palette_entries = 0;
|
||||
desc.sample_bits = 4;
|
||||
break;
|
||||
case 5:
|
||||
desc.palette_entries = 0;
|
||||
desc.sample_bits = 8;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
85
RSPTextureLib/src/RS_images.h
Normal file
85
RSPTextureLib/src/RS_images.h
Normal file
@ -0,0 +1,85 @@
|
||||
#ifndef RS_IMAGES_H_
|
||||
#define RS_IMAGES_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include "options.h"
|
||||
|
||||
/**
|
||||
* @brief Constant contain the number of channel inside a PIXEL definition.
|
||||
*/
|
||||
#define PIXEL_MEMBERS_NBR 4
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
///// Define new types //////
|
||||
/////////////////////////////
|
||||
|
||||
/**
|
||||
* @brief RGBA pixel structure, used to store datas for implementation inside PNG files.
|
||||
*/
|
||||
typedef struct PixelRGBA {
|
||||
unsigned char _red;
|
||||
unsigned char _green;
|
||||
unsigned char _blue;
|
||||
unsigned char _alpha;
|
||||
}PIXEL_A;
|
||||
|
||||
/**
|
||||
* @brief RGB pixel structure, used to store datas for implementation inside PNG files, optimised version without alpha channel support.
|
||||
*/
|
||||
typedef struct PixelRGB {
|
||||
unsigned char _red;
|
||||
unsigned char _green;
|
||||
unsigned char _blue;
|
||||
}PIXEL;
|
||||
|
||||
/**
|
||||
* @brief Image definition from Rogue Squadron HMT files
|
||||
*/
|
||||
typedef struct RSImage {
|
||||
int data_size; /**< Image bytes size */
|
||||
int width, height;
|
||||
unsigned char type_; /**< Image type (0 = RBG/4bits per pixel, 1 = RBG/8bpp, 3 = RGBA/32bpp , 4 = grayscale/4bpp, 5 = grayscale/8bpp */
|
||||
unsigned char sampleBits; /**< Bits per samble */
|
||||
int paletteEntries;
|
||||
PIXEL_A alpha_color;
|
||||
PIXEL_A *pixels; /**< Image pixels list, managed like an array and declared as a pointer */
|
||||
unsigned char *samples; /**< Image samples list managed like an array and declared as a pointer */
|
||||
PIXEL palette[256]; /**< Image palette definition */ //TODO: Create union struct type instead
|
||||
}RS_IMAGE;
|
||||
|
||||
typedef struct RSImage_desc {
|
||||
int palette_entries;
|
||||
int sample_bits;
|
||||
}RS_IMAGE_DESC;
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
///// Declare functions /////
|
||||
/////////////////////////////
|
||||
|
||||
/**
|
||||
* @brief Conversion table for image type using RS_IMAGE_DESC.
|
||||
* Return RS_IMAGE_DESC by providing image type as int\n
|
||||
*
|
||||
* Detailed conversion:\n\n
|
||||
* Type 0 -> Palette entries: 16 ; Sample bits: 4\n
|
||||
* Type 1 -> Palette entries: 256 ; Sample bits: 8\n
|
||||
* Type 2 -> Palette entries: 0 ; Sample bits: 16\n
|
||||
* Type 3 -> Palette entries: 0 ; Sample bits: 32\n
|
||||
* Type 4 -> Palette entries: 0 ; Sample bits: 4\n
|
||||
* Type 5 -> Palette entries: 0 ; Sample bits: 8\n
|
||||
*/
|
||||
RS_IMAGE_DESC getImageDescFromType(unsigned char type); //TODO: Optimise function
|
||||
|
||||
int isTransparentColor(PIXEL_A *testColor, PIXEL_A *transp_color);
|
||||
void convert4bitsGreyTo32bitsRGBA(unsigned char *samples_tab, PIXEL_A *pixels_tab, int sampling, PIXEL_A *transp_color);
|
||||
void convert4bitsTo32bitsRGBA(unsigned char *samples_tab, PIXEL_A *pixels_tab, int size, PIXEL *pal, PIXEL_A *transp_color);
|
||||
void convert8bitsTo32bitsRGBA(unsigned char *samples_tab, PIXEL_A *pixels_tab, int size, PIXEL *pal, PIXEL_A *transp_color);
|
||||
void useOddBytes(unsigned char *src, PIXEL_A *dst, int size);
|
||||
void decodePixels(RS_IMAGE *img);
|
||||
PIXEL_A *pixelAt(RS_IMAGE *img, int posX , int posY);
|
||||
|
||||
#endif
|
@ -12,7 +12,7 @@
|
||||
#endif
|
||||
#include "config.h"
|
||||
#include "options.h"
|
||||
#include "HMT_Parser.h"
|
||||
#include "hmt_parser.h"
|
||||
#include "RS_images.h"
|
||||
#include "Image_Exporter.h"
|
||||
|
6
RSPTextureLib/src/config.h
Normal file
6
RSPTextureLib/src/config.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
#define PRG_VERSION "2.0.0"
|
||||
|
||||
#endif /* CONFIG_H_ */
|
167
RSPTextureLib/src/hmt_parser.c
Normal file
167
RSPTextureLib/src/hmt_parser.c
Normal file
@ -0,0 +1,167 @@
|
||||
#include "hmt_parser.h"
|
||||
|
||||
|
||||
HMT_FILE *parseHMTFile(FILE *hmt_src) {
|
||||
int i;
|
||||
HMT_FILE *_buff = NULL;
|
||||
|
||||
if (hmt_src == NULL) return NULL;
|
||||
_buff = calloc(1, sizeof(HMT_FILE));
|
||||
|
||||
rewind(hmt_src); //Rewind file at the start
|
||||
fread(&(_buff->material_count), 4, 1, hmt_src); // Extract first usefull datas
|
||||
fread(&(_buff->texture_offset), 4, 1, hmt_src);
|
||||
|
||||
// Read materials
|
||||
printf("[INFO] Materials detected: %d\n", _buff->material_count);
|
||||
_buff->materials_list = calloc(_buff->material_count, sizeof(HMT_MATERIAL)); // Create a big list of materials entries
|
||||
for (i=0; i<_buff->material_count; i++) {
|
||||
// Extract materials datas
|
||||
if (readMaterial(&(_buff->materials_list[i]), hmt_src) != 0) {
|
||||
purgeHMTFromMemory(_buff);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Read textures
|
||||
fseek(hmt_src, _buff->texture_offset, SEEK_SET);
|
||||
fread(&(_buff->texture_count), 4, 1, hmt_src);
|
||||
printf("[INFO] Textures detected: %d\n", _buff->texture_count);
|
||||
if (_buff->texture_count > 0) {
|
||||
_buff->textures_list = calloc(_buff->texture_count, sizeof(HMT_TEXTURE)); // Create a big list of textures entries
|
||||
for (i=0; i<_buff->texture_count; i++) {
|
||||
// Extract textures datas
|
||||
if (readTexture(&(_buff->textures_list[i]), hmt_src) != 0) {
|
||||
purgeHMTFromMemory(_buff);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _buff;
|
||||
}
|
||||
|
||||
int readMaterial(HMT_MATERIAL *mat, FILE *hmt_src) {
|
||||
if (mat == NULL || hmt_src == NULL) return EXIT_FAILURE;
|
||||
|
||||
fread(mat, sizeof(HMT_MATERIAL), 1, hmt_src);
|
||||
|
||||
if (_options & 0x1) {
|
||||
if (mat->zero != 0 || mat->hex_a != 0x0A) printf("\n Uncommon file detected!\n");
|
||||
printf(" Material type: %d\n Texture index: %d\n\n", mat->type_, mat->texture_index); //TODO: To develop?!
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int readTexture(HMT_TEXTURE *tex, FILE *hmt_src) {
|
||||
unsigned char u0,u1,bpp;
|
||||
long pos;
|
||||
RS_IMAGE_DESC desc;
|
||||
|
||||
fread(&(tex->data_offset), 4, 1, hmt_src);
|
||||
fseek(hmt_src, 28, SEEK_CUR); // Skip zeros area
|
||||
fread(&(tex->palette_offset), 4, 1, hmt_src);
|
||||
fread(&(tex->textureName_offset), 4, 1, hmt_src);
|
||||
fread(&(tex->width), 2, 1, hmt_src);
|
||||
fread(&(tex->height), 2, 1, hmt_src);
|
||||
|
||||
fread(&u0, 1, 1, hmt_src);
|
||||
fread(&bpp, 1, 1, hmt_src);
|
||||
fread(&(tex->image.type_), 1, 1, hmt_src);
|
||||
fread(&u1, 1, 1, hmt_src);
|
||||
fread(&(tex->image.alpha_color._red), 1, 1, hmt_src);
|
||||
fread(&(tex->image.alpha_color._green), 1, 1, hmt_src);
|
||||
fread(&(tex->image.alpha_color._blue), 1, 1, hmt_src);
|
||||
fread(&(tex->image.alpha_color._alpha), 1, 1, hmt_src);
|
||||
|
||||
pos = ftell(hmt_src);
|
||||
fseek(hmt_src, tex->textureName_offset, SEEK_SET);
|
||||
fread(&(tex->name), 16, 1, hmt_src);
|
||||
fseek(hmt_src, pos, SEEK_SET);
|
||||
|
||||
desc = getImageDescFromType(tex->image.type_);
|
||||
tex->image.paletteEntries = desc.palette_entries;
|
||||
tex->image.sampleBits = desc.sample_bits;
|
||||
tex->image.width = tex->width;
|
||||
tex->image.height = tex->height;
|
||||
|
||||
if (_options & VERBOSE_ENABLED) {
|
||||
printf(" Texture name: %s\n", tex->name);
|
||||
printf(" Size w: %ld h: %ld\n", tex->width, tex->height);
|
||||
printf(" u0: %d u1: %d\n", u0, u1);
|
||||
printf(" Texture type: %d\n", tex->image.type_);
|
||||
printf(" Samplebits: %d\n", tex->image.sampleBits);
|
||||
printf(" Palette entries: %d\n", tex->image.paletteEntries);
|
||||
printf(" Transparent color (RGB): %X %X %X\n", tex->image.alpha_color._red, tex->image.alpha_color._green, tex->image.alpha_color._blue);
|
||||
printf(" Palette offset: %d\n", tex->palette_offset);
|
||||
printf(" Data offset: %d\n", tex->data_offset);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (tex->palette_offset > 0) {
|
||||
if (_options & VERBOSE_ENABLED) printf("\nPalette entries: %d\n", tex->image.paletteEntries);
|
||||
fseek(hmt_src, tex->palette_offset, SEEK_SET);
|
||||
getPaletteFromFile(&(tex->image), hmt_src);
|
||||
}
|
||||
fseek(hmt_src, tex->data_offset, SEEK_SET);
|
||||
getSamplesFromFile(&(tex->image), hmt_src);
|
||||
decodePixels(&(tex->image));
|
||||
|
||||
fseek(hmt_src, pos, SEEK_SET);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int getPaletteFromFile(RS_IMAGE *img, FILE *f) {
|
||||
int entries = img->paletteEntries;
|
||||
|
||||
switch (entries) {
|
||||
case 16:
|
||||
case 256:
|
||||
fread(img->palette, sizeof(PIXEL), entries, f);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int getSamplesFromFile(RS_IMAGE *img, FILE *f) {
|
||||
int sample_bits = img->sampleBits;
|
||||
int size = div(img->width*img->height*sample_bits, 8).quot;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (f->_bufsiz >= ftell(f)+size) {
|
||||
printf("[ERR] WARNING! Please fix size/sample.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#else
|
||||
if (__fbufsize(f) >= ftell(f)+size) {
|
||||
printf("[ERR] WARNING! Please fix size/sample.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
img->samples = calloc(1, size);
|
||||
fread(img->samples, size, 1, f);
|
||||
if (img->type_ == 2) fread(img->samples, div(size, 4).quot, 1, f);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void purgeHMTFromMemory(HMT_FILE *_f) {
|
||||
if (_f == NULL) return;
|
||||
|
||||
if (_f->textures_list != NULL) {
|
||||
if (_f->textures_list->image.pixels != NULL) free(_f->textures_list->image.pixels);
|
||||
if (_f->textures_list->image.samples != NULL) free(_f->textures_list->image.samples);
|
||||
}
|
||||
free(_f->textures_list);
|
||||
|
||||
if (_f->materials_list != NULL) free(_f->materials_list);
|
||||
|
||||
free(_f);
|
||||
}
|
111
RSPTextureLib/src/hmt_parser.h
Normal file
111
RSPTextureLib/src/hmt_parser.h
Normal file
@ -0,0 +1,111 @@
|
||||
#ifndef HMT_PARSER_H_
|
||||
#define HMT_PARSER_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#ifndef _WIN32
|
||||
#include <stdio_ext.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include "options.h"
|
||||
#include "RS_images.h"
|
||||
|
||||
/////////////////////////////
|
||||
///// Define HMT types //////
|
||||
/////////////////////////////
|
||||
|
||||
/**
|
||||
* @brief Material struct inside HMT file type
|
||||
*
|
||||
* Actual RE material struct:\n
|
||||
* 4B material entry count MC\n
|
||||
* 4B offset after material entries / offset to textures\n
|
||||
* MC * material entry (36B)\n
|
||||
* [\n
|
||||
* 2B int material/texture type:\n
|
||||
* 1 - material with texture\n
|
||||
* 2 - material without texture\n
|
||||
* 2B int texture index\n
|
||||
* 4B float (scale factor?)\n
|
||||
* 4B float (always 1.0)\n
|
||||
* 4B int zero\n
|
||||
* 4B int 0x0A\n
|
||||
* 16B name\n
|
||||
* ]\n
|
||||
*
|
||||
* @image html hmt_materialDef.png
|
||||
*/
|
||||
typedef struct HMTMaterial {
|
||||
short type_; /**< Material type:\n 1 = Material with texture\n 2 = Material without texture */
|
||||
short texture_index;
|
||||
float unknow1,unknow2;
|
||||
int zero;
|
||||
int hex_a;
|
||||
char name[16];
|
||||
}HMT_MATERIAL;
|
||||
|
||||
/**
|
||||
* @brief Texture struct inside HMT file type
|
||||
*
|
||||
* Actual RE texture struct:\n
|
||||
* 4B int texcount Tc\n
|
||||
* TC * texture entry 52B\n
|
||||
* [\n
|
||||
* 4B int pixel offset\n
|
||||
* 28B zero\n
|
||||
* 4B int palette offset, 0 = no palette\n
|
||||
* 4B int texname offset\n
|
||||
* 2B int width\n
|
||||
* 2B int height\n
|
||||
* 8B texture format [\n
|
||||
* 1B int : always 1?\n
|
||||
* 1B int : bits per sample?\n
|
||||
* 1B int : subtype:\n
|
||||
* -0 - palette 16x3B RGB, 4bit per pixel\n
|
||||
* -1 - 256x3B palette RGB, 8bit per pixel\n
|
||||
* -3 - RGBA 32bpp\n
|
||||
* -4 - greyscale, 4bpp\n
|
||||
* -5 - grayscale, 8bpp\n
|
||||
* 1B int ? 0, 0x40, 0x80\n
|
||||
* 4B RGBA transparent color?\n
|
||||
* ]\n
|
||||
* ]\n
|
||||
*
|
||||
* @image html hmt_textureDef.png
|
||||
*/
|
||||
typedef struct HMTTexture {
|
||||
int data_offset;
|
||||
int palette_offset;
|
||||
int textureName_offset;
|
||||
unsigned long width, height;
|
||||
char name[16];
|
||||
RS_IMAGE image;
|
||||
}HMT_TEXTURE;
|
||||
|
||||
/**
|
||||
* @brief Instance of HMTFile in memory
|
||||
* This structure contain all parsed data for a single HMT file.
|
||||
*/
|
||||
typedef struct HMTFile {
|
||||
int material_count; /**< Number of materials registered inside HMTFile instance. */
|
||||
int texture_offset; /**< Address from which texture data begins. */
|
||||
int texture_count; /**< Number of textures registered inside HMTFile instance. */
|
||||
HMT_MATERIAL *materials_list; /**< Starting pointer of the materials list. Managed like an array and declared as a pointer */
|
||||
HMT_TEXTURE *textures_list; /**< Starting pointer of the textures list. Managed like an array and declared as a pointer*/
|
||||
}HMT_FILE;
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
///// Declare functions /////
|
||||
/////////////////////////////
|
||||
HMT_FILE *parseHMTFile(FILE *hmt_src);
|
||||
int readMaterial(HMT_MATERIAL *mat, FILE *hmt_src);
|
||||
int readTexture(HMT_TEXTURE *tex, FILE *hmt_src);
|
||||
HMT_MATERIAL *getMaterialFromIndex(int i);
|
||||
HMT_MATERIAL *getMaterialFromName(char *matName);
|
||||
HMT_TEXTURE *getTextureFromIndex(int i);
|
||||
HMT_TEXTURE *getTextureFromMaterial(HMT_MATERIAL *mat);
|
||||
int getPaletteFromFile(RS_IMAGE *img, FILE *f);
|
||||
int getSamplesFromFile(RS_IMAGE *img, FILE *f);
|
||||
void purgeHMTFromMemory(HMT_FILE *_f);
|
||||
|
||||
#endif
|
71
RSPTextureLib/src/hmt_struct.h
Normal file
71
RSPTextureLib/src/hmt_struct.h
Normal file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @file hmp_struct.h
|
||||
* @date 22/08/2022
|
||||
* @author JackCarterSmith
|
||||
* @copyright GPL-v3.0
|
||||
* @brief HMP file mapping definition.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RSPTERRAINLIB_HMP_STRUCT_H_
|
||||
#define RSPTERRAINLIB_HMP_STRUCT_H_
|
||||
|
||||
|
||||
/*
|
||||
* long = 64bits??? (8 Bytes)
|
||||
* int = 32bits (4 Bytes)
|
||||
* short = 16bits (2 Bytes)
|
||||
* char = 8bits (1 Bytes)
|
||||
*/
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define PACK
|
||||
#elif defined(__GNUC__)
|
||||
#define PACK __attribute__((packed))
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Declaration of Memory Mapped Structure
|
||||
// Caution: the place of variable is important for correct mapping!
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(push, 1)
|
||||
#endif
|
||||
|
||||
typedef struct PACK hmpfile_header {
|
||||
unsigned int reserved0; //12B of zeros
|
||||
unsigned int reserved1;
|
||||
unsigned int reserved2;
|
||||
|
||||
float reserved3; // Always 0x3F000000
|
||||
float height_scale;
|
||||
float reserved4; // Always 0x3F000000
|
||||
|
||||
unsigned short tiles_count;
|
||||
unsigned short unknown0;
|
||||
|
||||
unsigned int tiles_start_offset;
|
||||
unsigned int unknown1; // Offset to some datas?
|
||||
|
||||
unsigned short width_BLK;
|
||||
unsigned short height_BLK;
|
||||
} T_HMPFILE_HEADER;
|
||||
|
||||
typedef unsigned short T_TILE_INDICES;
|
||||
|
||||
typedef struct PACK hmpfile_tile {
|
||||
unsigned short texmap_id;
|
||||
|
||||
unsigned char unknown0;
|
||||
unsigned char low_height; // LOD application? Clipping? Terrain render quadrants?
|
||||
unsigned char high_height;
|
||||
|
||||
unsigned char height_values[5][5]; // first and last row/column overlap with a neighboring tile, "glue" for tiles, need to be identical to avoid "hill" effect
|
||||
} T_HMPFILE_TILE;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
#endif /* RSPTERRAINLIB_HMP_STRUCT_H_ */
|
@ -1,5 +1,4 @@
|
||||
[requires]
|
||||
zlib/1.2.11
|
||||
libpng/1.6.37
|
||||
|
||||
[generators]
|
||||
@ -7,8 +6,7 @@ cmake
|
||||
cmake_find_package
|
||||
|
||||
[options]
|
||||
zlib:shared=True
|
||||
libpng:shared=True
|
||||
|
||||
[imports]
|
||||
bin, *.dll -> .
|
||||
bin, *.dll -> ./bin
|
6
config.h.in
Normal file
6
config.h.in
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
#define PRG_VERSION "@PROJECT_VERSION@"
|
||||
|
||||
#endif /* CONFIG_H_ */
|
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
#define VERSION "@PROJECT_VERSION@"
|
Loading…
x
Reference in New Issue
Block a user