~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to base/gshtx.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: gshtx.c 8250 2007-09-25 13:31:24Z giles $ */
 
14
/* $Id$ */
15
15
/* Stand-alone halftone/transfer function related code */
16
16
#include "memory_.h"
17
17
#include "gx.h"
28
28
 */
29
29
static void
30
30
free_comps(
31
 
              gs_memory_t * pmem,
32
 
              void *pvht,
33
 
              client_name_t cname
 
31
              gs_memory_t * pmem,
 
32
              void *pvht,
 
33
              client_name_t cname
34
34
)
35
35
{
36
36
    gs_ht *pht = (gs_ht *) pvht;
45
45
 */
46
46
static float
47
47
null_closure_transfer(
48
 
                         floatp val,
49
 
                         const gx_transfer_map * pmap_dummy,    /* NOTUSED */
50
 
                         const void *dummy      /* NOTUSED */
 
48
                         floatp val,
 
49
                         const gx_transfer_map * pmap_dummy,    /* NOTUSED */
 
50
                         const void *dummy      /* NOTUSED */
51
51
)
52
52
{
53
53
    return val;
54
54
}
55
55
 
56
 
 
57
56
/*
58
57
 * Build a gs_ht halftone structure.
59
58
 */
60
59
int
61
60
gs_ht_build(
62
 
               gs_ht ** ppht,
63
 
               uint num_comps,
64
 
               gs_memory_t * pmem
 
61
               gs_ht ** ppht,
 
62
               uint num_comps,
 
63
               gs_memory_t * pmem
65
64
)
66
65
{
67
66
    gs_ht *pht;
71
70
    /* must have at least one component */
72
71
    *ppht = 0;
73
72
    if (num_comps == 0)
74
 
        return_error(gs_error_rangecheck);
 
73
        return_error(gs_error_rangecheck);
75
74
 
76
75
    /* allocate the halftone and the array of components */
77
76
    rc_alloc_struct_1(pht,
78
 
                      gs_ht,
79
 
                      &st_gs_ht,
80
 
                      pmem,
81
 
                      return_error(gs_error_VMerror),
82
 
                      "gs_ht_build"
83
 
        );
 
77
                      gs_ht,
 
78
                      &st_gs_ht,
 
79
                      pmem,
 
80
                      return_error(gs_error_VMerror),
 
81
                      "gs_ht_build"
 
82
        );
84
83
    phtc = gs_alloc_struct_array(pmem,
85
 
                                 num_comps,
86
 
                                 gs_ht_component,
87
 
                                 &st_ht_comp_element,
88
 
                                 "gs_ht_build"
89
 
        );
 
84
                                 num_comps,
 
85
                                 gs_ht_component,
 
86
                                 &st_ht_comp_element,
 
87
                                 "gs_ht_build"
 
88
        );
90
89
    if (phtc == 0) {
91
 
        gs_free_object(pmem, pht, "gs_ht_build");
92
 
        return_error(gs_error_VMerror);
 
90
        gs_free_object(pmem, pht, "gs_ht_build");
 
91
        return_error(gs_error_VMerror);
93
92
    }
94
93
    /* initialize the halftone */
95
94
    pht->type = ht_type_multiple;
99
98
 
100
99
    for (i = 0; i < num_comps; i++) {
101
100
        phtc[i].comp_number = i;
102
 
        phtc[i].cname = 0;
103
 
        phtc[i].type = ht_type_none;
 
101
        phtc[i].cname = 0;
 
102
        phtc[i].type = ht_type_none;
104
103
    }
105
104
 
106
105
    *ppht = pht;
113
112
 */
114
113
int
115
114
gs_ht_set_spot_comp(
116
 
                       gs_ht * pht,
117
 
                       int comp,
118
 
                       floatp freq,
119
 
                       floatp angle,
120
 
                       float (*spot_func) (floatp, floatp),
121
 
                       bool accurate,
122
 
                       gs_ht_transfer_proc transfer,
123
 
                       const void *client_data
 
115
                       gs_ht * pht,
 
116
                       int comp,
 
117
                       floatp freq,
 
118
                       floatp angle,
 
119
                       float (*spot_func) (floatp, floatp),
 
120
                       bool accurate,
 
121
                       gs_ht_transfer_proc transfer,
 
122
                       const void *client_data
124
123
)
125
124
{
126
125
    gs_ht_component *phtc = &(pht->params.ht_multiple.components[comp]);
127
126
 
128
127
    if (comp >= pht->params.ht_multiple.num_comp)
129
 
        return_error(gs_error_rangecheck);
 
128
        return_error(gs_error_rangecheck);
130
129
    if (phtc->type != ht_type_none)
131
 
        return_error(gs_error_invalidaccess);
 
130
        return_error(gs_error_invalidaccess);
132
131
 
133
132
    phtc->type = ht_type_spot;
134
133
    phtc->params.ht_spot.screen.frequency = freq;
138
137
    phtc->params.ht_spot.transfer = gs_mapped_transfer;
139
138
 
140
139
    phtc->params.ht_spot.transfer_closure.proc =
141
 
        (transfer == 0 ? null_closure_transfer : transfer);
 
140
        (transfer == 0 ? null_closure_transfer : transfer);
142
141
    phtc->params.ht_spot.transfer_closure.data = client_data;
143
142
 
144
143
    return 0;
150
149
 */
151
150
int
152
151
gs_ht_set_threshold_comp(
153
 
                            gs_ht * pht,
154
 
                            int comp,
155
 
                            int width,
156
 
                            int height,
157
 
                            const gs_const_string * thresholds,
158
 
                            gs_ht_transfer_proc transfer,
159
 
                            const void *client_data
 
152
                            gs_ht * pht,
 
153
                            int comp,
 
154
                            int width,
 
155
                            int height,
 
156
                            const gs_const_string * thresholds,
 
157
                            gs_ht_transfer_proc transfer,
 
158
                            const void *client_data
160
159
)
161
160
{
162
161
    gs_ht_component *phtc = &(pht->params.ht_multiple.components[comp]);
163
162
 
164
163
    if (comp >= pht->params.ht_multiple.num_comp)
165
 
        return_error(gs_error_rangecheck);
 
164
        return_error(gs_error_rangecheck);
166
165
    if (phtc->type != ht_type_none)
167
 
        return_error(gs_error_invalidaccess);
 
166
        return_error(gs_error_invalidaccess);
168
167
 
169
168
    phtc->type = ht_type_threshold;
170
169
    phtc->params.ht_threshold.width = width;
173
172
    phtc->params.ht_threshold.transfer = gs_mapped_transfer;
174
173
 
175
174
    phtc->params.ht_threshold.transfer_closure.proc =
176
 
        (transfer == 0 ? null_closure_transfer : transfer);
 
175
        (transfer == 0 ? null_closure_transfer : transfer);
177
176
    phtc->params.ht_threshold.transfer_closure.data = client_data;
178
177
 
179
178
    return 0;
184
183
 */
185
184
void
186
185
gs_ht_reference(
187
 
                   gs_ht * pht
 
186
                   gs_ht * pht
188
187
)
189
188
{
190
189
    rc_increment(pht);
196
195
 */
197
196
void
198
197
gs_ht_release(
199
 
                 gs_ht * pht
 
198
                 gs_ht * pht
200
199
)
201
200
{
202
201
    rc_decrement_only(pht, "gs_ht_release");
203
202
}
204
203
 
205
 
 
206
204
/*
207
205
 *  Verify that a gs_ht halftone is legitimate.
208
206
 */
209
207
static int
210
208
check_ht(
211
 
            gs_ht * pht
 
209
            gs_ht * pht
212
210
)
213
211
{
214
212
    int i;
215
213
    int num_comps = pht->params.ht_multiple.num_comp;
216
214
 
217
215
    if (pht->type != ht_type_multiple)
218
 
        return_error(gs_error_unregistered);
 
216
        return_error(gs_error_unregistered);
219
217
    for (i = 0; i < num_comps; i++) {
220
 
        gs_ht_component *phtc = &(pht->params.ht_multiple.components[i]);
221
 
        if ((phtc->type != ht_type_spot) && (phtc->type != ht_type_threshold))
222
 
            return_error(gs_error_unregistered);
 
218
        gs_ht_component *phtc = &(pht->params.ht_multiple.components[i]);
 
219
        if ((phtc->type != ht_type_spot) && (phtc->type != ht_type_threshold))
 
220
            return_error(gs_error_unregistered);
223
221
    }
224
222
    return 0;
225
223
}
229
227
 */
230
228
static void
231
229
build_transfer_map(
232
 
                      gs_ht_component * phtc,
233
 
                      gx_transfer_map * pmap
 
230
                      gs_ht_component * phtc,
 
231
                      gx_transfer_map * pmap
234
232
)
235
233
{
236
234
    gs_ht_transfer_proc proc;
239
237
    frac *values = pmap->values;
240
238
 
241
239
    if (phtc->type == ht_type_spot) {
242
 
        proc = phtc->params.ht_spot.transfer_closure.proc;
243
 
        client_info = phtc->params.ht_spot.transfer_closure.data;
 
240
        proc = phtc->params.ht_spot.transfer_closure.proc;
 
241
        client_info = phtc->params.ht_spot.transfer_closure.data;
244
242
    } else {
245
 
        proc = phtc->params.ht_threshold.transfer_closure.proc;
246
 
        client_info = phtc->params.ht_threshold.transfer_closure.data;
 
243
        proc = phtc->params.ht_threshold.transfer_closure.proc;
 
244
        client_info = phtc->params.ht_threshold.transfer_closure.data;
247
245
    }
248
246
 
249
247
    for (i = 0; i < transfer_map_size; i++) {
250
 
        float fval =
251
 
            proc(i * (1 / (double)(transfer_map_size - 1)), pmap, client_info);
 
248
        float fval =
 
249
            proc(i * (1 / (double)(transfer_map_size - 1)), pmap, client_info);
252
250
 
253
 
        values[i] =
254
 
            (fval <= 0.0 ? frac_0 : fval >= 1.0 ? frac_1 :
255
 
             float2frac(fval));
 
251
        values[i] =
 
252
            (fval <= 0.0 ? frac_0 : fval >= 1.0 ? frac_1 :
 
253
             float2frac(fval));
256
254
    }
257
255
}
258
256
 
263
261
 */
264
262
static gx_ht_order_component *
265
263
alloc_ht_order(
266
 
                  const gs_ht * pht,
267
 
                  gs_memory_t * pmem,
268
 
                  byte * comp2order
 
264
                  const gs_ht * pht,
 
265
                  gs_memory_t * pmem,
 
266
                  byte * comp2order
269
267
)
270
268
{
271
269
    int num_comps = pht->params.ht_multiple.num_comp;
272
270
    gx_ht_order_component *pocs = gs_alloc_struct_array(
273
 
                                                           pmem,
274
 
                                           pht->params.ht_multiple.num_comp,
275
 
                                                      gx_ht_order_component,
276
 
                                             &st_ht_order_component_element,
277
 
                                                           "alloc_ht_order"
 
271
                                                           pmem,
 
272
                                           pht->params.ht_multiple.num_comp,
 
273
                                                      gx_ht_order_component,
 
274
                                             &st_ht_order_component_element,
 
275
                                                           "alloc_ht_order"
278
276
    );
279
277
    int inext = 0;
280
278
    int i;
281
279
 
282
280
    if (pocs == 0)
283
 
        return 0;
 
281
        return 0;
284
282
    pocs->corder.transfer = 0;
285
283
 
286
284
    for (i = 0; i < num_comps; i++) {
287
 
        gs_ht_component *phtc = &(pht->params.ht_multiple.components[i]);
288
 
        gx_transfer_map *pmap = gs_alloc_struct(pmem,
289
 
                                                gx_transfer_map,
290
 
                                                &st_transfer_map,
291
 
                                                "alloc_ht_order"
292
 
        );
293
 
 
294
 
        if (pmap == 0) {
295
 
            int j;
296
 
 
297
 
            for (j = 0; j < inext; j++)
298
 
                gs_free_object(pmem, pocs[j].corder.transfer, "alloc_ht_order");
299
 
            gs_free_object(pmem, pocs, "alloc_ht_order");
300
 
            return 0;
301
 
        }
302
 
        pmap->proc = gs_mapped_transfer;
303
 
        pmap->id = gs_next_ids(pmem, 1);
304
 
        pocs[inext].corder.levels = 0;
305
 
        pocs[inext].corder.bit_data = 0;
306
 
        pocs[inext].corder.cache = 0;
307
 
        pocs[inext].corder.transfer = pmap;
308
 
        pocs[inext].cname = phtc->cname;
 
285
        gs_ht_component *phtc = &(pht->params.ht_multiple.components[i]);
 
286
        gx_transfer_map *pmap = gs_alloc_struct(pmem,
 
287
                                                gx_transfer_map,
 
288
                                                &st_transfer_map,
 
289
                                                "alloc_ht_order"
 
290
        );
 
291
 
 
292
        if (pmap == 0) {
 
293
            int j;
 
294
 
 
295
            for (j = 0; j < inext; j++)
 
296
                gs_free_object(pmem, pocs[j].corder.transfer, "alloc_ht_order");
 
297
            gs_free_object(pmem, pocs, "alloc_ht_order");
 
298
            return 0;
 
299
        }
 
300
        pmap->proc = gs_mapped_transfer;
 
301
        pmap->id = gs_next_ids(pmem, 1);
 
302
        pocs[inext].corder.levels = 0;
 
303
        pocs[inext].corder.bit_data = 0;
 
304
        pocs[inext].corder.cache = 0;
 
305
        pocs[inext].corder.transfer = pmap;
 
306
        pocs[inext].cname = phtc->cname;
309
307
        pocs[inext].comp_number = phtc->comp_number;
310
 
        comp2order[i] = inext++;
 
308
        comp2order[i] = inext++;
311
309
    }
312
310
 
313
311
    return pocs;
318
316
 */
319
317
static int
320
318
build_component(
321
 
                   gs_ht_component * phtc,
322
 
                   gx_ht_order * porder,
323
 
                   gs_state * pgs,
324
 
                   gs_memory_t * pmem
 
319
                   gs_ht_component * phtc,
 
320
                   gx_ht_order * porder,
 
321
                   gs_state * pgs,
 
322
                   gs_memory_t * pmem
325
323
)
326
324
{
327
325
    if (phtc->type == ht_type_spot) {
328
 
        gs_screen_enum senum;
329
 
        int code;
330
 
 
331
 
        code = gx_ht_process_screen_memory(&senum,
332
 
                                           pgs,
333
 
                                           &phtc->params.ht_spot.screen,
334
 
                                      phtc->params.ht_spot.accurate_screens,
335
 
                                           pmem
336
 
            );
337
 
        if (code < 0)
338
 
            return code;
339
 
 
340
 
        /* avoid wiping out the transfer structure pointer */
341
 
        senum.order.transfer = porder->transfer;
342
 
        *porder = senum.order;
 
326
        gs_screen_enum senum;
 
327
        int code;
 
328
 
 
329
        code = gx_ht_process_screen_memory(&senum,
 
330
                                           pgs,
 
331
                                           &phtc->params.ht_spot.screen,
 
332
                                      phtc->params.ht_spot.accurate_screens,
 
333
                                           pmem
 
334
            );
 
335
        if (code < 0)
 
336
            return code;
 
337
 
 
338
        /* avoid wiping out the transfer structure pointer */
 
339
        senum.order.transfer = porder->transfer;
 
340
        *porder = senum.order;
343
341
 
344
342
    } else {                    /* ht_type_threshold */
345
 
        int code;
346
 
        gx_transfer_map *transfer = porder->transfer;
 
343
        int code;
 
344
        gx_transfer_map *transfer = porder->transfer;
347
345
 
348
 
        porder->params.M = phtc->params.ht_threshold.width;
349
 
        porder->params.N = 0;
350
 
        porder->params.R = 1;
351
 
        porder->params.M1 = phtc->params.ht_threshold.height;
352
 
        porder->params.N1 = 0;
353
 
        porder->params.R1 = 1;
354
 
        code = gx_ht_alloc_threshold_order(porder,
355
 
                                           phtc->params.ht_threshold.width,
356
 
                                           phtc->params.ht_threshold.height,
357
 
                                           256,
358
 
                                           pmem
359
 
            );
360
 
        if (code < 0)
361
 
            return code;
362
 
        gx_ht_construct_threshold_order(
363
 
                                porder,
364
 
                                phtc->params.ht_threshold.thresholds.data
365
 
            );
366
 
        /*
367
 
         * gx_ht_construct_threshold_order wipes out transfer map pointer,
368
 
         * restore it here.
369
 
         */
370
 
        porder->transfer = transfer;
 
346
        porder->params.M = phtc->params.ht_threshold.width;
 
347
        porder->params.N = 0;
 
348
        porder->params.R = 1;
 
349
        porder->params.M1 = phtc->params.ht_threshold.height;
 
350
        porder->params.N1 = 0;
 
351
        porder->params.R1 = 1;
 
352
        code = gx_ht_alloc_threshold_order(porder,
 
353
                                           phtc->params.ht_threshold.width,
 
354
                                           phtc->params.ht_threshold.height,
 
355
                                           256,
 
356
                                           pmem
 
357
            );
 
358
        if (code < 0)
 
359
            return code;
 
360
        gx_ht_construct_threshold_order(
 
361
                                porder,
 
362
                                phtc->params.ht_threshold.thresholds.data
 
363
            );
 
364
        /*
 
365
         * gx_ht_construct_threshold_order wipes out transfer map pointer,
 
366
         * restore it here.
 
367
         */
 
368
        porder->transfer = transfer;
371
369
    }
372
370
 
373
371
    build_transfer_map(phtc, porder->transfer);
379
377
 */
380
378
static void
381
379
free_order_array(
382
 
                    gx_ht_order_component * pocs,
383
 
                    int num_comps,
384
 
                    gs_memory_t * pmem
 
380
                    gx_ht_order_component * pocs,
 
381
                    int num_comps,
 
382
                    gs_memory_t * pmem
385
383
)
386
384
{
387
385
    int i;
388
386
 
389
387
    for (i = 0; i < num_comps; i++)
390
 
        gx_ht_order_release(&(pocs[i].corder), pmem, true);
 
388
        gx_ht_order_release(&(pocs[i].corder), pmem, true);
391
389
    gs_free_object(pmem, pocs, "gs_ht_install");
392
390
}
393
391
 
394
 
 
395
392
/*
396
393
 *  Install a gs_ht halftone as the current halftone in the graphic state.
397
394
 */
398
395
int
399
396
gs_ht_install(
400
 
                 gs_state * pgs,
401
 
                 gs_ht * pht
 
397
                 gs_state * pgs,
 
398
                 gs_ht * pht
402
399
)
403
400
{
404
401
    int code = 0;
411
408
 
412
409
    /* perform so sanity checks (must have one default component) */
413
410
    if ((code = check_ht(pht)) != 0)
414
 
        return code;
 
411
        return code;
415
412
 
416
413
    /* allocate the halftone order structure and transfer maps */
417
414
    if ((pocs = alloc_ht_order(pht, pmem, comp2order)) == 0)
418
 
        return_error(gs_error_VMerror);
 
415
        return_error(gs_error_VMerror);
419
416
 
420
417
    /* build all of the order for each component */
421
418
    for (i = 0; i < num_comps; i++) {
422
 
        int j = comp2order[i];
423
 
 
424
 
        code = build_component(&(pht->params.ht_multiple.components[i]),
425
 
                               &(pocs[j].corder),
426
 
                               pgs,
427
 
                               pmem
428
 
            );
429
 
 
430
 
        if ((code >= 0) && (j != 0)) {
431
 
            gx_ht_cache *pcache;
432
 
 
433
 
            pcache = gx_ht_alloc_cache(pmem,
434
 
                                       4,
435
 
                                       pocs[j].corder.raster *
436
 
                                       (pocs[j].corder.num_bits /
437
 
                                        pocs[j].corder.width) * 4
438
 
                );
439
 
 
440
 
            if (pcache == 0)
441
 
                code = gs_note_error(gs_error_VMerror);
442
 
            else {
443
 
                pocs[j].corder.cache = pcache;
444
 
                gx_ht_init_cache(pmem, pcache, &(pocs[j].corder));
445
 
            }
446
 
        }
447
 
        if (code < 0)
448
 
            break;
 
419
        int j = comp2order[i];
 
420
 
 
421
        code = build_component(&(pht->params.ht_multiple.components[i]),
 
422
                               &(pocs[j].corder),
 
423
                               pgs,
 
424
                               pmem
 
425
            );
 
426
 
 
427
        if ((code >= 0) && (j != 0)) {
 
428
            gx_ht_cache *pcache;
 
429
 
 
430
            pcache = gx_ht_alloc_cache(pmem,
 
431
                                       4,
 
432
                                       pocs[j].corder.raster *
 
433
                                       (pocs[j].corder.num_bits /
 
434
                                        pocs[j].corder.width) * 4
 
435
                );
 
436
 
 
437
            if (pcache == 0)
 
438
                code = gs_note_error(gs_error_VMerror);
 
439
            else {
 
440
                pocs[j].corder.cache = pcache;
 
441
                gx_ht_init_cache(pmem, pcache, &(pocs[j].corder));
 
442
            }
 
443
        }
 
444
        if (code < 0)
 
445
            break;
449
446
    }
450
447
 
451
448
    if (code < 0) {
452
 
        free_order_array(pocs, num_comps, pmem);
453
 
        return code;
 
449
        free_order_array(pocs, num_comps, pmem);
 
450
        return code;
454
451
    }
455
452
    /* initialize the device halftone structure */
456
453
    dev_ht.rc.memory = pmem;
457
454
    dev_ht.order = pocs[0].corder;      /* Default */
458
455
    if (num_comps == 1) {
459
 
        /* we have only a Default; we don't need components. */
460
 
        gs_free_object(pmem, pocs, "gs_ht_install");
461
 
        dev_ht.components = 0;
 
456
        /* we have only a Default; we don't need components. */
 
457
        gs_free_object(pmem, pocs, "gs_ht_install");
 
458
        dev_ht.components = 0;
462
459
    } else {
463
 
        dev_ht.components = pocs;
464
 
        dev_ht.num_comp = num_comps;
 
460
        dev_ht.components = pocs;
 
461
        dev_ht.num_comp = num_comps;
465
462
    }
466
463
 
467
464
    /* at last, actually install the halftone in the graphic state */
479
476
 */
480
477
static int
481
478
create_mask_bits(const byte * mask1, const byte * mask2,
482
 
                 int width, int height, gx_ht_bit * bits)
 
479
                 int width, int height, gx_ht_bit * bits)
483
480
{
484
481
    /*
485
482
     * We do this with the slowest, simplest possible algorithm....
489
486
    int count = 0;
490
487
 
491
488
    for (y = 0; y < height; ++y)
492
 
        for (x = 0; x < width; ++x) {
493
 
            int offset = y * width_bytes + (x >> 3);
494
 
            byte bit_mask = 0x80 >> (x & 7);
 
489
        for (x = 0; x < width; ++x) {
 
490
            int offset = y * width_bytes + (x >> 3);
 
491
            byte bit_mask = 0x80 >> (x & 7);
495
492
 
496
 
            if ((mask1[offset] ^ mask2[offset]) & bit_mask) {
497
 
                if (bits)
498
 
                    gx_ht_construct_bit(&bits[count], width, y * width + x);
499
 
                ++count;
500
 
            }
501
 
        }
 
493
            if ((mask1[offset] ^ mask2[offset]) & bit_mask) {
 
494
                if (bits)
 
495
                    gx_ht_construct_bit(&bits[count], width, y * width + x);
 
496
                ++count;
 
497
            }
 
498
        }
502
499
    return count;
503
500
}
504
501
static int
505
502
create_mask_order(gx_ht_order * porder, gs_state * pgs,
506
 
                  const gs_client_order_halftone * phcop,
507
 
                  gs_memory_t * mem)
 
503
                  const gs_client_order_halftone * phcop,
 
504
                  gs_memory_t * mem)
508
505
{
509
506
    int width_bytes = (phcop->width + 7) >> 3;
510
507
    const byte *masks = (const byte *)phcop->client_data;
517
514
 
518
515
    /* Do a first pass to compute how many bits entries will be needed. */
519
516
    for (prev_mask = masks, num_bits = 0, i = 0;
520
 
         i < num_levels - 1;
521
 
         ++i, prev_mask += bytes_per_mask
522
 
        )
523
 
        num_bits += create_mask_bits(prev_mask, prev_mask + bytes_per_mask,
524
 
                                     phcop->width, phcop->height, NULL);
 
517
         i < num_levels - 1;
 
518
         ++i, prev_mask += bytes_per_mask
 
519
        )
 
520
        num_bits += create_mask_bits(prev_mask, prev_mask + bytes_per_mask,
 
521
                                     phcop->width, phcop->height, NULL);
525
522
    code = gx_ht_alloc_client_order(porder, phcop->width, phcop->height,
526
 
                                    num_levels, num_bits, mem);
 
523
                                    num_levels, num_bits, mem);
527
524
    if (code < 0)
528
 
        return code;
 
525
        return code;
529
526
    /* Fill in the bits and levels entries. */
530
527
    for (prev_mask = masks, num_bits = 0, i = 0;
531
 
         i < num_levels - 1;
532
 
         ++i, prev_mask += bytes_per_mask
533
 
        ) {
534
 
        porder->levels[i] = num_bits;
535
 
        num_bits += create_mask_bits(prev_mask, prev_mask + bytes_per_mask,
536
 
                                     phcop->width, phcop->height,
537
 
                                     ((gx_ht_bit *)porder->bit_data) +
538
 
                                      num_bits);
 
528
         i < num_levels - 1;
 
529
         ++i, prev_mask += bytes_per_mask
 
530
        ) {
 
531
        porder->levels[i] = num_bits;
 
532
        num_bits += create_mask_bits(prev_mask, prev_mask + bytes_per_mask,
 
533
                                     phcop->width, phcop->height,
 
534
                                     ((gx_ht_bit *)porder->bit_data) +
 
535
                                      num_bits);
539
536
    }
540
537
    porder->levels[num_levels - 1] = num_bits;
541
538
    return 0;
554
551
 */
555
552
int
556
553
gs_ht_set_mask_comp(gs_ht * pht,
557
 
                    int component_index,
558
 
                    int width, int height, int num_levels,
559
 
                    const byte * masks,         /* width x height x num_levels bits */
560
 
                    gs_ht_transfer_proc transfer,
561
 
                    const void *client_data)
 
554
                    int component_index,
 
555
                    int width, int height, int num_levels,
 
556
                    const byte * masks,         /* width x height x num_levels bits */
 
557
                    gs_ht_transfer_proc transfer,
 
558
                    const void *client_data)
562
559
{
563
560
    gs_ht_component *phtc =
564
561
    &(pht->params.ht_multiple.components[component_index]);
565
562
 
566
563
    if (component_index >= pht->params.ht_multiple.num_comp)
567
 
        return_error(gs_error_rangecheck);
 
564
        return_error(gs_error_rangecheck);
568
565
    if (phtc->type != ht_type_none)
569
 
        return_error(gs_error_invalidaccess);
 
566
        return_error(gs_error_invalidaccess);
570
567
 
571
568
    phtc->type = ht_type_client_order;
572
569
    phtc->params.client_order.width = width;
575
572
    phtc->params.client_order.procs = &mask_order_procs;
576
573
    phtc->params.client_order.client_data = masks;
577
574
    phtc->params.client_order.transfer_closure.proc =
578
 
        (transfer == 0 ? null_closure_transfer : transfer);
 
575
        (transfer == 0 ? null_closure_transfer : transfer);
579
576
    phtc->params.client_order.transfer_closure.data = client_data;
580
577
 
581
578
    return 0;