From 3132dfb0ebc81723e3255f72804f782d724fbcae Mon Sep 17 00:00:00 2001 From: Chong Kai Xiong Date: Fri, 24 Jan 2025 06:40:05 +0800 Subject: [PATCH 1/5] Core (LV::Video): Fix BMP loader not returning error despite not supporting BI_BITFIELDS. --- libvisual/libvisual/private/lv_video_bmp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvisual/libvisual/private/lv_video_bmp.cpp b/libvisual/libvisual/private/lv_video_bmp.cpp index fdfdf68c0..71d0b0bc3 100644 --- a/libvisual/libvisual/private/lv_video_bmp.cpp +++ b/libvisual/libvisual/private/lv_video_bmp.cpp @@ -341,7 +341,7 @@ namespace LV { return nullptr; } - if (bi_compression > 3) { + if (bi_compression >= 3) { visual_log (VISUAL_LOG_ERROR, "Bitmap uses an invalid or unsupported compression scheme"); fp.seekg (saved_stream_pos); return nullptr; From 17dcf8721030d9cedcc63b53e4ead1e7b9fcf95b Mon Sep 17 00:00:00 2001 From: Chong Kai Xiong Date: Fri, 24 Jan 2025 06:42:05 +0800 Subject: [PATCH 2/5] Core (LV::Video): Fix BMP loader not loading palette from the correct offset. --- libvisual/libvisual/private/lv_video_bmp.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvisual/libvisual/private/lv_video_bmp.cpp b/libvisual/libvisual/private/lv_video_bmp.cpp index 71d0b0bc3..dbf0627ce 100644 --- a/libvisual/libvisual/private/lv_video_bmp.cpp +++ b/libvisual/libvisual/private/lv_video_bmp.cpp @@ -286,6 +286,8 @@ namespace LV { fp.read (reinterpret_cast (&bf_bits), 4); bf_bits = VISUAL_ENDIAN_LEI32 (bf_bits); + auto dib_header_pos = fp.tellg (); + /* Read the info structure size */ fp.read (reinterpret_cast (&bi_size), 4); bi_size = VISUAL_ENDIAN_LEI32 (bi_size); @@ -347,6 +349,8 @@ namespace LV { return nullptr; } + fp.seekg (dib_header_pos + std::streampos {bi_size}, std::ios::beg); + /* Load the palette */ if (bi_bitcount < 24) { if (bi_clrused == 0) { From 0b41ed78504896a8a9e8cf56d4fff3f773213e1d Mon Sep 17 00:00:00 2001 From: Chong Kai Xiong Date: Fri, 24 Jan 2025 06:45:46 +0800 Subject: [PATCH 3/5] Core (LV::Video): Check palettes are equal in has_same_content(). --- libvisual/libvisual/lv_video.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvisual/libvisual/lv_video.cpp b/libvisual/libvisual/lv_video.cpp index 9bb5f1b17..6367418e4 100644 --- a/libvisual/libvisual/lv_video.cpp +++ b/libvisual/libvisual/lv_video.cpp @@ -392,6 +392,10 @@ namespace LV { } } + // Videos must have the same palette. + if (m_impl->palette != video->m_impl->palette) + return false; + return true; } From 54a9d7e2a491a90a21eb1b313e730ecf3c8dac9c Mon Sep 17 00:00:00 2001 From: Chong Kai Xiong Date: Sat, 25 Jan 2025 18:30:51 +0800 Subject: [PATCH 4/5] Core (LV::Video): Add BI_BITFIELDS #define in BMP loader for clarity. --- libvisual/libvisual/private/lv_video_bmp.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libvisual/libvisual/private/lv_video_bmp.cpp b/libvisual/libvisual/private/lv_video_bmp.cpp index dbf0627ce..1299795d4 100644 --- a/libvisual/libvisual/private/lv_video_bmp.cpp +++ b/libvisual/libvisual/private/lv_video_bmp.cpp @@ -31,9 +31,12 @@ #include #include -#define BI_RGB 0 -#define BI_RLE8 1 -#define BI_RLE4 2 +/* BMP compression methods */ +#define BI_RGB 0 +#define BI_RLE8 1 +#define BI_RLE4 2 +#define BI_BITFIELDS 3 + namespace LV { @@ -343,7 +346,7 @@ namespace LV { return nullptr; } - if (bi_compression >= 3) { + if (bi_compression >= BI_BITFIELDS) { visual_log (VISUAL_LOG_ERROR, "Bitmap uses an invalid or unsupported compression scheme"); fp.seekg (saved_stream_pos); return nullptr; From 175e9b265ca869bb4390e59097e030106660fb62 Mon Sep 17 00:00:00 2001 From: Chong Kai Xiong Date: Sat, 25 Jan 2025 18:32:09 +0800 Subject: [PATCH 5/5] Core (LV::Video): Additional comments in BMP loader on color table reading. --- libvisual/libvisual/private/lv_video_bmp.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libvisual/libvisual/private/lv_video_bmp.cpp b/libvisual/libvisual/private/lv_video_bmp.cpp index 1299795d4..90a37b7a8 100644 --- a/libvisual/libvisual/private/lv_video_bmp.cpp +++ b/libvisual/libvisual/private/lv_video_bmp.cpp @@ -352,9 +352,13 @@ namespace LV { return nullptr; } + /* Load the palette */ + + /* Skip past DIB header to color table */ + /* BI_BITFIELDS and BI_ALPHABITFIELDS are unsupported, so there are + no bitmasks after the DIB header. */ fp.seekg (dib_header_pos + std::streampos {bi_size}, std::ios::beg); - /* Load the palette */ if (bi_bitcount < 24) { if (bi_clrused == 0) { /* When the colors used variable is zero, use the @@ -392,6 +396,8 @@ namespace LV { if (palette) video->set_palette (*palette); + /* Read and decode image data */ + /* Set to the beginning of image data, note that MickeySoft likes stuff upside down .. */ fp.seekg (bf_bits, std::ios::beg);