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
|
/*
*
* Performance-critical functions that should be inlined, based on
* measurements.
*
* Copyright 1997-2003 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Revision History:
*
* See ChangeLog
*/
#ifndef GUTENPRINT_INTERNAL_DITHER_INLINED_FUNCTIONS_H
#define GUTENPRINT_INTERNAL_DITHER_INLINED_FUNCTIONS_H
/*
* Inlining has yielded significant (measured) speedup, even with the
* more complicated dither function. --rlk 20011219
*/
static inline unsigned
ditherpoint(const stpi_dither_t *d, stp_dither_matrix_impl_t *mat, int x)
{
if (mat->fast_mask)
return mat->matrix[(mat->last_y_mod +
((x + mat->x_offset) & mat->fast_mask))];
/*
* This rather bizarre code is an attempt to avoid having to compute a lot
* of modulus and multiplication operations, which are typically slow.
*/
if (x == mat->last_x + 1)
{
mat->last_x_mod++;
mat->index++;
if (mat->last_x_mod >= mat->x_size)
{
mat->last_x_mod -= mat->x_size;
mat->index -= mat->x_size;
}
}
else if (x == mat->last_x - 1)
{
mat->last_x_mod--;
mat->index--;
if (mat->last_x_mod < 0)
{
mat->last_x_mod += mat->x_size;
mat->index += mat->x_size;
}
}
else if (x != mat->last_x)
{
mat->last_x_mod = (x + mat->x_offset) % mat->x_size;
mat->index = mat->last_x_mod + mat->last_y_mod;
}
mat->last_x = x;
return mat->matrix[mat->index];
}
static inline void
set_row_ends(stpi_dither_channel_t *dc, int x)
{
if (dc->row_ends[0] == -1)
dc->row_ends[0] = x;
dc->row_ends[1] = x;
}
#endif /* GUTENPRINT_INTERNAL_DITHER_INLINED_FUNCTIONS_H */
|