From 8aa6cb99260fc567848a5568350a4130a0a6f98f Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Tue, 24 Aug 2021 20:59:19 +0200 Subject: [PATCH] Add management files Conan + libs --- CMakeLists.txt | 12 ++-- conanfile.txt | 14 +++++ src/Image_Exporter.c | 72 +++++++++++++++++++++++ src/Image_Exporter.h | 12 ++++ src/Map-Extractor.c | 133 +++++++++++++++++++++++++++++++++++++++++++ src/Map-Extractor.h | 26 +++++++++ src/config.h.in | 1 + src/options.h | 9 +++ 8 files changed, 275 insertions(+), 4 deletions(-) create mode 100644 conanfile.txt create mode 100644 src/Image_Exporter.c create mode 100644 src/Image_Exporter.h create mode 100644 src/Map-Extractor.c create mode 100644 src/Map-Extractor.h create mode 100644 src/config.h.in create mode 100644 src/options.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 737c45c..02f7b0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,10 @@ cmake_minimum_required(VERSION 3.1) cmake_policy(VERSION 3.1) +set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) # define project +#add_definitions(-DCONF_NO_GL) if(DEFINED ENV{CI}) 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}) @@ -18,18 +20,20 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_SOURC include(CheckIncludeFile) include(CheckCSourceCompiles) +#include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +#conan_basic_setup() # needed packages -find_package(ZLIB REQUIRED) +find_package(ZLIB 1.2.11 EXACT REQUIRED) include_directories(${ZLIB_INCLUDE_DIR}) -find_package(PNG REQUIRED) +find_package(PNG 1.6.37 EXACT REQUIRED) include_directories(${PNG_INCLUDE_DIR}) # define src/headers files -FILE(GLOB RSE_MAP_SRCS src/*.c) -FILE(GLOB RSE_MAP_HRDS src/*.h) +FILE(GLOB_RECURSE RSE_MAP_SRCS src/*.c) +FILE(GLOB_RECURSE RSE_MAP_HRDS src/*.h) SOURCE_GROUP("Source Files" FILES ${RSE_MAP_SRCS}) SOURCE_GROUP("Header Files" FILES ${RSE_MAP_HRDS}) diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..26b54e2 --- /dev/null +++ b/conanfile.txt @@ -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 -> . \ No newline at end of file diff --git a/src/Image_Exporter.c b/src/Image_Exporter.c new file mode 100644 index 0000000..dd43284 --- /dev/null +++ b/src/Image_Exporter.c @@ -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; yheight; y++) { + png_byte *row = png_malloc(png_ptr, img->width*sizeof(PIXEL_A)); + row_ptrs[y] = row; + for (x=0; xwidth; 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; yheight; 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; +} diff --git a/src/Image_Exporter.h b/src/Image_Exporter.h new file mode 100644 index 0000000..d0ff59f --- /dev/null +++ b/src/Image_Exporter.h @@ -0,0 +1,12 @@ +#ifndef IMAGE_EXPORTER_H_ +#define IMAGE_EXPORTER_H_ + +#include "options.h" +#include "RS_images.h" +#include +#include + + +int saveToPNG(RS_IMAGE *img, char *tex_name, char *hmt_fileName); + +#endif diff --git a/src/Map-Extractor.c b/src/Map-Extractor.c new file mode 100644 index 0000000..796a06d --- /dev/null +++ b/src/Map-Extractor.c @@ -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 1) { + for (i=1; itexture_count > 0) { + if (_options & OUTPUT_DIR) createSubDir(filename); + for (i=0; itexture_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] \n", VERSION); + printf("\n"); +} diff --git a/src/Map-Extractor.h b/src/Map-Extractor.h new file mode 100644 index 0000000..1311701 --- /dev/null +++ b/src/Map-Extractor.h @@ -0,0 +1,26 @@ +#ifndef MAP_EXTRACTOR_H_ +#define MAP_EXTRACTOR_H_ + +#include +#include +#include +#if defined(_WIN32) + #include +#else + #include + #include +#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 diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 0000000..d35c5f2 --- /dev/null +++ b/src/config.h.in @@ -0,0 +1 @@ +#define VERSION "@PROJECT_VERSION@" diff --git a/src/options.h b/src/options.h new file mode 100644 index 0000000..904c2d3 --- /dev/null +++ b/src/options.h @@ -0,0 +1,9 @@ +#ifndef OPTIONS_H_ +#define OPTIONS_H_ + +#define VERBOSE_ENABLED 0x0001 +#define OUTPUT_DIR 0x0002 + +extern int _options; + +#endif