From 1483f2b87be32a60ef7e0038f3a893624a3c6639 Mon Sep 17 00:00:00 2001 From: dolcetriade Date: Thu, 5 Jul 2018 12:07:31 -0700 Subject: [PATCH] q3map2: Add crn loading support to q3map2 --- tools/quake3/CMakeLists.txt | 3 +++ tools/quake3/q3map2/image.c | 32 +++++++++++++++++++++++++++++++- tools/quake3/q3map2/q3map2.h | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tools/quake3/CMakeLists.txt b/tools/quake3/CMakeLists.txt index 1a852983..eb3060ec 100644 --- a/tools/quake3/CMakeLists.txt +++ b/tools/quake3/CMakeLists.txt @@ -31,6 +31,8 @@ include_directories(${ZLIB_INCLUDE_DIRS}) find_package(Minizip REQUIRED) include_directories(${Minizip_INCLUDE_DIRS}) +include_directories(${CMAKE_SOURCE_DIR}/libs/crunch) + set(q3map2_games q3map2/game_darkplaces.h q3map2/game_dq.h @@ -127,6 +129,7 @@ target_link_libraries(q3map2 ${Minizip_LIBRARIES} ${ZLIB_LIBRARIES} ddslib + crnlib etclib filematch l_net diff --git a/tools/quake3/q3map2/image.c b/tools/quake3/q3map2/image.c index 6ae88ca7..4bf1ec0e 100644 --- a/tools/quake3/q3map2/image.c +++ b/tools/quake3/q3map2/image.c @@ -86,6 +86,26 @@ static void LoadDDSBuffer( byte *buffer, int size, byte **pixels, int *width, in DDSDecompress( (ddsBuffer_t*) buffer, *pixels ); } +/* + LoadCRNBuffer + loads a crn image into a valid rgba image +*/ +void LoadCRNBuffer( byte *buffer, int size, byte **pixels, int *width, int *height) { + /* dummy check */ + if ( buffer == NULL || size <= 0 || pixels == NULL || width == NULL || height == NULL ) { + return; + } + if ( !GetCRNImageSize( buffer, size, width, height ) ) { + Sys_FPrintf( SYS_WRN, "WARNING: Error getting crn imag dimensions.\n");; + return; + } + int outBufSize = *width * *height * 4; + *pixels = safe_malloc( outBufSize ); + if ( !ConvertCRNtoRGBA( buffer, size, outBufSize, *pixels) ) { + Sys_FPrintf( SYS_WRN, "WARNING: Error decoding crn image.\n", 0 ); + return; + } +} /* @@ -437,6 +457,16 @@ image_t *ImageLoad( const char *filename ){ if ( size > 0 ) { LoadKTXBufferFirstImage( buffer, size, &image->pixels, &image->width, &image->height ); } + else + { + /* attempt to load crn */ + StripExtension( name ); + strcat( name, ".crn" ); + size = vfsLoadFile( ( const char* ) name, ( void** ) &buffer, 0 ); + if ( size > 0 ) { + LoadCRNBuffer( buffer, size, &image->pixels, &image->width, &image->height ); + } + } } } } @@ -473,7 +503,7 @@ image_t *ImageLoad( const char *filename ){ if (pixels) { // On error, LoadJPGBuff might store a pointer to the error message in pixels Sys_FPrintf( SYS_WRN, "WARNING: LoadJPGBuff %s %s\n", name, (unsigned char*) pixels ); - } + } } else { if ( width == image->width && height == image->height ) { int i; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 46fec5ee..698e57c1 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -70,6 +70,7 @@ #include "mathlib.h" #include "md5lib.h" #include "ddslib.h" +#include "crn_rgba.h" #include "picomodel.h" -- 2.39.2