summaryrefslogtreecommitdiff
path: root/render/thscreen.h
blob: d3ac9b1b093c5abae0e739c32d75145a6e16d9f4 (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
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

#ifndef THSCREEN_H
#define THSCREEN_H

/*
 * render2d
 *
 * Threshold screen pixel processing object.
 * (Simplified from DPS code)
 *
 * Author:  Graeme W. Gill
 * Date:    11/7/2005
 * Version: 1.00
 *
 * Copyright 2005, 2012 Graeme W. Gill
 * All rights reserved.
 * This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :-
 * see the License.txt file for licencing details.
 *
 */

/* Light Separation in screening flag */
typedef enum {
	scls_false = 0,		/* Don't do light ink separation during screening. */
	scls_true  = 0		/* Do light ink separation during screening. */
} sc_lightsep;

/* Input encoding */
typedef enum {
	scie_8  = 0,		/*  8 bit per component */
	scie_16 = 1			/* 16 bit per component */
} sc_iencoding;

/* Output bit order within byte */
typedef enum {
	scoo_l = 0,		/* Little endian */
	scoo_b = 1		/* Big endian */
} sc_oorder;


/* ---------------------------- */
/* Setup a set of screens */

struct _thscreens {
	int np;						/* Number of planes */
	struct _thscreen **sc;		/* List of screens */

	/* Screen a single color plane */
	void (* screen)(			/* Pointer to dither function */
		struct _thscreens *t,	/* Screening object pointer */
		int width, int height,	/* Width and height to screen in pixels */
		int xoff, int yoff,		/* Offset into screening pattern */
		unsigned char *in,		/* Input pixel buffer */
		unsigned long ipitch,	/* Increment between input lines */
		unsigned char *out,		/* Output pixel buffer */
		unsigned long opitch);	/* Increment between output lines */

	void (* del)(				/* Destructor */
		struct _thscreens *t);	/* Screening objects pointer */

}; typedef struct _thscreens thscreens;


/* Return a thscreens object */
/* Screen data is used that best matches the requested parameters. */
/* Return NULL on error */
thscreens *new_thscreens(
	int exact,				/* Return only exact matches */
	int nplanes,			/* Number of planes to screen */
	double asp,				/* Target aspect ratio (== dpiX/dpiY) */
	int size,				/* Target size */
	sc_iencoding ie,		/* Input encoding - must be scie_16 */
	int oebpc,				/* Output encoding bits per component - must be 8 */
	int oelev,				/* Output encoding levels. Must be <= 2 ^ oebpc */
	int *oevalues,			/* Optional output encoding values for each level */
							/* Must be oelev entries. Default is 0 .. oelev-1 */
	sc_oorder oo,			/* Output bit ordering */
	double overlap,			/* Overlap between levels, 0 - 1.0 */
	void   **cntx,			/* List of contexts for lookup table callback */
	double (**lutfunc)(void *cntx, double in)	/* List of callback function, NULL if none */
);

/* ---------------------------- */
/* Screen defintion information */

typedef struct {
	int x;
	int y;
} ccoord;

typedef struct {
	int size;			/* General size */
	int width;			/* width in pixels */
	int height;			/* Height in pixels */
	double asp;			/* Aspect ratio (== dpiX/dpiY) */
	int joint;			/* na for joint screens */
	ccoord **list;		/* Pointer to list of pointers to threshold coordinates */
} thscdef;

/* ------------------------ */
/* Setup of a single screen */

struct _thscreen {
	sc_iencoding ie;			/* Input encoding */
	int oebpc;					/* Output encoding bits per component, 1,2,4 or 8 */
	int oelev;					/* Output encoding levels. Must be <= 2 ^ oebpc */
	int oevalues[256];			/* Output encoding values for each level */
	sc_oorder oo;				/* Output bit ordering */
	double asp;					/* Aspect ratio (== dpiX/dpiY) */
	double overlap;				/* Overlap between levels, 0 - 1.0 */
	int *lut;					/* Lookup table */
	unsigned char _tht[65536 * 3];/* Threshold table */
	unsigned char *tht;			/* Pointer to base of threshold table */
	unsigned char **thp;		/* Pointers to threshold table (offset int _tht) */
	int swidth;					/* Given screen width */
	int sheight;				/* Given screen height */
	int twidth;					/* Rounded up screen table width & stride */
	int theight;				/* Screen table height */ 

	void (* screen)(			/* Pointer to dither function */
		struct _thscreen *t,	/* Screening object pointer */
		int width, int height,	/* Width and height to screen in pixels */
		int xoff, int yoff,		/* Offset into screening pattern */
		unsigned char *in,		/* Input pixel buffer */
		unsigned long ipinc,	/* Increment between input pixels */
		unsigned long ipitch,	/* Increment between input lines */
		unsigned char *out,		/* Output pixel buffer */
		unsigned long opinc,	/* Increment between output pixels */
		unsigned long opitch);	/* Increment between output lines */

	void (* del)(				/* Destructor */
		struct _thscreen *t);	/* Screening object pointer */

}; typedef struct _thscreen thscreen;

/* Create a new thscreen object */
/* Return NULL on error */
thscreen *new_thscreen(
	int width,					/* width in pixels */
	int height,					/* Height in pixels */
	int xoff, int yoff,			/* Pattern offsets into width & height (must be +ve) */
	double asp,					/* Aspect ratio (== dpiX/dpiY) */
	int swap,					/* Swap X & Y to invert aspect ratio */
	ccoord *thli,				/* List of screen initialisation threshold coordinates */
	sc_iencoding ie,			/* Input encoding - must be scie_16 */
	int oebpc,					/* Output encoding bits per component - must be 8 */
	int oelev,					/* Output encoding levels. Must be <= 2 ^ oebpc */
	int *oevalues,				/* Optional output encoding values for each level */
								/* Must be oelev entries. Default is 0 .. oelev-1 */
	sc_oorder oo,				/* Output bit ordering */
	double olap,				/* Overlap between levels, 0 - 1.0 */
	void   *cntx,				/* Context for LUT table callback */
	double (*lutfunc)(void *cntx, double in)	/* Callback function, NULL if none */
);

#endif /* THSCREEN_H */