x, temp, val2. Find the bug.
r < 50. Now it only pauses for dark pixels. Debug targeted, not randomly.val2 → contrastFactor, temp → pixelMean. Good variable names eliminate the need for comments. Leave the code better than you found it.Don't try to understand everything. Find the entry point and the output. What goes in? What comes out? Trace the data flow from input to output.
Trace the data flow with strategic logging. Don't log everything — pick the 5 most important transformation points where values should change. Compare expected vs actual output at each.
Set a breakpoint at the start of the function. Step through line by line. Watch the pixel values: are they correct after each step?
Use a conditional breakpoint that only pauses when processing dark pixels (r < 50) — this is where the bug shows.
The bug: the contrast formula uses 128 as the midpoint instead of the image's actual mean brightness.
// Bug: hardcoded 128 as midpoint
// const adjusted = (pixel - 128) * factor + 128;
// Fix: use actual mean
const adjusted = (pixel - mean) * factor + mean;
Rename 8 variables to self-documenting names:
| Before | After |
|---|---|
| val2 | contrastFactor |
| temp | pixelMean |
| x | pixelValue |
| res | adjustedValue |
Add comments explaining the non-obvious parts. Leave the code better than you found it.
git switch -c bugfix/PIXELCRAFT-026-contrast-dark-images
git add src/scripts/
git commit -m "Fix contrast midpoint bug + clean up variable names (PIXELCRAFT-026)"
git push origin bugfix/PIXELCRAFT-026-contrast-dark-images
# PR → Review → Merge → Close ticket ✅
Professional developers spend more time reading code than writing it.
Studies show a 10:1 ratio — for every line written, 10 lines are read.