1/* **********************************************************
2 * Copyright (C) 1999-2001 VMware, Inc.
3 * All Rights Reserved
4 * **********************************************************/
5#ifdef VMX86_DEVEL
6char rcsId_bits2pixels[] = "Id: bits2pixels.c,v 1.6 2001/01/26 23:32:15 yoel Exp $";
7#else
8#define FILECODE "F(814)"
9#endif
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15/*
16 * bits2pixels.c --
17 *
18 *      Emulation routines to convert bitmaps to pixmaps
19 */
20
21#include "vm_basic_types.h"
22#include "bits2pixels.h"
23
24
25/*
26 *  Local functions
27 */
28
29static void RasterBitsToPixels8(uint8 *bits, uint32 bits_increment,
30			 uint8 *pix, uint32 pix_increment,
31			 uint32 width, uint32 height, uint32 fg, uint32 bg);
32
33static void RasterBitsToPixels16(uint8 *bits, uint32 bits_increment,
34			  uint8 *pix, uint32 pix_increment,
35			  uint32 width, uint32 height, uint32 fg, uint32 bg);
36
37static void RasterBitsToPixels24(uint8 *bits, uint32 bits_increment,
38			  uint8 *pix, uint32 pix_increment,
39			  uint32 width, uint32 height, uint32 fg, uint32 bg);
40
41static void RasterBitsToPixels32(uint8 *bits, uint32 bits_increment,
42			  uint8 *pix, uint32 pix_increment,
43			  uint32 width, uint32 height, uint32 fg, uint32 bg);
44
45
46/*
47 *----------------------------------------------------------------------
48 *
49 * vmwareRaster_BitsToPixels --
50 *
51 *	Convert a bitmap to a pixmap, converting 1 bits to the foreground
52 *      color (fg) and 0 bits to the background color (bg).
53 *
54 * Results:
55 *      Pixmap filled with pixels
56 *
57 * Side effects:
58 *	None
59 *
60 *----------------------------------------------------------------------
61 */
62
63void
64vmwareRaster_BitsToPixels(uint8 *bits, uint32 bits_increment,
65		    uint8 *pix, uint32 pix_increment, int bytes_per_pixel,
66		    uint32 width, uint32 height, uint32 fg, uint32 bg)
67{
68   switch (bytes_per_pixel) {
69      case 1:
70	 RasterBitsToPixels8(bits, bits_increment, pix, pix_increment,
71			     width, height, fg, bg);
72	 break;
73
74      case 2:
75	 RasterBitsToPixels16(bits, bits_increment, pix, pix_increment,
76			      width, height, fg, bg);
77	 break;
78
79      case 3:
80	 RasterBitsToPixels24(bits, bits_increment, pix, pix_increment,
81			      width, height, fg, bg);
82	 break;
83
84      case 4:
85	 RasterBitsToPixels32(bits, bits_increment, pix, pix_increment,
86			      width, height, fg, bg);
87	 break;
88   }
89}
90
91
92/*
93 *----------------------------------------------------------------------
94 *
95 * RasterBitsToPixels8 --
96 *
97 *	Convert a bitmap to a pixmap, converting 1 bits to the foreground
98 *      color (fg) and 0 bits to the background color (bg), for an 8-bit
99 *	pixmap
100 *
101 * Results:
102 *      Pixmap filled with pixels
103 *
104 * Side effects:
105 *	None
106 *
107 *----------------------------------------------------------------------
108 */
109
110void
111RasterBitsToPixels8(uint8 *bits, uint32 bits_increment,
112		    uint8 *pix, uint32 pix_increment,
113		    uint32 width, uint32 height, uint32 fg, uint32 bg)
114{
115   uint8 *lpix, *lbits;
116   int i, j;
117   uint32 expbits = 0;		 /* Bits to be expanded */
118
119   for (i=0; i<height; i++) {
120      lpix = pix;
121      lbits = bits;
122      for (j = width ; j > 0; j -= 4) {
123	 expbits = (*lbits >> 4) & 0x0f;
124
125	 if (j < 4)
126	    break;
127
128	 switch (expbits) {
129	 case 0:
130	    *lpix++ = bg;
131	    *lpix++ = bg;
132	    *lpix++ = bg;
133	    *lpix++ = bg;
134	    break;
135	 case 1:
136	    *lpix++ = bg;
137	    *lpix++ = bg;
138	    *lpix++ = bg;
139	    *lpix++ = fg;
140	    break;
141	 case 2:
142	    *lpix++ = bg;
143	    *lpix++ = bg;
144	    *lpix++ = fg;
145	    *lpix++ = bg;
146	    break;
147	 case 3:
148	    *lpix++ = bg;
149	    *lpix++ = bg;
150	    *lpix++ = fg;
151	    *lpix++ = fg;
152	    break;
153	 case 4:
154	    *lpix++ = bg;
155	    *lpix++ = fg;
156	    *lpix++ = bg;
157	    *lpix++ = bg;
158	    break;
159	 case 5:
160	    *lpix++ = bg;
161	    *lpix++ = fg;
162	    *lpix++ = bg;
163	    *lpix++ = fg;
164	    break;
165	 case 6:
166	    *lpix++ = bg;
167	    *lpix++ = fg;
168	    *lpix++ = fg;
169	    *lpix++ = bg;
170	    break;
171	 case 7:
172	    *lpix++ = bg;
173	    *lpix++ = fg;
174	    *lpix++ = fg;
175	    *lpix++ = fg;
176	    break;
177	 case 8:
178	    *lpix++ = fg;
179	    *lpix++ = bg;
180	    *lpix++ = bg;
181	    *lpix++ = bg;
182	    break;
183	 case 9:
184	    *lpix++ = fg;
185	    *lpix++ = bg;
186	    *lpix++ = bg;
187	    *lpix++ = fg;
188	    break;
189	 case 10:
190	    *lpix++ = fg;
191	    *lpix++ = bg;
192	    *lpix++ = fg;
193	    *lpix++ = bg;
194	    break;
195	 case 11:
196	    *lpix++ = fg;
197	    *lpix++ = bg;
198	    *lpix++ = fg;
199	    *lpix++ = fg;
200	    break;
201	 case 12:
202	    *lpix++ = fg;
203	    *lpix++ = fg;
204	    *lpix++ = bg;
205	    *lpix++ = bg;
206	    break;
207	 case 13:
208	    *lpix++ = fg;
209	    *lpix++ = fg;
210	    *lpix++ = bg;
211	    *lpix++ = fg;
212	    break;
213	 case 14:
214	    *lpix++ = fg;
215	    *lpix++ = fg;
216	    *lpix++ = fg;
217	    *lpix++ = bg;
218	    break;
219	 case 15:
220	    *lpix++ = fg;
221	    *lpix++ = fg;
222	    *lpix++ = fg;
223	    *lpix++ = fg;
224	    break;
225	 }
226
227	 expbits = *lbits & 0x0f;
228
229	 j -= 4;
230	 if (j < 4) {
231	    break;
232	 }
233
234	 switch (expbits) {
235	 case 0:
236	    *lpix++ = bg;
237	    *lpix++ = bg;
238	    *lpix++ = bg;
239	    *lpix++ = bg;
240	    break;
241	 case 1:
242	    *lpix++ = bg;
243	    *lpix++ = bg;
244	    *lpix++ = bg;
245	    *lpix++ = fg;
246	    break;
247	 case 2:
248	    *lpix++ = bg;
249	    *lpix++ = bg;
250	    *lpix++ = fg;
251	    *lpix++ = bg;
252	    break;
253	 case 3:
254	    *lpix++ = bg;
255	    *lpix++ = bg;
256	    *lpix++ = fg;
257	    *lpix++ = fg;
258	    break;
259	 case 4:
260	    *lpix++ = bg;
261	    *lpix++ = fg;
262	    *lpix++ = bg;
263	    *lpix++ = bg;
264	    break;
265	 case 5:
266	    *lpix++ = bg;
267	    *lpix++ = fg;
268	    *lpix++ = bg;
269	    *lpix++ = fg;
270	    break;
271	 case 6:
272	    *lpix++ = bg;
273	    *lpix++ = fg;
274	    *lpix++ = fg;
275	    *lpix++ = bg;
276	    break;
277	 case 7:
278	    *lpix++ = bg;
279	    *lpix++ = fg;
280	    *lpix++ = fg;
281	    *lpix++ = fg;
282	    break;
283	 case 8:
284	    *lpix++ = fg;
285	    *lpix++ = bg;
286	    *lpix++ = bg;
287	    *lpix++ = bg;
288	    break;
289	 case 9:
290	    *lpix++ = fg;
291	    *lpix++ = bg;
292	    *lpix++ = bg;
293	    *lpix++ = fg;
294	    break;
295	 case 10:
296	    *lpix++ = fg;
297	    *lpix++ = bg;
298	    *lpix++ = fg;
299	    *lpix++ = bg;
300	    break;
301	 case 11:
302	    *lpix++ = fg;
303	    *lpix++ = bg;
304	    *lpix++ = fg;
305	    *lpix++ = fg;
306	    break;
307	 case 12:
308	    *lpix++ = fg;
309	    *lpix++ = fg;
310	    *lpix++ = bg;
311	    *lpix++ = bg;
312	    break;
313	 case 13:
314	    *lpix++ = fg;
315	    *lpix++ = fg;
316	    *lpix++ = bg;
317	    *lpix++ = fg;
318	    break;
319	 case 14:
320	    *lpix++ = fg;
321	    *lpix++ = fg;
322	    *lpix++ = fg;
323	    *lpix++ = bg;
324	    break;
325	 case 15:
326	    *lpix++ = fg;
327	    *lpix++ = fg;
328	    *lpix++ = fg;
329	    *lpix++ = fg;
330	    break;
331	 }
332	 lbits++;
333      }
334
335      if (j > 0) {
336	 *lpix++ = (expbits & 0x08) ? fg : bg;
337	 j--;
338	 if (j > 0) {
339	    *lpix++ = (expbits & 0x04) ? fg : bg;
340	    j--;
341	    if (j > 0) {
342	       *lpix++ = (expbits & 0x02) ? fg : bg;
343	       j--;
344	    }
345	 }
346      }
347
348      pix += pix_increment;
349      bits += bits_increment;
350   }
351   return;
352}
353
354
355/*
356 *----------------------------------------------------------------------
357 *
358 * RasterBitsToPixels16 --
359 *
360 *	Convert a bitmap to a pixmap, converting 1 bits to the foreground
361 *      color (fg) and 0 bits to the background color (bg), for a 16-bit
362 *	pixmap
363 *
364 * Results:
365 *      Pixmap filled with pixels
366 *
367 * Side effects:
368 *	None
369 *
370 *----------------------------------------------------------------------
371 */
372
373void
374RasterBitsToPixels16(uint8 *bits, uint32 bits_increment,
375		     uint8 *pix, uint32 pix_increment,
376		     uint32 width, uint32 height, uint32 fg, uint32 bg)
377{
378   uint16 *lpix;
379   uint8 *lbits;
380   int i, j;
381   uint32 expbits = 0;		 /* Bits to be expanded */
382
383   for (i=0; i<height; i++) {
384      lpix = (uint16 *)pix;
385      lbits = bits;
386      for (j = width; j > 0; j -= 4) {
387	 expbits = (*lbits >> 4) & 0x0f;
388
389	 if (j < 4)
390	    break;
391
392	 switch (expbits) {
393	 case 0:
394	    *lpix++ = bg;
395	    *lpix++ = bg;
396	    *lpix++ = bg;
397	    *lpix++ = bg;
398	    break;
399	 case 1:
400	    *lpix++ = bg;
401	    *lpix++ = bg;
402	    *lpix++ = bg;
403	    *lpix++ = fg;
404	    break;
405	 case 2:
406	    *lpix++ = bg;
407	    *lpix++ = bg;
408	    *lpix++ = fg;
409	    *lpix++ = bg;
410	    break;
411	 case 3:
412	    *lpix++ = bg;
413	    *lpix++ = bg;
414	    *lpix++ = fg;
415	    *lpix++ = fg;
416	    break;
417	 case 4:
418	    *lpix++ = bg;
419	    *lpix++ = fg;
420	    *lpix++ = bg;
421	    *lpix++ = bg;
422	    break;
423	 case 5:
424	    *lpix++ = bg;
425	    *lpix++ = fg;
426	    *lpix++ = bg;
427	    *lpix++ = fg;
428	    break;
429	 case 6:
430	    *lpix++ = bg;
431	    *lpix++ = fg;
432	    *lpix++ = fg;
433	    *lpix++ = bg;
434	    break;
435	 case 7:
436	    *lpix++ = bg;
437	    *lpix++ = fg;
438	    *lpix++ = fg;
439	    *lpix++ = fg;
440	    break;
441	 case 8:
442	    *lpix++ = fg;
443	    *lpix++ = bg;
444	    *lpix++ = bg;
445	    *lpix++ = bg;
446	    break;
447	 case 9:
448	    *lpix++ = fg;
449	    *lpix++ = bg;
450	    *lpix++ = bg;
451	    *lpix++ = fg;
452	    break;
453	 case 10:
454	    *lpix++ = fg;
455	    *lpix++ = bg;
456	    *lpix++ = fg;
457	    *lpix++ = bg;
458	    break;
459	 case 11:
460	    *lpix++ = fg;
461	    *lpix++ = bg;
462	    *lpix++ = fg;
463	    *lpix++ = fg;
464	    break;
465	 case 12:
466	    *lpix++ = fg;
467	    *lpix++ = fg;
468	    *lpix++ = bg;
469	    *lpix++ = bg;
470	    break;
471	 case 13:
472	    *lpix++ = fg;
473	    *lpix++ = fg;
474	    *lpix++ = bg;
475	    *lpix++ = fg;
476	    break;
477	 case 14:
478	    *lpix++ = fg;
479	    *lpix++ = fg;
480	    *lpix++ = fg;
481	    *lpix++ = bg;
482	    break;
483	 case 15:
484	    *lpix++ = fg;
485	    *lpix++ = fg;
486	    *lpix++ = fg;
487	    *lpix++ = fg;
488	    break;
489	 }
490
491	 expbits = *lbits & 0x0f;
492
493	 j -= 4;
494	 if (j < 4) {
495	    break;
496	 }
497
498	 switch (expbits) {
499	 case 0:
500	    *lpix++ = bg;
501	    *lpix++ = bg;
502	    *lpix++ = bg;
503	    *lpix++ = bg;
504	    break;
505	 case 1:
506	    *lpix++ = bg;
507	    *lpix++ = bg;
508	    *lpix++ = bg;
509	    *lpix++ = fg;
510	    break;
511	 case 2:
512	    *lpix++ = bg;
513	    *lpix++ = bg;
514	    *lpix++ = fg;
515	    *lpix++ = bg;
516	    break;
517	 case 3:
518	    *lpix++ = bg;
519	    *lpix++ = bg;
520	    *lpix++ = fg;
521	    *lpix++ = fg;
522	    break;
523	 case 4:
524	    *lpix++ = bg;
525	    *lpix++ = fg;
526	    *lpix++ = bg;
527	    *lpix++ = bg;
528	    break;
529	 case 5:
530	    *lpix++ = bg;
531	    *lpix++ = fg;
532	    *lpix++ = bg;
533	    *lpix++ = fg;
534	    break;
535	 case 6:
536	    *lpix++ = bg;
537	    *lpix++ = fg;
538	    *lpix++ = fg;
539	    *lpix++ = bg;
540	    break;
541	 case 7:
542	    *lpix++ = bg;
543	    *lpix++ = fg;
544	    *lpix++ = fg;
545	    *lpix++ = fg;
546	    break;
547	 case 8:
548	    *lpix++ = fg;
549	    *lpix++ = bg;
550	    *lpix++ = bg;
551	    *lpix++ = bg;
552	    break;
553	 case 9:
554	    *lpix++ = fg;
555	    *lpix++ = bg;
556	    *lpix++ = bg;
557	    *lpix++ = fg;
558	    break;
559	 case 10:
560	    *lpix++ = fg;
561	    *lpix++ = bg;
562	    *lpix++ = fg;
563	    *lpix++ = bg;
564	    break;
565	 case 11:
566	    *lpix++ = fg;
567	    *lpix++ = bg;
568	    *lpix++ = fg;
569	    *lpix++ = fg;
570	    break;
571	 case 12:
572	    *lpix++ = fg;
573	    *lpix++ = fg;
574	    *lpix++ = bg;
575	    *lpix++ = bg;
576	    break;
577	 case 13:
578	    *lpix++ = fg;
579	    *lpix++ = fg;
580	    *lpix++ = bg;
581	    *lpix++ = fg;
582	    break;
583	 case 14:
584	    *lpix++ = fg;
585	    *lpix++ = fg;
586	    *lpix++ = fg;
587	    *lpix++ = bg;
588	    break;
589	 case 15:
590	    *lpix++ = fg;
591	    *lpix++ = fg;
592	    *lpix++ = fg;
593	    *lpix++ = fg;
594	    break;
595	 }
596	 lbits++;
597      }
598
599      if (j > 0) {
600	 *lpix++ = (expbits & 0x08) ? fg : bg;
601	 j--;
602	 if (j > 0) {
603	    *lpix++ = (expbits & 0x04) ? fg : bg;
604	    j--;
605	    if (j > 0) {
606	       *lpix++ = (expbits & 0x02) ? fg : bg;
607	       j--;
608	    }
609	 }
610      }
611
612      pix += pix_increment;
613      bits += bits_increment;
614   }
615   return;
616}
617
618
619
620/*
621 *----------------------------------------------------------------------
622 *
623 * RasterBitsToPixels24 --
624 *
625 *	Convert a bitmap to a pixmap, converting 1 bits to the foreground
626 *      color (fg) and 0 bits to the background color (bg), for a 24-bit
627 *	pixmap
628 *
629 * Results:
630 *      Pixmap filled with pixels
631 *
632 * Side effects:
633 *	None
634 *
635 *----------------------------------------------------------------------
636 */
637
638void
639RasterBitsToPixels24(uint8 *bits, uint32 bits_increment,
640		     uint8 *pix, uint32 pix_increment,
641		     uint32 width, uint32 height, uint32 fg, uint32 bg)
642{
643   uint8 *lpix, *lbits;
644   uint32 fgColor1, fgColor2, fgColor3;
645   uint32 bgColor1, bgColor2, bgColor3;
646
647   int i, j;
648   uint32 expbits = 0;		 /* Bits to be expanded */
649
650   fgColor1 = fg & 0x000000ff;
651   fgColor2 = (fg >> 8) & 0x000000ff;
652   fgColor3 = (fg >> 16) & 0x000000ff;
653
654   bgColor1 = bg & 0x000000ff;
655   bgColor2 = (bg >> 8) & 0x000000ff;
656   bgColor3 = (bg >> 16) & 0x000000ff;
657
658   for (i=0; i<height; i++) {
659      lpix = pix;
660      lbits = bits;
661      for (j = width; j > 0; j -= 4) {
662	 expbits = (*lbits >> 4) & 0x0f;
663
664	 if (j < 4)
665	    break;
666
667	 switch (expbits) {
668	 case 0:
669	    *lpix++ = bgColor1;
670	    *lpix++ = bgColor2;
671	    *lpix++ = bgColor3;
672	    *lpix++ = bgColor1;
673	    *lpix++ = bgColor2;
674	    *lpix++ = bgColor3;
675	    *lpix++ = bgColor1;
676	    *lpix++ = bgColor2;
677	    *lpix++ = bgColor3;
678	    *lpix++ = bgColor1;
679	    *lpix++ = bgColor2;
680	    *lpix++ = bgColor3;
681	    break;
682	 case 1:
683	    *lpix++ = bgColor1;
684	    *lpix++ = bgColor2;
685	    *lpix++ = bgColor3;
686	    *lpix++ = bgColor1;
687	    *lpix++ = bgColor2;
688	    *lpix++ = bgColor3;
689	    *lpix++ = bgColor1;
690	    *lpix++ = bgColor2;
691	    *lpix++ = bgColor3;
692	    *lpix++ = fgColor1;
693	    *lpix++ = fgColor2;
694	    *lpix++ = fgColor3;
695	    break;
696	 case 2:
697	    *lpix++ = bgColor1;
698	    *lpix++ = bgColor2;
699	    *lpix++ = bgColor3;
700	    *lpix++ = bgColor1;
701	    *lpix++ = bgColor2;
702	    *lpix++ = bgColor3;
703	    *lpix++ = fgColor1;
704	    *lpix++ = fgColor2;
705	    *lpix++ = fgColor3;
706	    *lpix++ = bgColor1;
707	    *lpix++ = bgColor2;
708	    *lpix++ = bgColor3;
709	    break;
710	 case 3:
711	    *lpix++ = bgColor1;
712	    *lpix++ = bgColor2;
713	    *lpix++ = bgColor3;
714	    *lpix++ = bgColor1;
715	    *lpix++ = bgColor2;
716	    *lpix++ = bgColor3;
717	    *lpix++ = fgColor1;
718	    *lpix++ = fgColor2;
719	    *lpix++ = fgColor3;
720	    *lpix++ = fgColor1;
721	    *lpix++ = fgColor2;
722	    *lpix++ = fgColor3;
723	    break;
724	 case 4:
725	    *lpix++ = bgColor1;
726	    *lpix++ = bgColor2;
727	    *lpix++ = bgColor3;
728	    *lpix++ = fgColor1;
729	    *lpix++ = fgColor2;
730	    *lpix++ = fgColor3;
731	    *lpix++ = bgColor1;
732	    *lpix++ = bgColor2;
733	    *lpix++ = bgColor3;
734	    *lpix++ = bgColor1;
735	    *lpix++ = bgColor2;
736	    *lpix++ = bgColor3;
737	    break;
738	 case 5:
739	    *lpix++ = bgColor1;
740	    *lpix++ = bgColor2;
741	    *lpix++ = bgColor3;
742	    *lpix++ = fgColor1;
743	    *lpix++ = fgColor2;
744	    *lpix++ = fgColor3;
745	    *lpix++ = bgColor1;
746	    *lpix++ = bgColor2;
747	    *lpix++ = bgColor3;
748	    *lpix++ = fgColor1;
749	    *lpix++ = fgColor2;
750	    *lpix++ = fgColor3;
751	    break;
752	 case 6:
753	    *lpix++ = bgColor1;
754	    *lpix++ = bgColor2;
755	    *lpix++ = bgColor3;
756	    *lpix++ = fgColor1;
757	    *lpix++ = fgColor2;
758	    *lpix++ = fgColor3;
759	    *lpix++ = fgColor1;
760	    *lpix++ = fgColor2;
761	    *lpix++ = fgColor3;
762	    *lpix++ = bgColor1;
763	    *lpix++ = bgColor2;
764	    *lpix++ = bgColor3;
765	    break;
766	 case 7:
767	    *lpix++ = bgColor1;
768	    *lpix++ = bgColor2;
769	    *lpix++ = bgColor3;
770	    *lpix++ = fgColor1;
771	    *lpix++ = fgColor2;
772	    *lpix++ = fgColor3;
773	    *lpix++ = fgColor1;
774	    *lpix++ = fgColor2;
775	    *lpix++ = fgColor3;
776	    *lpix++ = fgColor1;
777	    *lpix++ = fgColor2;
778	    *lpix++ = fgColor3;
779	    break;
780	 case 8:
781	    *lpix++ = fgColor1;
782	    *lpix++ = fgColor2;
783	    *lpix++ = fgColor3;
784	    *lpix++ = bgColor1;
785	    *lpix++ = bgColor2;
786	    *lpix++ = bgColor3;
787	    *lpix++ = bgColor1;
788	    *lpix++ = bgColor2;
789	    *lpix++ = bgColor3;
790	    *lpix++ = bgColor1;
791	    *lpix++ = bgColor2;
792	    *lpix++ = bgColor3;
793	    break;
794	 case 9:
795	    *lpix++ = fgColor1;
796	    *lpix++ = fgColor2;
797	    *lpix++ = fgColor3;
798	    *lpix++ = bgColor1;
799	    *lpix++ = bgColor2;
800	    *lpix++ = bgColor3;
801	    *lpix++ = bgColor1;
802	    *lpix++ = bgColor2;
803	    *lpix++ = bgColor3;
804	    *lpix++ = fgColor1;
805	    *lpix++ = fgColor2;
806	    *lpix++ = fgColor3;
807	    break;
808	 case 10:
809	    *lpix++ = fgColor1;
810	    *lpix++ = fgColor2;
811	    *lpix++ = fgColor3;
812	    *lpix++ = bgColor1;
813	    *lpix++ = bgColor2;
814	    *lpix++ = bgColor3;
815	    *lpix++ = fgColor1;
816	    *lpix++ = fgColor2;
817	    *lpix++ = fgColor3;
818	    *lpix++ = bgColor1;
819	    *lpix++ = bgColor2;
820	    *lpix++ = bgColor3;
821	    break;
822	 case 11:
823	    *lpix++ = fgColor1;
824	    *lpix++ = fgColor2;
825	    *lpix++ = fgColor3;
826	    *lpix++ = bgColor1;
827	    *lpix++ = bgColor2;
828	    *lpix++ = bgColor3;
829	    *lpix++ = fgColor1;
830	    *lpix++ = fgColor2;
831	    *lpix++ = fgColor3;
832	    *lpix++ = fgColor1;
833	    *lpix++ = fgColor2;
834	    *lpix++ = fgColor3;
835	    break;
836	 case 12:
837	    *lpix++ = fgColor1;
838	    *lpix++ = fgColor2;
839	    *lpix++ = fgColor3;
840	    *lpix++ = fgColor1;
841	    *lpix++ = fgColor2;
842	    *lpix++ = fgColor3;
843	    *lpix++ = bgColor1;
844	    *lpix++ = bgColor2;
845	    *lpix++ = bgColor3;
846	    *lpix++ = bgColor1;
847	    *lpix++ = bgColor2;
848	    *lpix++ = bgColor3;
849	    break;
850	 case 13:
851	    *lpix++ = fgColor1;
852	    *lpix++ = fgColor2;
853	    *lpix++ = fgColor3;
854	    *lpix++ = fgColor1;
855	    *lpix++ = fgColor2;
856	    *lpix++ = fgColor3;
857	    *lpix++ = bgColor1;
858	    *lpix++ = bgColor2;
859	    *lpix++ = bgColor3;
860	    *lpix++ = fgColor1;
861	    *lpix++ = fgColor2;
862	    *lpix++ = fgColor3;
863	    break;
864	 case 14:
865	    *lpix++ = fgColor1;
866	    *lpix++ = fgColor2;
867	    *lpix++ = fgColor3;
868	    *lpix++ = fgColor1;
869	    *lpix++ = fgColor2;
870	    *lpix++ = fgColor3;
871	    *lpix++ = fgColor1;
872	    *lpix++ = fgColor2;
873	    *lpix++ = fgColor3;
874	    *lpix++ = bgColor1;
875	    *lpix++ = bgColor2;
876	    *lpix++ = bgColor3;
877	    break;
878	 case 15:
879	    *lpix++ = fgColor1;
880	    *lpix++ = fgColor2;
881	    *lpix++ = fgColor3;
882	    *lpix++ = fgColor1;
883	    *lpix++ = fgColor2;
884	    *lpix++ = fgColor3;
885	    *lpix++ = fgColor1;
886	    *lpix++ = fgColor2;
887	    *lpix++ = fgColor3;
888	    *lpix++ = fgColor1;
889	    *lpix++ = fgColor2;
890	    *lpix++ = fgColor3;
891	    break;
892	 }
893
894	 expbits = *lbits & 0x0f;
895
896	 j -= 4;
897	 if (j < 4) {
898	    break;
899	 }
900
901	 switch (expbits) {
902	 case 0:
903	    *lpix++ = bgColor1;
904	    *lpix++ = bgColor2;
905	    *lpix++ = bgColor3;
906	    *lpix++ = bgColor1;
907	    *lpix++ = bgColor2;
908	    *lpix++ = bgColor3;
909	    *lpix++ = bgColor1;
910	    *lpix++ = bgColor2;
911	    *lpix++ = bgColor3;
912	    *lpix++ = bgColor1;
913	    *lpix++ = bgColor2;
914	    *lpix++ = bgColor3;
915	    break;
916	 case 1:
917	    *lpix++ = bgColor1;
918	    *lpix++ = bgColor2;
919	    *lpix++ = bgColor3;
920	    *lpix++ = bgColor1;
921	    *lpix++ = bgColor2;
922	    *lpix++ = bgColor3;
923	    *lpix++ = bgColor1;
924	    *lpix++ = bgColor2;
925	    *lpix++ = bgColor3;
926	    *lpix++ = fgColor1;
927	    *lpix++ = fgColor2;
928	    *lpix++ = fgColor3;
929	    break;
930	 case 2:
931	    *lpix++ = bgColor1;
932	    *lpix++ = bgColor2;
933	    *lpix++ = bgColor3;
934	    *lpix++ = bgColor1;
935	    *lpix++ = bgColor2;
936	    *lpix++ = bgColor3;
937	    *lpix++ = fgColor1;
938	    *lpix++ = fgColor2;
939	    *lpix++ = fgColor3;
940	    *lpix++ = bgColor1;
941	    *lpix++ = bgColor2;
942	    *lpix++ = bgColor3;
943	    break;
944	 case 3:
945	    *lpix++ = bgColor1;
946	    *lpix++ = bgColor2;
947	    *lpix++ = bgColor3;
948	    *lpix++ = bgColor1;
949	    *lpix++ = bgColor2;
950	    *lpix++ = bgColor3;
951	    *lpix++ = fgColor1;
952	    *lpix++ = fgColor2;
953	    *lpix++ = fgColor3;
954	    *lpix++ = fgColor1;
955	    *lpix++ = fgColor2;
956	    *lpix++ = fgColor3;
957	    break;
958	 case 4:
959	    *lpix++ = bgColor1;
960	    *lpix++ = bgColor2;
961	    *lpix++ = bgColor3;
962	    *lpix++ = fgColor1;
963	    *lpix++ = fgColor2;
964	    *lpix++ = fgColor3;
965	    *lpix++ = bgColor1;
966	    *lpix++ = bgColor2;
967	    *lpix++ = bgColor3;
968	    *lpix++ = bgColor1;
969	    *lpix++ = bgColor2;
970	    *lpix++ = bgColor3;
971	    break;
972	 case 5:
973	    *lpix++ = bgColor1;
974	    *lpix++ = bgColor2;
975	    *lpix++ = bgColor3;
976	    *lpix++ = fgColor1;
977	    *lpix++ = fgColor2;
978	    *lpix++ = fgColor3;
979	    *lpix++ = bgColor1;
980	    *lpix++ = bgColor2;
981	    *lpix++ = bgColor3;
982	    *lpix++ = fgColor1;
983	    *lpix++ = fgColor2;
984	    *lpix++ = fgColor3;
985	    break;
986	 case 6:
987	    *lpix++ = bgColor1;
988	    *lpix++ = bgColor2;
989	    *lpix++ = bgColor3;
990	    *lpix++ = fgColor1;
991	    *lpix++ = fgColor2;
992	    *lpix++ = fgColor3;
993	    *lpix++ = fgColor1;
994	    *lpix++ = fgColor2;
995	    *lpix++ = fgColor3;
996	    *lpix++ = bgColor1;
997	    *lpix++ = bgColor2;
998	    *lpix++ = bgColor3;
999	    break;
1000	 case 7:
1001	    *lpix++ = bgColor1;
1002	    *lpix++ = bgColor2;
1003	    *lpix++ = bgColor3;
1004	    *lpix++ = fgColor1;
1005	    *lpix++ = fgColor2;
1006	    *lpix++ = fgColor3;
1007	    *lpix++ = fgColor1;
1008	    *lpix++ = fgColor2;
1009	    *lpix++ = fgColor3;
1010	    *lpix++ = fgColor1;
1011	    *lpix++ = fgColor2;
1012	    *lpix++ = fgColor3;
1013	    break;
1014	 case 8:
1015	    *lpix++ = fgColor1;
1016	    *lpix++ = fgColor2;
1017	    *lpix++ = fgColor3;
1018	    *lpix++ = bgColor1;
1019	    *lpix++ = bgColor2;
1020	    *lpix++ = bgColor3;
1021	    *lpix++ = bgColor1;
1022	    *lpix++ = bgColor2;
1023	    *lpix++ = bgColor3;
1024	    *lpix++ = bgColor1;
1025	    *lpix++ = bgColor2;
1026	    *lpix++ = bgColor3;
1027	    break;
1028	 case 9:
1029	    *lpix++ = fgColor1;
1030	    *lpix++ = fgColor2;
1031	    *lpix++ = fgColor3;
1032	    *lpix++ = bgColor1;
1033	    *lpix++ = bgColor2;
1034	    *lpix++ = bgColor3;
1035	    *lpix++ = bgColor1;
1036	    *lpix++ = bgColor2;
1037	    *lpix++ = bgColor3;
1038	    *lpix++ = fgColor1;
1039	    *lpix++ = fgColor2;
1040	    *lpix++ = fgColor3;
1041	    break;
1042	 case 10:
1043	    *lpix++ = fgColor1;
1044	    *lpix++ = fgColor2;
1045	    *lpix++ = fgColor3;
1046	    *lpix++ = bgColor1;
1047	    *lpix++ = bgColor2;
1048	    *lpix++ = bgColor3;
1049	    *lpix++ = fgColor1;
1050	    *lpix++ = fgColor2;
1051	    *lpix++ = fgColor3;
1052	    *lpix++ = bgColor1;
1053	    *lpix++ = bgColor2;
1054	    *lpix++ = bgColor3;
1055	    break;
1056	 case 11:
1057	    *lpix++ = fgColor1;
1058	    *lpix++ = fgColor2;
1059	    *lpix++ = fgColor3;
1060	    *lpix++ = bgColor1;
1061	    *lpix++ = bgColor2;
1062	    *lpix++ = bgColor3;
1063	    *lpix++ = fgColor1;
1064	    *lpix++ = fgColor2;
1065	    *lpix++ = fgColor3;
1066	    *lpix++ = fgColor1;
1067	    *lpix++ = fgColor2;
1068	    *lpix++ = fgColor3;
1069	    break;
1070	 case 12:
1071	    *lpix++ = fgColor1;
1072	    *lpix++ = fgColor2;
1073	    *lpix++ = fgColor3;
1074	    *lpix++ = fgColor1;
1075	    *lpix++ = fgColor2;
1076	    *lpix++ = fgColor3;
1077	    *lpix++ = bgColor1;
1078	    *lpix++ = bgColor2;
1079	    *lpix++ = bgColor3;
1080	    *lpix++ = bgColor1;
1081	    *lpix++ = bgColor2;
1082	    *lpix++ = bgColor3;
1083	    break;
1084	 case 13:
1085	    *lpix++ = fgColor1;
1086	    *lpix++ = fgColor2;
1087	    *lpix++ = fgColor3;
1088	    *lpix++ = fgColor1;
1089	    *lpix++ = fgColor2;
1090	    *lpix++ = fgColor3;
1091	    *lpix++ = bgColor1;
1092	    *lpix++ = bgColor2;
1093	    *lpix++ = bgColor3;
1094	    *lpix++ = fgColor1;
1095	    *lpix++ = fgColor2;
1096	    *lpix++ = fgColor3;
1097	    break;
1098	 case 14:
1099	    *lpix++ = fgColor1;
1100	    *lpix++ = fgColor2;
1101	    *lpix++ = fgColor3;
1102	    *lpix++ = fgColor1;
1103	    *lpix++ = fgColor2;
1104	    *lpix++ = fgColor3;
1105	    *lpix++ = fgColor1;
1106	    *lpix++ = fgColor2;
1107	    *lpix++ = fgColor3;
1108	    *lpix++ = bgColor1;
1109	    *lpix++ = bgColor2;
1110	    *lpix++ = bgColor3;
1111	    break;
1112	 case 15:
1113	    *lpix++ = fgColor1;
1114	    *lpix++ = fgColor2;
1115	    *lpix++ = fgColor3;
1116	    *lpix++ = fgColor1;
1117	    *lpix++ = fgColor2;
1118	    *lpix++ = fgColor3;
1119	    *lpix++ = fgColor1;
1120	    *lpix++ = fgColor2;
1121	    *lpix++ = fgColor3;
1122	    *lpix++ = fgColor1;
1123	    *lpix++ = fgColor2;
1124	    *lpix++ = fgColor3;
1125	    break;
1126	 }
1127	 lbits++;
1128      }
1129
1130      if (j > 0) {
1131	 *lpix++ = (expbits & 0x08) ? fgColor1 : bgColor1;
1132	 *lpix++ = (expbits & 0x08) ? fgColor2 : bgColor2;
1133	 *lpix++ = (expbits & 0x08) ? fgColor3 : bgColor3;
1134	 j--;
1135	 if (j > 0) {
1136	    *lpix++ = (expbits & 0x04) ? fgColor1 : bgColor1;
1137	    *lpix++ = (expbits & 0x04) ? fgColor2 : bgColor2;
1138	    *lpix++ = (expbits & 0x04) ? fgColor3 : bgColor3;
1139	    j--;
1140	    if (j > 0) {
1141	       *lpix++ = (expbits & 0x02) ? fgColor1 : bgColor1;
1142	       *lpix++ = (expbits & 0x02) ? fgColor2 : bgColor2;
1143	       *lpix++ = (expbits & 0x02) ? fgColor3 : bgColor3;
1144	       j--;
1145	    }
1146	 }
1147      }
1148
1149      pix += pix_increment;
1150      bits += bits_increment;
1151   }
1152   return;
1153}
1154
1155
1156
1157/*
1158 *----------------------------------------------------------------------
1159 *
1160 * RasterBitsToPixels32 --
1161 *
1162 *	Convert a bitmap to a pixmap, converting 1 bits to the foreground
1163 *      color (fg) and 0 bits to the background color (bg), for a 32-bit
1164 *	pixmap
1165 *
1166 * Results:
1167 *      Pixmap filled with pixels
1168 *
1169 * Side effects:
1170 *	None
1171 *
1172 *----------------------------------------------------------------------
1173 */
1174
1175void
1176RasterBitsToPixels32(uint8 *bits, uint32 bits_increment,
1177		     uint8 *pix, uint32 pix_increment,
1178		     uint32 width, uint32 height, uint32 fg, uint32 bg)
1179{
1180   uint32 *lpix;
1181   uint8 *lbits;
1182   int i, j;
1183   uint32 expbits = 0;		 /* Bits to be expanded */
1184
1185   for (i=0; i<height; i++) {
1186      lpix = (uint32 *)pix;
1187      lbits = bits;
1188      for (j = width; j > 0; j -= 4) {
1189	 expbits = (*lbits >> 4) & 0x0f;
1190
1191	 if (j < 4)
1192	    break;
1193
1194	 switch (expbits) {
1195	 case 0:
1196	    *lpix++ = bg;
1197	    *lpix++ = bg;
1198	    *lpix++ = bg;
1199	    *lpix++ = bg;
1200	    break;
1201	 case 1:
1202	    *lpix++ = bg;
1203	    *lpix++ = bg;
1204	    *lpix++ = bg;
1205	    *lpix++ = fg;
1206	    break;
1207	 case 2:
1208	    *lpix++ = bg;
1209	    *lpix++ = bg;
1210	    *lpix++ = fg;
1211	    *lpix++ = bg;
1212	    break;
1213	 case 3:
1214	    *lpix++ = bg;
1215	    *lpix++ = bg;
1216	    *lpix++ = fg;
1217	    *lpix++ = fg;
1218	    break;
1219	 case 4:
1220	    *lpix++ = bg;
1221	    *lpix++ = fg;
1222	    *lpix++ = bg;
1223	    *lpix++ = bg;
1224	    break;
1225	 case 5:
1226	    *lpix++ = bg;
1227	    *lpix++ = fg;
1228	    *lpix++ = bg;
1229	    *lpix++ = fg;
1230	    break;
1231	 case 6:
1232	    *lpix++ = bg;
1233	    *lpix++ = fg;
1234	    *lpix++ = fg;
1235	    *lpix++ = bg;
1236	    break;
1237	 case 7:
1238	    *lpix++ = bg;
1239	    *lpix++ = fg;
1240	    *lpix++ = fg;
1241	    *lpix++ = fg;
1242	    break;
1243	 case 8:
1244	    *lpix++ = fg;
1245	    *lpix++ = bg;
1246	    *lpix++ = bg;
1247	    *lpix++ = bg;
1248	    break;
1249	 case 9:
1250	    *lpix++ = fg;
1251	    *lpix++ = bg;
1252	    *lpix++ = bg;
1253	    *lpix++ = fg;
1254	    break;
1255	 case 10:
1256	    *lpix++ = fg;
1257	    *lpix++ = bg;
1258	    *lpix++ = fg;
1259	    *lpix++ = bg;
1260	    break;
1261	 case 11:
1262	    *lpix++ = fg;
1263	    *lpix++ = bg;
1264	    *lpix++ = fg;
1265	    *lpix++ = fg;
1266	    break;
1267	 case 12:
1268	    *lpix++ = fg;
1269	    *lpix++ = fg;
1270	    *lpix++ = bg;
1271	    *lpix++ = bg;
1272	    break;
1273	 case 13:
1274	    *lpix++ = fg;
1275	    *lpix++ = fg;
1276	    *lpix++ = bg;
1277	    *lpix++ = fg;
1278	    break;
1279	 case 14:
1280	    *lpix++ = fg;
1281	    *lpix++ = fg;
1282	    *lpix++ = fg;
1283	    *lpix++ = bg;
1284	    break;
1285	 case 15:
1286	    *lpix++ = fg;
1287	    *lpix++ = fg;
1288	    *lpix++ = fg;
1289	    *lpix++ = fg;
1290	    break;
1291	 }
1292
1293	 expbits = *lbits & 0x0f;
1294
1295	 j -= 4;
1296	 if (j < 4) {
1297	    break;
1298	 }
1299
1300	 switch (expbits) {
1301	 case 0:
1302	    *lpix++ = bg;
1303	    *lpix++ = bg;
1304	    *lpix++ = bg;
1305	    *lpix++ = bg;
1306	    break;
1307	 case 1:
1308	    *lpix++ = bg;
1309	    *lpix++ = bg;
1310	    *lpix++ = bg;
1311	    *lpix++ = fg;
1312	    break;
1313	 case 2:
1314	    *lpix++ = bg;
1315	    *lpix++ = bg;
1316	    *lpix++ = fg;
1317	    *lpix++ = bg;
1318	    break;
1319	 case 3:
1320	    *lpix++ = bg;
1321	    *lpix++ = bg;
1322	    *lpix++ = fg;
1323	    *lpix++ = fg;
1324	    break;
1325	 case 4:
1326	    *lpix++ = bg;
1327	    *lpix++ = fg;
1328	    *lpix++ = bg;
1329	    *lpix++ = bg;
1330	    break;
1331	 case 5:
1332	    *lpix++ = bg;
1333	    *lpix++ = fg;
1334	    *lpix++ = bg;
1335	    *lpix++ = fg;
1336	    break;
1337	 case 6:
1338	    *lpix++ = bg;
1339	    *lpix++ = fg;
1340	    *lpix++ = fg;
1341	    *lpix++ = bg;
1342	    break;
1343	 case 7:
1344	    *lpix++ = bg;
1345	    *lpix++ = fg;
1346	    *lpix++ = fg;
1347	    *lpix++ = fg;
1348	    break;
1349	 case 8:
1350	    *lpix++ = fg;
1351	    *lpix++ = bg;
1352	    *lpix++ = bg;
1353	    *lpix++ = bg;
1354	    break;
1355	 case 9:
1356	    *lpix++ = fg;
1357	    *lpix++ = bg;
1358	    *lpix++ = bg;
1359	    *lpix++ = fg;
1360	    break;
1361	 case 10:
1362	    *lpix++ = fg;
1363	    *lpix++ = bg;
1364	    *lpix++ = fg;
1365	    *lpix++ = bg;
1366	    break;
1367	 case 11:
1368	    *lpix++ = fg;
1369	    *lpix++ = bg;
1370	    *lpix++ = fg;
1371	    *lpix++ = fg;
1372	    break;
1373	 case 12:
1374	    *lpix++ = fg;
1375	    *lpix++ = fg;
1376	    *lpix++ = bg;
1377	    *lpix++ = bg;
1378	    break;
1379	 case 13:
1380	    *lpix++ = fg;
1381	    *lpix++ = fg;
1382	    *lpix++ = bg;
1383	    *lpix++ = fg;
1384	    break;
1385	 case 14:
1386	    *lpix++ = fg;
1387	    *lpix++ = fg;
1388	    *lpix++ = fg;
1389	    *lpix++ = bg;
1390	    break;
1391	 case 15:
1392	    *lpix++ = fg;
1393	    *lpix++ = fg;
1394	    *lpix++ = fg;
1395	    *lpix++ = fg;
1396	    break;
1397	 }
1398	 lbits++;
1399      }
1400
1401      if (j > 0) {
1402	 *lpix++ = (expbits & 0x08) ? fg : bg;
1403	 j--;
1404	 if (j > 0) {
1405	    *lpix++ = (expbits & 0x04) ? fg : bg;
1406	    j--;
1407	    if (j > 0) {
1408	       *lpix++ = (expbits & 0x02) ? fg : bg;
1409	       j--;
1410	    }
1411	 }
1412      }
1413
1414      pix += pix_increment;
1415      bits += bits_increment;
1416   }
1417   return;
1418}
1419