void GfxPalette32::submit(const HunkPalette &hunkPalette) { if (hunkPalette.getVersion() == _version) { return; } submit(hunkPalette.toPalette()); hunkPalette.setVersion(_version); }
Palette GfxPalette32::getPaletteFromResource(const GuiResourceId resourceId) const { Resource *palResource = _resMan->findResource(ResourceId(kResourceTypePalette, resourceId), false); if (!palResource) { error("Could not load vary palette %d", resourceId); } const HunkPalette rawPalette(palResource->data); return rawPalette.toPalette(); }
void GfxPalette32::submit(const HunkPalette &hunkPalette) { if (hunkPalette.getVersion() == _version) { return; } const Palette oldSourcePalette(_sourcePalette); const Palette palette = hunkPalette.toPalette(); mergePalette(_sourcePalette, palette); if (!_needsUpdate && oldSourcePalette != _sourcePalette) { ++_version; _needsUpdate = true; } hunkPalette.setVersion(_version); }
void GfxPalette32::updateHardware() { if (_currentPalette == _nextPalette && !_gammaChanged) { return; } #ifdef USE_RGB_COLOR uint8 *bpal = _hardwarePalette; #else uint8 bpal[256 * 3]; #endif // HACK: There are resources in a couple of Windows-only games that seem to // include bogus palette entries above 236. SSCI does a lot of extra work // when running in Windows to shift palettes and rewrite view & pic pixel // data on-the-fly to account for the way Windows palettes work, which // seems to end up masking the fact that there is some bad palette data. // Since only one demo and one game seem to have this problem, we instead // "fix" the problem here by ignoring attempts to send high palette entries // to the backend. This makes those high pixels render black, which seems to // match what would happen in the original interpreter, and saves us from // having to clutter up the engine with a bunch of palette shifting garbage. int maxIndex = ARRAYSIZE(_currentPalette.colors) - 2; if (g_sci->getGameId() == GID_HOYLE5 || (g_sci->getGameId() == GID_GK2 && g_sci->isDemo())) { maxIndex = 235; } for (int i = 0; i <= maxIndex; ++i) { _currentPalette.colors[i] = _nextPalette.colors[i]; // All color entries MUST be copied, not just "used" entries, otherwise // uninitialised memory from bpal makes its way into the system palette. // This would not normally be a problem, except that games sometimes use // unused palette entries. e.g. Phant1 title screen references palette // entries outside its own palette, so will render garbage colors where // the game expects them to be black if (_gammaLevel == -1) { bpal[i * 3 ] = _currentPalette.colors[i].r; bpal[i * 3 + 1] = _currentPalette.colors[i].g; bpal[i * 3 + 2] = _currentPalette.colors[i].b; } else { bpal[i * 3 ] = gammaTables[_gammaLevel][_currentPalette.colors[i].r]; bpal[i * 3 + 1] = gammaTables[_gammaLevel][_currentPalette.colors[i].g]; bpal[i * 3 + 2] = gammaTables[_gammaLevel][_currentPalette.colors[i].b]; } } #ifndef USE_RGB_COLOR // When creating a raw palette on the stack, any skipped area of the palette // needs to be blacked out or else it will contain garbage memory memset(bpal + (maxIndex + 1) * 3, 0, (255 - maxIndex - 1) * 3); #endif #ifdef ENABLE_SCI32_MAC if (g_sci->getPlatform() == Common::kPlatformMacintosh) { bpal[255 * 3 ] = 0; bpal[255 * 3 + 1] = 0; bpal[255 * 3 + 2] = 0; } else { #else { #endif // The last color must always be white bpal[255 * 3 ] = 255; bpal[255 * 3 + 1] = 255; bpal[255 * 3 + 2] = 255; } // If the system is in a high color mode, which can happen during video // playback, attempting to send the palette to OSystem is illegal and will // result in a crash if (g_system->getScreenFormat().bytesPerPixel == 1) { g_system->getPaletteManager()->setPalette(bpal, 0, 256); } _gammaChanged = false; } Palette GfxPalette32::getPaletteFromResource(const GuiResourceId resourceId) const { Resource *palResource = _resMan->findResource(ResourceId(kResourceTypePalette, resourceId), false); if (!palResource) { error("Could not load vary palette %d", resourceId); } const HunkPalette rawPalette(*palResource); return rawPalette.toPalette(); }