Skip to content

Commit

Permalink
LibGfx: Remove TGA image format support
Browse files Browse the repository at this point in the history
This format is not supported by other browsers.
  • Loading branch information
awesomekling committed Jun 17, 2024
1 parent 681a2ac commit b7f8d7a
Show file tree
Hide file tree
Showing 16 changed files with 1 addition and 366 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 0 additions & 20 deletions Meta/Lagom/Fuzzers/FuzzTGALoader.cpp

This file was deleted.

2 changes: 0 additions & 2 deletions Meta/Lagom/Fuzzers/fuzzers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ set(FUZZER_TARGETS
SHA512
Tar
TextDecoder
TGALoader
TIFFLoader
TTF
TinyVGLoader
Expand Down Expand Up @@ -97,7 +96,6 @@ set(FUZZER_DEPENDENCIES_SHA384 LibCrypto)
set(FUZZER_DEPENDENCIES_SHA512 LibCrypto)
set(FUZZER_DEPENDENCIES_Tar LibArchive)
set(FUZZER_DEPENDENCIES_TextDecoder LibTextCodec)
set(FUZZER_DEPENDENCIES_TGALoader LibGfx)
set(FUZZER_DEPENDENCIES_TIFFLoader LibGfx)
set(FUZZER_DEPENDENCIES_TTF LibGfx)
set(FUZZER_DEPENDENCIES_TinyVGLoader LibGfx)
Expand Down
1 change: 0 additions & 1 deletion Meta/gn/secondary/Userland/Libraries/LibGfx/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ shared_library("LibGfx") {
"ImageFormats/PNGLoader.cpp",
"ImageFormats/PNGWriter.cpp",
"ImageFormats/QMArithmeticDecoder.cpp",
"ImageFormats/TGALoader.cpp",
"ImageFormats/TIFFLoader.cpp",
"ImageFormats/TinyVGLoader.cpp",
"ImageFormats/WebPLoader.cpp",
Expand Down
37 changes: 0 additions & 37 deletions Tests/LibGfx/TestImageDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <LibGfx/ImageFormats/JPEGXLLoader.h>
#include <LibGfx/ImageFormats/PNGLoader.h>
#include <LibGfx/ImageFormats/QMArithmeticDecoder.h>
#include <LibGfx/ImageFormats/TGALoader.h>
#include <LibGfx/ImageFormats/TIFFLoader.h>
#include <LibGfx/ImageFormats/TIFFMetadata.h>
#include <LibGfx/ImageFormats/TinyVGLoader.h>
Expand Down Expand Up @@ -726,42 +725,6 @@ TEST_CASE(test_png_malformed_frame)
}
}

TEST_CASE(test_targa_bottom_left)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-uncompressed.tga"sv)));
EXPECT(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));

TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
}

TEST_CASE(test_targa_top_left)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-uncompressed.tga"sv)));
EXPECT(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));

TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
}

TEST_CASE(test_targa_bottom_left_compressed)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-compressed.tga"sv)));
EXPECT(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));

TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
}

TEST_CASE(test_targa_top_left_compressed)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-compressed.tga"sv)));
EXPECT(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes()));

TRY_OR_FAIL(expect_single_frame(*plugin_decoder));
}

TEST_CASE(test_tiff_uncompressed)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tiff/uncompressed.tiff"sv)));
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion Userland/Libraries/LibGfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ set(SOURCES
ImageFormats/PNGLoader.cpp
ImageFormats/PNGWriter.cpp
ImageFormats/QMArithmeticDecoder.cpp
ImageFormats/TGALoader.cpp
ImageFormats/TIFFLoader.cpp
ImageFormats/TinyVGLoader.cpp
ImageFormats/WebPLoader.cpp
Expand Down
31 changes: 1 addition & 30 deletions Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <LibGfx/ImageFormats/JPEGLoader.h>
#include <LibGfx/ImageFormats/JPEGXLLoader.h>
#include <LibGfx/ImageFormats/PNGLoader.h>
#include <LibGfx/ImageFormats/TGALoader.h>
#include <LibGfx/ImageFormats/TIFFLoader.h>
#include <LibGfx/ImageFormats/TinyVGLoader.h>
#include <LibGfx/ImageFormats/WebPLoader.h>
Expand Down Expand Up @@ -53,39 +52,11 @@ static ErrorOr<OwnPtr<ImageDecoderPlugin>> probe_and_sniff_for_appropriate_plugi
return OwnPtr<ImageDecoderPlugin> {};
}

static ErrorOr<OwnPtr<ImageDecoderPlugin>> probe_and_sniff_for_appropriate_plugin_with_known_mime_type(StringView mime_type, ReadonlyBytes bytes)
{
struct ImagePluginWithMIMETypeInitializer {
bool (*validate_before_create)(ReadonlyBytes) = nullptr;
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> (*create)(ReadonlyBytes) = nullptr;
StringView mime_type;
};

static constexpr ImagePluginWithMIMETypeInitializer s_initializers_with_mime_type[] = {
{ TGAImageDecoderPlugin::validate_before_create, TGAImageDecoderPlugin::create, "image/x-targa"sv },
};

for (auto& plugin : s_initializers_with_mime_type) {
if (plugin.mime_type != mime_type)
continue;
auto validation_result = plugin.validate_before_create(bytes);
if (!validation_result)
continue;
return TRY(plugin.create(bytes));
}
return OwnPtr<ImageDecoderPlugin> {};
}

ErrorOr<RefPtr<ImageDecoder>> ImageDecoder::try_create_for_raw_bytes(ReadonlyBytes bytes, Optional<ByteString> mime_type)
ErrorOr<RefPtr<ImageDecoder>> ImageDecoder::try_create_for_raw_bytes(ReadonlyBytes bytes, [[maybe_unused]] Optional<ByteString> mime_type)
{
if (auto plugin = TRY(probe_and_sniff_for_appropriate_plugin(bytes)); plugin)
return adopt_ref_if_nonnull(new (nothrow) ImageDecoder(plugin.release_nonnull()));

if (mime_type.has_value()) {
if (OwnPtr<ImageDecoderPlugin> plugin = TRY(probe_and_sniff_for_appropriate_plugin_with_known_mime_type(mime_type.value(), bytes)); plugin)
return adopt_ref_if_nonnull(new (nothrow) ImageDecoder(plugin.release_nonnull()));
}

return RefPtr<ImageDecoder> {};
}

Expand Down
242 changes: 0 additions & 242 deletions Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp

This file was deleted.

Loading

0 comments on commit b7f8d7a

Please sign in to comment.