summaryrefslogtreecommitdiffstats
path: root/cmhw/org/cyanogenmod/hardware/DisplayColorCalibration.java
blob: 1cffbff616d3efb11e60dc95f851c8d91d8bbf6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (C) 2016 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

 /*
  * According to the OMAP color phase correction documentation,
  * this happens:
  *
  * +-    -+         +-        -+   +-   -+
  * | Rout |         | Rr Rg Rb |   | Rin |
  * |      |    1    |          |   |     |
  * | Gout | = --- * | Gr Gg Gb | * | Gin |
  * |      |   256   |          |   |     |
  * | Bout |         | Br Bg Bb |   | Bin |
  * +-    -+         +-        -+   +-   -+
  *
  * So to get the unmodified color, the values for Rr, Gg and Bb should
  * be set to 256, all others to 0. The values are 10 bit signed.
  *
  * This interface is exposed via sysfs and takes one line in the format:
  * Rr Rg Rb Gr Gg Gb Br Bg Bb
  */

package org.cyanogenmod.hardware;

import org.cyanogenmod.internal.util.FileUtils;

public class DisplayColorCalibration {
    private static final String COLOR_FILE = "/sys/devices/platform/omapdss/manager0/cpr_coef";
    private static final String COLOR_FILE_CTRL = "/sys/devices/platform/omapdss/manager0/cpr_enable";
    private static int last_rgb[] = { 256, 256, 256 };

    public static boolean isSupported() {
        return true;
    }

    public static int getMaxValue()  {
        return 256;
    }

    public static int getMinValue()  {
        return 0;
    }

    public static int getDefValue() {
        return getMaxValue();
    }

    public static String getCurColors()  {
        return last_rgb[0] + " " + last_rgb[1] + " " + last_rgb[2];
    }

    public static boolean setColors(String colors)  {
        String rgb[] = colors.split(" ");
        String cpr_coefs = rgb[0] + " 0 0 0 " + rgb[1] + " 0 0 0 " + rgb[2];

        if (last_rgb[0] == Integer.parseInt(rgb[0]) &&
                last_rgb[1] == Integer.parseInt(rgb[1]) &&
                last_rgb[2] == Integer.parseInt(rgb[2])) {
            return true;
        }

        if (!FileUtils.writeLine(COLOR_FILE, cpr_coefs)) {
            return false;
        }

        last_rgb[0] = Integer.parseInt(rgb[0]);
        last_rgb[1] = Integer.parseInt(rgb[1]);
        last_rgb[2] = Integer.parseInt(rgb[2]);

        return FileUtils.writeLine(COLOR_FILE_CTRL, "1");
    }
}