Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AGS: Fix playing CLUT8 videos #4938

Merged
merged 4 commits into from
Apr 25, 2023
Merged

AGS: Fix playing CLUT8 videos #4938

merged 4 commits into from
Apr 25, 2023

Conversation

criezy
Copy link
Member

@criezy criezy commented Apr 24, 2023

Playing CLUT8 videos (such as FLIC videos) was not working properly:

  • If the game itself is CLUT8, it was using the previously set palette from the game and ignore the one from the video decoder, resulting in wrong colors.
  • If the game uses 16bit or 32bit colors, it was crashing as the decoder palette was not passed to the blitting code that was expected it.

There were two separate crash:

  • If the video is stretched in AGS, it was asserting in Graphics::transBlitPixel due to the source palette being a nullptr pointer.
  • If the video is not stretched in AGS, it was trying to access 0x0 memory. There was an incorrect assert that was not triggered and should have caught this before getting to the invalid memory access.

The ManagedSurface blitting code only allowed blitting from CLUT8 source to non-CLUT8 destination if the source was itself a ManagedSurface. This pull request adds the possibility to do this also if the source is a Surface (such as a VideoDecoder frame). This is used in the AGS engine to fix the crash mentioned above.

Crash call-stack for the CLUT8 -> 16/32bit color (for stretched videos, the non-stretch one is similar but crashes in ManagedSurface::blitFromInner instead):

Assertion failure: 'srcPalette != nullptr' in graphics/managed_surface.cpp:558 (void Graphics::transBlitPixel(TSRC, TDEST &, const Graphics::PixelFormat &, const Graphics::PixelFormat &, uint32, uint32, const uint32 *, const byte *) [TSRC = unsigned char, TDEST = unsigned int])
  #04  __assert2 40)
  #05  void Graphics::transBlitPixel<unsigned char, unsigned int>(unsigned char, unsigned int&, Graphics::PixelFormat const&, Graphics::PixelFormat const&, unsigned int, unsigned int, unsigned int const*, unsigned char const*) 548)
  #06  void Graphics::transBlit<unsigned char, unsigned int>(Graphics::Surface const&, Common::Rect const&, Graphics::ManagedSurface&, Common::Rect const&, unsigned char, bool, unsigned int, unsigned int, unsigned int const*, unsigned int const*, Graphics::Surface const*, bool) 1048)
  #07  Graphics::ManagedSurface::transBlitFromInner(Graphics::Surface const&, Common::Rect const&, Common::Rect const&, unsigned int, bool, unsigned int, unsigned int, unsigned int const*, unsigned int const*, Graphics::Surface const*, bool) 460)
  #08  Graphics::ManagedSurface::transBlitFrom(Graphics::Surface const&, Common::Rect const&, Common::Rect const&, unsigned int, bool, unsigned int, unsigned int, Graphics::Surface const*, bool) 36)
  #09  AGS3::play_video(Video::VideoDecoder*, char const*, int, AGS3::VideoSkipType, bool) 524)
  #10  AGS3::play_flc_video(int, int, AGS3::VideoSkipType) 72)

Example of wrong color for CLUT8 -> CLUT8:
Before
image
After
image

I am opening this pull request to check there is no compilation error before committing (I only compiled with the AGS engine locally) and give the opportunity to those who want to review the changes to the Graphics::ManagedSurface code. I think it is straightforward, but I may have overlooked something.

When blitting from CLUT8 to another format, we need a palette
for the source surface.
The palette from the video decoder was ignored, and it was using the
palette from the game instead.
The inner blitting code already handled that case, but we needed to be able to
pass the Surface palette to that inner code.
The blitting code asserted on the palette pointer as it was not
passed to it.
@criezy
Copy link
Member Author

criezy commented Apr 25, 2023

All the checks passed, so I will merged it.

@criezy criezy merged commit fd2bc62 into scummvm:master Apr 25, 2023
@criezy criezy deleted the ags-clut8-video branch April 25, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant