Precalculate BMP grayscale palette #10580
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.36) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 191 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.315
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #10580"
general
weight: 0.35
radarhere
Alternative to https://github.com/python-pillow/Pillow/pull/10574
This code loops through a range (or
(0, 255)) and converts each value to bytes, and checks that against each the corresponding item in the BMP palette.https://github.com/python-pillow/Pillow/blob/389d62adf44ab13173045a36451e9cbdbc357f56/src/PIL/BmpImagePlugin.py#L276-L286
paddingis only ever 3 or 4.https://en.wikipedia.org/wiki/BMP_file_format
This means there are only four types of grayscale palettes, and we can calculate them beforehand -
(0, 255)rangerangewith a padding byte after each entryThe earlier code is checking that the BMP palette is matches one of these grayscale palettes until it runs out of entries (until
file_info["colors"]is hit). It is checking that the BMP palette starts with one of these grayscale palettes.I did have to change one of our test images, but it came from https://github.com/python-pillow/Pillow/pull/5667. I wouldn't have been aware of the convention that the padding byte in the palette should be zero.