mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-02 15:46:33 +00:00
TestImageWriter: Add a PNG roundtrip test
This commit is contained in:
parent
aefab64984
commit
0a26831a10
Notes:
sideshowbarker
2024-07-17 02:29:45 +09:00
Author: https://github.com/nico
Commit: 0a26831a10
Pull-request: https://github.com/SerenityOS/serenity/pull/24245
Reviewed-by: https://github.com/LucasChollet ✅
1 changed files with 16 additions and 3 deletions
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include <AK/MemoryStream.h>
|
#include <AK/MemoryStream.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
|
#include <LibGfx/ImageFormats/PNGLoader.h>
|
||||||
|
#include <LibGfx/ImageFormats/PNGWriter.h>
|
||||||
#include <LibGfx/ImageFormats/WebPLoader.h>
|
#include <LibGfx/ImageFormats/WebPLoader.h>
|
||||||
#include <LibGfx/ImageFormats/WebPWriter.h>
|
#include <LibGfx/ImageFormats/WebPWriter.h>
|
||||||
#include <LibTest/TestCase.h>
|
#include <LibTest/TestCase.h>
|
||||||
|
@ -32,9 +34,14 @@ static ErrorOr<NonnullRefPtr<Gfx::Bitmap>> expect_single_frame_of_size(Gfx::Imag
|
||||||
template<class Writer, class Loader>
|
template<class Writer, class Loader>
|
||||||
static ErrorOr<void> test_roundtrip(Gfx::Bitmap const& bitmap)
|
static ErrorOr<void> test_roundtrip(Gfx::Bitmap const& bitmap)
|
||||||
{
|
{
|
||||||
AllocatingMemoryStream stream;
|
ByteBuffer encoded_data;
|
||||||
TRY(Writer::encode(stream, bitmap));
|
if constexpr (requires(AllocatingMemoryStream stream) { Writer::encode(stream, bitmap); }) {
|
||||||
auto encoded_data = TRY(stream.read_until_eof());
|
AllocatingMemoryStream stream;
|
||||||
|
TRY(Writer::encode(stream, bitmap));
|
||||||
|
encoded_data = TRY(stream.read_until_eof());
|
||||||
|
} else {
|
||||||
|
encoded_data = TRY(Writer::encode(bitmap));
|
||||||
|
}
|
||||||
|
|
||||||
auto plugin = TRY(Loader::create(encoded_data));
|
auto plugin = TRY(Loader::create(encoded_data));
|
||||||
auto decoded = TRY(expect_single_frame_of_size(*plugin, bitmap.size()));
|
auto decoded = TRY(expect_single_frame_of_size(*plugin, bitmap.size()));
|
||||||
|
@ -72,6 +79,12 @@ static ErrorOr<AK::NonnullRefPtr<Gfx::Bitmap>> create_test_rgba_bitmap()
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(test_png)
|
||||||
|
{
|
||||||
|
TRY_OR_FAIL((test_roundtrip<Gfx::PNGWriter, Gfx::PNGImageDecoderPlugin>(TRY_OR_FAIL(create_test_rgb_bitmap()))));
|
||||||
|
TRY_OR_FAIL((test_roundtrip<Gfx::PNGWriter, Gfx::PNGImageDecoderPlugin>(TRY_OR_FAIL(create_test_rgba_bitmap()))));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE(test_webp)
|
TEST_CASE(test_webp)
|
||||||
{
|
{
|
||||||
TRY_OR_FAIL((test_roundtrip<Gfx::WebPWriter, Gfx::WebPImageDecoderPlugin>(TRY_OR_FAIL(create_test_rgb_bitmap()))));
|
TRY_OR_FAIL((test_roundtrip<Gfx::WebPWriter, Gfx::WebPImageDecoderPlugin>(TRY_OR_FAIL(create_test_rgb_bitmap()))));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue