Skip to content

fix(blp): scale 1-bit and 4-bit alpha to 8-bit range#46

Merged
danielsreichenbach merged 1 commit intomainfrom
fix/issue-32-blp1-alpha-scaling
Feb 16, 2026
Merged

fix(blp): scale 1-bit and 4-bit alpha to 8-bit range#46
danielsreichenbach merged 1 commit intomainfrom
fix/issue-32-blp1-alpha-scaling

Conversation

@danielsreichenbach
Copy link
Member

Summary

Fixes incorrect transparency rendering for BLP1 textures with 1-bit and 4-bit alpha channels.

Problem

BLP1 images with 1-bit and 4-bit alpha channels were not correctly scaling alpha values to the 0-255 range required by RGBA image formats. This caused transparency to appear incorrectly in War3 textures like the Mountain King.

1-bit alpha bug: Values 0-1 were used directly as 0-1 instead of scaling to 0-255
4-bit alpha bug: Values 0-15 were used directly instead of scaling to 0-255

Solution

  • 1-bit alpha: Now correctly maps 0→0, 1→255
  • 4-bit alpha: Now correctly maps 0-15→0-255 via multiplication by 17 (equivalent to (nibble << 4) | nibble)

This matches the behavior of the reference blp-rs implementation.

Testing

Added two new tests:

  • test_raw1_1bit_alpha_scaling: Verifies 1-bit alpha is scaled to 0 or 255
  • test_raw1_4bit_alpha_scaling: Verifies 4-bit alpha is scaled to valid 8-bit values

All existing tests pass.

Issue

Fixes #32

BLP1 images with 1-bit and 4-bit alpha channels were not
correctly scaling alpha values to the 0-255 range required by
RGBA image formats.

- 1-bit alpha: now maps 0→0, 1→255 (previously 0→0, 1→1)
- 4-bit alpha: now maps 0-15→0-255 via multiplication by 17
  (previously left as 0-15 values)

This matches the behavior of the reference blp-rs implementation
and fixes transparency issues with War3 textures like Mountain King.

Fixes #32
@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
file-formats/graphics/wow-blp/src/convert/raw1.rs 0.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@danielsreichenbach danielsreichenbach merged commit 7d46766 into main Feb 16, 2026
16 of 17 checks passed
@danielsreichenbach danielsreichenbach deleted the fix/issue-32-blp1-alpha-scaling branch February 16, 2026 12:22
danielsreichenbach added a commit that referenced this pull request Feb 16, 2026
- Added entry for BLP1 alpha scaling fix (issue #32)
- Added entry for M2 texture_combiner_combos flag fix (issue #35)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: The transparency of blp1 was not handled correctly

1 participant