Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(766)

Unified Diff: src/ply-gamma.c

Issue 6877024: Add gamma support to ply-image. (Closed) Base URL: ssh://gitrw.chromium.org:9222/ply-image.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/ply-gamma.h ('K') | « src/ply-gamma.h ('k') | src/ply-image.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ply-gamma.c
diff --git a/src/ply-gamma.c b/src/ply-gamma.c
new file mode 100644
index 0000000000000000000000000000000000000000..1cd1ea9a39609779f09f0e1a7ff4fef12df0c0ec
--- /dev/null
+++ b/src/ply-gamma.c
@@ -0,0 +1,124 @@
+/* ply-gamma.c - plymouth gamma setup via KMS
+ *
+ * Copyright (C) 2011, The Chromium OS Authors.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include "ply-gamma.h"
Daniel Erat 2011/04/19 16:46:02 nit: this include should come first
marcheu 2011/04/19 18:02:45 Done.
+
+static const char* gammaRampFile = "/usr/share/color/icc/internal_display.bin";
+static const int internalPanel = 1;
Daniel Erat 2011/04/19 16:46:02 name variables like_this instead of likeThis
marcheu 2011/04/19 18:02:45 Done but differently per our discussion.
+
+typedef struct {
+ uint16_t *red;
+ uint16_t *green;
+ uint16_t *blue;
+} gamma_ramp;
Daniel Erat 2011/04/19 16:46:02 this should be GammaRamp instead (at least, i thin
marcheu 2011/04/19 18:02:45 Done.
+
+static gamma_ramp* load_gamma_ramp(const char* file)
+{
Daniel Erat 2011/04/19 16:46:02 move to end of previous line here and elsewhere
marcheu 2011/04/19 18:02:45 Done.
+ const int gamma_size = 256;
Daniel Erat 2011/04/19 16:46:02 kGammaSize
marcheu 2011/04/19 18:02:45 Done.
+ int i, r = 0;
+
+ FILE* f = fopen(file, "rb");
+ if (!f)
+ return NULL;
+
+ unsigned char red[gamma_size], green[gamma_size], blue[gamma_size];
+
+ r += fread(red, gamma_size, 1, f);
Daniel Erat 2011/04/19 16:46:02 can you s/gamma_size/sizeof(red)/ here?
marcheu 2011/04/19 18:02:45 Done.
+ r += fread(green, gamma_size, 1, f);
+ r += fread(blue, gamma_size, 1, f);
+ fclose(f);
+
+ if (r != 3)
+ return NULL;
+
+ gamma_ramp* ramp = (gamma_ramp*)malloc(sizeof(gamma_ramp));
+ ramp->red = (uint16_t*)malloc(sizeof(uint16_t) * gamma_size);
+ ramp->green = (uint16_t*)malloc(sizeof(uint16_t) * gamma_size);
+ ramp->blue = (uint16_t*)malloc(sizeof(uint16_t) * gamma_size);
+
+ for(i = 0; i < gamma_size; ++i)
+ {
Daniel Erat 2011/04/19 16:46:02 you know what i'm going to say here
marcheu 2011/04/19 18:02:45 Done.
+ ramp->red[i] = (uint16_t)red[i] * 257;
+ ramp->green[i] = (uint16_t)green[i] * 257;
+ ramp->blue[i] = (uint16_t)blue[i] * 257;
+ }
+
+ return ramp;
+}
+
+static void free_gamma_ramp(gamma_ramp* ramp)
+{
+ free(ramp->red);
+ free(ramp->green);
+ free(ramp->blue);
+ free(ramp);
+}
+
+bool
+ply_gamma_set()
Daniel Erat 2011/04/19 16:46:02 return type and function name should be on same li
marcheu 2011/04/19 18:02:45 Done.
+{
+ int i, r;
+ drmModeCrtcPtr mode;
+ gamma_ramp* ramp;
+
+ ramp = load_gamma_ramp (gammaRampFile);
Daniel Erat 2011/04/19 16:46:02 no space between function name and opening parenth
marcheu 2011/04/19 18:02:45 Done.
+
+ if (!ramp)
+ {
+ fprintf(stderr, "Unable to load gamma ramp\n");
+ return false;
+ }
+
+ int fd = drmOpen("i915", NULL);
+ if (fd < 0)
+ {
+ fprintf(stderr, "Unable to open i915 drm\n");
+ return false;
+ }
+
+ drmModeRes *resources = drmModeGetResources (fd);
+ if (!resources)
+ {
+ fprintf(stderr, "Unable to get mode resources\n");
+ drmClose(fd);
+ return false;
+ }
+
+ mode = drmModeGetCrtc (fd, resources->crtcs[internalPanel]);
+ r = drmModeCrtcSetGamma (fd,
+ mode->crtc_id,
+ mode->gamma_size,
+ ramp->red,
+ ramp->green,
+ ramp->blue);
+
+ drmModeFreeResources(resources);
+ drmClose(fd);
+ free_gamma_ramp(ramp);
+ return r >= 0;
+}
+
Daniel Erat 2011/04/19 16:46:02 remove extra newlines at end of file
marcheu 2011/04/19 18:02:45 Done.
+
« src/ply-gamma.h ('K') | « src/ply-gamma.h ('k') | src/ply-image.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698