Add management files
Some checks failed
JCS-Prod/RSE-Map/pipeline/head There was a failure building this commit
Some checks failed
JCS-Prod/RSE-Map/pipeline/head There was a failure building this commit
Conan + libs
This commit is contained in:
parent
0548720eae
commit
8aa6cb9926
@ -5,8 +5,10 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.1)
|
||||||
cmake_policy(VERSION 3.1)
|
cmake_policy(VERSION 3.1)
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
# define project
|
# define project
|
||||||
|
#add_definitions(-DCONF_NO_GL)
|
||||||
if(DEFINED ENV{CI})
|
if(DEFINED ENV{CI})
|
||||||
project(rse-map VERSION 1.0.0.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Map" LANGUAGES C)
|
project(rse-map VERSION 1.0.0.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Map" LANGUAGES C)
|
||||||
set(RSE_MAP_NAME $ENV{CI_OUTPUT_NAME}-${PROJECT_VERSION})
|
set(RSE_MAP_NAME $ENV{CI_OUTPUT_NAME}-${PROJECT_VERSION})
|
||||||
@ -18,18 +20,20 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_SOURC
|
|||||||
|
|
||||||
include(CheckIncludeFile)
|
include(CheckIncludeFile)
|
||||||
include(CheckCSourceCompiles)
|
include(CheckCSourceCompiles)
|
||||||
|
#include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||||
|
#conan_basic_setup()
|
||||||
|
|
||||||
# needed packages
|
# needed packages
|
||||||
|
|
||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB 1.2.11 EXACT REQUIRED)
|
||||||
include_directories(${ZLIB_INCLUDE_DIR})
|
include_directories(${ZLIB_INCLUDE_DIR})
|
||||||
find_package(PNG REQUIRED)
|
find_package(PNG 1.6.37 EXACT REQUIRED)
|
||||||
include_directories(${PNG_INCLUDE_DIR})
|
include_directories(${PNG_INCLUDE_DIR})
|
||||||
|
|
||||||
# define src/headers files
|
# define src/headers files
|
||||||
|
|
||||||
FILE(GLOB RSE_MAP_SRCS src/*.c)
|
FILE(GLOB_RECURSE RSE_MAP_SRCS src/*.c)
|
||||||
FILE(GLOB RSE_MAP_HRDS src/*.h)
|
FILE(GLOB_RECURSE RSE_MAP_HRDS src/*.h)
|
||||||
SOURCE_GROUP("Source Files" FILES ${RSE_MAP_SRCS})
|
SOURCE_GROUP("Source Files" FILES ${RSE_MAP_SRCS})
|
||||||
SOURCE_GROUP("Header Files" FILES ${RSE_MAP_HRDS})
|
SOURCE_GROUP("Header Files" FILES ${RSE_MAP_HRDS})
|
||||||
|
|
||||||
|
14
conanfile.txt
Normal file
14
conanfile.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[requires]
|
||||||
|
zlib/1.2.11
|
||||||
|
libpng/1.6.37
|
||||||
|
|
||||||
|
[generators]
|
||||||
|
cmake
|
||||||
|
cmake_find_package
|
||||||
|
|
||||||
|
[options]
|
||||||
|
zlib:shared=True
|
||||||
|
libpng:shared=True
|
||||||
|
|
||||||
|
[imports]
|
||||||
|
bin, *.dll -> .
|
72
src/Image_Exporter.c
Normal file
72
src/Image_Exporter.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include "Image_Exporter.h"
|
||||||
|
|
||||||
|
|
||||||
|
int saveToPNG(RS_IMAGE *img, char *tex_path, char *hmt_fileName) {
|
||||||
|
if (tex_path == NULL || img == NULL) return EXIT_FAILURE;
|
||||||
|
char export_path[128];
|
||||||
|
FILE *_png_f = NULL;
|
||||||
|
png_structp png_ptr = NULL;
|
||||||
|
png_infop info_ptr = NULL;
|
||||||
|
size_t x,y;
|
||||||
|
png_byte **row_ptrs = NULL;
|
||||||
|
PIXEL_A *pixel = NULL;
|
||||||
|
//int pixel_size = 3;
|
||||||
|
//int depth = 8; //bit par color channel (RGB)
|
||||||
|
|
||||||
|
if (_options & OUTPUT_DIR) {
|
||||||
|
strcpy(export_path, hmt_fileName);
|
||||||
|
#ifdef _WIN32
|
||||||
|
strcat(export_path, "-out\\");
|
||||||
|
#else
|
||||||
|
strcat(export_path, "-out/");
|
||||||
|
#endif
|
||||||
|
strcat(export_path, tex_path);
|
||||||
|
} else {
|
||||||
|
strcpy(export_path, tex_path);
|
||||||
|
}
|
||||||
|
strcat(export_path, ".png");
|
||||||
|
_png_f = fopen(export_path, "wb");
|
||||||
|
if (_png_f == NULL) return EXIT_FAILURE;
|
||||||
|
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
|
if (png_ptr == NULL) {
|
||||||
|
fclose(_png_f);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
|
if (info_ptr == NULL) {
|
||||||
|
fclose(_png_f);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set image attributes
|
||||||
|
png_set_IHDR(png_ptr, info_ptr, img->width, img->height, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||||
|
|
||||||
|
// Init PNG datas
|
||||||
|
row_ptrs = png_malloc(png_ptr, img->height * sizeof(png_byte *));
|
||||||
|
for (y=0; y<img->height; y++) {
|
||||||
|
png_byte *row = png_malloc(png_ptr, img->width*sizeof(PIXEL_A));
|
||||||
|
row_ptrs[y] = row;
|
||||||
|
for (x=0; x<img->width; x++) {
|
||||||
|
pixel = pixelAt(img, x , y);
|
||||||
|
if(pixel == NULL) return EXIT_FAILURE;
|
||||||
|
|
||||||
|
*row++ = pixel->_red;
|
||||||
|
*row++ = pixel->_green;
|
||||||
|
*row++ = pixel->_blue;
|
||||||
|
*row++ = pixel->_alpha;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
png_init_io(png_ptr, _png_f);
|
||||||
|
png_set_rows(png_ptr, info_ptr, row_ptrs);
|
||||||
|
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
|
||||||
|
|
||||||
|
for (y=0; y<img->height; y++) {
|
||||||
|
png_free(png_ptr, row_ptrs[y]);
|
||||||
|
}
|
||||||
|
png_free(png_ptr, row_ptrs);
|
||||||
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
|
fclose(_png_f);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
12
src/Image_Exporter.h
Normal file
12
src/Image_Exporter.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef IMAGE_EXPORTER_H_
|
||||||
|
#define IMAGE_EXPORTER_H_
|
||||||
|
|
||||||
|
#include "options.h"
|
||||||
|
#include "RS_images.h"
|
||||||
|
#include <zlib.h>
|
||||||
|
#include <png.h>
|
||||||
|
|
||||||
|
|
||||||
|
int saveToPNG(RS_IMAGE *img, char *tex_name, char *hmt_fileName);
|
||||||
|
|
||||||
|
#endif
|
133
src/Map-Extractor.c
Normal file
133
src/Map-Extractor.c
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
================================================================================
|
||||||
|
Name : Map-Extractor.c
|
||||||
|
Author : JackCarterSmith
|
||||||
|
License : GPL-v3.0
|
||||||
|
Description : DAT textures extractor to PNG format with enhanced function in C
|
||||||
|
================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Map-Extractor.h"
|
||||||
|
|
||||||
|
|
||||||
|
int _options; // Global options settings variable
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
// Init buffer vars
|
||||||
|
HMT_FILE *hmt_fdatas = NULL;
|
||||||
|
int file_index;
|
||||||
|
|
||||||
|
printf("\n*** RogueSquadron Extractor (RSE) - MAP module - v%s ***\n", VERSION);
|
||||||
|
|
||||||
|
// Check if filenames arguments exist
|
||||||
|
if (argc < 2) {
|
||||||
|
printf("\n[ERR] No input file/commands specified!\n");
|
||||||
|
dispHelp();
|
||||||
|
return EXIT_FAILURE; //TODO: implement own error codes system
|
||||||
|
}
|
||||||
|
_options = checkArgs(argv, argc); // Analyse program arguments
|
||||||
|
if (_options == -1) return EXIT_SUCCESS;
|
||||||
|
|
||||||
|
// Do the work
|
||||||
|
for (file_index=(_options >> 8) & 0xFF; file_index<argc; file_index++) { // Manage multiple inputs files
|
||||||
|
hmt_fdatas = extractDatasFromHMT(argv[file_index]);
|
||||||
|
if (hmt_fdatas == NULL) return EXIT_FAILURE;
|
||||||
|
if (exportTextures(hmt_fdatas, argv[file_index]) == EXIT_FAILURE) return EXIT_FAILURE;
|
||||||
|
purgeHMTFromMemory(hmt_fdatas); // Clean up memory (because I'm a good boy)
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int checkArgs(char *args[], int arg_nbr) {
|
||||||
|
int _o = 0x0002; // Default options parameters
|
||||||
|
char test[256];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (arg_nbr > 1) {
|
||||||
|
for (i=1; i<arg_nbr; i++) {
|
||||||
|
strcpy(test, args[i]);
|
||||||
|
if (args[i][0] != '-') break;
|
||||||
|
if (strcmp(args[i], "-h") == 0) {
|
||||||
|
dispHelp();
|
||||||
|
return -1;
|
||||||
|
} else if (strcmp(args[i], "-v") == 0) {
|
||||||
|
_o |= VERBOSE_ENABLED;
|
||||||
|
printf("[OPTN] Verbose enabled.\n");
|
||||||
|
} else if (strcmp(args[i], "-no-subdir") == 0) {
|
||||||
|
_o &= ~OUTPUT_DIR;
|
||||||
|
printf("[OPTN] Extract to current directory.\n");
|
||||||
|
} else {
|
||||||
|
printf("[ERR] Unknown option: %s\n", args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_o = (i << 8) | (_o & 0x00FF);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _o;
|
||||||
|
}
|
||||||
|
|
||||||
|
void createSubDir(char *dirName) {
|
||||||
|
if (dirName == NULL) return;
|
||||||
|
char _dir[260]; //TODO: Change directory management
|
||||||
|
strcpy(_dir, dirName);
|
||||||
|
strcat(_dir, "-out");
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
CreateDirectory(_dir, NULL);
|
||||||
|
#else
|
||||||
|
mkdir(_dir, 0755);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
HMT_FILE *extractDatasFromHMT(char *hmt_filename) {
|
||||||
|
FILE *_hmtFile = NULL;
|
||||||
|
HMT_FILE *hmt_fdatas = NULL;
|
||||||
|
|
||||||
|
_hmtFile = fopen(hmt_filename, "rb");
|
||||||
|
if (_hmtFile != NULL) {
|
||||||
|
printf("\n=============================================\n[INFO] - Parsing file: %s ...\n", hmt_filename);
|
||||||
|
hmt_fdatas = parseHMTFile(_hmtFile);
|
||||||
|
if (hmt_fdatas == NULL) printf("[ERR] Failed to parse datas from %s\n", hmt_filename);
|
||||||
|
} else {
|
||||||
|
printf("\n[ERR] Input file %s not found!\n", hmt_filename);
|
||||||
|
}
|
||||||
|
fclose(_hmtFile);
|
||||||
|
|
||||||
|
return hmt_fdatas;
|
||||||
|
}
|
||||||
|
|
||||||
|
int exportTextures(HMT_FILE *hmt_f, char *filename) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(hmt_f->texture_count > 0) {
|
||||||
|
if (_options & OUTPUT_DIR) createSubDir(filename);
|
||||||
|
for (i=0; i<hmt_f->texture_count; i++) {
|
||||||
|
switch (hmt_f->textures_list[i].image.type_) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
case 5:
|
||||||
|
if (saveToPNG(&(hmt_f->textures_list[i].image), hmt_f->textures_list[i].name, filename)) {
|
||||||
|
printf("[ERR] Failed saving image file: %s\n", hmt_f->textures_list[i].name);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
} else printf("[INFO] Saved image file: %s\n", hmt_f->textures_list[i].name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("[WARN] Can't export %s ! Image type %d not currently supported! (WIP)\n", hmt_f->textures_list[i].name, hmt_f->textures_list[i].image.type_);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispHelp() {
|
||||||
|
printf("\n");
|
||||||
|
printf("Options:\n -h Print this message\n -v Activate verbose console output\n -no-subdir Extract textures inside current folder\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("Usage: RSE-Texture_%s [options] <hmt files...>\n", VERSION);
|
||||||
|
printf("\n");
|
||||||
|
}
|
26
src/Map-Extractor.h
Normal file
26
src/Map-Extractor.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef MAP_EXTRACTOR_H_
|
||||||
|
#define MAP_EXTRACTOR_H_
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
#include "config.h"
|
||||||
|
#include "options.h"
|
||||||
|
#include "HMT_Parser.h"
|
||||||
|
#include "RS_images.h"
|
||||||
|
#include "Image_Exporter.h"
|
||||||
|
|
||||||
|
|
||||||
|
void createSubDir(char *dirName);
|
||||||
|
int checkArgs(char *args[], int arg_nbr);
|
||||||
|
HMT_FILE *extractDatasFromHMT(char* hmt_filename);
|
||||||
|
int exportTextures(HMT_FILE *hmt_f, char *filename);
|
||||||
|
void dispHelp();
|
||||||
|
|
||||||
|
#endif
|
1
src/config.h.in
Normal file
1
src/config.h.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
#define VERSION "@PROJECT_VERSION@"
|
9
src/options.h
Normal file
9
src/options.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef OPTIONS_H_
|
||||||
|
#define OPTIONS_H_
|
||||||
|
|
||||||
|
#define VERBOSE_ENABLED 0x0001
|
||||||
|
#define OUTPUT_DIR 0x0002
|
||||||
|
|
||||||
|
extern int _options;
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user