1 /* Copyright (C) 1997, 1999 Aladdin Enterprises. All rights reserved.
2
3 This software is provided AS-IS with no warranty, either express or
4 implied.
5
6 This software is distributed under license and may not be copied,
7 modified or distributed except as expressly authorized under the terms
8 of the license contained in the file LICENSE in this distribution.
9
10 For more information about licensing, please refer to
11 http://www.ghostscript.com/licensing/. For information on
12 commercial licensing, go to http://www.artifex.com/licensing/ or
13 contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 San Rafael, CA 94903, U.S.A., +1(415)492-9861.
15 */
16
17 /* $Id: gxsample.c,v 1.7 2005/06/08 14:38:21 igor Exp $ */
18 /* Sample unpacking procedures */
19 #include "gx.h"
20 #include "gxsample.h"
21 #include "gxfixed.h"
22 #include "gximage.h"
23 /* #include "gxsamplp.h" Do not remove - this file is included below. */
24
25
26 /* ---------------- Lookup tables ---------------- */
27
28 /*
29 * Define standard tables for spreading 1-bit input data.
30 * Note that these depend on the end-orientation of the CPU.
31 * We can't simply define them as byte arrays, because
32 * they might not wind up properly long- or short-aligned.
33 */
34 #define map4tox(z,a,b,c,d)\
35 z, z^a, z^b, z^(a+b),\
36 z^c, z^(a+c), z^(b+c), z^(a+b+c),\
37 z^d, z^(a+d), z^(b+d), z^(a+b+d),\
38 z^(c+d), z^(a+c+d), z^(b+c+d), z^(a+b+c+d)
39 /* Work around warnings from really picky compilers. */
40 #ifdef __STDC__
41 # define n0L 0xffffffffU
42 # define ffL8 0x0000ff00U
43 # define ffL16 0x00ff0000U
44 # define ffL24 0xff000000U
45 #else
46 #if arch_sizeof_long == 4
47 /*
48 * The compiler evaluates long expressions mod 2^32. Even very picky
49 * compilers allow assigning signed longs to unsigned longs, so we use
50 * signed constants.
51 */
52 # define n0L (-1)
53 # define ffL8 0x0000ff00
54 # define ffL16 0x00ff0000
55 # define ffL24 (-0x01000000)
56 #else
57 /*
58 * The compiler evaluates long expressions mod 2^64.
59 */
60 # define n0L 0xffffffffL
61 # define ffL8 0x0000ff00L
62 # define ffL16 0x00ff0000L
63 # define ffL24 0xff000000L
64 #endif
65 #endif
66 #if arch_is_big_endian
67 const bits32 lookup4x1to32_identity[16] = {
68 map4tox(0, 0xff, ffL8, ffL16, ffL24)
69 };
70 const bits32 lookup4x1to32_inverted[16] = {
71 map4tox(n0L, 0xff, ffL8, ffL16, ffL24)
72 };
73 #else /* !arch_is_big_endian */
74 const bits32 lookup4x1to32_identity[16] = {
75 map4tox(0, ffL24, ffL16, ffL8, 0xff)
76 };
77 const bits32 lookup4x1to32_inverted[16] = {
78 map4tox(n0L, ffL24, ffL16, ffL8, 0xff)
79 };
80 #endif
81 #undef n0L
82 #undef ffL8
83 #undef ffL16
84 #undef ffL24
85
86 /* ---------------- Unpacking procedures ---------------- */
87
88 const byte *
sample_unpack_copy(byte * bptr,int * pdata_x,const byte * data,int data_x,uint dsize,const sample_map * ignore_smap,int spread,int ignore_num_components_per_plane)89 sample_unpack_copy(byte * bptr, int *pdata_x, const byte * data, int data_x,
90 uint dsize, const sample_map *ignore_smap, int spread,
91 int ignore_num_components_per_plane)
92 { /* We're going to use the data right away, so no copying is needed. */
93 *pdata_x = data_x;
94 return data;
95 }
96
97 #define MULTIPLE_MAPS 0
98 #define TEMPLATE_sample_unpack_1 sample_unpack_1
99 #define TEMPLATE_sample_unpack_2 sample_unpack_2
100 #define TEMPLATE_sample_unpack_4 sample_unpack_4
101 #define TEMPLATE_sample_unpack_8 sample_unpack_8
102
103 #include "gxsamplp.h"
104
105 #undef MULTIPLE_MAPS
106 #undef TEMPLATE_sample_unpack_1
107 #undef TEMPLATE_sample_unpack_2
108 #undef TEMPLATE_sample_unpack_4
109 #undef TEMPLATE_sample_unpack_8
110
111
112 #define MULTIPLE_MAPS 1
113 #define TEMPLATE_sample_unpack_1 sample_unpack_1_interleaved
114 #define TEMPLATE_sample_unpack_2 sample_unpack_2_interleaved
115 #define TEMPLATE_sample_unpack_4 sample_unpack_4_interleaved
116 #define TEMPLATE_sample_unpack_8 sample_unpack_8_interleaved
117
118 #include "gxsamplp.h"
119
120 #undef TEMPLATE_sample_unpack_1
121 #undef TEMPLATE_sample_unpack_2
122 #undef TEMPLATE_sample_unpack_4
123 #undef TEMPLATE_sample_unpack_8
124 #undef MULTIPLE_MAPS
125