diff --git a/src/app/main.cpp b/src/app/main.cpp index c48801c..95310fb 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -3607,8 +3607,10 @@ int main(int argc, char** argv) { for (const auto [picture, milliseconds] : std::array, 3>{{{138, 3000}, {139, 1000}, {137, 1500}}}) { if (!running || skip_opening) break; - present_season(load_vga(ui::asset_path(data / "KB", std::to_string(picture) + ".VGA")), - window_title.c_str()); + const auto picture_path = ui::asset_path(data / "KB", std::to_string(picture) + ".VGA"); + const auto picture_palette = load_optional_embedded_palette(picture_path); + present_season(load_vga(picture_path), window_title.c_str(), + picture_palette ? &*picture_palette : nullptr); const auto until = SDL_GetTicks64() + milliseconds; while (running && !skip_opening && SDL_GetTicks64() < until) { SDL_Event opening_event; diff --git a/src/formats/palette.cpp b/src/formats/palette.cpp index fea6e83..bbe9b1a 100644 --- a/src/formats/palette.cpp +++ b/src/formats/palette.cpp @@ -16,6 +16,24 @@ Palette load_palette(const std::filesystem::path& path) { return p; } +std::optional load_optional_embedded_palette(const std::filesystem::path& path) { + const Bytes bytes = read_file(path); + if (bytes.size() < 8) throw FormatError("VGA palette source is truncated"); + const size_t rle_end = 8 + size_t(le32(bytes, 4)); + if (rle_end > bytes.size()) throw FormatError("VGA RLE length exceeds palette source"); + const size_t trailing = bytes.size() - rle_end; + if (trailing == 0) return std::nullopt; + if (trailing < 768) throw FormatError("truncated embedded VGA palette"); + Palette palette; + for (size_t i = 0; i < palette.argb.size(); ++i) { + const auto channel = [&](size_t component) { + return uint32_t(vga_dac_rgb8(bytes[rle_end + i * 3 + component])); + }; + palette.argb[i] = 0xff000000u | channel(0) << 16 | channel(1) << 8 | channel(2); + } + return palette; +} + uint8_t Palette::nearest(uint8_t r, uint8_t g, uint8_t b) const { int best = 0, best_dist = INT32_MAX; for (int i = 0; i < 256; i++) { diff --git a/src/formats/palette.hpp b/src/formats/palette.hpp index 4a9bfee..3eb104b 100644 --- a/src/formats/palette.hpp +++ b/src/formats/palette.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace bmh { @@ -21,5 +22,7 @@ constexpr uint8_t vga_dac_rgb8(uint8_t channel) { } Palette load_palette(const std::filesystem::path& path); +// Some full-screen VGA pictures carry their own DAC palette after the RLE data. +std::optional load_optional_embedded_palette(const std::filesystem::path& path); } // namespace bmh diff --git a/src/ui/sportschau.cpp b/src/ui/sportschau.cpp index 3efbbc3..1073d38 100644 --- a/src/ui/sportschau.cpp +++ b/src/ui/sportschau.cpp @@ -89,28 +89,6 @@ Image load_kb(const std::filesystem::path& data_directory, const char* file) { return load_vga(data_directory / "KB" / file); } -std::optional load_optional_embedded_palette(const std::filesystem::path& path) { - const Bytes bytes = read_file(path); - if (bytes.size() < 8) throw FormatError("sportschau: VGA palette source is truncated"); - const size_t rle_end = 8 + size_t(le32(bytes, 4)); - if (rle_end > bytes.size()) throw FormatError("sportschau: VGA RLE length exceeds palette source"); - const size_t trailing = bytes.size() - rle_end; - if (trailing == 0) return std::nullopt; - if (trailing < 768) throw FormatError("sportschau: truncated embedded VGA palette"); - - // PaletteOverride reads 0x300 bytes after the RLE stream and installs them - // through KeepSameSixBitDACExpansion/Size5. Keep the same six-bit DAC expansion - // used for M3PC.COL; only the palette source differs for embedded VGA art. - Palette palette; - for (size_t i = 0; i < palette.argb.size(); ++i) { - const auto channel = [&](size_t component) { - return uint32_t(vga_dac_rgb8(bytes[rle_end + i * 3 + component])); - }; - palette.argb[i] = 0xff000000u | channel(0) << 16 | channel(1) << 8 | channel(2); - } - return palette; -} - std::string short_bytes(const std::vector& bytes) { return std::string(bytes.begin(), bytes.end()); }