]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Merge branch 'webp' into 'master'
authorMario <zacjardine@y7mail.com>
Sat, 3 Nov 2018 22:36:18 +0000 (22:36 +0000)
committerMario <zacjardine@y7mail.com>
Sat, 3 Nov 2018 22:36:18 +0000 (22:36 +0000)
add webp support (Ingar code)

See merge request xonotic/netradiant!100

Makefile
README.md
cmake/FindWebP.cmake [new file with mode: 0644]
plugins/CMakeLists.txt
plugins/imagewebp/CMakeLists.txt [new file with mode: 0644]
plugins/imagewebp/imagewebp.def [new file with mode: 0644]
plugins/imagewebp/plugin.cpp [new file with mode: 0644]
plugins/imagewebp/plugin.h [new file with mode: 0644]
tools/quake3/CMakeLists.txt
tools/quake3/q3map2/image.c

index 4443837f0eaece6512222ab8636eae3858a9bd96..8d05f8b99acda728b6d755f968bfe6b1245e402e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -68,6 +68,9 @@ LIBS_XML           ?= $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) li
 CPPFLAGS_PNG       ?= $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) libpng --cflags $(STDERR_TO_DEVNULL))
 LIBS_PNG           ?= $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) libpng --libs-only-L $(STDERR_TO_DEVNULL)) \
                       $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) libpng --libs-only-l $(STDERR_TO_DEVNULL))
+CPPFLAGS_WEBP      ?= $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) libwebp --cflags $(STDERR_TO_DEVNULL))
+LIBS_WEBP          ?= $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) libwebp --libs-only-L $(STDERR_TO_DEVNULL)) \
+                      $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) libwebp --libs-only-l $(STDERR_TO_DEVNULL))
 CPPFLAGS_GTK       ?= $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) gtk+-2.0 --cflags $(STDERR_TO_DEVNULL))
 LIBS_GTK           ?= $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) gtk+-2.0 --libs-only-L $(STDERR_TO_DEVNULL)) \
                       $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKGCONFIG) gtk+-2.0 --libs-only-l $(STDERR_TO_DEVNULL))
@@ -352,6 +355,7 @@ dependencies-check:
        checkheader libglib2.0-dev glib.h g_path_is_absolute "$(CPPFLAGS_GLIB)" "$(LIBS_GLIB)"; \
        checkheader libxml2-dev libxml/xpath.h xmlXPathInit "$(CPPFLAGS_XML)" "$(LIBS_XML)"; \
        checkheader libpng12-dev png.h png_create_read_struct "$(CPPFLAGS_PNG)" "$(LIBS_PNG)"; \
+       checkheader libwebp-dev webp/decode.h WebPGetInfo "$(CPPFLAGS_WEBP)" "$(LIBS_WEBP)"; \
        checkheader "mesa-common-dev (or another OpenGL library)" GL/gl.h glClear "$(CPPFLAGS_GL)" "$(LIBS_GL)"; \
        checkheader libgtk2.0-dev gtk/gtkdialog.h gtk_dialog_run "$(CPPFLAGS_GTK)" "$(LIBS_GTK)"; \
        checkheader libpango1.0-dev pango/pangoft2.h pango_ft2_font_map_new "$(CPPFLAGS_PANGOFT2)" "$(LIBS_PANGOFT2)"; \
@@ -382,6 +386,7 @@ binaries-radiant-modules: \
        $(INSTALLDIR)/modules/image.$(DLL) \
        $(INSTALLDIR)/modules/imagehl.$(DLL) \
        $(INSTALLDIR)/modules/imagepng.$(DLL) \
+       $(INSTALLDIR)/modules/imagewebp.$(DLL) \
        $(INSTALLDIR)/modules/imageq2.$(DLL) \
        $(INSTALLDIR)/modules/mapq3.$(DLL) \
        $(INSTALLDIR)/modules/mapxml.$(DLL) \
@@ -485,8 +490,8 @@ endif
        $(CC) $< $(CFLAGS) $(CFLAGS_COMMON) $(CPPFLAGS_EXTRA) $(CPPFLAGS_COMMON) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@
 
 
-$(INSTALLDIR)/q3map2.$(EXE): LIBS_EXTRA := $(LIBS_XML) $(LIBS_GLIB) $(LIBS_PNG) $(LIBS_JPEG) $(LIBS_ZLIB)
-$(INSTALLDIR)/q3map2.$(EXE): CPPFLAGS_EXTRA := $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) $(CPPFLAGS_PNG) $(CPPFLAGS_JPEG) -Itools/quake3/common -Ilibs -Iinclude
+$(INSTALLDIR)/q3map2.$(EXE): LIBS_EXTRA := $(LIBS_XML) $(LIBS_GLIB) $(LIBS_PNG) $(LIBS_JPEG) $(LIBS_WEBP) $(LIBS_ZLIB)
+$(INSTALLDIR)/q3map2.$(EXE): CPPFLAGS_EXTRA := $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) $(CPPFLAGS_PNG) $(CPPFLAGS_JPEG) $(CPPFLAGS_WEBP) -Itools/quake3/common -Ilibs -Iinclude
 $(INSTALLDIR)/q3map2.$(EXE): \
        tools/quake3/common/cmdlib.o \
        tools/quake3/common/imagelib.o \
@@ -826,6 +831,11 @@ $(INSTALLDIR)/modules/imagepng.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_PNG) -Ilibs
 $(INSTALLDIR)/modules/imagepng.$(DLL): \
        plugins/imagepng/plugin.o \
 
+$(INSTALLDIR)/modules/imagewebp.$(DLL): LIBS_EXTRA := $(LIBS_WEBP)
+$(INSTALLDIR)/modules/imagewebp.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_WEBP) -Ilibs -Iinclude
+$(INSTALLDIR)/modules/imagewebp.$(DLL): \
+       plugins/imagewebp/plugin.o \
+
 $(INSTALLDIR)/modules/mapq3.$(DLL): CPPFLAGS_EXTRA := $(CPPFLAGS_GLIB) -Ilibs -Iinclude
 $(INSTALLDIR)/modules/mapq3.$(DLL): \
        plugins/mapq3/parse.o \
index eb6bf9756e4256557e13621653db93363296293b..90059acc4fc6408ee1306152ea3f5f8498ed0ea4 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,7 +1,9 @@
 NetRadiant
 ==========
 
-The open source, cross platform level editor for idtech games (Radiant fork)
+![NetRadiant logo](setup/data/tools/bitmaps/splash.png)
+
+The open source, cross platform level editor for idtech games (Radiant fork).
 
 # Getting the Sources
 
@@ -11,7 +13,8 @@ https://gitlab.com/xonotic/netradiant.git
 The git client can be obtained from the Git website:
 http://git-scm.org
 
-To get a copy of the source using the commandline git client:
+To get a copy of the source using the command line git client:
+
 ```
 git clone --recursive https://gitlab.com/xonotic/netradiant.git
 cd netradiant
@@ -27,6 +30,7 @@ See also https://gitlab.com/xonotic/netradiant/ for a source browser, issues and
  * GtkGLExt
  * LibJpeg
  * LibPng
+ * LibWebp
  * Minizip
  * ZLib
 
@@ -37,28 +41,29 @@ Under MSYS2, the mingw shell must be used
 ### 32 bit:
 
 ```
-pacman -S --needed base-devel mingw-w64-i686-{toolchain,cmake,make,gtk2,gtkglext}
+pacman -S --needed base-devel mingw-w64-i686-{toolchain,cmake,make,gtk2,gtkglexti,libwebp}
 ```
 
 ### 64 bit:
 
 ```
-pacman -S --needed base-devel mingw-w64-x86_64-{toolchain,cmake,make,gtk2,gtkglext}
+pacman -S --needed base-devel mingw-w64-x86_64-{toolchain,cmake,make,gtk2,gtkglext,libwebp}
 ```
 
 ## OS X:
 
 ```
 brew install gtkglext
+brew install webp
 brew install Caskroom/cask/xquartz
 brew link --force gettext
 ```
 
 # Submodules
 
- * Crunch
+ * Crunch (optional, disabled by default, only supported with CMake build)
 
-If you forgot to add `--recursive` option at `git clone` time, fetch it this way:
+If you have not used `--recursive` option at `git clone` time, you can fetch Crunch this way (run it whithin NetRadiant repository):
 
 
 ```
@@ -84,12 +89,16 @@ cmake -G "Unix Makefiles" -H. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --buil
 ## More Compilation Details
 
 options:
- * `DOWNLOAD_GAMEPACKS=ON`
+
+ * `DOWNLOAD_GAMEPACKS=ON`  
    Automatically download the gamepack data during the first compilation
- * `RADIANT_ABOUTMSG="Custom build"`
+ * `BUILD_CRUNCH=ON`  
+   Enable crunch support
+ * `RADIANT_ABOUTMSG="Custom build"`  
    A message shown in the about dialog
 
 targets:
+
  * `radiant`    Compiles the radiant core binary
  * `modules`    Compiles all modules (each module has its own target as well)
  * `plugins`    Compiles all plugins (each plugin has its own target as well)
@@ -100,4 +109,4 @@ targets:
 
 ## Note about Crunch
 
-The crnlib used to decode `.crn` files is the one from [Dæmon](http://github.com/DaemonEngine/Daemon) which is just the one by [Unity](https://github.com/Unity-Technologies/crunch/tree/unity) made cross-platform. Since Unity brokes compatibility with [BinomialLLC's legacy tree](https://github.com/BinomialLLC/crunch) it's required to use either crunch from Dæmon or the one from Unity to compress textures that have to be read by radiant or q3map2.
+The crnlib used to decode `.crn` files is the one from [Dæmon](http://github.com/DaemonEngine/Daemon) which is the one by [Unity](https://github.com/Unity-Technologies/crunch/tree/unity) made cross-platform and slightly improved. Since Unity brokes compatibility with [BinomialLLC's legacy tree](https://github.com/BinomialLLC/crunch) it's required to use either the `crunch` tool from Dæmon or the one from Unity to compress textures that have to be read by radiant or q3map2.
diff --git a/cmake/FindWebP.cmake b/cmake/FindWebP.cmake
new file mode 100644 (file)
index 0000000..0868255
--- /dev/null
@@ -0,0 +1,73 @@
+# - Find WebP library
+# Find the native WebP headers and libraries.
+#
+#  WEBP_INCLUDE_DIRS - where to find webp/decode.h, etc.
+#  WEBP_LIBRARIES    - List of libraries when using webp.
+#  WEBP_FOUND        - True if webp is found.
+
+#=============================================================================
+#Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+#All rights reserved.
+#
+#Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#* Redistributions of source code must retain the above copyright notice,
+#this list of conditions and the following disclaimer.
+#
+#* Redistributions in binary form must reproduce the above copyright notice,
+#this list of conditions and the following disclaimer in the documentation
+#and/or other materials provided with the distribution.
+#
+#* Neither the names of Kitware, Inc., the Insight Software Consortium, nor
+#the names of their contributors may be used to endorse or promote products
+#derived from this software without specific prior written  permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+#LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+#CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+#SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+#CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+#ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+#POSSIBILITY OF SUCH DAMAGE.
+#=============================================================================
+
+# Look for the header file.
+FIND_PATH(WEBP_INCLUDE_DIR NAMES webp/decode.h)
+MARK_AS_ADVANCED(WEBP_INCLUDE_DIR)
+
+# Look for the library.
+FIND_LIBRARY(WEBP_LIBRARY NAMES webp)
+MARK_AS_ADVANCED(WEBP_LIBRARY)
+
+# handle the QUIETLY and REQUIRED arguments and set WEBFOUND_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(WebP DEFAULT_MSG WEBP_LIBRARY WEBP_INCLUDE_DIR)
+
+SET(WEBP_LIBRARIES ${WEBP_LIBRARY})
+SET(WEBP_INCLUDE_DIRS ${WEBP_INCLUDE_DIR})
+
+SET(_WEBP_RQ_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
+
+if(NOT DEFINED _WEBP_COMPILATION_TEST)
+  INCLUDE (CheckCSourceCompiles)
+  SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${WEBP_INCLUDE_DIRS})
+  CHECK_C_SOURCE_COMPILES("#include <webp/decode.h>
+  int main(void) {
+  #if WEBP_DECODER_ABI_VERSION < 0x0200
+  error; // Deliberate compile-time error
+  #endif
+  return 0;
+  }"
+   _WEBP_COMPILATION_TEST)
+  SET(CMAKE_REQUIRED_INCLUDES ${_WEBP_RQ_INCLUDES})
+endif()
+
+if(NOT _WEBP_COMPILATION_TEST)
+  set( USE_INTERNAL_WEBP 1 )
+endif()
index d6c7f075b474e957de5f9f4060c44aac9d88ddee..80f45f1fc638a3b8417709d78ee91544635a95c8 100644 (file)
@@ -25,6 +25,7 @@ endif()
 add_subdirectory(imagehl)
 add_subdirectory(imagepng)
 add_subdirectory(imageq2)
+add_subdirectory(imagewebp)
 add_subdirectory(iqmmodel)
 add_subdirectory(mapq3)
 add_subdirectory(mapxml)
diff --git a/plugins/imagewebp/CMakeLists.txt b/plugins/imagewebp/CMakeLists.txt
new file mode 100644 (file)
index 0000000..baac0ca
--- /dev/null
@@ -0,0 +1,7 @@
+radiant_plugin(imagewebp
+        plugin.cpp
+        )
+
+find_package(WebP REQUIRED)
+target_include_directories(imagewebp PRIVATE ${WEBP_INCLUDE_DIR})
+target_link_libraries(imagewebp PRIVATE ${WEBP_LIBRARIES})
diff --git a/plugins/imagewebp/imagewebp.def b/plugins/imagewebp/imagewebp.def
new file mode 100644 (file)
index 0000000..d04effc
--- /dev/null
@@ -0,0 +1,7 @@
+; imagewebp.def : Declares the module parameters for the DLL.
+
+LIBRARY      "IMAGEWEBP"
+
+EXPORTS
+    ; Explicit exports can go here
+       Radiant_RegisterModules @1
diff --git a/plugins/imagewebp/plugin.cpp b/plugins/imagewebp/plugin.cpp
new file mode 100644 (file)
index 0000000..0dcd7ed
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+   Copyright (C) 1999-2006 Id Software, Inc. and contributors.
+   For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+   This file is part of NetRadiant.
+
+   NetRadiant is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   NetRadiant is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with NetRadiant; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "plugin.h"
+#include "debugging/debugging.h"
+#include "ifilesystem.h"
+#include "iimage.h"
+
+#include "imagelib.h"
+
+// ====== WEBP loader functionality ======
+
+#include "webp/decode.h"
+
+Image* LoadWEBPBuff( unsigned char* buffer, size_t buffer_length ){
+       int image_width;
+       int image_height;
+
+       if ( !WebPGetInfo( (byte *) buffer, buffer_length, &image_width, &image_height) ){
+               globalErrorStream() << "libwebp error: WebPGetInfo: can't get image info\n";
+               return 0;
+       }
+           
+       // allocate the pixel buffer
+       RGBAImage* image = new RGBAImage( image_width, image_height );
+       int out_stride = image_width  *sizeof(RGBAPixel);
+       int out_size =  image_height * out_stride;
+       
+        if ( !WebPDecodeRGBAInto( (byte *) buffer, buffer_length, image->getRGBAPixels(), out_size, out_stride ) )
+        {
+                return 0;
+        }
+
+       return image;
+}
+
+Image* LoadWEBP( ArchiveFile& file ){
+       ScopedArchiveBuffer buffer( file );
+       return LoadWEBPBuff( buffer.buffer, buffer.length );
+}
+
+
+#include "modulesystem/singletonmodule.h"
+
+
+class ImageDependencies : public GlobalFileSystemModuleRef
+{
+};
+
+class ImageWEBPAPI
+{
+_QERPlugImageTable m_imagewebp;
+public:
+typedef _QERPlugImageTable Type;
+STRING_CONSTANT( Name, "webp" );
+
+ImageWEBPAPI(){
+       m_imagewebp.loadImage = LoadWEBP;
+}
+_QERPlugImageTable* getTable(){
+       return &m_imagewebp;
+}
+};
+
+typedef SingletonModule<ImageWEBPAPI, ImageDependencies> ImageWEBPModule;
+
+ImageWEBPModule g_ImageWEBPModule;
+
+
+extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
+       initialiseModule( server );
+
+       g_ImageWEBPModule.selfRegister();
+}
diff --git a/plugins/imagewebp/plugin.h b/plugins/imagewebp/plugin.h
new file mode 100644 (file)
index 0000000..28a2933
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+   Copyright (C) 1999-2006 Id Software, Inc. and contributors.
+   For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+   This file is part of NetRadiant.
+
+   NetRadiant is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   NetRadiant is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with NetRadiant; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#if !defined( INCLUDED_PLUGIN_H )
+#define INCLUDED_PLUGIN_H
+
+#endif
index 2dfc9ef98c5c99abbf4b8526e9423e0e941186cd..b1e8e67b3dd8fbd29af0d142a6147908db94b6a5 100644 (file)
@@ -22,6 +22,9 @@ include_directories(${JPEG_INCLUDE_DIR})
 find_package(PNG REQUIRED)
 include_directories(${PNG_INCLUDE_DIR})
 
+find_package(WebP REQUIRED)
+include_directories(${WEBP_INCLUDE_DIR})
+
 find_package(LibXml2 REQUIRED)
 include_directories(${LIBXML2_INCLUDE_DIR})
 
@@ -135,6 +138,7 @@ target_link_libraries(q3map2
         ${GLIB_LIBRARIES}
         ${JPEG_LIBRARIES}
         ${PNG_LIBRARIES}
+        ${WEBP_LIBRARIES}
         ${LIBXML2_LIBRARIES}
         ${Minizip_LIBRARIES}
         ${ZLIB_LIBRARIES}
index 1732867b6ca0aac13d825406cf7e66fe2346c44c..91f4aae93ada5b7eba79eb5bc989daf51c87f182 100644 (file)
@@ -36,7 +36,7 @@
 /* dependencies */
 #include "q3map2.h"
 
-
+#include "webp/decode.h"
 
 /* -------------------------------------------------------------------------------
 
@@ -248,6 +248,34 @@ static void LoadPNGBuffer( byte *buffer, int size, byte **pixels, int *width, in
 
 
 
+static void LoadWEBPBuffer( byte *buffer, int size, byte **pixels, int *width, int *height ){
+
+       int image_width;
+       int image_height;
+       
+       if ( !WebPGetInfo( buffer, ( size_t) size, &image_width, &image_height ) )
+       {
+               Sys_Printf( "WARNING: An error occurred reading WEBP image info\n" );
+               return;
+       }
+
+       /* create image pixel buffer */
+       *pixels = safe_malloc( image_width * image_height * 4 );
+       *width = image_width;
+       *height = image_height;
+
+       int out_stride = image_width  * 4;
+       int out_size =  image_height * out_stride;
+
+               if ( !WebPDecodeRGBAInto( buffer, (size_t) size, *pixels, out_size, out_stride ) )
+               {
+               Sys_FPrintf( SYS_WRN, "WARNING: An error occurred reading WEBP image\n" );
+                       return;
+               }
+}
+
+
+
 /*
    ImageInit()
    implicitly called by every function to set up image list
@@ -404,78 +432,71 @@ image_t *ImageLoad( const char *filename ){
        size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
        if ( size > 0 ) {
                LoadTGABuffer( buffer, buffer + size, &image->pixels, &image->width, &image->height );
+               goto image_load_success;
        }
-       else
-       {
-               /* attempt to load png */
-               StripExtension( name );
-               strcat( name, ".png" );
-               size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
-               if ( size > 0 ) {
-                       LoadPNGBuffer( buffer, size, &image->pixels, &image->width, &image->height );
-               }
-               else
-               {
-                       /* attempt to load jpg */
-                       StripExtension( name );
-                       strcat( name, ".jpg" );
-                       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 ) {
-                                       // On error, LoadJPGBuff might store a pointer to the error message in image->pixels
-                                       Sys_FPrintf( SYS_WRN, "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels );
-                               }
-                               alphaHack = qtrue;
-                       }
-                       else
-                       {
-                               /* attempt to load dds */
-                               StripExtension( name );
-                               strcat( name, ".dds" );
-                               size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
-                               if ( size > 0 ) {
-                                       LoadDDSBuffer( buffer, size, &image->pixels, &image->width, &image->height );
-
-                                       /* debug code */
-                                       #if 1
-                                       {
-                                               ddsPF_t pf;
-                                               DDSGetInfo( (ddsBuffer_t*) buffer, NULL, NULL, &pf );
-                                               Sys_Printf( "pf = %d\n", pf );
-                                               if ( image->width > 0 ) {
-                                                       StripExtension( name );
-                                                       strcat( name, "_converted.tga" );
-                                                       WriteTGA( "C:\\games\\quake3\\baseq3\\textures\\rad\\dds_converted.tga", image->pixels, image->width, image->height );
-                                               }
-                                       }
-                                       #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 );
-                                       }
-                                       #ifdef BUILD_CRUNCH
-                                       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 );
-                                               }
-                                       }
-                                       #endif // BUILD_CRUNCH
-                               }
-                       }
+
+       /* attempt to load png */
+       StripExtension( name );
+       strcat( name, ".png" );
+       size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+       if ( size > 0 ) {
+               LoadPNGBuffer( buffer, size, &image->pixels, &image->width, &image->height );
+               goto image_load_success;
+       }
+
+       /* attempt to load jpg */
+       StripExtension( name );
+       strcat( name, ".jpg" );
+       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 ) {
+                       // On error, LoadJPGBuff might store a pointer to the error message in image->pixels
+                       Sys_FPrintf( SYS_WRN, "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels );
                }
+               alphaHack = qtrue;
+               goto image_load_success;
        }
 
+       /* attempt to load dds */
+       StripExtension( name );
+       strcat( name, ".dds" );
+       size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+       if ( size > 0 ) {
+               LoadDDSBuffer( buffer, size, &image->pixels, &image->width, &image->height );
+               goto image_load_success;
+       }
+
+       /* 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 );
+               goto image_load_success;
+       }
+
+       #ifdef BUILD_CRUNCH
+       /* 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 );
+               goto image_load_success;
+       }
+       #endif // BUILD_CRUNCH
+
+       /* attempt to load webp */
+       StripExtension( name );
+       strcat( name, ".webp" );
+       size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+       if ( size > 0 ) {
+               LoadWEBPBuffer( buffer, size, &image->pixels, &image->width, &image->height );
+               goto image_load_success;
+       }
+
+       image_load_success:
+
        /* free file buffer */
        free( buffer );