shithub: libicc

Download patch

ref: 6727b8912f34a00c4a8a83b0795f9bbf96c06fe9
parent: 7fa741a4a2b7d50a232daec2b6fcb67afdabc2a5
author: sirjofri <sirjofri@sirjofri.de>
date: Mon Apr 6 17:45:57 EDT 2026

successfully read mluc data

--- a/icc.h
+++ b/icc.h
@@ -108,10 +108,30 @@
 	ulong ntags;
 };
 
+typedef struct ICCTagPtr ICCTagPtr;
+struct ICCTagPtr {
+	uchar *ptr;
+	u32int type;
+	u32int size;
+};
+
 ICCprofile *iccload(int fd);
 char *iccgetclass(ICCprofile*);
 char *iccgetdataspace(ICCprofile*);
 char *iccgetpcs(ICCprofile*);
+
+ICCTagPtr iccfindtag(ICCprofile*, u32int);
+
+typedef struct MlucEntry MlucEntry;
+struct MlucEntry {
+	u16int language;
+	u16int country;
+	char *str;
+	int length;
+};
+
+int mlucnum(uchar*);
+MlucEntry mlucentry(uchar*, int);
 
 double s15f16tod(s15f16);
 s15f16 dtos16f16(double);
\ No newline at end of file
--- a/load.c
+++ b/load.c
@@ -42,7 +42,7 @@
 	[IFCLR]   "FCLR",
 };
 
-static u16int
+u16int
 iread16(uchar *data)
 {
 	u16int *d = (u16int*)data;
@@ -49,7 +49,7 @@
 	return ((*d)<<8)&0xff00 | ((*d)>>8)&0x00ff;
 }
 
-static u32int
+u32int
 iread32(uchar *data)
 {
 	u32int *d = (u32int*)data;
@@ -61,7 +61,7 @@
 	);
 }
 
-static u64int
+u64int
 iread64(uchar *data)
 {
 	u64int *d = (u64int*)data;
@@ -264,6 +264,27 @@
 	}
 	
 	return prof;
+}
+
+ICCTagPtr
+iccfindtag(ICCprofile *prof, u32int signature)
+{
+	ICCTagPtr p;
+	int i;
+	
+	for (i = 0; i < prof->ntags; i++) {
+		if (prof->tags[i].signature != signature)
+			continue;
+		p.ptr = prof->tagdata + prof->tags[i].offset - 128;
+		p.size = prof->tags[i].size;
+		p.type = iread32(p.ptr);
+		return p;
+	}
+	
+	p.ptr = nil;
+	p.type = 0;
+	p.size = 0;
+	return p;
 }
 
 double
--- a/mkfile
+++ b/mkfile
@@ -3,5 +3,6 @@
 LIB=icc.a$O
 OFILES=\
 	load.$O\
+	mluc.$O\
 
 </sys/src/cmd/mklib
--- a/test/t.c
+++ b/test/t.c
@@ -10,6 +10,7 @@
 	s += sprint(s, "%s ", attr&IDMatte ? "matte" : "glossy");
 	s += sprint(s, "%s ", attr&IDNegative ? "negative" : "positive");
 	s += sprint(s, "%s", attr&IDMono ? "mono" : "color");
+	USED(s);
 }
 
 void
@@ -35,6 +36,46 @@
 }
 
 void
+asascii16(char *out, u16int data)
+{
+	char a, b;
+	a = (data>>8)&0xff;
+	b = (data>>0)&0xff;
+	
+	if (!(isalnum(a) || isalnum(b))) {
+		out[0] = 0;
+		return;
+	}
+	
+	out[0] = a;
+	out[1] = b;
+	out[2] = 0;
+}
+
+void
+loca(ICCTagPtr tag)
+{
+	char lang[3];
+	char coun[3];
+	int num, n;
+	MlucEntry m;
+	if (tag.type != 0x6d6c7563) {
+		fprint(2, "bad type!\n");
+		return;
+	}
+	num = mlucnum(tag.ptr);
+	fprint(2, "    mluc num: %d\n", num);
+	for (n = 0; n < num; n++) {
+		m = mlucentry(tag.ptr, n);
+		asascii16(lang, m.language);
+		asascii16(coun, m.country);
+		fprint(2, "      %2s-%2s: ", lang, coun);
+		write(2, m.str, m.length);
+		fprint(2, "\n");
+	}
+}
+
+void
 main(void)
 {
 	char buf[512];
@@ -41,6 +82,7 @@
 	double dx, dy, dz;
 	ICCprofile *prof;
 	ICCdate d;
+	ICCTagPtr ptr;
 	int fd;
 	int n;
 	
@@ -77,7 +119,7 @@
 	n = enc64(buf, sizeof buf, prof->id, sizeof prof->id);
 	fprint(2, "id:     %*s\n", n, buf);
 	
-	fprint(2, "ntags:  %d\n", prof->ntags);
+	fprint(2, "ntags:  %uld\n", prof->ntags);
 	
 	for (n = 0; n < prof->ntags; n++) {
 		fprint(2, "  tag: %d\n", n);
@@ -85,6 +127,18 @@
 		fprint(2, "    signature: 0x%x (%4s)\n", prof->tags[n].signature, *buf ? buf : "");
 		fprint(2, "    offset:    %d\n", prof->tags[n].offset);
 		fprint(2, "    size:      %d\n", prof->tags[n].size);
+	}
+	
+	ptr = iccfindtag(prof, 0x63707274);
+	if (ptr.ptr) {
+		fprint(2, "Loca copyright\n");
+		loca(ptr);
+	}
+	
+	ptr = iccfindtag(prof, 0x64657363);
+	if (ptr.ptr) {
+		fprint(2, "Loca description\n");
+		loca(ptr);
 	}
 	
 	exits(nil);
--