ref: 7b9490c36eed8a9545890a108e003c5b0e57a39f
parent: 239bac5fd6ad3503d15ea1b5dd142ffec51b6433
author: Noam Preil <noam@pixelhero.dev>
date: Fri Apr 8 19:53:51 EDT 2022
gs: implement color space setting
--- a/op.c
+++ b/op.c
@@ -339,10 +339,50 @@
return 0;
}
+char *colorspacedevices[] = {"DeviceGray", "DeviceRGB", "DeviceCMYK"};
+ColorSpace colorspacechans[] = {
+ [1] = DeviceGray,
+ [3] = DeviceRGB,
+ [4] = DeviceCMYK,
+};
+
static int
+iccbasedcspace(Object *icc, ColorSpace *c)
+{
+ Object *o;
+ *c = colorspacechans[dictint(icc, "N")];
+ if((o = dictget(icc, "Alternate")) != &null){
+ if(*c > 2 || strcmp(colorspacedevices[*c], o->name) != 0){
+ werrstr("ICCBased cspace: TODO: handle non-device alternate '%s'", o->name);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+static int
cspace(Op *op, Page *p)
{
- USED(op, p);
+ ColorSpace *c = (op->flags & Nonstroking) ? &p->GSactive->NSCS : &p->GSactive->SCS;
+ char *s = arrayget(p->stack, 0)->name;
+ Object *o;
+ int i;
+ for(i = 0; i < 3; i += 1)
+ if(strcmp(s, colorspacedevices[i]) == 0){
+ *c = i;
+ return 1;
+ }
+ if((o = dictget(dictget(p->obj, "Resources"), "ColorSpace")) == &null
+ || (o = dictget(o, s)) == &null){
+ werrstr("colorspace '%s' not found", s);
+ return 0;
+ }
+ if(strcmp(arrayget(o, 0)->name, "ICCBased") == 0){
+ /* Don't support ICC; fall back to Alternate or default */
+ o = arrayget(o, 1);
+ return iccbasedcspace(o, c);
+ }
+ werrstr("cspace: TODO: %s color space", arrayget(o, 0)->name);
return 0;
}