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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /* ply-gamma.c - plymouth gamma setup via KMS
2 *
3 * Copyright (C) 2011, The Chromium OS Authors.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 * 02111-1307, USA.
19 *
20 */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <xf86drm.h>
25 #include <xf86drmMode.h>
26
27 #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.
28
29 static const char* gammaRampFile = "/usr/share/color/icc/internal_display.bin";
30 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.
31
32 typedef struct {
33 uint16_t *red;
34 uint16_t *green;
35 uint16_t *blue;
36 } 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.
37
38 static gamma_ramp* load_gamma_ramp(const char* file)
39 {
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.
40 const int gamma_size = 256;
Daniel Erat 2011/04/19 16:46:02 kGammaSize
marcheu 2011/04/19 18:02:45 Done.
41 int i, r = 0;
42
43 FILE* f = fopen(file, "rb");
44 if (!f)
45 return NULL;
46
47 unsigned char red[gamma_size], green[gamma_size], blue[gamma_size];
48
49 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.
50 r += fread(green, gamma_size, 1, f);
51 r += fread(blue, gamma_size, 1, f);
52 fclose(f);
53
54 if (r != 3)
55 return NULL;
56
57 gamma_ramp* ramp = (gamma_ramp*)malloc(sizeof(gamma_ramp));
58 ramp->red = (uint16_t*)malloc(sizeof(uint16_t) * gamma_size);
59 ramp->green = (uint16_t*)malloc(sizeof(uint16_t) * gamma_size);
60 ramp->blue = (uint16_t*)malloc(sizeof(uint16_t) * gamma_size);
61
62 for(i = 0; i < gamma_size; ++i)
63 {
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.
64 ramp->red[i] = (uint16_t)red[i] * 257;
65 ramp->green[i] = (uint16_t)green[i] * 257;
66 ramp->blue[i] = (uint16_t)blue[i] * 257;
67 }
68
69 return ramp;
70 }
71
72 static void free_gamma_ramp(gamma_ramp* ramp)
73 {
74 free(ramp->red);
75 free(ramp->green);
76 free(ramp->blue);
77 free(ramp);
78 }
79
80 bool
81 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.
82 {
83 int i, r;
84 drmModeCrtcPtr mode;
85 gamma_ramp* ramp;
86
87 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.
88
89 if (!ramp)
90 {
91 fprintf(stderr, "Unable to load gamma ramp\n");
92 return false;
93 }
94
95 int fd = drmOpen("i915", NULL);
96 if (fd < 0)
97 {
98 fprintf(stderr, "Unable to open i915 drm\n");
99 return false;
100 }
101
102 drmModeRes *resources = drmModeGetResources (fd);
103 if (!resources)
104 {
105 fprintf(stderr, "Unable to get mode resources\n");
106 drmClose(fd);
107 return false;
108 }
109
110 mode = drmModeGetCrtc (fd, resources->crtcs[internalPanel]);
111 r = drmModeCrtcSetGamma (fd,
112 mode->crtc_id,
113 mode->gamma_size,
114 ramp->red,
115 ramp->green,
116 ramp->blue);
117
118 drmModeFreeResources(resources);
119 drmClose(fd);
120 free_gamma_ramp(ramp);
121 return r >= 0;
122 }
123
Daniel Erat 2011/04/19 16:46:02 remove extra newlines at end of file
marcheu 2011/04/19 18:02:45 Done.
124
OLDNEW
« 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