contrast
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | contrast [2017-05-25 01:54:20] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Setting contrast in X.org ====== | ||
| + | Use-case: Enhance contrast when reading scanned document and document viewer does not support contrast adjustment. | ||
| + | |||
| + | <note warning> | ||
| + | |||
| + | I was unable to find a tool that can fix this (tried xcalib, xgamma, xrandr and redshift). So I have created one myself. Unfortunately I don't know how to set contrast per window, so your whole X session is affected. | ||
| + | |||
| + | Compile: | ||
| + | |||
| + | gcc -std=gnu99 -O2 -g -ggdb3 -I/ | ||
| + | |||
| + | Usage: | ||
| + | < | ||
| + | (it's the same syntax like in GIMP) | ||
| + | |||
| + | Examples: | ||
| + | |||
| + | * Web2.0 page using gray text on white background (like [[http:// | ||
| + | < | ||
| + | |||
| + | * Scanned or photographed document | ||
| + | < | ||
| + | |||
| + | * Help! I've broken my X server and I see only a white/black screen! | ||
| + | < | ||
| + | |||
| + | |||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | int main(int argc, char **argv) { | ||
| + | |||
| + | /* XF86 substitution table */ | ||
| + | uint16_t rtable[256]; | ||
| + | |||
| + | |||
| + | /* read input */ | ||
| + | |||
| + | uint32_t lowcut = atoi(argv[1]); | ||
| + | uint32_t highcut = (255-atoi(argv[2])); | ||
| + | |||
| + | float slope = 257; | ||
| + | |||
| + | float range = 65535 - (lowcut*257 + highcut*257); | ||
| + | |||
| + | printf(" | ||
| + | |||
| + | if(range != 0) { | ||
| + | slope *= 65535/ | ||
| + | } | ||
| + | |||
| + | printf(" | ||
| + | |||
| + | |||
| + | /* compute profile */ | ||
| + | |||
| + | for(int i=0; i<256; i++) { | ||
| + | |||
| + | rtable[i] = (uint16_t) (slope*(i-lowcut)); | ||
| + | |||
| + | if(i< | ||
| + | rtable[i] = 0; | ||
| + | } | ||
| + | |||
| + | if(i> | ||
| + | rtable[i] = 0xffff; | ||
| + | } | ||
| + | |||
| + | printf(" | ||
| + | if(i%16 == 15 && i>1) { | ||
| + | printf(" | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | /* X11 magic */ | ||
| + | |||
| + | Display *dpy = NULL; | ||
| + | dpy = XOpenDisplay (NULL); | ||
| + | int screen = DefaultScreen (dpy); | ||
| + | |||
| + | XF86VidModeSetGammaRamp (dpy, screen, 256, rtable, rtable, rtable); | ||
| + | |||
| + | } | ||
| + | |||
| + | </ | ||
contrast.txt · Last modified: by 127.0.0.1
