2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of NetRadiant.
7 NetRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 NetRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with NetRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "debugging/debugging.h"
24 #include "ifilesystem.h"
29 // ====== WEBP loader functionality ======
31 #include "webp/decode.h"
33 Image* LoadWEBPBuff( unsigned char* buffer, size_t buffer_length ){
37 if ( !WebPGetInfo( (byte *) buffer, buffer_length, &image_width, &image_height) ){
38 globalErrorStream() << "libwebp error: WebPGetInfo: can't get image info\n";
42 // allocate the pixel buffer
43 RGBAImage* image = new RGBAImage( image_width, image_height );
44 int out_stride = image_width *sizeof(RGBAPixel);
45 int out_size = image_height * out_stride;
47 if ( !WebPDecodeRGBAInto( (byte *) buffer, buffer_length, image->getRGBAPixels(), out_size, out_stride ) )
55 Image* LoadWEBP( ArchiveFile& file ){
56 ScopedArchiveBuffer buffer( file );
57 return LoadWEBPBuff( buffer.buffer, buffer.length );
61 #include "modulesystem/singletonmodule.h"
64 class ImageDependencies : public GlobalFileSystemModuleRef
70 _QERPlugImageTable m_imagewebp;
72 typedef _QERPlugImageTable Type;
73 STRING_CONSTANT( Name, "webp" );
76 m_imagewebp.loadImage = LoadWEBP;
78 _QERPlugImageTable* getTable(){
83 typedef SingletonModule<ImageWEBPAPI, ImageDependencies> ImageWEBPModule;
85 ImageWEBPModule g_ImageWEBPModule;
88 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
89 initialiseModule( server );
91 g_ImageWEBPModule.selfRegister();