Skip to content

Honor DWORD-aligned rows in 24-bit BMP textures - #108

Open
PS2HomeDeveloper wants to merge 2 commits into
ps2dev:masterfrom
PS2HomeDeveloper:patch-4
Open

PS2HomeDeveloper wants to merge 2 commits into
ps2dev:masterfrom
PS2HomeDeveloper:patch-4

Conversation

@PS2HomeDeveloper

Copy link
Copy Markdown

Summary

Uncompressed BMP scanlines are DWORD-aligned, but the 24-bpp loader advances through source data as if each row were exactly width * 3 bytes. When a row has padding, the loader reads padding bytes as pixel data for the next row and the texture colors are corrupted.

Calculate and validate the 24-bpp source-row stride, then index each source row using that stride.

Testing

  • Build gsKit with the PS2 toolchain.
  • Load 24-bpp BMPs with widths 1, 2, and 3 and at least two rows; use distinct colors per row and verify row order and colors.
  • Load a 24-bpp BMP with width 4 to verify that rows without padding remain correct.
  • Verify a truncated 24-bpp pixel payload is rejected before row data is accessed.

## Summary

Uncompressed BMP scanlines are DWORD-aligned, but the 24-bpp loader advances through source data as if each row were exactly `width * 3` bytes. When a row has padding, the loader reads padding bytes as pixel data for the next row and the texture colors are corrupted.

Calculate and validate the 24-bpp source-row stride, then index each source row using that stride.

## Testing

- Build gsKit with the PS2 toolchain.
- Load 24-bpp BMPs with widths 1, 2, and 3 and at least two rows; use distinct colors per row and verify row order and colors.
- Load a 24-bpp BMP with width 4 to verify that rows without padding remain correct.
- Verify a truncated 24-bpp pixel payload is rejected before row data is accessed.
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