From 23e8719f8db3ce3c7fae54b8ac6ddffaa983e418 Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Thu, 4 Jul 2019 23:42:36 +0200 Subject: [PATCH] Add better support -Add prototype of PNG export function (WIP) -Updated libs files and information -Credit work of @dpethes --- README.md | 22 +++++++++----- Texture-Extractor Debug.launch | 2 +- Texture-Extractor Release.launch | 2 +- src/Image_Exporter.c | 52 ++++++++++++++++++++++++++++++++ src/Image_Exporter.h | 10 ++++++ src/RS_images.h | 2 ++ src/Texture-Extractor.c | 24 +++++++++++++-- src/Texture-Extractor.h | 4 +-- 8 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 src/Image_Exporter.c create mode 100644 src/Image_Exporter.h diff --git a/README.md b/README.md index 2bd2f5d..9c24a29 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,32 @@ # RogueSquadron Data Extractor - TEXTURE module +Inspired by the work **dpethes** (https://github.com/dpethes/rerogue) + This set of git repos are a compilation of tools coded in C to make RS modding far more than a dream! The collection consist of few independants modules, each of them deals with specific data like sound, textures, heightmaps, etc... -This is the **TEXTURE** module. -**CAUTION! This module is in very alpha! Don't use it for the moment.** + +All modules are independants. This is the **'TEXTURE'** module. + +**CAUTION! Master branch is hugely buggy and should not be used, please take only released versions.** ## TEXTURE MODULE It's extract texture datas from Rogue Squadron 3D (PC) game files (DAT). +### Using + +*TODO...* + ### Dependencies -- zlib (1.2.3) -- libpng (1.2.37) +Necessary libs for running (provided in release) and for compiling. + +- zlib (1.2.11) +- libpng (1.6.37) ### Compiling You can compile on both Windows or Linux system, you only need to adjust your dependencies. *Makefile is coming...* - -### Using - -`TEXTractor ` diff --git a/Texture-Extractor Debug.launch b/Texture-Extractor Debug.launch index 5aa1357..05dfc8f 100644 --- a/Texture-Extractor Debug.launch +++ b/Texture-Extractor Debug.launch @@ -20,7 +20,7 @@ - + diff --git a/Texture-Extractor Release.launch b/Texture-Extractor Release.launch index 10c879e..985c68d 100644 --- a/Texture-Extractor Release.launch +++ b/Texture-Extractor Release.launch @@ -20,7 +20,7 @@ - + diff --git a/src/Image_Exporter.c b/src/Image_Exporter.c new file mode 100644 index 0000000..e4844f4 --- /dev/null +++ b/src/Image_Exporter.c @@ -0,0 +1,52 @@ +#include "Image_Exporter.h" + + +int saveToPNG(RS_IMAGE *img, char *tex_name) { + char tex_path[64]; + FILE *_png_f = NULL; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; + //size_t x,y; + png_byte **row_ptrs = NULL; + //int pixel_size = 3; + //int depth = 8; + + strcpy(tex_path,tex_name); + strcat(tex_path, ".png"); + _png_f = fopen(tex_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_RGB, 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(unsigned char)*3); + row_ptrs[y] = row; + for (x=0; xwidth; x++) { + unsigned char pixel[3] = pixelAt(img->pixels); + } + }*/ + memcpy(row_ptrs, img->pixels, sizeof(unsigned char)*3*img->height*img->width); + + 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); + + 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..8451a18 --- /dev/null +++ b/src/Image_Exporter.h @@ -0,0 +1,10 @@ +#ifndef IMAGE_EXPORTER_H_ +#define IMAGE_EXPORTER_H_ + +#include "RS_images.h" +#include +#include + +int saveToPNG(RS_IMAGE *img, char *tex_name); + +#endif diff --git a/src/RS_images.h b/src/RS_images.h index 851aa59..d74b387 100644 --- a/src/RS_images.h +++ b/src/RS_images.h @@ -4,8 +4,10 @@ #include #include #if defined(_WIN32) + #define OS 1 #include #else + #define OS 2 #include #include #endif diff --git a/src/Texture-Extractor.c b/src/Texture-Extractor.c index f92e57b..d0b4192 100644 --- a/src/Texture-Extractor.c +++ b/src/Texture-Extractor.c @@ -58,9 +58,27 @@ HMT_FILE *extractDatasFromHMT(char *hmt_filename) { } int exportTextures(HMT_FILE *hmt_f, char *filename) { - return EXIT_SUCCESS; -} + int i; + + for (i=0; itexture_count; i++) { + switch (hmt_f->textures_list[i].image.type_) { + case 0: + case 1: + saveToPNG(&(hmt_f->textures_list[i].image), hmt_f->textures_list[i].name); + //Write to PNM + break; + case 3: + //Write to TGA + break; + case 4: + case 5: + saveToPNG(&(hmt_f->textures_list[i].image), hmt_f->textures_list[i].name); + //Write to PGM + break; + default: + printf("[INFO] Image type %d not currently supported!", hmt_f->textures_list[i].image.type_); + } + } -int saveToPNG(RS_IMAGE *img, char *tex_name) { return EXIT_SUCCESS; } diff --git a/src/Texture-Extractor.h b/src/Texture-Extractor.h index fe8d398..6ebb323 100644 --- a/src/Texture-Extractor.h +++ b/src/Texture-Extractor.h @@ -4,14 +4,12 @@ #include #include #include -//#include -#include #include "HMT_Parser.h" #include "RS_images.h" +#include "Image_Exporter.h" void purgeHMTFromMemory(HMT_FILE *_f); HMT_FILE *extractDatasFromHMT(char* hmt_filename); int exportTextures(HMT_FILE *hmt_f, char *filename); -int saveToPNG(RS_IMAGE *img, char *tex_name); #endif