1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
#include "mupdf/fitz.h"
enum
{
FZ_SEPARATION_DISABLED_RENDER = 3
};
struct fz_separations_s
{
int refs;
int num_separations;
int controllable;
uint32_t state[(2*FZ_MAX_SEPARATIONS + 31) / 32];
uint32_t equiv_rgb[FZ_MAX_SEPARATIONS];
uint32_t equiv_cmyk[FZ_MAX_SEPARATIONS];
char *name[FZ_MAX_SEPARATIONS];
};
fz_separations *fz_new_separations(fz_context *ctx, int controllable)
{
fz_separations *sep;
sep = fz_malloc_struct(ctx, fz_separations);
sep->refs = 1;
sep->controllable = controllable;
return sep;
}
fz_separations *fz_keep_separations(fz_context *ctx, fz_separations *sep)
{
return fz_keep_imp(ctx, sep, &sep->refs);
}
void fz_drop_separations(fz_context *ctx, fz_separations *sep)
{
if (fz_drop_imp(ctx, sep, &sep->refs))
{
int i;
for (i = 0; i < sep->num_separations; i++)
fz_free(ctx, sep->name[i]);
fz_free(ctx, sep);
}
}
void fz_add_separation(fz_context *ctx, fz_separations *sep, uint32_t rgb, uint32_t cmyk, const char *name)
{
int n;
if (!sep)
fz_throw(ctx, FZ_ERROR_GENERIC, "can't add to non-existent separations");
n = sep->num_separations;
if (n == FZ_MAX_SEPARATIONS)
fz_throw(ctx, FZ_ERROR_GENERIC, "too many separations");
sep->name[n] = fz_strdup(ctx, name);
sep->equiv_rgb[n] = rgb;
sep->equiv_cmyk[n] = cmyk;
sep->num_separations++;
}
int fz_separations_controllable(fz_context *ctx, const fz_separations *sep)
{
return (!sep || sep->controllable);
}
void fz_set_separation_behavior(fz_context *ctx, fz_separations *sep, int separation, fz_separation_behavior beh)
{
int shift;
fz_separation_behavior old;
if (!sep || separation < 0 || separation >= sep->num_separations)
fz_throw(ctx, FZ_ERROR_GENERIC, "can't control non-existent separation");
if (beh == FZ_SEPARATION_DISABLED && !sep->controllable)
beh = FZ_SEPARATION_DISABLED_RENDER;
shift = ((2*separation) & 31);
separation >>= 4;
old = (sep->state[separation]>>shift) & 3;
if (old == (fz_separation_behavior)FZ_SEPARATION_DISABLED_RENDER)
old = FZ_SEPARATION_DISABLED;
/* If no change, great */
if (old == beh)
return;
sep->state[separation] = (sep->state[separation] & ~(3<<shift)) | (beh<<shift);
/* FIXME: Could only empty images from the store, or maybe only
* images that depend on separations. */
fz_empty_store(ctx);
}
static inline fz_separation_behavior
sep_state(const fz_separations *sep, int i)
{
return (fz_separation_behavior)((sep->state[i>>5]>>((2*i) & 31)) & 3);
}
fz_separation_behavior fz_separation_current_behavior_internal(fz_context *ctx, const fz_separations *sep, int separation)
{
if (!sep || separation < 0 || separation >= sep->num_separations)
fz_throw(ctx, FZ_ERROR_GENERIC, "can't disable non-existent separation");
return sep_state(sep, separation);
}
fz_separation_behavior fz_separation_current_behavior(fz_context *ctx, const fz_separations *sep, int separation)
{
int beh = fz_separation_current_behavior_internal(ctx, sep, separation);
if (beh == FZ_SEPARATION_DISABLED_RENDER)
return FZ_SEPARATION_DISABLED;
return beh;
}
int fz_separations_all_composite(fz_context *ctx, const fz_separations *sep)
{
int i;
if (!sep)
return 1;
for (i = 0; i < (FZ_MAX_SEPARATIONS + 31) / 32; i++)
if (sep->state[i] != FZ_SEPARATION_COMPOSITE)
return 0;
return 1;
}
const char *fz_get_separation(fz_context *ctx, const fz_separations *sep, int separation, uint32_t *rgb, uint32_t *cmyk)
{
if (!sep || separation < 0 || separation >= sep->num_separations)
fz_throw(ctx, FZ_ERROR_GENERIC, "can't access non-existent separation");
if (rgb)
*rgb = sep->equiv_rgb[separation];
if (cmyk)
*cmyk = sep->equiv_cmyk[separation];
return sep->name[separation];
}
int fz_count_separations(fz_context *ctx, const fz_separations *sep)
{
if (!sep)
return 0;
return sep->num_separations;
}
int fz_count_active_separations(fz_context *ctx, const fz_separations *sep)
{
int i, n, c;
if (!sep)
return 0;
n = sep->num_separations;
c = 0;
for (i = 0; i < n; i++)
if (sep_state(sep, i) == FZ_SEPARATION_SPOT)
c++;
return c;
}
|