* .webp image format support

This commit is contained in:
Garux
2025-12-06 16:05:51 +05:00
parent 88e52d51b9
commit a7545a9917
10 changed files with 4927 additions and 1 deletions
+7
View File
@@ -607,6 +607,7 @@ $(INSTALLDIR)/q3map2.$(EXE): \
libetclib.$(A) \
libfilematch.$(A) \
libl_net.$(A) \
libwebplib.$(A) \
$(if $(findstring Win32,$(OS)),icons/q3map2.o,) \
| $(if $(findstring yes,$(ASSIMP_INTERNAL)),$(INSTALLDIR)/libassimp_.$(DLL),) \
@@ -864,6 +865,10 @@ libetclib.$(A): CPPFLAGS_EXTRA := -Ilibs
libetclib.$(A): \
libs/etclib.o \
libwebplib.$(A): CPPFLAGS_EXTRA := -Ilibs
libwebplib.$(A): \
libs/webplib/webplib.o \
$(INSTALLDIR)/radiant.$(EXE): LDFLAGS_EXTRA := $(MWINDOWS)
$(INSTALLDIR)/radiant.$(EXE): LIBS_EXTRA := $(LIBS_GL) $(LIBS_DL) $(LIBS_XML) $(LIBS_GLIB) $(LIBS_QTWIDGETS) $(LIBS_QTSVG) $(LIBS_ZLIB)
$(INSTALLDIR)/radiant.$(EXE): CPPFLAGS_EXTRA := $(CPPFLAGS_GL) $(CPPFLAGS_DL) $(CPPFLAGS_XML) $(CPPFLAGS_GLIB) $(CPPFLAGS_QTWIDGETS) $(CPPFLAGS_QTSVG) -Ilibs -Iinclude
@@ -1052,9 +1057,11 @@ $(INSTALLDIR)/modules/image.$(DLL): \
plugins/image/ktx.o \
plugins/image/pcx.o \
plugins/image/tga.o \
plugins/image/webp.o \
libcrnlib.$(A) \
libddslib.$(A) \
libetclib.$(A) \
libwebplib.$(A) \
$(INSTALLDIR)/modules/imageq2.$(DLL): CPPFLAGS_EXTRA := -Ilibs -Iinclude
$(INSTALLDIR)/modules/imageq2.$(DLL): \
+2
View File
@@ -196,6 +196,7 @@ Q3map2:
* volumetric merge of triangles for model autoclip in axial backplane, max extrude modes
* .crn image format support
* .dpk .dpkdir game archives support
* .webp image format support
@@ -1164,6 +1165,7 @@ misc...
* adjust icons in light GUI themes for better visibility
* .crn image format support
* .dpk .dpkdir game archives support
* .webp image format support
File diff suppressed because it is too large Load Diff
+35
View File
@@ -0,0 +1,35 @@
/*
Copyright (C) 2018, Unvanquished Developers
All Rights Reserved.
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 "webplib.h"
#define twp_IMPLEMENTATION
#include "tiny_webp.h"
bool GetWebpImageSize( const void *buffer, int length, int& width, int& height ) {
return twp_get_info_from_memory( const_cast<void*>( buffer ), length, &width, &height, nullptr, nullptr );
}
unsigned char* ConvertWebptoRGBA( const void *buffer, int length, int& width, int& height ) {
return twp_read_from_memory( const_cast<void*>( buffer ), length, &width, &height, twp_FORMAT_RGBA, 0 );
}
+25
View File
@@ -0,0 +1,25 @@
/*
Copyright (C) 2018, Unvanquished Developers
All Rights Reserved.
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
*/
#pragma once
bool GetWebpImageSize( const void *buffer, int length, int& width, int& height );
unsigned char* ConvertWebptoRGBA( const void *buffer, int length, int& width, int& height );
-1
View File
@@ -23,7 +23,6 @@
#include "crn.h"
#include "iarchive.h"
#include "idatastream.h"
#include "stream/textstream.h"
#include "crnlib/crnlib.h"
+22
View File
@@ -31,6 +31,7 @@
#include "dds.h"
#include "ktx.h"
#include "crn.h"
#include "webp.h"
#include "modulesystem/singletonmodule.h"
@@ -179,6 +180,26 @@ typedef SingletonModule<ImageCRNAPI, ImageDependencies> ImageCRNModule;
ImageCRNModule g_ImageCRNModule;
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 );
@@ -189,4 +210,5 @@ extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server
g_ImageDDSModule.selfRegister();
g_ImageKTXModule.selfRegister();
g_ImageCRNModule.selfRegister();
g_ImageWebpModule.selfRegister();
}
+45
View File
@@ -0,0 +1,45 @@
/*
Copyright (C) 2018, Unvanquished Developers
All Rights Reserved.
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 "webp.h"
#include "iarchive.h"
#include "stream/textstream.h"
#include "webplib/webplib.h"
#include "imagelib.h"
Image* LoadWebpBuff( const byte *buffer, int length ){
int width, height;
if ( unsigned char *img = ConvertWebptoRGBA( buffer, length, width, height ) ) {
auto *image = new RGBAImage( width, height );
memcpy( image->getRGBAPixels(), img, width * height * sizeof( *RGBAImage::pixels ) );
free( img );
return image;
}
return nullptr;
}
Image* LoadWebp( ArchiveFile& file ){
ScopedArchiveBuffer buffer( file );
return LoadWebpBuff( buffer.buffer, buffer.length );
}
+27
View File
@@ -0,0 +1,27 @@
/*
Copyright (C) 2018, Unvanquished Developers
All Rights Reserved.
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
*/
#pragma once
class Image;
class ArchiveFile;
Image* LoadWebp( ArchiveFile &file );
+5
View File
@@ -33,6 +33,7 @@
#include "png.h"
#include "ddslib.h"
#include "crnlib/crnlib.h"
#include "webplib/webplib.h"
@@ -347,6 +348,10 @@ const image_t *ImageLoad( const char *name ){
{
LoadCRNBuffer( buffer.data(), buffer.size(), &pixels, &width, &height );
}
else if( path_set_extension( filename, ".webp" ); ( buffer = vfsLoadFile( filename ) ) )
{
pixels = ConvertWebptoRGBA( buffer.data(), buffer.size(), width, height );
}
/* make sure everything's kosher */
if ( !buffer || width <= 0 || height <= 0 || pixels == nullptr ) {