fbpict.c 46.4 KB
Newer Older
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1
2
/*
 *
3
 * Copyright © 2000 SuSE, Inc.
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of SuSE not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  SuSE makes no representations about the
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 *
 * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
20
21
22
23
24
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author:  Keith Packard, SuSE, Inc.
 */

25
26
27
28
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif

29
30
#include <string.h>

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
31
32
33
34
35
36
37
#include "fb.h"

#ifdef RENDER

#include "picturestr.h"
#include "mipict.h"
#include "fbpict.h"
38
#include "fbmmx.h"
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
39

40
41
42
43
44
45
46
47
48
49
50
51
52
typedef void	(*CompositeFunc) (CARD8      op,
				  PicturePtr pSrc,
				  PicturePtr pMask,
				  PicturePtr pDst,
				  INT16      xSrc,
				  INT16      ySrc,
				  INT16      xMask,
                                  INT16      yMask,
				  INT16      xDst,
				  INT16      yDst,
				  CARD16     width,
				  CARD16     height);

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
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
CARD32
fbOver (CARD32 x, CARD32 y)
{
    CARD16  a = ~x >> 24;
    CARD16  t;
    CARD32  m,n,o,p;

    m = FbOverU(x,y,0,a,t);
    n = FbOverU(x,y,8,a,t);
    o = FbOverU(x,y,16,a,t);
    p = FbOverU(x,y,24,a,t);
    return m|n|o|p;
}

CARD32
fbOver24 (CARD32 x, CARD32 y)
{
    CARD16  a = ~x >> 24;
    CARD16  t;
    CARD32  m,n,o;

    m = FbOverU(x,y,0,a,t);
    n = FbOverU(x,y,8,a,t);
    o = FbOverU(x,y,16,a,t);
    return m|n|o;
}

CARD32
fbIn (CARD32 x, CARD8 y)
{
    CARD16  a = y;
    CARD16  t;
    CARD32  m,n,o,p;

    m = FbInU(x,0,a,t);
    n = FbInU(x,8,a,t);
    o = FbInU(x,16,a,t);
    p = FbInU(x,24,a,t);
    return m|n|o|p;
}

94
95
#define genericCombine24(a,b,c,d) (((a)*(c)+(b)*(d)))

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
/*
 * This macro does src IN mask OVER dst when src and dst are 0888.
 * If src has alpha, this will not work
 */
#define inOver0888(alpha, source, destval, dest) { \
 	CARD32 dstrb=destval&0xFF00FF; CARD32 dstag=(destval>>8)&0xFF00FF; \
 	CARD32 drb=((source&0xFF00FF)-dstrb)*alpha; CARD32 dag=(((source>>8)&0xFF00FF)-dstag)*alpha; \
	dest =((((drb>>8) + dstrb) & 0x00FF00FF) | ((((dag>>8) + dstag) << 8) & 0xFF00FF00)); \
    }

/*
 * This macro does src IN mask OVER dst when src and dst are 0565 and
 * mask is a 5-bit alpha value.  Again, if src has alpha, this will not
 * work.
 */
#define inOver0565(alpha, source, destval, dest) { \
 	CARD16 dstrb = destval & 0xf81f; CARD16 dstg  = destval & 0x7e0; \
 	CARD32 drb = ((source&0xf81f)-dstrb)*alpha; CARD32 dg=((source & 0x7e0)-dstg)*alpha; \
	dest = ((((drb>>5) + dstrb)&0xf81f) | (((dg>>5)  + dstg) & 0x7e0)); \
    }


#define inOver2x0565(alpha, source, destval, dest) { \
 	CARD32 dstrb = destval & 0x07e0f81f; CARD32 dstg  = (destval & 0xf81f07e0)>>5; \
 	CARD32 drb = ((source&0x07e0f81f)-dstrb)*alpha; CARD32 dg=(((source & 0xf81f07e0)>>5)-dstg)*alpha; \
	dest = ((((drb>>5) + dstrb)&0x07e0f81f) | ((((dg>>5)  + dstg)<<5) & 0xf81f07e0)); \
    }
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


#if IMAGE_BYTE_ORDER == LSBFirst
	#define setupPackedReader(count,temp,where,workingWhere,workingVal) count=(int)where; \
					temp=count&3; \
					where-=temp; \
					workingWhere=(CARD32 *)where; \
					workingVal=*workingWhere++; \
					count=4-temp; \
					workingVal>>=(8*temp)
	#define readPacked(where,x,y,z) {if(!(x)) { (x)=4; y=*z++; } where=(y)&0xff; (y)>>=8; (x)--;}
	#define readPackedSource(where) readPacked(where,ws,workingSource,wsrc)
	#define readPackedDest(where) readPacked(where,wd,workingiDest,widst)
	#define writePacked(what) workingoDest>>=8; workingoDest|=(what<<24); ww--; if(!ww) { ww=4; *wodst++=workingoDest; } 
#else
	#warning "I havn't tested fbCompositeTrans_0888xnx0888() on big endian yet!"
	#define setupPackedReader(count,temp,where,workingWhere,workingVal) count=(int)where; \
					temp=count&3; \
					where-=temp; \
					workingWhere=(CARD32 *)where; \
					workingVal=*workingWhere++; \
					count=4-temp; \
					workingVal<<=(8*temp)
	#define readPacked(where,x,y,z) {if(!(x)) { (x)=4; y=*z++; } where=(y)>>24; (y)<<=8; (x)--;}
	#define readPackedSource(where) readPacked(where,ws,workingSource,wsrc)
	#define readPackedDest(where) readPacked(where,wd,workingiDest,widst)
	#define writePacked(what) workingoDest<<=8; workingoDest|=what; ww--; if(!ww) { ww=4; *wodst++=workingoDest; } 
#endif
151

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
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
/*
 * Naming convention:
 *
 *  opSRCxMASKxDST
 */

void
fbCompositeSolidMask_nx8x8888 (CARD8      op,
			       PicturePtr pSrc,
			       PicturePtr pMask,
			       PicturePtr pDst,
			       INT16      xSrc,
			       INT16      ySrc,
			       INT16      xMask,
			       INT16      yMask,
			       INT16      xDst,
			       INT16      yDst,
			       CARD16     width,
			       CARD16     height)
{
    CARD32	src, srca;
    CARD32	*dstLine, *dst, d, dstMask;
    CARD8	*maskLine, *mask, m;
    FbStride	dstStride, maskStride;
    CARD16	w;

178
    fbComposeGetSolid(pSrc, src, pDst->format);
179

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
180
181
182
183
    dstMask = FbFullMask (pDst->pDrawable->depth);
    srca = src >> 24;
    if (src == 0)
	return;
184

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
185
186
    fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1);
    fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1);
187

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
188
189
190
191
192
193
194
195
196
197
    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	mask = maskLine;
	maskLine += maskStride;
	w = width;

	while (w--)
	{
Aaron Plattner's avatar
Aaron Plattner committed
198
	    m = READ(mask++);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
199
200
201
	    if (m == 0xff)
	    {
		if (srca == 0xff)
Aaron Plattner's avatar
Aaron Plattner committed
202
		    WRITE(dst, src & dstMask);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
203
		else
Aaron Plattner's avatar
Aaron Plattner committed
204
		    WRITE(dst, fbOver (src, READ(dst)) & dstMask);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
205
206
207
208
	    }
	    else if (m)
	    {
		d = fbIn (src, m);
Aaron Plattner's avatar
Aaron Plattner committed
209
		WRITE(dst, fbOver (d, READ(dst)) & dstMask);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
210
211
212
213
	    }
	    dst++;
	}
    }
214
215
216

    fbFinishAccess (pMask->pDrawable);
    fbFinishAccess (pDst->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
}

void
fbCompositeSolidMask_nx8888x8888C (CARD8      op,
				   PicturePtr pSrc,
				   PicturePtr pMask,
				   PicturePtr pDst,
				   INT16      xSrc,
				   INT16      ySrc,
				   INT16      xMask,
				   INT16      yMask,
				   INT16      xDst,
				   INT16      yDst,
				   CARD16     width,
				   CARD16     height)
{
    CARD32	src, srca;
    CARD32	*dstLine, *dst, d, dstMask;
    CARD32	*maskLine, *mask, ma;
    FbStride	dstStride, maskStride;
    CARD16	w;
    CARD32	m, n, o, p;

240
    fbComposeGetSolid(pSrc, src, pDst->format);
241

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
242
243
244
245
    dstMask = FbFullMask (pDst->pDrawable->depth);
    srca = src >> 24;
    if (src == 0)
	return;
246

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
247
248
    fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1);
    fbComposeGetStart (pMask, xMask, yMask, CARD32, maskStride, maskLine, 1);
249

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
250
251
252
253
254
255
256
257
258
259
    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	mask = maskLine;
	maskLine += maskStride;
	w = width;

	while (w--)
	{
Aaron Plattner's avatar
Aaron Plattner committed
260
	    ma = READ(mask++);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
261
262
263
	    if (ma == 0xffffffff)
	    {
		if (srca == 0xff)
Aaron Plattner's avatar
Aaron Plattner committed
264
		    WRITE(dst, src & dstMask);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
265
		else
Aaron Plattner's avatar
Aaron Plattner committed
266
		    WRITE(dst, fbOver (src, READ(dst)) & dstMask);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
267
268
269
	    }
	    else if (ma)
	    {
Aaron Plattner's avatar
Aaron Plattner committed
270
		d = READ(dst);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#define FbInOverC(src,srca,msk,dst,i,result) { \
    CARD16  __a = FbGet8(msk,i); \
    CARD32  __t, __ta; \
    CARD32  __i; \
    __t = FbIntMult (FbGet8(src,i), __a,__i); \
    __ta = (CARD8) ~FbIntMult (srca, __a,__i); \
    __t = __t + FbIntMult(FbGet8(dst,i),__ta,__i); \
    __t = (CARD32) (CARD8) (__t | (-(__t >> 8))); \
    result = __t << (i); \
}
		FbInOverC (src, srca, ma, d, 0, m);
		FbInOverC (src, srca, ma, d, 8, n);
		FbInOverC (src, srca, ma, d, 16, o);
		FbInOverC (src, srca, ma, d, 24, p);
Aaron Plattner's avatar
Aaron Plattner committed
285
		WRITE(dst, m|n|o|p);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
286
287
288
289
	    }
	    dst++;
	}
    }
290
291
292

    fbFinishAccess (pMask->pDrawable);
    fbFinishAccess (pDst->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
293
294
}

295
#define srcAlphaCombine24(a,b) genericCombine24(a,b,srca,srcia)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
296
297
298
299
300
301
302
303
304
305
306
307
308
309
void
fbCompositeSolidMask_nx8x0888 (CARD8      op,
			       PicturePtr pSrc,
			       PicturePtr pMask,
			       PicturePtr pDst,
			       INT16      xSrc,
			       INT16      ySrc,
			       INT16      xMask,
			       INT16      yMask,
			       INT16      xDst,
			       INT16      yDst,
			       CARD16     width,
			       CARD16     height)
{
310
311
    CARD32	src, srca, srcia;
    CARD8	*dstLine, *dst, *edst;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
312
313
314
    CARD8	*maskLine, *mask, m;
    FbStride	dstStride, maskStride;
    CARD16	w;
315
    CARD32 rs,gs,bs,rd,gd,bd;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
316

317
    fbComposeGetSolid(pSrc, src, pDst->format);
318

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
319
    srca = src >> 24;
320
    srcia = 255-srca;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
321
322
    if (src == 0)
	return;
323

324
325
326
327
    rs=src&0xff;
    gs=(src>>8)&0xff;
    bs=(src>>16)&0xff;
      
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
328
329
    fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 3);
    fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1);
330

331
332
     while (height--)
  	{
333
	        /* fixme: cleanup unused */
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
 		unsigned int wt,wd;
 		CARD32 workingiDest;
 		CARD32 *widst;
 		
 		edst=dst = dstLine;
 		dstLine += dstStride;
 		mask = maskLine;
 		maskLine += maskStride;
 		w = width;
 		
#ifndef NO_MASKED_PACKED_READ
 		setupPackedReader(wd,wt,edst,widst,workingiDest);
#endif
 				
 		while (w--)
 		{
#ifndef NO_MASKED_PACKED_READ
 			readPackedDest(rd);
 			readPackedDest(gd);
 			readPackedDest(bd);
#else
 			rd= *edst++;
 			gd= *edst++;
 			bd= *edst++;
#endif
 			m = *mask++;
 			if (m == 0xff)
 			{
 				if (srca == 0xff)
 				{
 					*dst++=rs;
 					*dst++=gs;
 					*dst++=bs;
 				}
 				else
 				{
 					*dst++=(srcAlphaCombine24(rs, rd)>>8);
 					*dst++=(srcAlphaCombine24(gs, gd)>>8);
 					*dst++=(srcAlphaCombine24(bs, bd)>>8);
				}
 			}
 			else if (m)
 			{
 				int na=(srca*(int)m)>>8;
 				int nia=255-na;
 				*dst++=(genericCombine24(rs, rd, na, nia)>>8);
 				*dst++=(genericCombine24(gs, gd, na, nia)>>8);
 				*dst++=(genericCombine24(bs, bd, na, nia)>>8);
 			}
 			else
 			{
 				dst+=3;
 			}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
387
388
		}
	}
389
390
391

    fbFinishAccess (pMask->pDrawable);
    fbFinishAccess (pDst->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
}

void
fbCompositeSolidMask_nx8x0565 (CARD8      op,
				  PicturePtr pSrc,
				  PicturePtr pMask,
				  PicturePtr pDst,
				  INT16      xSrc,
				  INT16      ySrc,
				  INT16      xMask,
				  INT16      yMask,
				  INT16      xDst,
				  INT16      yDst,
				  CARD16     width,
				  CARD16     height)
{
408
409
410
411
412
413
414
415
416
417
418
419
420
421
    CARD32	src, srca8, srca5;
    CARD16	*dstLine, *dst;
    CARD16	d;
    CARD32	t;
    CARD8	*maskLine, *mask, m;
    FbStride	dstStride, maskStride;
    CARD16	w,src16;
    
    fbComposeGetSolid(pSrc, src, pDst->format);

    
    
    if (src == 0)
	return;
422
      
423
424
425
426
427
428
    srca8 = (src >> 24);
    srca5 = (srca8 >> 3);
    src16 = cvt8888to0565(src);
     
    fbComposeGetStart (pDst, xDst, yDst, CARD16, dstStride, dstLine, 1);
    fbComposeGetStart (pMask, xMask, yMask, CARD8, maskStride, maskLine, 1);
429
    
430
431
432
433
434
435
436
    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	mask = maskLine;
	maskLine += maskStride;
	w = width;
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
	while (w--)
	{
	    m = *mask++;
	    if (m == 0)
		dst++;
	    else if (srca5 == (0xff >> 3))
	    {
		if (m == 0xff)
		    *dst++ = src16;
		else 
 		{
		    d = *dst;
		    m >>= 3;
		    inOver0565 (m, src16, d, *dst++);
 		}
	    }
	    else
	    {
		d = *dst;
		if (m == 0xff) 
		{
		    t = fbOver24 (src, cvt0565to0888 (d));
		}
		else
		{
		    t = fbIn (src, m);
		    t = fbOver (t, cvt0565to0888 (d));
		}
		*dst++ = cvt8888to0565 (t);
	    }
	}
    }
    
471
472
    fbFinishAccess (pMask->pDrawable);
    fbFinishAccess (pDst->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
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
static void
fbCompositeSolidMask_nx8888x0565 (CARD8      op,
				  PicturePtr pSrc,
				  PicturePtr pMask,
				  PicturePtr pDst,
				  INT16      xSrc,
				  INT16      ySrc,
				  INT16      xMask,
				  INT16      yMask,
				  INT16      xDst,
				  INT16      yDst,
				  CARD16     width,
				  CARD16     height)
{
    CARD32	src, srca8, srca5;
    CARD16	*dstLine, *dst;
    CARD16	d;
    CARD32	*maskLine, *mask;
    CARD32	t;
    CARD8	m;
    FbStride	dstStride, maskStride;
    CARD16	w, src16;

    fbComposeGetSolid(pSrc, src, pDst->format);

    if (src == 0)
	return;

    srca8 = src >> 24;
    srca5 = srca8 >> 3;
    src16 = cvt8888to0565(src);

    fbComposeGetStart (pDst, xDst, yDst, CARD16, dstStride, dstLine, 1);
    fbComposeGetStart (pMask, xMask, yMask, CARD32, maskStride, maskLine, 1);

    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	mask = maskLine;
	maskLine += maskStride;
	w = width;

	while (w--)
	{
	    m = *mask++ >> 24;
	    if (m == 0)
		dst++;
	    else if (srca5 == (0xff >> 3))
	    {
		if (m == 0xff)
		    *dst++ = src16;
		else
		{
		    d = *dst;
		    m >>= 3;
		    inOver0565 (m, src16, d, *dst++);
		}
	    }
	    else
	    {
		if (m == 0xff) 
		{
		    d = *dst;
		    t = fbOver24 (src, cvt0565to0888 (d));
		    *dst++ = cvt8888to0565 (t);
		}
		else
		{
		    d = *dst;
		    t = fbIn (src, m);
		    t = fbOver (t, cvt0565to0888 (d));
		    *dst++ = cvt8888to0565 (t);
		}
	    }
	}
    }
}

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
void
fbCompositeSolidMask_nx8888x0565C (CARD8      op,
				   PicturePtr pSrc,
				   PicturePtr pMask,
				   PicturePtr pDst,
				   INT16      xSrc,
				   INT16      ySrc,
				   INT16      xMask,
				   INT16      yMask,
				   INT16      xDst,
				   INT16      yDst,
				   CARD16     width,
				   CARD16     height)
{
    CARD32	src, srca;
    CARD16	src16;
    CARD16	*dstLine, *dst;
    CARD32	d;
    CARD32	*maskLine, *mask, ma;
    FbStride	dstStride, maskStride;
    CARD16	w;
    CARD32	m, n, o;

577
    fbComposeGetSolid(pSrc, src, pDst->format);
578

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
579
580
581
    srca = src >> 24;
    if (src == 0)
	return;
582

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
583
    src16 = cvt8888to0565(src);
584

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
585
586
    fbComposeGetStart (pDst, xDst, yDst, CARD16, dstStride, dstLine, 1);
    fbComposeGetStart (pMask, xMask, yMask, CARD32, maskStride, maskLine, 1);
587

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
588
589
590
591
592
593
594
595
596
597
    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	mask = maskLine;
	maskLine += maskStride;
	w = width;

	while (w--)
	{
Aaron Plattner's avatar
Aaron Plattner committed
598
	    ma = READ(mask++);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
599
600
601
602
	    if (ma == 0xffffffff)
	    {
		if (srca == 0xff)
		{
Aaron Plattner's avatar
Aaron Plattner committed
603
		    WRITE(dst, src16);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
604
605
606
		}
		else
		{
Aaron Plattner's avatar
Aaron Plattner committed
607
		    d = READ(dst);
608
		    d = fbOver24 (src, cvt0565to0888(d));
Aaron Plattner's avatar
Aaron Plattner committed
609
		    WRITE(dst, cvt8888to0565(d));
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
610
611
612
613
		}
	    }
	    else if (ma)
	    {
Aaron Plattner's avatar
Aaron Plattner committed
614
		d = READ(dst);
615
		d = cvt0565to0888(d);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
616
617
618
619
		FbInOverC (src, srca, ma, d, 0, m);
		FbInOverC (src, srca, ma, d, 8, n);
		FbInOverC (src, srca, ma, d, 16, o);
		d = m|n|o;
Aaron Plattner's avatar
Aaron Plattner committed
620
		WRITE(dst, cvt8888to0565(d));
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
621
622
623
624
	    }
	    dst++;
	}
    }
625
626
627

    fbFinishAccess (pMask->pDrawable);
    fbFinishAccess (pDst->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
}

void
fbCompositeSrc_8888x8888 (CARD8      op,
			 PicturePtr pSrc,
			 PicturePtr pMask,
			 PicturePtr pDst,
			 INT16      xSrc,
			 INT16      ySrc,
			 INT16      xMask,
			 INT16      yMask,
			 INT16      xDst,
			 INT16      yDst,
			 CARD16     width,
			 CARD16     height)
{
    CARD32	*dstLine, *dst, dstMask;
    CARD32	*srcLine, *src, s;
    FbStride	dstStride, srcStride;
    CARD8	a;
    CARD16	w;
649

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
650
651
    fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1);
    fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1);
652

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
653
654
655
656
657
658
659
660
661
662
663
664
    dstMask = FbFullMask (pDst->pDrawable->depth);

    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	src = srcLine;
	srcLine += srcStride;
	w = width;

	while (w--)
	{
Aaron Plattner's avatar
Aaron Plattner committed
665
	    s = READ(src++);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
666
667
	    a = s >> 24;
	    if (a == 0xff)
Aaron Plattner's avatar
Aaron Plattner committed
668
		WRITE(dst, s & dstMask);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
669
	    else if (a)
Aaron Plattner's avatar
Aaron Plattner committed
670
		WRITE(dst, fbOver (s, READ(dst)) & dstMask);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
671
672
673
	    dst++;
	}
    }
674
675
676

    fbFinishAccess (pSrc->pDrawable);
    fbFinishAccess (pDst->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
}

void
fbCompositeSrc_8888x0888 (CARD8      op,
			 PicturePtr pSrc,
			 PicturePtr pMask,
			 PicturePtr pDst,
			 INT16      xSrc,
			 INT16      ySrc,
			 INT16      xMask,
			 INT16      yMask,
			 INT16      xDst,
			 INT16      yDst,
			 CARD16     width,
			 CARD16     height)
{
    CARD8	*dstLine, *dst;
    CARD32	d;
    CARD32	*srcLine, *src, s;
    CARD8	a;
    FbStride	dstStride, srcStride;
    CARD16	w;
699

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
700
701
    fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 3);
    fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1);
702

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
703
704
705
706
707
708
709
710
711
712
    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	src = srcLine;
	srcLine += srcStride;
	w = width;

	while (w--)
	{
Aaron Plattner's avatar
Aaron Plattner committed
713
	    s = READ(src++);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
714
715
716
717
718
719
720
721
722
723
724
725
	    a = s >> 24;
	    if (a)
	    {
		if (a == 0xff)
		    d = s;
		else
		    d = fbOver24 (s, Fetch24(dst));
		Store24(dst,d);
	    }
	    dst += 3;
	}
    }
726
727
728

    fbFinishAccess (pSrc->pDrawable);
    fbFinishAccess (pDst->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
}

void
fbCompositeSrc_8888x0565 (CARD8      op,
			 PicturePtr pSrc,
			 PicturePtr pMask,
			 PicturePtr pDst,
			 INT16      xSrc,
			 INT16      ySrc,
			 INT16      xMask,
			 INT16      yMask,
			 INT16      xDst,
			 INT16      yDst,
			 CARD16     width,
			 CARD16     height)
{
    CARD16	*dstLine, *dst;
    CARD32	d;
    CARD32	*srcLine, *src, s;
    CARD8	a;
    FbStride	dstStride, srcStride;
    CARD16	w;
751

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
752
753
754
755
756
757
758
759
760
761
762
763
764
    fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1);
    fbComposeGetStart (pDst, xDst, yDst, CARD16, dstStride, dstLine, 1);

    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	src = srcLine;
	srcLine += srcStride;
	w = width;

	while (w--)
	{
Aaron Plattner's avatar
Aaron Plattner committed
765
	    s = READ(src++);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
766
767
768
769
770
771
772
	    a = s >> 24;
	    if (a)
	    {
		if (a == 0xff)
		    d = s;
		else
		{
Aaron Plattner's avatar
Aaron Plattner committed
773
		    d = READ(dst);
774
		    d = fbOver24 (s, cvt0565to0888(d));
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
775
		}
Aaron Plattner's avatar
Aaron Plattner committed
776
		WRITE(dst, cvt8888to0565(d));
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
777
778
779
780
	    }
	    dst++;
	}
    }
781
782
783

    fbFinishAccess (pDst->pDrawable);
    fbFinishAccess (pSrc->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
}

void
fbCompositeSrcAdd_8000x8000 (CARD8	op,
			     PicturePtr pSrc,
			     PicturePtr pMask,
			     PicturePtr pDst,
			     INT16      xSrc,
			     INT16      ySrc,
			     INT16      xMask,
			     INT16      yMask,
			     INT16      xDst,
			     INT16      yDst,
			     CARD16     width,
			     CARD16     height)
{
    CARD8	*dstLine, *dst;
    CARD8	*srcLine, *src;
    FbStride	dstStride, srcStride;
    CARD16	w;
    CARD8	s, d;
    CARD16	t;
806

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
807
808
809
810
811
812
813
814
815
816
817
818
819
    fbComposeGetStart (pSrc, xSrc, ySrc, CARD8, srcStride, srcLine, 1);
    fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 1);

    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	src = srcLine;
	srcLine += srcStride;
	w = width;

	while (w--)
	{
Aaron Plattner's avatar
Aaron Plattner committed
820
	    s = READ(src++);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
821
822
823
824
	    if (s)
	    {
		if (s != 0xff)
		{
Aaron Plattner's avatar
Aaron Plattner committed
825
		    d = READ(dst);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
826
827
828
		    t = d + s;
		    s = t | (0 - (t >> 8));
		}
Aaron Plattner's avatar
Aaron Plattner committed
829
		WRITE(dst, s);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
830
831
832
833
	    }
	    dst++;
	}
    }
834
835
836

    fbFinishAccess (pDst->pDrawable);
    fbFinishAccess (pSrc->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
}

void
fbCompositeSrcAdd_8888x8888 (CARD8	op,
			     PicturePtr pSrc,
			     PicturePtr pMask,
			     PicturePtr pDst,
			     INT16      xSrc,
			     INT16      ySrc,
			     INT16      xMask,
			     INT16      yMask,
			     INT16      xDst,
			     INT16      yDst,
			     CARD16     width,
			     CARD16     height)
{
    CARD32	*dstLine, *dst;
    CARD32	*srcLine, *src;
    FbStride	dstStride, srcStride;
    CARD16	w;
    CARD32	s, d;
    CARD16	t;
    CARD32	m,n,o,p;
860

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
861
862
863
864
865
866
867
868
869
870
871
872
873
    fbComposeGetStart (pSrc, xSrc, ySrc, CARD32, srcStride, srcLine, 1);
    fbComposeGetStart (pDst, xDst, yDst, CARD32, dstStride, dstLine, 1);

    while (height--)
    {
	dst = dstLine;
	dstLine += dstStride;
	src = srcLine;
	srcLine += srcStride;
	w = width;

	while (w--)
	{
Aaron Plattner's avatar
Aaron Plattner committed
874
	    s = READ(src++);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
875
876
877
878
	    if (s)
	    {
		if (s != 0xffffffff)
		{
Aaron Plattner's avatar
Aaron Plattner committed
879
		    d = READ(dst);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
880
881
882
883
884
885
886
887
888
		    if (d)
		    {
			m = FbAdd(s,d,0,t);
			n = FbAdd(s,d,8,t);
			o = FbAdd(s,d,16,t);
			p = FbAdd(s,d,24,t);
			s = m|n|o|p;
		    }
		}
Aaron Plattner's avatar
Aaron Plattner committed
889
		WRITE(dst, s);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
890
891
892
893
	    }
	    dst++;
	}
    }
894
895
896

    fbFinishAccess (pDst->pDrawable);
    fbFinishAccess (pSrc->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
}

void
fbCompositeSrcAdd_1000x1000 (CARD8	op,
			     PicturePtr pSrc,
			     PicturePtr pMask,
			     PicturePtr pDst,
			     INT16      xSrc,
			     INT16      ySrc,
			     INT16      xMask,
			     INT16      yMask,
			     INT16      xDst,
			     INT16      yDst,
			     CARD16     width,
			     CARD16     height)
{
    FbBits	*dstBits, *srcBits;
    FbStride	dstStride, srcStride;
    int		dstBpp, srcBpp;
    int		dstXoff, dstYoff;
    int		srcXoff, srcYoff;
918

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
    fbGetDrawable(pSrc->pDrawable, srcBits, srcStride, srcBpp, srcXoff, srcYoff);

    fbGetDrawable(pDst->pDrawable, dstBits, dstStride, dstBpp, dstXoff, dstYoff);

    fbBlt (srcBits + srcStride * (ySrc + srcYoff),
	   srcStride,
	   xSrc + srcXoff,

	   dstBits + dstStride * (yDst + dstYoff),
	   dstStride,
	   xDst + dstXoff,

	   width,
	   height,

	   GXor,
	   FB_ALLONES,
	   srcBpp,

	   FALSE,
	   FALSE);
940
941
942

    fbFinishAccess(pDst->pDrawable);
    fbFinishAccess(pSrc->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
}

void
fbCompositeSolidMask_nx1xn (CARD8      op,
			    PicturePtr pSrc,
			    PicturePtr pMask,
			    PicturePtr pDst,
			    INT16      xSrc,
			    INT16      ySrc,
			    INT16      xMask,
			    INT16      yMask,
			    INT16      xDst,
			    INT16      yDst,
			    CARD16     width,
			    CARD16     height)
{
    FbBits	*dstBits;
    FbStip	*maskBits;
    FbStride	dstStride, maskStride;
    int		dstBpp, maskBpp;
    int		dstXoff, dstYoff;
    int		maskXoff, maskYoff;
    FbBits	src;
966

967
    fbComposeGetSolid(pSrc, src, pDst->format);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
968
969
970
971

    if ((src & 0xff000000) != 0xff000000)
    {
	fbCompositeGeneral  (op, pSrc, pMask, pDst,
972
			     xSrc, ySrc, xMask, yMask, xDst, yDst,
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
			     width, height);
	return;
    }
    fbGetStipDrawable (pMask->pDrawable, maskBits, maskStride, maskBpp, maskXoff, maskYoff);
    fbGetDrawable (pDst->pDrawable, dstBits, dstStride, dstBpp, dstXoff, dstYoff);

    switch (dstBpp) {
    case 32:
	break;
    case 24:
	break;
    case 16:
	src = cvt8888to0565(src);
	break;
    }

    src = fbReplicatePixel (src, dstBpp);

    fbBltOne (maskBits + maskStride * (yMask + maskYoff),
	      maskStride,
	      xMask + maskXoff,

	      dstBits + dstStride * (yDst + dstYoff),
	      dstStride,
	      (xDst + dstXoff) * dstBpp,
	      dstBpp,

	      width * dstBpp,
	      height,

	      0x0,
	      src,
	      FB_ALLONES,
	      0x0);
1007
1008
1009

    fbFinishAccess (pDst->pDrawable);
    fbFinishAccess (pMask->pDrawable);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1010
1011
1012
1013
}

# define mod(a,b)	((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b))

1014
1015
1016
/*
 * Apply a constant alpha value in an over computation
 */
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
static void
fbCompositeSrcSrc_nxn  (CARD8	   op,
			PicturePtr pSrc,
			PicturePtr pMask,
			PicturePtr pDst,
			INT16      xSrc,
			INT16      ySrc,
			INT16      xMask,
			INT16      yMask,
			INT16      xDst,
			INT16      yDst,
			CARD16     width,
			CARD16     height);
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050

static void
fbCompositeTrans_0565xnx0565(CARD8      op,
			     PicturePtr pSrc,
			     PicturePtr pMask,
			     PicturePtr pDst,
			     INT16      xSrc,
			     INT16      ySrc,
			     INT16      xMask,
			     INT16      yMask,
			     INT16      xDst,
			     INT16      yDst,
			     CARD16     width,
			     CARD16     height)
{
    CARD16	*dstLine, *dst;
    CARD16	*srcLine, *src;
    FbStride	dstStride, srcStride;
    CARD16	w;
    FbBits	mask;
    CARD8	maskAlpha;
1051
1052
    CARD16	s_16, d_16;
    CARD32	s_32, d_32;
1053
1054
    
    fbComposeGetSolid (pMask, mask, pDst->format);
1055
    maskAlpha = mask >> 27;
1056
1057
1058
1059
1060
    
    if (!maskAlpha)
	return;
    if (maskAlpha == 0xff)
    {
1061
1062
1063
	fbCompositeSrcSrc_nxn (PictOpSrc, pSrc, pMask, pDst,
			       xSrc, ySrc, xMask, yMask, xDst, yDst, 
			       width, height);
1064
1065
1066
1067
1068
1069
1070
	return;
    }

    fbComposeGetStart (pSrc, xSrc, ySrc, CARD16, srcStride, srcLine, 1);
    fbComposeGetStart (pDst, xDst, yDst, CARD16, dstStride, dstLine, 1);

    while (height--)
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
    {
	CARD32 *isrc, *idst;
	dst = dstLine;
	dstLine += dstStride;
	src = srcLine;
	srcLine += srcStride;
	w = width;
	
	if(((int)src&1)==1)
	{
	    s_16 = *src++;
	    d_16 = *dst;
	    inOver0565(maskAlpha, s_16, d_16, *dst++);
	    w--;
	}
	isrc=(CARD32 *)src;
	if(((int)dst&1)==0)
	{
	    idst=(CARD32 *)dst;
	    while (w>1)
	    {
		s_32 = *isrc++;
		d_32 = *idst;
		inOver2x0565(maskAlpha, s_32, d_32, *idst++);
		w-=2;
	    }
	    dst=(CARD16 *)idst;
	}
	else
	{
	    while (w > 1)
	    {
		s_32 = *isrc++;
1104
#if IMAGE_BYTE_ORDER == LSBFirst
1105
		s_16=s_32&0xffff;
1106
#else
1107
		s_16=s_32>>16;
1108
#endif
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
		d_16 = *dst;
		inOver0565 (maskAlpha, s_16, d_16, *dst++);
#if IMAGE_BYTE_ORDER == LSBFirst
		s_16=s_32>>16;
#else
		s_16=s_32&0xffff;
#endif
		d_16 = *dst;
		inOver0565(maskAlpha, s_16, d_16, *dst++);
		w-=2;
	    }
	}
	src=(CARD16 *)isrc;
	if(w!=0)
	{
	    s_16 = *src;
	    d_16 = *dst;
	    inOver0565(maskAlpha, s_16, d_16, *dst);
	}
    }
    
1130
1131
1132
1133
    fbFinishAccess (pSrc->pDrawable);
    fbFinishAccess (pDst->pDrawable);
}

1134
/* macros for "i can't believe it's not fast" packed pixel handling */
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
#define alphamaskCombine24(a,b) genericCombine24(a,b,maskAlpha,maskiAlpha)
static void
fbCompositeTrans_0888xnx0888(CARD8      op,
 			     PicturePtr pSrc,
 			     PicturePtr pMask,
 			     PicturePtr pDst,
 			     INT16      xSrc,
 			     INT16      ySrc,
 			     INT16      xMask,
 			     INT16      yMask,
 			     INT16      xDst,
 			     INT16      yDst,
 			     CARD16     width,
 			     CARD16     height)
 {
     CARD8	*dstLine, *dst,*idst;
     CARD8	*srcLine, *src;
     FbStride	dstStride, srcStride;
     CARD16	w;
     FbBits	mask;
     CARD16	maskAlpha,maskiAlpha;
     
     fbComposeGetSolid (pMask, mask, pDst->format);
     maskAlpha = mask >> 24;
 	maskiAlpha= 255-maskAlpha;
     
     if (!maskAlpha)
 	return;
1163
1164
1165
1166
1167
1168
1169
1170
1171
     /*
     if (maskAlpha == 0xff)
     {
 	fbCompositeSrc_0888x0888 (op, pSrc, pMask, pDst,
 				  xSrc, ySrc, xMask, yMask, xDst, yDst, 
 				  width, height);
 	return;
     }
     */
1172
1173
1174
1175
1176
 	
     fbComposeGetStart (pSrc, xSrc, ySrc, CARD8, srcStride, srcLine, 3);
     fbComposeGetStart (pDst, xDst, yDst, CARD8, dstStride, dstLine, 3);
  
  	{
1177
 		unsigned int ws,wt;
1178
 		CARD32 workingSource;
1179
1180
1181
1182
		CARD32 *wsrc, *wdst, *widst;
		CARD32 rs, rd, nd;
		CARD8 *isrc;

1183
 
1184
1185
1186
 		/* are xSrc and xDst at the same alignment?  if not, we need to be complicated :) */
 		/* if(0==0) */
		if( (((xSrc*3)&3)!=((xDst*3)&3)) || ((srcStride&3)!=(dstStride&3)))
1187
1188
1189
 		{
 			while (height--)
 			{
1190
			        dst = dstLine;
1191
 				dstLine += dstStride;
1192
 				isrc = src = srcLine;
1193
1194
1195
 				srcLine += srcStride;
 				w = width*3;
 				
1196
1197
1198
				setupPackedReader(ws,wt,isrc,wsrc,workingSource);
				
 				/* get to word aligned */
1199
1200
1201
 				switch(!(int)src&3)
 				{
 					case 1:
1202
1203
1204
1205
1206
					        readPackedSource(rs);
						/* *dst++=alphamaskCombine24(rs, *dst)>>8; */
						rd=*dst;  /* make gcc happy.  hope it doens't cost us too much performance*/
						*dst++=alphamaskCombine24(rs, rd)>>8;
						w--; if(w==0) break;
1207
 					case 2:
1208
1209
1210
					        readPackedSource(rs);
						rd=*dst;  
						*dst++=alphamaskCombine24(rs, rd)>>8;
1211
1212
 						w--; if(w==0) break;
 					case 3:
1213
1214
1215
					        readPackedSource(rs);
						rd=*dst;  
						*dst++=alphamaskCombine24(rs, rd)>>8;
1216
1217
 						w--; if(w==0) break;
 				}
1218
 				wdst=(CARD32 *)dst;
1219
1220
1221
				while (w>3)
				{
 					rs=*wsrc++;
1222
1223
1224
					/* FIXME: write a special readPackedWord macro, which knows how to 
					 * halfword combine
					 */
1225
 #if IMAGE_BYTE_ORDER == LSBFirst
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
					rd=*wdst;
					readPackedSource(nd);
					readPackedSource(rs);
					nd|=rs<<8;
					readPackedSource(rs);
					nd|=rs<<16;
					readPackedSource(rs);
					nd|=rs<<24;
#else
					readPackedSource(nd);
					nd<<=24;
					readPackedSource(rs);
					nd|=rs<<16;
					readPackedSource(rs);
					nd|=rs<<8;
					readPackedSource(rs);
					nd|=rs;
#endif
					inOver0888(maskAlpha, nd, rd, *wdst++);
1245
1246
 					w-=4;
 				}
1247
 				src=(CARD8 *)wdst;
1248
1249
1250
 				switch(w)
 				{
 					case 3:
1251
1252
1253
						readPackedSource(rs);
						rd=*dst;  
						*dst++=alphamaskCombine24(rs, rd)>>8;
1254
 					case 2:
1255
1256
1257
					        readPackedSource(rs);
						rd=*dst;  
						*dst++=alphamaskCombine24(rs, rd)>>8;
1258
 					case 1:
1259
1260
1261
                                               readPackedSource(rs);
                                               rd=*dst;  
                                               *dst++=alphamaskCombine24(rs, rd)>>8;
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
 				}
 			}
 		}
 		else
 		{
 			while (height--)
 			{
 				idst=dst = dstLine;
 				dstLine += dstStride;
 				src = srcLine;
 				srcLine += srcStride;
 				w = width*3;
1274
 				/* get to word aligned */
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
 				switch(!(int)src&3)
 				{
					case 1:
 						rd=alphamaskCombine24(*src++, *dst)>>8;
 						*dst++=rd;
 						w--; if(w==0) break;
 					case 2:
 						rd=alphamaskCombine24(*src++, *dst)>>8;
 						*dst++=rd;
 						w--; if(w==0) break;
					case 3:
 						rd=alphamaskCombine24(*src++, *dst)>>8;
 						*dst++=rd;
 						w--; if(w==0) break;
 				}
 				wsrc=(CARD32 *)src;
 				widst=(CARD32 *)dst;
 				while(w>3)
 				{
 					rs = *wsrc++;
 					rd = *widst;
1296
 					inOver0888 (maskAlpha, rs, rd, *widst++);
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
 					w-=4;
 				}
				src=(CARD8 *)wsrc;
 				dst=(CARD8 *)widst;
 				switch(w)
 				{
 					case 3:
 						rd=alphamaskCombine24(*src++, *dst)>>8;
 						*dst++=rd;
 					case 2:
						rd=alphamaskCombine24(*src++, *dst)>>8;
 						*dst++=rd;
 					case 1:
 						rd=alphamaskCombine24(*src++, *dst)>>8;
 						*dst++=rd;
 				}
 			}
 		}
 	}
  }


1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
/*
 * Simple bitblt
 */

static void
fbCompositeSrcSrc_nxn  (CARD8	   op,
			PicturePtr pSrc,
			PicturePtr pMask,
			PicturePtr pDst,
			INT16      xSrc,
			INT16      ySrc,
			INT16      xMask,
			INT16      yMask,
			INT16      xDst,
			INT16      yDst,
			CARD16     width,
			CARD16     height)
{
    FbBits	*dst;
    FbBits	*src;
    FbStride	dstStride, srcStride;
    int		srcXoff, srcYoff;
    int		dstXoff, dstYoff;
    int		srcBpp;
    int		dstBpp;
    Bool	reverse = FALSE;
    Bool	upsidedown = FALSE;
1346
1347
1348
1349
1350
1351
1352
    
    fbGetDrawable(pSrc->pDrawable,src,srcStride,srcBpp,srcXoff,srcYoff);
    fbGetDrawable(pDst->pDrawable,dst,dstStride,dstBpp,dstXoff,dstYoff);
	
    fbBlt (src + (ySrc + srcYoff) * srcStride,
	   srcStride,
	   (xSrc + srcXoff) * srcBpp,
1353
 
1354
1355
1356
	   dst + (yDst + dstYoff) * dstStride,
	   dstStride,
	   (xDst + dstXoff) * dstBpp,
1357

1358
1359
1360
1361
1362
1363
1364
1365
1366
	   (width) * dstBpp,
	   (height),

	   GXcopy,
	   FB_ALLONES,
	   dstBpp,

	   reverse,
	   upsidedown);
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
    
    fbFinishAccess(pSrc->pDrawable);
    fbFinishAccess(pDst->pDrawable);
}

/*
 * Solid fill
void
fbCompositeSolidSrc_nxn  (CARD8	op,
			  PicturePtr pSrc,
			  PicturePtr pMask,
			  PicturePtr pDst,
			  INT16      xSrc,
			  INT16      ySrc,
			  INT16      xMask,
			  INT16      yMask,
			  INT16      xDst,
			  INT16      yDst,
			  CARD16     width,
			  CARD16     height)
{
    
}
 */

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
void
fbComposite (CARD8      op,
	     PicturePtr pSrc,
	     PicturePtr pMask,
	     PicturePtr pDst,
	     INT16      xSrc,
	     INT16      ySrc,
	     INT16      xMask,
	     INT16      yMask,
	     INT16      xDst,
	     INT16      yDst,
	     CARD16     width,
	     CARD16     height)
{
    RegionRec	    region;
    int		    n;
    BoxPtr	    pbox;
1409
    CompositeFunc   func = NULL;
1410
    Bool	    srcRepeat = pSrc->pDrawable && pSrc->repeat;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1411
1412
1413
1414
1415
1416
    Bool	    maskRepeat = FALSE;
    Bool	    srcAlphaMap = pSrc->alphaMap != 0;
    Bool	    maskAlphaMap = FALSE;
    Bool	    dstAlphaMap = pDst->alphaMap != 0;
    int		    x_msk, y_msk, x_src, y_src, x_dst, y_dst;
    int		    w, h, w_this, h_this;
1417

1418
1419
1420
1421
1422
1423
1424
1425
#ifdef USE_MMX
    static Bool mmx_setup = FALSE;
    if (!mmx_setup) {
        fbComposeSetupMMX();
        mmx_setup = TRUE;
    }
#endif
        
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1426
1427
    xDst += pDst->pDrawable->x;
    yDst += pDst->pDrawable->y;
1428
1429
1430
1431
1432
    if (pSrc->pDrawable) {
        xSrc += pSrc->pDrawable->x;
        ySrc += pSrc->pDrawable->y;
    }
    if (pMask && pMask->pDrawable)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1433
1434
1435
    {
	xMask += pMask->pDrawable->x;
	yMask += pMask->pDrawable->y;
1436
	maskRepeat = pMask->repeat == RepeatNormal;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1437
1438
	maskAlphaMap = pMask->alphaMap != 0;
    }
1439

1440
1441
1442
1443
1444
    if (pSrc->pDrawable && (!pMask || pMask->pDrawable)
        && !pSrc->transform && !(pMask && pMask->transform)
        && !maskAlphaMap && !srcAlphaMap && !dstAlphaMap
        && (pSrc->filter != PictFilterConvolution)
        && (!pMask || pMask->filter != PictFilterConvolution))
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1445
    switch (op) {
1446
1447
1448
    case PictOpSrc:
#ifdef USE_MMX
	if (!pMask && pSrc->format == pDst->format &&
1449
	    pSrc->format != PICT_a8 && pSrc->pDrawable != pDst->pDrawable)
1450
1451
1452
	{
	    func = fbCompositeCopyAreammx;
	}
1453
	else
1454
#endif
1455
1456
	    if (pMask == 0)
	    {
1457
		if (pSrc->format == pDst->format)
1458
1459
		    func = fbCompositeSrcSrc_nxn;
	    }
1460
	break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1461
1462
1463
    case PictOpOver:
	if (pMask)
	{
1464
1465
	    if (fbCanGetSolid(pSrc) &&
		!maskRepeat)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1466
1467
1468
1469
1470
1471
1472
	    {
		if (PICT_FORMAT_COLOR(pSrc->format)) {
		    switch (pMask->format) {
		    case PICT_a8:
			switch (pDst->format) {
			case PICT_r5g6b5:
			case PICT_b5g6r5:
1473
#ifdef USE_MMX
1474
1475
1476
1477
1478
			    if (fbHaveMMX())
				func = fbCompositeSolidMask_nx8x0565mmx;
			    else
#endif
				func = fbCompositeSolidMask_nx8x0565;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1479
1480
1481
1482
1483
1484
1485
1486
1487
			    break;
			case PICT_r8g8b8:
			case PICT_b8g8r8:
			    func = fbCompositeSolidMask_nx8x0888;
			    break;
			case PICT_a8r8g8b8:
			case PICT_x8r8g8b8:
			case PICT_a8b8g8r8:
			case PICT_x8b8g8r8:
1488
#ifdef USE_MMX
1489
1490
1491
1492
1493
			    if (fbHaveMMX())
				func = fbCompositeSolidMask_nx8x8888mmx;
			    else
#endif
				func = fbCompositeSolidMask_nx8x8888;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1494
			    break;
1495
1496
			default:
			    break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1497
1498
1499
1500
1501
1502
1503
			}
			break;
		    case PICT_a8r8g8b8:
			if (pMask->componentAlpha) {
			    switch (pDst->format) {
			    case PICT_a8r8g8b8:
			    case PICT_x8r8g8b8:
1504
#ifdef USE_MMX
1505
1506
1507
1508
1509
				if (fbHaveMMX())
				    func = fbCompositeSolidMask_nx8888x8888Cmmx;
				else
#endif
				    func = fbCompositeSolidMask_nx8888x8888C;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1510
1511
				break;
			    case PICT_r5g6b5:
1512
#ifdef USE_MMX
1513
1514
1515
1516
1517
				if (fbHaveMMX())
				    func = fbCompositeSolidMask_nx8888x0565Cmmx;
				else
#endif
				    func = fbCompositeSolidMask_nx8888x0565C;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1518
				break;
1519
1520
			    default:
				break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1521
1522
			    }
			}
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
			else
			{
			    switch (pDst->format) {
                            case PICT_r5g6b5:
                                func = fbCompositeSolidMask_nx8888x0565;
                                break;
			    default:
				break;
                            }
			}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1533
1534
1535
1536
1537
1538
			break;
		    case PICT_a8b8g8r8:
			if (pMask->componentAlpha) {
			    switch (pDst->format) {
			    case PICT_a8b8g8r8:
			    case PICT_x8b8g8r8:
1539
#ifdef USE_MMX
1540
1541
1542
1543
1544
				if (fbHaveMMX())
				    func = fbCompositeSolidMask_nx8888x8888Cmmx;
				else
#endif
				    func = fbCompositeSolidMask_nx8888x8888C;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1545
1546
				break;
			    case PICT_b5g6r5:
1547
#ifdef USE_MMX
1548
1549
1550
1551
1552
				if (fbHaveMMX())
				    func = fbCompositeSolidMask_nx8888x0565Cmmx;
				else
#endif
				    func = fbCompositeSolidMask_nx8888x0565C;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1553
				break;
1554
1555
			    default:
				break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1556
1557
			    }
			}
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
			else
			{
			    switch (pDst->format) {
                            case PICT_b5g6r5:
                                func = fbCompositeSolidMask_nx8888x0565;
                                break;
			    default:
				break;
                            }
			}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
			break;
		    case PICT_a1:
			switch (pDst->format) {
			case PICT_r5g6b5:
			case PICT_b5g6r5:
			case PICT_r8g8b8:
			case PICT_b8g8r8:
			case PICT_a8r8g8b8:
			case PICT_x8r8g8b8:
			case PICT_a8b8g8r8:
			case PICT_x8b8g8r8:
			    func = fbCompositeSolidMask_nx1xn;
			    break;
1581
1582
			default:
			    break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1583
			}
1584
			break;
1585
1586
		    default:
			break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1587
		    }
1588
1589
		default:
		    break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1590
1591
		}
	    }
1592
	    else if (! srcRepeat) /* has mask and non-repeating source */
1593
1594
1595
	    {
		if (pSrc->pDrawable == pMask->pDrawable &&
		    xSrc == xMask && ySrc == yMask &&
1596
		    !pMask->componentAlpha && !maskRepeat)
1597
		{
1598
		    /* source == mask: non-premultiplied data */
1599
1600
1601
1602
1603
1604
1605
1606
		    switch (pSrc->format) {
		    case PICT_x8b8g8r8:
			switch (pMask->format) {
			case PICT_a8r8g8b8:
			case PICT_a8b8g8r8:
			    switch (pDst->format) {
			    case PICT_a8r8g8b8:
			    case PICT_x8r8g8b8:
1607
#ifdef USE_MMX
1608
1609
1610
1611
1612
				if (fbHaveMMX())
				    func = fbCompositeSrc_8888RevNPx8888mmx;
#endif
				break;
			    case PICT_r5g6b5:
1613
#ifdef USE_MMX
1614
1615
1616
1617
				if (fbHaveMMX())
				    func = fbCompositeSrc_8888RevNPx0565mmx;
#endif
				break;
1618
1619
			    default:
				break;
1620
1621
			    }
			    break;
1622
1623
			default:
			    break;
1624
1625
1626
1627
1628
1629
1630
1631
1632
			}
			break;
		    case PICT_x8r8g8b8:
			switch (pMask->format) {
			case PICT_a8r8g8b8:
			case PICT_a8b8g8r8:
			    switch (pDst->format) {
			    case PICT_a8b8g8r8:
			    case PICT_x8b8g8r8:
1633
#ifdef USE_MMX
1634
1635
1636
1637
1638
				if (fbHaveMMX())
				    func = fbCompositeSrc_8888RevNPx8888mmx;
#endif
				break;
			    case PICT_r5g6b5:
1639
#ifdef USE_MMX
1640
1641
1642
1643
				if (fbHaveMMX())
				    func = fbCompositeSrc_8888RevNPx0565mmx;
#endif
				break;
1644
1645
			    default:
				break;
1646
1647
			    }
			    break;
1648
1649
			default:
			    break;
1650
1651
			}
			break;
1652
1653
		    default:
			break;