Skip to content

Commit

Permalink
Adjust transparent color detection in BAM V1 animations
Browse files Browse the repository at this point in the history
Solves display issues with a number of game resources.
  • Loading branch information
Argent77 committed Sep 4, 2024
1 parent a8f685e commit 707a19f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/org/infinity/resource/graphics/BamV1Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ private void preparePalette(int[] externalPalette) {
currentPalette[idx] |= alphaMask;
}
alphaUsed |= (currentPalette[idx] & 0xff000000) != 0;
if (idx == 0 || (currentPalette[idx] & 0x00ffffff) == 0x0000ff00) {
if (idx == 0 || (currentPalette[idx] & 0x00ffffff) == 0x0000ff00 && transIndices.size() < 2) {
transIndices.add(idx);
}
}
Expand All @@ -773,12 +773,17 @@ private void preparePalette(int[] externalPalette) {
}
}

// applying transparent indices
for (int i : transIndices) {
// applying transparent index
// use only one transparent color index (prefer magic color "green" over first palette index)
if (transIndices.size() > 1 && (currentPalette[transIndices.get(0)] & 0x00ffffff) != 0x0000ff00) {
transIndices.remove(0);
}
final int transIndex = !transIndices.isEmpty() ? transIndices.get(0) : -1;
if (transIndex >= 0) {
if (transparencyEnabled) {
currentPalette[i] = 0;
currentPalette[transIndex] = 0;
} else {
currentPalette[i] |= 0xff000000;
currentPalette[transIndex] |= 0xff000000;
}
}
}
Expand Down

0 comments on commit 707a19f

Please sign in to comment.