summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/XIE/mixie/import/midraw.c
blob: eeec94079162c75660209b042c2e7b1396bebebf (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
/* $XConsortium: midraw.c,v 1.9 94/04/17 20:34:52 rws Exp $ */
/**** module midraw.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.
*****************************************************************************
  
	midraw.c -- DDXIE prototype import drawable element
  
	Larry Hare -- AGE Logic, Inc. June, 1993
  
*****************************************************************************/

#define _XIEC_IDRAW
#define _XIEC_MIDRAW

/*
 *  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>
#include <scrnintstr.h>
#include <pixmapstr.h>
#include <regionstr.h>
#include <gcstruct.h>
#include <windowstr.h>
/*
 *  Server XIE Includes
 */
#include <error.h>
#include <macro.h>
#include <photomap.h>
#include <element.h>
#include <texstr.h>
#include <xiemd.h>


DrawablePtr ValDrawable();


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

/*
 *  routines used internal to this module
 */
static int CreateIDraw();
static int InitializeIDraw();
static int ActivateIDrawStrip();
static int ActivateIDrawAlign();
static int ActivateIDrawP();
static int ResetIDraw();
static int DestroyIDraw();

static void adjustStride4to8();
static void adjustStride24to32();

static Bool XIEGetImage();


/*
 * DDXIE ImportDrawable && ImportDrawablePlane entry points
 */
static ddElemVecRec miDrawVec = {
  CreateIDraw,
  InitializeIDraw,
  ActivateIDrawStrip,
  (xieIntProc)NULL,
  ResetIDraw,
  DestroyIDraw
  };

static ddElemVecRec miDrawPVec = {
  CreateIDraw,
  InitializeIDraw,
  ActivateIDrawP,
  (xieIntProc)NULL,
  ResetIDraw,
  DestroyIDraw
  };

typedef struct _midraw {
  RegionPtr	pExposed;
  RegionRec	 Exposed;
  xieVoidProc	 adjust;
} miDrawRec, *miDrawPtr;	

/*------------------------------------------------------------------------
------------------- see if we can handle this element --------------------
------------------------------------------------------------------------*/
int miAnalyzeIDraw(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  /* for now just stash our entry point vector in the peDef */
  ped->ddVec = miDrawVec;
  return(TRUE);
}                               /* end miAnalyzeIDraw */

int miAnalyzeIDrawP(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  /* for now just stash our entry point vector in the peDef */
  ped->ddVec = miDrawPVec;
  return(TRUE);
}                               /* end miAnalyzeIDrawP */


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


/*------------------------------------------------------------------------
---------------------------- initialize peTex . . . ----------------------
------------------------------------------------------------------------*/
static int InitializeIDraw(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  iDrawDefPtr		dix = (iDrawDefPtr) ped->elemPvt;
  miDrawPtr		ddx = (miDrawPtr) ped->peTex->private;
  formatPtr		sf  = &ped->inFloLst[SRCtag].format[0];
  formatPtr		df  = &ped->outFlo.format[0];
  BOOL notify;

  if(((xieFloImportDrawable*)ped->elemRaw)->elemType==xieElemImportDrawable) {
    Bool adj_stride = sf->stride != df->stride;
    Bool adj_pitch  = sf->pitch  != df->pitch;

    if(adj_stride || adj_pitch) {
      ped->ddVec.activate = ActivateIDrawAlign;

      if(adj_stride) {
	if(sf->stride == 24 && df->stride == 32)
	  ddx->adjust  = adjustStride24to32;
      
	else if(sf->stride == 4 && df->stride == 8)
	  ddx->adjust  = adjustStride4to8;
      
	/* add more adjustment routines as required */
      }
    } else {
      ped->ddVec.activate = ActivateIDrawStrip;
    }
    notify = ((xieFloImportDrawable*)ped->elemRaw)->notify;
  } else
    notify = ((xieFloImportDrawablePlane*)ped->elemRaw)->notify;

  if(notify && dix->pDraw->type != DRAWABLE_PIXMAP) {
    ddx->pExposed = &ddx->Exposed;
    (*dix->pDraw->pScreen->RegionInit) (ddx->pExposed, NullBox, 0);
  }
  /* note: ImportResource elements don't use their receptors */
  return InitEmitter(flo,ped,NO_DATAMAP,NO_INPLACE);
}                               /* end InitializeIDraw */


/*------------------------------------------------------------------------
----------------------------- crank some data ----------------------------
------------------------------------------------------------------------*/
static int ActivateIDrawAlign(flo,ped,pet)
     floDefPtr flo;
     peDefPtr  ped;
     peTexPtr  pet;
{
  xieFloImportDrawable	 *raw = (xieFloImportDrawable *) ped->elemRaw;
  miDrawPtr		  ddx = (miDrawPtr) pet->private;
  bandPtr		  bnd = &pet->emitter[0];
  DrawablePtr	        pDraw = ValDrawable(flo,ped,raw->drawable);
  char			 *dst = (char*)GetCurrentDst(flo,pet,bnd);
  CARD16		width = bnd->format->width;

  if(!pDraw || !dst) return FALSE;

  do {
    if(!XIEGetImage(pDraw,				/* drawable	 */
		    (CARD16) raw->srcX,			/* drawable-x	 */
		    (CARD16)(raw->srcY+bnd->current),	/* drawable-y	 */
		    (CARD16) width, (CARD16)1,		/* width, height */
		    (CARD32)ZPixmap,			/* data format   */
		    (CARD32)~0,				/* plane mask	 */
		    dst,				/* data buffer   */
		    raw->fill,				/* augment	 */ 
		    ddx->pExposed			/* accumulate    */
		    ))
      DrawableError(flo,ped,raw->drawable, return(FALSE));

    if(ddx->adjust)
      (*ddx->adjust)(dst, width);

  } while(dst = (char*)GetNextDst(flo,pet,bnd,FLUSH));

  return TRUE;
}                               /* end ActivateIDrawAlign */

/*------------------------------------------------------------------------
----------------------------- crank some data ----------------------------
------------------------------------------------------------------------*/
static int ActivateIDrawStrip(flo,ped,pet)
     floDefPtr flo;
     peDefPtr  ped;
     peTexPtr  pet;
{
  xieFloImportDrawable	*raw = (xieFloImportDrawable *) ped->elemRaw;
  miDrawPtr		 ddx = (miDrawPtr) pet->private;
  bandPtr		 bnd = &pet->emitter[0];
  char			*dst;
  DrawablePtr		 pDraw;

  if (!(pDraw = ValDrawable(flo,ped,raw->drawable)))
    return FALSE;

  if (!(dst = (char*)GetCurrentDst(flo,pet,bnd)))
    return FALSE;

  if(!XIEGetImage( pDraw,				/* drawable	*/
		  (CARD16) raw->srcX,			/* drawable-x	*/
		  (CARD16)(raw->srcY+bnd->minLocal),	/* drawable-y	*/
		  (CARD16)(bnd->format->width),		/* width	*/
		  (CARD16)(bnd->strip->length),		/* height	*/
		  (CARD32)ZPixmap,			/* data format  */
		  (CARD32)~0,				/* plane mask	*/
		  dst,					/* data buffer  */
		  raw->fill,				/* augment	*/ 
		  ddx->pExposed				/* accumulate   */
		  ))
    DrawableError(flo,ped,raw->drawable, return(FALSE));

  PutData(flo,pet,bnd,bnd->maxLocal);

  return TRUE;
}                               /* end ActivateIDrawStrip */

static int ActivateIDrawP(flo,ped,pet)
     floDefPtr flo;
     peDefPtr  ped;
     peTexPtr  pet;
{
  xieFloImportDrawablePlane *raw = (xieFloImportDrawablePlane *) ped->elemRaw;
  miDrawPtr		ddx = (miDrawPtr) pet->private;
  bandPtr		bnd = &pet->emitter[0];
  char			*dst;
  DrawablePtr		pDraw;

  if (!(pDraw = ValDrawable(flo,ped,raw->drawable)))
    return FALSE;

  if(!(dst = (char*)GetCurrentDst(flo,pet,bnd)))
    return FALSE;

  if(!XIEGetImage( pDraw,				/* drawable	*/
		  (CARD16)(raw->srcX),			/* drawable-x   */
		  (CARD16)(raw->srcY+bnd->minLocal),	/* drawable-y   */
		  (CARD16)(bnd->format->width),		/* width	*/
		  (CARD16)(bnd->strip->length),		/* height	*/
		  (CARD32)XYPixmap,			/* data format  */
		  raw->bitPlane,			/* plane mask   */
		  dst,					/* data buffer  */
		  raw->fill,				/* augment	*/ 
		  ddx->pExposed				/* accumulate   */
		  ))
    DrawableError(flo,ped,raw->drawable, return(FALSE));

#if (BITMAP_BIT_ORDER != IMAGE_BYTE_ORDER)
  {
    int nb = bnd->pitch * bnd->strip->length;
    while (nb--) *dst++ = (char)_ByteReverseTable[*dst];
  }
#endif

  PutData(flo,pet,bnd,bnd->maxLocal);

  return TRUE;
}                               /* end ActivateIDrawP */


/*------------------------------------------------------------------------
------------------------ get rid of run-time stuff -----------------------
------------------------------------------------------------------------*/
static void FlushExposeEvents(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  xieFloImportDrawablePlane *raw = (xieFloImportDrawablePlane *) ped->elemRaw;
  miDrawPtr		     pvt = (miDrawPtr) ped->peTex->private;

  if (pvt->pExposed) {
    RegionPtr      rp = pvt->pExposed;
    DrawablePtr pDraw = ValDrawable(flo,ped,raw->drawable);
    int      numrects = REGION_NUM_RECTS(rp);

    if (pDraw) {
	if (numrects > 0 && !ferrCode(flo) && !flo->flags.aborted) {
	    BoxPtr rects = REGION_RECTS(rp);

	    /* if numrects is large, send 1 event for extents ?? */
	    for ( ; numrects > 0; numrects--, rects++) {
		SendImportObscuredEvent(flo,ped,raw->drawable,
					rects->x1,
					rects->y1,
					rects->x2 - rects->x1,
					rects->y2 - rects->y1);
	    }
	}
    	(*pDraw->pScreen->RegionUninit) (rp);
    } /* else Memory Leak */
    pvt->pExposed = NullRegion;
  }
}                               /* end FlushExposeEvents */


static int ResetIDraw(flo,ped)
     floDefPtr flo;
     peDefPtr  ped;
{
  FlushExposeEvents(flo,ped); 
  ResetEmitter(ped);
  
  return(TRUE);
}                               /* end ResetIDraw */

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

/*------------------------------------------------------------------------
--- similar to GetGCAndDrawableAndValidate (from extension.h)          ---
--- made callable because the macro version returned standard X errors ---
------------------------------------------------------------------------*/
DrawablePtr ValDrawable(flo,ped,draw_id)
     floDefPtr    flo;
     peDefPtr     ped;
     Drawable	  draw_id;
{
  register ClientPtr	client = flo->runClient;
  register DrawablePtr	draw;
  
  if (client->clientGone) return(NULL);

  if (client->lastDrawableID != draw_id) {
    draw = (DrawablePtr)LookupIDByClass(draw_id, RC_DRAWABLE);
    if (draw->type  == UNDRAWABLE_WINDOW)
	MatchError(flo,ped, return(NULL));
      
    client->lastDrawable   = draw;
    client->lastDrawableID = draw_id;
  } else {
    draw = client->lastDrawable;
  }
  if(!draw) {
    client->errorValue = draw_id;
    DrawableError(flo,ped,draw_id, return(NULL));
  }
  return draw;
}                               /* end ValDrawable */


/*
**  In order to support 'fill' and 'expose events' we must layer some
**  code on top of the normal screen GetImage procedure.  Use the defined
**  backing store interface that aid's in copy expose processing, to try
**  to knowingly recover backing store.  Keep track of remaining regions
**  which were not visible or in backing store.  Always fill such leftover
**  regions, and queue them up for later expose event processing.
*/

static Bool
XIEGetImage (pDrawable, sx, sy, w, h, format, pmask, pdst, fill, Exposed)
    DrawablePtr	pDrawable;
    CARD16	 sx, sy, w, h;
    CARD32	 format;
    CARD32	 pmask;
    char	*pdst;
    CARD32	 fill;
    RegionPtr	 Exposed;
{
    ScreenPtr		    pScreen = pDrawable->pScreen;
    BoxRec		    bounds;
    unsigned char	    depth;

    if(pDrawable->type != DRAWABLE_PIXMAP && (sx + w > pDrawable->width ||
					      sy + h > pDrawable->height))
      return(FALSE);

    if(pDrawable->type != DRAWABLE_PIXMAP &&
	((WindowPtr)pDrawable)->visibility != VisibilityUnobscured) {
	PixmapPtr	pPixmap;
	GCPtr		pGC;
	WindowPtr	pWin, pSrcWin;
	RegionRec	Remaining;
	BoxPtr		pBox;
	int		i;
	int		x, y;
	xRectangle	*pRect;
	int		numRects;

	pWin = (WindowPtr) pDrawable;
	pPixmap = 0;
	depth = pDrawable->depth;
	bounds.x1 = sx + pDrawable->x;
	bounds.y1 = sy + pDrawable->y;
	bounds.x2 = bounds.x1 + w;
	bounds.y2 = bounds.y1 + h;
	(*pScreen->RegionInit) (&Remaining, &bounds, 0);
	if (!(pPixmap = (*pScreen->CreatePixmap) (pScreen, w, h, depth)))
	    goto punt;
	if(!(pGC = GetScratchGC (depth, pScreen))) {
	    (*pScreen->DestroyPixmap) (pPixmap);
	    goto punt;
	}
	if (pWin->viewable && 
	    (*pScreen->RectIn) (&Remaining, (*pScreen->RegionExtents)
					(&pWin->borderSize)) != rgnOUT) {
	    XID	subWindowMode = IncludeInferiors;
	    ChangeGC (pGC, GCSubwindowMode, &subWindowMode);
	    ValidateGC ((DrawablePtr)pPixmap, pGC);
	    pSrcWin = (WindowPtr) pDrawable;
	    x = sx;
	    y = sy;
	    if (pSrcWin->parent) {
		x += pSrcWin->origin.x;
		y += pSrcWin->origin.y;
		pSrcWin = pSrcWin->parent;
	    }
	    (*pGC->ops->CopyArea) ((DrawablePtr)pSrcWin,
				   (DrawablePtr)pPixmap, pGC,
				   x, y, w, h,
				   0, 0);
	    (*pScreen->Subtract) (&Remaining, &Remaining,
				  &((WindowPtr) pDrawable)->borderClip);
	    if (REGION_NUM_RECTS(&Remaining) == 0) goto done;
	}
        (*pScreen->TranslateRegion) (&Remaining, -pWin->drawable.x,
						     -pWin->drawable.y);

	/* Copy in Backstore now */
	if (pWin->backStorage) {
		(*pWin->drawable.pScreen->ExposeCopy) (pWin,
						       (DrawablePtr)pPixmap,
						       pGC, &Remaining,
						       sx, sy,
						       0, 0,
						       0);
					
	}

	/* Fill in Remaining Area now */
	ChangeGC (pGC, GCForeground, &fill);
	ValidateGC ((DrawablePtr)pPixmap, pGC);
	numRects = REGION_NUM_RECTS(&Remaining);
	pBox = REGION_RECTS(&Remaining);
	pRect = (xRectangle *)ALLOCATE_LOCAL(numRects * sizeof(xRectangle));
	if (pRect) {
	    for (i = numRects; --i >= 0; pBox++, pRect++) {
		pRect->x = pBox->x1 - sx;
		pRect->y = pBox->y1 - sy;
		pRect->width = pBox->x2 - pBox->x1;
		pRect->height = pBox->y2 - pBox->y1;
	    }
	    pRect -= numRects;
	    (*pGC->ops->PolyFillRect) ((DrawablePtr)pPixmap, pGC,
				       numRects, pRect);
	    DEALLOCATE_LOCAL (pRect);
	}

	/* Accumulate Exposures if requested */
	if (REGION_NUM_RECTS(&Remaining) > 0) {
	    if (Exposed) {
		(*pScreen->Union) (Exposed, Exposed, &Remaining);
	    }
	}

done:
	(*pScreen->RegionUninit) (&Remaining);
	(*pScreen->GetImage) ((DrawablePtr) pPixmap, 0, 0, w, h,
			      format, pmask, pdst);
	(*pScreen->DestroyPixmap) (pPixmap);
	FreeScratchGC (pGC);
    }
    else
    {
punt:	;
	(*pScreen->GetImage) (pDrawable, sx, sy, w, h,
			      format, pmask, pdst);
    }
  return(TRUE);
}

static void adjustStride24to32(buf,width)
     char      *buf;
     CARD32	width;
{
  register BytePixel *ip = (BytePixel*)(&buf[3 * width]);
  register QuadPixel *op = (QuadPixel*)(&buf[4 * width]);
  int   i;

  for(i = width; i; --i)
#if (IMAGE_BYTE_ORDER == LSBFirst && IMAGE_BYTE_ORDER == BITMAP_BIT_ORDER ||     IMAGE_BYTE_ORDER == MSBFirst && IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER)
  { ip -= 3; *(--op) = (int)ip[2]<<16 | (int)ip[1]<<8 | (int)ip[0]; }
#else
  { ip -= 3; *(--op) = (int)ip[0]<<16 | (int)ip[1]<<8 | (int)ip[2]; }
#endif
}

static void adjustStride4to8(buf,width)
     char      *buf;
     CARD32	width;
{
  register BytePixel *ip = (BytePixel*)(&buf[1 * width]);
  register BytePixel *op = (BytePixel*)(&buf[2 * width]);
  int   i;

  for(i = width; i; --i)
#if (IMAGE_BYTE_ORDER == LSBFirst && IMAGE_BYTE_ORDER == BITMAP_BIT_ORDER ||     IMAGE_BYTE_ORDER == MSBFirst && IMAGE_BYTE_ORDER != BITMAP_BIT_ORDER)
  { *(--op) = *(--ip) & (BytePixel)0x0f; *(--op) = *ip >> 4; }
#else
  { *(--op) = *(--ip) >> 4; *(--op) = *ip & (BytePixel)0x0f; }
#endif
}


/* end module midraw.c */