mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 08:11:13 +00:00
Tests: Add test for color indexing for single-channel images
The color indexing transform shouldn't make single-channel images larger (by needlessly writing a palette). If there <= 16 colors in the single channel, it should make the image smaller.
This commit is contained in:
parent
347e2831b2
commit
3ca6dfba48
Notes:
sideshowbarker
2024-07-16 17:12:03 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/3ca6dfba48 Pull-request: https://github.com/SerenityOS/serenity/pull/24503 Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/timschumi ✅
|
@ -216,6 +216,39 @@ TEST_CASE(test_webp_color_indexing_transform)
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE(test_webp_color_indexing_transform_single_channel)
|
||||
{
|
||||
Array<Color, 256> colors;
|
||||
for (size_t i = 0; i < colors.size(); ++i) {
|
||||
colors[i].set_red(0);
|
||||
colors[i].set_green(255 - i);
|
||||
colors[i].set_blue(128);
|
||||
colors[i].set_alpha(255);
|
||||
}
|
||||
for (int bits_per_pixel : { 1, 2, 4, 8 }) {
|
||||
int number_of_colors = 1 << bits_per_pixel;
|
||||
|
||||
auto bitmap = TRY_OR_FAIL(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, { 47, 33 }));
|
||||
for (int y = 0; y < bitmap->height(); ++y)
|
||||
for (int x = 0; x < bitmap->width(); ++x)
|
||||
bitmap->set_pixel(x, y, colors[(x * bitmap->width() + y) % number_of_colors]);
|
||||
|
||||
auto encoded_data = TRY_OR_FAIL(encode_bitmap<Gfx::WebPWriter>(bitmap));
|
||||
auto decoded_bitmap = TRY_OR_FAIL(expect_single_frame_of_size(*TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(encoded_data)), bitmap->size()));
|
||||
expect_bitmaps_equal(*decoded_bitmap, *bitmap);
|
||||
|
||||
Gfx::WebPEncoderOptions options;
|
||||
options.vp8l_options.allowed_transforms = 0;
|
||||
auto encoded_data_without_color_indexing = TRY_OR_FAIL(encode_bitmap<Gfx::WebPWriter>(bitmap, options));
|
||||
if (bits_per_pixel == 8)
|
||||
EXPECT(encoded_data.size() <= encoded_data_without_color_indexing.size());
|
||||
else
|
||||
EXPECT(encoded_data.size() < encoded_data_without_color_indexing.size());
|
||||
auto decoded_bitmap_without_color_indexing = TRY_OR_FAIL(expect_single_frame_of_size(*TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(encoded_data)), bitmap->size()));
|
||||
expect_bitmaps_equal(*decoded_bitmap_without_color_indexing, *decoded_bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(test_webp_icc)
|
||||
{
|
||||
auto sRGB_icc_profile = MUST(Gfx::ICC::sRGB());
|
||||
|
|
Loading…
Reference in a new issue