File: zht1.c

package info (click to toggle)
ghostscript 8.71~dfsg2-9+squeeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 79,896 kB
  • ctags: 80,654
  • sloc: ansic: 501,432; sh: 25,689; python: 4,853; cpp: 3,633; perl: 3,597; tcl: 1,480; makefile: 1,187; lisp: 407; asm: 284; xml: 263; awk: 66; csh: 17; yacc: 15
file content (176 lines) | stat: -rw-r--r-- 5,092 bytes parent folder | download | duplicates (2)
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
/* Copyright (C) 2001-2006 Artifex Software, Inc.
   All Rights Reserved.
  
   This software is provided AS-IS with no warranty, either express or
   implied.

   This software is distributed under license and may not be copied, modified
   or distributed except as expressly authorized under the terms of that
   license.  Refer to licensing information at http://www.artifex.com/
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
*/

/* $Id: zht1.c 10454 2009-12-06 00:56:38Z alexcher $ */
/* setcolorscreen operator */
#include "ghost.h"
#include "memory_.h"
#include "oper.h"
#include "estack.h"
#include "gsstruct.h"		/* must precede igstate.h, */
					/* because of #ifdef in gsht.h */
#include "ialloc.h"
#include "igstate.h"
#include "gsmatrix.h"
#include "gxdevice.h"		/* for gzht.h */
#include "gzht.h"
#include "gsstate.h"
#include "iht.h"
#include "store.h"

/* Dummy spot function */
static float
spot_dummy(floatp x, floatp y)
{
    return (x + y) / 2;
}

/* <red_freq> ... <gray_proc> setcolorscreen - */
static int setcolorscreen_finish(i_ctx_t *);
static int setcolorscreen_cleanup(i_ctx_t *);
static int
zsetcolorscreen_aux(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gs_colorscreen_halftone cscreen;
    ref sprocs[4];
    gs_halftone *pht;
    gx_device_halftone *pdht;
    int i;
    int code = 0;
    int space = 0;
    gs_memory_t *mem;

    for (i = 0; i < 4; i++) {
	os_ptr op1 = op - 9 + i * 3;
	int code = zscreen_params(op1, &cscreen.screens.indexed[i]);

	if (code < 0)
	    return code;
	cscreen.screens.indexed[i].spot_function = spot_dummy;
	sprocs[i] = *op1;
	space = max(space, r_space_index(op1));
    }
    mem = (gs_memory_t *)idmemory->spaces_indexed[space];
    check_estack(8);		/* for sampling screens */
    rc_alloc_struct_0(pht, gs_halftone, &st_halftone,
		      mem, pht = 0, "setcolorscreen(halftone)");
    rc_alloc_struct_0(pdht, gx_device_halftone, &st_device_halftone,
		      mem, pdht = 0, "setcolorscreen(device halftone)");
    if (pht == 0 || pdht == 0)
	code = gs_note_error(e_VMerror);
    else {
	pht->type = ht_type_colorscreen;
	pht->params.colorscreen = cscreen;
	code = gs_sethalftone_prepare(igs, pht, pdht);
    }
    if (code >= 0) {		/* Schedule the sampling of the screens. */
	es_ptr esp0 = esp;	/* for backing out */

	esp += 8;
	make_mark_estack(esp - 7, es_other, setcolorscreen_cleanup);
	memcpy(esp - 6, sprocs, sizeof(ref) * 4);	/* procs */
	make_istruct(esp - 2, 0, pht);
	make_istruct(esp - 1, 0, pdht);
	make_op_estack(esp, setcolorscreen_finish);
	for (i = 0; i < 4; i++) {
	    /* Shuffle the indices to correspond to */
	    /* the component order. */
	    code = zscreen_enum_init(i_ctx_p,
				     &pdht->components[(i + 1) & 3].corder,
				&pht->params.colorscreen.screens.indexed[i],
				     &sprocs[i], 0, 0, space);
	    if (code < 0) {
		esp = esp0;
		break;
	    }
	}
    }
    if (code < 0) {
	gs_free_object(mem, pdht, "setcolorscreen(device halftone)");
	gs_free_object(mem, pht, "setcolorscreen(halftone)");
	return code;
    }
    pop(12);
    return o_push_estack;
}
/* Install the color screen after sampling. */
static int
setcolorscreen_finish(i_ctx_t *i_ctx_p)
{
    gx_device_halftone *pdht = r_ptr(esp, gx_device_halftone);
    int code;

    pdht->order = pdht->components[0].corder;
    code = gx_ht_install(igs, r_ptr(esp - 1, gs_halftone), pdht);
    if (code < 0)
	return code;
    istate->screen_procs.red   = esp[-5];
    istate->screen_procs.green = esp[-4];
    istate->screen_procs.blue  = esp[-3];
    istate->screen_procs.gray  = esp[-2];
    make_null(&istate->halftone);
    esp -= 7;
    setcolorscreen_cleanup(i_ctx_p);
    return o_pop_estack;
}
/* Clean up after installing the color screen. */
static int
setcolorscreen_cleanup(i_ctx_t *i_ctx_p)
{
    gs_halftone *pht = r_ptr(esp + 6, gs_halftone);
    gx_device_halftone *pdht = r_ptr(esp + 7, gx_device_halftone);

    gs_free_object(pdht->rc.memory, pdht,
		   "setcolorscreen_cleanup(device halftone)");
    gs_free_object(pht->rc.memory, pht,
		   "setcolorscreen_cleanup(halftone)");
    return 0;
}

extern int zswapcolors(i_ctx_t *i_ctx_p);

static int
zsetcolorscreen(i_ctx_t *i_ctx_p)
{
    check_ostack(12);
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    osp++; *osp = osp[-12];
    check_estack(4);
    esp += 4;
    make_op_estack(esp-3, zsetcolorscreen_aux);
    make_op_estack(esp-2, zswapcolors);
    make_op_estack(esp-1, zsetcolorscreen_aux);
    make_op_estack(esp,   zswapcolors);
    return o_push_estack;
}

/* ------ Initialization procedure ------ */

const op_def zht1_op_defs[] =
{
    {"<setcolorscreen", zsetcolorscreen},
		/* Internal operators */
    {"0%setcolorscreen_finish", setcolorscreen_finish},
    op_def_end(0)
};