Skip to content

Commit

Permalink
LibGfx: Remove JPEG2000 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 a34a5af commit 1039acc
Show file tree
Hide file tree
Showing 26 changed files with 0 additions and 2,261 deletions.
4 changes: 0 additions & 4 deletions AK/Debug.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@
# cmakedefine01 JOB_DEBUG
#endif

#ifndef JPEG2000_DEBUG
# cmakedefine01 JPEG2000_DEBUG
#endif

#ifndef JS_BYTECODE_DEBUG
# cmakedefine01 JS_BYTECODE_DEBUG
#endif
Expand Down
1 change: 0 additions & 1 deletion Meta/CMake/all_the_debug_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ set(IDL_DEBUG ON)
set(IMAGE_DECODER_DEBUG ON)
set(IMAGE_LOADER_DEBUG ON)
set(JOB_DEBUG ON)
set(JPEG2000_DEBUG ON)
set(JS_BYTECODE_DEBUG ON)
set(JS_MODULE_DEBUG ON)
set(LEXER_DEBUG ON)
Expand Down
1 change: 0 additions & 1 deletion Meta/Lagom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ endif()

lagom_utility(icc SOURCES ../../Userland/Utilities/icc.cpp LIBS LibGfx LibMain LibURL)
lagom_utility(image SOURCES ../../Userland/Utilities/image.cpp LIBS LibGfx LibMain)
lagom_utility(isobmff SOURCES ../../Userland/Utilities/isobmff.cpp LIBS LibGfx LibMain)
lagom_utility(ttfdisasm SOURCES ../../Userland/Utilities/ttfdisasm.cpp LIBS LibGfx LibMain)
lagom_utility(js SOURCES ../../Userland/Utilities/js.cpp LIBS LibCrypto LibJS LibLine LibLocale LibMain LibTextCodec Threads::Threads)

Expand Down
20 changes: 0 additions & 20 deletions Meta/Lagom/Fuzzers/FuzzJPEG2000Loader.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 @@ -13,7 +13,6 @@ set(FUZZER_TARGETS
HttpRequest
ICCProfile
ICOLoader
JPEG2000Loader
JPEGLoader
Js
JsonParser
Expand Down Expand Up @@ -70,7 +69,6 @@ set(FUZZER_DEPENDENCIES_GzipRoundtrip LibCompress)
set(FUZZER_DEPENDENCIES_HttpRequest LibHTTP)
set(FUZZER_DEPENDENCIES_ICCProfile LibGfx)
set(FUZZER_DEPENDENCIES_ICOLoader LibGfx)
set(FUZZER_DEPENDENCIES_JPEG2000Loader LibGfx)
set(FUZZER_DEPENDENCIES_JPEGLoader LibGfx)
set(FUZZER_DEPENDENCIES_Js LibJS)
set(FUZZER_DEPENDENCIES_LzmaDecompression LibArchive LibCompress)
Expand Down
1 change: 0 additions & 1 deletion Meta/gn/secondary/AK/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ write_cmake_config("ak_debug_gen") {
"IMAGE_DECODER_DEBUG=",
"IMAGE_LOADER_DEBUG=",
"JOB_DEBUG=",
"JPEG2000_DEBUG=",
"JS_BYTECODE_DEBUG=",
"JS_MODULE_DEBUG=",
"LEXER_DEBUG=",
Expand Down
4 changes: 0 additions & 4 deletions Meta/gn/secondary/Userland/Libraries/LibGfx/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ shared_library("LibGfx") {
"ImageFormats/CCITTDecoder.cpp",
"ImageFormats/GIFLoader.cpp",
"ImageFormats/ICOLoader.cpp",
"ImageFormats/ISOBMFF/Boxes.cpp",
"ImageFormats/ISOBMFF/JPEG2000Boxes.cpp",
"ImageFormats/ISOBMFF/Reader.cpp",
"ImageFormats/ImageDecoder.cpp",
"ImageFormats/JPEG2000Loader.cpp",
"ImageFormats/JPEGLoader.cpp",
"ImageFormats/JPEGWriter.cpp",
"ImageFormats/JPEGXLLoader.cpp",
Expand Down
1 change: 0 additions & 1 deletion Tests/LibGfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set(TEST_SOURCES
TestImageWriter.cpp
TestMedianCut.cpp
TestPainter.cpp
TestParseISOBMFF.cpp
TestRect.cpp
TestScalingFunctions.cpp
TestWOFF.cpp
Expand Down
132 changes: 0 additions & 132 deletions Tests/LibGfx/TestImageDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <LibGfx/ImageFormats/GIFLoader.h>
#include <LibGfx/ImageFormats/ICOLoader.h>
#include <LibGfx/ImageFormats/ImageDecoder.h>
#include <LibGfx/ImageFormats/JPEG2000Loader.h>
#include <LibGfx/ImageFormats/JPEGLoader.h>
#include <LibGfx/ImageFormats/JPEGXLLoader.h>
#include <LibGfx/ImageFormats/PNGLoader.h>
Expand Down Expand Up @@ -334,137 +333,6 @@ TEST_CASE(test_jpeg_malformed_frame)
}
}

TEST_CASE(test_jpeg2000_spec_annex_j_10)
{
// J.10 An example of decoding showing intermediate steps
// clang-format off
constexpr Array data = to_array<u8>({
0xFF, 0x4F, 0xFF, 0x51, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x01, 0xFF, 0x5C, 0x00,
0x07, 0x40, 0x40, 0x48, 0x48, 0x50, 0xFF, 0x52, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
0x04, 0x04, 0x00, 0x01, 0xFF, 0x90, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x01,
0xFF, 0x93, 0xC7, 0xd4, 0x0C, 0x01, 0x8F, 0x0D, 0xC8, 0x75, 0x5D, 0xC0, 0x7C, 0x21, 0x80, 0x0F,
0xB1, 0x76, 0xFF, 0xD9,
});
// clang-format on

auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEG2000ImageDecoderPlugin::create(data));
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(1, 9));

// FIXME: Do something with this.
// For now, this is useful for debugging:
// `Build/lagom/bin/TestImageDecoder test_jpeg2000_spec_annex_j_10` prints internal state with JPEG2000_DEBUG=1.
(void)plugin_decoder->frame(0);
}

TEST_CASE(test_jpeg2000_simple)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpeg2000/simple.jp2"sv)));
EXPECT(Gfx::JPEG2000ImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEG2000ImageDecoderPlugin::create(file->bytes()));

EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(119, 101));

auto icc_bytes = MUST(plugin_decoder->icc_data());
EXPECT(icc_bytes.has_value());
EXPECT_EQ(icc_bytes->size(), 3144u);
}

TEST_CASE(test_jpeg2000_gray)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jpeg2000/buggie-gray.jpf"sv)));
EXPECT(Gfx::JPEG2000ImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEG2000ImageDecoderPlugin::create(file->bytes()));

EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(64, 138));

// The file contains both a simple and a real profile. Make sure we get the bigger one.
auto icc_bytes = MUST(plugin_decoder->icc_data());
EXPECT(icc_bytes.has_value());
EXPECT_EQ(icc_bytes->size(), 912u);
}

TEST_CASE(test_jpeg2000_tag_tree)
{
{
// The example from the NOTE at the end of B.10.2 Tag trees:
auto tree = TRY_OR_FAIL(Gfx::JPEG2000::TagTree::create(6, 3));
auto bits = to_array<u8>({
0, 1, 1, 1, 1, // q3(0, 0)
0, 0, 1, // q3(1, 0)
1, 0, 1, // q3(2, 0)
});
size_t index = 0;
Function<ErrorOr<bool>()> read_bit = [&]() -> bool {
return bits[index++];
};
EXPECT_EQ(1u, MUST(tree.read_value(0, 0, read_bit)));
EXPECT_EQ(index, 5u);
EXPECT_EQ(3u, MUST(tree.read_value(1, 0, read_bit)));
EXPECT_EQ(index, 8u);
EXPECT_EQ(2u, MUST(tree.read_value(2, 0, read_bit)));
EXPECT_EQ(index, 11u);
}

{
// The inclusion tag tree bits from Table B.5 – Example packet header bit stream.
auto tree = TRY_OR_FAIL(Gfx::JPEG2000::TagTree::create(3, 2));
auto bits = to_array<u8>({
1, 1, 1, // Code-block 0, 0 included for the first time (partial inclusion tag tree)
1, // Code-block 1, 0 included for the first time (partial inclusion tag tree)
0, // Code-block 2, 0 not yet included (partial tag tree)
0, // Code-block 0, 1 not yet included
0, // Code-block 1, 2 not yet included
// Code-block 2, 1 not yet included (no data needed, already conveyed by partial tag tree for code-block 2, 0)
});
size_t index = 0;
Function<ErrorOr<bool>()> read_bit = [&]() -> bool {
return bits[index++];
};
u32 next_layer = 1;
EXPECT_EQ(0u, MUST(tree.read_value(0, 0, read_bit, next_layer)));
EXPECT_EQ(index, 3u);
EXPECT_EQ(0u, MUST(tree.read_value(1, 0, read_bit, next_layer)));
EXPECT_EQ(index, 4u);
EXPECT_EQ(1u, MUST(tree.read_value(2, 0, read_bit, next_layer)));
EXPECT_EQ(index, 5u);
EXPECT_EQ(1u, MUST(tree.read_value(0, 1, read_bit, next_layer)));
EXPECT_EQ(index, 6u);
EXPECT_EQ(1u, MUST(tree.read_value(1, 1, read_bit, next_layer)));
EXPECT_EQ(index, 7u);
EXPECT_EQ(1u, MUST(tree.read_value(2, 1, read_bit, next_layer)));
EXPECT_EQ(index, 7u); // Didn't change!
}

{
// This isn't in the spec. If one dimension is 2^n + 1 and the other side is just 1, then the topmost node will have
// 2^n x 1 and 1 x 1 children. The first child will have n levels of children. The 1 x 1 child could end immediately,
// or it could require that it also has n levels of (all 1 x 1) children. The spec isn't clear on which of
// the two alternatives should happen. We currently have n levels of 1 x 1 blocks.
constexpr auto n = 5;
auto tree = TRY_OR_FAIL(Gfx::JPEG2000::TagTree::create((1 << n) + 1, 1));
Vector<u8> bits;
bits.append(1); // Finalize topmost node.
bits.append(0); // Increment value in 1 x 1 child.
bits.append(1); // Finalize 1 x 1 child.

// Finalize further 1 x 1 children, if present.
for (size_t i = 0; i < n; ++i)
bits.append(1);

size_t index = 0;
Function<ErrorOr<bool>()> read_bit = [&]() -> bool {
return bits[index++];
};

EXPECT_EQ(1u, MUST(tree.read_value(1 << n, 0, read_bit)));

// This will read either 3 or 3 + n bits, depending on the interpretation.
EXPECT_EQ(index, 3u + n);
}
}

TEST_CASE(test_png)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("png/buggie.png"sv)));
Expand Down
37 changes: 0 additions & 37 deletions Tests/LibGfx/TestParseISOBMFF.cpp

This file was deleted.

Binary file removed Tests/LibGfx/test-inputs/jpeg2000/buggie-gray.jpf
Binary file not shown.
Binary file removed Tests/LibGfx/test-inputs/jpeg2000/simple.jp2
Binary file not shown.
4 changes: 0 additions & 4 deletions Userland/Libraries/LibGfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ set(SOURCES
ImageFormats/GIFWriter.cpp
ImageFormats/ICOLoader.cpp
ImageFormats/ImageDecoder.cpp
ImageFormats/ISOBMFF/Boxes.cpp
ImageFormats/ISOBMFF/JPEG2000Boxes.cpp
ImageFormats/ISOBMFF/Reader.cpp
ImageFormats/JPEG2000Loader.cpp
ImageFormats/JPEGLoader.cpp
ImageFormats/JPEGXLLoader.cpp
ImageFormats/JPEGWriter.cpp
Expand Down
49 changes: 0 additions & 49 deletions Userland/Libraries/LibGfx/ImageFormats/ISOBMFF/BoxStream.h

This file was deleted.

Loading

0 comments on commit 1039acc

Please sign in to comment.