11
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: zfjpx.c 8332 2007-10-30 00:58:44Z giles $ */
14
/* $Id: zfjpx.c 8819 2008-07-04 18:20:44Z giles $ */
16
16
/* This is the ps interpreter interface to the JPXDecode filter
17
17
used for (JPEG2000) scanned image compression. PDF only specifies
68
73
/* get a reference to the name's string value */
69
74
name_string_ref(imemory, csname, &sref);
70
75
/* request raw index values if the colorspace is /Indexed */
71
if (!memcmp(sref.value.const_bytes, "Indexed", min(7,r_size(&sref))))
76
if (!ISTRCMP(&sref, "Indexed"))
72
77
state.colorspace = gs_jpx_cs_indexed;
78
/* tell the filter what output we want for other spaces */
79
else if (!ISTRCMP(&sref, "DeviceGray"))
80
state.colorspace = gs_jpx_cs_gray;
81
else if (!ISTRCMP(&sref, "DeviceRGB"))
82
state.colorspace = gs_jpx_cs_rgb;
83
else if (!ISTRCMP(&sref, "DeviceCMYK"))
84
state.colorspace = gs_jpx_cs_cmyk;
85
else if (!ISTRCMP(&sref, "ICCBased")) {
86
/* The second array element should be the profile's
88
ref *csdict = sop->value.refs + 1;
91
if (r_is_array(sop) && (r_size(sop) > 1) &&
92
r_has_type(csdict, t_dictionary)) {
93
check_dict_read(*csdict);
94
/* try to look up the alternate space */
95
if (dict_find_string(csdict, "Alternate", &nref) > 0) {
96
name_string_ref(imemory, csname, &altname);
97
if (!ISTRCMP(&altname, "DeviceGray"))
98
state.colorspace = gs_jpx_cs_gray;
99
else if (!ISTRCMP(&altname, "DeviceRGB"))
100
state.colorspace = gs_jpx_cs_rgb;
101
else if (!ISTRCMP(&altname, "DeviceCMYK"))
102
state.colorspace = gs_jpx_cs_cmyk;
104
/* else guess based on the number of components */
105
if (state.colorspace == gs_jpx_cs_unset &&
106
dict_find_string(csdict, "N", &nref) > 0) {
107
if_debug1('w', "[w] JPX image has an external %d"
108
" channel colorspace\n", nref->value.intval);
109
switch (nref->value.intval) {
110
case 1: state.colorspace = gs_jpx_cs_gray;
112
case 3: state.colorspace = gs_jpx_cs_rgb;
114
case 4: state.colorspace = gs_jpx_cs_cmyk;
74
121
if_debug0('w', "[w] Couldn't read JPX ColorSpace key!\n");
79
126
/* we pass npop=0, since we've no arguments left to consume */
80
127
/* we pass 0 instead of the usual rspace(sop) which will allocate storage
81
128
for filter state from the same memory pool as the stream it's coding.