~ubuntu-branches/debian/squeeze/ghostscript/squeeze

« back to all changes in this revision

Viewing changes to src/zfjpx.c

  • Committer: Bazaar Package Importer
  • Author(s): Masayuki Hatta (mhatta)
  • Date: 2009-01-04 12:09:59 UTC
  • mfrom: (16.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090104120959-m9lbagj775ucg0h3
Tags: 8.63.dfsg.1-2
libgs-dev: put versioned dependency on libgs8 - closes: #510691

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2001-2006 Artifex Software, Inc.
 
1
/* Copyright (C) 2001-2008 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: zfjpx.c 8332 2007-10-30 00:58:44Z giles $ */
 
14
/* $Id: zfjpx.c 8819 2008-07-04 18:20:44Z giles $ */
15
15
 
16
16
/* This is the ps interpreter interface to the JPXDecode filter
17
17
   used for (JPEG2000) scanned image compression. PDF only specifies
37
37
#include "sjpx.h"
38
38
#endif
39
39
 
 
40
/* macro to test a name ref against a C string */
 
41
# define ISTRCMP(ref, string) (memcmp((ref)->value.const_bytes, string, \
 
42
        min(strlen(string), r_size(ref))))
 
43
 
40
44
/* <source> /JPXDecode <file> */
41
45
/* <source> <dict> /JPXDecode <file> */
42
46
static int
48
52
    stream_jpxd_state state;
49
53
 
50
54
    /* it's our responsibility to call set_defaults() */
51
 
    (*s_jpxd_template.set_defaults)((stream_state *)&state);
 
55
    if (s_jpxd_template.set_defaults)
 
56
      (*s_jpxd_template.set_defaults)((stream_state *)&state);
52
57
    state.jpx_memory = imemory->non_gc_memory;
53
58
    if (r_has_type(op, t_dictionary)) {
54
59
        check_dict_read(*op);
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
 
87
                       stream dict */
 
88
                    ref *csdict = sop->value.refs + 1;
 
89
                    ref *nref;
 
90
                    ref altname;
 
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;
 
103
                        }
 
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;
 
111
                                break;
 
112
                            case 3: state.colorspace = gs_jpx_cs_rgb;
 
113
                                break;
 
114
                            case 4: state.colorspace = gs_jpx_cs_cmyk;
 
115
                                break;
 
116
                          }
 
117
                        }
 
118
                    }
 
119
                }
73
120
            } else {
74
121
                if_debug0('w', "[w] Couldn't read JPX ColorSpace key!\n");
75
122
            }
76
123
        }
77
124
    }
78
 
        
 
125
 
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.