summaryrefslogtreecommitdiff
path: root/src/pdflib/pdflib/p_color.h
blob: 4a1f5849c2ad848964f6d3dd037deff53644dfd5 (plain)
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
/*---------------------------------------------------------------------------*
 |              PDFlib - A library for generating PDF on the fly             |
 +---------------------------------------------------------------------------+
 | Copyright (c) 1997-2006 Thomas Merz and PDFlib GmbH. All rights reserved. |
 +---------------------------------------------------------------------------+
 |                                                                           |
 |    This software is subject to the PDFlib license. It is NOT in the       |
 |    public domain. Extended versions and commercial licenses are           |
 |    available, please check http://www.pdflib.com.                         |
 |                                                                           |
 *---------------------------------------------------------------------------*/

/* $Id: p_color.h,v 1.2 2009/10/20 18:14:16 scuri Exp $
 *
 * PDFlib color definitions
 *
 */

#ifndef P_COLOR_H
#define P_COLOR_H

/*
 * These are treated specially in the global colorspace list, and are not
 * written as /ColorSpace resource since we always specify them directly.
 * Pattern colorspace with base == pdc_undef means PaintType == 1.
 */
#define PDF_SIMPLE_COLORSPACE(cs)		\
	((cs)->type == DeviceGray ||		\
	 (cs)->type == DeviceRGB ||		\
	 (cs)->type == DeviceCMYK ||		\
	 ((cs)->type == PatternCS && cs->val.pattern.base == pdc_undef))


struct pdf_pattern_s {
    pdc_id	obj_id;			/* object id of this pattern */
    int		painttype;		/* colored (1) or uncolored (2) */
    pdc_bool	used_on_current_page;	/* this pattern used on current page */
};

typedef pdc_byte pdf_colormap[256][3];

typedef struct {
    int      		cs;     	/* slot of underlying color space */

    union {
        pdc_scalar      gray;           /* DeviceGray */
        int             pattern;        /* Pattern */
        int             idx;        	/* Indexed */
        struct {                        /* DeviceRGB */
            pdc_scalar  r;
            pdc_scalar  g;
            pdc_scalar  b;
        } rgb;
        struct {                        /* DeviceCMYK */
            pdc_scalar  c;
            pdc_scalar  m;
            pdc_scalar  y;
            pdc_scalar  k;
        } cmyk;
    } val;
} pdf_color;

struct pdf_colorspace_s {
    pdf_colorspacetype type;            /* color space type */

    union {
	struct {			/* Indexed */
	    int   	base;		/* base color space */
	    pdf_colormap *colormap;	/* pointer to colormap */
	    pdc_bool	colormap_done;	/* colormap already written to output */
	    int		palette_size;	/* # of palette entries (not bytes!) */
	    pdc_id	colormap_id;	/* object id of colormap */
	} indexed;

	struct {			/* Pattern */
	    int   	base;		/* base color space for PaintType 2 */
	} pattern;

    } val;

    pdc_id      obj_id;                 /* object id of this colorspace */
    pdc_bool    used_on_current_page;   /* this resource used on current page */
};

/* "color" option */
typedef struct
{
    char name[PDF_MAX_NAMESTRING + 1];
    int type;
    pdc_scalar value[4];
}
pdf_coloropt;


pdf_color *pdf_get_cstate(PDF *p, pdf_drawmode mode);
void    pdf_get_page_colorspaces(PDF *p, pdf_reslist *rl);
void    pdf_write_function_dict(PDF *p, pdf_color *c0, pdf_color *c1,
                                pdc_scalar N);
int	pdf_add_colorspace(PDF *p, pdf_colorspace *cs, pdc_bool inuse);
void    pdf_parse_coloropt(PDF *p, const char *optname, char **optvalue, int ns,
                           int maxtype, pdf_coloropt *c);
void    pdf_set_coloropt(PDF *p, int drawmode, pdf_coloropt *c);
void    pdf_init_coloropt(PDF *p, pdf_coloropt *c);
void    pdf_logg_coloropt(PDF *p, pdf_coloropt *c, pdc_bool newline);



#endif  /* P_COLOR_H */