ref: 4514f7351d135f29d3f322c1512cf348c656a022
dir: /test/t.c/
#include <u.h>
#include <libc.h>
#include <ctype.h>
#include "../icc.h"
void
readattrs(char *s, u64int attr)
{
s += sprint(s, "%s ", attr&IDTransparent ? "transparent" : "reflective");
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
asascii(char *out, u32int data)
{
char a, b, c, d;
a = (data>>24)&0xff;
b = (data>>16)&0xff;
c = (data>>8 )&0xff;
d = (data>>0 )&0xff;
if (!(isalnum(a) || isalnum(b) || isalnum(c) || isalnum(d))) {
out[0] = 0;
return;
}
out[0] = a;
out[1] = b;
out[2] = c;
out[3] = d;
out[4] = 0;
}
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];
double dx, dy, dz;
ICCprofile *prof;
ICCdate d;
ICCTagPtr ptr;
int fd;
int n;
fd = open("sRGB_v4_ICC_preference.icc", OREAD);
prof = iccload(fd);
close(fd);
fprint(2, "size: %d\n", prof->size);
fprint(2, "cmm: %d\n", prof->cmm);
fprint(2, "vers: %d.%d.%d\n", prof->vmajor, prof->vminor, prof->vbugfix);
fprint(2, "class: %s\n", iccgetclass(prof));
fprint(2, "data: %s\n", iccgetdataspace(prof));
fprint(2, "pcs: %s\n", iccgetpcs(prof));
d = prof->creationdate;
fprint(2, "cdate: %4d.%02d.%02d %02d:%02d:%02d\n", d.year, d.month, d.day, d.hours, d.minutes, d.seconds);
fprint(2, "plat: %s\n", prof->platform);
fprint(2, "dmanu: %d\n", prof->devmanufacturer);
fprint(2, "dmodel: %d\n", prof->devmodel);
readattrs(buf, prof->devattrs);
fprint(2, "dattrs: %s\n", buf);
fprint(2, "intent: %d\n", prof->rendintent);
dx = s15f16tod(prof->illuminant.x);
dy = s15f16tod(prof->illuminant.y);
dz = s15f16tod(prof->illuminant.z);
fprint(2, "illum: %f %f %f\n", dx, dy, dz);
fprint(2, "creatr: %d\n", prof->creator);
n = enc64(buf, sizeof buf, prof->id, sizeof prof->id);
fprint(2, "id: %*s\n", n, buf);
fprint(2, "ntags: %uld\n", prof->ntags);
for (n = 0; n < prof->ntags; n++) {
fprint(2, " tag: %d\n", n);
asascii(buf, prof->tags[n].signature);
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);
}