Skip to content

Commit 2b48778

Browse files
authored
Merge pull request scp-fs2open#7410 from Goober5000/documentation/4148
add documentation for issue 4148
2 parents 0e43b19 + e270754 commit 2b48778

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

code/anim/packunpack.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,15 @@ int unpack_pixel(anim_instance *ai, ubyte *data, ubyte pix, int aabitmap, int bp
142142
bit_16 = (ushort)pix;
143143
break;
144144
case 8:
145-
// 8 bit-per-pixel aa bitmaps are a bit special since they only use a palette index value in the range [0, 15]. These
146-
// palette indexes must be remapped to alpha values between [0, 255] which is what graphics code expects. Palette
147-
// range [0, 14] is a gradient from black to white, and palette index 15 is a special color which indicates the background
148-
// area of a HUD gauge. Retail code uses the final alpha value for index 1 for this special index to give gauges a dark
149-
// transparent background.
145+
// 8-bit-per-pixel HUD gauge ANI aabitmaps use the palette index directly as an alpha value —
146+
// the actual RGB colors stored in the palette are completely ignored. The valid range is [0, 15]:
147+
// [0]: fully transparent (alpha 0)
148+
// [1-14]: black-to-white gradient (alpha = index * 18)
149+
// [15]: special HUD background (alpha 18, matching index 1, for a dark transparent tint)
150+
// [>15]: clamped to fully opaque (alpha 255)
151+
// Because only the index value matters, the palette in the source file must be ordered so that
152+
// index 0 is the transparent end and index 14 is the opaque end. A reversed palette causes the
153+
// gauge to render as a solid white square (see GitHub issue #4148).
150154
if (pix > 15) {
151155
bit_8 = 255;
152156
}
@@ -240,11 +244,15 @@ int unpack_pixel_count(anim_instance *ai, ubyte *data, ubyte pix, int count = 0,
240244
bit_16 = (ushort)pix;
241245
break;
242246
case 8 :
243-
// 8 bit-per-pixel aa bitmaps are a bit special since they only use a palette index value in the range [0, 15]. These
244-
// palette indexes must be remapped to alpha values between [0, 255] which is what graphics code expects. Palette
245-
// range [0, 14] is a gradient from black to white, and palette index 15 is a special color which indicates the background
246-
// area of a HUD gauge. Retail code uses the final alpha value for index 1 for this special index to give gauges a dark
247-
// transparent background.
247+
// 8-bit-per-pixel HUD gauge ANI aabitmaps use the palette index directly as an alpha value —
248+
// the actual RGB colors stored in the palette are completely ignored. The valid range is [0, 15]:
249+
// [0]: fully transparent (alpha 0)
250+
// [1-14]: black-to-white gradient (alpha = index * 18)
251+
// [15]: special HUD background (alpha 18, matching index 1, for a dark transparent tint)
252+
// [>15]: clamped to fully opaque (alpha 255)
253+
// Because only the index value matters, the palette in the source file must be ordered so that
254+
// index 0 is the transparent end and index 14 is the opaque end. A reversed palette causes the
255+
// gauge to render as a solid white square (see GitHub issue #4148).
248256
if (pix > 15) {
249257
bit_8 = 255;
250258
}

code/pcxutils/pcxutils.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,16 @@ int pcx_read_bitmap( const char * real_filename, ubyte *org_data, ubyte * /*pal*
312312
if ( byte_size == 1 ) {
313313
auto pixel_val = data;
314314
if (!mask_bitmap) {
315-
// 8 bit-per-pixel aa bitmaps are a bit special since they only use values in the range [0, 15] where 15 wraps
316-
// around back to 0. Since the rest of the code expects the value to be in the range [0, 255] the pixel value
317-
// needs to be adjusted here. By multiplying the value with 17 the original range [0, 15] is mapped to [0, 255]
318-
// This only applies to bitmaps that are not used as masks since mask bitmaps use higher values
319-
// to indicate their mask area
315+
// 8-bit-per-pixel HUD gauge PCX aabitmaps use the pixel value directly as an alpha level —
316+
// the actual RGB colors in the palette are completely ignored. The valid range is [0, 15]:
317+
// [0]: fully transparent (alpha 0)
318+
// [1-14]: black-to-white gradient (alpha = value * 17)
319+
// [15]: special HUD background (alpha 17, matching index 1, for a dark transparent tint)
320+
// [>15]: clamped to fully transparent (alpha 0)
321+
// Because only the pixel value matters, the palette in the source file must be ordered so that
322+
// index 0 is the transparent end and index 14 is the opaque end. A reversed palette causes the
323+
// gauge to render as a solid white square (see GitHub issue #4148).
324+
// Mask bitmaps skip this block because they use the full value range for the mask area.
320325
if (data > 15) {
321326
pixel_val = 0;
322327
} else if (data == 15) {

0 commit comments

Comments
 (0)