@@ -19,8 +19,7 @@ private static (Rgba32 Low, Rgba32 High) Decode(ColorEndpointMode mode, params i
1919 return ( pair . LdrLow , pair . LdrHigh ) ;
2020 }
2121
22- // ---- Mode 0: LdrLumaDirect (spec §C.2.14 — "Direct luminance") ----
23-
22+ // Mode 0: LdrLumaDirect (spec §C.2.14 — "Direct luminance")
2423 [ Fact ]
2524 public void Decode_LdrLumaDirect_ProducesGrayscaleWithFullAlpha ( )
2625 {
@@ -31,12 +30,13 @@ public void Decode_LdrLumaDirect_ProducesGrayscaleWithFullAlpha()
3130 Assert . Equal ( new Rgba32 ( 0xE0 , 0xE0 , 0xE0 , 255 ) , high ) ;
3231 }
3332
34- // ---- Mode 1: LdrLumaBaseOffset (spec §C.2.14 — "Luminance, base+offset") ----
35-
33+ // Mode 1: LdrLumaBaseOffset (spec §C.2.14 — "Luminance, base+offset")
3634 [ Fact ]
3735 public void Decode_LdrLumaBaseOffset_DecodesBaseAndOffset ( )
3836 {
39- // L0 = (v0 >> 2) | (v1 & 0xC0); L1 = L0 + (v1 & 0x3F), saturated at 0xFF.
37+ // Mode 1 (spec §C.2.14): the base luma is packed across v0 and v1's high bits, and v1's
38+ // low bits are a saturating offset producing the high endpoint. The expected values below
39+ // mirror that derivation.
4040 int v0 = 0x80 ;
4141 int v1 = 0x6F ;
4242 int l0 = ( v0 >> 2 ) | ( v1 & 0xC0 ) ;
@@ -51,14 +51,14 @@ public void Decode_LdrLumaBaseOffset_DecodesBaseAndOffset()
5151 [ Fact ]
5252 public void Decode_LdrLumaBaseOffset_SaturatesOffsetAtFF ( )
5353 {
54- // Choose v1 so L0 + offset > 0xFF.
54+ // Mode 1 (spec §C.2.14): max inputs push the base+offset high endpoint past 0xFF, forcing
55+ // the saturation clamp.
5556 ( Rgba32 _ , Rgba32 high ) = Decode ( ColorEndpointMode . LdrLumaBaseOffset , 0xFF , 0xFF ) ;
5657
5758 Assert . Equal ( 255 , high . R ) ;
5859 }
5960
60- // ---- Mode 4: LdrLumaAlphaDirect (spec §C.2.14 — "Luminance+alpha, direct") ----
61-
61+ // Mode 4: LdrLumaAlphaDirect (spec §C.2.14 — "Luminance+alpha, direct")
6262 [ Fact ]
6363 public void Decode_LdrLumaAlphaDirect_DecodesLumaAndAlphaIndependently ( )
6464 {
@@ -69,12 +69,12 @@ public void Decode_LdrLumaAlphaDirect_DecodesLumaAndAlphaIndependently()
6969 Assert . Equal ( new Rgba32 ( 0xF0 , 0xF0 , 0xF0 , 0xC0 ) , high ) ;
7070 }
7171
72- // ---- Mode 5: LdrLumaAlphaBaseOffset (spec §C.2.14) ----
73-
72+ // Mode 5: LdrLumaAlphaBaseOffset (spec §C.2.14)
7473 [ Fact ]
7574 public void Decode_LdrLumaAlphaBaseOffset_DecodesTransferPrecisionPairs ( )
7675 {
77- // TransferPrecision unpacks each (high, low) pair into (offset, base).
76+ // Mode 5 (spec §C.2.14): luma and alpha each arrive as a (base, offset) pair recovered by
77+ // the spec's bit_transfer_signed step (BitOperations.TransferPrecision).
7878 ( int b0 , int a0 ) = BitOperations . TransferPrecision ( 0x30 , 0x80 ) ;
7979 ( int b2 , int a2 ) = BitOperations . TransferPrecision ( 0x10 , 0x40 ) ;
8080
@@ -86,47 +86,48 @@ public void Decode_LdrLumaAlphaBaseOffset_DecodesTransferPrecisionPairs()
8686 Assert . Equal ( new Rgba32 ( ( byte ) highLuma , ( byte ) highLuma , ( byte ) highLuma , ( byte ) highAlpha ) , high ) ;
8787 }
8888
89- // ---- Mode 6: LdrRgbBaseScale (spec §C.2.14 — "RGB, base+scale") ----
90-
89+ // Mode 6: LdrRgbBaseScale (spec §C.2.14 — "RGB, base+scale")
9190 [ Fact ]
9291 public void Decode_LdrRgbBaseScale_LowIsScaledHigh ( )
9392 {
94- // low = (v0,v1,v2) * v3 >> 8 ; high = (v0,v1,v2). Alpha = 255 on both.
93+ // Mode 6 (spec §C.2.14): the high endpoint is the base RGB (v0,v1,v2), and the low
94+ // endpoint is that base scaled down by v3. Alpha is opaque on both.
9595 ( Rgba32 low , Rgba32 high ) = Decode ( ColorEndpointMode . LdrRgbBaseScale , 0xFF , 0x80 , 0x40 , 0x80 ) ;
9696
97- Assert . Equal ( new Rgba32 ( ( byte ) ( ( 0xFF * 0x80 ) >> 8 ) , ( byte ) ( ( 0x80 * 0x80 ) >> 8 ) , ( byte ) ( ( 0x40 * 0x80 ) >> 8 ) , 255 ) , low ) ;
97+ Assert . Equal ( new Rgba32 ( ( 0xFF * 0x80 ) >> 8 , ( 0x80 * 0x80 ) >> 8 , ( 0x40 * 0x80 ) >> 8 , 255 ) , low ) ;
9898 Assert . Equal ( new Rgba32 ( 0xFF , 0x80 , 0x40 , 255 ) , high ) ;
9999 }
100100
101- // ---- Mode 8: LdrRgbDirect (spec §C.2.14) with blue-contract swap ----
102-
101+ // Mode 8: LdrRgbDirect (spec §C.2.14) with blue-contract swap
103102 [ Fact ]
104103 public void Decode_LdrRgbDirect_WhenHighIsDimmer_SwapsEndpointsAndAveragesBlue ( )
105104 {
106- // sum1 (high) < sum0 (low) triggers blue-contract swap.
105+ // Mode 8 (spec §C.2.14): when the high triple is dimmer than the low triple the endpoints
106+ // are swapped and the blue-contract correction is applied. These inputs select that path.
107107 ( Rgba32 low , Rgba32 high ) = Decode ( ColorEndpointMode . LdrRgbDirect , 0xC0 , 0x20 , 0xC0 , 0x20 , 0xC0 , 0x20 ) ;
108108
109- // Swapped: low uses odd-indexed (high-side) values with blue-contract averaging.
110109 Assert . Equal ( new Rgba32 ( ( byte ) ( ( 0x20 + 0x20 ) >> 1 ) , ( byte ) ( ( 0x20 + 0x20 ) >> 1 ) , 0x20 , 255 ) , low ) ;
111110 Assert . Equal ( new Rgba32 ( ( byte ) ( ( 0xC0 + 0xC0 ) >> 1 ) , ( byte ) ( ( 0xC0 + 0xC0 ) >> 1 ) , 0xC0 , 255 ) , high ) ;
112111 }
113112
114113 [ Fact ]
115114 public void Decode_LdrRgbDirect_WhenHighIsBrighter_KeepsDirectValues ( )
116115 {
117- // sum1 (high) >= sum0 (low) → no swap.
116+ // Mode 8 (spec §C.2.14): when the high triple is brighter, no swap or blue-contract is
117+ // applied and the endpoints pass through directly.
118118 ( Rgba32 low , Rgba32 high ) = Decode ( ColorEndpointMode . LdrRgbDirect , 0x20 , 0xC0 , 0x20 , 0xC0 , 0x20 , 0xC0 ) ;
119119
120120 Assert . Equal ( new Rgba32 ( 0x20 , 0x20 , 0x20 , 255 ) , low ) ;
121121 Assert . Equal ( new Rgba32 ( 0xC0 , 0xC0 , 0xC0 , 255 ) , high ) ;
122122 }
123123
124- // ---- Mode 9: LdrRgbBaseOffset (spec §C.2.14 — with blue-contract) ----
125-
124+ // Mode 9: LdrRgbBaseOffset (spec §C.2.14 — with blue-contract)
126125 [ Fact ]
127126 public void Decode_LdrRgbBaseOffset_NonNegativeSum_ProducesBasePlusOffset ( )
128127 {
129- // b0+b1+b2 >= 0 → low = base, high = base + offset.
128+ // Mode 9 (spec §C.2.14): each channel is a (base, offset) pair via bit_transfer_signed.
129+ // With a non-negative offset sum, the blue-contract branch is skipped: low = base,
130+ // high = base + offset.
130131 ( int b0 , int a0 ) = BitOperations . TransferPrecision ( 0x10 , 0x80 ) ;
131132 ( int b1 , int a1 ) = BitOperations . TransferPrecision ( 0x08 , 0x40 ) ;
132133 ( int b2 , int a2 ) = BitOperations . TransferPrecision ( 0x04 , 0x20 ) ;
@@ -140,19 +141,17 @@ public void Decode_LdrRgbBaseOffset_NonNegativeSum_ProducesBasePlusOffset()
140141 Assert . Equal ( new Rgba32 ( ( byte ) hr , ( byte ) hg , ( byte ) hb , 255 ) , high ) ;
141142 }
142143
143- // ---- Mode 10: LdrRgbBaseScaleTwoA (spec §C.2.14 — base+scale with separate alpha) ----
144-
144+ // Mode 10: LdrRgbBaseScaleTwoA (spec §C.2.14 — base+scale with separate alpha)
145145 [ Fact ]
146146 public void Decode_LdrRgbBaseScaleTwoA_AppliesScaleAndSeparateAlphaChannels ( )
147147 {
148148 ( Rgba32 low , Rgba32 high ) = Decode ( ColorEndpointMode . LdrRgbBaseScaleTwoA , 0xFF , 0x80 , 0x40 , 0x80 , 0x20 , 0xE0 ) ;
149149
150- Assert . Equal ( new Rgba32 ( ( byte ) ( ( 0xFF * 0x80 ) >> 8 ) , ( byte ) ( ( 0x80 * 0x80 ) >> 8 ) , ( byte ) ( ( 0x40 * 0x80 ) >> 8 ) , 0x20 ) , low ) ;
150+ Assert . Equal ( new Rgba32 ( ( 0xFF * 0x80 ) >> 8 , ( 0x80 * 0x80 ) >> 8 , ( 0x40 * 0x80 ) >> 8 , 0x20 ) , low ) ;
151151 Assert . Equal ( new Rgba32 ( 0xFF , 0x80 , 0x40 , 0xE0 ) , high ) ;
152152 }
153153
154- // ---- Mode 12: LdrRgbaDirect (spec §C.2.14) ----
155-
154+ // Mode 12: LdrRgbaDirect (spec §C.2.14)
156155 [ Fact ]
157156 public void Decode_LdrRgbaDirect_WhenHighIsBrighter_KeepsDirectValues ( )
158157 {
@@ -167,13 +166,13 @@ public void Decode_LdrRgbaDirect_WhenHighIsDimmer_AppliesBlueContractAndSwaps()
167166 {
168167 ( Rgba32 low , Rgba32 high ) = Decode ( ColorEndpointMode . LdrRgbaDirect , 0xC0 , 0x20 , 0xC0 , 0x20 , 0xC0 , 0x20 , 0x30 , 0xB0 ) ;
169168
170- // Blue-contract swap: alpha indexes (6,7) swap too — low gets v7, high gets v6.
171- Assert . Equal ( new Rgba32 ( ( byte ) ( ( 0x20 + 0x20 ) >> 1 ) , ( byte ) ( ( 0x20 + 0x20 ) >> 1 ) , 0x20 , 0xB0 ) , low ) ;
172- Assert . Equal ( new Rgba32 ( ( byte ) ( ( 0xC0 + 0xC0 ) >> 1 ) , ( byte ) ( ( 0xC0 + 0xC0 ) >> 1 ) , 0xC0 , 0x30 ) , high ) ;
169+ // Mode 12 (spec §C.2.14): the dimmer-high case swaps endpoints (RGB via blue-contract,
170+ // alpha by index swap), so low takes the high-side alpha and vice versa.
171+ Assert . Equal ( new Rgba32 ( ( 0x20 + 0x20 ) >> 1 , ( 0x20 + 0x20 ) >> 1 , 0x20 , 0xB0 ) , low ) ;
172+ Assert . Equal ( new Rgba32 ( ( 0xC0 + 0xC0 ) >> 1 , ( 0xC0 + 0xC0 ) >> 1 , 0xC0 , 0x30 ) , high ) ;
173173 }
174174
175- // ---- Mode 13: LdrRgbaBaseOffset (spec §C.2.14) ----
176-
175+ // Mode 13: LdrRgbaBaseOffset (spec §C.2.14)
177176 [ Fact ]
178177 public void Decode_LdrRgbaBaseOffset_DecodesAllFourChannelsWithTransferPrecision ( )
179178 {
0 commit comments