diff options
author | Lucas CHOLLET <lucas.chollet@free.fr> | 2023-02-18 16:09:16 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-02-18 23:56:24 +0100 |
commit | 856d0202f2fb32df47a45844775c1dbba08c24a7 (patch) | |
tree | db86ff86ee8c07fce4e44d3bac2e6abdf8a59472 | |
parent | ab298ca106e0d2aba871cf8dae164e8fcfd7f90b (diff) | |
download | serenity-856d0202f2fb32df47a45844775c1dbba08c24a7.zip |
LibGfx: Rename `JPGLoader` to `JPEGLoader`
The patch also contains modifications on several classes, functions or
files that are related to the `JPGLoader`.
Renaming include:
- JPGLoader{.h, .cpp}
- JPGImageDecoderPlugin
- JPGLoadingContext
- JPG_DEBUG
- decode_jpg
- FuzzJPGLoader.cpp
- Few string literals or texts
-rw-r--r-- | AK/Debug.h.in | 4 | ||||
-rw-r--r-- | Base/usr/share/man/man1/image2bin.md | 2 | ||||
-rw-r--r-- | Meta/CMake/all_the_debug_macros.cmake | 2 | ||||
-rw-r--r-- | Meta/Lagom/Fuzzers/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Meta/Lagom/Fuzzers/FuzzJPEGLoader.cpp (renamed from Meta/Lagom/Fuzzers/FuzzJPGLoader.cpp) | 4 | ||||
-rw-r--r-- | Tests/LibGfx/TestICCProfile.cpp | 4 | ||||
-rw-r--r-- | Tests/LibGfx/TestImageDecoder.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/ImageDecoder.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/JPEGLoader.cpp (renamed from Userland/Libraries/LibGfx/JPGLoader.cpp) | 172 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/JPEGLoader.h (renamed from Userland/Libraries/LibGfx/JPGLoader.h) | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibPDF/Filter.cpp | 8 | ||||
-rw-r--r-- | Userland/Services/SpiceAgent/SpiceAgent.cpp | 10 | ||||
-rw-r--r-- | Userland/Utilities/test-fuzz.cpp | 6 |
14 files changed, 118 insertions, 118 deletions
diff --git a/AK/Debug.h.in b/AK/Debug.h.in index 295f3cc4ed..eb04cba8db 100644 --- a/AK/Debug.h.in +++ b/AK/Debug.h.in @@ -238,8 +238,8 @@ #cmakedefine01 JOB_DEBUG #endif -#ifndef JPG_DEBUG -#cmakedefine01 JPG_DEBUG +#ifndef JPEG_DEBUG +#cmakedefine01 JPEG_DEBUG #endif #ifndef JS_BYTECODE_DEBUG diff --git a/Base/usr/share/man/man1/image2bin.md b/Base/usr/share/man/man1/image2bin.md index 52623f24aa..061224c711 100644 --- a/Base/usr/share/man/man1/image2bin.md +++ b/Base/usr/share/man/man1/image2bin.md @@ -18,6 +18,6 @@ in a raw binary format for further examination. ```sh # Convert a PNG image to raw bitmap $ image2bin example.png > example.bin -# Convert a JPG image to raw bitmap +# Convert a JPEG image to raw bitmap $ image2bin another_example.jpg > another_example.bin ``` diff --git a/Meta/CMake/all_the_debug_macros.cmake b/Meta/CMake/all_the_debug_macros.cmake index 8e960ca465..8a5db2c19a 100644 --- a/Meta/CMake/all_the_debug_macros.cmake +++ b/Meta/CMake/all_the_debug_macros.cmake @@ -96,7 +96,7 @@ set(ISO9660_DEBUG ON) set(ISO9660_VERY_DEBUG ON) set(ITEM_RECTS_DEBUG ON) set(JOB_DEBUG ON) -set(JPG_DEBUG ON) +set(JPEG_DEBUG ON) set(JS_BYTECODE_DEBUG ON) set(JS_MODULE_DEBUG ON) set(KEYBOARD_DEBUG ON) diff --git a/Meta/Lagom/Fuzzers/CMakeLists.txt b/Meta/Lagom/Fuzzers/CMakeLists.txt index c3c7fc5205..9478721d27 100644 --- a/Meta/Lagom/Fuzzers/CMakeLists.txt +++ b/Meta/Lagom/Fuzzers/CMakeLists.txt @@ -32,7 +32,7 @@ add_simple_fuzzer(FuzzGzipCompression LibCompress) add_simple_fuzzer(FuzzGzipDecompression LibCompress) add_simple_fuzzer(FuzzICCProfile LibGfx) add_simple_fuzzer(FuzzICOLoader LibGfx) -add_simple_fuzzer(FuzzJPGLoader LibGfx) +add_simple_fuzzer(FuzzJPEGLoader LibGfx) add_simple_fuzzer(FuzzMatroskaReader LibVideo) add_simple_fuzzer(FuzzMD5 LibCrypto) add_simple_fuzzer(FuzzMP3Loader LibAudio) diff --git a/Meta/Lagom/Fuzzers/FuzzJPGLoader.cpp b/Meta/Lagom/Fuzzers/FuzzJPEGLoader.cpp index c9dc81de7a..c85de25cdd 100644 --- a/Meta/Lagom/Fuzzers/FuzzJPGLoader.cpp +++ b/Meta/Lagom/Fuzzers/FuzzJPEGLoader.cpp @@ -4,13 +4,13 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <LibGfx/JPGLoader.h> +#include <LibGfx/JPEGLoader.h> #include <stddef.h> #include <stdint.h> extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { - auto decoder_or_error = Gfx::JPGImageDecoderPlugin::create({ data, size }); + auto decoder_or_error = Gfx::JPEGImageDecoderPlugin::create({ data, size }); if (decoder_or_error.is_error()) return 0; auto decoder = decoder_or_error.release_value(); diff --git a/Tests/LibGfx/TestICCProfile.cpp b/Tests/LibGfx/TestICCProfile.cpp index 1ad04195cf..4db30ac133 100644 --- a/Tests/LibGfx/TestICCProfile.cpp +++ b/Tests/LibGfx/TestICCProfile.cpp @@ -6,7 +6,7 @@ #include <LibCore/MappedFile.h> #include <LibGfx/ICC/Profile.h> -#include <LibGfx/JPGLoader.h> +#include <LibGfx/JPEGLoader.h> #include <LibGfx/PNGLoader.h> #include <LibTest/TestCase.h> @@ -31,7 +31,7 @@ TEST_CASE(png) TEST_CASE(jpg) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("icc-v4.jpg"sv))); - auto jpg = MUST(Gfx::JPGImageDecoderPlugin::create(file->bytes())); + auto jpg = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); EXPECT(jpg->initialize()); auto icc_bytes = MUST(jpg->icc_data()); EXPECT(icc_bytes.has_value()); diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 58dc750e3e..b47fc2d5b2 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -11,7 +11,7 @@ #include <LibGfx/GIFLoader.h> #include <LibGfx/ICOLoader.h> #include <LibGfx/ImageDecoder.h> -#include <LibGfx/JPGLoader.h> +#include <LibGfx/JPEGLoader.h> #include <LibGfx/PBMLoader.h> #include <LibGfx/PGMLoader.h> #include <LibGfx/PNGLoader.h> @@ -88,8 +88,8 @@ TEST_CASE(test_bmp_embedded_in_ico) TEST_CASE(test_jpg) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("rgb24.jpg"sv))); - EXPECT(MUST(Gfx::JPGImageDecoderPlugin::sniff(file->bytes()))); - auto plugin_decoder = MUST(Gfx::JPGImageDecoderPlugin::create(file->bytes())); + EXPECT(MUST(Gfx::JPEGImageDecoderPlugin::sniff(file->bytes()))); + auto plugin_decoder = MUST(Gfx::JPEGImageDecoderPlugin::create(file->bytes())); EXPECT(plugin_decoder->initialize()); EXPECT(plugin_decoder->frame_count()); diff --git a/Userland/Libraries/LibGfx/CMakeLists.txt b/Userland/Libraries/LibGfx/CMakeLists.txt index c3fbb6f56f..3f5073ec8e 100644 --- a/Userland/Libraries/LibGfx/CMakeLists.txt +++ b/Userland/Libraries/LibGfx/CMakeLists.txt @@ -34,7 +34,7 @@ set(SOURCES ICC/TagTypes.cpp ICOLoader.cpp ImageDecoder.cpp - JPGLoader.cpp + JPEGLoader.cpp PBMLoader.cpp PGMLoader.cpp PNGLoader.cpp diff --git a/Userland/Libraries/LibGfx/ImageDecoder.cpp b/Userland/Libraries/LibGfx/ImageDecoder.cpp index ad0feaa6df..3395a55bd9 100644 --- a/Userland/Libraries/LibGfx/ImageDecoder.cpp +++ b/Userland/Libraries/LibGfx/ImageDecoder.cpp @@ -10,7 +10,7 @@ #include <LibGfx/GIFLoader.h> #include <LibGfx/ICOLoader.h> #include <LibGfx/ImageDecoder.h> -#include <LibGfx/JPGLoader.h> +#include <LibGfx/JPEGLoader.h> #include <LibGfx/PBMLoader.h> #include <LibGfx/PGMLoader.h> #include <LibGfx/PNGLoader.h> @@ -33,7 +33,7 @@ static constexpr ImagePluginInitializer s_initializers[] = { { PGMImageDecoderPlugin::sniff, PGMImageDecoderPlugin::create }, { PPMImageDecoderPlugin::sniff, PPMImageDecoderPlugin::create }, { ICOImageDecoderPlugin::sniff, ICOImageDecoderPlugin::create }, - { JPGImageDecoderPlugin::sniff, JPGImageDecoderPlugin::create }, + { JPEGImageDecoderPlugin::sniff, JPEGImageDecoderPlugin::create }, { DDSImageDecoderPlugin::sniff, DDSImageDecoderPlugin::create }, { QOIImageDecoderPlugin::sniff, QOIImageDecoderPlugin::create }, }; diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPEGLoader.cpp index 69124fb91a..31536717ea 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPEGLoader.cpp @@ -14,7 +14,7 @@ #include <AK/String.h> #include <AK/Try.h> #include <AK/Vector.h> -#include <LibGfx/JPGLoader.h> +#include <LibGfx/JPEGLoader.h> #define JPG_INVALID 0X0000 @@ -173,7 +173,7 @@ struct ICCMultiChunkState { FixedArray<ByteBuffer> chunks; }; -struct JPGLoadingContext { +struct JPEGLoadingContext { enum State { NotDecoded = 0, Error, @@ -218,13 +218,13 @@ static void generate_huffman_codes(HuffmanTableSpec& table) static ErrorOr<size_t> read_huffman_bits(HuffmanStreamState& hstream, size_t count = 1) { if (count > (8 * sizeof(size_t))) { - dbgln_if(JPG_DEBUG, "Can't read {} bits at once!", count); + dbgln_if(JPEG_DEBUG, "Can't read {} bits at once!", count); return Error::from_string_literal("Reading too much huffman bits at once"); } size_t value = 0; while (count--) { if (hstream.byte_offset >= hstream.stream.size()) { - dbgln_if(JPG_DEBUG, "Huffman stream exhausted. This could be an error!"); + dbgln_if(JPEG_DEBUG, "Huffman stream exhausted. This could be an error!"); return Error::from_string_literal("Huffman stream exhausted."); } u8 current_byte = hstream.stream[hstream.byte_offset]; @@ -253,7 +253,7 @@ static ErrorOr<u8> get_next_symbol(HuffmanStreamState& hstream, HuffmanTableSpec } } - dbgln_if(JPG_DEBUG, "If you're seeing this...the jpeg decoder needs to support more kinds of JPEGs!"); + dbgln_if(JPEG_DEBUG, "If you're seeing this...the jpeg decoder needs to support more kinds of JPEGs!"); return Error::from_string_literal("This kind of JPEG is not yet supported by the decoder"); } @@ -284,7 +284,7 @@ static inline i32* get_component(Macroblock& block, unsigned component) * macroblocks that share the chrominance data. Next two iterations (assuming that * we are dealing with three components) will fill up the blocks with chroma data. */ -static ErrorOr<void> build_macroblocks(JPGLoadingContext& context, Vector<Macroblock>& macroblocks, u32 hcursor, u32 vcursor) +static ErrorOr<void> build_macroblocks(JPEGLoadingContext& context, Vector<Macroblock>& macroblocks, u32 hcursor, u32 vcursor) { for (unsigned component_i = 0; component_i < context.component_count; component_i++) { auto& component = context.components[component_i]; @@ -305,7 +305,7 @@ static ErrorOr<void> build_macroblocks(JPGLoadingContext& context, Vector<Macrob // For DC coefficients, symbol encodes the length of the coefficient. auto dc_length = TRY(get_next_symbol(context.huffman_stream, dc_table)); if (dc_length > 11) { - dbgln_if(JPG_DEBUG, "DC coefficient too long: {}!", dc_length); + dbgln_if(JPEG_DEBUG, "DC coefficient too long: {}!", dc_length); return Error::from_string_literal("DC coefficient too long"); } @@ -334,13 +334,13 @@ static ErrorOr<void> build_macroblocks(JPGLoadingContext& context, Vector<Macrob j += run_length; if (j >= 64) { - dbgln_if(JPG_DEBUG, "Run-length exceeded boundaries. Cursor: {}, Skipping: {}!", j, run_length); + dbgln_if(JPEG_DEBUG, "Run-length exceeded boundaries. Cursor: {}, Skipping: {}!", j, run_length); return Error::from_string_literal("Run-length exceeded boundaries"); } u8 coeff_length = ac_symbol & 0x0F; if (coeff_length > 10) { - dbgln_if(JPG_DEBUG, "AC coefficient too long: {}!", coeff_length); + dbgln_if(JPEG_DEBUG, "AC coefficient too long: {}!", coeff_length); return Error::from_string_literal("AC coefficient too long"); } @@ -359,12 +359,12 @@ static ErrorOr<void> build_macroblocks(JPGLoadingContext& context, Vector<Macrob return {}; } -static ErrorOr<Vector<Macroblock>> decode_huffman_stream(JPGLoadingContext& context) +static ErrorOr<Vector<Macroblock>> decode_huffman_stream(JPEGLoadingContext& context) { Vector<Macroblock> macroblocks; macroblocks.resize(context.mblock_meta.padded_total); - if constexpr (JPG_DEBUG) { + if constexpr (JPEG_DEBUG) { dbgln("Image width: {}", context.frame.width); dbgln("Image height: {}", context.frame.height); dbgln("Macroblocks in a row: {}", context.mblock_meta.hpadded_count); @@ -403,7 +403,7 @@ static ErrorOr<Vector<Macroblock>> decode_huffman_stream(JPGLoadingContext& cont } if (auto result = build_macroblocks(context, macroblocks, hcursor, vcursor); result.is_error()) { - if constexpr (JPG_DEBUG) { + if constexpr (JPEG_DEBUG) { dbgln("Failed to build Macroblock {}", i); dbgln("Huffman stream byte offset {}", context.huffman_stream.byte_offset); dbgln("Huffman stream bit offset {}", context.huffman_stream.bit_offset); @@ -430,7 +430,7 @@ static inline bool is_valid_marker(const Marker marker) if (marker >= JPG_APPN0 && marker <= JPG_APPNF) { if (marker != JPG_APPN0) - dbgln_if(JPG_DEBUG, "{:#04x} not supported yet. The decoder may fail!", marker); + dbgln_if(JPEG_DEBUG, "{:#04x} not supported yet. The decoder may fail!", marker); return true; } if (marker >= JPG_RESERVED1 && marker <= JPG_RESERVEDD) @@ -452,7 +452,7 @@ static inline bool is_valid_marker(const Marker marker) if (marker >= 0xFFC0 && marker <= 0xFFCF) { if (marker != 0xFFC4 && marker != 0xFFC8 && marker != 0xFFCC) { - dbgln_if(JPG_DEBUG, "Decoding this frame-type (SOF{}) is not currently supported. Decoder will fail!", marker & 0xf); + dbgln_if(JPEG_DEBUG, "Decoding this frame-type (SOF{}) is not currently supported. Decoder will fail!", marker & 0xf); return false; } } @@ -477,10 +477,10 @@ static inline ErrorOr<Marker> read_marker_at_cursor(Stream& stream) return is_valid_marker(marker) ? marker : JPG_INVALID; } -static ErrorOr<void> read_start_of_scan(AK::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr<void> read_start_of_scan(AK::SeekableStream& stream, JPEGLoadingContext& context) { - if (context.state < JPGLoadingContext::State::FrameDecoded) { - dbgln_if(JPG_DEBUG, "{}: SOS found before reading a SOF!", TRY(stream.tell())); + if (context.state < JPEGLoadingContext::State::FrameDecoded) { + dbgln_if(JPEG_DEBUG, "{}: SOS found before reading a SOF!", TRY(stream.tell())); return Error::from_string_literal("SOS found before reading a SOF"); } @@ -488,7 +488,7 @@ static ErrorOr<void> read_start_of_scan(AK::SeekableStream& stream, JPGLoadingCo TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); u8 component_count = TRY(stream.read_value<u8>()); if (component_count != context.component_count) { - dbgln_if(JPG_DEBUG, "{}: Unsupported number of components: {}!", TRY(stream.tell()), component_count); + dbgln_if(JPEG_DEBUG, "{}: Unsupported number of components: {}!", TRY(stream.tell()), component_count); return Error::from_string_literal("Unsupported number of components"); } @@ -507,17 +507,17 @@ static ErrorOr<void> read_start_of_scan(AK::SeekableStream& stream, JPGLoadingCo component.ac_destination_id = table_ids & 0x0F; if (context.dc_tables.size() != context.ac_tables.size()) { - dbgln_if(JPG_DEBUG, "{}: DC & AC table count mismatch!", TRY(stream.tell())); + dbgln_if(JPEG_DEBUG, "{}: DC & AC table count mismatch!", TRY(stream.tell())); return Error::from_string_literal("DC & AC table count mismatch"); } if (!context.dc_tables.contains(component.dc_destination_id)) { - dbgln_if(JPG_DEBUG, "DC table (id: {}) does not exist!", component.dc_destination_id); + dbgln_if(JPEG_DEBUG, "DC table (id: {}) does not exist!", component.dc_destination_id); return Error::from_string_literal("DC table does not exist"); } if (!context.ac_tables.contains(component.ac_destination_id)) { - dbgln_if(JPG_DEBUG, "AC table (id: {}) does not exist!", component.ac_destination_id); + dbgln_if(JPEG_DEBUG, "AC table (id: {}) does not exist!", component.ac_destination_id); return Error::from_string_literal("AC table does not exist"); } } @@ -528,7 +528,7 @@ static ErrorOr<void> read_start_of_scan(AK::SeekableStream& stream, JPGLoadingCo // The three values should be fixed for baseline JPEGs utilizing sequential DCT. if (spectral_selection_start != 0 || spectral_selection_end != 63 || successive_approximation != 0) { - dbgln_if(JPG_DEBUG, "{}: ERROR! Start of Selection: {}, End of Selection: {}, Successive Approximation: {}!", + dbgln_if(JPEG_DEBUG, "{}: ERROR! Start of Selection: {}, End of Selection: {}, Successive Approximation: {}!", TRY(stream.tell()), spectral_selection_start, spectral_selection_end, @@ -538,18 +538,18 @@ static ErrorOr<void> read_start_of_scan(AK::SeekableStream& stream, JPGLoadingCo return {}; } -static ErrorOr<void> read_reset_marker(AK::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr<void> read_reset_marker(AK::SeekableStream& stream, JPEGLoadingContext& context) { u16 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2; if (bytes_to_read != 2) { - dbgln_if(JPG_DEBUG, "{}: Malformed reset marker found!", TRY(stream.tell())); + dbgln_if(JPEG_DEBUG, "{}: Malformed reset marker found!", TRY(stream.tell())); return Error::from_string_literal("Malformed reset marker found"); } context.dc_reset_interval = TRY(stream.read_value<BigEndian<u16>>()); return {}; } -static ErrorOr<void> read_huffman_table(AK::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr<void> read_huffman_table(AK::SeekableStream& stream, JPEGLoadingContext& context) { i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()); TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); @@ -560,11 +560,11 @@ static ErrorOr<void> read_huffman_table(AK::SeekableStream& stream, JPGLoadingCo u8 table_type = table_info >> 4; u8 table_destination_id = table_info & 0x0F; if (table_type > 1) { - dbgln_if(JPG_DEBUG, "{}: Unrecognized huffman table: {}!", TRY(stream.tell()), table_type); + dbgln_if(JPEG_DEBUG, "{}: Unrecognized huffman table: {}!", TRY(stream.tell()), table_type); return Error::from_string_literal("Unrecognized huffman table"); } if (table_destination_id > 1) { - dbgln_if(JPG_DEBUG, "{}: Invalid huffman table destination id: {}!", TRY(stream.tell()), table_destination_id); + dbgln_if(JPEG_DEBUG, "{}: Invalid huffman table destination id: {}!", TRY(stream.tell()), table_destination_id); return Error::from_string_literal("Invalid huffman table destination id"); } @@ -595,13 +595,13 @@ static ErrorOr<void> read_huffman_table(AK::SeekableStream& stream, JPGLoadingCo } if (bytes_to_read != 0) { - dbgln_if(JPG_DEBUG, "{}: Extra bytes detected in huffman header!", TRY(stream.tell())); + dbgln_if(JPEG_DEBUG, "{}: Extra bytes detected in huffman header!", TRY(stream.tell())); return Error::from_string_literal("Extra bytes detected in huffman header"); } return {}; } -static ErrorOr<void> read_icc_profile(SeekableStream& stream, JPGLoadingContext& context, int bytes_to_read) +static ErrorOr<void> read_icc_profile(SeekableStream& stream, JPEGLoadingContext& context, int bytes_to_read) { if (bytes_to_read <= 2) return Error::from_string_literal("icc marker too small"); @@ -659,7 +659,7 @@ static ErrorOr<void> read_icc_profile(SeekableStream& stream, JPGLoadingContext& return {}; } -static ErrorOr<void> read_app_marker(SeekableStream& stream, JPGLoadingContext& context, int app_marker_number) +static ErrorOr<void> read_app_marker(SeekableStream& stream, JPEGLoadingContext& context, int app_marker_number) { i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()); TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); @@ -690,7 +690,7 @@ static ErrorOr<void> read_app_marker(SeekableStream& stream, JPGLoadingContext& return stream.discard(bytes_to_read); } -static inline bool validate_luma_and_modify_context(ComponentSpec const& luma, JPGLoadingContext& context) +static inline bool validate_luma_and_modify_context(ComponentSpec const& luma, JPEGLoadingContext& context) { if ((luma.hsample_factor == 1 || luma.hsample_factor == 2) && (luma.vsample_factor == 1 || luma.vsample_factor == 2)) { context.mblock_meta.hpadded_count += luma.hsample_factor == 1 ? 0 : context.mblock_meta.hcount % 2; @@ -700,7 +700,7 @@ static inline bool validate_luma_and_modify_context(ComponentSpec const& luma, J context.hsample_factor = luma.hsample_factor; context.vsample_factor = luma.vsample_factor; - if constexpr (JPG_DEBUG) { + if constexpr (JPEG_DEBUG) { dbgln("Horizontal Subsampling Factor: {}", luma.hsample_factor); dbgln("Vertical Subsampling Factor: {}", luma.vsample_factor); } @@ -710,7 +710,7 @@ static inline bool validate_luma_and_modify_context(ComponentSpec const& luma, J return false; } -static inline void set_macroblock_metadata(JPGLoadingContext& context) +static inline void set_macroblock_metadata(JPEGLoadingContext& context) { context.mblock_meta.hcount = (context.frame.width + 7) / 8; context.mblock_meta.vcount = (context.frame.height + 7) / 8; @@ -719,10 +719,10 @@ static inline void set_macroblock_metadata(JPGLoadingContext& context) context.mblock_meta.total = context.mblock_meta.hcount * context.mblock_meta.vcount; } -static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPEGLoadingContext& context) { - if (context.state == JPGLoadingContext::FrameDecoded) { - dbgln_if(JPG_DEBUG, "{}: SOF repeated!", TRY(stream.tell())); + if (context.state == JPEGLoadingContext::FrameDecoded) { + dbgln_if(JPEG_DEBUG, "{}: SOF repeated!", TRY(stream.tell())); return Error::from_string_literal("SOF repeated"); } @@ -733,14 +733,14 @@ static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPGLoadingC context.frame.precision = TRY(stream.read_value<u8>()); if (context.frame.precision != 8) { - dbgln_if(JPG_DEBUG, "{}: SOF precision != 8!", TRY(stream.tell())); + dbgln_if(JPEG_DEBUG, "{}: SOF precision != 8!", TRY(stream.tell())); return Error::from_string_literal("SOF precision != 8"); } context.frame.height = TRY(stream.read_value<BigEndian<u16>>()); context.frame.width = TRY(stream.read_value<BigEndian<u16>>()); if (!context.frame.width || !context.frame.height) { - dbgln_if(JPG_DEBUG, "{}: ERROR! Image height: {}, Image width: {}!", TRY(stream.tell()), context.frame.height, context.frame.width); + dbgln_if(JPEG_DEBUG, "{}: ERROR! Image height: {}, Image width: {}!", TRY(stream.tell()), context.frame.height, context.frame.width); return Error::from_string_literal("Image frame height of width null"); } @@ -753,7 +753,7 @@ static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPGLoadingC context.component_count = TRY(stream.read_value<u8>()); if (context.component_count != 1 && context.component_count != 3) { - dbgln_if(JPG_DEBUG, "{}: Unsupported number of components in SOF: {}!", TRY(stream.tell()), context.component_count); + dbgln_if(JPEG_DEBUG, "{}: Unsupported number of components in SOF: {}!", TRY(stream.tell()), context.component_count); return Error::from_string_literal("Unsupported number of components in SOF"); } @@ -775,7 +775,7 @@ static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPGLoadingC // By convention, downsampling is applied only on chroma components. So we should // hope to see the maximum sampling factor in the luma component. if (!validate_luma_and_modify_context(component, context)) { - dbgln_if(JPG_DEBUG, "{}: Unsupported luma subsampling factors: horizontal: {}, vertical: {}", + dbgln_if(JPEG_DEBUG, "{}: Unsupported luma subsampling factors: horizontal: {}, vertical: {}", TRY(stream.tell()), component.hsample_factor, component.vsample_factor); @@ -783,7 +783,7 @@ static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPGLoadingC } } else { if (component.hsample_factor != 1 || component.vsample_factor != 1) { - dbgln_if(JPG_DEBUG, "{}: Unsupported chroma subsampling factors: horizontal: {}, vertical: {}", + dbgln_if(JPEG_DEBUG, "{}: Unsupported chroma subsampling factors: horizontal: {}, vertical: {}", TRY(stream.tell()), component.hsample_factor, component.vsample_factor); @@ -793,7 +793,7 @@ static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPGLoadingC component.qtable_id = TRY(stream.read_value<u8>()); if (component.qtable_id > 1) { - dbgln_if(JPG_DEBUG, "{}: Unsupported quantization table id: {}!", TRY(stream.tell()), component.qtable_id); + dbgln_if(JPEG_DEBUG, "{}: Unsupported quantization table id: {}!", TRY(stream.tell()), component.qtable_id); return Error::from_string_literal("Unsupported quantization table id"); } @@ -803,7 +803,7 @@ static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPGLoadingC return {}; } -static ErrorOr<void> read_quantization_table(AK::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr<void> read_quantization_table(AK::SeekableStream& stream, JPEGLoadingContext& context) { i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2; TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size)); @@ -811,12 +811,12 @@ static ErrorOr<void> read_quantization_table(AK::SeekableStream& stream, JPGLoad u8 info_byte = TRY(stream.read_value<u8>()); u8 element_unit_hint = info_byte >> 4; if (element_unit_hint > 1) { - dbgln_if(JPG_DEBUG, "{}: Unsupported unit hint in quantization table: {}!", TRY(stream.tell()), element_unit_hint); + dbgln_if(JPEG_DEBUG, "{}: Unsupported unit hint in quantization table: {}!", TRY(stream.tell()), element_unit_hint); return Error::from_string_literal("Unsupported unit hint in quantization table"); } u8 table_id = info_byte & 0x0F; if (table_id > 1) { - dbgln_if(JPG_DEBUG, "{}: Unsupported quantization table id: {}!", TRY(stream.tell()), table_id); + dbgln_if(JPEG_DEBUG, "{}: Unsupported quantization table id: {}!", TRY(stream.tell()), table_id); return Error::from_string_literal("Unsupported quantization table id"); } u32* table = table_id == 0 ? context.luma_table : context.chroma_table; @@ -832,7 +832,7 @@ static ErrorOr<void> read_quantization_table(AK::SeekableStream& stream, JPGLoad bytes_to_read -= 1 + (element_unit_hint == 0 ? 64 : 128); } if (bytes_to_read != 0) { - dbgln_if(JPG_DEBUG, "{}: Invalid length for one or more quantization tables!", TRY(stream.tell())); + dbgln_if(JPEG_DEBUG, "{}: Invalid length for one or more quantization tables!", TRY(stream.tell())); return Error::from_string_literal("Invalid length for one or more quantization tables"); } @@ -846,7 +846,7 @@ static ErrorOr<void> skip_marker_with_length(Stream& stream) return {}; } -static void dequantize(JPGLoadingContext& context, Vector<Macroblock>& macroblocks) +static void dequantize(JPEGLoadingContext& context, Vector<Macroblock>& macroblocks) { for (u32 vcursor = 0; vcursor < context.mblock_meta.vcount; vcursor += context.vsample_factor) { for (u32 hcursor = 0; hcursor < context.mblock_meta.hcount; hcursor += context.hsample_factor) { @@ -867,7 +867,7 @@ static void dequantize(JPGLoadingContext& context, Vector<Macroblock>& macrobloc } } -static void inverse_dct(JPGLoadingContext const& context, Vector<Macroblock>& macroblocks) +static void inverse_dct(JPEGLoadingContext const& context, Vector<Macroblock>& macroblocks) { static float const m0 = 2.0f * AK::cos(1.0f / 16.0f * 2.0f * AK::Pi<float>); static float const m1 = 2.0f * AK::cos(2.0f / 16.0f * 2.0f * AK::Pi<float>); @@ -1034,7 +1034,7 @@ static void inverse_dct(JPGLoadingContext const& context, Vector<Macroblock>& ma } } -static void ycbcr_to_rgb(JPGLoadingContext const& context, Vector<Macroblock>& macroblocks) +static void ycbcr_to_rgb(JPEGLoadingContext const& context, Vector<Macroblock>& macroblocks) { for (u32 vcursor = 0; vcursor < context.mblock_meta.vcount; vcursor += context.vsample_factor) { for (u32 hcursor = 0; hcursor < context.mblock_meta.hcount; hcursor += context.hsample_factor) { @@ -1067,7 +1067,7 @@ static void ycbcr_to_rgb(JPGLoadingContext const& context, Vector<Macroblock>& m } } -static ErrorOr<void> compose_bitmap(JPGLoadingContext& context, Vector<Macroblock> const& macroblocks) +static ErrorOr<void> compose_bitmap(JPEGLoadingContext& context, Vector<Macroblock> const& macroblocks) { context.bitmap = TRY(Bitmap::create(BitmapFormat::BGRx8888, { context.frame.width, context.frame.height })); @@ -1087,11 +1087,11 @@ static ErrorOr<void> compose_bitmap(JPGLoadingContext& context, Vector<Macrobloc return {}; } -static ErrorOr<void> parse_header(AK::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr<void> parse_header(AK::SeekableStream& stream, JPEGLoadingContext& context) { auto marker = TRY(read_marker_at_cursor(stream)); if (marker != JPG_SOI) { - dbgln_if(JPG_DEBUG, "{}: SOI not found: {:x}!", TRY(stream.tell()), marker); + dbgln_if(JPEG_DEBUG, "{}: SOI not found: {:x}!", TRY(stream.tell()), marker); return Error::from_string_literal("SOI not found"); } for (;;) { @@ -1117,7 +1117,7 @@ static ErrorOr<void> parse_header(AK::SeekableStream& stream, JPGLoadingContext& case JPG_RST7: case JPG_SOI: case JPG_EOI: - dbgln_if(JPG_DEBUG, "{}: Unexpected marker {:x}!", TRY(stream.tell()), marker); + dbgln_if(JPEG_DEBUG, "{}: Unexpected marker {:x}!", TRY(stream.tell()), marker); return Error::from_string_literal("Unexpected marker"); case JPG_APPN0: case JPG_APPN1: @@ -1139,7 +1139,7 @@ static ErrorOr<void> parse_header(AK::SeekableStream& stream, JPGLoadingContext& break; case JPG_SOF0: TRY(read_start_of_frame(stream, context)); - context.state = JPGLoadingContext::FrameDecoded; + context.state = JPEGLoadingContext::FrameDecoded; break; case JPG_DQT: TRY(read_quantization_table(stream, context)); @@ -1154,7 +1154,7 @@ static ErrorOr<void> parse_header(AK::SeekableStream& stream, JPGLoadingContext& return read_start_of_scan(stream, context); default: if (auto result = skip_marker_with_length(stream); result.is_error()) { - dbgln_if(JPG_DEBUG, "{}: Error skipping marker: {:x}!", TRY(stream.tell()), marker); + dbgln_if(JPEG_DEBUG, "{}: Error skipping marker: {:x}!", TRY(stream.tell()), marker); return result.release_error(); } break; @@ -1164,7 +1164,7 @@ static ErrorOr<void> parse_header(AK::SeekableStream& stream, JPGLoadingContext& VERIFY_NOT_REACHED(); } -static ErrorOr<void> scan_huffman_stream(AK::SeekableStream& stream, JPGLoadingContext& context) +static ErrorOr<void> scan_huffman_stream(AK::SeekableStream& stream, JPEGLoadingContext& context) { u8 last_byte; u8 current_byte = TRY(stream.read_value<u8>()); @@ -1189,7 +1189,7 @@ static ErrorOr<void> scan_huffman_stream(AK::SeekableStream& stream, JPGLoadingC current_byte = TRY(stream.read_value<u8>()); continue; } - dbgln_if(JPG_DEBUG, "{}: Invalid marker: {:x}!", TRY(stream.tell()), marker); + dbgln_if(JPEG_DEBUG, "{}: Invalid marker: {:x}!", TRY(stream.tell()), marker); return Error::from_string_literal("Invalid marker"); } else { context.huffman_stream.stream.append(last_byte); @@ -1199,21 +1199,21 @@ static ErrorOr<void> scan_huffman_stream(AK::SeekableStream& stream, JPGLoadingC VERIFY_NOT_REACHED(); } -static ErrorOr<void> decode_header(JPGLoadingContext& context) +static ErrorOr<void> decode_header(JPEGLoadingContext& context) { - if (context.state < JPGLoadingContext::State::HeaderDecoded) { + if (context.state < JPEGLoadingContext::State::HeaderDecoded) { context.stream = TRY(try_make<FixedMemoryStream>(ReadonlyBytes { context.data, context.data_size })); if (auto result = parse_header(*context.stream, context); result.is_error()) { - context.state = JPGLoadingContext::State::Error; + context.state = JPEGLoadingContext::State::Error; return result.release_error(); } - context.state = JPGLoadingContext::State::HeaderDecoded; + context.state = JPEGLoadingContext::State::HeaderDecoded; } return {}; } -static ErrorOr<void> decode_jpg(JPGLoadingContext& context) +static ErrorOr<void> decode_jpeg(JPEGLoadingContext& context) { TRY(decode_header(context)); TRY(scan_huffman_stream(*context.stream, context)); @@ -1226,45 +1226,45 @@ static ErrorOr<void> decode_jpg(JPGLoadingContext& context) return {}; } -JPGImageDecoderPlugin::JPGImageDecoderPlugin(u8 const* data, size_t size) +JPEGImageDecoderPlugin::JPEGImageDecoderPlugin(u8 const* data, size_t size) { - m_context = make<JPGLoadingContext>(); + m_context = make<JPEGLoadingContext>(); m_context->data = data; m_context->data_size = size; m_context->huffman_stream.stream.ensure_capacity(50 * KiB); } -JPGImageDecoderPlugin::~JPGImageDecoderPlugin() = default; +JPEGImageDecoderPlugin::~JPEGImageDecoderPlugin() = default; -IntSize JPGImageDecoderPlugin::size() +IntSize JPEGImageDecoderPlugin::size() { - if (m_context->state == JPGLoadingContext::State::Error) + if (m_context->state == JPEGLoadingContext::State::Error) return {}; - if (m_context->state >= JPGLoadingContext::State::FrameDecoded) + if (m_context->state >= JPEGLoadingContext::State::FrameDecoded) return { m_context->frame.width, m_context->frame.height }; return {}; } -void JPGImageDecoderPlugin::set_volatile() +void JPEGImageDecoderPlugin::set_volatile() { if (m_context->bitmap) m_context->bitmap->set_volatile(); } -bool JPGImageDecoderPlugin::set_nonvolatile(bool& was_purged) +bool JPEGImageDecoderPlugin::set_nonvolatile(bool& was_purged) { if (!m_context->bitmap) return false; return m_context->bitmap->set_nonvolatile(was_purged); } -bool JPGImageDecoderPlugin::initialize() +bool JPEGImageDecoderPlugin::initialize() { return true; } -ErrorOr<bool> JPGImageDecoderPlugin::sniff(ReadonlyBytes data) +ErrorOr<bool> JPEGImageDecoderPlugin::sniff(ReadonlyBytes data) { return data.size() > 3 && data.data()[0] == 0xFF @@ -1272,46 +1272,46 @@ ErrorOr<bool> JPGImageDecoderPlugin::sniff(ReadonlyBytes data) && data.data()[2] == 0xFF; } -ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> JPGImageDecoderPlugin::create(ReadonlyBytes data) +ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> JPEGImageDecoderPlugin::create(ReadonlyBytes data) { - return adopt_nonnull_own_or_enomem(new (nothrow) JPGImageDecoderPlugin(data.data(), data.size())); + return adopt_nonnull_own_or_enomem(new (nothrow) JPEGImageDecoderPlugin(data.data(), data.size())); } -bool JPGImageDecoderPlugin::is_animated() +bool JPEGImageDecoderPlugin::is_animated() { return false; } -size_t JPGImageDecoderPlugin::loop_count() +size_t JPEGImageDecoderPlugin::loop_count() { return 0; } -size_t JPGImageDecoderPlugin::frame_count() +size_t JPEGImageDecoderPlugin::frame_count() { return 1; } -ErrorOr<ImageFrameDescriptor> JPGImageDecoderPlugin::frame(size_t index) +ErrorOr<ImageFrameDescriptor> JPEGImageDecoderPlugin::frame(size_t index) { if (index > 0) - return Error::from_string_literal("JPGImageDecoderPlugin: Invalid frame index"); + return Error::from_string_literal("JPEGImageDecoderPlugin: Invalid frame index"); - if (m_context->state == JPGLoadingContext::State::Error) - return Error::from_string_literal("JPGImageDecoderPlugin: Decoding failed"); + if (m_context->state == JPEGLoadingContext::State::Error) + return Error::from_string_literal("JPEGImageDecoderPlugin: Decoding failed"); - if (m_context->state < JPGLoadingContext::State::BitmapDecoded) { - if (auto result = decode_jpg(*m_context); result.is_error()) { - m_context->state = JPGLoadingContext::State::Error; + if (m_context->state < JPEGLoadingContext::State::BitmapDecoded) { + if (auto result = decode_jpeg(*m_context); result.is_error()) { + m_context->state = JPEGLoadingContext::State::Error; return result.release_error(); } - m_context->state = JPGLoadingContext::State::BitmapDecoded; + m_context->state = JPEGLoadingContext::State::BitmapDecoded; } return ImageFrameDescriptor { m_context->bitmap, 0 }; } -ErrorOr<Optional<ReadonlyBytes>> JPGImageDecoderPlugin::icc_data() +ErrorOr<Optional<ReadonlyBytes>> JPEGImageDecoderPlugin::icc_data() { TRY(decode_header(*m_context)); diff --git a/Userland/Libraries/LibGfx/JPGLoader.h b/Userland/Libraries/LibGfx/JPEGLoader.h index 0d738aea73..0e345aeb6f 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.h +++ b/Userland/Libraries/LibGfx/JPEGLoader.h @@ -10,14 +10,14 @@ namespace Gfx { -struct JPGLoadingContext; +struct JPEGLoadingContext; -class JPGImageDecoderPlugin : public ImageDecoderPlugin { +class JPEGImageDecoderPlugin : public ImageDecoderPlugin { public: static ErrorOr<bool> sniff(ReadonlyBytes); static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes); - virtual ~JPGImageDecoderPlugin() override; + virtual ~JPEGImageDecoderPlugin() override; virtual IntSize size() override; virtual void set_volatile() override; [[nodiscard]] virtual bool set_nonvolatile(bool& was_purged) override; @@ -29,9 +29,9 @@ public: virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override; private: - JPGImageDecoderPlugin(u8 const*, size_t); + JPEGImageDecoderPlugin(u8 const*, size_t); - OwnPtr<JPGLoadingContext> m_context; + OwnPtr<JPEGLoadingContext> m_context; }; } diff --git a/Userland/Libraries/LibPDF/Filter.cpp b/Userland/Libraries/LibPDF/Filter.cpp index 976c3be9de..b250101dd1 100644 --- a/Userland/Libraries/LibPDF/Filter.cpp +++ b/Userland/Libraries/LibPDF/Filter.cpp @@ -6,7 +6,7 @@ #include <AK/Hex.h> #include <LibCompress/Deflate.h> -#include <LibGfx/JPGLoader.h> +#include <LibGfx/JPEGLoader.h> #include <LibPDF/CommonNames.h> #include <LibPDF/Filter.h> @@ -269,14 +269,14 @@ ErrorOr<ByteBuffer> Filter::decode_jbig2(ReadonlyBytes) ErrorOr<ByteBuffer> Filter::decode_dct(ReadonlyBytes bytes) { - if (Gfx::JPGImageDecoderPlugin::sniff({ bytes.data(), bytes.size() }).release_value_but_fixme_should_propagate_errors()) { - auto decoder = Gfx::JPGImageDecoderPlugin::create({ bytes.data(), bytes.size() }).release_value_but_fixme_should_propagate_errors(); + if (Gfx::JPEGImageDecoderPlugin::sniff({ bytes.data(), bytes.size() }).release_value_but_fixme_should_propagate_errors()) { + auto decoder = Gfx::JPEGImageDecoderPlugin::create({ bytes.data(), bytes.size() }).release_value_but_fixme_should_propagate_errors(); if (decoder->initialize()) { auto frame = TRY(decoder->frame(0)); return frame.image->serialize_to_byte_buffer(); } } - return AK::Error::from_string_literal("Not a JPG image!"); + return AK::Error::from_string_literal("Not a JPEG image!"); }; ErrorOr<ByteBuffer> Filter::decode_jpx(ReadonlyBytes) diff --git a/Userland/Services/SpiceAgent/SpiceAgent.cpp b/Userland/Services/SpiceAgent/SpiceAgent.cpp index fcd52767e2..68fd353eab 100644 --- a/Userland/Services/SpiceAgent/SpiceAgent.cpp +++ b/Userland/Services/SpiceAgent/SpiceAgent.cpp @@ -10,7 +10,7 @@ #include <LibGfx/BMPLoader.h> #include <LibGfx/BMPWriter.h> #include <LibGfx/Bitmap.h> -#include <LibGfx/JPGLoader.h> +#include <LibGfx/JPEGLoader.h> #include <LibGfx/PNGLoader.h> #include <LibGfx/PNGWriter.h> #include <memory.h> @@ -154,10 +154,10 @@ void SpiceAgent::on_message_received() frame_or_error = bmp_decoder->frame(0); } } else if (type == ClipboardType::JPG) { - if (Gfx::JPGImageDecoderPlugin::sniff({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors()) { - auto jpg_decoder = Gfx::JPGImageDecoderPlugin::create({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors(); - if (jpg_decoder->initialize()) - frame_or_error = jpg_decoder->frame(0); + if (Gfx::JPEGImageDecoderPlugin::sniff({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors()) { + auto jpeg_decoder = Gfx::JPEGImageDecoderPlugin::create({ data_buffer.data(), data_buffer.size() }).release_value_but_fixme_should_propagate_errors(); + if (jpeg_decoder->initialize()) + frame_or_error = jpeg_decoder->frame(0); } } else { dbgln("Unknown clipboard type: {}", (u32)type); diff --git a/Userland/Utilities/test-fuzz.cpp b/Userland/Utilities/test-fuzz.cpp index 77128a6a1a..ad4db50240 100644 --- a/Userland/Utilities/test-fuzz.cpp +++ b/Userland/Utilities/test-fuzz.cpp @@ -17,7 +17,7 @@ T(GIFLoader) \ T(HttpRequest) \ T(ICOLoader) \ - T(JPGLoader) \ + T(JPEGLoader) \ T(Js) \ T(Markdown) \ T(PBMLoader) \ @@ -61,8 +61,8 @@ ENUMERATE_TARGETS(__ENUMERATE_TARGET) #include <Meta/Lagom/Fuzzers/FuzzICOLoader.cpp> #undef LLVMFuzzerTestOneInput -#define LLVMFuzzerTestOneInput TestJPGLoader -#include <Meta/Lagom/Fuzzers/FuzzJPGLoader.cpp> +#define LLVMFuzzerTestOneInput TestJPEGLoader +#include <Meta/Lagom/Fuzzers/FuzzJPEGLoader.cpp> #undef LLVMFuzzerTestOneInput #define LLVMFuzzerTestOneInput TestJs |