1
/* $Xorg: mpcnst.c,v 1.4 2001/02/09 02:04:30 xorgcvs Exp $ */
2
/* AGE Logic - Oct 15 1995 - Larry Hare */
3
/**** module mpcnst.c ****/
4
/******************************************************************************
6
Copyright 1993, 1994, 1998 The Open Group
8
Permission to use, copy, modify, distribute, and sell this software and its
9
documentation for any purpose is hereby granted without fee, provided that
10
the above copyright notice appear in all copies and that both that
11
copyright notice and this permission notice appear in supporting
14
The above copyright notice and this permission notice shall be included in
15
all copies or substantial portions of the Software.
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
Except as contained in this notice, the name of The Open Group shall not be
25
used in advertising or otherwise to promote the sale, use or other dealings
26
in this Software without prior written authorization from The Open Group.
31
This software is being provided by AGE Logic, Inc. under the
32
following license. By obtaining, using and/or copying this software,
33
you agree that you have read, understood, and will comply with these
36
Permission to use, copy, modify, distribute and sell this
37
software and its documentation for any purpose and without
38
fee or royalty and to grant others any or all rights granted
39
herein is hereby granted, provided that you agree to comply
40
with the following copyright notice and statements, including
41
the disclaimer, and that the same appears on all copies and
42
derivative works of the software and documentation you make.
44
"Copyright 1993, 1994 by AGE Logic, Inc."
46
THIS SOFTWARE IS PROVIDED "AS IS". AGE LOGIC MAKES NO
47
REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way of
48
example, but not limitation, AGE LOGIC MAKE NO
49
REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
50
FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
51
INFRINGE THIRD-PARTY PROPRIETARY RIGHTS. AGE LOGIC
52
SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE. IN NO
53
EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
54
INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
55
OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
56
ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
57
BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
58
HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
61
The name of AGE Logic, Inc. may not be used in
62
advertising or publicity pertaining to this software without
63
specific, written prior permission from AGE Logic.
65
Title to this software shall at all times remain with AGE
67
*****************************************************************************
69
mpcnst.c -- DDXIE constrain element
71
Dean Verheiden && Larry Hare -- AGE Logic, Inc. May, 1993
73
*****************************************************************************/
74
/* $XFree86: xc/programs/Xserver/XIE/mixie/process/mpcnst.c,v 3.5 2001/12/14 19:58:44 dawes Exp $ */
95
* more X server includes.
98
#include <dixstruct.h>
100
* Server XIE Includes
110
* routines referenced by other DDXIE modules
112
int miAnalyzeConstrain();
115
* routines used internal to this module
117
static int CreateConstrain();
118
static int InitializeConstrain();
119
static int ActivateConstrain();
120
static int ResetConstrain();
121
static int DestroyConstrain();
124
* DDXIE ImportClientPhoto entry points
126
static ddElemVecRec ConstrainVec = {
136
/*------------------------------------------------------------------------
137
------------------------ Local declares and defines --------------------
138
------------------------------------------------------------------------*/
140
typedef struct _mpconstraindef {
144
} mpCnstPvtRec, *mpCnstPvtPtr;
147
static void (*hc_nop())();
148
static void (*HCp_Rb())(), (*HCp_bb())(), (*HCp_Bb())(),
149
(*HCp_Pb())(), (*HCp_Qb())();
150
static void (*HCp_RB())(), (*HCp_bB())(), (*HCp_BB())(),
151
(*HCp_PB())(), (*HCp_QB())();
152
static void (*HCp_RP())(), (*HCp_bP())(), (*HCp_BP())(),
153
(*HCp_PP())(), (*HCp_QP())();
154
static void (*HCp_RQ())(), (*HCp_bQ())(), (*HCp_BQ())(),
155
(*HCp_PQ())(), (*HCp_QQ())();
157
static void (*(*prep_hc[5][5])())() = {
158
hc_nop, hc_nop, hc_nop, hc_nop, hc_nop, /* [out=0][inp=0...4] */
159
HCp_Rb, HCp_bb, HCp_Bb, HCp_Pb, HCp_Qb, /* [out=1][inp=0...4] */
160
HCp_RB, HCp_bB, HCp_BB, HCp_PB, HCp_QB, /* [out=2][inp=0...4] */
161
HCp_RP, HCp_bP, HCp_BP, HCp_PP, HCp_QP, /* [out=3][inp=0...4] */
162
HCp_RQ, HCp_bQ, HCp_BQ, HCp_PQ, HCp_QQ, /* [out=4][inp=0...4] */
165
static void (*cs_nop())();
166
static void (*CSp_Rb())(), (*CSp_bb())(), (*CSp_Bb())(),
167
(*CSp_Pb())(), (*CSp_Qb())();
168
static void (*CSp_RB())(), (*CSp_bB())(), (*CSp_BB())(),
169
(*CSp_PB())(), (*CSp_QB())();
170
static void (*CSp_RP())(), (*CSp_bP())(), (*CSp_BP())(),
171
(*CSp_PP())(), (*CSp_QP())();
172
static void (*CSp_RQ())(), (*CSp_bQ())(), (*CSp_BQ())(),
173
(*CSp_PQ())(), (*CSp_QQ())();
175
static void (*(*prep_cs[5][5])())() = {
176
cs_nop, cs_nop, cs_nop, cs_nop, cs_nop, /* [0][0...4] */
177
CSp_Rb, CSp_bb, CSp_Bb, CSp_Pb, CSp_Qb, /* [1][0...4] */
178
CSp_RB, CSp_bB, CSp_BB, CSp_PB, CSp_QB, /* [2][0...4] */
179
CSp_RP, CSp_bP, CSp_BP, CSp_PP, CSp_QP, /* [3][0...4] */
180
CSp_RQ, CSp_bQ, CSp_BQ, CSp_PQ, CSp_QQ, /* [4][0...4] */
183
/*------------------------------------------------------------------------
184
------------------------ fill in the vector ---------------------------
185
------------------------------------------------------------------------*/
186
int miAnalyzeConstrain(flo,ped)
191
ped->ddVec = ConstrainVec;
193
/* based on the technique, fill in the appropriate entry point vector */
195
switch(((xieFloConstrain *)ped->elemRaw)->constrain) {
196
case xieValConstrainClipScale:
197
case xieValConstrainHardClip:
200
ImplementationError(flo,ped, return(FALSE));
207
/*------------------------------------------------------------------------
208
---------------------------- create peTex . . . --------------------------
209
------------------------------------------------------------------------*/
210
static int CreateConstrain(flo,ped)
214
int auxsize = xieValMaxBands * sizeof(mpCnstPvtRec);
216
return MakePETex(flo,ped,auxsize,NO_SYNC,NO_SYNC);
220
/*------------------------------------------------------------------------
221
---------------------------- initialize peTex . . . ----------------------
222
------------------------------------------------------------------------*/
224
static int InitializeConstrain(flo,ped)
228
peTexPtr pet = ped->peTex;
229
pCnstDefPtr techpvt = (pCnstDefPtr)ped->techPvt;
230
mpCnstPvtPtr pvt = (mpCnstPvtPtr) pet->private;
233
int band, nbands, status;
235
status = InitReceptors(flo,ped,NO_DATAMAP,1) &&
236
InitEmitter(flo,ped,NO_DATAMAP,NO_INPLACE);
238
nbands = pet->receptor[SRCtag].inFlo->bands;
239
iband = &(pet->receptor[SRCtag].band[0]);
240
oband = &(pet->emitter[0]);
242
for(band = 0; band < nbands; band++, pvt++, iband++, oband++) {
244
int oo = IndexClass(oband->format->class);
245
int ii = IndexClass(iband->format->class);
247
switch(((xieFloConstrain *)ped->elemRaw)->constrain) {
249
case xieValConstrainClipScale:
251
((*(prep_cs[oo][ii])) (iband, oband, pvt, techpvt, band));
253
case xieValConstrainHardClip:
255
((*(prep_hc[oo][ii])) (iband, oband, pvt, techpvt, band));
262
/*------------------------------------------------------------------------
263
----------------------------- crank some data ----------------------------
264
------------------------------------------------------------------------*/
265
static int ActivateConstrain(flo,ped,pet)
270
mpCnstPvtPtr pvt = (mpCnstPvtPtr) pet->private;
271
int band, nbands = pet->receptor[SRCtag].inFlo->bands;
272
bandPtr iband = &(pet->receptor[SRCtag].band[0]);
273
bandPtr oband = &(pet->emitter[0]);
275
for(band = 0; band < nbands; band++, pvt++, iband++, oband++) {
276
register int bw = iband->format->width;
277
pointer ivoid, ovoid;
279
if (!(ivoid = GetCurrentSrc(flo,pet,iband)))
283
do { /* pass a clone of the current src strip downstream */
284
if(!PassStrip(flo,pet,oband,iband->strip))
286
ivoid = GetSrc(flo,pet,iband,iband->maxLocal,TRUE);
287
} while (!ferrCode(flo) && ivoid) ;
288
FreeData(flo, pet, iband, iband->current);
292
if (!(ovoid = GetCurrentDst(flo,pet,oband)))
296
(*(pvt->action)) (ivoid, ovoid, pvt, bw);
297
ivoid = GetNextSrc(flo,pet,iband,TRUE);
298
ovoid = GetNextDst(flo,pet,oband,TRUE);
299
} while (!ferrCode(flo) && ivoid && ovoid) ;
301
FreeData(flo, pet, iband, iband->current);
307
/*------------------------------------------------------------------------
308
------------------------ get rid of run-time stuff -----------------------
309
------------------------------------------------------------------------*/
310
static int ResetConstrain(flo,ped)
314
mpCnstPvtPtr pvt = (mpCnstPvtPtr) ped->peTex->private;
317
/* free any dynamic private data */
318
for (band = 0 ; band < xieValMaxBands ; band++, pvt++)
320
pvt->lut = (pointer) XieFree(pvt->lut);
328
/*------------------------------------------------------------------------
329
-------------------------- get rid of this element -----------------------
330
------------------------------------------------------------------------*/
331
static int DestroyConstrain(flo,ped)
335
/* get rid of the peTex structure */
336
ped->peTex = (peTexPtr) XieFree(ped->peTex);
338
/* zap this element's entry point vector */
339
ped->ddVec.create = (xieIntProc)NULL;
340
ped->ddVec.initialize = (xieIntProc)NULL;
341
ped->ddVec.activate = (xieIntProc)NULL;
342
ped->ddVec.reset = (xieIntProc)NULL;
343
ped->ddVec.destroy = (xieIntProc)NULL;
348
/*------------------------------------------------------------------------
349
------------------------ This guy must be nuts -------------------------
350
------------------------------------------------------------------------*/
352
/*----------------------------- HardClip --------------------------------*/
355
** DO_HCb - consume bits, produce bits.
356
** DO_HCc - consume bits, produce otype.
357
** DO_HCcx - consume bits, produce otype (using bitexpand).
358
** DO_HCp - consume itype, produce bits..
359
** DO_HCfp - consume floats, produce bits.
360
** DO_HClt - consume itype, produce otype (itype < otype).
361
** DO_HCeq - consume itype, produce otype (itype == otype).
362
** DO_HCgt - consume itype, produce otype (itype > otype)
363
** DO_HCf - consume floats, produce otype.
366
static void constrain_nop(INP,OUTP,pvt,bw)
367
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw;
371
static void (*hc_nop(iband,oband,pvt,techpvt,band))()
372
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band;
374
return constrain_nop;
376
static void (*cs_nop(iband,oband,pvt,techpvt,band))()
377
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band;
379
return constrain_nop;
382
static void clearbitline(INP,OUTP,pvt,bw)
383
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw;
385
action_clear(OUTP, bw, 0);
388
static void setbitline(INP,OUTP,pvt,bw)
389
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw;
391
action_set(OUTP, bw, 0);
394
static void copybitline(INP,OUTP,pvt,bw)
395
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw;
397
passcopy_bit(OUTP, INP, bw, 0);
400
static void invertbitline(INP,OUTP,pvt,bw)
401
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw;
403
passcopy_bit (OUTP, INP, bw, 0);
404
action_invert(OUTP, bw, 0);
407
#define LEVELSM1(T) *((T *) &(pvt->pad[0]))
409
#define DO_HCb(fn_prep,fn_do_a, fn_do_b,itype,otype) \
411
(*fn_prep (iband,oband,pvt,techpvt,band))() \
412
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
414
if (iband->format->levels == 1) \
415
return clearbitline; \
416
if (oband->format->levels == 1) \
417
return clearbitline; \
418
return copybitline; \
421
#define DO_HCc(fn_prep,fn_do_a, fn_do_b,itype,otype) \
423
fn_do_a(INP,OUTP,pvt,bw) \
424
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
426
LogInt inval, M, *inp = (LogInt *) INP; \
427
otype *outp = (otype *) OUTP; \
428
for ( ; bw >= LOGSIZE ; bw -= LOGSIZE) \
429
for (M=LOGLEFT, inval = *inp++; M; LOGRIGHT(M)) \
430
*outp++ = (inval & M) ? (otype) 1 : (otype) 0; \
432
for (M=LOGLEFT, inval = *inp++; bw; bw--, LOGRIGHT(M)) \
433
*outp++ = (inval & M) ? (otype) 1 : (otype) 0; \
436
fn_do_b(INP,OUTP,pvt,bw) \
437
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
439
bzero((char *)OUTP, bw * sizeof(otype)); \
440
/* action_clear(OUTP, (bw * sizeof(otype)) << 3, 0); */ \
443
(*fn_prep (iband,oband,pvt,techpvt,band))() \
444
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
446
if (iband->format->levels == 1) \
451
#define DO_HCcx(fn_prep,fn_do,fn_do_b,itype,otype) \
453
fn_do(INP,OUTP,pvt,bw) \
454
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
456
bitexpand(INP, OUTP, bw, 0, 1); \
459
fn_do_b(INP,OUTP,pvt,bw) \
460
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
462
bzero((char *)OUTP, bw * sizeof(otype)); \
463
/* action_clear(OUTP, (bw * sizeof(otype)) << 3, 0); */ \
466
(*fn_prep (iband,oband,pvt,techpvt,band))() \
467
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
469
if (iband->format->levels == 1) \
474
#define DO_HCp(fn_prep,fn_do_a, fn_do_b,itype,otype) \
476
fn_do_a(INP,OUTP,pvt,bw) \
477
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
479
itype *inp = (itype *) INP; \
480
LogInt outval, M, *outp = (LogInt *) OUTP; \
481
for ( ; bw >= LOGSIZE ; *outp++ = outval, bw -= LOGSIZE) \
482
for (M=LOGLEFT, outval = 0; M; LOGRIGHT(M)) \
486
for (M=LOGLEFT, outval = 0; bw; bw--, LOGRIGHT(M)) \
493
(*fn_prep (iband,oband,pvt,techpvt,band))() \
494
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
496
if (oband->format->levels == 1) \
497
return clearbitline; \
501
#define DO_HCfp(fn_prep,fn_do_a, fn_do_b,itype,otype) \
503
fn_do_a(INP,OUTP,pvt,bw) \
504
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
506
itype *inp = (itype *) INP; \
507
LogInt outval, M, *outp = (LogInt *) OUTP; \
508
for ( ; bw >= LOGSIZE ; *outp++ = outval, bw -= LOGSIZE) \
509
for (M=LOGLEFT, outval = 0; M; LOGRIGHT(M)) \
510
if (*inp++ >= (itype) 1.0) \
513
for (M=LOGLEFT, outval = 0; bw; bw--, LOGRIGHT(M)) \
514
if (*inp++ >= (itype) 1.0) \
520
(*fn_prep (iband,oband,pvt,techpvt,band))() \
521
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
523
if (oband->format->levels == 1) \
524
return clearbitline; \
528
#define DO_HClt(fn_prep,fn_do_a, fn_do_b,itype,otype) \
530
fn_do_b(INP,OUTP,pvt,bw) \
531
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
533
itype *inp = (itype *) INP; \
534
otype *outp = (otype *) OUTP; \
535
while (bw-- > 0 ) { \
536
*outp++ = (otype) *inp++; \
540
(*fn_prep (iband,oband,pvt,techpvt,band))() \
541
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
546
#define DO_HCeq(fn_prep,fn_do_a, fn_do_b,itype,otype) \
548
fn_do_a(INP,OUTP,pvt,bw) \
549
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
551
itype *inp = (itype *) INP; \
552
otype *outp = (otype *) OUTP; \
553
itype inval, lm1 = LEVELSM1(itype); \
554
while (bw-- > 0 ) { \
555
if ((inval = *inp++) > lm1) inval = lm1; \
556
*outp++ = (otype) inval; \
559
/* fn_do_b was memcpy, now done at higher level with PassStrip */ \
561
(*fn_prep (iband,oband,pvt,techpvt,band))() \
562
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
564
itype ilm1 = (itype)( (iband->format->levels) \
565
? iband->format->levels - 1 : ~0); \
566
itype olm1 = (itype)( (oband->format->levels) \
567
? oband->format->levels - 1 : ~0); \
569
/*special hint to PassStrip */ \
570
return (void (*) ()) 0; \
572
LEVELSM1(itype) = (itype) olm1; \
576
#define DO_HCgt(fn_prep,fn_do_a, fn_do_b,itype,otype) \
578
fn_do_a(INP,OUTP,pvt,bw) \
579
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
581
itype *inp = (itype *) INP; \
582
otype *outp = (otype *) OUTP; \
583
itype inval, lm1 = LEVELSM1(itype); \
584
while (bw-- > 0 ) { \
585
if ((inval = *inp++) > lm1) inval = lm1; \
586
*outp++ = (otype) inval; \
590
(*fn_prep (iband,oband,pvt,techpvt,band))() \
591
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
593
otype olm1 = (otype)( (oband->format->levels) \
594
? oband->format->levels - 1 : ~0); \
595
LEVELSM1(itype) = (itype) olm1; \
600
#define DO_HCf(fn_prep,fn_do_a,fn_do_b,itype,otype) \
602
fn_do_a(INP,OUTP,pvt,bw) \
603
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
605
itype *inp = (itype *) INP; \
606
otype *outp = (otype *) OUTP; \
607
itype inval, olm1 = *((itype *) &(pvt->pad[0])); \
608
while (bw-- > 0 ) { \
609
if ((inval = *inp++) > olm1) inval = olm1; \
610
else if (inval < 0) inval = (itype) 0; \
611
*outp++ = (otype) inval; \
615
(*fn_prep (iband,oband,pvt,techpvt,band))() \
616
bandPtr iband, oband; mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
618
otype olm1 = (otype)( (oband->format->levels) \
619
? oband->format->levels - 1 : ~0); \
620
*((itype *) &(pvt->pad[0])) = olm1; \
624
DO_HCb (HCp_bb, HCa_bb, HCb_bb, BitPixel, BitPixel)
625
DO_HCp (HCp_Bb, HCa_Bb, HCb_Bb, BytePixel, BitPixel)
626
DO_HCp (HCp_Pb, HCa_Pb, HCb_Pb, PairPixel, BitPixel)
627
DO_HCp (HCp_Qb, HCa_Qb, HCb_Qb, QuadPixel, BitPixel)
628
DO_HCfp (HCp_Rb, HCa_Rb, HCb_Rb, RealPixel, BitPixel)
630
DO_HCcx (HCp_bB, HCa_bB, HCb_bB, BitPixel, BytePixel)
631
DO_HCeq (HCp_BB, HCa_BB, HCb_BB, BytePixel, BytePixel)
632
DO_HCgt (HCp_PB, HCa_PB, HCb_PB, PairPixel, BytePixel)
633
DO_HCgt (HCp_QB, HCa_QB, HCb_QB, QuadPixel, BytePixel)
634
DO_HCf (HCp_RB, HCa_RB, HCb_RB, RealPixel, BytePixel)
636
DO_HCc (HCp_bP, HCa_bP, HCb_bP, BitPixel, PairPixel)
637
DO_HClt (HCp_BP, HCa_BP, HCb_BP, BytePixel, PairPixel)
638
DO_HCeq (HCp_PP, HCa_PP, HCb_PP, PairPixel, PairPixel)
639
DO_HCgt (HCp_QP, HCa_QP, HCb_QP, QuadPixel, PairPixel)
640
DO_HCf (HCp_RP, HCa_RP, HCb_RP, RealPixel, PairPixel)
642
DO_HCc (HCp_bQ, HCa_bQ, HCb_bQ, BitPixel, QuadPixel)
643
DO_HClt (HCp_BQ, HCa_BQ, HCb_BQ, BytePixel, QuadPixel)
644
DO_HClt (HCp_PQ, HCa_PQ, HCb_PQ, PairPixel, QuadPixel)
645
DO_HCeq (HCp_QQ, HCa_QQ, HCb_QQ, QuadPixel, QuadPixel)
646
DO_HCf (HCp_RQ, HCa_RQ, HCb_RQ, RealPixel, QuadPixel)
650
/*----------------------------- ClipScale --------------------------------*/
652
typedef float ConstrainFloat;
653
#define HALF ((ConstrainFloat) 0.5)
655
#define LBOUND(T) *((T *) &(pvt->pad[0]))
656
#define UBOUND(T) *((T *) &(pvt->pad[1]))
657
#define OLOW(T) *((T *) &(pvt->pad[2]))
658
#define OHIGH(T) *((T *) &(pvt->pad[3]))
659
#define FLT_SF *((ConstrainFloat *) &(pvt->pad[4]))
660
#define FLT_OFF *((ConstrainFloat *) &(pvt->pad[5]))
661
#define INT_SF *((INT32 *) &(pvt->pad[4]))
662
#define INT_OFF *((INT32 *) &(pvt->pad[5]))
665
cs_scale_equation(pvt,techpvt,band)
666
mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band;
668
QuadPixel olow = techpvt->output_low[band];
669
ConstrainFloat ilow = techpvt->input_low[band];
670
ConstrainFloat sf = (techpvt->output_high[band] - olow) /
671
(techpvt->input_high[band] - ilow);
673
FLT_OFF = (ConstrainFloat) olow - sf * ilow;
677
cs_fix_bits(pvt,techpvt,band)
678
mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band;
680
ConstrainFloat ilow = techpvt->input_low[band];
681
ConstrainFloat ihigh = techpvt->input_high[band];
682
QuadPixel olow = techpvt->output_low[band];
683
QuadPixel ohigh = techpvt->output_high[band];
684
/* Prep guarantees ilow != ihigh, but what if ilow > ihigh */
685
if (ilow == 0.0 && ihigh == 1.0) {
686
OLOW(QuadPixel) = olow;
687
OHIGH(QuadPixel) = ohigh;
689
} else if (ilow == 1.0 && ihigh == 0.0) {
690
OLOW(QuadPixel) = ohigh;
691
OHIGH(QuadPixel) = olow;
694
cs_scale_equation(pvt,techpvt,band);
696
if (0.0 <= ilow) OLOW(QuadPixel) = olow;
697
else if (0.0 >= ihigh) OLOW(QuadPixel) = ohigh;
698
else OLOW(QuadPixel) = FLT_SF * 0. + FLT_OFF + HALF;
699
if (1.0 <= ilow) OHIGH(QuadPixel) = olow;
700
else if (1.0 >= ihigh) OHIGH(QuadPixel) = ohigh;
701
else OHIGH(QuadPixel) = FLT_SF * 1. + FLT_OFF + HALF;
703
if (0.0 >= ilow) OLOW(QuadPixel) = olow;
704
else if (0.0 <= ihigh) OLOW(QuadPixel) = ohigh;
705
else OLOW(QuadPixel) = FLT_SF * 0. + FLT_OFF + HALF;
706
if (1.0 >= ilow) OHIGH(QuadPixel) = olow;
707
else if (1.0 <= ihigh) OHIGH(QuadPixel) = ohigh;
708
else OHIGH(QuadPixel) = FLT_SF * 1. + FLT_OFF + HALF;
712
#define DO_CSb(fn_prep,fn_do,fn_do_b,itype,otype) \
714
(*fn_prep (iband,oband,pvt,techpvt,band))() \
715
bandPtr iband, oband; \
716
mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
718
if (iband->format->levels == 1 || oband->format->levels == 1) \
719
return clearbitline; \
720
cs_fix_bits(pvt,techpvt,band); \
721
return (OLOW(QuadPixel) == OHIGH(QuadPixel)) \
722
? ((OLOW(QuadPixel) == 0) ? clearbitline: setbitline) \
723
: ((OLOW(QuadPixel) == 0) ? copybitline: invertbitline); \
727
#define DO_CSc(fn_prep,fn_do,fn_do_b,itype,otype) \
729
fn_do(INP,OUTP,pvt,bw) \
730
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
732
LogInt inval, M, *inp = (LogInt *) INP; \
733
otype *outp = (otype *) OUTP; \
734
otype olow = OLOW(otype), ohigh = OHIGH(otype); \
735
for ( ; bw >= LOGSIZE ; bw -= LOGSIZE) \
736
for (M=LOGLEFT, inval = *inp++; M; LOGRIGHT(M)) \
737
*outp++ = (inval & M) ? ohigh : olow ; \
739
for (M=LOGLEFT, inval = *inp++; bw; bw--, LOGRIGHT(M)) \
740
*outp++ = (inval & M) ? ohigh : olow ; \
743
(*fn_prep (iband,oband,pvt,techpvt,band))() \
744
bandPtr iband, oband; \
745
mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
747
cs_fix_bits(pvt,techpvt,band); \
748
OLOW(otype) = OLOW(QuadPixel); \
749
OHIGH(otype) = OHIGH(QuadPixel); \
753
#define DO_CScx(fn_prep,fn_do,fn_do_b,itype,otype) \
755
fn_do(INP,OUTP,pvt,bw) \
756
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
758
otype olow = OLOW(otype), ohigh = OHIGH(otype); \
759
bitexpand(INP, OUTP, bw, olow, ohigh); \
762
(*fn_prep (iband,oband,pvt,techpvt,band))() \
763
bandPtr iband, oband; \
764
mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
766
cs_fix_bits(pvt,techpvt,band); \
767
OLOW(otype) = OLOW(QuadPixel); \
768
OHIGH(otype) = OHIGH(QuadPixel); \
772
#define DO_CSp(fn_prep,fn_do,fn_do_b,itype,otype) \
774
fn_do(INP,OUTP,pvt,bw) \
775
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
777
itype *inp = (itype *) INP; \
778
LogInt outval, M, *outp = (LogInt *) OUTP; \
779
itype imedian = UBOUND(itype); \
780
for ( ; bw >= LOGSIZE ; *outp++ = outval, bw -= LOGSIZE) \
781
for (M=LOGLEFT, outval = 0; M; LOGRIGHT(M)) \
782
if (*inp++ > imedian) \
785
for (M=LOGLEFT, outval = 0; bw; bw--, LOGRIGHT(M)) \
786
if (*inp++ > imedian) \
792
fn_do_b(INP,OUTP,pvt,bw) \
793
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
795
itype *inp = (itype *) INP; \
796
LogInt outval, M, *outp = (LogInt *) OUTP; \
797
itype imedian = UBOUND(itype); \
798
for ( ; bw >= LOGSIZE ; *outp++ = outval, bw -= LOGSIZE) \
799
for (M=LOGLEFT, outval = 0; M; LOGRIGHT(M)) \
800
if (*inp++ <= imedian) \
803
for (M=LOGLEFT, outval = 0; bw; bw--, LOGRIGHT(M)) \
804
if (*inp++ <= imedian) \
810
(*fn_prep (iband,oband,pvt,techpvt,band))() \
811
bandPtr iband, oband; \
812
mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
814
otype olow = techpvt->output_low[band]; \
815
otype ohigh = techpvt->output_high[band]; \
817
return (olow == 0) ? clearbitline : setbitline; \
818
UBOUND(itype) = HALF * \
819
(techpvt->input_low[band] + techpvt->input_high[band]); \
820
return (techpvt->input_low[band] < techpvt->input_high[band]) \
824
#define DO_CS(fn_prep,fn_do,fn_do_b,itype,otype) \
826
fn_do(INP,OUTP,pvt,bw) \
827
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
829
itype *inp = (itype *) INP; otype *outp = (otype *) OUTP; \
830
itype inv, lbound = LBOUND(itype), ubound = UBOUND(itype); \
831
otype out, olow = OLOW(otype), ohigh = OHIGH(otype); \
832
ConstrainFloat sf = FLT_SF, offset = FLT_OFF; \
838
else if (inv > lbound) \
839
out = (otype)(sf * inv + offset); \
844
fn_do_b(INP,OUTP,pvt,bw) \
845
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
847
itype *inp = (itype *) INP; otype *outp = (otype *) OUTP; \
848
itype inv, lbound = LBOUND(itype), ubound = UBOUND(itype); \
849
otype out, olow = OLOW(otype), ohigh = OHIGH(otype); \
850
ConstrainFloat sf = FLT_SF, offset = FLT_OFF; \
856
else if (inv > ubound) \
857
out = (otype)(sf * inv + offset); \
862
(*fn_prep (iband,oband,pvt,techpvt,band))() \
863
bandPtr iband, oband; \
864
mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
866
OLOW(otype) = techpvt->output_low[band]; \
867
OHIGH(otype) = techpvt->output_high[band]; \
868
LBOUND(itype) = (itype) (techpvt->input_low[band] + HALF); \
869
UBOUND(itype) = (itype) (techpvt->input_high[band] + HALF); \
870
cs_scale_equation(pvt,techpvt,band); \
872
return (FLT_SF >= 0.0) ? fn_do : fn_do_b; \
875
#if defined(USE_FLOATS)
876
#define DO_CSi(fn_prep,fn_do,fn_do_b,itype,otype,shift) \
877
DO_CS(fn_prep,fn_do,fn_do_b,itype,otype)
879
/* XXX need LUT based approach for small sizes */
880
#define DO_CSi_part1(fna,itype,otype,shift) \
882
fna(INP,OUTP,pvt,bw) \
883
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
885
itype *inp = (itype *) INP; otype *outp = (otype *) OUTP; \
886
otype out, olow = OLOW(otype), ohigh = OHIGH(otype); \
887
INT32 lbound = (INT32) LBOUND(itype); \
888
INT32 ubound = (INT32) UBOUND(itype); \
889
INT32 int_sf = INT_SF, int_off = INT_OFF; \
895
if (inv < ubound) { \
896
out = (otype)((int_sf * inv + int_off)>>shift); \
903
#define DO_CSi_part2(fnb,itype,otype,shift) \
905
fnb(INP,OUTP,pvt,bw) \
906
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
908
itype *inp = (itype *) INP; otype *outp = (otype *) OUTP; \
909
otype out, olow = OLOW(otype), ohigh = OHIGH(otype); \
910
INT32 lbound = (INT32) LBOUND(itype); \
911
INT32 ubound = (INT32) UBOUND(itype); \
912
INT32 int_sf = INT_SF, int_off = INT_OFF; \
918
if (inv < lbound) { \
919
out = (otype)((int_sf * inv + int_off)>>shift); \
926
/* some compilers gag on long macros. somehow this helps */
927
#define DO_CSi(fn_prep,fn_do,fn_do_b,itype,otype,shift) \
928
DO_CSi_part1(fn_do,itype,otype,shift) \
929
DO_CSi_part2(fn_do_b,itype,otype,shift) \
931
(*fn_prep (iband,oband,pvt,techpvt,band))() \
932
bandPtr iband, oband; \
933
mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
935
CARD32 olow, ohigh; INT32 int_sf, int_off; \
936
olow = techpvt->output_low[band]; \
937
ohigh = techpvt->output_high[band]; \
938
LBOUND(itype) = (itype) (techpvt->input_low[band] + HALF); \
939
UBOUND(itype) = (itype) (techpvt->input_high[band] + HALF); \
940
OLOW(otype) = olow = techpvt->output_low[band]; \
941
OHIGH(otype) = ohigh = techpvt->output_high[band]; \
944
INT_SF = int_sf = (ohigh - olow) / \
945
(techpvt->input_high[band] - techpvt->input_low[band]); \
946
INT_OFF = int_off = (1<<(shift-1)) + olow - \
947
int_sf * (INT32) techpvt->input_low[band]; \
950
return (int_sf >= 0) ? fn_do : fn_do_b; \
954
#define DO_CSf(fn_prep,fn_do,fn_do_b,itype,otype) \
956
fn_do(INP,OUTP,pvt,bw) \
957
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
959
itype *inp = (itype *) INP; otype *outp = (otype *) OUTP; \
960
itype inv, lbound = LBOUND(itype), ubound = UBOUND(itype); \
961
otype out, olow = OLOW(otype), ohigh = OHIGH(otype); \
962
ConstrainFloat sf = FLT_SF, offset = FLT_OFF; \
968
else if (inv > lbound) \
969
out = (otype)(sf * inv + offset); \
974
fn_do_b(INP,OUTP,pvt,bw) \
975
pointer INP; pointer OUTP; mpCnstPvtPtr pvt; int bw; \
977
itype *inp = (itype *) INP; otype *outp = (otype *) OUTP; \
978
itype inv, lbound = LBOUND(itype), ubound = UBOUND(itype); \
979
otype out, olow = OLOW(otype), ohigh = OHIGH(otype); \
980
ConstrainFloat sf = FLT_SF, offset = FLT_OFF; \
986
else if (inv > ubound) \
987
out = (otype)(sf * inv + offset); \
992
(*fn_prep (iband,oband,pvt,techpvt,band))() \
993
bandPtr iband, oband; \
994
mpCnstPvtPtr pvt; pCnstDefPtr techpvt; int band; \
996
OLOW(otype) = techpvt->output_low[band]; \
997
OHIGH(otype) = techpvt->output_high[band]; \
998
LBOUND(itype) = (itype) techpvt->input_low[band]; \
999
UBOUND(itype) = (itype) techpvt->input_high[band]; \
1000
cs_scale_equation(pvt,techpvt,band); \
1001
return (FLT_SF >= 0.0) ? fn_do : fn_do_b; \
1004
DO_CSb (CSp_bb, CSa_bb, CSb_bb, BitPixel, BitPixel)
1005
DO_CSp (CSp_Bb, CSa_Bb, CSb_Bb, BytePixel, BitPixel)
1006
DO_CSp (CSp_Pb, CSa_Pb, CSb_Pb, PairPixel, BitPixel)
1007
DO_CSp (CSp_Qb, CSa_Qb, CSb_Qb, QuadPixel, BitPixel)
1008
DO_CSp (CSp_Rb, CSa_Rb, CSb_Rb, RealPixel, BitPixel)
1010
DO_CScx (CSp_bB, CSa_bB, CSb_bB, BitPixel, BytePixel)
1011
DO_CSi (CSp_BB, CSa_BB, CSb_BB, BytePixel, BytePixel, 22)
1012
DO_CSi (CSp_PB, CSa_PB, CSb_PB, PairPixel, BytePixel, 22)
1013
DO_CSi (CSp_QB, CSa_QB, CSb_QB, QuadPixel, BytePixel, 22)
1014
DO_CSf (CSp_RB, CSa_RB, CSb_RB, RealPixel, BytePixel)
1016
DO_CSc (CSp_bP, CSa_bP, CSb_bP, BitPixel, PairPixel)
1017
DO_CSi (CSp_BP, CSa_BP, CSb_BP, BytePixel, PairPixel, 14)
1018
DO_CSi (CSp_PP, CSa_PP, CSb_PP, PairPixel, PairPixel, 14)
1019
DO_CSi (CSp_QP, CSa_QP, CSb_QP, QuadPixel, PairPixel, 14)
1020
DO_CSf (CSp_RP, CSa_RP, CSb_RP, RealPixel, PairPixel)
1022
DO_CSc (CSp_bQ, CSa_bQ, CSb_bQ, BitPixel, QuadPixel)
1023
DO_CSi (CSp_BQ, CSa_BQ, CSb_BQ, BytePixel, QuadPixel, 6)
1024
DO_CSi (CSp_PQ, CSa_PQ, CSb_PQ, PairPixel, QuadPixel, 6)
1025
DO_CSi (CSp_QQ, CSa_QQ, CSb_QQ, QuadPixel, QuadPixel, 6)
1026
DO_CSf (CSp_RQ, CSa_RQ, CSb_RQ, RealPixel, QuadPixel)
1037
/* end module mpcnst.c */