ref: e432f766e0589685a77ac9f8b0a84be64299f68e
parent: 89a32fa2357bbd6ce57965712cc620b9f0db475e
author: Sigrid Haflínudóttir <[email protected]>
date: Thu Sep 3 17:10:24 EDT 2020
resample: add colorspace (-c) option
--- a/resample.c
+++ b/resample.c
@@ -18,10 +18,15 @@
[STBIR_FILTER_MITCHELL] = "mitchell",
};
+static char *cspaces[] = {
+ [STBIR_COLORSPACE_LINEAR] = "linear",
+ [STBIR_COLORSPACE_SRGB] = "srgb",
+};
+
static void
usage(void)
{
- fprint(2, "usage: %s [-x size] [-y size] [-f filter]\n", argv0);
+ fprint(2, "usage: %s [-x size] [-y size] [-f filter] [-c colorspace]\n", argv0);
exits("usage");
}
@@ -30,14 +35,15 @@
{
Memimage *a, *b;
u8int *in, *out;
- char *flts, *s;
+ char *flts, *s, *csps;
int n, w, h, bp;
int ow, oh, obp;
- int wp, hp, f;
+ int wp, hp, f, c;
ow = oh = 0;
wp = hp = 0;
flts = filters[STBIR_FILTER_MITCHELL];
+ csps = cspaces[STBIR_COLORSPACE_LINEAR];
ARGBEGIN{
case 'x':
s = EARGF(usage());
@@ -50,6 +56,9 @@
case 'f':
flts = EARGF(usage());
break;
+ case 'c':
+ csps = EARGF(usage());
+ break;
default:
usage();
}ARGEND
@@ -68,6 +77,11 @@
if(f >= nelem(filters)){
fprint(2, "invalid filter %s\n", flts);
exits("filter");
+ }
+ for(c = 0; c < nelem(cspaces) && strcmp(csps, cspaces[c]) != 0; c++);
+ if(c >= nelem(cspaces)){
+ fprint(2, "invalid colorspace %s\n", csps);
+ exits("colorspace");
}
memimageinit();