summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blueshift_iccprofile.c15
-rw-r--r--src/icc.py53
2 files changed, 56 insertions, 12 deletions
diff --git a/src/blueshift_iccprofile.c b/src/blueshift_iccprofile.c
index 152b547..688b335 100644
--- a/src/blueshift_iccprofile.c
+++ b/src/blueshift_iccprofile.c
@@ -184,16 +184,17 @@ int main(int argc, char** argv)
}
{
- char* value = alloca((len + 1) * sizeof(char));
+ char* value = alloca((2 * len + 1) * sizeof(char));
char* value_ = xcb_get_property_value(prop_reply);
- memcpy(value, value_, len);
- *(value + len) = 0;
+ for (i = 0; i < len; i++)
+ {
+ *(value + i * 2 + 0) = "0123456789abcdef"[(*(value_ + i) >> 4) & 15];
+ *(value + i * 2 + 1) = "0123456789abcdef"[(*(value_ + i) >> 0) & 15];
+ }
+ *(value + 2 * len) = 0;
- printf("%i: %i: %s", screen_i, monitor, value);
- fflush(stdout);
- putchar('\0');
- putchar('\n');
+ printf("%i: %i: %s\n", screen_i, monitor, value);
}
free(prop_reply);
diff --git a/src/icc.py b/src/icc.py
index fbd7bdc..8e0dd14 100644
--- a/src/icc.py
+++ b/src/icc.py
@@ -15,6 +15,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from subprocess import Popen, PIPE
+
from curve import *
@@ -22,8 +24,52 @@ def load_icc(pathname):
'''
Load ICC profile from a file
- @param pathname The ICC profile file
- @return Function to invoke, parameterless, to apply the ICC profile to the colour curves
+ @param pathname:str The ICC profile file
+ @return :()→void Function to invoke, parameterless, to apply the ICC profile to the colour curves
+ '''
+ content = None
+ with open(pathname, 'rb') as file:
+ content = file.read()
+ return content
+
+
+def get_current_icc():
+ '''
+ Get all currently applied ICC profiles as profile applying functions
+
+ @return list<(screen:int, monitor:int, profile:()→void)> List of used profiles
+ '''
+ return [(screen, monitor, parse_icc(profile)) for screen, monitor, profile in get_current_icc_raw()]
+
+
+def get_current_icc_raw():
+ '''
+ Get all currently applied ICC profiles as raw profile data
+
+ @return list<(screen:int, monitor:int, profile:bytes())> List of used profiles
+ '''
+ process = Popen([LIBEXECDIR + "/blueshift_iccprofile"], stdout = PIPE)
+ lines = process.communicate()[0].decode('utf-8', 'error').split('\n')
+ while process.returncode is None:
+ process.wait()
+ if process.returncode != 0:
+ raise Exception('blueshift_iccprofile exited with value %i' % process.returncode)
+ rc = []
+ for line in lines:
+ if len(line) == 0:
+ continue
+ (s, m, p) = lines.split(': ')
+ p = bytes([int(p[i : i + 2], 16) for i in range(0, len(p), 2)])
+ rc.append((s, m, p))
+ return rc
+
+
+def parse_icc(content):
+ '''
+ Parse ICC profile from raw data
+
+ @param content:bytes The ICC profile data
+ @return :()→void Function to invoke, parameterless, to apply the ICC profile to the colour curves
'''
MLUT_TAG = 0x6d4c5554
VCGT_TAG = 0x76636774
@@ -42,9 +88,6 @@ def load_icc(pathname):
rc, content[:] = content[:n], content[n:]
return rc
- content = None
- with open(pathname, 'rb') as file:
- content = file.read()
content = list(content)
read(128)