From 9ce39213f4e21a5b080a101245ec63893e3e3a14 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Wed, 13 Jan 2016 23:06:07 +0100 Subject: add CMHW for ColorCalibration/LiveDisplay This uses the color phase rotation hardware of Omap4 to set RGB calibration values. Change-Id: I101953fbac46235a178824f9d94470b4fe558b76 --- .../hardware/DisplayColorCalibration.java | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 cmhw/org/cyanogenmod/hardware/DisplayColorCalibration.java diff --git a/cmhw/org/cyanogenmod/hardware/DisplayColorCalibration.java b/cmhw/org/cyanogenmod/hardware/DisplayColorCalibration.java new file mode 100644 index 0000000..bc6cc85 --- /dev/null +++ b/cmhw/org/cyanogenmod/hardware/DisplayColorCalibration.java @@ -0,0 +1,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.hardware.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"); + } +} -- cgit v1.1