| 1 |
/* Copyright (C) 2018-2023 Artifex Software, Inc. |
| 2 |
All Rights Reserved. |
| 3 |
|
| 4 |
This software is provided AS-IS with no warranty, either express or |
| 5 |
implied. |
| 6 |
|
| 7 |
This software is distributed under license and may not be copied, |
| 8 |
modified or distributed except as expressly authorized under the terms |
| 9 |
of the license contained in the file LICENSE in this distribution. |
| 10 |
|
| 11 |
Refer to licensing information at http://www.artifex.com or contact |
| 12 |
Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
| 13 |
CA 94129, USA, for further information. |
| 14 |
*/ |
| 15 |
|
| 16 |
/* colour operations for the PDF interpreter */ |
| 17 |
|
| 18 |
#ifndef PDF_COLOUR_OPERATORS |
| 19 |
#define PDF_COLOUR_OPERATORS |
| 20 |
|
| 21 |
#include "gscolor1.h" |
| 22 |
#include "gscspace.h" |
| 23 |
#include "pdf_stack.h" /* for pdfi_countup/countdown */ |
| 24 |
#include "pdf_misc.h" /* for pdf_name_cmp */ |
| 25 |
|
| 26 |
static inline void pdfi_set_colourspace_name(pdf_context *ctx, gs_color_space *pcs, pdf_name *n) |
| 27 |
{ |
| 28 |
if (pcs->interpreter_data != NULL) { |
| 29 |
pdf_obj *o = (pdf_obj *)(pcs->interpreter_data); |
| 30 |
if (o != NULL && pdfi_type_of(o) == PDF_NAME) { |
| 31 |
pdfi_countdown(o); |
| 32 |
pcs->interpreter_data = NULL; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
if (n != NULL) { |
| 37 |
pcs->interpreter_data = n; |
| 38 |
pdfi_countup(n); |
| 39 |
} else { |
| 40 |
if (pcs->interpreter_data == NULL) |
| 41 |
pcs->interpreter_data = ctx; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
static inline void pdfi_set_colour_callback(gs_color_space *pcs, pdf_context *ctx, gs_cspace_free_proc_t pdfi_cspace_free_callback) |
| 46 |
{ |
| 47 |
if (pcs->interpreter_data == NULL) |
| 48 |
pcs->interpreter_data = ctx; |
| 49 |
pcs->interpreter_free_cspace_proc = pdfi_cspace_free_callback; |
| 50 |
} |
| 51 |
|
| 52 |
static inline int check_same_current_space(pdf_context *ctx, pdf_name *n) |
| 53 |
{ |
| 54 |
pdf_obj *o = (pdf_obj *)(ctx->pgs->color[0].color_space->interpreter_data); |
| 55 |
|
| 56 |
if (o == NULL || pdfi_type_of(o) != PDF_NAME) |
| 57 |
return 0; |
| 58 |
|
| 59 |
if (pdfi_name_cmp(n, (pdf_name *)o) == 0) { |
| 60 |
if (n->object_num == o->object_num && n->indirect_num == o->indirect_num) |
| 61 |
return 1; |
| 62 |
} |
| 63 |
return 0; |
| 64 |
} |
| 65 |
|
| 66 |
int pdfi_setgraystroke(pdf_context *ctx); |
| 67 |
int pdfi_setgrayfill(pdf_context *ctx); |
| 68 |
int pdfi_setrgbstroke(pdf_context *ctx); |
| 69 |
int pdfi_setrgbfill(pdf_context *ctx); |
| 70 |
int pdfi_setrgbfill_array(pdf_context *ctx); |
| 71 |
int pdfi_setcmykstroke(pdf_context *ctx); |
| 72 |
int pdfi_setcmykfill(pdf_context *ctx); |
| 73 |
int pdfi_setstrokecolor_space(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict); |
| 74 |
int pdfi_setfillcolor_space(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict); |
| 75 |
int pdfi_setstrokecolor(pdf_context *ctx); |
| 76 |
int pdfi_setfillcolor(pdf_context *ctx); |
| 77 |
int pdfi_setcolorN(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict, bool is_fill); |
| 78 |
int pdfi_ri(pdf_context *ctx); |
| 79 |
|
| 80 |
int pdfi_setcolor_from_array(pdf_context *ctx, pdf_array *array); |
| 81 |
int pdfi_gs_setgray(pdf_context *ctx, double d); |
| 82 |
int pdfi_gs_setrgbcolor(pdf_context *ctx, double r, double g, double b); |
| 83 |
|
| 84 |
/* For potential use by other types of object (images etc) */ |
| 85 |
int pdfi_gs_setcolorspace(pdf_context *ctx, gs_color_space *pcs); |
| 86 |
int pdfi_setcolorspace(pdf_context *ctx, pdf_obj *space, pdf_dict *stream_dict, pdf_dict *page_dict); |
| 87 |
int pdfi_create_colorspace(pdf_context *ctx, pdf_obj *space, pdf_dict *stream_dict, pdf_dict *page_dict, gs_color_space **ppcs, bool inline_image); |
| 88 |
int pdfi_create_icc_colorspace_from_stream(pdf_context *ctx, pdf_c_stream *stream, gs_offset_t offset, |
| 89 |
unsigned int length, int comps, int *icc_N, ulong dictkey, gs_color_space **ppcs); |
| 90 |
|
| 91 |
/* Page level spot colour detection and enumeration */ |
| 92 |
int pdfi_check_ColorSpace_for_spots(pdf_context *ctx, pdf_obj *space, pdf_dict *parent_dict, pdf_dict *page_dict, pdf_dict *spot_dict); |
| 93 |
|
| 94 |
int pdfi_color_setoutputintent(pdf_context *ctx, pdf_dict *intent_dict, pdf_stream *profile); |
| 95 |
|
| 96 |
/* Sets up the DefaultRGB, DefaultCMYK and DefaultGray colour spaces if present */ |
| 97 |
int pdfi_setup_DefaultSpaces(pdf_context *ctx, pdf_dict *source_dict); |
| 98 |
|
| 99 |
#endif |