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

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: git cl push 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
« no previous file with comments | « src/ply-gamma.h ('k') | src/ply-image.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ply-gamma.h"
23
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <xf86drm.h>
28 #include <xf86drmMode.h>
29
30 static const int kInternalPanel = 1;
31
32 typedef struct {
33 uint16_t *red;
34 uint16_t *green;
35 uint16_t *blue;
36 } GammaRamp;
37
38 static GammaRamp* load_gamma_ramp(const char* file) {
39 const int kGammaSize = 256;
40 int i, r = 0;
41
42 FILE* f = fopen(file, "rb");
43 if (!f)
44 return NULL;
45
46 unsigned char red[kGammaSize], green[kGammaSize], blue[kGammaSize];
47
48 r += fread(red, sizeof(red), 1, f);
49 r += fread(green, sizeof(green), 1, f);
50 r += fread(blue, sizeof(blue), 1, f);
51 fclose(f);
52
53 if (r != 3)
54 return NULL;
55
56 GammaRamp* ramp = (GammaRamp*)malloc(sizeof(GammaRamp));
57 ramp->red = (uint16_t*)malloc(sizeof(uint16_t) * kGammaSize);
58 ramp->green = (uint16_t*)malloc(sizeof(uint16_t) * kGammaSize);
59 ramp->blue = (uint16_t*)malloc(sizeof(uint16_t) * kGammaSize);
60
61 for(i = 0; i < kGammaSize; ++i) {
62 ramp->red[i] = (uint16_t)red[i] * 257;
63 ramp->green[i] = (uint16_t)green[i] * 257;
64 ramp->blue[i] = (uint16_t)blue[i] * 257;
65 }
66
67 return ramp;
68 }
69
70 static void free_gamma_ramp(GammaRamp* ramp) {
71 free(ramp->red);
72 free(ramp->green);
73 free(ramp->blue);
74 free(ramp);
75 }
76
77 bool ply_gamma_set(const char* file) {
78 int r;
79 drmModeCrtcPtr mode;
80 GammaRamp* ramp;
81
82 ramp = load_gamma_ramp(file);
83
84 if (!ramp) {
85 fprintf(stderr, "Unable to load gamma ramp\n");
86 return false;
87 }
88
89 int fd = drmOpen("i915", NULL);
90 if (fd < 0) {
91 fprintf(stderr, "Unable to open i915 drm\n");
92 return false;
93 }
94
95 drmModeRes *resources = drmModeGetResources(fd);
96 if (!resources) {
97 fprintf(stderr, "Unable to get mode resources\n");
98 drmClose(fd);
99 return false;
100 }
101
102 mode = drmModeGetCrtc(fd, resources->crtcs[kInternalPanel]);
103 r = drmModeCrtcSetGamma(fd,
104 mode->crtc_id,
105 mode->gamma_size,
106 ramp->red,
107 ramp->green,
108 ramp->blue);
109
110 drmModeFreeResources(resources);
111 drmClose(fd);
112 free_gamma_ramp(ramp);
113 return r >= 0;
114 }
OLDNEW
« no previous file with comments | « src/ply-gamma.h ('k') | src/ply-image.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698