summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/XIE/mixie/process/mpcfromi.c
blob: eafb04e80bd011fa174bff685a358ba999a64c90 (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
/* $TOG: mpcfromi.c /main/6 1998/02/09 16:21:31 kaleb $ */
/**** module mpcfromi.c ****/
/******************************************************************************

Copyright 1993, 1994, 1998  The Open Group

All Rights Reserved.

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
OPEN GROUP 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 Open Group 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 Open Group.


				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.
*****************************************************************************
  
	mpcfromi.c -- DDXIE ConvertFromIndex element
  
	Robert NC Shelley -- AGE Logic, Inc. July, 1993
  
*****************************************************************************/
/* $XFree86: xc/programs/Xserver/XIE/mixie/process/mpcfromi.c,v 3.3 1998/10/05 13:22:42 dawes Exp $ */

#define _XIEC_MPCFROMI
#define _XIEC_PCFROMI

/*
 *  Include files
 */

/*
 *  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>
#include <scrnintstr.h>
#include <colormapst.h>
/*
 *  Server XIE Includes
 */
#include <error.h>
#include <macro.h>
#include <colorlst.h>
#include <element.h>
#include <xiemd.h>
#include <texstr.h>
#include <memory.h>

extern int QueryColors(); /* in ...server/dix/colormap.c */

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

/* routines used internal to this module
 */
static int CreateCfromI();
static int InitCfromI();
static int DoSingleCfromI();
static int DoTripleCfromI();
static int ResetCfromI();
static int DestroyCfromI();


/* DDXIE ConvertFromIndex entry points
 */
static ddElemVecRec mpCfromIVec = {
  CreateCfromI,
  InitCfromI,
  (xieIntProc)NULL,
  (xieIntProc)NULL,
  ResetCfromI,
  DestroyCfromI
  };


/* Local Declarations.
 */
typedef struct _mpcfromi {
  pCfromIDefPtr  dix;
  xieIntProc	 action;
  bandPtr        iband;
  bandPtr        oband;
  Pixel         *pixLst;
  xrgb          *rgbLst;
  CARD32	 width;
  pointer	ibuf;
  pointer	obuf[xieValMaxBands];
} mpCfromIRec, *mpCfromIPtr;

/* action routines
 */
#define    CfromI_1bb CfromI_1BB
#define    CfromI_1bB CfromI_1BB
#define    CfromI_1bP CfromI_1BP
#define    CfromI_1Bb CfromI_1BB
#define    CfromI_1Pb CfromI_1PB
#define    CfromI_1Qb CfromI_1QB
#define    CfromI_3bb CfromI_3BB
#define    CfromI_3bB CfromI_3BB
#define    CfromI_3bP CfromI_3BP
#define    CfromI_3Bb CfromI_3BB
#define    CfromI_3Pb CfromI_3PB
#define    CfromI_3Qb CfromI_3QB
static int CfromI_1BB(), CfromI_1BP(), CfromI_3BB(), CfromI_3BP();
static int CfromI_1PB(), CfromI_1PP(), CfromI_3PB(), CfromI_3PP();
static int CfromI_1QB(), CfromI_1QP(), CfromI_3QB(), CfromI_3QP();

static int (*action_CfromI[2][3][4])() = {
  CfromI_1bb, CfromI_1Bb, CfromI_1Pb, CfromI_1Qb, /* single, o=1, i=1..4 */
  CfromI_1bB, CfromI_1BB, CfromI_1PB, CfromI_1QB, /* single, o=2, i=1..4 */
  CfromI_1bP, CfromI_1BP, CfromI_1PP, CfromI_1QP, /* single, o=3, i=1..4 */
  CfromI_3bb, CfromI_3Bb, CfromI_3Pb, CfromI_3Qb, /* triple, o=1, i=1..4 */
  CfromI_3bB, CfromI_3BB, CfromI_3PB, CfromI_3QB, /* triple, o=2, i=1..4 */
  CfromI_3bP, CfromI_3BP, CfromI_3PP, CfromI_3QP, /* triple, o=3, i=1..4 */
};


/*------------------------------------------------------------------------
------------------- see if we can handle this element --------------------
------------------------------------------------------------------------*/
int miAnalyzeCvtFromInd(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  /* stash the entry point vector with the appropriate activate routine
   */
  ped->ddVec = mpCfromIVec;

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

/*------------------------------------------------------------------------
---------------------------- create peTex . . . --------------------------
------------------------------------------------------------------------*/
static int CreateCfromI(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  return(MakePETex(flo, ped, sizeof(mpCfromIRec), NO_SYNC, NO_SYNC));
}                               /* end CreateCfromI */


/*------------------------------------------------------------------------
---------------------------- initialize peTex . . . ----------------------
------------------------------------------------------------------------*/
static int InitCfromI(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  xieFloConvertFromIndex *raw = (xieFloConvertFromIndex *)ped->elemRaw;
  peTexPtr      pet =  ped->peTex;
  formatPtr     ift = &ped->inFloLst[SRCtag].format[0];
  formatPtr     oft = &ped->outFlo.format[0];
  pCfromIDefPtr dix = (pCfromIDefPtr) ped->elemPvt;
  mpCfromIPtr   ddx = (mpCfromIPtr)pet->private;
  CARD32  i, pseudo = !dix->pixMsk[0];
  CARD32 cells, odx =  ped->outFlo.bands == 1 ? 0 : 1;
  CARD8          oc = oft->class, ic = ift->class;
  Pixel  *p;
  xrgb   *rgb;
  
  /* set up action parameters
   */
  ddx->dix    = dix;
  ddx->width  = oft->width;
  ddx->iband  = &pet->receptor[SRCtag].band[0];
  ddx->oband  = &pet->emitter[0];
  ddx->action = action_CfromI[odx][oc-1][ift->class-1];
  if(!ddx->action) ImplementationError(flo,ped, return(FALSE));
  ped->ddVec.activate = !odx ? DoSingleCfromI : DoTripleCfromI;

  if(ic == BIT_PIXEL && !(ddx->ibuf = (BytePixel*)XieMalloc(ddx->width+7)))
    AllocError(flo,ped, return(FALSE));

  if(oc == BIT_PIXEL)
    if( odx && (!(ddx->obuf[0] = (BytePixel*)XieMalloc(ddx->width+7))  ||
		!(ddx->obuf[1] = (BytePixel*)XieMalloc(ddx->width+7))  ||
		!(ddx->obuf[2] = (BytePixel*)XieMalloc(ddx->width+7))) ||
       !odx &&  !(ddx->obuf[0] = (BytePixel*)XieMalloc(ddx->width+7)))
      AllocError(flo,ped, return(FALSE));
  
  /* snapshot the current contents of the colormap
   */
  SetDepthFromLevels(dix->cells,i); cells = 1<<i;
  if(!(ddx->pixLst = (Pixel*) XieMalloc(cells * sizeof(Pixel))) ||
     !(ddx->rgbLst = (xrgb *) XieMalloc(cells * sizeof(xrgb))))
    AllocError(flo,ped, return(FALSE));
  for(p = ddx->pixLst, i = 0; i < cells; ++i)
    *p++ = pseudo ? i : (i << dix->pixPos[0] & dix->pixMsk[0] |
                         i << dix->pixPos[1] & dix->pixMsk[1] |
                         i << dix->pixPos[2] & dix->pixMsk[2]);
  if(QueryColors(dix->cmap,cells,ddx->pixLst,ddx->rgbLst))
    ColormapError(flo,ped,raw->colormap, return(FALSE));   /* XXX hmmm? */

  /* adjust the RGB values according to the client's precision requirements
   */
  for(rgb = ddx->rgbLst, i = 0; i < cells; ++rgb, ++i) {
    rgb->red   >>= dix->precShift;
    rgb->green >>= dix->precShift;
    rgb->blue  >>= dix->precShift;
  }
    
  return(InitReceptors(flo, ped, NO_DATAMAP, 1) &&
         InitEmitter(flo, ped, NO_DATAMAP, NO_INPLACE));
}                               /* end InitCfromI */


/*------------------------------------------------------------------------
------------------------- crank some input data --------------------------
------------------------------------------------------------------------*/
static int DoSingleCfromI(flo,ped,pet)	/* one band out */
     floDefPtr flo;
     peDefPtr  ped;
     peTexPtr  pet;
{
  mpCfromIPtr  ddx = (mpCfromIPtr) pet->private;
  bandPtr    iband = ddx->iband;
  bandPtr    oband = ddx->oband;
  CARD32     width = iband->format->width;
  pointer src, dst;
  
  if((src = GetCurrentSrc(flo,pet,iband)) &&
     (dst = GetCurrentDst(flo,pet,oband)))
    do {
      if(ddx->ibuf) src = bitexpand(src,ddx->ibuf,width,(char)1,(char)0);

      (*ddx->action)(ddx, src, ddx->obuf[0] ? ddx->obuf[0] : dst);

      if(ddx->obuf[0]) bitshrink(ddx->obuf[0],dst,width,(char)1);

      src = GetNextSrc(flo,pet,iband,FLUSH);
      dst = GetNextDst(flo,pet,oband,FLUSH);
    } while(src && dst);
    
  FreeData(flo,pet,iband,iband->current);

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

static int DoTripleCfromI(flo,ped,pet)	/* three bands out */
     floDefPtr flo;
     peDefPtr  ped;
     peTexPtr  pet;
{
  mpCfromIPtr  ddx = (mpCfromIPtr) pet->private;
  bandPtr    iband = ddx->iband;
  bandPtr    oband = ddx->oband;
  CARD32     width = iband->format->width;
  pointer src, dstR, dstG, dstB;
  
  src  = GetCurrentSrc(flo,pet,iband);
  dstR = GetCurrentDst(flo,pet,oband); oband++;
  dstG = GetCurrentDst(flo,pet,oband); oband++;
  dstB = GetCurrentDst(flo,pet,oband); oband -=2;

  while(src && dstR && dstG && dstB) {
        
    if(ddx->ibuf) src = bitexpand(src,ddx->ibuf,width,(char)1,(char)0);

    (*ddx->action)(ddx, src,
		   ddx->obuf[0] ? ddx->obuf[0] : dstR,
		   ddx->obuf[1] ? ddx->obuf[1] : dstG,
		   ddx->obuf[2] ? ddx->obuf[2] : dstB);

    if(ddx->obuf[0]) bitshrink(ddx->obuf[0],dstR,width,(char)1);
    if(ddx->obuf[1]) bitshrink(ddx->obuf[1],dstG,width,(char)1);
    if(ddx->obuf[2]) bitshrink(ddx->obuf[2],dstB,width,(char)1);

    src  = GetNextSrc(flo,pet,iband,FLUSH);
    dstR = GetNextDst(flo,pet,oband,FLUSH); oband++;
    dstG = GetNextDst(flo,pet,oband,FLUSH); oband++;
    dstB = GetNextDst(flo,pet,oband,FLUSH); oband -=2;
  }
  FreeData(flo,pet,iband,iband->current);

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



/*------------------------------------------------------------------------
------------------------ get rid of run-time stuff -----------------------
------------------------------------------------------------------------*/
static int ResetCfromI(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  mpCfromIPtr ddx = (mpCfromIPtr) ped->peTex->private;

  if(ddx->pixLst ) ddx->pixLst  = (Pixel*) XieFree(ddx->pixLst );
  if(ddx->rgbLst ) ddx->rgbLst  = (xrgb *) XieFree(ddx->rgbLst );
  if(ddx->ibuf   ) ddx->ibuf    = (pointer ) XieFree(ddx->ibuf   );
  if(ddx->obuf[0]) ddx->obuf[0] = (pointer ) XieFree(ddx->obuf[0]);
  if(ddx->obuf[1]) ddx->obuf[1] = (pointer ) XieFree(ddx->obuf[1]);
  if(ddx->obuf[2]) ddx->obuf[2] = (pointer ) XieFree(ddx->obuf[2]);

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


/*------------------------------------------------------------------------
-------------------------- get rid of this element -----------------------
------------------------------------------------------------------------*/
static int DestroyCfromI(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 DestroyCfromI */

/* Single band output action routines:
 */

#define DO_SINGLE_CFROMI(fn_do,itype,otype)			\
static int fn_do(ddx,SRC,DST)					\
  mpCfromIPtr ddx; pointer SRC; pointer DST;			\
{								\
  itype *s = (itype *)SRC;					\
  otype *d = (otype *)DST;					\
  xrgb  *x =  ddx->rgbLst;					\
  int    w =  ddx->width;					\
  switch(ddx->dix->class) {					\
  case StaticGray:						\
  case GrayScale:						\
  case StaticColor:						\
  case PseudoColor:						\
    while(w--) *d++ = x[*s++].red;				\
    break;							\
  case TrueColor:						\
  case DirectColor:						\
    { int rm = ddx->dix->pixMsk[0], rs = ddx->dix->pixPos[0];	\
      while(w--) *d++ = x[(*s++ & rm) >> rs].red;		\
    }								\
  }								\
}
/* bit versions - nyi */
/*		 CfromI_1bb,BitPixel, BitPixel  */
/*		 CfromI_1bB,BitPixel, BytePixel */
/*		 CfromI_1bP,BitPixel, PairPixel */
/*		 CfromI_1Bb,BytePixel,BitPixel  */
DO_SINGLE_CFROMI(CfromI_1BB,BytePixel,BytePixel)
DO_SINGLE_CFROMI(CfromI_1BP,BytePixel,PairPixel)
/*		 CfromI_1Pb,PairPixel,BitPixel  */
DO_SINGLE_CFROMI(CfromI_1PB,PairPixel,BytePixel)
DO_SINGLE_CFROMI(CfromI_1PP,PairPixel,PairPixel)
/*		 CfromI_1Qb,QuadPixel,BitPixel  */
DO_SINGLE_CFROMI(CfromI_1QB,QuadPixel,BytePixel)
DO_SINGLE_CFROMI(CfromI_1QP,QuadPixel,PairPixel)


/* Triple band output action routines:
 */

#define DO_TRIPLE_CFROMI(fn_do,itype,otype)			\
static int fn_do(ddx,SRC,DSTR,DSTG,DSTB)			\
    mpCfromIPtr ddx; pointer SRC, DSTR, DSTG, DSTB;		\
{								\
  itype  *s = (itype *)SRC;					\
  otype  *r = (otype *)DSTR;					\
  otype  *g = (otype *)DSTG;					\
  otype  *b = (otype *)DSTB;					\
  xrgb   *x =  ddx->rgbLst;					\
  int     w =  ddx->width;					\
  switch(ddx->dix->class) {					\
  case StaticGray:						\
  case GrayScale:						\
    while(w--) *r++ = *g++ = *b++ = x[*s++].red;		\
    break;							\
  case StaticColor:						\
  case PseudoColor:						\
    while(w--) {						\
      xrgb *p = x + *s++;					\
      *r++ = p->red; *g++ = p->green; *b++ = p->blue;		\
    }								\
    break;							\
  case TrueColor:						\
  case DirectColor:						\
    { int rm = ddx->dix->pixMsk[0], rs = ddx->dix->pixPos[0];	\
      int gm = ddx->dix->pixMsk[1], gs = ddx->dix->pixPos[1];	\
      int bm = ddx->dix->pixMsk[2], bs = ddx->dix->pixPos[2];	\
      while(w--) {						\
	Pixel p = *s++;						\
	*r++ = x[(p & rm) >> rs].red;				\
	*g++ = x[(p & gm) >> gs].green;				\
	*b++ = x[(p & bm) >> bs].blue;				\
      }								\
    }								\
  }								\
}
/* bit versions - nyi */
/*		 CfromI_3bb,BitPixel, BitPixel  */
/*		 CfromI_3bB,BitPixel, BytePixel */
/*		 CfromI_3bP,BitPixel, PairPixel */
/*		 CfromI_3Bb,BytePixel,BitPixel  */
DO_TRIPLE_CFROMI(CfromI_3BB,BytePixel,BytePixel)
DO_TRIPLE_CFROMI(CfromI_3BP,BytePixel,PairPixel)
/*		 CfromI_3Pb,PairPixel,BitPixel  */
DO_TRIPLE_CFROMI(CfromI_3PB,PairPixel,BytePixel)
DO_TRIPLE_CFROMI(CfromI_3PP,PairPixel,PairPixel)
     /*		 CfromI_3Qb,QuadPixel,BitPixel  */
DO_TRIPLE_CFROMI(CfromI_3QB,QuadPixel,BytePixel)
DO_TRIPLE_CFROMI(CfromI_3QP,QuadPixel,PairPixel)

/* end module mpcfromi.c */