summaryrefslogtreecommitdiff
path: root/include/gutenprint/dither.h
blob: 73f3ab725903b064f8a30fa85a24f1a9cc12a7ee (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
 *   libgimpprint dither header.
 *
 *   Copyright 1997-2000 Michael Sweet (mike@easysw.com) and
 *	Robert Krawitz (rlk@alum.mit.edu)
 *
 *   This program is free software; you can redistribute it and/or modify it
 *   under the terms of the GNU General Public License as published by the Free
 *   Software Foundation; either version 2 of the License, or (at your option)
 *   any later version.
 *
 *   This program is distributed in the hope that it will be useful, but
 *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *   for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Revision History:
 *
 *   See ChangeLog
 */

/**
 * @file gutenprint/dither.h
 * @brief Dither functions.
 */

/*
 * This file must include only standard C header files.  The core code must
 * compile on generic platforms that don't support glib, gimp, gtk, etc.
 */

#ifndef GUTENPRINT_DITHER_H
#define GUTENPRINT_DITHER_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/*
 * STP_ECOLOR_K must be 0
 */
#define STP_ECOLOR_K  0
#define STP_ECOLOR_C  1
#define STP_ECOLOR_M  2
#define STP_ECOLOR_Y  3
#define STP_NCOLORS (4)

typedef struct stp_dither_matrix_short
{
  int x;
  int y;
  int bytes;
  int prescaled;
  const unsigned short *data;
} stp_dither_matrix_short_t;

typedef struct stp_dither_matrix_normal
{
  int x;
  int y;
  int bytes;
  int prescaled;
  const unsigned *data;
} stp_dither_matrix_normal_t;

typedef struct stp_dither_matrix_generic
{
  int x;
  int y;
  int bytes;
  int prescaled;
  const void *data;
} stp_dither_matrix_generic_t;

typedef struct dither_matrix_impl
{
  int base;
  int exp;
  int x_size;
  int y_size;
  int total_size;
  int last_x;
  int last_x_mod;
  int last_y;
  int last_y_mod;
  int index;
  int i_own;
  int x_offset;
  int y_offset;
  unsigned fast_mask;
  unsigned *matrix;
} stp_dither_matrix_impl_t;

extern void stp_dither_matrix_iterated_init(stp_dither_matrix_impl_t *mat, size_t size,
					    size_t exponent, const unsigned *array);
extern void stp_dither_matrix_shear(stp_dither_matrix_impl_t *mat,
				    int x_shear, int y_shear);
extern void stp_dither_matrix_init(stp_dither_matrix_impl_t *mat, int x_size,
				   int y_size, const unsigned int *array,
				   int transpose, int prescaled);
extern void stp_dither_matrix_init_short(stp_dither_matrix_impl_t *mat, int x_size,
					 int y_size,
					 const unsigned short *array,
					 int transpose, int prescaled);
extern int stp_dither_matrix_validate_array(const stp_array_t *array);
extern void stp_dither_matrix_init_from_dither_array(stp_dither_matrix_impl_t *mat,
						     const stp_array_t *array,
						     int transpose);
extern void stp_dither_matrix_destroy(stp_dither_matrix_impl_t *mat);
extern void stp_dither_matrix_clone(const stp_dither_matrix_impl_t *src,
				    stp_dither_matrix_impl_t *dest,
				    int x_offset, int y_offset);
extern void stp_dither_matrix_copy(const stp_dither_matrix_impl_t *src,
				   stp_dither_matrix_impl_t *dest);
extern void stp_dither_matrix_scale_exponentially(stp_dither_matrix_impl_t *mat,
						  double exponent);
extern void stp_dither_matrix_set_row(stp_dither_matrix_impl_t *mat, int y);
extern stp_array_t *stp_find_standard_dither_array(int x_aspect, int y_aspect);


typedef struct stp_dotsize
{
  unsigned bit_pattern;
  double value;
} stp_dotsize_t;

typedef struct stp_shade
{
  double value;
  int numsizes;
  const stp_dotsize_t *dot_sizes;
} stp_shade_t;

extern stp_parameter_list_t stp_dither_list_parameters(const stp_vars_t *v);

extern void
stp_dither_describe_parameter(const stp_vars_t *v, const char *name,
			      stp_parameter_t *description);

extern void stp_dither_init(stp_vars_t *v, stp_image_t *image,
			    int out_width, int xdpi, int ydpi);
extern void stp_dither_set_iterated_matrix(stp_vars_t *v, size_t edge,
					   size_t iterations,
					   const unsigned *data,
					   int prescaled,
					   int x_shear, int y_shear);
extern void stp_dither_set_matrix(stp_vars_t *v, const stp_dither_matrix_generic_t *mat,
				  int transpose, int x_shear, int y_shear);
extern void stp_dither_set_matrix_from_dither_array(stp_vars_t *v,
						    const stp_array_t *array,
						    int transpose);
extern void stp_dither_set_transition(stp_vars_t *v, double);
extern void stp_dither_set_randomizer(stp_vars_t *v, int color, double);
extern void stp_dither_set_ink_spread(stp_vars_t *v, int spread);
extern void stp_dither_set_adaptive_limit(stp_vars_t *v, double limit);
extern int stp_dither_get_first_position(stp_vars_t *v, int color, int subchan);
extern int stp_dither_get_last_position(stp_vars_t *v, int color, int subchan);
extern void stp_dither_set_inks_simple(stp_vars_t *v, int color, int nlevels,
				       const double *levels, double density,
				       double darkness);
extern void stp_dither_set_inks_full(stp_vars_t *v, int color, int nshades,
				     const stp_shade_t *shades,
				     double density, double darkness);
extern void stp_dither_set_inks(stp_vars_t *v, int color,
				double density, double darkness,
				int nshades, const double *svalues,
				int ndotsizes, const double *dvalues);


extern void stp_dither_add_channel(stp_vars_t *v, unsigned char *data,
				   unsigned channel, unsigned subchannel);

extern unsigned char *stp_dither_get_channel(stp_vars_t *v,
					     unsigned channel,
					     unsigned subchannel);

extern void stp_dither(stp_vars_t *v, int row, int duplicate_line,
		       int zero_mask, const unsigned char *mask);

/* #ifdef STP_TESTDITHER */
extern void stp_dither_internal(stp_vars_t *v, int row,
				const unsigned short *input,
				int duplicate_line, int zero_mask,
				const unsigned char *mask);
/* #endif */

#ifdef __cplusplus
  }
#endif

#endif /* GUTENPRINT_DITHER_H */