29
29
* Is there a >8 bit way of getting/setting RAMDAC indexes ?
31
* It would be good to be able to calibrate this with a faste
32
* meter like the i1d3. Run the i1d3 at (say) 10 msec sample time
33
* and see how many msec white<->black until it is stable.
34
* Double + add 50msec.
1397
1402
/* restoring the previous display profile whenever the current ColorSync display profile */
1398
1403
/* is restored to the screen. NOTE that this trick will fail if it is not possible */
1399
1404
/* to rename the currently selected profile file, ie. because it is a system profile. */
1405
/* [ Would a workaround be to use a link, or copy of the system file ? ] */
1400
1406
if (persist) { /* Persistent */
1402
1408
CMProfileRef prof; /* Current AVID profile */
1875
1881
#endif /* NT */
1883
/* For Linux and OS X, make sure we don't create a file with the wrong owner */
1885
/* If we're creating a user profile and running as root sudo */
1886
if (scope == p_scope_user && geteuid() == 0) {
1890
debugr("We're setting a user profile running as root - run as user\n");
1891
if ((uids = getenv("SUDO_UID")) != NULL
1892
&& (gids = getenv("SUDO_GID")) != NULL) {
1895
if (setegid(gid) || seteuid(uid)) {
1896
debugr("seteuid or setegid failed\n");
1898
debug2((errout,"Set euid %d and egid %d\n",uid,gid));
1900
/* If setting local system proile and not effective root, but sudo */
1901
} else if (scope != p_scope_user && getuid() == 0 && geteuid() != 0) {
1902
if (getenv("SUDO_UID") != NULL
1903
&& getenv("SUDO_GID") != NULL) {
1905
debugr("We're setting a system profile running as user - revert to root\n");
1910
#endif /* OS X || Linux */
1877
1912
#ifdef __APPLE__
2103
2138
#endif /* NT */
2140
/* For Linux and OS X, make sure we don't create a file with the wrong owner */
2142
/* If we're creating a user profile and running as root sudo */
2143
if (scope == p_scope_user && geteuid() == 0) {
2147
debugr("We're setting a user profile running as root - run as user\n");
2148
if ((uids = getenv("SUDO_UID")) != NULL
2149
&& (gids = getenv("SUDO_GID")) != NULL) {
2152
if (setegid(gid) || seteuid(uid)) {
2153
debugr("seteuid or setegid failed\n");
2155
debug2((errout,"Set euid %d and egid %d\n",uid,gid));
2157
/* If setting local system proile and not effective root, but sudo */
2158
} else if (scope != p_scope_user && getuid() == 0 && geteuid() != 0) {
2159
if (getenv("SUDO_UID") != NULL
2160
&& getenv("SUDO_GID") != NULL) {
2162
debugr("We're setting a system profile running as user - revert to root\n");
2167
#endif /* OS X || Linux */
2105
2169
#ifdef __APPLE__
3027
3091
#endif /* NT */
3029
/* Create a RAMDAC access and display test window, default white */
3093
/* Create a RAMDAC access and display test window, default grey */
3030
3094
dispwin *new_dispwin(
3031
3095
disppath *disp, /* Display to calibrate. */
3032
3096
double width, double height, /* Width and height in mm */
3033
3097
double hoff, double voff, /* Offset from center in fraction of screen, range -1.0 .. 1.0 */
3034
3098
int nowin, /* NZ if no window should be created - RAMDAC access only */
3035
3099
int native, /* 0 = use current current or given calibration curve */
3036
/* 1 = set native linear output and use ramdac high prec'n */
3037
/* 2 = set native linear output */
3100
/* 1 = use native linear out & high precision */
3101
int *noramdac, /* Return nz if no ramdac access. native is set to 0 */
3038
3102
int blackbg, /* NZ if whole screen should be filled with black */
3039
3103
int override, /* NZ if override_redirect is to be used on X11 */
3040
3104
int ddebug /* >0 to print debug statements to stderr */
3756
3820
debug("About to setup native mode\n");
3757
3821
if ((p->or = p->get_ramdac(p)) == NULL
3758
3822
|| (p->r = p->or->clone(p->or)) == NULL) {
3759
if (p->native == 1) {
3760
debugr("new_dispwin: Native mode can't work, no VideoLUT support\n");
3761
warning("new_dispwin: Native mode can't work, no VideoLUT support");
3765
debugr("new_dispwin: Accessing VideoLUT failed, so no way to guarantee that calibration is turned off!!\n");
3766
warning("new_dispwin: Accessing VideoLUT failed, so no way to guarantee that calibration is turned off!!");
3823
if (noramdac != NULL)
3825
debugr("new_dispwin: Accessing VideoLUT failed, so no way to guarantee that calibration is turned off!!\n");
3826
warning("new_dispwin: Accessing VideoLUT failed, so no way to guarantee that calibration is turned off!!");
3769
3829
p->r->setlin(p->r);
3830
if (noramdac != NULL)
3770
3832
debug("Saved original VideoLUT\n");
3835
if (p->get_ramdac(p) == NULL) {
3836
if (noramdac != NULL)
3774
3841
/* Make sure initial test color is displayed */
3900
3967
if (verb) printf("Updating display %d = '%s'\n",i+1,dp[i]->description);
3902
if ((dw = new_dispwin(dp[i], 0.0, 0.0, 0.0, 0.0, 1, 0, 0, 0, ddebug)) == NULL) {
3969
if ((dw = new_dispwin(dp[i], 0.0, 0.0, 0.0, 0.0, 1, 0, NULL, 0, 0, ddebug)) == NULL) {
3903
3970
if (verb) printf("Failed to access screen %d of display '%s'\n",i+1,dnbuf);
4050
4117
free_disppaths(dp);
4118
fprintf(stderr," -dweb[:port] Display via a web server at port (default 8080)\n");
4051
4119
fprintf(stderr," -P ho,vo,ss Position test window and scale it\n");
4052
4120
fprintf(stderr," -F Fill whole screen with black background\n");
4053
4121
fprintf(stderr," -i Run forever with random values\n");
4081
4149
int fa, nfa, mfa; /* current argument we're looking at */
4082
4150
int verb = 0; /* Verbose flag */
4083
4151
int ddebug = 0; /* debug level */
4152
int webdisp = 0; /* NZ for web display, == port number */
4084
4153
disppath *disp = NULL; /* Display being used */
4085
4154
double patscale = 1.0; /* scale factor for test patch size */
4086
4155
double ho = 0.0, vo = 0.0; /* Test window offsets, -1.0 to 1.0 */
4091
4160
int native = 0; /* 0 = use current current or given calibration curve */
4092
4161
/* 1 = set native linear output and use ramdac high prec'n */
4093
4162
/* 2 = set native linear output */
4163
int noramdac = 0; /* Set to nz if there is no VideoLUT access */
4094
4164
int inf = 0; /* Infnite/manual patches flag */
4095
4165
char pcname[MAXNAMEL+1] = "\000"; /* CGATS patch color name */
4096
4166
int clear = 0; /* Clear any display calibration (any calname is ignored) */
4149
4219
/* Display number */
4150
4220
else if (argv[fa][1] == 'd') {
4221
if (strncmp(na,"web",3) == 0
4222
|| strncmp(na,"WEB",3) == 0) {
4225
webdisp = atoi(na+4);
4226
if (webdisp == 0 || webdisp > 65535)
4227
usage("Web port number must be in range 1..65535");
4151
4231
#if defined(UNIX) && !defined(__APPLE__)
4154
/* X11 type display name. */
4155
if (strcmp(&argv[fa][2], "isplay") == 0 || strcmp(&argv[fa][2], "ISPLAY") == 0) {
4156
if (++fa >= argc || argv[fa][0] == '-') usage("-DISPLAY parameter missing");
4157
setenv("DISPLAY", argv[fa], 1);
4159
if (na == NULL) usage("-d parameter missing");
4234
/* X11 type display name. */
4235
if (strcmp(&argv[fa][2], "isplay") == 0 || strcmp(&argv[fa][2], "ISPLAY") == 0) {
4236
if (++fa >= argc || argv[fa][0] == '-') usage("-DISPLAY parameter missing");
4237
setenv("DISPLAY", argv[fa], 1);
4239
if (na == NULL) usage("-d parameter missing");
4241
if (sscanf(na, "%d,%d",&ix,&iv) != 2) {
4246
free_a_disppath(disp);
4247
if ((disp = get_a_display(ix-1)) == NULL)
4248
usage("-d parameter '%s' is out of range",na);
4250
disp->rscreen = iv-1;
4254
if (na == NULL) usage("-d parameter is missing");
4161
if (sscanf(na, "%d,%d",&ix,&iv) != 2) {
4165
4257
if (disp != NULL)
4166
4258
free_a_disppath(disp);
4167
4259
if ((disp = get_a_display(ix-1)) == NULL)
4168
4260
usage("-d parameter '%s' is out of range",na);
4170
disp->rscreen = iv-1;
4174
if (na == NULL) usage("-d parameter is missing");
4178
free_a_disppath(disp);
4179
if ((disp = get_a_display(ix-1)) == NULL)
4180
usage("-d parameter '%s' is out of range",na);
4184
4265
/* Test patch offset and size */
4312
4393
if (ramd != 0 || sname[0] != '\000' || clear != 0 || verify != 0 || loadfile != 0 || installprofile != 0 || loadprofile != 0)
4316
printf("About to open dispwin object on the display\n");
4318
if ((dw = new_dispwin(disp, 100.0 * patscale, 100.0 * patscale, ho, vo, nowin, native, blackbg, 1, ddebug)) == NULL) {
4319
printf("Error - new_dispwin failed!\n");
4398
if ((dw = new_webwin(webdisp, 100.0 * patscale, 100.0 * patscale, ho, vo, nowin, blackbg, verb, ddebug)) == NULL) {
4399
printf("Error - new_webpwin failed!\n");
4405
if (verb) printf("About to open dispwin object on the display\n");
4406
if ((dw = new_dispwin(disp, 100.0 * patscale, 100.0 * patscale, ho, vo, nowin, native, &noramdac, blackbg, 1, ddebug)) == NULL) {
4407
printf("Error - new_dispwin failed!\n");
4412
if (native != 0 && noramdac) {
4413
error("We don't have access to the VideoLUT so can't display native colors\n");
4323
4416
/* Save the current Video LUT to the calfile */
4324
4417
if (sname[0] != '\000') {
4325
4418
cgats *ocg; /* output cgats structure */
4401
4494
printf("About to clear the calibration\n");
4402
4495
if ((rv = dw->set_ramdac(dw,r,1)) != 0) {
4404
error("Failed to set VideoLUTs persistently due to current System Profile");
4497
warning("Failed to set VideoLUTs persistently because current System Profile can't be renamed");
4406
4499
error("Failed to set VideoLUTs");
4434
4527
icc *icco = NULL;
4435
4528
cgats *ccg = NULL; /* calibration cgats structure */
4437
if ((r = dw->get_ramdac(dw)) == NULL) {
4438
error("We don't have access to the VideoLUT");
4530
/* Get a calibration that's compatible with the display. */
4531
/* This can fail and return NULL - error if we later need it */
4532
r = dw->get_ramdac(dw);
4441
4534
/* Should we load calfile instead of installed profile if it's present ??? */
4442
4535
if (loadprofile) {
4466
4559
is_ok_icc = 1; /* The profile is OK */
4468
4561
if ((wo = (icmVideoCardGamma *)icco->read_tag(icco, icSigVideoCardGammaTag)) == NULL) {
4469
warning("No vcgt tag found in profile - using linear\n");
4470
for (i = 0; i < r->nent; i++) {
4471
iv = i/(r->nent-1.0);
4562
warning("No vcgt tag found in profile - assuming linear\n");
4564
for (i = 0; i < r->nent; i++) {
4565
iv = i/(r->nent-1.0);
4573
/* Hmm. Perhaps we should ignore this if the vcgt is linear ?? */
4575
error("We don't have access to the VideoLUT");
4478
4577
if (wo->u.table.channels == 3) {
4479
4578
for (i = 0; i < r->nent; i++) {
4480
4579
iv = i/(r->nent-1.0);
4597
4699
} else if (loadfile != 0 || (loadprofile != 0 && verify == 0)) {
4601
error("ICC profile '%s' has no vcgt calibration table",calname);
4603
printf("About to set display to given calibration\n");
4604
if ((rv = dw->set_ramdac(dw,r,1)) != 0) {
4606
error("Failed to set VideoLUTs persistently due to current System Profile");
4608
error("Failed to set VideoLUTs");
4702
/* r == NULL if no VideoLUT access and ICC profile without vcgt */
4704
warning("No linear calibration loaded because there is no access to the VideoLUT");
4707
printf("About to set display to given calibration\n");
4708
if ((rv = dw->set_ramdac(dw,r,1)) != 0) {
4710
error("Failed to set VideoLUTs persistently because current System Profile can't be renamed");
4712
error("Failed to set VideoLUTs");
4715
printf("Calibration set\n");
4611
printf("Calibration set\n");
4614
4719
if (verify != 0) {
4617
4722
if ((or = dw->get_ramdac(dw)) == NULL)
4618
4723
error("Unable to get current VideoLUT for verify");
4726
error("No calibration to verify against");
4620
4728
for (j = 0; j < 3; j++) {
4621
4729
for (i = 0; i < r->nent; i++) {