1
/* $Xorg: pdither.c,v 1.4 2001/02/09 02:04:22 xorgcvs Exp $ */
2
/**** module pdither.c ****/
3
/******************************************************************************
5
Copyright 1993, 1994, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
30
This software is being provided by AGE Logic, Inc. under the
31
following license. By obtaining, using and/or copying this software,
32
you agree that you have read, understood, and will comply with these
35
Permission to use, copy, modify, distribute and sell this
36
software and its documentation for any purpose and without
37
fee or royalty and to grant others any or all rights granted
38
herein is hereby granted, provided that you agree to comply
39
with the following copyright notice and statements, including
40
the disclaimer, and that the same appears on all copies and
41
derivative works of the software and documentation you make.
43
"Copyright 1993, 1994 by AGE Logic, Inc."
45
THIS SOFTWARE IS PROVIDED "AS IS". AGE LOGIC MAKES NO
46
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way of
47
example, but not limitation, AGE LOGIC MAKE NO
48
REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
49
FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
50
INFRINGE THIRD-PARTY PROPRIETARY RIGHTS. AGE LOGIC
51
SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE. IN NO
52
EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
53
INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
54
OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
55
ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
56
BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
57
HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
60
The name of AGE Logic, Inc. may not be used in
61
advertising or publicity pertaining to this software without
62
specific, written prior permission from AGE Logic.
64
Title to this software shall at all times remain with AGE
66
*****************************************************************************
68
pdither.c -- DIXIE routines for managing the Dither element
70
Larry Hare -- AGE Logic, Inc. May 1993
72
*****************************************************************************/
73
/* $XFree86: xc/programs/Xserver/XIE/dixie/process/pdither.c,v 3.5 2001/12/14 19:58:05 dawes Exp $ */
102
* routines internal to this module
104
static Bool PrepPDither(floDefPtr flo, peDefPtr ped);
105
static Bool PrepPDitherStandard(floDefPtr flo, peDefPtr ped, pointer raw, pointer tec);
108
* dixie element entry points
110
static diElemVecRec pDitherVec = {
111
PrepPDither /* prepare for analysis and execution */
114
/*------------------------------------------------------------------------
115
-------------------- routine: make a dither element ------------------
116
------------------------------------------------------------------------*/
117
peDefPtr MakeDither(floDefPtr flo, xieTypPhototag tag, xieFlo *pe)
120
ELEMENT(xieFloDither);
121
ELEMENT_AT_LEAST_SIZE(xieFloDither);
122
ELEMENT_NEEDS_1_INPUT(src);
124
if(!(ped = MakePEDef(1, (CARD32)stuff->elemLength<<2, 0)))
125
FloAllocError(flo,tag,xieElemDither, return(NULL)) ;
127
ped->diVec = &pDitherVec;
129
ped->flags.process = TRUE;
130
raw = (xieFloDither *)ped->elemRaw;
132
* copy the client element parameters (swap if necessary)
134
if( flo->reqClient->swapped ) {
135
raw->elemType = stuff->elemType;
136
raw->elemLength = stuff->elemLength;
137
cpswaps(stuff->src, raw->src);
138
raw->bandMask = stuff->bandMask;
139
cpswapl(stuff->levels0, raw->levels0);
140
cpswapl(stuff->levels1, raw->levels1);
141
cpswapl(stuff->levels2, raw->levels2);
142
cpswaps(stuff->lenParams, raw->lenParams);
143
cpswaps(stuff->dither, raw->dither);
146
memcpy((char *)raw, (char *)stuff, sizeof(xieFloDither));
148
* copy technique data (if any)
150
if(!(ped->techVec = FindTechnique(xieValDither, raw->dither)) ||
151
!(ped->techVec->copyfnc(flo, ped, &stuff[1], &raw[1], raw->lenParams,
152
raw->dither == xieValDefault)))
153
TechniqueError(flo,ped,xieValDither,raw->dither,raw->lenParams,
157
* assign phototag to inFlo
159
ped->inFloLst[SRCtag].srcTag = raw->src;
163
} /* end MakePDither */
165
/*------------------------------------------------------------------------
166
---------------- routine: copy routine for no Error Diffusion technique --
167
------------------------------------------------------------------------*/
169
Bool CopyPDitherErrorDiffusion(TECHNQ_COPY_ARGS)
171
VALIDATE_TECHNIQUE_SIZE(ped->techVec, tsize, isDefault);
176
/*------------------------------------------------------------------------
177
---------------- routine: copy routine for Ordered techniques ---------
178
------------------------------------------------------------------------*/
181
#define sparms ((xieTecDitherOrdered *)sParms)
183
#define rparms ((xieTecDitherOrdered *)rParms)
185
Bool CopyPDitherOrdered(TECHNQ_COPY_ARGS)
187
VALIDATE_TECHNIQUE_SIZE(ped->techVec, tsize, isDefault);
190
rparms->thresholdOrder = sparms->thresholdOrder;
192
rparms->thresholdOrder = 4;
197
/*------------------------------------------------------------------------
198
---------------- routine: prep routine for no param techniques -------------
199
------------------------------------------------------------------------*/
201
Bool PrepPDitherStandard(
210
/*------------------------------------------------------------------------
211
---------------- routine: prep routine for Error Diffusion techniques ----
212
------------------------------------------------------------------------*/
213
Bool PrepPDitherErrorDiffusion(
219
return PrepPDitherStandard(flo, ped, (pointer) raw, tec);
222
/*------------------------------------------------------------------------
223
---------------- routine: prep routine for Ordered technique -------------
224
------------------------------------------------------------------------*/
225
Bool PrepPDitherOrdered(
229
xieTecDitherOrdered *tec)
231
return PrepPDitherStandard(flo, ped, (pointer) raw, (pointer) tec);
234
/*------------------------------------------------------------------------
235
---------------- routine: prepare for analysis and execution -------------
236
------------------------------------------------------------------------*/
238
static Bool PrepPDither(floDefPtr flo, peDefPtr ped)
240
inFloPtr inf = &ped->inFloLst[SRCtag];
241
outFloPtr src = &inf->srcDef->outFlo;
242
outFloPtr dst = &ped->outFlo;
243
xieFloDither *raw = (xieFloDither *)ped->elemRaw;
244
CARD32 *levels = &(raw->levels0);
247
/* grab a copy of the src attributes and propagate them to our input */
248
dst->bands = inf->bands = src->bands;
249
for(b = 0; b < src->bands; b++) {
251
dst->format[b] = inf->format[b] = src->format[b];
253
if ((raw->bandMask & (1<<b)) == 0)
256
if (IsntConstrained(src->format[b].class) &&
257
src->format[b].class == BIT_PIXEL)
258
MatchError(flo, ped, return(FALSE));
260
if ((dst->format[b].levels = *(levels+b)) > src->format[b].levels)
261
ValueError(flo,ped,*(levels+b),return(FALSE));
264
/* Set depth, class, stride, and pitch */
265
if (UpdateFormatfromLevels(ped) == FALSE)
266
MatchError(flo,ped, return(FALSE));
268
/* Take care of any technique parameters */
269
if (!(ped->techVec->prepfnc(flo, ped, raw, &raw[1])))
270
TechniqueError(flo,ped,xieValDither,raw->dither,raw->lenParams,
276
/* end module pdither.c */