forked from 1b-agent/opencadstudio-upstream
PDF underlays: adjusting for a dark background turns every colour's lightness over
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c1ecb0edaf
commit
cfa4b186c5
1 file changed
+9
-15
@@ -247,21 +247,15 @@ pub fn adjusted_pixels(path: &str, page: &str, raster: &PdfPage, adjust: PageAdj
|
|||||||
let l = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2];
|
let l = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2];
|
||||||
rgb = [l; 3];
|
rgb = [l; 3];
|
||||||
}
|
}
|
||||||
if adjust.adjust_for_background {
|
if adjust.adjust_for_background && adjust.dark_background {
|
||||||
// Content that would vanish into the background — near-black on a
|
// On a dark background every colour's lightness is turned over
|
||||||
// dark background, near-white on a light one, without much
|
// (plus 20/255, capped at full), hue and saturation kept: black
|
||||||
// colour — turns to its opposite; coloured and mid-tone content
|
// becomes white, dark red light pink. On a light background the
|
||||||
// stays as drawn.
|
// colours stay as drawn.
|
||||||
let max = rgb[0].max(rgb[1]).max(rgb[2]);
|
// ponytail: offset and the light-background rule measured on the
|
||||||
let min = rgb[0].min(rgb[1]).min(rgb[2]);
|
// default backgrounds only (pure white on paper not measured).
|
||||||
let saturation = if max > 0.0 { (max - min) / max } else { 0.0 };
|
let (h, s, l) = rgb_to_hsl(rgb);
|
||||||
let l = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2];
|
rgb = hsl_to_rgb(h, s, (1.0 - l + 20.0 / 255.0).min(1.0));
|
||||||
// ponytail: fixed 0.2 / 0.8 thresholds measured on black, white
|
|
||||||
// and 30 % grey; a contrast-to-background test if mid tones clash.
|
|
||||||
let clash = if adjust.dark_background { l < 0.2 } else { l > 0.8 };
|
|
||||||
if saturation < 0.25 && clash {
|
|
||||||
rgb = rgb.map(|c| 1.0 - c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if adjust.contrast < 100 {
|
if adjust.contrast < 100 {
|
||||||
// Lightness is pulled towards one third, hue and saturation kept:
|
// Lightness is pulled towards one third, hue and saturation kept:
|
||||||
|
|||||||
Reference in new issue
Block a user