~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/XIE/mixie/export/mephoto.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: mephoto.c,v 1.4 2001/02/09 02:04:24 xorgcvs Exp $ */
 
2
/**** module mephoto.c ****/
 
3
/******************************************************************************
 
4
 
 
5
Copyright 1993, 1994, 1998  The Open Group
 
6
 
 
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
 
11
documentation.
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
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.
 
22
 
 
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.
 
26
 
 
27
 
 
28
                                NOTICE
 
29
                              
 
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
 
33
terms and conditions:
 
34
 
 
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.
 
42
     
 
43
     "Copyright 1993, 1994 by AGE Logic, Inc."
 
44
     
 
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
 
58
     DAMAGES.
 
59
    
 
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.
 
63
 
 
64
     Title to this software shall at all times remain with AGE
 
65
     Logic, Inc.
 
66
*****************************************************************************
 
67
  
 
68
        mephoto.c -- DDXIE prototype export photomap element
 
69
  
 
70
        Robert NC Shelley -- AGE Logic, Inc. June, 1993
 
71
        Dean && Ben - various additions to handle different techniques
 
72
  
 
73
*****************************************************************************/
 
74
/* $XFree86: xc/programs/Xserver/XIE/mixie/export/mephoto.c,v 3.6 2001/12/14 19:58:20 dawes Exp $ */
 
75
 
 
76
#define _XIEC_MEPHOTO
 
77
#define _XIEC_EPHOTO
 
78
 
 
79
/*
 
80
 *  Include files
 
81
 */
 
82
 
 
83
/*
 
84
 *  Core X Includes
 
85
 */
 
86
#include <X.h>
 
87
#include <Xproto.h>
 
88
/*
 
89
 *  XIE Includes
 
90
 */
 
91
#include <XIE.h>
 
92
#include <XIEproto.h>
 
93
/*
 
94
 *  more X server includes.
 
95
 */
 
96
#include <misc.h>
 
97
#include <dixstruct.h>
 
98
/*
 
99
 *  Server XIE Includes
 
100
 */
 
101
#include <error.h>
 
102
#include <macro.h>
 
103
#include <photomap.h>
 
104
#include <element.h>
 
105
#include <texstr.h>
 
106
#include <xiemd.h>
 
107
#include <meuncomp.h>
 
108
#include <memory.h>
 
109
 
 
110
/*
 
111
 *  routines used internal to this module
 
112
 */
 
113
static int CreateEPhotoUncom(floDefPtr flo, peDefPtr ped);
 
114
static int InitializeEPhotoBypass(floDefPtr flo, peDefPtr ped);
 
115
static int InitializeEPhotoUncomByPlane(floDefPtr flo, peDefPtr ped);
 
116
static int ActivateEPhotoUncomByPlane(floDefPtr flo, peDefPtr ped, peTexPtr pet);
 
117
static int ResetEPhoto(floDefPtr flo, peDefPtr ped);
 
118
static int DestroyEPhoto(floDefPtr flo, peDefPtr ped);
 
119
 
 
120
#if XIE_FULL
 
121
static int InitializeEPhotoUncomByPixel(floDefPtr flo, peDefPtr ped);
 
122
static int ActivateEPhotoUncomByPixel(floDefPtr flo, peDefPtr ped, peTexPtr pet);
 
123
#endif /* XIE_FULL */
 
124
 
 
125
 
 
126
/*
 
127
 * routines we need from somewhere else
 
128
 */
 
129
 
 
130
extern int CreateEPhotoJPEGBaseline();
 
131
extern int InitializeEPhotoJPEGBaseline();
 
132
extern int ActivateEPhotoJPEGBaseline();
 
133
extern int ResetEPhotoJPEGBaseline();
 
134
extern int DestroyEPhotoJPEGBaseline();
 
135
 
 
136
extern int CreateEPhotoFAX();
 
137
extern int InitializeEPhotoFAX();
 
138
extern int ActivateEPhotoFAX();
 
139
extern int ResetEPhotoFAX();
 
140
extern int DestroyEPhotoFAX();
 
141
 
 
142
/*
 
143
 * DDXIE ExportPhotomap entry points
 
144
 */
 
145
static ddElemVecRec EPhotoBypassVec = {
 
146
  CreateEPhotoUncom,
 
147
  InitializeEPhotoBypass,
 
148
  (xieIntProc)NULL,
 
149
  (xieIntProc)NULL,
 
150
  ResetEPhoto,
 
151
  DestroyEPhoto
 
152
  };
 
153
 
 
154
static ddElemVecRec EPhotoUncomByPlaneVec = {
 
155
  CreateEPhotoUncom,
 
156
  InitializeEPhotoUncomByPlane,
 
157
  ActivateEPhotoUncomByPlane,
 
158
  (xieIntProc)NULL,
 
159
  ResetEPhoto,
 
160
  DestroyEPhoto
 
161
  };
 
162
 
 
163
static ddElemVecRec EPhotoFAXVec = {
 
164
  CreateEPhotoFAX,
 
165
  InitializeEPhotoFAX,
 
166
  ActivateEPhotoFAX,
 
167
  (xieIntProc)NULL,
 
168
  ResetEPhotoFAX,
 
169
  DestroyEPhotoFAX
 
170
  };
 
171
 
 
172
#if XIE_FULL
 
173
static ddElemVecRec EPhotoUncomByPixelVec = {
 
174
  CreateEPhotoUncom,
 
175
  InitializeEPhotoUncomByPixel,
 
176
  ActivateEPhotoUncomByPixel,
 
177
  (xieIntProc)NULL,
 
178
  ResetEPhoto,
 
179
  DestroyEPhoto
 
180
  };
 
181
 
 
182
static ddElemVecRec EPhotoJPEGBaselineVec = {
 
183
  CreateEPhotoJPEGBaseline,
 
184
  InitializeEPhotoJPEGBaseline,
 
185
  ActivateEPhotoJPEGBaseline,
 
186
  (xieIntProc)NULL,
 
187
  ResetEPhotoJPEGBaseline,
 
188
  DestroyEPhotoJPEGBaseline
 
189
  };
 
190
#endif /* XIE_FULL */
 
191
 
 
192
 
 
193
/*------------------------------------------------------------------------
 
194
------------------- see if we can handle this element --------------------
 
195
------------------------------------------------------------------------*/
 
196
int miAnalyzeEPhoto(floDefPtr flo, peDefPtr ped)
 
197
{
 
198
  ePhotoDefPtr pvt = (ePhotoDefPtr)ped->elemPvt;
 
199
 
 
200
  if(pvt->congress) {
 
201
    ped->ddVec = EPhotoBypassVec;
 
202
    return(TRUE);
 
203
  }
 
204
  switch(pvt->encodeNumber) {
 
205
 
 
206
  case xieValEncodeUncompressedSingle:
 
207
    ped->ddVec = EPhotoUncomByPlaneVec;
 
208
    break;
 
209
      
 
210
  case xieValEncodeG31D:
 
211
  case xieValEncodeG32D:
 
212
  case xieValEncodeG42D:
 
213
  case xieValEncodeTIFF2:
 
214
  case xieValEncodeTIFFPackBits:
 
215
    ped->ddVec = EPhotoFAXVec;
 
216
    break;
 
217
      
 
218
#if XIE_FULL
 
219
  case xieValEncodeUncompressedTriple:
 
220
    {
 
221
        xieTecEncodeUncompressedTriple *tecParms = 
 
222
                 (xieTecEncodeUncompressedTriple *)pvt->encodeParms;
 
223
        if(tecParms->interleave == xieValBandByPlane)
 
224
          ped->ddVec = EPhotoUncomByPlaneVec;
 
225
        else
 
226
          ped->ddVec = EPhotoUncomByPixelVec;
 
227
    }
 
228
    break;
 
229
  case xieValEncodeJPEGBaseline:
 
230
    { /*** JPEG for SI can only handle 8 bit image depths ***/
 
231
      inFloPtr inf  = &ped->inFloLst[IMPORT];
 
232
      outFloPtr src = &inf->srcDef->outFlo;
 
233
      int b;
 
234
      for (b=0; b< src->bands; ++b) 
 
235
        if(src->format[b].depth != 8) {
 
236
          xieFloExportPhotomap *raw = (xieFloExportPhotomap *)ped->elemRaw;
 
237
 
 
238
          TechniqueError(flo, ped, xieValEncode,
 
239
                         raw->encodeTechnique, raw->lenParams, return(FALSE));
 
240
        }
 
241
    }
 
242
    ped->ddVec = EPhotoJPEGBaselineVec;
 
243
    break;
 
244
  case xieValEncodeJPEGLossless:
 
245
#endif /* XIE_FULL */
 
246
  default:  ImplementationError(flo,ped, return(FALSE));
 
247
  }
 
248
  return(TRUE);
 
249
}                               /* end miAnalyzeEPhoto */
 
250
 
 
251
/*------------------------------------------------------------------------
 
252
---------------------------- create peTex . . . --------------------------
 
253
------------------------------------------------------------------------*/
 
254
static int CreateEPhotoUncom(floDefPtr flo, peDefPtr ped)
 
255
{
 
256
  /* attach an execution context to the photo element definition */
 
257
  return(MakePETex(flo, ped, xieValMaxBands * sizeof(meUncompRec), 
 
258
                                NO_SYNC, NO_SYNC));
 
259
}                               /* end CreateEPhotoUncom */
 
260
 
 
261
/*------------------------------------------------------------------------
 
262
---------------------------- initialize peTex . . . ----------------------
 
263
------------------------------------------------------------------------*/
 
264
static int InitializeEPhotoBypass(floDefPtr flo, peDefPtr ped)
 
265
{
 
266
  /* Allows data manager to bypass element entirely */
 
267
  return(InitReceptor(flo, ped, ped->peTex->receptor,
 
268
                      NO_DATAMAP, 1, NO_BANDS, ALL_BANDS));
 
269
}                               /* end InitializeEPhotoBypass */
 
270
 
 
271
/*------------------------------------------------------------------------
 
272
---------------------------- initialize peTex . . . ----------------------
 
273
------------------------------------------------------------------------*/
 
274
static int InitializeEPhotoUncomByPlane(floDefPtr flo, peDefPtr ped)
 
275
{
 
276
  peTexPtr              pet = ped->peTex;
 
277
  meUncompPtr           pvt = (meUncompPtr)pet->private;
 
278
  formatPtr             inf = ped->inFloLst[SRCtag].format;
 
279
  bandPtr              sbnd = pet->receptor->band;
 
280
  CARD32             nbands = ped->outFlo.bands, b, s;
 
281
  xieTypOrientation pixelOrder, fillOrder;
 
282
  Bool inited = FALSE;
 
283
  
 
284
  if (nbands == 1) {
 
285
    xieTecEncodeUncompressedSingle *tecParms = 
 
286
                                (xieTecEncodeUncompressedSingle *)
 
287
                                ((ePhotoDefPtr)ped->elemPvt)->encodeParms;
 
288
    pixelOrder = tecParms->pixelOrder;
 
289
    fillOrder  = tecParms->fillOrder;
 
290
    pvt[0].bandMap = 0;
 
291
  } else {
 
292
    xieTecEncodeUncompressedTriple *tecParms = 
 
293
                                (xieTecEncodeUncompressedTriple *)
 
294
                                ((ePhotoDefPtr)ped->elemPvt)->encodeParms;
 
295
    pixelOrder = tecParms->pixelOrder;
 
296
    fillOrder  = tecParms->fillOrder;
 
297
    if(tecParms->bandOrder == xieValLSFirst) 
 
298
      for(b = 0; b < xieValMaxBands; ++b)
 
299
        pvt[b].bandMap = b;
 
300
    else 
 
301
      for(s = 0, b = xieValMaxBands; b--; ++s)
 
302
        pvt[s].bandMap = b;
 
303
  }
 
304
  for (b = 0; b < nbands; b++, pvt++, inf++, sbnd++) {
 
305
    bandPtr   dbnd = &pet->emitter[pvt->bandMap];
 
306
    formatPtr outf = &ped->outFlo.format[pvt->bandMap];
 
307
    CARD8 class    = inf->class;
 
308
    if (class == BIT_PIXEL) {
 
309
          pvt->width  = inf->width;
 
310
#if (IMAGE_BYTE_ORDER == MSBFirst)
 
311
          if (outf->stride != 1) {
 
312
              pvt->action = (fillOrder == xieValMSFirst) ? btoIS: sbtoIS;
 
313
          } else {
 
314
              pvt->action = (fillOrder == xieValMSFirst) ? 
 
315
                                                (void (*)())NULL : sbtoS;
 
316
          }
 
317
#else
 
318
          if (outf->stride != 1) {
 
319
              pvt->action = (fillOrder == xieValLSFirst) ? btoIS: sbtoIS;
 
320
          } else {
 
321
              pvt->action = (fillOrder == xieValLSFirst) ? 
 
322
                                                (void (*)())NULL : sbtoS;
 
323
          }
 
324
#endif
 
325
          pvt->stride = outf->stride;
 
326
          pvt->pitch  = outf->pitch;
 
327
    } else if (class == BYTE_PIXEL)  {
 
328
          pvt->width = inf->width;
 
329
          if (!(outf->stride & 7)) {
 
330
              if (outf->stride == 8)
 
331
                  pvt->action = BtoS;
 
332
              else
 
333
                  pvt->action = BtoIS;
 
334
              pvt->Bstride   = outf->stride >> 3;
 
335
              pvt->dstoffset = 0;
 
336
              pvt->mask      = 0; /* Unused */
 
337
              pvt->shift     = 0; /* Unused */
 
338
              pvt->clear_dst = FALSE;
 
339
          } else {
 
340
              if (pixelOrder == xieValLSFirst) {
 
341
                  if (fillOrder == xieValLSFirst) 
 
342
                      pvt->action = BtoLLUB;
 
343
                  else 
 
344
                      pvt->action = BtoLMUB;
 
345
              } else {
 
346
                  if (fillOrder == xieValLSFirst) 
 
347
                      pvt->action = BtoMLUB;
 
348
                  else 
 
349
                      pvt->action = BtoMMUB;
 
350
              } 
 
351
              pvt->bitOff   = 0;        /* Bit offset to first pixel on line */
 
352
              pvt->leftOver = 0;        /* Left over bits from last line     */
 
353
              pvt->depth    = inf->depth;
 
354
              pvt->stride   = outf->stride;
 
355
              pvt->pitch    = outf->pitch;
 
356
          } 
 
357
    } else if (class == PAIR_PIXEL) {
 
358
          pvt->width = inf->width;
 
359
          if (!(outf->stride & 15)) {
 
360
#if (IMAGE_BYTE_ORDER == LSBFirst)
 
361
              if (outf->stride == 16)
 
362
                  pvt->action = (fillOrder == xieValLSFirst) ? 
 
363
                                                (void (*)())NULL : sPtoS;
 
364
              else
 
365
                  pvt->action = (fillOrder == xieValLSFirst) ? PtoIS: sPtoIS;
 
366
#else
 
367
              if (outf->stride == 16)
 
368
                  pvt->action = (fillOrder == xieValMSFirst) ? 
 
369
                                                (void (*)())NULL : sPtoS;
 
370
              else
 
371
                  pvt->action = (fillOrder == xieValMSFirst) ? PtoIS: sPtoIS;
 
372
#endif
 
373
              pvt->Bstride   = outf->stride >> 3;
 
374
              pvt->dstoffset = 0;
 
375
              pvt->mask      = 0; /* Unused */
 
376
              pvt->shift     = 0; /* Unused */
 
377
              pvt->clear_dst = FALSE;
 
378
          } else {
 
379
              if (pixelOrder == xieValLSFirst) {
 
380
                  if (fillOrder == xieValLSFirst) 
 
381
                      pvt->action = PtoLLUP;
 
382
                  else 
 
383
                      pvt->action = PtoLMUP;
 
384
              } else {
 
385
                  if (fillOrder == xieValLSFirst) 
 
386
                      pvt->action = PtoMLUP;
 
387
                  else 
 
388
                      pvt->action = PtoMMUP;
 
389
              } 
 
390
              pvt->bitOff   = 0;        /* Bit offset to first pixel on line */
 
391
              pvt->leftOver = 0;        /* Left over bits from last line     */
 
392
              pvt->depth    = inf->depth;
 
393
              pvt->stride   = outf->stride;
 
394
              pvt->pitch    = outf->pitch;
 
395
          } 
 
396
    } else if (class == QUAD_PIXEL) {
 
397
          pvt->width = inf->width;
 
398
          if (!(outf->stride & 31)) {
 
399
#if (IMAGE_BYTE_ORDER == LSBFirst)
 
400
              if (outf->stride == 32)
 
401
                  pvt->action = (fillOrder == xieValLSFirst) ? 
 
402
                                                (void (*)())NULL : sQtoS;
 
403
              else
 
404
                  pvt->action = (fillOrder == xieValLSFirst) ? QtoIS: sQtoIS;
 
405
#else
 
406
              if (outf->stride == 32)
 
407
                  pvt->action = (fillOrder == xieValMSFirst) ? 
 
408
                                                (void (*)())NULL : sQtoS;
 
409
              else
 
410
                  pvt->action = (fillOrder == xieValMSFirst) ? QtoIS: sQtoIS;
 
411
#endif
 
412
              pvt->Bstride   = outf->stride >> 3;
 
413
              pvt->dstoffset = 0;
 
414
              pvt->mask      = 0; /* Unused */
 
415
              pvt->shift     = 0; /* Unused */
 
416
              pvt->clear_dst = FALSE;
 
417
          } else {
 
418
              if (pixelOrder == xieValLSFirst) {
 
419
                  if (fillOrder == xieValLSFirst) 
 
420
                      pvt->action = QtoLLUQ;
 
421
                  else 
 
422
                      pvt->action = QtoLMUQ;
 
423
              } else {
 
424
                  if (fillOrder == xieValLSFirst) 
 
425
                      pvt->action = QtoMLUQ;
 
426
                  else 
 
427
                      pvt->action = QtoMMUQ;
 
428
              } 
 
429
          } 
 
430
      } else
 
431
        ImplementationError(flo,ped, return(FALSE)); 
 
432
    
 
433
    if (pvt->action) {
 
434
      pvt->bitOff   = 0;                /* Bit offset to first pixel on line */
 
435
      pvt->leftOver = 0;                /* Left over bits from last line     */
 
436
      pvt->width    = inf->width;
 
437
      pvt->depth    = inf->depth;
 
438
      pvt->stride   = outf->stride;
 
439
      pvt->pitch    = outf->pitch;
 
440
      if(!InitBand(flo,ped,sbnd,NO_DATAMAP,(CARD32)1,NO_INPLACE) ||
 
441
         !InitBand(flo,ped,dbnd,NO_DATAMAP,(CARD32)0,NO_INPLACE))
 
442
        return(FALSE);
 
443
      inited = TRUE;
 
444
    } else {
 
445
      *outf = *inf;             /* Pass data into photomap in native format */
 
446
      sbnd->receptor->bypass |= 1<<b;
 
447
    }
 
448
  }
 
449
  pet->bandSync = NO_SYNC;
 
450
  
 
451
  return(inited ? TRUE :
 
452
         /* Allows data manager to bypass element entirely */
 
453
         InitReceptor(flo,ped,pet->receptor,NO_DATAMAP,1,NO_BANDS,ALL_BANDS));
 
454
}                               /* end InitializeEPhotoUncomByPlane */
 
455
 
 
456
/*------------------------------------------------------------------------
 
457
----------------------------- crank some data ----------------------------
 
458
------------------------------------------------------------------------*/
 
459
static int ActivateEPhotoUncomByPlane(floDefPtr flo, peDefPtr ped, peTexPtr pet)
 
460
{
 
461
  meUncompPtr           pvt = (meUncompPtr)pet->private;
 
462
  receptorPtr           rcp = pet->receptor;
 
463
  CARD32              bands = rcp->inFlo->bands;
 
464
  bandPtr              sbnd = rcp->band, dbnd;
 
465
  CARD32 b, olddlen, nextdlen, width, stride, pitch;
 
466
  pointer src;
 
467
  CARD8 *dst;
 
468
  
 
469
  for(b = 0; b < bands; ++sbnd, ++b, ++pvt) {
 
470
    dbnd     = &pet->emitter[pvt->bandMap];
 
471
    width    = sbnd->format->width;
 
472
    pitch    = dbnd->format->pitch;
 
473
    stride   = dbnd->format->stride;
 
474
    nextdlen = (pvt->bitOff + pitch + 7) >> 3;
 
475
    
 
476
    if (!(pet->scheduled & 1<<b)) continue;     /* This band is bypassed */
 
477
    
 
478
    src      = GetCurrentSrc(flo,pet,sbnd);
 
479
    dst      = (CARD8*)GetDstBytes(flo,pet,dbnd,dbnd->current,nextdlen,KEEP);
 
480
    
 
481
    while(!ferrCode(flo) && src && dst) {
 
482
      
 
483
      (*pvt->action)(src,dst,pvt);
 
484
      
 
485
      src         = GetNextSrc(flo,pet,sbnd,FLUSH);
 
486
      pvt->bitOff = (pvt->bitOff + pitch) & 7;  /* Set next */
 
487
      olddlen     = (pvt->bitOff) ? nextdlen - 1: nextdlen;
 
488
      nextdlen    = (pvt->bitOff + pitch + 7) >> 3;
 
489
      dst         = (CARD8*)GetDstBytes(flo,pet,dbnd,dbnd->current+olddlen,
 
490
                                        nextdlen,KEEP);
 
491
    }
 
492
    FreeData(flo,pet,sbnd,sbnd->current);
 
493
 
 
494
    if(!src && sbnd->final) {
 
495
      if (pvt->bitOff) /* If we have any bits left, send them out now */
 
496
        *(CARD8*)GetDstBytes(flo,pet,dbnd,dbnd->current,1,KEEP)=pvt->leftOver;
 
497
 
 
498
      SetBandFinal(dbnd);
 
499
      PutData(flo,pet,dbnd,dbnd->maxGlobal);   /* write the remaining data */
 
500
    }
 
501
  }
 
502
  return(TRUE);
 
503
}                               /* end ActivateEPhotoUncomByPlane  */
 
504
 
 
505
 
 
506
#if XIE_FULL
 
507
/*------------------------------------------------------------------------
 
508
---------------------------- initialize peTex . . . ----------------------
 
509
------------------------------------------------------------------------*/
 
510
static int InitializeEPhotoUncomByPixel(floDefPtr flo, peDefPtr ped)
 
511
{
 
512
  peTexPtr                 pet = ped->peTex;
 
513
  meUncompPtr              pvt = (meUncompPtr)pet->private;
 
514
  xieTecEncodeUncompressedTriple *tec =
 
515
                        (xieTecEncodeUncompressedTriple *)
 
516
                        ((ePhotoDefPtr)ped->elemPvt)->encodeParms;
 
517
  formatPtr               outf = pet->emitter[0].format;
 
518
  bandPtr sbnd1,sbnd2,sbnd3;
 
519
  CARD32 depth1,depth2,depth3,dstride;
 
520
  int s, d;
 
521
  
 
522
  pvt->unaligned = (tec->pixelStride[0] & 7) != 0;
 
523
  
 
524
  if(tec->bandOrder == xieValLSFirst)
 
525
    for(d = 0; d < xieValMaxBands; ++d)
 
526
      pvt[d].bandMap = d;
 
527
  else 
 
528
    for(s = 0, d = xieValMaxBands; d--; ++s)
 
529
      pvt[s].bandMap = d;
 
530
  
 
531
  sbnd1   = &pet->receptor[SRCtag].band[pvt[0].bandMap];
 
532
  sbnd2   = &pet->receptor[SRCtag].band[pvt[1].bandMap];
 
533
  sbnd3   = &pet->receptor[SRCtag].band[pvt[2].bandMap];
 
534
  depth1  = pvt[0].depth = sbnd1->format->depth;
 
535
  depth2  = pvt[1].depth = sbnd2->format->depth;
 
536
  depth3  = pvt[2].depth = sbnd3->format->depth;
 
537
  dstride = tec->pixelStride[0]>>3;
 
538
  pvt[0].width = pvt[1].width = pvt[2].width = sbnd1->format->width;
 
539
 
 
540
  if (!pvt->unaligned) {
 
541
    /* Look for special cases */
 
542
    if (depth1 == 16 && depth2 == 16 && depth3 == 16) {
 
543
#if (IMAGE_BYTE_ORDER == MSBFirst)
 
544
      void (*pa)() = (tec->pixelOrder == xieValMSFirst) ? PtoIS : sPtoIS;
 
545
#else
 
546
      void (*pa)() = (tec->pixelOrder == xieValMSFirst) ? sPtoIS : PtoIS;
 
547
#endif
 
548
      for(s = 0; s < xieValMaxBands; s++, pvt++) {
 
549
        pvt->action    = pa;
 
550
        pvt->Bstride   = dstride;
 
551
        pvt->dstoffset = s;
 
552
        pvt->mask      = 0; /* Unused */
 
553
        pvt->shift     = 0; /* Unused */
 
554
        pvt->clear_dst = FALSE;
 
555
      }
 
556
    } else if (depth1 == 8 && depth2 == 8 && depth3 == 8) {
 
557
      for(s = 0; s < xieValMaxBands; s++, pvt++) {
 
558
        pvt->action    = BtoIS;
 
559
        pvt->Bstride   = dstride;
 
560
        pvt->dstoffset = s;
 
561
        pvt->mask      = 0; /* Unused */
 
562
        pvt->shift     = 0; /* Unused */
 
563
        pvt->clear_dst = FALSE;
 
564
      }
 
565
    } else if (depth1 == 4 && depth2 == 4 && depth3 == 4) {
 
566
      if (tec->fillOrder == xieValMSFirst) {
 
567
        pvt->action    = BtoISb;
 
568
        pvt->Bstride   = dstride;
 
569
        pvt->dstoffset = 0;
 
570
        pvt->mask      = 0xf0; 
 
571
        pvt->clear_dst = FALSE;
 
572
        (pvt++)->shift = 4; 
 
573
        pvt->action    = BtoISb;
 
574
        pvt->Bstride   = dstride;
 
575
        pvt->dstoffset = 0;
 
576
        pvt->mask      = 0x0f; 
 
577
        pvt->clear_dst = FALSE;
 
578
        (pvt++)->shift = 0; 
 
579
        pvt->action    = BtoISb;
 
580
        pvt->Bstride   = dstride;
 
581
        pvt->dstoffset = 1;
 
582
        pvt->mask      = 0xf0; 
 
583
        pvt->clear_dst = FALSE;
 
584
        pvt->shift     = 4; 
 
585
      } else { /* xieValLSFirst */
 
586
        pvt->action    = BtoISb;
 
587
        pvt->Bstride   = dstride;
 
588
        pvt->dstoffset = 0;
 
589
        pvt->clear_dst = FALSE;
 
590
        pvt->mask      = 0x0f; 
 
591
        (pvt++)->shift = 0; 
 
592
        pvt->action    = BtoISb;
 
593
        pvt->Bstride   = dstride;
 
594
        pvt->dstoffset = 0;
 
595
        pvt->mask      = 0xf0; 
 
596
        pvt->clear_dst = FALSE;
 
597
        (pvt++)->shift = 4; 
 
598
        pvt->action    = BtoISb;
 
599
        pvt->Bstride   = dstride;
 
600
        pvt->dstoffset = 1;
 
601
        pvt->mask      = 0x0f; 
 
602
        pvt->clear_dst = FALSE;
 
603
        pvt->shift     = 0; 
 
604
      }
 
605
    } else if (depth1 + depth2 + depth3 <= 8) {
 
606
      CARD8 ones = 0xff,smask1,smask2,smask3,shift1,shift2,shift3;
 
607
      if (tec->fillOrder == xieValMSFirst) {
 
608
        smask1 = ~(ones>>depth1);
 
609
        smask2 = ~(ones>>(depth1 + depth2) | smask1);
 
610
        smask3 = ~(ones>>(depth1 + depth2 + depth3) | smask1 | smask2);
 
611
        shift1 = 8 - depth1;
 
612
        shift2 = 8 - (depth1 + depth2);
 
613
        shift3 = 8 - (depth1 + depth2 + depth3);
 
614
      } else { /* fillOrder == xieValLSFirst */
 
615
        smask3 = ~(ones<<depth3);
 
616
        smask2 = ~(ones<<(depth2 + depth3) | smask3);
 
617
        smask1 = ~(ones<<(depth1 + depth2 + depth3) | smask2 | smask3);
 
618
        shift3 = 0;
 
619
        shift2 = depth3;
 
620
        shift1 = depth2 + depth3;
 
621
      }
 
622
      pvt->action    = (depth1 > 1) ? BtoISb : btoISb;
 
623
      pvt->Bstride   = dstride;
 
624
      pvt->dstoffset = 0;
 
625
      pvt->mask      = smask1;
 
626
      pvt->clear_dst = TRUE;
 
627
      (pvt++)->shift = shift1;
 
628
      pvt->action    = (depth2 > 1) ? BtoISb : btoISb;
 
629
      pvt->Bstride   = dstride;
 
630
      pvt->dstoffset = 0;
 
631
      pvt->mask      = smask2;
 
632
      pvt->clear_dst = TRUE;
 
633
      (pvt++)->shift = shift2; 
 
634
      pvt->action    = (depth3 > 1) ? BtoISb : btoISb;
 
635
      pvt->Bstride   = dstride;
 
636
      pvt->dstoffset = 0;
 
637
      pvt->mask      = smask3;
 
638
      pvt->clear_dst = TRUE;
 
639
      pvt->shift     = shift3; 
 
640
    } else
 
641
        pvt->unaligned = TRUE;
 
642
  } 
 
643
  pvt = (meUncompPtr)pet->private;
 
644
  if (pvt->unaligned) { 
 
645
    /* No special cases, do it the hard way */
 
646
    pvt[0].pitch = outf->pitch;
 
647
    pvt->action = EncodeTripleFuncs[tec->pixelOrder == xieValLSFirst ? 0 : 1]
 
648
                                   [tec->fillOrder  == xieValLSFirst ? 0 : 1]
 
649
                                   [depth1 <= 8 ? 0 : 1]
 
650
                                   [depth2 <= 8 ? 0 : 1]
 
651
                                   [depth3 <= 8 ? 0 : 1];
 
652
    if((depth1 == 1 && !(pvt[0].buf = (pointer)XieMalloc(pvt[0].width+7))) ||
 
653
       (depth2 == 1 && !(pvt[1].buf = (pointer)XieMalloc(pvt[1].width+7))) ||
 
654
       (depth3 == 1 && !(pvt[2].buf = (pointer)XieMalloc(pvt[2].width+7))))
 
655
      AllocError(flo,ped, return(FALSE));
 
656
  }
 
657
  pet->bandSync = SYNC;
 
658
  
 
659
  return(InitReceptors(flo, ped, NO_DATAMAP, 1) && 
 
660
         InitEmitter(flo, ped, NO_DATAMAP, NO_INPLACE));
 
661
}                               /* end InitializeEPhotoUncomByPixel */
 
662
 
 
663
 
 
664
/*------------------------------------------------------------------------
 
665
----------------------------- crank some data ----------------------------
 
666
------------------------------------------------------------------------*/
 
667
static int ActivateEPhotoUncomByPixel(floDefPtr flo, peDefPtr ped, peTexPtr pet)
 
668
{
 
669
  meUncompPtr pvt = (meUncompPtr)pet->private;
 
670
  bandPtr   sb0 = &pet->receptor[SRCtag].band[pvt[0].bandMap];
 
671
  bandPtr   sb1 = &pet->receptor[SRCtag].band[pvt[1].bandMap];
 
672
  bandPtr   sb2 = &pet->receptor[SRCtag].band[pvt[2].bandMap];
 
673
  bandPtr  dbnd = &pet->emitter[0];
 
674
  CARD32  pitch = dbnd->format->pitch;
 
675
  pointer sp0 = (pointer )NULL, sp1 = (pointer )NULL, sp2 = (pointer )NULL;
 
676
  CARD8 *dst;
 
677
  
 
678
  
 
679
  if (pvt->unaligned) {
 
680
    CARD32 stride   = dbnd->format->stride;
 
681
    CARD32 width    = dbnd->format->width;
 
682
    CARD32 nextdlen = (pvt->bitOff + pitch + 7) >> 3, olddlen;
 
683
    if((sp0 = GetCurrentSrc(flo,pet,sb0)) &&
 
684
       (sp1 = GetCurrentSrc(flo,pet,sb1)) && 
 
685
       (sp2 = GetCurrentSrc(flo,pet,sb2)) &&
 
686
       (dst = (BytePixel*)GetDstBytes(flo,pet,dbnd,dbnd->current,
 
687
                                      nextdlen,KEEP)))
 
688
      do {
 
689
        if(pvt[0].buf) sp0 = bitexpand(sp0,pvt[0].buf,width,(char)0,(char)1);
 
690
        if(pvt[1].buf) sp1 = bitexpand(sp1,pvt[1].buf,width,(char)0,(char)1);
 
691
        if(pvt[2].buf) sp2 = bitexpand(sp2,pvt[2].buf,width,(char)0,(char)1);
 
692
 
 
693
        (*pvt->action)(sp0,sp1,sp2,dst,stride,pvt);
 
694
        
 
695
        sp0         = GetNextSrc(flo,pet,sb0,FLUSH);
 
696
        sp1         = GetNextSrc(flo,pet,sb1,FLUSH);
 
697
        sp2         = GetNextSrc(flo,pet,sb2,FLUSH);
 
698
        pvt->bitOff = (pvt->bitOff + pitch) & 7;  /* Set next */
 
699
        olddlen     = (pvt->bitOff) ? nextdlen - 1 : nextdlen;
 
700
        nextdlen    = (pvt->bitOff + pitch + 7) >> 3;
 
701
        dst         = (BytePixel*)GetDstBytes(flo,pet,dbnd,
 
702
                                        dbnd->current+olddlen,nextdlen,KEEP);
 
703
      } while(dst && sp0 && sp1 && sp2);
 
704
 
 
705
  } else {
 
706
    CARD32  dlen  = pitch >> 3; /* For nicely aligned data */
 
707
    if((sp0 = GetCurrentSrc(flo,pet,sb0)) &&
 
708
       (sp1 = GetCurrentSrc(flo,pet,sb1)) && 
 
709
       (sp2 = GetCurrentSrc(flo,pet,sb2)) &&
 
710
       (dst = (BytePixel*)GetDstBytes(flo,pet,dbnd,dbnd->current,dlen,KEEP)))
 
711
 
 
712
      do {
 
713
        
 
714
        if (pvt[0].clear_dst) bzero(dst,(int)dlen);
 
715
        
 
716
        (*pvt[0].action)(sp0,dst,&pvt[0]);
 
717
        (*pvt[1].action)(sp1,dst,&pvt[1]);
 
718
        (*pvt[2].action)(sp2,dst,&pvt[2]);
 
719
        
 
720
        sp0 = GetNextSrc(flo,pet,sb0,FLUSH);
 
721
        sp1 = GetNextSrc(flo,pet,sb1,FLUSH);
 
722
        sp2 = GetNextSrc(flo,pet,sb2,FLUSH);
 
723
        dst = (BytePixel*)GetDstBytes(flo,pet,dbnd,dbnd->current+dlen,
 
724
                                      dlen,KEEP);
 
725
      } while(dst && sp0 && sp1 && sp2);
 
726
  }
 
727
  
 
728
  FreeData(flo,pet,sb0,sb0->current);
 
729
  FreeData(flo,pet,sb1,sb1->current);
 
730
  FreeData(flo,pet,sb2,sb2->current);
 
731
 
 
732
  if(!sp0 && sb0->final && !sp1 && sb1->final && !sp2 && sb2->final) {
 
733
    if (pvt->bitOff) /* If we have any bits left, send them out now */
 
734
      *(CARD8*)GetDstBytes(flo,pet,dbnd,dbnd->current,1,KEEP) = pvt->leftOver;
 
735
 
 
736
    SetBandFinal(dbnd);
 
737
    PutData(flo,pet,dbnd,dbnd->maxGlobal);   /* write the remaining data */
 
738
  }
 
739
  
 
740
  return(TRUE);
 
741
}                               /* end ActivateEPhotoUncomByPixel */
 
742
#endif /* XIE_FULL */
 
743
 
 
744
/*------------------------------------------------------------------------
 
745
------------------------ get rid of run-time stuff -----------------------
 
746
------------------------------------------------------------------------*/
 
747
static int ResetEPhoto(floDefPtr flo, peDefPtr ped)
 
748
{
 
749
  meUncompPtr pvt = (meUncompPtr)ped->peTex->private;
 
750
  int i;
 
751
 
 
752
  for(i = 0; i < xieValMaxBands; ++i)
 
753
    if(pvt[i].buf) pvt[i].buf = (pointer) XieFree(pvt[i].buf);
 
754
 
 
755
  ResetReceptors(ped);
 
756
  ResetEmitter(ped);
 
757
  
 
758
  return(TRUE);
 
759
}                               /* end ResetEPhoto */
 
760
 
 
761
/*------------------------------------------------------------------------
 
762
-------------------------- get rid of this element -----------------------
 
763
------------------------------------------------------------------------*/
 
764
static int DestroyEPhoto(floDefPtr flo, peDefPtr ped)
 
765
{
 
766
  /* get rid of the peTex structure  */
 
767
  ped->peTex = (peTexPtr) XieFree(ped->peTex);
 
768
 
 
769
  /* zap this element's entry point vector */
 
770
  ped->ddVec.create     = (xieIntProc) NULL;
 
771
  ped->ddVec.initialize = (xieIntProc) NULL;
 
772
  ped->ddVec.activate   = (xieIntProc) NULL;
 
773
  ped->ddVec.reset      = (xieIntProc) NULL;
 
774
  ped->ddVec.destroy    = (xieIntProc) NULL;
 
775
 
 
776
  return(TRUE);
 
777
}                               /* end DestroyEPhoto */
 
778
 
 
779
/* end module mephoto.c */