Skip to content

Commit 513d465

Browse files
committed
Fix plMipmap JPEG decompression using the wrong channel for JPEG alpha
JPEG alpha images store the alpha data in the red channel, but our decompression code incorrectly extracted the blue channel instead, leading to corrupted alpha channels for mipmaps with JPEG alpha. The uncompressed buffers in question are stored in BGRA order in memory, but the channel extraction/swapping code accesses them as an array of 32-bit ints. From this perspective, on little-endian systems, the buffer "looks like" ARGB. So to use the red channel as alpha, we need to shift each 32-bit int 8 bits to the left and mask out the low 24 bits.
1 parent 83e9d9f commit 513d465

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

core/PRP/Surface/plMipmap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ void plMipmap::DecompressImage(size_t level, void* dest, size_t size) const
701701
unsigned int* dp = (unsigned int*)dest;
702702
unsigned int* sp = (unsigned int*)jbuffer;
703703
for (size_t i=0; i<(size/4); i++)
704-
dp[i] = (dp[i] & 0x00FFFFFF) | ((sp[i] << 24) & 0xFF000000);
704+
dp[i] = (dp[i] & 0x00FFFFFF) | ((sp[i] << 8) & 0xFF000000);
705705
}
706706

707707
free_aligned(jbuffer);

0 commit comments

Comments
 (0)