(by Codex) Render opening artwork with its supplied embedded palette

This commit is contained in:
Codex committed 2026-11-01 17:55:16 +01:00
1 parent 7482697248
commit fc07e45bbc
4 files changed
+25 -24

No files matched your search

+4 -2
View File
@@ -3607,8 +3607,10 @@ int main(int argc, char** argv) {
for (const auto [picture, milliseconds] :
std::array<std::pair<int, Uint64>, 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;
+18
View File
@@ -16,6 +16,24 @@ Palette load_palette(const std::filesystem::path& path) {
return p;
}
std::optional<Palette> 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++) {
+3
View File
@@ -4,6 +4,7 @@
#include <array>
#include <cstdint>
#include <filesystem>
#include <optional>
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<Palette> load_optional_embedded_palette(const std::filesystem::path& path);
} // namespace bmh
-22
View File
@@ -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<Palette> 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<uint8_t>& bytes) {
return std::string(bytes.begin(), bytes.end());
}