mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 18:15:58 +00:00
LibGfx/DDSLoader: Allow image dimensions that are not divisible by 4
This commit is contained in:
parent
bf75ecdcf7
commit
b25efa219b
|
@ -8,6 +8,7 @@
|
|||
#include <AK/DeprecatedString.h>
|
||||
#include <LibCore/MappedFile.h>
|
||||
#include <LibGfx/ImageFormats/BMPLoader.h>
|
||||
#include <LibGfx/ImageFormats/DDSLoader.h>
|
||||
#include <LibGfx/ImageFormats/GIFLoader.h>
|
||||
#include <LibGfx/ImageFormats/ICOLoader.h>
|
||||
#include <LibGfx/ImageFormats/ILBMLoader.h>
|
||||
|
@ -617,3 +618,18 @@ TEST_CASE(test_jxl_modular_property_8)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(test_dds)
|
||||
{
|
||||
Array file_names = {
|
||||
TEST_INPUT("dds/catdog-alert-29x29.dds"sv),
|
||||
TEST_INPUT("dds/catdog-alert-32x32.dds"sv)
|
||||
};
|
||||
|
||||
for (auto file_name : file_names) {
|
||||
auto file = MUST(Core::MappedFile::map(file_name));
|
||||
EXPECT(Gfx::DDSImageDecoderPlugin::sniff(file->bytes()));
|
||||
auto plugin_decoder = MUST(Gfx::DDSImageDecoderPlugin::create(file->bytes()));
|
||||
expect_single_frame(*plugin_decoder);
|
||||
}
|
||||
}
|
||||
|
|
BIN
Tests/LibGfx/test-inputs/dds/catdog-alert-29x29.dds
Normal file
BIN
Tests/LibGfx/test-inputs/dds/catdog-alert-29x29.dds
Normal file
Binary file not shown.
BIN
Tests/LibGfx/test-inputs/dds/catdog-alert-32x32.dds
Normal file
BIN
Tests/LibGfx/test-inputs/dds/catdog-alert-32x32.dds
Normal file
Binary file not shown.
|
@ -253,8 +253,8 @@ static ErrorOr<void> decode_dx5_alpha_block(Stream& stream, DDSLoadingContext& c
|
|||
color[7] = 255;
|
||||
}
|
||||
|
||||
for (size_t y = 0; y < 4; y++) {
|
||||
for (size_t x = 0; x < 4; x++) {
|
||||
for (size_t y = 0; y < 4 && bitmap_y + y < static_cast<u64>(context.bitmap->height()); y++) {
|
||||
for (size_t x = 0; x < 4 && bitmap_x + x < static_cast<u64>(context.bitmap->width()); x++) {
|
||||
u8 index = 3 * (4 * y + x);
|
||||
u8 bit_location = floor(index / 8.0);
|
||||
u8 adjusted_index = index - (bit_location * 8);
|
||||
|
@ -284,8 +284,8 @@ static ErrorOr<void> decode_dx3_alpha_block(Stream& stream, DDSLoadingContext& c
|
|||
u64 alpha_0 = a0 + 256u * (a1 + 256u * (a2 + 256u * (a3 + 256u)));
|
||||
u64 alpha_1 = a4 + 256u * (a5 + 256u * (a6 + 256u * a7));
|
||||
|
||||
for (size_t y = 0; y < 4; y++) {
|
||||
for (size_t x = 0; x < 4; x++) {
|
||||
for (size_t y = 0; y < 4 && bitmap_y + y < static_cast<u64>(context.bitmap->height()); y++) {
|
||||
for (size_t x = 0; x < 4 && bitmap_x + x < static_cast<u64>(context.bitmap->width()); x++) {
|
||||
u8 code = 4 * (4 * y + x);
|
||||
|
||||
if (code >= 32) {
|
||||
|
@ -357,8 +357,8 @@ static ErrorOr<void> decode_color_block(Stream& stream, DDSLoadingContext& conte
|
|||
}
|
||||
|
||||
size_t i = 0;
|
||||
for (size_t y = 0; y < 4; y++) {
|
||||
for (size_t x = 0; x < 4; x++) {
|
||||
for (size_t y = 0; y < 4 && bitmap_y + y < static_cast<u64>(context.bitmap->height()); y++) {
|
||||
for (size_t x = 0; x < 4 && bitmap_x + x < static_cast<u64>(context.bitmap->width()); x++) {
|
||||
u8 code_byte = (code >> (i * 2)) & 3;
|
||||
u8 r = rgba[code_byte][0];
|
||||
u8 g = rgba[code_byte][1];
|
||||
|
|
Loading…
Reference in a new issue