mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-12 04:22:28 +00:00
LibGfx/JBIG2: Call decode_immediate_generic_region for lossless regions
It seems to do the right thing already, and nothing in the spec says not to do this as far as I can tell. With this, we can finally decode Tests/LibGfx/test-inputs/jbig2/bitmap.jbig2 and add a test for decoding simple arithmetic-coded images.
This commit is contained in:
parent
6788a82ec5
commit
f391c7822d
Notes:
sideshowbarker
2024-07-16 22:24:48 +09:00
Author: https://github.com/nico
Commit: f391c7822d
Pull-request: https://github.com/SerenityOS/serenity/pull/23594
2 changed files with 23 additions and 8 deletions
|
@ -336,6 +336,23 @@ TEST_CASE(test_jbig2_white_47x23)
|
||||||
EXPECT_EQ(pixel, Gfx::Color(Gfx::Color::White).value());
|
EXPECT_EQ(pixel, Gfx::Color(Gfx::Color::White).value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(test_jbig2_generic_region_arithmetic_code)
|
||||||
|
{
|
||||||
|
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jbig2/bitmap.jbig2"sv)));
|
||||||
|
EXPECT(Gfx::JBIG2ImageDecoderPlugin::sniff(file->bytes()));
|
||||||
|
auto plugin_decoder = TRY_OR_FAIL(Gfx::JBIG2ImageDecoderPlugin::create(file->bytes()));
|
||||||
|
|
||||||
|
auto bmp_file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("bmp/bitmap.bmp"sv)));
|
||||||
|
auto bmp_plugin_decoder = TRY_OR_FAIL(Gfx::JBIG2ImageDecoderPlugin::create(file->bytes()));
|
||||||
|
|
||||||
|
auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 399, 400 }));
|
||||||
|
auto bmp_frame = TRY_OR_FAIL(expect_single_frame_of_size(*bmp_plugin_decoder, { 399, 400 }));
|
||||||
|
|
||||||
|
for (int y = 0; y < frame.image->height(); ++y)
|
||||||
|
for (int x = 0; x < frame.image->width(); ++x)
|
||||||
|
EXPECT_EQ(frame.image->get_pixel(x, y), bmp_frame.image->get_pixel(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE(test_jbig2_arithmetic_decoder)
|
TEST_CASE(test_jbig2_arithmetic_decoder)
|
||||||
{
|
{
|
||||||
// https://www.itu.int/rec/T-REC-T.88-201808-I
|
// https://www.itu.int/rec/T-REC-T.88-201808-I
|
||||||
|
|
|
@ -922,11 +922,6 @@ static ErrorOr<void> decode_immediate_generic_region(JBIG2LoadingContext& contex
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ErrorOr<void> decode_immediate_lossless_generic_region(JBIG2LoadingContext&, SegmentData const&)
|
|
||||||
{
|
|
||||||
return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode immediate lossless generic region yet");
|
|
||||||
}
|
|
||||||
|
|
||||||
static ErrorOr<void> decode_intermediate_generic_refinement_region(JBIG2LoadingContext&, SegmentData const&)
|
static ErrorOr<void> decode_intermediate_generic_refinement_region(JBIG2LoadingContext&, SegmentData const&)
|
||||||
{
|
{
|
||||||
return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode intermediate generic refinement region yet");
|
return Error::from_string_literal("JBIG2ImageDecoderPlugin: Cannot decode intermediate generic refinement region yet");
|
||||||
|
@ -1118,10 +1113,13 @@ static ErrorOr<void> decode_data(JBIG2LoadingContext& context)
|
||||||
TRY(decode_intermediate_generic_region(context, segment));
|
TRY(decode_intermediate_generic_region(context, segment));
|
||||||
break;
|
break;
|
||||||
case SegmentType::ImmediateGenericRegion:
|
case SegmentType::ImmediateGenericRegion:
|
||||||
TRY(decode_immediate_generic_region(context, segment));
|
|
||||||
break;
|
|
||||||
case SegmentType::ImmediateLosslessGenericRegion:
|
case SegmentType::ImmediateLosslessGenericRegion:
|
||||||
TRY(decode_immediate_lossless_generic_region(context, segment));
|
// 7.4.6 Generic region segment syntax
|
||||||
|
// "The data parts of all three of the generic region segment types ("intermediate generic region", "immediate generic region" and
|
||||||
|
// "immediate lossless generic region") are coded identically, but are acted upon differently, see 8.2."
|
||||||
|
// But 8.2 only describes a difference between intermediate and immediate regions as far as I can tell,
|
||||||
|
// and calling the immediate generic region handler for immediate generic lossless regions seems to do the right thing (?).
|
||||||
|
TRY(decode_immediate_generic_region(context, segment));
|
||||||
break;
|
break;
|
||||||
case SegmentType::IntermediateGenericRefinementRegion:
|
case SegmentType::IntermediateGenericRefinementRegion:
|
||||||
TRY(decode_intermediate_generic_refinement_region(context, segment));
|
TRY(decode_intermediate_generic_refinement_region(context, segment));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue