summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/XIE/mixie/export/mephoto.c
blob: 5abde19d51b5f51222b69e04b9c6f04b01af0777 (plain)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
/* $XConsortium: mephoto.c,v 1.7 94/04/17 20:34:23 dpw Exp $ */
/**** module mephoto.c ****/
/******************************************************************************

Copyright (c) 1993, 1994  X Consortium

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.


				NOTICE
                              
This software is being provided by AGE Logic, Inc. under the
following license.  By obtaining, using and/or copying this software,
you agree that you have read, understood, and will comply with these
terms and conditions:

     Permission to use, copy, modify, distribute and sell this
     software and its documentation for any purpose and without
     fee or royalty and to grant others any or all rights granted
     herein is hereby granted, provided that you agree to comply
     with the following copyright notice and statements, including
     the disclaimer, and that the same appears on all copies and
     derivative works of the software and documentation you make.
     
     "Copyright 1993, 1994 by AGE Logic, Inc."
     
     THIS SOFTWARE IS PROVIDED "AS IS".  AGE LOGIC MAKES NO
     REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  By way of
     example, but not limitation, AGE LOGIC MAKE NO
     REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS
     FOR ANY PARTICULAR PURPOSE OR THAT THE SOFTWARE DOES NOT
     INFRINGE THIRD-PARTY PROPRIETARY RIGHTS.  AGE LOGIC 
     SHALL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE.  IN NO
     EVENT SHALL EITHER PARTY BE LIABLE FOR ANY INDIRECT,
     INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS
     OF PROFITS, REVENUE, DATA OR USE, INCURRED BY EITHER PARTY OR
     ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT OR
     BASED ON A WARRANTY, EVEN IF AGE LOGIC LICENSEES
     HEREUNDER HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
     DAMAGES.
    
     The name of AGE Logic, Inc. may not be used in
     advertising or publicity pertaining to this software without
     specific, written prior permission from AGE Logic.

     Title to this software shall at all times remain with AGE
     Logic, Inc.
*****************************************************************************
  
	mephoto.c -- DDXIE prototype export photomap element
  
	Robert NC Shelley -- AGE Logic, Inc. June, 1993
	Dean && Ben - various additions to handle different techniques
  
*****************************************************************************/

#define _XIEC_MEPHOTO
#define _XIEC_EPHOTO

/*
 *  Include files
 */
#include <stdio.h>

/*
 *  Core X Includes
 */
#include <X.h>
#include <Xproto.h>
/*
 *  XIE Includes
 */
#include <XIE.h>
#include <XIEproto.h>
/*
 *  more X server includes.
 */
#include <misc.h>
#include <dixstruct.h>
/*
 *  Server XIE Includes
 */
#include <error.h>
#include <macro.h>
#include <photomap.h>
#include <element.h>
#include <texstr.h>
#include <xiemd.h>
#include <meuncomp.h>


/*
 *  routines referenced by other DDXIE modules
 */
int	miAnalyzeEPhoto();

/*
 *  routines used internal to this module
 */
static int CreateEPhotoUncom();
static int InitializeEPhotoBypass();
static int InitializeEPhotoUncomByPlane();
static int ActivateEPhotoUncomByPlane();
static int ResetEPhoto();
static int DestroyEPhoto();

#if XIE_FULL
static int InitializeEPhotoUncomByPixel();
static int ActivateEPhotoUncomByPixel();
#endif /* XIE_FULL */


/*
 * routines we need from somewhere else
 */

extern int CreateEPhotoJPEGBaseline();
extern int InitializeEPhotoJPEGBaseline();
extern int ActivateEPhotoJPEGBaseline();
extern int ResetEPhotoJPEGBaseline();
extern int DestroyEPhotoJPEGBaseline();

extern int CreateEPhotoFAX();
extern int InitializeEPhotoFAX();
extern int ActivateEPhotoFAX();
extern int ResetEPhotoFAX();
extern int DestroyEPhotoFAX();

/*
 * DDXIE ExportPhotomap entry points
 */
static ddElemVecRec EPhotoBypassVec = {
  CreateEPhotoUncom,
  InitializeEPhotoBypass,
  (xieIntProc)NULL,
  (xieIntProc)NULL,
  ResetEPhoto,
  DestroyEPhoto
  };

static ddElemVecRec EPhotoUncomByPlaneVec = {
  CreateEPhotoUncom,
  InitializeEPhotoUncomByPlane,
  ActivateEPhotoUncomByPlane,
  (xieIntProc)NULL,
  ResetEPhoto,
  DestroyEPhoto
  };

static ddElemVecRec EPhotoFAXVec = {
  CreateEPhotoFAX,
  InitializeEPhotoFAX,
  ActivateEPhotoFAX,
  (xieIntProc)NULL,
  ResetEPhotoFAX,
  DestroyEPhotoFAX
  };

#if XIE_FULL
static ddElemVecRec EPhotoUncomByPixelVec = {
  CreateEPhotoUncom,
  InitializeEPhotoUncomByPixel,
  ActivateEPhotoUncomByPixel,
  (xieIntProc)NULL,
  ResetEPhoto,
  DestroyEPhoto
  };

static ddElemVecRec EPhotoJPEGBaselineVec = {
  CreateEPhotoJPEGBaseline,
  InitializeEPhotoJPEGBaseline,
  ActivateEPhotoJPEGBaseline,
  (xieIntProc)NULL,
  ResetEPhotoJPEGBaseline,
  DestroyEPhotoJPEGBaseline
  };
#endif /* XIE_FULL */


/*------------------------------------------------------------------------
------------------- see if we can handle this element --------------------
------------------------------------------------------------------------*/
int miAnalyzeEPhoto(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  ePhotoDefPtr pvt = (ePhotoDefPtr)ped->elemPvt;

  if(pvt->congress) {
    ped->ddVec = EPhotoBypassVec;
    return(TRUE);
  }
  switch(pvt->encodeNumber) {

  case xieValEncodeUncompressedSingle:
    ped->ddVec = EPhotoUncomByPlaneVec;
    break;
      
  case xieValEncodeG31D:
  case xieValEncodeG32D:
  case xieValEncodeG42D:
  case xieValEncodeTIFF2:
  case xieValEncodeTIFFPackBits:
    ped->ddVec = EPhotoFAXVec;
    break;
      
#if XIE_FULL
  case xieValEncodeUncompressedTriple:
    {
        xieTecEncodeUncompressedTriple *tecParms = 
	         (xieTecEncodeUncompressedTriple *)pvt->encodeParms;
        if(tecParms->interleave == xieValBandByPlane)
          ped->ddVec = EPhotoUncomByPlaneVec;
        else
          ped->ddVec = EPhotoUncomByPixelVec;
    }
    break;
  case xieValEncodeJPEGBaseline:
    { /*** JPEG for SI can only handle 8 bit image depths ***/
      inFloPtr inf  = &ped->inFloLst[IMPORT];
      outFloPtr src = &inf->srcDef->outFlo;
      int b;
      for (b=0; b< src->bands; ++b) 
        if(src->format[b].depth != 8) {
  	  xieFloExportPhotomap *raw = (xieFloExportPhotomap *)ped->elemRaw;

	  TechniqueError(flo, ped, xieValEncode,
	                 raw->encodeTechnique, raw->lenParams, return(FALSE));
	}
    }
    ped->ddVec = EPhotoJPEGBaselineVec;
    break;
  case xieValEncodeJPEGLossless:
#endif /* XIE_FULL */
  default:  ImplementationError(flo,ped, return(FALSE));
  }
  return(TRUE);
}                               /* end miAnalyzeEPhoto */

/*------------------------------------------------------------------------
---------------------------- create peTex . . . --------------------------
------------------------------------------------------------------------*/
static int CreateEPhotoUncom(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  /* attach an execution context to the photo element definition */
  return(MakePETex(flo, ped, xieValMaxBands * sizeof(meUncompRec), 
				NO_SYNC, NO_SYNC));
}                               /* end CreateEPhotoUncom */

/*------------------------------------------------------------------------
---------------------------- initialize peTex . . . ----------------------
------------------------------------------------------------------------*/
static int InitializeEPhotoBypass(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  /* Allows data manager to bypass element entirely */
  return(InitReceptor(flo, ped, ped->peTex->receptor,
		      NO_DATAMAP, 1, NO_BANDS, ALL_BANDS));
}                               /* end InitializeEPhotoBypass */

/*------------------------------------------------------------------------
---------------------------- initialize peTex . . . ----------------------
------------------------------------------------------------------------*/
static int InitializeEPhotoUncomByPlane(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  peTexPtr              pet = ped->peTex;
  meUncompPtr           pvt = (meUncompPtr)pet->private;
  formatPtr             inf = ped->inFloLst[SRCtag].format;
  bandPtr	       sbnd = pet->receptor->band;
  CARD32	     nbands = ped->outFlo.bands, b, s;
  xieTypOrientation pixelOrder, fillOrder;
  Bool inited = FALSE;
  
  if (nbands == 1) {
    xieTecEncodeUncompressedSingle *tecParms = 
				(xieTecEncodeUncompressedSingle *)
				((ePhotoDefPtr)ped->elemPvt)->encodeParms;
    pixelOrder = tecParms->pixelOrder;
    fillOrder  = tecParms->fillOrder;
    pvt[0].bandMap = 0;
  } else {
    xieTecEncodeUncompressedTriple *tecParms = 
				(xieTecEncodeUncompressedTriple *)
				((ePhotoDefPtr)ped->elemPvt)->encodeParms;
    pixelOrder = tecParms->pixelOrder;
    fillOrder  = tecParms->fillOrder;
    if(tecParms->bandOrder == xieValLSFirst) 
      for(b = 0; b < xieValMaxBands; ++b)
	pvt[b].bandMap = b;
    else 
      for(s = 0, b = xieValMaxBands; b--; ++s)
	pvt[s].bandMap = b;
  }
  for (b = 0; b < nbands; b++, pvt++, inf++, sbnd++) {
    bandPtr   dbnd = &pet->emitter[pvt->bandMap];
    formatPtr outf = &ped->outFlo.format[pvt->bandMap];
    CARD8 class    = inf->class;
    if (class == BIT_PIXEL) {
          pvt->width  = inf->width;
#if (IMAGE_BYTE_ORDER == MSBFirst)
          if (outf->stride != 1) {
	      pvt->action = (fillOrder == xieValMSFirst) ? btoIS: sbtoIS;
          } else {
      	      pvt->action = (fillOrder == xieValMSFirst) ? 
						(void (*)())NULL : sbtoS;
          }
#else
          if (outf->stride != 1) {
	      pvt->action = (fillOrder == xieValLSFirst) ? btoIS: sbtoIS;
          } else {
      	      pvt->action = (fillOrder == xieValLSFirst) ? 
						(void (*)())NULL : sbtoS;
          }
#endif
          pvt->stride = outf->stride;
          pvt->pitch  = outf->pitch;
    } else if (class == BYTE_PIXEL)  {
          pvt->width = inf->width;
	  if (!(outf->stride & 7)) {
	      if (outf->stride == 8)
	      	  pvt->action = BtoS;
	      else
	      	  pvt->action = BtoIS;
              pvt->Bstride   = outf->stride >> 3;
	      pvt->dstoffset = 0;
	      pvt->mask      = 0; /* Unused */
	      pvt->shift     = 0; /* Unused */
	      pvt->clear_dst = FALSE;
	  } else {
	      if (pixelOrder == xieValLSFirst) {
		  if (fillOrder == xieValLSFirst) 
	              pvt->action = BtoLLUB;
	          else 
	              pvt->action = BtoLMUB;
	      } else {
		  if (fillOrder == xieValLSFirst) 
	              pvt->action = BtoMLUB;
	          else 
	              pvt->action = BtoMMUB;
	      }	
              pvt->bitOff   = 0;	/* Bit offset to first pixel on line */
              pvt->leftOver = 0;	/* Left over bits from last line     */
              pvt->depth    = inf->depth;
              pvt->stride   = outf->stride;
              pvt->pitch    = outf->pitch;
	  } 
    } else if (class == PAIR_PIXEL) {
          pvt->width = inf->width;
	  if (!(outf->stride & 15)) {
#if (IMAGE_BYTE_ORDER == LSBFirst)
	      if (outf->stride == 16)
	      	  pvt->action = (fillOrder == xieValLSFirst) ? 
						(void (*)())NULL : sPtoS;
	      else
	      	  pvt->action = (fillOrder == xieValLSFirst) ? PtoIS: sPtoIS;
#else
	      if (outf->stride == 16)
	      	  pvt->action = (fillOrder == xieValMSFirst) ? 
						(void (*)())NULL : sPtoS;
	      else
	      	  pvt->action = (fillOrder == xieValMSFirst) ? PtoIS: sPtoIS;
#endif
              pvt->Bstride   = outf->stride >> 3;
	      pvt->dstoffset = 0;
	      pvt->mask      = 0; /* Unused */
	      pvt->shift     = 0; /* Unused */
	      pvt->clear_dst = FALSE;
	  } else {
	      if (pixelOrder == xieValLSFirst) {
		  if (fillOrder == xieValLSFirst) 
	              pvt->action = PtoLLUP;
	          else 
	              pvt->action = PtoLMUP;
	      } else {
		  if (fillOrder == xieValLSFirst) 
	              pvt->action = PtoMLUP;
	          else 
	              pvt->action = PtoMMUP;
	      }	
              pvt->bitOff   = 0;	/* Bit offset to first pixel on line */
              pvt->leftOver = 0;	/* Left over bits from last line     */
              pvt->depth    = inf->depth;
              pvt->stride   = outf->stride;
              pvt->pitch    = outf->pitch;
	  } 
    } else if (class == QUAD_PIXEL) {
          pvt->width = inf->width;
	  if (!(outf->stride & 31)) {
#if (IMAGE_BYTE_ORDER == LSBFirst)
	      if (outf->stride == 32)
	      	  pvt->action = (fillOrder == xieValLSFirst) ? 
						(void (*)())NULL : sQtoS;
	      else
	      	  pvt->action = (fillOrder == xieValLSFirst) ? QtoIS: sQtoIS;
#else
	      if (outf->stride == 32)
	      	  pvt->action = (fillOrder == xieValMSFirst) ? 
						(void (*)())NULL : sQtoS;
	      else
	      	  pvt->action = (fillOrder == xieValMSFirst) ? QtoIS: sQtoIS;
#endif
              pvt->Bstride   = outf->stride >> 3;
	      pvt->dstoffset = 0;
	      pvt->mask      = 0; /* Unused */
	      pvt->shift     = 0; /* Unused */
	      pvt->clear_dst = FALSE;
	  } else {
	      if (pixelOrder == xieValLSFirst) {
		  if (fillOrder == xieValLSFirst) 
	              pvt->action = QtoLLUQ;
	          else 
	              pvt->action = QtoLMUQ;
	      } else {
		  if (fillOrder == xieValLSFirst) 
	              pvt->action = QtoMLUQ;
	          else 
	              pvt->action = QtoMMUQ;
	      }	
	  } 
      } else
        ImplementationError(flo,ped, return(FALSE)); 
    
    if (pvt->action) {
      pvt->bitOff   = 0;		/* Bit offset to first pixel on line */
      pvt->leftOver = 0;		/* Left over bits from last line     */
      pvt->width    = inf->width;
      pvt->depth    = inf->depth;
      pvt->stride   = outf->stride;
      pvt->pitch    = outf->pitch;
      if(!InitBand(flo,ped,sbnd,NO_DATAMAP,(CARD32)1,NO_INPLACE) ||
	 !InitBand(flo,ped,dbnd,NO_DATAMAP,(CARD32)0,NO_INPLACE))
	return(FALSE);
      inited = TRUE;
    } else {
      *outf = *inf;		/* Pass data into photomap in native format */
      sbnd->receptor->bypass |= 1<<b;
    }
  }
  pet->bandSync = NO_SYNC;
  
  return(inited ? TRUE :
	 /* Allows data manager to bypass element entirely */
	 InitReceptor(flo,ped,pet->receptor,NO_DATAMAP,1,NO_BANDS,ALL_BANDS));
}                               /* end InitializeEPhotoUncomByPlane */

/*------------------------------------------------------------------------
----------------------------- crank some data ----------------------------
------------------------------------------------------------------------*/
static int ActivateEPhotoUncomByPlane(flo,ped,pet)
     floDefPtr flo;
     peDefPtr  ped;
     peTexPtr  pet;
{
  meUncompPtr           pvt = (meUncompPtr)pet->private;
  receptorPtr           rcp = pet->receptor;
  CARD32              bands = rcp->inFlo->bands;
  bandPtr              sbnd = rcp->band, dbnd;
  CARD32 b, olddlen, nextdlen, width, stride, pitch;
  pointer src;
  CARD8 *dst;
  
  for(b = 0; b < bands; ++sbnd, ++b, ++pvt) {
    dbnd     = &pet->emitter[pvt->bandMap];
    width    = sbnd->format->width;
    pitch    = dbnd->format->pitch;
    stride   = dbnd->format->stride;
    nextdlen = pvt->bitOff + pitch + 7 >> 3;
    
    if (!(pet->scheduled & 1<<b)) continue;	/* This band is bypassed */
    
    src      = GetCurrentSrc(flo,pet,sbnd);
    dst      = (CARD8*)GetDstBytes(flo,pet,dbnd,dbnd->current,nextdlen,KEEP);
    
    while(!ferrCode(flo) && src && dst) {
      
      (*pvt->action)(src,dst,pvt);
      
      src         = GetNextSrc(flo,pet,sbnd,FLUSH);
      pvt->bitOff = pvt->bitOff + pitch & 7;  /* Set next */
      olddlen     = (pvt->bitOff) ? nextdlen - 1: nextdlen;
      nextdlen    = pvt->bitOff + pitch + 7 >> 3;
      dst         = (CARD8*)GetDstBytes(flo,pet,dbnd,dbnd->current+olddlen,
					nextdlen,KEEP);
    }
    FreeData(flo,pet,sbnd,sbnd->current);

    if(!src && sbnd->final) {
      if (pvt->bitOff) /* If we have any bits left, send them out now */
	*(CARD8*)GetDstBytes(flo,pet,dbnd,dbnd->current,1,KEEP)=pvt->leftOver;

      SetBandFinal(dbnd);
      PutData(flo,pet,dbnd,dbnd->maxGlobal);   /* write the remaining data */
    }
  }
  return(TRUE);
}                               /* end ActivateEPhotoUncomByPlane  */


#if XIE_FULL
/*------------------------------------------------------------------------
---------------------------- initialize peTex . . . ----------------------
------------------------------------------------------------------------*/
static int InitializeEPhotoUncomByPixel(flo,ped) 
     floDefPtr flo;
     peDefPtr  ped;
{
  peTexPtr                 pet = ped->peTex;
  meUncompPtr              pvt = (meUncompPtr)pet->private;
  xieTecEncodeUncompressedTriple *tec =
			(xieTecEncodeUncompressedTriple *)
			((ePhotoDefPtr)ped->elemPvt)->encodeParms;
  formatPtr	          outf = pet->emitter[0].format;
  bandPtr sbnd1,sbnd2,sbnd3;
  CARD32 depth1,depth2,depth3,dstride;
  int s, d;
  
  pvt->unaligned = (tec->pixelStride[0] & 7) != 0;
  
  if(tec->bandOrder == xieValLSFirst)
    for(d = 0; d < xieValMaxBands; ++d)
      pvt[d].bandMap = d;
  else 
    for(s = 0, d = xieValMaxBands; d--; ++s)
      pvt[s].bandMap = d;
  
  sbnd1   = &pet->receptor[SRCtag].band[pvt[0].bandMap];
  sbnd2   = &pet->receptor[SRCtag].band[pvt[1].bandMap];
  sbnd3   = &pet->receptor[SRCtag].band[pvt[2].bandMap];
  depth1  = pvt[0].depth = sbnd1->format->depth;
  depth2  = pvt[1].depth = sbnd2->format->depth;
  depth3  = pvt[2].depth = sbnd3->format->depth;
  dstride = tec->pixelStride[0]>>3;
  pvt[0].width = pvt[1].width = pvt[2].width = sbnd1->format->width;

  if (!pvt->unaligned) {
    /* Look for special cases */
    if (depth1 == 16 && depth2 == 16 && depth3 == 16) {
#if (IMAGE_BYTE_ORDER == MSBFirst)
      void (*pa)() = (tec->pixelOrder == xieValMSFirst) ? PtoIS : sPtoIS;
#else
      void (*pa)() = (tec->pixelOrder == xieValMSFirst) ? sPtoIS : PtoIS;
#endif
      for(s = 0; s < xieValMaxBands; s++, pvt++) {
	pvt->action    = pa;
	pvt->Bstride   = dstride;
	pvt->dstoffset = s;
	pvt->mask      = 0; /* Unused */
	pvt->shift     = 0; /* Unused */
	pvt->clear_dst = FALSE;
      }
    } else if (depth1 == 8 && depth2 == 8 && depth3 == 8) {
      for(s = 0; s < xieValMaxBands; s++, pvt++) {
	pvt->action    = BtoIS;
	pvt->Bstride   = dstride;
	pvt->dstoffset = s;
	pvt->mask      = 0; /* Unused */
	pvt->shift     = 0; /* Unused */
	pvt->clear_dst = FALSE;
      }
    } else if (depth1 == 4 && depth2 == 4 && depth3 == 4) {
      if (tec->fillOrder == xieValMSFirst) {
	pvt->action    = BtoISb;
	pvt->Bstride   = dstride;
	pvt->dstoffset = 0;
	pvt->mask      = 0xf0; 
	pvt->clear_dst = FALSE;
	(pvt++)->shift = 4; 
	pvt->action    = BtoISb;
	pvt->Bstride   = dstride;
	pvt->dstoffset = 0;
	pvt->mask      = 0x0f; 
	pvt->clear_dst = FALSE;
	(pvt++)->shift = 0; 
	pvt->action    = BtoISb;
	pvt->Bstride   = dstride;
	pvt->dstoffset = 1;
	pvt->mask      = 0xf0; 
	pvt->clear_dst = FALSE;
	pvt->shift     = 4; 
      } else { /* xieValLSFirst */
	pvt->action    = BtoISb;
	pvt->Bstride   = dstride;
	pvt->dstoffset = 0;
	pvt->clear_dst = FALSE;
	pvt->mask      = 0x0f; 
	(pvt++)->shift = 0; 
	pvt->action    = BtoISb;
	pvt->Bstride   = dstride;
	pvt->dstoffset = 0;
	pvt->mask      = 0xf0; 
	pvt->clear_dst = FALSE;
	(pvt++)->shift = 4; 
	pvt->action    = BtoISb;
	pvt->Bstride   = dstride;
	pvt->dstoffset = 1;
	pvt->mask      = 0x0f; 
	pvt->clear_dst = FALSE;
	pvt->shift     = 0; 
      }
    } else if (depth1 + depth2 + depth3 <= 8) {
      CARD8 ones = 0xff,smask1,smask2,smask3,shift1,shift2,shift3;
      if (tec->fillOrder == xieValMSFirst) {
	smask1 = ~(ones>>depth1);
	smask2 = ~(ones>>(depth1 + depth2) | smask1);
	smask3 = ~(ones>>(depth1 + depth2 + depth3) | smask1 | smask2);
	shift1 = 8 - depth1;
	shift2 = 8 - (depth1 + depth2);
	shift3 = 8 - (depth1 + depth2 + depth3);
      } else { /* fillOrder == xieValLSFirst */
	smask3 = ~(ones<<depth3);
	smask2 = ~(ones<<(depth2 + depth3) | smask3);
	smask1 = ~(ones<<(depth1 + depth2 + depth3) | smask2 | smask3);
	shift3 = 0;
	shift2 = depth3;
	shift1 = depth2 + depth3;
      }
      pvt->action    = (depth1 > 1) ? BtoISb : btoISb;
      pvt->Bstride   = dstride;
      pvt->dstoffset = 0;
      pvt->mask      = smask1;
      pvt->clear_dst = TRUE;
      (pvt++)->shift = shift1;
      pvt->action    = (depth2 > 1) ? BtoISb : btoISb;
      pvt->Bstride   = dstride;
      pvt->dstoffset = 0;
      pvt->mask      = smask2;
      pvt->clear_dst = TRUE;
      (pvt++)->shift = shift2; 
      pvt->action    = (depth3 > 1) ? BtoISb : btoISb;
      pvt->Bstride   = dstride;
      pvt->dstoffset = 0;
      pvt->mask      = smask3;
      pvt->clear_dst = TRUE;
      pvt->shift     = shift3; 
    } else
	pvt->unaligned = TRUE;
  } 
  pvt = (meUncompPtr)pet->private;
  if (pvt->unaligned) { 
    /* No special cases, do it the hard way */
    pvt[0].pitch = outf->pitch;
    pvt->action = EncodeTripleFuncs[tec->pixelOrder == xieValLSFirst ? 0 : 1]
				   [tec->fillOrder  == xieValLSFirst ? 0 : 1]
				   [depth1 <= 8 ? 0 : 1]
				   [depth2 <= 8 ? 0 : 1]
				   [depth3 <= 8 ? 0 : 1];
    if(depth1 == 1 && !(pvt[0].buf = (pointer)XieMalloc(pvt[0].width+7)) ||
       depth2 == 1 && !(pvt[1].buf = (pointer)XieMalloc(pvt[1].width+7)) ||
       depth3 == 1 && !(pvt[2].buf = (pointer)XieMalloc(pvt[2].width+7)))
      AllocError(flo,ped, return(FALSE));
  }
  pet->bandSync = SYNC;
  
  return(InitReceptors(flo, ped, NO_DATAMAP, 1) && 
	 InitEmitter(flo, ped, NO_DATAMAP, NO_INPLACE));
}                               /* end InitializeEPhotoUncomByPixel */


/*------------------------------------------------------------------------
----------------------------- crank some data ----------------------------
------------------------------------------------------------------------*/
static int ActivateEPhotoUncomByPixel(flo,ped,pet)
     floDefPtr flo;
     peDefPtr  ped;
     peTexPtr  pet;
{
  meUncompPtr pvt = (meUncompPtr)pet->private;
  bandPtr   sb0 = &pet->receptor[SRCtag].band[pvt[0].bandMap];
  bandPtr   sb1 = &pet->receptor[SRCtag].band[pvt[1].bandMap];
  bandPtr   sb2 = &pet->receptor[SRCtag].band[pvt[2].bandMap];
  bandPtr  dbnd = &pet->emitter[0];
  CARD32  pitch = dbnd->format->pitch;
  pointer sp0 = (pointer )NULL, sp1 = (pointer )NULL, sp2 = (pointer )NULL;
  CARD8 *dst;
  
  
  if (pvt->unaligned) {
    CARD32 stride   = dbnd->format->stride;
    CARD32 width    = dbnd->format->width;
    CARD32 nextdlen = pvt->bitOff + pitch + 7 >> 3, olddlen;
    if((sp0 = GetCurrentSrc(flo,pet,sb0)) &&
       (sp1 = GetCurrentSrc(flo,pet,sb1)) && 
       (sp2 = GetCurrentSrc(flo,pet,sb2)) &&
       (dst = (BytePixel*)GetDstBytes(flo,pet,dbnd,dbnd->current,
				      nextdlen,KEEP)))
      do {
	if(pvt[0].buf) sp0 = bitexpand(sp0,pvt[0].buf,width,(char)0,(char)1);
	if(pvt[1].buf) sp1 = bitexpand(sp1,pvt[1].buf,width,(char)0,(char)1);
	if(pvt[2].buf) sp2 = bitexpand(sp2,pvt[2].buf,width,(char)0,(char)1);

	(*pvt->action)(sp0,sp1,sp2,dst,stride,pvt);
	
	sp0         = GetNextSrc(flo,pet,sb0,FLUSH);
	sp1         = GetNextSrc(flo,pet,sb1,FLUSH);
	sp2         = GetNextSrc(flo,pet,sb2,FLUSH);
	pvt->bitOff = pvt->bitOff + pitch & 7;  /* Set next */
	olddlen     = (pvt->bitOff) ? nextdlen - 1 : nextdlen;
	nextdlen    = pvt->bitOff + pitch + 7 >> 3;
	dst         = (BytePixel*)GetDstBytes(flo,pet,dbnd,
					dbnd->current+olddlen,nextdlen,KEEP);
      } while(dst && sp0 && sp1 && sp2);

  } else {
    CARD32  dlen  = pitch >> 3;	/* For nicely aligned data */
    if((sp0 = GetCurrentSrc(flo,pet,sb0)) &&
       (sp1 = GetCurrentSrc(flo,pet,sb1)) && 
       (sp2 = GetCurrentSrc(flo,pet,sb2)) &&
       (dst = (BytePixel*)GetDstBytes(flo,pet,dbnd,dbnd->current,dlen,KEEP)))

      do {
	
	if (pvt[0].clear_dst) bzero(dst,(int)dlen);
	
	(*pvt[0].action)(sp0,dst,&pvt[0]);
	(*pvt[1].action)(sp1,dst,&pvt[1]);
	(*pvt[2].action)(sp2,dst,&pvt[2]);
	
	sp0 = GetNextSrc(flo,pet,sb0,FLUSH);
	sp1 = GetNextSrc(flo,pet,sb1,FLUSH);
	sp2 = GetNextSrc(flo,pet,sb2,FLUSH);
	dst = (BytePixel*)GetDstBytes(flo,pet,dbnd,dbnd->current+dlen,
				      dlen,KEEP);
      } while(dst && sp0 && sp1 && sp2);
  }
  
  FreeData(flo,pet,sb0,sb0->current);
  FreeData(flo,pet,sb1,sb1->current);
  FreeData(flo,pet,sb2,sb2->current);

  if(!sp0 && sb0->final && !sp1 && sb1->final && !sp2 && sb2->final) {
    if (pvt->bitOff) /* If we have any bits left, send them out now */
      *(CARD8*)GetDstBytes(flo,pet,dbnd,dbnd->current,1,KEEP) = pvt->leftOver;

    SetBandFinal(dbnd);
    PutData(flo,pet,dbnd,dbnd->maxGlobal);   /* write the remaining data */
  }
  
  return(TRUE);
}                               /* end ActivateEPhotoUncomByPixel */
#endif /* XIE_FULL */

/*------------------------------------------------------------------------
------------------------ get rid of run-time stuff -----------------------
------------------------------------------------------------------------*/
static int ResetEPhoto(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  meUncompPtr pvt = (meUncompPtr)ped->peTex->private;
  int i;

  for(i = 0; i < xieValMaxBands; ++i)
    if(pvt[i].buf) pvt[i].buf = (pointer) XieFree(pvt[i].buf);

  ResetReceptors(ped);
  ResetEmitter(ped);
  
  return(TRUE);
}                               /* end ResetEPhoto */

/*------------------------------------------------------------------------
-------------------------- get rid of this element -----------------------
------------------------------------------------------------------------*/
static int DestroyEPhoto(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  /* get rid of the peTex structure  */
  ped->peTex = (peTexPtr) XieFree(ped->peTex);

  /* zap this element's entry point vector */
  ped->ddVec.create     = (xieIntProc) NULL;
  ped->ddVec.initialize = (xieIntProc) NULL;
  ped->ddVec.activate   = (xieIntProc) NULL;
  ped->ddVec.reset      = (xieIntProc) NULL;
  ped->ddVec.destroy    = (xieIntProc) NULL;

  return(TRUE);
}                               /* end DestroyEPhoto */

/* end module mephoto.c */