1
/* $Xorg: pgeom.c,v 1.4 2001/02/09 02:04:22 xorgcvs Exp $ */
2
/**** module pgeom.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
pgeom.c -- DIXIE routines for managing the Geometry element
70
Ben Fahy -- AGE Logic, Inc. June 1993
72
*****************************************************************************/
73
/* $XFree86: xc/programs/Xserver/XIE/dixie/process/pgeom.c,v 3.6 2001/12/14 19:58:05 dawes Exp $ */
102
* routines internal to this module
104
static Bool PrepGeometry(
107
static Bool CopyGeomNoParams(TECHNQ_COPY_ARGS);
112
static diElemVecRec pGeometryVec = {
113
PrepGeometry /* prepare for analysis and execution */
116
/*------------------------------------------------------------------------
117
----------------------- routine: make a convolution element --------------
118
------------------------------------------------------------------------*/
119
peDefPtr MakeGeometry(floDefPtr flo, xieTypPhototag tag, xieFlo *pe)
127
ELEMENT(xieFloGeometry);
128
ELEMENT_AT_LEAST_SIZE(xieFloGeometry);
129
ELEMENT_NEEDS_1_INPUT(src);
133
if(!(ped = MakePEDef(inputs, (CARD32)stuff->elemLength<<2,
134
sizeof(pGeomDefRec))))
135
FloAllocError(flo, tag, xieElemGeometry, return(NULL));
137
ped->diVec = &pGeometryVec;
139
ped->flags.process = TRUE;
140
raw = (xieFloGeometry *)ped->elemRaw;
142
* copy the client element parameters (swap if necessary)
144
if( flo->reqClient->swapped ) {
145
raw->elemType = stuff->elemType;
146
raw->elemLength = stuff->elemLength;
147
cpswaps(stuff->src, raw->src);
148
raw->bandMask = stuff->bandMask;
149
cpswapl(stuff->width, raw->width);
150
cpswapl(stuff->height, raw->height);
151
cpswaps(stuff->sample, raw->sample);
152
cpswaps(stuff->lenParams, raw->lenParams);
155
memcpy((char *)raw, (char *)stuff, sizeof(xieFloGeometry));
157
/* Copy over and convert the floating point stuff */
158
kptr = (xieTypFloat *)&stuff->a;
159
pvt = (pGeomDefPtr)ped->elemPvt;
161
if (flo->reqClient->swapped) {
162
for (i = 0; i < 6; ++kptr, ++i)
163
pvt->coeffs[i] = ConvertFromIEEE(lswapl(*kptr));
164
for (i = 0; i < xieValMaxBands; ++kptr, ++i)
165
pvt->constant[i] = ConvertFromIEEE(lswapl(*kptr));
167
for (i = 0; i < 6; i++)
168
pvt->coeffs[i] = ConvertFromIEEE(*kptr++);
169
for (i = 0; i < xieValMaxBands; i++)
170
pvt->constant[i] = ConvertFromIEEE(*kptr++);
173
* copy technique data (if any)
175
if(!(ped->techVec = FindTechnique(xieValGeometry, raw->sample)) ||
176
!(ped->techVec->copyfnc(flo, ped, &stuff[1], &raw[1], raw->lenParams,
177
raw->sample == xieValDefault)))
178
TechniqueError(flo,ped,xieValGeometry,raw->sample,raw->lenParams,
182
* assign phototags to inFlos
184
inFlo = ped->inFloLst;
185
inFlo[SRCtag].srcTag = raw->src;
188
} /* end MakeGeometry */
190
/*------------------------------------------------------------------------
191
----------- routine: copy routine for NearestNeighbor technique ---------
192
------------------------------------------------------------------------*/
195
#define sparms ((xieTecGeomNearestNeighbor *)sParms)
197
#define rparms ((xieTecGeomNearestNeighbor *)rParms)
199
Bool CopyGeomNearestNeighbor(TECHNQ_COPY_ARGS)
201
pTecGeomNearestNeighborDefPtr pvt;
203
VALIDATE_TECHNIQUE_SIZE(ped->techVec, tsize, isDefault);
205
if (!(ped->techPvt = XieMalloc(sizeof(pTecGeomNearestNeighborDefRec))))
206
FloAllocError(flo, ped->phototag, xieElemGeometry, return(TRUE));
208
pvt = (pTecGeomNearestNeighborDefPtr)ped->techPvt;
211
* Nearest Neighbor can be called with no parameters
214
pvt->modify = xieValFavorUp;
216
pvt->modify = sparms->modify;
222
/*------------------------------------------------------------------------
223
------ routine: copy routine for bilinear interpolation technique --------
224
------------------------------------------------------------------------*/
225
Bool CopyGeomBilinearInterp(TECHNQ_COPY_ARGS)
227
VALIDATE_TECHNIQUE_SIZE(ped->techVec, tsize, isDefault);
229
return( CopyGeomNoParams(flo, ped, sparms, rparms, tsize, isDefault) );
231
/*------------------------------------------------------------------------
232
------ routine: copy routine for gaussian interpolation technique --------
233
------------------------------------------------------------------------*/
236
#define sparms ((xieTecGeomGaussian *)sParms)
238
#define rparms ((xieTecGeomGaussian *)rParms)
240
Bool CopyGeomGaussian(TECHNQ_COPY_ARGS)
242
pTecGeomGaussianDefPtr pvt;
244
VALIDATE_TECHNIQUE_SIZE(ped->techVec, tsize, isDefault);
246
if (!(ped->techPvt=XieMalloc(sizeof(pTecGeomGaussianDefRec))))
247
FloAllocError(flo, ped->phototag, xieElemGeometry, return(TRUE));
249
pvt = (pTecGeomGaussianDefPtr)ped->techPvt;
251
if( flo->reqClient->swapped ) {
252
pvt->sigma = ConvertFromIEEE(lswapl(sparms->sigma));
253
pvt->normalize = ConvertFromIEEE(lswapl(sparms->normalize));
255
pvt->sigma = ConvertFromIEEE(sparms->sigma);
256
pvt->normalize = ConvertFromIEEE(sparms->normalize);
258
pvt->radius = sparms->radius;
259
pvt->simple = sparms->simple;
264
if (pvt->sigma == 0.0)
265
return(FALSE); /* musn't divide by zero, deary */
267
if (pvt->normalize <= 0.0)
268
return(FALSE); /* don't want to bother clipping pixels < 0 */
274
/*------------------------------------------------------------------------
275
------ routine: copy routine for antialias technique --------
276
------------------------------------------------------------------------*/
278
Bool CopyGeomAntiAlias(TECHNQ_COPY_ARGS)
280
VALIDATE_TECHNIQUE_SIZE(ped->techVec, tsize, isDefault);
282
return( CopyGeomNoParams(flo, ped, sparms, rparms, tsize, isDefault) );
285
/*------------------------------------------------------------------------
286
------------ routine: copy routine for techniques with no params --------
287
------------------------------------------------------------------------*/
292
static Bool CopyGeomNoParams(TECHNQ_COPY_ARGS)
297
/*------------------------------------------------------------------------
298
---------------- routine: prepare for analysis and execution -------------
299
------------------------------------------------------------------------*/
300
static Bool PrepGeometry(floDefPtr flo, peDefPtr ped)
302
xieFloGeometry *raw = (xieFloGeometry *)ped->elemRaw;
303
inFloPtr in = &ped->inFloLst[SRCtag];
304
outFloPtr src = &in->srcDef->outFlo;
305
outFloPtr dst = &ped->outFlo;
306
pGeomDefPtr pvt = (pGeomDefPtr)ped->elemPvt;
309
/* grab a copy of the input attributes and propagate them to our output */
310
dst->bands = in->bands = src->bands;
312
for(b = 0; b < dst->bands; b++) {
313
if (IsntCanonic(src->format[b].class))
314
MatchError(flo, ped, return(FALSE));
316
dst->format[b] = in->format[b] = src->format[b];
317
pvt->do_band[b] = (dst->bands==1)? 1 : raw->bandMask & (1<<b);
318
if (pvt->do_band[b]) {
319
dst->format[b].width = raw->width;
320
dst->format[b].height = raw->height;
322
bits = dst->format[b].width * dst->format[b].stride;
323
dst->format[b].pitch = bits + Align(bits,PITCH_MOD);
326
if(!(ped->techVec->prepfnc(flo, ped, raw, &raw[1]))) {
327
TechniqueError(flo,ped,xieValGeometry,raw->sample,raw->lenParams,
332
} /* end PrepGeometry */
334
/*------------------------------------------------------------------------
335
---------------- routine: prep routine for nearest neighbor --------------
336
------------------------------------------------------------------------*/
337
Bool PrepGeomNearestNeighbor(
347
/*------------------------------------------------------------------------
348
---------- routine: prep routine for bilinear interpolation --------------
349
------------------------------------------------------------------------*/
350
Bool PrepGeomBilinearInterp(
358
/*------------------------------------------------------------------------
359
---------- routine: prep routine for gaussian ----------------------------
360
------------------------------------------------------------------------*/
361
Bool PrepGeomGaussian(
371
/*------------------------------------------------------------------------
372
---------- routine: prep routine for antialias ---------------------------
373
------------------------------------------------------------------------*/
374
Bool PrepGeomAntiAlias(
383
/* end module pgeom.c */