X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=tools%2Fquake3%2Fq3map2%2Fimage.c;h=c1c737f51b3282b74d827a80fd9fe06110ec7346;hb=25e4f9e8cf6aa80de16ba5f25cfc9b3da7c2c368;hp=bb6a52563206a2e65bc92ae1551e05611e8d25c3;hpb=3c73487420fde8d4a3b5360d8b99e48132517900;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/q3map2/image.c b/tools/quake3/q3map2/image.c index bb6a5256..c1c737f5 100644 --- a/tools/quake3/q3map2/image.c +++ b/tools/quake3/q3map2/image.c @@ -98,8 +98,7 @@ typedef struct pngBuffer_s { byte *buffer; png_size_t size, offset; -} -pngBuffer_t; +} pngBuffer_t; void PNGReadData( png_struct *png, png_byte *buffer, png_size_t size ){ pngBuffer_t *pb = (pngBuffer_t*) png_get_io_ptr( png ); @@ -124,11 +123,11 @@ static void LoadPNGBuffer( byte *buffer, int size, byte **pixels, int *width, in png_struct *png; png_info *info, *end; pngBuffer_t pb; + //pngBuffer_t *pb = (pngBuffer_t*) png_get_io_ptr( png ); int bitDepth, colorType; png_uint_32 w, h, i; byte **rowPointers; - /* dummy check */ if ( buffer == NULL || size <= 0 || pixels == NULL || width == NULL || height == NULL ) { return; @@ -171,9 +170,10 @@ static void LoadPNGBuffer( byte *buffer, int size, byte **pixels, int *width, in pb.size = size; pb.offset = 0; png_set_read_fn( png, &pb, PNGReadData ); + //png->io_ptr = &pb; /* hack! */ /* set error longjmp */ - if ( setjmp( png_jmpbuf( png ) ) ) { + if ( setjmp( png_jmpbuf(png) ) ) { Sys_Printf( "WARNING: An error occurred reading PNG image\n" ); png_destroy_read_struct( &png, &info, &end ); return; @@ -402,7 +402,8 @@ image_t *ImageLoad( const char *filename ){ size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); if ( size > 0 ) { if ( LoadJPGBuff( buffer, size, &image->pixels, &image->width, &image->height ) == -1 && image->pixels != NULL ) { - Sys_Printf( "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels ); + // On error, LoadJPGBuff might store a pointer to the error message in image->pixels + Sys_Printf( "WARNING: LoadJPGBuff %s %s\n", name, (unsigned char*) image->pixels ); } alphaHack = qtrue; } @@ -429,6 +430,16 @@ image_t *ImageLoad( const char *filename ){ } #endif } + else + { + /* attempt to load ktx */ + StripExtension( name ); + strcat( name, ".ktx" ); + size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); + if ( size > 0 ) { + LoadKTXBufferFirstImage( buffer, size, &image->pixels, &image->width, &image->height ); + } + } } } } @@ -460,15 +471,19 @@ image_t *ImageLoad( const char *filename ){ if ( size > 0 ) { unsigned char *pixels; int width, height; - if ( LoadJPGBuff( buffer, size, &pixels, &width, &height ) == -1 && pixels != NULL ) { - Sys_Printf( "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels ); - } - if ( pixels && width == image->width && height == image->height ) { - int i; - for ( i = 0; i < width * height; ++i ) - image->pixels[4 * i + 3] = pixels[4 * i + 2]; // copy alpha from blue channel + if ( LoadJPGBuff( buffer, size, &pixels, &width, &height ) == -1 ) { + if (pixels) { + // On error, LoadJPGBuff might store a pointer to the error message in pixels + Sys_Printf( "WARNING: LoadJPGBuff %s %s\n", name, (unsigned char*) pixels ); + } + } else { + if ( width == image->width && height == image->height ) { + int i; + for ( i = 0; i < width * height; ++i ) + image->pixels[4 * i + 3] = pixels[4 * i + 2]; // copy alpha from blue channel + } + free( pixels ); } - free( pixels ); free( buffer ); } }