aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-08-08 21:33:02 +0200
committerMattias Andrée <maandree@operamail.com>2014-08-08 21:33:02 +0200
commit680aab24bb74f33b4021e5ebd2a01884149feeaf (patch)
treef43b90b20a9aa2a57654f899b8a42b963d6b49d7 /src
parentm (diff)
downloadcrt-calibrator-680aab24bb74f33b4021e5ebd2a01884149feeaf.tar.gz
crt-calibrator-680aab24bb74f33b4021e5ebd2a01884149feeaf.tar.bz2
crt-calibrator-680aab24bb74f33b4021e5ebd2a01884149feeaf.tar.xz
misc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r--src/calibrator.c61
-rw-r--r--src/gamma.c2
-rw-r--r--src/state.c39
-rw-r--r--src/state.h17
4 files changed, 114 insertions, 5 deletions
diff --git a/src/calibrator.c b/src/calibrator.c
index 9ee0d88..b308c38 100644
--- a/src/calibrator.c
+++ b/src/calibrator.c
@@ -199,6 +199,44 @@ void draw_gamma(void)
}
+static int read_calibs(void)
+{
+ size_t c;
+ for (c = 0; c < crtc_count; c++)
+ {
+ if (drm_get_gamma(crtcs + c) < 0)
+ return -1;
+
+ gamma_analyse(crtcs[c].gamma_stops, crtcs[c].red, gammas[0] + c,
+ contrasts[0] + c, brightnesses[0] + c);
+ gamma_analyse(crtcs[c].gamma_stops, crtcs[c].green, gammas[1] + c,
+ contrasts[1] + c, brightnesses[1] + c);
+ gamma_analyse(crtcs[c].gamma_stops, crtcs[c].blue, gammas[2] + c,
+ contrasts[2] + c, brightnesses[2] + c);
+ }
+ return 0;
+}
+
+
+static int apply_calibs(void)
+{
+ size_t c;
+ for (c = 0; c < crtc_count; c++)
+ {
+ gamma_generate(crtcs[c].gamma_stops, crtcs[c].red, gammas[0][c],
+ contrasts[0][c], brightnesses[0][c]);
+ gamma_generate(crtcs[c].gamma_stops, crtcs[c].green, gammas[1][c],
+ contrasts[1][c], brightnesses[1][c]);
+ gamma_generate(crtcs[c].gamma_stops, crtcs[c].blue, gammas[2][c],
+ contrasts[2][c], brightnesses[2][c]);
+
+ if (drm_set_gamma(crtcs + c) < 0)
+ return -1;
+ }
+ return 0;
+}
+
+
int main(int argc __attribute__((unused)), char* argv[])
{
int tty_configured = 0, rc = 0, in_fork = 0;
@@ -262,7 +300,7 @@ int main(int argc __attribute__((unused)), char* argv[])
printf("contrast should be as high as possible without\n");
printf("causing distortion.\n");
printf("\n");
- printf("Press ENTER to continue, and ENTER again once\n");
+ printf("Press ENTER to continue, and ENTER again when\n");
printf("your are done.\n");
fflush(stdout);
@@ -276,7 +314,26 @@ int main(int argc __attribute__((unused)), char* argv[])
while (getchar() != 10)
;
- if (draw_id() < 0)
+ printf("\033[H\033[2J");
+ printf("An index will be displayed on each monitor.\n");
+ printf("It behoves you to memorise them.\n");
+ printf("\n");
+ printf("Press ENTER to continue, and ENTER again when\n");
+ printf("your are done.\n");
+ fflush(stdout);
+
+ while (getchar() != 10)
+ ;
+
+ printf("\033[H\033[2J");
+ fflush(stdout);
+ if ((read_calibs() < 0) || (draw_id() < 0))
+ goto fail;
+
+ while (getchar() != 10)
+ ;
+
+ if (apply_calibs() < 0)
goto fail;
done:
diff --git a/src/gamma.c b/src/gamma.c
index 843403d..f0dc05b 100644
--- a/src/gamma.c
+++ b/src/gamma.c
@@ -38,7 +38,7 @@ void gamma_analyse(size_t stops, const uint16_t* restrict ramp, double* restrict
middle = (double)(ramp[stops / 2]) / (double)0xFFFF;
middle = (middle - min) / (max - min);
- *gamma = log((double)2) / log(middle);
+ *gamma = -log((double)2) / log(middle);
}
diff --git a/src/state.c b/src/state.c
index 4ca3a75..b4ec11a 100644
--- a/src/state.c
+++ b/src/state.c
@@ -46,7 +46,22 @@ size_t card_count = 0;
drm_crtc_t* restrict crtcs = NULL;
/**
- * The number of elements in `crtcs`
+ * The software brightness setting on each connected CRT controller, on each channel
+ */
+double* restrict brightnesses[3];
+
+/**
+ * The software contrast setting on each connected CRT controller, on each channel
+ */
+double* restrict contrasts[3];
+
+/**
+ * The gamma correction on each connected CRT controller, on each channel
+ */
+double* restrict gammas[3];
+
+/**
+ * The number of elements in `crtcs`, `brightnesses[]`, `contrasts[]` and `gammas[]`
*/
size_t crtc_count = 0;
@@ -105,6 +120,21 @@ int acquire_video(void)
}
}
+ for (c = 0; c < 3; c++)
+ {
+ brightnesses[c] = malloc(crtc_count * sizeof(double));
+ if (brightnesses[c] == NULL)
+ return -1;
+
+ contrasts[c] = malloc(crtc_count * sizeof(double));
+ if (contrasts[c] == NULL)
+ return -1;
+
+ gammas[c] = malloc(crtc_count * sizeof(double));
+ if (gammas[c] == NULL)
+ return -1;
+ }
+
return 0;
}
@@ -128,6 +158,13 @@ void release_video(void)
fb_close(framebuffers + i);
framebuffer_count = 0;
+ for (i = 0; i < 3; i++)
+ {
+ free(brightnesses[i]), brightnesses[i] = NULL;
+ free(contrasts[i]), contrasts[i] = NULL;
+ free(gammas[i]), gammas[i] = NULL;
+ }
+
free(crtcs), crtcs = NULL;
free(cards), cards = NULL;
free(framebuffers), framebuffers = NULL;
diff --git a/src/state.h b/src/state.h
index fd5a18e..da4a580 100644
--- a/src/state.h
+++ b/src/state.h
@@ -51,7 +51,22 @@ extern size_t card_count;
extern drm_crtc_t* restrict crtcs;
/**
- * The number of elements in `crtcs`
+ * The software brightness setting on each connected CRT controller, on each channel
+ */
+extern double* restrict brightnesses[3];
+
+/**
+ * The software contrast setting on each connected CRT controller, on each channel
+ */
+extern double* restrict contrasts[3];
+
+/**
+ * The gamma correction on each connected CRT controller, on each channel
+ */
+extern double* restrict gammas[3];
+
+/**
+ * The number of elements in `crtcs`, `brightnesses[]`, `contrasts[]` and `gammas[]`
*/
extern size_t crtc_count;