| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "mupdf/fitz.h" |
| 24 |
#include "mupdf/pdf.h" |
| 25 |
|
| 26 |
#include <string.h> |
| 27 |
#include <math.h> |
| 28 |
#include <float.h> |
| 29 |
|
| 30 |
typedef struct |
| 31 |
{ |
| 32 |
void *opaque; |
| 33 |
pdf_recolor_vertex *recolor; |
| 34 |
fz_colorspace *dst_cs; |
| 35 |
fz_colorspace *src_cs; |
| 36 |
int funcs; |
| 37 |
} recolor_details; |
| 38 |
|
| 39 |
#define FUNSEGS 256 |
| 40 |
#define FUNBPS 8 |
| 41 |
|
| 42 |
static void |
| 43 |
fz_recolor_shade_type1(fz_context *ctx, pdf_obj *shade, pdf_function **func, recolor_details *rd) |
| 44 |
{ |
| 45 |
float x0 = 0; |
| 46 |
float y0 = 0; |
| 47 |
float x1 = 1; |
| 48 |
float y1 = 1; |
| 49 |
float in[FZ_MAX_COLORS] = { 0 }; |
| 50 |
float out[(FUNSEGS+1)*(FUNSEGS+1)*FZ_MAX_COLORS]; |
| 51 |
float *p; |
| 52 |
float fv[2]; |
| 53 |
int xx, yy; |
| 54 |
pdf_obj *obj; |
| 55 |
int n_in = rd->src_cs->n; |
| 56 |
int n_out = rd->dst_cs->n; |
| 57 |
pdf_obj *fun_obj = NULL; |
| 58 |
float range[FZ_MAX_COLORS]; |
| 59 |
int i; |
| 60 |
pdf_document *doc = pdf_get_bound_document(ctx, shade); |
| 61 |
pdf_obj *ref = NULL; |
| 62 |
fz_buffer *buf = NULL; |
| 63 |
fz_output *output = NULL; |
| 64 |
|
| 65 |
obj = pdf_dict_get(ctx, shade, PDF_NAME(Domain)); |
| 66 |
if (obj) |
| 67 |
{ |
| 68 |
x0 = pdf_array_get_real(ctx, obj, 0); |
| 69 |
x1 = pdf_array_get_real(ctx, obj, 1); |
| 70 |
y0 = pdf_array_get_real(ctx, obj, 2); |
| 71 |
y1 = pdf_array_get_real(ctx, obj, 3); |
| 72 |
} |
| 73 |
|
| 74 |
if (rd->funcs != 1 && rd->funcs != n_in) |
| 75 |
{ |
| 76 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "Unexpected function-arity."); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
for (i = 0; i < n_out; i++) |
| 81 |
{ |
| 82 |
range[2 * i] = FLT_MAX; |
| 83 |
range[2 * i + 1] = -FLT_MAX; |
| 84 |
} |
| 85 |
p = out; |
| 86 |
for (yy = 0; yy <= FUNSEGS; yy++) |
| 87 |
{ |
| 88 |
fv[1] = y0 + (y1 - y0) * yy / FUNSEGS; |
| 89 |
|
| 90 |
for (xx = 0; xx <= FUNSEGS; xx++) |
| 91 |
{ |
| 92 |
fv[0] = x0 + (x1 - x0) * xx / FUNSEGS; |
| 93 |
|
| 94 |
if (rd->funcs == 1) |
| 95 |
pdf_eval_function(ctx, func[0], fv, 2, in, n_in); |
| 96 |
else |
| 97 |
{ |
| 98 |
int zz; |
| 99 |
for (zz = 0; zz < n_in; zz++) |
| 100 |
pdf_eval_function(ctx, func[zz], fv, 2, &in[zz], 1); |
| 101 |
} |
| 102 |
|
| 103 |
rd->recolor(ctx, rd->opaque, rd->dst_cs, p, rd->src_cs, in); |
| 104 |
|
| 105 |
for (i = 0; i < n_out; i++) |
| 106 |
{ |
| 107 |
if (range[2 * i] > p[i]) |
| 108 |
range[2 * i] = p[i]; |
| 109 |
if (range[2 * i + 1] < p[i]) |
| 110 |
range[2 * i + 1] = p[i]; |
| 111 |
} |
| 112 |
p += n_out; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
fun_obj = pdf_new_dict(ctx, doc, 3); |
| 118 |
pdf_dict_put_int(ctx, fun_obj, PDF_NAME(FunctionType), 0); |
| 119 |
|
| 120 |
|
| 121 |
obj = pdf_dict_put_array(ctx, fun_obj, PDF_NAME(Domain), 4); |
| 122 |
pdf_array_push_real(ctx, obj, x0); |
| 123 |
pdf_array_push_real(ctx, obj, x1); |
| 124 |
pdf_array_push_real(ctx, obj, y0); |
| 125 |
pdf_array_push_real(ctx, obj, y1); |
| 126 |
|
| 127 |
|
| 128 |
obj = pdf_dict_put_array(ctx, fun_obj, PDF_NAME(Range), 4); |
| 129 |
for (i = 0; i < 2*n_out; i++) |
| 130 |
pdf_array_push_real(ctx, obj, range[i]); |
| 131 |
|
| 132 |
|
| 133 |
obj = pdf_dict_put_array(ctx, fun_obj, PDF_NAME(Size), 2); |
| 134 |
pdf_array_push_int(ctx, obj, FUNSEGS+1); |
| 135 |
pdf_array_push_int(ctx, obj, FUNSEGS+1); |
| 136 |
|
| 137 |
|
| 138 |
pdf_dict_put_int(ctx, fun_obj, PDF_NAME(BitsPerSample), FUNBPS); |
| 139 |
|
| 140 |
buf = fz_new_buffer(ctx, 1); |
| 141 |
output = fz_new_output_with_buffer(ctx, buf); |
| 142 |
|
| 143 |
p = out; |
| 144 |
for (yy = 0; yy <= FUNSEGS; yy++) |
| 145 |
{ |
| 146 |
for (xx = 0; xx <= FUNSEGS; xx++) |
| 147 |
{ |
| 148 |
for (i = 0; i < n_out; i++) |
| 149 |
{ |
| 150 |
float v = p[i]; |
| 151 |
float d = range[2 * i + 1] - range[2 * i]; |
| 152 |
int iv; |
| 153 |
|
| 154 |
v -= range[2 * i]; |
| 155 |
if (d != 0) |
| 156 |
v = v * ((1<<FUNBPS)-1) / d; |
| 157 |
iv = (int)(v + 0.5f); |
| 158 |
fz_write_bits(ctx, output, iv, FUNBPS); |
| 159 |
} |
| 160 |
p += n_out; |
| 161 |
} |
| 162 |
} |
| 163 |
fz_write_bits_sync(ctx, output); |
| 164 |
fz_close_output(ctx, output); |
| 165 |
fz_drop_output(ctx, output); |
| 166 |
|
| 167 |
ref = pdf_add_object(ctx, doc, fun_obj); |
| 168 |
pdf_update_stream(ctx, doc, ref, buf, 0); |
| 169 |
fz_drop_buffer(ctx, buf); |
| 170 |
pdf_dict_put(ctx, shade, PDF_NAME(Function), ref); |
| 171 |
} |
| 172 |
|
| 173 |
static void |
| 174 |
fz_recolor_shade_function(fz_context *ctx, pdf_obj *shade, float *samples, int stride, recolor_details *rd) |
| 175 |
{ |
| 176 |
int i; |
| 177 |
int n_in = fz_colorspace_n(ctx, rd->src_cs); |
| 178 |
int n_out = fz_colorspace_n(ctx, rd->dst_cs); |
| 179 |
float localp[256*FZ_MAX_COLORS]; |
| 180 |
float *q = localp; |
| 181 |
float p[FZ_MAX_COLORS]; |
| 182 |
pdf_obj *fun_obj = NULL; |
| 183 |
pdf_document *doc = pdf_get_bound_document(ctx, shade); |
| 184 |
pdf_obj *obj; |
| 185 |
float t0 = 0; |
| 186 |
float t1 = 1; |
| 187 |
float range[FZ_MAX_COLORS]; |
| 188 |
pdf_obj *ref = NULL; |
| 189 |
fz_buffer *buf = NULL; |
| 190 |
fz_output *output = NULL; |
| 191 |
int t; |
| 192 |
|
| 193 |
obj = pdf_dict_get(ctx, shade, PDF_NAME(Domain)); |
| 194 |
if (obj) |
| 195 |
{ |
| 196 |
t0 = pdf_array_get_real(ctx, obj, 0); |
| 197 |
t1 = pdf_array_get_real(ctx, obj, 1); |
| 198 |
} |
| 199 |
|
| 200 |
for (i = 0; i < n_out; i++) |
| 201 |
{ |
| 202 |
range[2 * i] = FLT_MAX; |
| 203 |
range[2 * i + 1] = -FLT_MAX; |
| 204 |
} |
| 205 |
for (t = 0; t < 256; t++) |
| 206 |
{ |
| 207 |
for (i = 0; i < n_in; i++) |
| 208 |
p[i] = samples[t*stride+i]; |
| 209 |
|
| 210 |
rd->recolor(ctx, rd->opaque, rd->dst_cs, q, rd->src_cs, p); |
| 211 |
|
| 212 |
for (i = 0; i < n_out; i++) |
| 213 |
{ |
| 214 |
if (range[2 * i] > q[i]) |
| 215 |
range[2 * i] = q[i]; |
| 216 |
if (range[2 * i + 1] < q[i]) |
| 217 |
range[2 * i + 1] = q[i]; |
| 218 |
} |
| 219 |
q += n_out; |
| 220 |
} |
| 221 |
|
| 222 |
fz_var(ref); |
| 223 |
fz_var(output); |
| 224 |
|
| 225 |
|
| 226 |
fun_obj = pdf_new_dict(ctx, doc, 3); |
| 227 |
fz_try(ctx) |
| 228 |
{ |
| 229 |
pdf_dict_put_int(ctx, fun_obj, PDF_NAME(FunctionType), 0); |
| 230 |
|
| 231 |
|
| 232 |
obj = pdf_dict_put_array(ctx, fun_obj, PDF_NAME(Domain), 2); |
| 233 |
pdf_array_push_real(ctx, obj, t0); |
| 234 |
pdf_array_push_real(ctx, obj, t1); |
| 235 |
|
| 236 |
|
| 237 |
obj = pdf_dict_put_array(ctx, fun_obj, PDF_NAME(Range), 2 * n_out); |
| 238 |
for (i = 0; i < 2 * n_out; i++) |
| 239 |
pdf_array_push_real(ctx, obj, range[i]); |
| 240 |
|
| 241 |
obj = pdf_dict_put_array(ctx, fun_obj, PDF_NAME(Size), 1); |
| 242 |
pdf_array_push_int(ctx, obj, 256); |
| 243 |
|
| 244 |
pdf_dict_put_int(ctx, fun_obj, PDF_NAME(BitsPerSample), FUNBPS); |
| 245 |
|
| 246 |
buf = fz_new_buffer(ctx, 1); |
| 247 |
output = fz_new_output_with_buffer(ctx, buf); |
| 248 |
|
| 249 |
q = localp; |
| 250 |
for (t = 0; t < 256; t++) |
| 251 |
{ |
| 252 |
for (i = 0; i < n_out; i++) |
| 253 |
{ |
| 254 |
float v = q[i]; |
| 255 |
float d = range[2 * i + 1] - range[2 * i]; |
| 256 |
int iv; |
| 257 |
|
| 258 |
v -= range[2 * i]; |
| 259 |
if (d != 0) |
| 260 |
v = v * ((1<<FUNBPS)-1) / d; |
| 261 |
iv = (int)(v + 0.5f); |
| 262 |
fz_write_bits(ctx, output, iv, FUNBPS); |
| 263 |
} |
| 264 |
q += n_out; |
| 265 |
} |
| 266 |
fz_write_bits_sync(ctx, output); |
| 267 |
fz_close_output(ctx, output); |
| 268 |
|
| 269 |
ref = pdf_add_object(ctx, doc, fun_obj); |
| 270 |
pdf_update_stream(ctx, doc, ref, buf, 0); |
| 271 |
pdf_dict_put(ctx, shade, PDF_NAME(Function), ref); |
| 272 |
} |
| 273 |
fz_always(ctx) |
| 274 |
{ |
| 275 |
fz_drop_output(ctx, output); |
| 276 |
fz_drop_buffer(ctx, buf); |
| 277 |
pdf_drop_obj(ctx, fun_obj); |
| 278 |
pdf_drop_obj(ctx, ref); |
| 279 |
} |
| 280 |
fz_catch(ctx) |
| 281 |
fz_rethrow(ctx); |
| 282 |
} |
| 283 |
|
| 284 |
static inline float read_sample(fz_context *ctx, fz_stream *stream, int bits, float min, float max) |
| 285 |
{ |
| 286 |
|
| 287 |
float bitscale = 1 / (powf(2, bits) - 1); |
| 288 |
return min + fz_read_bits(ctx, stream, bits) * (max - min) * bitscale; |
| 289 |
} |
| 290 |
|
| 291 |
static inline void write_sample(fz_context *ctx, fz_output *out, int bits, float min, float max, float val) |
| 292 |
{ |
| 293 |
|
| 294 |
float bitscale = (powf(2, bits) - 1); |
| 295 |
if (val < min) |
| 296 |
val = min; |
| 297 |
else if (val > max) |
| 298 |
val = max; |
| 299 |
val -= min; |
| 300 |
if (max != min) |
| 301 |
val /= (max - min); |
| 302 |
|
| 303 |
fz_write_bits(ctx, out, (int)(val * bitscale), bits); |
| 304 |
} |
| 305 |
|
| 306 |
typedef struct |
| 307 |
{ |
| 308 |
float *p; |
| 309 |
int len; |
| 310 |
int max; |
| 311 |
int pos; |
| 312 |
} float_queue; |
| 313 |
|
| 314 |
static void |
| 315 |
float_queue_push(fz_context *ctx, float_queue *p, float f) |
| 316 |
{ |
| 317 |
if (p->len == p->max) |
| 318 |
{ |
| 319 |
int new_max = p->max * 2; |
| 320 |
if (new_max == 0) |
| 321 |
new_max = 32; |
| 322 |
p->p = fz_realloc(ctx, p->p, sizeof(float) * new_max); |
| 323 |
p->max = new_max; |
| 324 |
} |
| 325 |
p->p[p->len++] = f; |
| 326 |
} |
| 327 |
|
| 328 |
static float |
| 329 |
float_queue_pop(fz_context *ctx, float_queue *p) |
| 330 |
{ |
| 331 |
return p->p[p->pos++]; |
| 332 |
} |
| 333 |
|
| 334 |
static void |
| 335 |
float_queue_drop(fz_context *ctx, float_queue *p) |
| 336 |
{ |
| 337 |
fz_free(ctx, p->p); |
| 338 |
} |
| 339 |
|
| 340 |
static void |
| 341 |
read_decode(fz_context *ctx, pdf_obj *shade, int n_in, float *c_min, float *c_max, int n_out, float *d_min, float *d_max) |
| 342 |
{ |
| 343 |
int i; |
| 344 |
pdf_obj *obj = pdf_dict_get(ctx, shade, PDF_NAME(Decode)); |
| 345 |
|
| 346 |
for (i = 0; i < n_in; i++) |
| 347 |
{ |
| 348 |
c_min[i] = pdf_array_get_int(ctx, obj, 2 * i + 4); |
| 349 |
c_max[i] = pdf_array_get_int(ctx, obj, 2 * i + 5); |
| 350 |
} |
| 351 |
for (i = 0; i < n_out; i++) |
| 352 |
{ |
| 353 |
d_min[i] = FLT_MAX; |
| 354 |
d_max[i] = -FLT_MAX; |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
static void |
| 359 |
rewrite_decode(fz_context *ctx, pdf_obj *shade, int n_out, float *d_min, float *d_max) |
| 360 |
{ |
| 361 |
int i; |
| 362 |
pdf_obj *obj = pdf_keep_obj(ctx, pdf_dict_get(ctx, shade, PDF_NAME(Decode))); |
| 363 |
pdf_obj *obj2; |
| 364 |
|
| 365 |
fz_try(ctx) |
| 366 |
{ |
| 367 |
obj2 = pdf_dict_put_array(ctx, shade, PDF_NAME(Decode), 4); |
| 368 |
|
| 369 |
for (i = 0; i < 4; i++) |
| 370 |
{ |
| 371 |
pdf_array_push(ctx, obj2, pdf_array_get(ctx, obj, i)); |
| 372 |
} |
| 373 |
for (i = 0; i < n_out; i++) |
| 374 |
{ |
| 375 |
pdf_array_push_real(ctx, obj2, d_min[i]); |
| 376 |
pdf_array_push_real(ctx, obj2, d_max[i]); |
| 377 |
} |
| 378 |
} |
| 379 |
fz_always(ctx) |
| 380 |
pdf_drop_obj(ctx, obj); |
| 381 |
fz_catch(ctx) |
| 382 |
fz_rethrow(ctx); |
| 383 |
} |
| 384 |
|
| 385 |
static void |
| 386 |
fz_recolor_shade_type4(fz_context *ctx, pdf_obj *shade, recolor_details *rd) |
| 387 |
{ |
| 388 |
fz_stream *stream; |
| 389 |
int i, n_in = rd->src_cs->n; |
| 390 |
int n_out = rd->dst_cs->n; |
| 391 |
int bpflag = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerFlag)); |
| 392 |
int bpcoord = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerCoordinate)); |
| 393 |
int bpcomp = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerComponent)); |
| 394 |
pdf_document *doc = pdf_get_bound_document(ctx, shade); |
| 395 |
float c[FZ_MAX_COLORS]; |
| 396 |
float d[FZ_MAX_COLORS]; |
| 397 |
float c_min[FZ_MAX_COLORS]; |
| 398 |
float c_max[FZ_MAX_COLORS]; |
| 399 |
float d_min[FZ_MAX_COLORS]; |
| 400 |
float d_max[FZ_MAX_COLORS]; |
| 401 |
fz_buffer *outbuf = NULL; |
| 402 |
fz_output *out = NULL; |
| 403 |
float_queue fq = { 0 }; |
| 404 |
|
| 405 |
fz_var(outbuf); |
| 406 |
fz_var(out); |
| 407 |
fz_var(stream); |
| 408 |
|
| 409 |
read_decode(ctx, shade, n_in, c_min, c_max, n_out, d_min, d_max); |
| 410 |
|
| 411 |
stream = pdf_open_stream(ctx, shade); |
| 412 |
fz_try(ctx) |
| 413 |
{ |
| 414 |
while (!fz_is_eof_bits(ctx, stream)) |
| 415 |
{ |
| 416 |
(void)fz_read_bits(ctx, stream, bpflag); |
| 417 |
(void)fz_read_bits(ctx, stream, bpcoord); |
| 418 |
(void)fz_read_bits(ctx, stream, bpcoord); |
| 419 |
for (i = 0; i < n_in; i++) |
| 420 |
c[i] = read_sample(ctx, stream, bpcomp, c_min[i], c_max[i]); |
| 421 |
|
| 422 |
rd->recolor(ctx, rd->opaque, rd->dst_cs, d, rd->src_cs, c); |
| 423 |
|
| 424 |
for (i = 0; i < n_out; i++) |
| 425 |
{ |
| 426 |
if (d[i] < d_min[i]) |
| 427 |
d_min[i] = d[i]; |
| 428 |
if (d[i] > d_max[i]) |
| 429 |
d_max[i] = d[i]; |
| 430 |
float_queue_push(ctx, &fq, d[i]); |
| 431 |
} |
| 432 |
} |
| 433 |
fz_drop_stream(ctx, stream); |
| 434 |
stream = NULL; |
| 435 |
|
| 436 |
rewrite_decode(ctx, shade, n_out, d_min, d_max); |
| 437 |
|
| 438 |
stream = pdf_open_stream(ctx, shade); |
| 439 |
outbuf = fz_new_buffer(ctx, 1); |
| 440 |
out = fz_new_output_with_buffer(ctx, outbuf); |
| 441 |
while (!fz_is_eof_bits(ctx, stream)) |
| 442 |
{ |
| 443 |
unsigned int flag = fz_read_bits(ctx, stream, bpflag); |
| 444 |
unsigned int x_bits = fz_read_bits(ctx, stream, bpcoord); |
| 445 |
unsigned int y_bits = fz_read_bits(ctx, stream, bpcoord); |
| 446 |
for (i = 0; i < n_in; i++) |
| 447 |
(void)fz_read_bits(ctx, stream, bpcomp); |
| 448 |
|
| 449 |
fz_write_bits(ctx, out, flag, bpflag); |
| 450 |
fz_write_bits(ctx, out, x_bits, bpcoord); |
| 451 |
fz_write_bits(ctx, out, y_bits, bpcoord); |
| 452 |
|
| 453 |
for (i = 0; i < n_out; i++) |
| 454 |
{ |
| 455 |
float f = float_queue_pop(ctx, &fq); |
| 456 |
write_sample(ctx, out, 8, d_min[i], d_max[i], f); |
| 457 |
} |
| 458 |
} |
| 459 |
fz_write_bits_sync(ctx, out); |
| 460 |
fz_close_output(ctx, out); |
| 461 |
|
| 462 |
pdf_dict_put_int(ctx, shade, PDF_NAME(BitsPerComponent), 8); |
| 463 |
|
| 464 |
pdf_update_stream(ctx, doc, shade, outbuf, 0); |
| 465 |
} |
| 466 |
fz_always(ctx) |
| 467 |
{ |
| 468 |
float_queue_drop(ctx, &fq); |
| 469 |
fz_drop_stream(ctx, stream); |
| 470 |
fz_drop_output(ctx, out); |
| 471 |
fz_drop_buffer(ctx, outbuf); |
| 472 |
} |
| 473 |
fz_catch(ctx) |
| 474 |
{ |
| 475 |
fz_rethrow(ctx); |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
static void |
| 480 |
fz_recolor_shade_type5(fz_context *ctx, pdf_obj *shade, recolor_details *rd) |
| 481 |
{ |
| 482 |
fz_stream *stream; |
| 483 |
int i, k, n_in = rd->src_cs->n; |
| 484 |
int n_out = rd->dst_cs->n; |
| 485 |
int bpcoord = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerCoordinate)); |
| 486 |
int bpcomp = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerComponent)); |
| 487 |
int vprow = pdf_dict_get_int(ctx, shade, PDF_NAME(VerticesPerRow)); |
| 488 |
pdf_document *doc = pdf_get_bound_document(ctx, shade); |
| 489 |
float c[FZ_MAX_COLORS]; |
| 490 |
float d[FZ_MAX_COLORS]; |
| 491 |
float c_min[FZ_MAX_COLORS]; |
| 492 |
float c_max[FZ_MAX_COLORS]; |
| 493 |
float d_min[FZ_MAX_COLORS]; |
| 494 |
float d_max[FZ_MAX_COLORS]; |
| 495 |
fz_buffer *outbuf = NULL; |
| 496 |
fz_output *out = NULL; |
| 497 |
float_queue fq = { 0 }; |
| 498 |
|
| 499 |
fz_var(outbuf); |
| 500 |
fz_var(out); |
| 501 |
fz_var(stream); |
| 502 |
|
| 503 |
read_decode(ctx, shade, n_in, c_min, c_max, n_out, d_min, d_max); |
| 504 |
|
| 505 |
stream = pdf_open_stream(ctx, shade); |
| 506 |
fz_try(ctx) |
| 507 |
{ |
| 508 |
while (!fz_is_eof_bits(ctx, stream)) |
| 509 |
{ |
| 510 |
for (i = 0; i < vprow; i++) |
| 511 |
{ |
| 512 |
(void)fz_read_bits(ctx, stream, bpcoord); |
| 513 |
(void)fz_read_bits(ctx, stream, bpcoord); |
| 514 |
for (k = 0; k < n_in; k++) |
| 515 |
c[k] = read_sample(ctx, stream, bpcomp, c_min[k], c_max[k]); |
| 516 |
|
| 517 |
rd->recolor(ctx, rd->opaque, rd->dst_cs, d, rd->src_cs, c); |
| 518 |
|
| 519 |
for (k = 0; k < n_out; k++) |
| 520 |
{ |
| 521 |
if (d[k] < d_min[k]) |
| 522 |
d_min[k] = d[k]; |
| 523 |
if (d[k] > d_max[k]) |
| 524 |
d_max[k] = d[k]; |
| 525 |
float_queue_push(ctx, &fq, d[k]); |
| 526 |
} |
| 527 |
} |
| 528 |
} |
| 529 |
fz_drop_stream(ctx, stream); |
| 530 |
stream = NULL; |
| 531 |
|
| 532 |
rewrite_decode(ctx, shade, n_out, d_min, d_max); |
| 533 |
|
| 534 |
stream = pdf_open_stream(ctx, shade); |
| 535 |
outbuf = fz_new_buffer(ctx, 1); |
| 536 |
out = fz_new_output_with_buffer(ctx, outbuf); |
| 537 |
while (!fz_is_eof_bits(ctx, stream)) |
| 538 |
{ |
| 539 |
for (i = 0; i < vprow; i++) |
| 540 |
{ |
| 541 |
unsigned int x_bits = fz_read_bits(ctx, stream, bpcoord); |
| 542 |
unsigned int y_bits = fz_read_bits(ctx, stream, bpcoord); |
| 543 |
for (k = 0; k < n_in; k++) |
| 544 |
(void)fz_read_bits(ctx, stream, bpcomp); |
| 545 |
|
| 546 |
fz_write_bits(ctx, out, x_bits, bpcoord); |
| 547 |
fz_write_bits(ctx, out, y_bits, bpcoord); |
| 548 |
for (k = 0; k < n_out; k++) |
| 549 |
{ |
| 550 |
float f = float_queue_pop(ctx, &fq); |
| 551 |
write_sample(ctx, out, 8, d_min[k], d_max[k], f); |
| 552 |
} |
| 553 |
} |
| 554 |
} |
| 555 |
fz_write_bits_sync(ctx, out); |
| 556 |
fz_close_output(ctx, out); |
| 557 |
|
| 558 |
pdf_dict_put_int(ctx, shade, PDF_NAME(BitsPerComponent), 8); |
| 559 |
|
| 560 |
pdf_update_stream(ctx, doc, shade, outbuf, 0); |
| 561 |
} |
| 562 |
fz_always(ctx) |
| 563 |
{ |
| 564 |
float_queue_drop(ctx, &fq); |
| 565 |
fz_drop_stream(ctx, stream); |
| 566 |
fz_drop_output(ctx, out); |
| 567 |
fz_drop_buffer(ctx, outbuf); |
| 568 |
} |
| 569 |
fz_catch(ctx) |
| 570 |
{ |
| 571 |
fz_rethrow(ctx); |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
static void |
| 576 |
fz_recolor_shade_type6(fz_context *ctx, pdf_obj *shade, recolor_details *rd) |
| 577 |
{ |
| 578 |
fz_stream *stream; |
| 579 |
int i, k, n_in = rd->src_cs->n; |
| 580 |
int n_out = rd->dst_cs->n; |
| 581 |
int bpflag = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerFlag)); |
| 582 |
int bpcoord = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerCoordinate)); |
| 583 |
int bpcomp = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerComponent)); |
| 584 |
pdf_document *doc = pdf_get_bound_document(ctx, shade); |
| 585 |
float c[FZ_MAX_COLORS]; |
| 586 |
float d[FZ_MAX_COLORS]; |
| 587 |
float c_min[FZ_MAX_COLORS]; |
| 588 |
float c_max[FZ_MAX_COLORS]; |
| 589 |
float d_min[FZ_MAX_COLORS]; |
| 590 |
float d_max[FZ_MAX_COLORS]; |
| 591 |
fz_buffer *outbuf = NULL; |
| 592 |
fz_output *out = NULL; |
| 593 |
float_queue fq = { 0 }; |
| 594 |
|
| 595 |
fz_var(outbuf); |
| 596 |
fz_var(out); |
| 597 |
fz_var(stream); |
| 598 |
|
| 599 |
read_decode(ctx, shade, n_in, c_min, c_max, n_out, d_min, d_max); |
| 600 |
|
| 601 |
stream = pdf_open_stream(ctx, shade); |
| 602 |
fz_try(ctx) |
| 603 |
{ |
| 604 |
while (!fz_is_eof_bits(ctx, stream)) |
| 605 |
{ |
| 606 |
int startcolor; |
| 607 |
int startpt; |
| 608 |
|
| 609 |
int flag = fz_read_bits(ctx, stream, bpflag); |
| 610 |
|
| 611 |
if (flag == 0) |
| 612 |
{ |
| 613 |
startpt = 0; |
| 614 |
startcolor = 0; |
| 615 |
} |
| 616 |
else |
| 617 |
{ |
| 618 |
startpt = 4; |
| 619 |
startcolor = 2; |
| 620 |
} |
| 621 |
|
| 622 |
for (i = startpt; i < 12; i++) |
| 623 |
{ |
| 624 |
(void) fz_read_bits(ctx, stream, bpcoord); |
| 625 |
(void) fz_read_bits(ctx, stream, bpcoord); |
| 626 |
} |
| 627 |
|
| 628 |
for (i = startcolor; i < 4; i++) |
| 629 |
{ |
| 630 |
for (k = 0; k < n_in; k++) |
| 631 |
c[k] = read_sample(ctx, stream, bpcomp, c_min[k], c_max[k]); |
| 632 |
|
| 633 |
rd->recolor(ctx, rd->opaque, rd->dst_cs, d, rd->src_cs, c); |
| 634 |
|
| 635 |
for (k = 0; k < n_out; k++) |
| 636 |
{ |
| 637 |
if (d[k] < d_min[k]) |
| 638 |
d_min[k] = d[k]; |
| 639 |
if (d[k] > d_max[k]) |
| 640 |
d_max[k] = d[k]; |
| 641 |
float_queue_push(ctx, &fq, d[k]); |
| 642 |
} |
| 643 |
} |
| 644 |
} |
| 645 |
fz_drop_stream(ctx, stream); |
| 646 |
stream = NULL; |
| 647 |
|
| 648 |
rewrite_decode(ctx, shade, n_out, d_min, d_max); |
| 649 |
|
| 650 |
stream = pdf_open_stream(ctx, shade); |
| 651 |
outbuf = fz_new_buffer(ctx, 1); |
| 652 |
out = fz_new_output_with_buffer(ctx, outbuf); |
| 653 |
while (!fz_is_eof_bits(ctx, stream)) |
| 654 |
{ |
| 655 |
int startcolor; |
| 656 |
int startpt; |
| 657 |
|
| 658 |
int flag = fz_read_bits(ctx, stream, bpflag); |
| 659 |
|
| 660 |
fz_write_bits(ctx, out, flag, bpflag); |
| 661 |
|
| 662 |
if (flag == 0) |
| 663 |
{ |
| 664 |
startpt = 0; |
| 665 |
startcolor = 0; |
| 666 |
} |
| 667 |
else |
| 668 |
{ |
| 669 |
startpt = 4; |
| 670 |
startcolor = 2; |
| 671 |
} |
| 672 |
|
| 673 |
for (i = startpt; i < 12; i++) |
| 674 |
{ |
| 675 |
unsigned int x_bits = fz_read_bits(ctx, stream, bpcoord); |
| 676 |
unsigned int y_bits = fz_read_bits(ctx, stream, bpcoord); |
| 677 |
fz_write_bits(ctx, out, x_bits, bpcoord); |
| 678 |
fz_write_bits(ctx, out, y_bits, bpcoord); |
| 679 |
} |
| 680 |
|
| 681 |
for (i = startcolor; i < 4; i++) |
| 682 |
{ |
| 683 |
for (k = 0; k < n_in; k++) |
| 684 |
(void)fz_read_bits(ctx, stream, bpcomp); |
| 685 |
|
| 686 |
for (k = 0; k < n_out; k++) |
| 687 |
{ |
| 688 |
float f = float_queue_pop(ctx, &fq); |
| 689 |
write_sample(ctx, out, 8, d_min[k], d_max[k], f); |
| 690 |
} |
| 691 |
} |
| 692 |
} |
| 693 |
fz_write_bits_sync(ctx, out); |
| 694 |
fz_close_output(ctx, out); |
| 695 |
|
| 696 |
pdf_dict_put_int(ctx, shade, PDF_NAME(BitsPerComponent), 8); |
| 697 |
|
| 698 |
pdf_update_stream(ctx, doc, shade, outbuf, 0); |
| 699 |
} |
| 700 |
fz_always(ctx) |
| 701 |
{ |
| 702 |
float_queue_drop(ctx, &fq); |
| 703 |
fz_drop_stream(ctx, stream); |
| 704 |
fz_drop_output(ctx, out); |
| 705 |
fz_drop_buffer(ctx, outbuf); |
| 706 |
} |
| 707 |
fz_catch(ctx) |
| 708 |
{ |
| 709 |
fz_rethrow(ctx); |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
static void |
| 714 |
fz_recolor_shade_type7(fz_context *ctx, pdf_obj *shade, recolor_details *rd) |
| 715 |
{ |
| 716 |
fz_stream *stream; |
| 717 |
int i, k, n_in = rd->src_cs->n; |
| 718 |
int n_out = rd->dst_cs->n; |
| 719 |
int bpflag = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerFlag)); |
| 720 |
int bpcoord = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerCoordinate)); |
| 721 |
int bpcomp = pdf_dict_get_int(ctx, shade, PDF_NAME(BitsPerComponent)); |
| 722 |
pdf_document *doc = pdf_get_bound_document(ctx, shade); |
| 723 |
float c[FZ_MAX_COLORS]; |
| 724 |
float d[FZ_MAX_COLORS]; |
| 725 |
float c_min[FZ_MAX_COLORS]; |
| 726 |
float c_max[FZ_MAX_COLORS]; |
| 727 |
float d_min[FZ_MAX_COLORS]; |
| 728 |
float d_max[FZ_MAX_COLORS]; |
| 729 |
fz_buffer *outbuf = NULL; |
| 730 |
fz_output *out = NULL; |
| 731 |
float_queue fq = { 0 }; |
| 732 |
|
| 733 |
fz_var(outbuf); |
| 734 |
fz_var(out); |
| 735 |
fz_var(stream); |
| 736 |
|
| 737 |
read_decode(ctx, shade, n_in, c_min, c_max, n_out, d_min, d_max); |
| 738 |
|
| 739 |
stream = pdf_open_stream(ctx, shade); |
| 740 |
fz_try(ctx) |
| 741 |
{ |
| 742 |
while (!fz_is_eof_bits(ctx, stream)) |
| 743 |
{ |
| 744 |
int startcolor; |
| 745 |
int startpt; |
| 746 |
|
| 747 |
int flag = fz_read_bits(ctx, stream, bpflag); |
| 748 |
|
| 749 |
if (flag == 0) |
| 750 |
{ |
| 751 |
startpt = 0; |
| 752 |
startcolor = 0; |
| 753 |
} |
| 754 |
else |
| 755 |
{ |
| 756 |
startpt = 4; |
| 757 |
startcolor = 2; |
| 758 |
} |
| 759 |
|
| 760 |
for (i = startpt; i < 16; i++) |
| 761 |
{ |
| 762 |
(void)fz_read_bits(ctx, stream, bpcoord); |
| 763 |
(void)fz_read_bits(ctx, stream, bpcoord); |
| 764 |
} |
| 765 |
|
| 766 |
for (i = startcolor; i < 4; i++) |
| 767 |
{ |
| 768 |
for (k = 0; k < n_in; k++) |
| 769 |
c[k] = read_sample(ctx, stream, bpcomp, c_min[k], c_max[k]); |
| 770 |
|
| 771 |
rd->recolor(ctx, rd->opaque, rd->dst_cs, d, rd->src_cs, c); |
| 772 |
|
| 773 |
for (k = 0; k < n_out; k++) |
| 774 |
{ |
| 775 |
if (d[k] < d_min[k]) |
| 776 |
d_min[k] = d[k]; |
| 777 |
if (d[k] > d_max[k]) |
| 778 |
d_max[k] = d[k]; |
| 779 |
float_queue_push(ctx, &fq, d[k]); |
| 780 |
} |
| 781 |
} |
| 782 |
} |
| 783 |
fz_drop_stream(ctx, stream); |
| 784 |
stream = NULL; |
| 785 |
|
| 786 |
rewrite_decode(ctx, shade, n_out, d_min, d_max); |
| 787 |
|
| 788 |
stream = pdf_open_stream(ctx, shade); |
| 789 |
outbuf = fz_new_buffer(ctx, 1); |
| 790 |
out = fz_new_output_with_buffer(ctx, outbuf); |
| 791 |
while (!fz_is_eof_bits(ctx, stream)) |
| 792 |
{ |
| 793 |
int startcolor; |
| 794 |
int startpt; |
| 795 |
|
| 796 |
int flag = fz_read_bits(ctx, stream, bpflag); |
| 797 |
|
| 798 |
fz_write_bits(ctx, out, flag, bpflag); |
| 799 |
|
| 800 |
if (flag == 0) |
| 801 |
{ |
| 802 |
startpt = 0; |
| 803 |
startcolor = 0; |
| 804 |
} |
| 805 |
else |
| 806 |
{ |
| 807 |
startpt = 4; |
| 808 |
startcolor = 2; |
| 809 |
} |
| 810 |
|
| 811 |
for (i = startpt; i < 16; i++) |
| 812 |
{ |
| 813 |
unsigned int x_bits = fz_read_bits(ctx, stream, bpcoord); |
| 814 |
unsigned int y_bits = fz_read_bits(ctx, stream, bpcoord); |
| 815 |
fz_write_bits(ctx, out, x_bits, bpcoord); |
| 816 |
fz_write_bits(ctx, out, y_bits, bpcoord); |
| 817 |
} |
| 818 |
|
| 819 |
for (i = startcolor; i < 4; i++) |
| 820 |
{ |
| 821 |
for (k = 0; k < n_in; k++) |
| 822 |
(void)fz_read_bits(ctx, stream, bpcomp); |
| 823 |
|
| 824 |
for (k = 0; k < n_out; k++) |
| 825 |
{ |
| 826 |
float f = float_queue_pop(ctx, &fq); |
| 827 |
write_sample(ctx, out, 8, d_min[k], d_max[k], f); |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
} |
| 832 |
fz_write_bits_sync(ctx, out); |
| 833 |
fz_close_output(ctx, out); |
| 834 |
|
| 835 |
pdf_dict_put_int(ctx, shade, PDF_NAME(BitsPerComponent), 8); |
| 836 |
|
| 837 |
pdf_update_stream(ctx, doc, shade, outbuf, 0); |
| 838 |
} |
| 839 |
fz_always(ctx) |
| 840 |
{ |
| 841 |
float_queue_drop(ctx, &fq); |
| 842 |
fz_drop_stream(ctx, stream); |
| 843 |
fz_drop_output(ctx, out); |
| 844 |
fz_drop_buffer(ctx, outbuf); |
| 845 |
} |
| 846 |
fz_catch(ctx) |
| 847 |
{ |
| 848 |
fz_rethrow(ctx); |
| 849 |
} |
| 850 |
} |
| 851 |
|
| 852 |
pdf_obj * |
| 853 |
pdf_new_colorspace(fz_context *ctx, fz_colorspace *cs) |
| 854 |
{ |
| 855 |
switch (fz_colorspace_type(ctx, cs)) |
| 856 |
{ |
| 857 |
case FZ_COLORSPACE_GRAY: |
| 858 |
return PDF_NAME(DeviceGray); |
| 859 |
case FZ_COLORSPACE_RGB: |
| 860 |
return PDF_NAME(DeviceRGB); |
| 861 |
case FZ_COLORSPACE_CMYK: |
| 862 |
return PDF_NAME(DeviceCMYK); |
| 863 |
default: |
| 864 |
fz_throw(ctx, FZ_ERROR_ARGUMENT, "Unimplemented colorspace"); |
| 865 |
} |
| 866 |
} |
| 867 |
|
| 868 |
pdf_obj * |
| 869 |
pdf_recolor_shade(fz_context *ctx, pdf_obj *shade, pdf_shade_recolorer *reshade, void *opaque) |
| 870 |
{ |
| 871 |
recolor_details rd; |
| 872 |
fz_colorspace *src_cs; |
| 873 |
pdf_obj *background, *new_bg = NULL; |
| 874 |
pdf_obj *function; |
| 875 |
pdf_obj *rewritten = NULL; |
| 876 |
pdf_obj *obj; |
| 877 |
int type, i; |
| 878 |
pdf_function *func[FZ_MAX_COLORS] = { NULL }; |
| 879 |
float d0, d1; |
| 880 |
float samples[256*(FZ_MAX_COLORS + 1)]; |
| 881 |
pdf_document *doc = pdf_get_bound_document(ctx, shade); |
| 882 |
|
| 883 |
src_cs = pdf_load_colorspace(ctx, pdf_dict_get(ctx, shade, PDF_NAME(ColorSpace))); |
| 884 |
|
| 885 |
fz_var(rewritten); |
| 886 |
|
| 887 |
rd.funcs = 0; |
| 888 |
|
| 889 |
fz_try(ctx) |
| 890 |
{ |
| 891 |
rd.recolor = reshade(ctx, opaque, src_cs, &rd.dst_cs); |
| 892 |
if (rd.recolor == NULL) |
| 893 |
break; |
| 894 |
|
| 895 |
rd.src_cs = src_cs; |
| 896 |
rd.opaque = opaque; |
| 897 |
|
| 898 |
rewritten = pdf_deep_copy_obj(ctx, shade); |
| 899 |
|
| 900 |
type = pdf_dict_get_int(ctx, shade, PDF_NAME(ShadingType)); |
| 901 |
|
| 902 |
pdf_dict_put_drop(ctx, rewritten, PDF_NAME(ColorSpace), pdf_new_colorspace(ctx, rd.dst_cs)); |
| 903 |
|
| 904 |
background = pdf_dict_get(ctx, shade, PDF_NAME(Background)); |
| 905 |
if (background) |
| 906 |
{ |
| 907 |
int n = pdf_array_len(ctx, background); |
| 908 |
float bg[FZ_MAX_COLORS]; |
| 909 |
float nbg[FZ_MAX_COLORS]; |
| 910 |
|
| 911 |
if (n > FZ_MAX_COLORS) |
| 912 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "Too many background components"); |
| 913 |
if (n != src_cs->n) |
| 914 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "Wrong background dimension"); |
| 915 |
|
| 916 |
for (i = 0; i < n; i++) |
| 917 |
bg[i] = pdf_array_get_real(ctx, background, i); |
| 918 |
|
| 919 |
rd.recolor(ctx, rd.opaque, rd.dst_cs, nbg, src_cs, bg); |
| 920 |
|
| 921 |
new_bg = pdf_dict_put_array(ctx, rewritten, PDF_NAME(Background), rd.dst_cs->n); |
| 922 |
for (i = 0; i < n; i++) |
| 923 |
pdf_array_put_real(ctx, new_bg, i, bg[i]); |
| 924 |
pdf_dict_put(ctx, rewritten, PDF_NAME(Background), new_bg); |
| 925 |
} |
| 926 |
|
| 927 |
d0 = 0; |
| 928 |
d1 = 1; |
| 929 |
obj = pdf_dict_get(ctx, shade, PDF_NAME(Domain)); |
| 930 |
if (obj) |
| 931 |
{ |
| 932 |
d0 = pdf_array_get_real(ctx, obj, 0); |
| 933 |
d1 = pdf_array_get_real(ctx, obj, 1); |
| 934 |
} |
| 935 |
|
| 936 |
function = pdf_dict_get(ctx, shade, PDF_NAME(Function)); |
| 937 |
if (pdf_is_dict(ctx, function)) |
| 938 |
{ |
| 939 |
rd.funcs = 1; |
| 940 |
func[0] = pdf_load_function(ctx, function, type == 1 ? 2 : 1, src_cs->n); |
| 941 |
if (!func[0]) |
| 942 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "cannot load shading function (%d 0 R)", pdf_to_num(ctx, obj)); |
| 943 |
|
| 944 |
if (type != 1) |
| 945 |
pdf_sample_shade_function(ctx, samples, src_cs->n, 1, func, d0, d1); |
| 946 |
} |
| 947 |
else if (pdf_is_array(ctx, function)) |
| 948 |
{ |
| 949 |
int in; |
| 950 |
|
| 951 |
rd.funcs = pdf_array_len(ctx, function); |
| 952 |
|
| 953 |
if (rd.funcs != 1 && rd.funcs != src_cs->n) |
| 954 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "incorrect number of shading functions"); |
| 955 |
if (rd.funcs > FZ_MAX_COLORS) |
| 956 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "too many shading functions"); |
| 957 |
if (type == 1) |
| 958 |
in = 2; |
| 959 |
else |
| 960 |
in = 1; |
| 961 |
|
| 962 |
for (i = 0; i < rd.funcs; i++) |
| 963 |
{ |
| 964 |
func[i] = pdf_load_function(ctx, pdf_array_get(ctx, function, i), in, 1); |
| 965 |
if (!func[i]) |
| 966 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "cannot load shading function (%d 0 R)", pdf_to_num(ctx, obj)); |
| 967 |
} |
| 968 |
|
| 969 |
if (type != 1) |
| 970 |
pdf_sample_shade_function(ctx, samples, src_cs->n, rd.funcs, func, d0, d1); |
| 971 |
} |
| 972 |
else if (type < 4) |
| 973 |
{ |
| 974 |
|
| 975 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "cannot load shading function (%d 0 R)", pdf_to_num(ctx, obj)); |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
if (type == 1) |
| 980 |
{ |
| 981 |
fz_recolor_shade_type1(ctx, rewritten, func, &rd); |
| 982 |
break; |
| 983 |
} |
| 984 |
|
| 985 |
|
| 986 |
if (rd.funcs) |
| 987 |
{ |
| 988 |
fz_recolor_shade_function(ctx, rewritten, samples, src_cs->n+1, &rd); |
| 989 |
break; |
| 990 |
} |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
obj = pdf_add_object(ctx, doc, rewritten); |
| 995 |
pdf_drop_obj(ctx, rewritten); |
| 996 |
rewritten = obj; |
| 997 |
|
| 998 |
switch (type) |
| 999 |
{ |
| 1000 |
case FZ_FUNCTION_BASED: |
| 1001 |
|
| 1002 |
break; |
| 1003 |
case FZ_LINEAR: |
| 1004 |
case FZ_RADIAL: |
| 1005 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "Linear/Radial shadings must use functions"); |
| 1006 |
break; |
| 1007 |
case FZ_MESH_TYPE4: |
| 1008 |
fz_recolor_shade_type4(ctx, rewritten, &rd); |
| 1009 |
break; |
| 1010 |
case FZ_MESH_TYPE5: |
| 1011 |
fz_recolor_shade_type5(ctx, rewritten, &rd); |
| 1012 |
break; |
| 1013 |
case FZ_MESH_TYPE6: |
| 1014 |
fz_recolor_shade_type6(ctx, rewritten, &rd); |
| 1015 |
break; |
| 1016 |
case FZ_MESH_TYPE7: |
| 1017 |
fz_recolor_shade_type7(ctx, rewritten, &rd); |
| 1018 |
break; |
| 1019 |
default: |
| 1020 |
fz_throw(ctx, FZ_ERROR_SYNTAX, "Unexpected mesh type %d\n", type); |
| 1021 |
} |
| 1022 |
} |
| 1023 |
fz_always(ctx) |
| 1024 |
{ |
| 1025 |
for (i = 0; i < rd.funcs; i++) |
| 1026 |
pdf_drop_function(ctx, func[i]); |
| 1027 |
fz_drop_colorspace(ctx, src_cs); |
| 1028 |
} |
| 1029 |
fz_catch(ctx) |
| 1030 |
{ |
| 1031 |
pdf_drop_obj(ctx, rewritten); |
| 1032 |
fz_rethrow(ctx); |
| 1033 |
} |
| 1034 |
|
| 1035 |
return rewritten ? rewritten : shade; |
| 1036 |
} |