Skip to content

Commit 1788dec

Browse files
authored
Merge pull request #386 from Libvisual/fix-bmp-palette-loading
Fix BMP palette loading.
2 parents 5a3a3c8 + 175e9b2 commit 1788dec

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

libvisual/libvisual/lv_video.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ namespace LV {
392392
}
393393
}
394394

395+
// Videos must have the same palette.
396+
if (m_impl->palette != video->m_impl->palette)
397+
return false;
398+
395399
return true;
396400
}
397401

libvisual/libvisual/private/lv_video_bmp.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
#include <istream>
3232
#include <cstring>
3333

34-
#define BI_RGB 0
35-
#define BI_RLE8 1
36-
#define BI_RLE4 2
34+
/* BMP compression methods */
35+
#define BI_RGB 0
36+
#define BI_RLE8 1
37+
#define BI_RLE4 2
38+
#define BI_BITFIELDS 3
39+
3740

3841
namespace LV {
3942

@@ -286,6 +289,8 @@ namespace LV {
286289
fp.read (reinterpret_cast<char*> (&bf_bits), 4);
287290
bf_bits = VISUAL_ENDIAN_LEI32 (bf_bits);
288291

292+
auto dib_header_pos = fp.tellg ();
293+
289294
/* Read the info structure size */
290295
fp.read (reinterpret_cast<char*> (&bi_size), 4);
291296
bi_size = VISUAL_ENDIAN_LEI32 (bi_size);
@@ -341,13 +346,19 @@ namespace LV {
341346
return nullptr;
342347
}
343348

344-
if (bi_compression > 3) {
349+
if (bi_compression >= BI_BITFIELDS) {
345350
visual_log (VISUAL_LOG_ERROR, "Bitmap uses an invalid or unsupported compression scheme");
346351
fp.seekg (saved_stream_pos);
347352
return nullptr;
348353
}
349354

350355
/* Load the palette */
356+
357+
/* Skip past DIB header to color table */
358+
/* BI_BITFIELDS and BI_ALPHABITFIELDS are unsupported, so there are
359+
no bitmasks after the DIB header. */
360+
fp.seekg (dib_header_pos + std::streampos {bi_size}, std::ios::beg);
361+
351362
if (bi_bitcount < 24) {
352363
if (bi_clrused == 0) {
353364
/* When the colors used variable is zero, use the
@@ -385,6 +396,8 @@ namespace LV {
385396
if (palette)
386397
video->set_palette (*palette);
387398

399+
/* Read and decode image data */
400+
388401
/* Set to the beginning of image data, note that MickeySoft likes stuff upside down .. */
389402
fp.seekg (bf_bits, std::ios::beg);
390403

0 commit comments

Comments
 (0)