Merge pull request #2339 from MikuAuahDark/swebp

Add WebP Image Support
This commit is contained in:
Sasha Szpakowski
2026-07-29 22:38:56 -03:00
committed by GitHub
6 changed files with 5813 additions and 4 deletions
+11
View File
@@ -756,6 +756,8 @@ add_library(love_image_magpie STATIC
src/modules/image/magpie/STBHandler.h
src/modules/image/magpie/QOIHandler.cpp
src/modules/image/magpie/QOIHandler.h
src/modules/image/magpie/WEBPHandler.cpp
src/modules/image/magpie/WEBPHandler.h
)
target_link_libraries(love_image_magpie PUBLIC
lovedep::Zlib
@@ -1878,6 +1880,15 @@ add_library(love_3p_xxhash
src/libraries/xxHash/xxhash.h
)
#
# Simple WebP
#
# Simple has no implementation files of its own.
#add_library(love_3p_simplewebp
# src/libraries/simplewebp/simplewebp.h
#)
#
# liblove
#
+10 -4
View File
@@ -109,11 +109,17 @@ This distribution contains code from the following projects (full license text b
License: MIT/Expat
Copyright (c) 2017 Sean Barrett
- simplewebp
Website: https://github.com/MikuAuahDark/simplewebp
Source download: https://github.com/MikuAuahDark/simplewebp/blob/d1a728a1f8ec7348ca2a5039b6dd813b83986fbb/simplewebp.h
License: 3-Clause BSD
Copyright (c) 2010 Google Inc., 2023 Miku AuahDark
- qoi
Website: https://qoiformat.org/
Source download: https://github.com/phoboslab/qoi/blob/97bacc86a9c4abf5a2d452102dc26546c4c670b9/qoi.h
Licence: MIT
Copyright (c) 2022 Dominic Szablewski
Website: https://qoiformat.org/
Source download: https://github.com/phoboslab/qoi/blob/97bacc86a9c4abf5a2d452102dc26546c4c670b9/qoi.h
Licence: MIT
Copyright (c) 2022 Dominic Szablewski
- OpenAL Soft
Website: https://openal-soft.org/
File diff suppressed because it is too large Load Diff
+2
View File
@@ -26,6 +26,7 @@
#include "magpie/STBHandler.h"
#include "magpie/EXRHandler.h"
#include "magpie/QOIHandler.h"
#include "magpie/WEBPHandler.h"
#include "magpie/ddsHandler.h"
#include "magpie/PVRHandler.h"
@@ -51,6 +52,7 @@ Image::Image()
new PNGHandler,
new STBHandler,
new EXRHandler,
new WEBPHandler,
new DDSHandler,
new PVRHandler,
new KTXHandler,
+92
View File
@@ -0,0 +1,92 @@
/**
* Copyright (c) 2006-2026 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "WEBPHandler.h"
// LOVE
#include "common/Exception.h"
// C++
#include <new>
// Simple WebP
#define SIMPLEWEBP_IMPLEMENTATION
#include "simplewebp/simplewebp.h"
namespace love
{
namespace image
{
namespace magpie
{
bool WEBPHandler::canDecode(Data *data)
{
simplewebp *swebp = nullptr;
simplewebp_error err = simplewebp_load_from_memory(data->getData(), data->getSize(), nullptr, &swebp);
if (err == SIMPLEWEBP_NO_ERROR)
simplewebp_unload(swebp);
return swebp != nullptr;
}
WEBPHandler::DecodedImage WEBPHandler::decode(Data *data)
{
simplewebp *swebp = nullptr;
simplewebp_error err = simplewebp_load_from_memory(data->getData(), data->getSize(), nullptr, &swebp);
if (err != SIMPLEWEBP_NO_ERROR)
throw love::Exception("Could not decode WebP image (%s)", simplewebp_get_error_text(err));
size_t width, height;
simplewebp_get_dimensions(swebp, &width, &height);
size_t imagesize = width * height * 4;
unsigned char *buf = new (std::nothrow) unsigned char[imagesize];
if (!buf)
throw love::Exception("Could not decode WebP image (not enough memory)");
err = simplewebp_decode(swebp, buf, nullptr);
simplewebp_unload(swebp);
if (err != SIMPLEWEBP_NO_ERROR)
{
delete[] buf;
throw love::Exception("Could not decode WebP image (%s)", simplewebp_get_error_text(err));
}
WEBPHandler::DecodedImage output;
output.data = buf;
output.width = (int) width;
output.height = (int) height;
output.size = imagesize;
output.format = PIXELFORMAT_RGBA8_UNORM;
return output;
}
void WEBPHandler::freeRawPixels(unsigned char *mem)
{
delete[] mem;
}
} // magpie
} // image
} // love
+47
View File
@@ -0,0 +1,47 @@
/**
* Copyright (c) 2006-2026 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#pragma once
// LOVE
#include "image/FormatHandler.h"
namespace love
{
namespace image
{
namespace magpie
{
class WEBPHandler: public FormatHandler
{
public:
~WEBPHandler() override {};
// Implements FormatHandler.
bool canDecode(Data *data) override;
DecodedImage decode(Data *data) override;
void freeRawPixels(unsigned char *mem) override;
};
} // magpie
} // image
} // love