Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / hidds / graphics / memblit.c
blob0bb70282d597d7fe04e98b04826604e8b9578348
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
8 #include <hidd/graphics.h>
9 #include "graphics_intern.h"
11 #define DEBUG 0
12 #include <aros/debug.h>
14 /****************************************************************************************/
16 VOID BM__Hidd_BitMap__FillMemRect8(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_FillMemRect8 *msg)
18 UBYTE *start;
19 LONG phase, width, height, w, p;
20 ULONG fill32;
21 ULONG start_add;
23 start = msg->dstBuf + msg->minY * msg->dstMod + msg->minX;
24 width = msg->maxX - msg->minX + 1;
25 height = msg->maxY - msg->minY + 1;
26 start_add = msg->dstMod - width;
28 if ((phase = (IPTR)start & 3L))
30 phase = 4 - phase;
31 if (phase > width) phase = width;
32 width -= phase;
35 fill32 = msg->fill;
36 fill32 |= (fill32 << 8);
37 fill32 |= (fill32 << 16);
39 while(height--)
41 w = width;
42 p = phase;
44 while(p--)
46 *start++ = (UBYTE)fill32;
48 while(w >= 4)
50 *((ULONG *)start) = fill32;
51 w -= 4; start += 4;
53 while(w--)
55 *start++ = (UBYTE)fill32;
57 start += start_add;
62 /****************************************************************************************/
64 VOID BM__Hidd_BitMap__FillMemRect16(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_FillMemRect16 *msg)
66 UBYTE *start;
67 LONG phase, width, height, w, p;
68 ULONG fill32;
69 ULONG start_add;
71 start = msg->dstBuf + msg->minY * msg->dstMod + msg->minX * 2;
72 width = msg->maxX - msg->minX + 1;
73 height = msg->maxY - msg->minY + 1;
74 start_add = msg->dstMod - width * 2;
76 if ((phase = (IPTR)start & 1L))
78 phase = 2 - phase;
79 if (phase > width) phase = width;
80 width -= phase;
83 fill32 = msg->fill;
84 fill32 |= (fill32 << 16);
86 while(height--)
88 w = width;
89 p = phase;
91 while(p--)
93 *((UWORD *)start) = (UWORD)fill32;
94 start += 2;
96 while(w >= 2)
98 *((ULONG *)start) = fill32;
99 w -= 2; start += 4;
101 while(w--)
103 *((UWORD *)start) = (UWORD)fill32;
104 start += 2;
106 start += start_add;
111 /****************************************************************************************/
113 VOID BM__Hidd_BitMap__FillMemRect24(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_FillMemRect24 *msg)
115 UBYTE *start;
116 LONG width, height, w;
117 UBYTE fill1, fill2, fill3;
118 ULONG start_add;
120 start = msg->dstBuf + msg->minY * msg->dstMod + msg->minX * 3;
121 width = msg->maxX - msg->minX + 1;
122 height = msg->maxY - msg->minY + 1;
123 start_add = msg->dstMod - width * 3;
125 #if AROS_BIG_ENDIAN
126 fill1 = (msg->fill >> 16) & 0xFF;
127 fill2 = (msg->fill >> 8) & 0xFF;
128 fill3 = msg->fill & 0xFF;
129 #else
130 fill1 = msg->fill & 0xFF;
131 fill2 = (msg->fill >> 8) & 0xFF;
132 fill3 = (msg->fill >> 16) & 0xFF;
133 #endif
135 while(height--)
137 w = width;
139 while(w--)
141 *start++ = fill1;
142 *start++ = fill2;
143 *start++ = fill3;
146 start += start_add;
150 /****************************************************************************************/
152 VOID BM__Hidd_BitMap__FillMemRect32(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_FillMemRect32 *msg)
154 UBYTE *start;
155 LONG width, height, w;
156 ULONG fill32;
157 ULONG start_add;
159 start = msg->dstBuf + msg->minY * msg->dstMod + msg->minX * 4;
160 width = msg->maxX - msg->minX + 1;
161 height = msg->maxY - msg->minY + 1;
162 start_add = msg->dstMod - width * 4;
164 fill32 = msg->fill;
166 while(height--)
168 w = width;
170 while(w--)
172 *((ULONG *)start) = fill32;
173 start += 4;
176 start += start_add;
180 /****************************************************************************************/
182 VOID BM__Hidd_BitMap__InvertMemRect(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_InvertMemRect *msg)
184 UBYTE *start;
185 LONG phase, width, height, w, p;
186 ULONG start_add;
188 start = msg->dstBuf + msg->minY * msg->dstMod + msg->minX;
189 width = msg->maxX - msg->minX + 1;
190 height = msg->maxY - msg->minY + 1;
191 start_add = msg->dstMod - width;
193 if ((phase = (IPTR)start & 3L))
195 phase = 4 - phase;
196 if (phase > width) phase = width;
197 width -= phase;
200 while(height--)
202 UBYTE bg;
203 ULONG bg32;
205 w = width;
206 p = phase;
208 while(p--)
210 bg = *start;
211 *start++ = ~bg;
213 while(w >= 4)
215 bg32 = *(ULONG *)start;
216 *((ULONG *)start) = ~bg32;
217 w -= 4; start += 4;
219 while(w--)
221 bg = *start;
222 *start++ = ~bg;
224 start += start_add;
229 /****************************************************************************************/
231 VOID BM__Hidd_BitMap__CopyMemBox8(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_CopyMemBox8 *msg)
233 UBYTE *src_start, *dst_start;
234 LONG phase, width, height, w, p;
235 ULONG src_start_add, dst_start_add;
236 BOOL descending;
238 width = msg->width;
239 height = msg->height;
241 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX;
242 src_start_add = msg->srcMod - width;
244 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX;
245 dst_start_add = msg->dstMod - width;
247 if ((IPTR)src_start > (IPTR)dst_start)
249 if ((phase = (IPTR)src_start & 3L))
251 phase = 4 - phase;
252 if (phase > width) phase = width;
253 width -= phase;
255 descending = FALSE;
257 else
259 src_start += (height - 1) * msg->srcMod + width;
260 dst_start += (height - 1) * msg->dstMod + width;
262 phase = ((IPTR)src_start & 3L);
263 if (phase > width) phase = width;
264 width -= phase;
266 descending = TRUE;
269 /* NOTE: This can write LONGs to odd addresses, which might not work
270 on some CPUs (MC68000) */
272 if (!descending)
274 while(height--)
276 w = width;
277 p = phase;
279 while(p--)
281 *dst_start++ = *src_start++;
283 while(w >= 4)
285 *((ULONG *)dst_start) = *((ULONG *)src_start);
286 w -= 4; dst_start += 4; src_start += 4;
288 while(w--)
290 *dst_start++ = *src_start++;
292 src_start += src_start_add;
293 dst_start += dst_start_add;
296 else
298 while(height--)
300 w = width;
301 p = phase;
303 while(p--)
305 *--dst_start = *--src_start;
307 while(w >= 4)
309 dst_start -= 4; src_start -= 4;
310 *(ULONG *)dst_start = *(ULONG *)src_start;
311 w -= 4;
313 while(w--)
315 *--dst_start = *--src_start;
317 src_start -= src_start_add;
318 dst_start -= dst_start_add;
324 /****************************************************************************************/
326 VOID BM__Hidd_BitMap__CopyMemBox16(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_CopyMemBox16 *msg)
328 UBYTE *src_start, *dst_start;
329 LONG phase, width, height, w, p;
330 ULONG src_start_add, dst_start_add;
331 BOOL descending;
333 width = msg->width;
334 height = msg->height;
336 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX * 2;
337 src_start_add = msg->srcMod - width * 2;
339 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX * 2;
340 dst_start_add = msg->dstMod - width * 2;
342 if ((IPTR)src_start > (IPTR)dst_start)
344 if ((phase = (IPTR)src_start & 1L))
346 phase = 2 - phase;
347 if (phase > width) phase = width;
348 width -= phase;
350 descending = FALSE;
352 else
354 src_start += (height - 1) * msg->srcMod + width * 2;
355 dst_start += (height - 1) * msg->dstMod + width * 2;
357 phase = ((IPTR)src_start & 1L);
358 if (phase > width) phase = width;
359 width -= phase;
361 descending = TRUE;
364 if (!descending)
366 while(height--)
368 w = width;
369 p = phase;
371 while(p--)
373 *((UWORD *)dst_start) = *((UWORD *)src_start);
374 dst_start += 2; src_start += 2;
376 while(w >= 2)
378 *((ULONG *)dst_start) = *((ULONG *)src_start);
379 w -= 2; dst_start += 4; src_start += 4;
381 while(w--)
383 *((UWORD *)dst_start) = *((UWORD *)src_start);
384 dst_start += 2; src_start += 2;
386 src_start += src_start_add;
387 dst_start += dst_start_add;
390 else
392 while(height--)
394 w = width;
395 p = phase;
397 while(p--)
399 dst_start -= 2; src_start -= 2;
400 *(UWORD *)dst_start = *(UWORD *)src_start;
402 while(w >= 2)
404 dst_start -= 4; src_start -= 4;
405 *(ULONG *)dst_start = *(ULONG *)src_start;
406 w -= 2;
408 while(w--)
410 dst_start -= 2; src_start -= 2;
411 *(UWORD *)dst_start = *(UWORD *)src_start;
413 src_start -= src_start_add;
414 dst_start -= dst_start_add;
420 /****************************************************************************************/
422 VOID BM__Hidd_BitMap__CopyMemBox24(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_CopyMemBox24 *msg)
424 UBYTE *src_start, *dst_start;
425 LONG width, height, w;
426 ULONG src_start_add, dst_start_add;
427 BOOL descending;
429 width = msg->width;
430 height = msg->height;
432 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX * 3;
433 src_start_add = msg->srcMod - width * 3;
435 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX * 3;
436 dst_start_add = msg->dstMod - width * 3;
438 if ((IPTR)src_start > (IPTR)dst_start)
440 descending = FALSE;
442 else
444 src_start += (height - 1) * msg->srcMod + width * 3;
445 dst_start += (height - 1) * msg->dstMod + width * 3;
447 descending = TRUE;
450 if (!descending)
452 while(height--)
454 w = width;
456 while(w--)
458 *dst_start++ = *src_start++;
459 *dst_start++ = *src_start++;
460 *dst_start++ = *src_start++;
463 src_start += src_start_add;
464 dst_start += dst_start_add;
467 else
469 while(height--)
471 w = width;
473 while(w--)
475 *--dst_start = *--src_start;
476 *--dst_start = *--src_start;
477 *--dst_start = *--src_start;
480 src_start -= src_start_add;
481 dst_start -= dst_start_add;
487 /****************************************************************************************/
489 VOID BM__Hidd_BitMap__CopyMemBox32(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_CopyMemBox32 *msg)
491 UBYTE *src_start, *dst_start;
492 LONG width, height, w;
493 ULONG src_start_add, dst_start_add;
494 BOOL descending;
496 width = msg->width;
497 height = msg->height;
499 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX * 4;
500 src_start_add = msg->srcMod - width * 4;
502 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX * 4;
503 dst_start_add = msg->dstMod - width * 4;
505 if ((IPTR)src_start > (IPTR)dst_start)
507 descending = FALSE;
509 else
511 src_start += (height - 1) * msg->srcMod + width * 4;
512 dst_start += (height - 1) * msg->dstMod + width * 4;
514 descending = TRUE;
517 if (!descending)
519 while(height--)
521 w = width;
523 while(w--)
525 *((ULONG *)dst_start) = *((ULONG *)src_start);
526 dst_start += 4; src_start += 4;
529 src_start += src_start_add;
530 dst_start += dst_start_add;
533 else
535 while(height--)
537 w = width;
539 while(w--)
541 dst_start -= 4; src_start -= 4;
542 *(ULONG *)dst_start = *(ULONG *)src_start;
545 src_start -= src_start_add;
546 dst_start -= dst_start_add;
552 /****************************************************************************************/
554 VOID BM__Hidd_BitMap__CopyLUTMemBox16(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_CopyLUTMemBox16 *msg)
556 HIDDT_Pixel *pixlut = msg->pixlut->pixels;
557 UBYTE *src_start, *dst_start;
558 LONG width, height, w;
559 ULONG src_start_add, dst_start_add;
561 if (!pixlut) return;
563 width = msg->width;
564 height = msg->height;
566 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX;
567 src_start_add = msg->srcMod - width;
569 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX * 2;
570 dst_start_add = msg->dstMod - width * 2;
572 while(height--)
574 w = width;
576 while(w--)
578 *(UWORD *)dst_start = (UWORD)(pixlut[*src_start++]);
579 dst_start += 2;
581 src_start += src_start_add;
582 dst_start += dst_start_add;
586 /****************************************************************************************/
588 VOID BM__Hidd_BitMap__CopyLUTMemBox24(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_CopyLUTMemBox24 *msg)
590 HIDDT_Pixel *pixlut = msg->pixlut->pixels;
591 UBYTE *src_start, *dst_start;
592 LONG width, height, w;
593 ULONG src_start_add, dst_start_add;
595 if (!pixlut) return;
597 width = msg->width;
598 height = msg->height;
600 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX;
601 src_start_add = msg->srcMod - width;
603 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX * 3;
604 dst_start_add = msg->dstMod - width * 3;
606 while(height--)
608 w = width;
610 while(w--)
612 HIDDT_Pixel pix = pixlut[*src_start++];
614 #if AROS_BIG_ENDIAN
615 *dst_start++ = (pix >> 16) & 0xFF;
616 *dst_start++ = (pix >> 8) & 0xFF;
617 *dst_start++ = pix & 0xFF;
618 #else
619 *dst_start++ = pix & 0xFF;
620 *dst_start++ = (pix >> 8) & 0xFF;
621 *dst_start++ = (pix >> 16) & 0xFF;
622 #endif
624 src_start += src_start_add;
625 dst_start += dst_start_add;
629 /****************************************************************************************/
631 VOID BM__Hidd_BitMap__CopyLUTMemBox32(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_CopyLUTMemBox32 *msg)
633 HIDDT_Pixel *pixlut = msg->pixlut->pixels;
634 UBYTE *src_start, *dst_start;
635 LONG width, height, w;
636 ULONG src_start_add, dst_start_add;
638 if (!pixlut) return;
640 width = msg->width;
641 height = msg->height;
643 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX;
644 src_start_add = msg->srcMod - width;
646 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX * 4;
647 dst_start_add = msg->dstMod - width * 4;
649 while(height--)
651 w = width;
653 while(w--)
655 *((ULONG *)dst_start) = (ULONG)(pixlut[*src_start++]);
656 dst_start += 4;
658 src_start += src_start_add;
659 dst_start += dst_start_add;
663 /****************************************************************************************/
665 VOID BM__Hidd_BitMap__PutMem32Image8(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMem32Image8 *msg)
667 UBYTE *src_start, *dst_start;
668 LONG width, height, w;
669 ULONG src_start_add, dst_start_add;
671 width = msg->width;
672 height = msg->height;
674 src_start = msg->src;
675 src_start_add = msg->srcMod - width * 4;
677 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX;
678 dst_start_add = msg->dstMod - width;
680 while(height--)
682 w = width;
684 while(w--)
686 *dst_start++ = (UBYTE)(*(ULONG *)src_start);
687 src_start += 4;
689 src_start += src_start_add;
690 dst_start += dst_start_add;
694 /****************************************************************************************/
696 VOID BM__Hidd_BitMap__PutMem32Image16(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMem32Image16 *msg)
698 UBYTE *src_start, *dst_start;
699 LONG width, height, w;
700 ULONG src_start_add, dst_start_add;
702 width = msg->width;
703 height = msg->height;
705 src_start = msg->src;
706 src_start_add = msg->srcMod - width * 4;
708 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX * 2;
709 dst_start_add = msg->dstMod - width * 2;
711 while(height--)
713 w = width;
715 while(w--)
717 *(UWORD *)dst_start = (UWORD)(*(ULONG *)src_start);
718 dst_start += 2; src_start += 4;
720 src_start += src_start_add;
721 dst_start += dst_start_add;
725 /****************************************************************************************/
727 VOID BM__Hidd_BitMap__PutMem32Image24(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMem32Image24 *msg)
729 UBYTE *src_start, *dst_start;
730 LONG width, height, w;
731 ULONG src_start_add, dst_start_add;
733 width = msg->width;
734 height = msg->height;
736 src_start = msg->src;
737 src_start_add = msg->srcMod - width * 4;
739 dst_start = msg->dst + msg->dstY * msg->dstMod + msg->dstX * 3;
740 dst_start_add = msg->dstMod - width * 3;
742 while(height--)
744 w = width;
746 while(w--)
748 ULONG pix = *(ULONG *)src_start;
750 src_start += 4;
752 #if AROS_BIG_ENDIAN
753 *dst_start++ = (pix >> 16) & 0xFF;
754 *dst_start++ = (pix >> 8) & 0xFF;
755 *dst_start++ = pix & 0xFF;
756 #else
757 *dst_start++ = pix & 0xFF;
758 *dst_start++ = (pix >> 8) & 0xFF;
759 *dst_start++ = (pix >> 16) & 0xFF;
760 #endif
763 src_start += src_start_add;
764 dst_start += dst_start_add;
768 /****************************************************************************************/
770 VOID BM__Hidd_BitMap__GetMem32Image8(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetMem32Image8 *msg)
772 UBYTE *src_start, *dst_start;
773 LONG width, height, w;
774 ULONG src_start_add, dst_start_add;
776 width = msg->width;
777 height = msg->height;
779 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX;
780 src_start_add = msg->srcMod - width;
782 dst_start = msg->dst;
783 dst_start_add = msg->dstMod - width * 4;
785 while(height--)
787 w = width;
789 while(w--)
791 *(ULONG *)dst_start = (ULONG)(*src_start++);
792 dst_start += 4;
794 src_start += src_start_add;
795 dst_start += dst_start_add;
799 /****************************************************************************************/
801 VOID BM__Hidd_BitMap__GetMem32Image16(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetMem32Image16 *msg)
803 UBYTE *src_start, *dst_start;
804 LONG width, height, w;
805 ULONG src_start_add, dst_start_add;
807 width = msg->width;
808 height = msg->height;
810 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX * 2;
811 src_start_add = msg->srcMod - width * 2;
813 dst_start = msg->dst;
814 dst_start_add = msg->dstMod - width * 4;
816 while(height--)
818 w = width;
820 while(w--)
822 *(ULONG *)dst_start = (ULONG)(*(UWORD *)src_start);
823 dst_start += 4; src_start += 2;
825 src_start += src_start_add;
826 dst_start += dst_start_add;
830 /****************************************************************************************/
832 VOID BM__Hidd_BitMap__GetMem32Image24(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetMem32Image24 *msg)
834 UBYTE *src_start, *dst_start;
835 LONG width, height, w;
836 ULONG src_start_add, dst_start_add;
838 width = msg->width;
839 height = msg->height;
841 src_start = msg->src + msg->srcY * msg->srcMod + msg->srcX * 3;
842 src_start_add = msg->srcMod - width * 3;
844 dst_start = msg->dst;
845 dst_start_add = msg->dstMod - width * 4;
847 while(height--)
849 w = width;
851 while(w--)
853 UBYTE pix1 = *src_start++;
854 UBYTE pix2 = *src_start++;
855 UBYTE pix3 = *src_start++;
857 #if AROS_BIG_ENDIAN
858 *(ULONG *)dst_start = (pix1 << 16) | (pix2 << 8) | pix3;
859 #else
860 *(ULONG *)dst_start = (pix3 << 16) | (pix2 << 8) | pix1;
861 #endif
863 dst_start += 4;
865 src_start += src_start_add;
866 dst_start += dst_start_add;
870 /****************************************************************************************/
872 VOID BM__Hidd_BitMap__PutMemTemplate8(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMemTemplate8 *msg)
874 WORD x, y;
875 UBYTE *bitarray, *buf;
876 UWORD bitmask;
877 OOP_Object *gc = msg->gc;
878 ULONG fg = GC_FG(gc);
879 ULONG bg = GC_BG(gc);
880 WORD type = 0;
882 if (msg->width <= 0 || msg->height <= 0)
883 return;
885 if (GC_COLEXP(gc) == vHidd_GC_ColExp_Transparent)
887 type = 0;
889 else if (GC_DRMD(gc) == vHidd_GC_DrawMode_Invert)
891 type = 2;
893 else
895 type = 4;
898 if (msg->inverttemplate) type++;
900 bitarray = msg->template + ((msg->srcx / 16) * 2);
901 bitmask = 0x8000 >> (msg->srcx & 0xF);
903 buf = msg->dst + msg->y * msg->dstMod + msg->x;
905 for(y = 0; y < msg->height; y++)
907 ULONG mask = bitmask;
908 UWORD *array = (UWORD *)bitarray;
909 UWORD bitword = AROS_BE2WORD(*array);
910 UBYTE *xbuf = buf;
912 switch(type)
914 case 0: /* JAM1 */
915 for(x = 0; x < msg->width; x++, xbuf++)
917 if (bitword & mask) *xbuf = fg;
919 mask >>= 1;
920 if (!mask)
922 mask = 0x8000;
923 array++;
924 bitword = AROS_BE2WORD(*array);
927 } /* for(x = 0; x < msg->width; x++) */
928 break;
930 case 1: /* JAM1 | INVERSVID */
931 for(x = 0; x < msg->width; x++, xbuf++)
933 if (!(bitword & mask)) *xbuf = fg;
935 mask >>= 1;
936 if (!mask)
938 mask = 0x8000;
939 array++;
940 bitword = AROS_BE2WORD(*array);
943 } /* for(x = 0; x < msg->width; x++) */
944 break;
946 case 2: /* COMPLEMENT */
947 for(x = 0; x < msg->width; x++, xbuf++)
949 if (bitword & mask) *xbuf = ~(*xbuf);
951 mask >>= 1;
952 if (!mask)
954 mask = 0x8000;
955 array++;
956 bitword = AROS_BE2WORD(*array);
958 } /* for(x = 0; x < msg->width; x++) */
959 break;
961 case 3: /* COMPLEMENT | INVERSVID*/
962 for(x = 0; x < msg->width; x++, xbuf++)
964 if (!(bitword & mask)) *xbuf = ~(*xbuf);
966 mask >>= 1;
967 if (!mask)
969 mask = 0x8000;
970 array++;
971 bitword = AROS_BE2WORD(*array);
973 } /* for(x = 0; x < msg->width; x++) */
974 break;
976 case 4: /* JAM2 */
977 for(x = 0; x < msg->width; x++)
979 *xbuf++ = (bitword & mask) ? fg : bg;
981 mask >>= 1;
982 if (!mask)
984 mask = 0x8000;
985 array++;
986 bitword = AROS_BE2WORD(*array);
989 } /* for(x = 0; x < msg->width; x++) */
990 break;
992 case 5: /* JAM2 | INVERSVID */
993 for(x = 0; x < msg->width; x++)
995 *xbuf++ = (bitword & mask) ? bg : fg;
997 mask >>= 1;
998 if (!mask)
1000 mask = 0x8000;
1001 array++;
1002 bitword = AROS_BE2WORD(*array);
1004 } /* for(x = 0; x < msg->width; x++) */
1005 break;
1007 } /* switch(type) */
1009 buf += msg->dstMod;
1010 bitarray += msg->modulo;
1012 } /* for(y = 0; y < msg->height; y++) */
1015 /****************************************************************************************/
1017 VOID BM__Hidd_BitMap__PutMemTemplate16(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMemTemplate16 *msg)
1019 WORD x, y;
1020 UBYTE *bitarray, *buf;
1021 UWORD bitmask;
1022 OOP_Object *gc = msg->gc;
1023 ULONG fg = GC_FG(gc);
1024 ULONG bg = GC_BG(gc);
1025 WORD type = 0;
1027 if (msg->width <= 0 || msg->height <= 0)
1028 return;
1030 if (GC_COLEXP(gc) == vHidd_GC_ColExp_Transparent)
1032 type = 0;
1034 else if (GC_DRMD(gc) == vHidd_GC_DrawMode_Invert)
1036 type = 2;
1038 else
1040 type = 4;
1043 if (msg->inverttemplate) type++;
1045 bitarray = msg->template + ((msg->srcx / 16) * 2);
1046 bitmask = 0x8000 >> (msg->srcx & 0xF);
1048 buf = msg->dst + msg->y * msg->dstMod + msg->x * 2;
1050 for(y = 0; y < msg->height; y++)
1052 ULONG mask = bitmask;
1053 UWORD *array = (UWORD *)bitarray;
1054 UWORD bitword = AROS_BE2WORD(*array);
1055 UWORD *xbuf = (UWORD *)buf;
1057 switch(type)
1059 case 0: /* JAM1 */
1060 for(x = 0; x < msg->width; x++, xbuf++)
1062 if (bitword & mask) *xbuf = fg;
1064 mask >>= 1;
1065 if (!mask)
1067 mask = 0x8000;
1068 array++;
1069 bitword = AROS_BE2WORD(*array);
1072 } /* for(x = 0; x < msg->width; x++) */
1073 break;
1075 case 1: /* JAM1 | INVERSVID */
1076 for(x = 0; x < msg->width; x++, xbuf++)
1078 if (!(bitword & mask)) *xbuf = fg;
1080 mask >>= 1;
1081 if (!mask)
1083 mask = 0x8000;
1084 array++;
1085 bitword = AROS_BE2WORD(*array);
1088 } /* for(x = 0; x < msg->width; x++) */
1089 break;
1091 case 2: /* COMPLEMENT */
1092 for(x = 0; x < msg->width; x++, xbuf++)
1094 if (bitword & mask) *xbuf = ~(*xbuf);
1096 mask >>= 1;
1097 if (!mask)
1099 mask = 0x8000;
1100 array++;
1101 bitword = AROS_BE2WORD(*array);
1103 } /* for(x = 0; x < msg->width; x++) */
1104 break;
1106 case 3: /* COMPLEMENT | INVERSVID*/
1107 for(x = 0; x < msg->width; x++, xbuf++)
1109 if (!(bitword & mask)) *xbuf = ~(*xbuf);
1111 mask >>= 1;
1112 if (!mask)
1114 mask = 0x8000;
1115 array++;
1116 bitword = AROS_BE2WORD(*array);
1118 } /* for(x = 0; x < msg->width; x++) */
1119 break;
1121 case 4: /* JAM2 */
1122 for(x = 0; x < msg->width; x++)
1124 *xbuf++ = (bitword & mask) ? fg : bg;
1126 mask >>= 1;
1127 if (!mask)
1129 mask = 0x8000;
1130 array++;
1131 bitword = AROS_BE2WORD(*array);
1134 } /* for(x = 0; x < msg->width; x++) */
1135 break;
1137 case 5: /* JAM2 | INVERSVID */
1138 for(x = 0; x < msg->width; x++)
1140 *xbuf++ = (bitword & mask) ? bg : fg;
1142 mask >>= 1;
1143 if (!mask)
1145 mask = 0x8000;
1146 array++;
1147 bitword = AROS_BE2WORD(*array);
1149 } /* for(x = 0; x < msg->width; x++) */
1150 break;
1152 } /* switch(type) */
1154 buf += msg->dstMod;
1155 bitarray += msg->modulo;
1157 } /* for(y = 0; y < msg->height; y++) */
1161 /****************************************************************************************/
1163 VOID BM__Hidd_BitMap__PutMemTemplate24(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMemTemplate24 *msg)
1165 WORD x, y;
1166 UBYTE *bitarray, *buf;
1167 UWORD bitmask;
1168 OOP_Object *gc = msg->gc;
1169 ULONG fg = GC_FG(gc);
1170 UBYTE fg1, fg2, fg3;
1171 ULONG bg = GC_BG(gc);
1172 UBYTE bg1, bg2, bg3;
1173 WORD type = 0;
1175 if (msg->width <= 0 || msg->height <= 0)
1176 return;
1178 #if AROS_BIG_ENDIAN
1179 fg1 = (fg >> 16) & 0xFF;
1180 fg2 = (fg >> 8) & 0xFF;
1181 fg3 = fg & 0xFF;
1183 bg1 = (bg >> 16) & 0xFF;
1184 bg2 = (bg >> 8) & 0xFF;
1185 bg3 = bg & 0xFF;
1186 #else
1187 fg1 = fg & 0xFF;
1188 fg2 = (fg >> 8) & 0xFF;
1189 fg3 = (fg >> 16) & 0xFF;
1191 bg1 = bg & 0xFF;
1192 bg2 = (bg >> 8) & 0xFF;
1193 bg3 = (bg >> 16) & 0xFF;
1194 #endif
1196 if (GC_COLEXP(gc) == vHidd_GC_ColExp_Transparent)
1198 type = 0;
1200 else if (GC_DRMD(gc) == vHidd_GC_DrawMode_Invert)
1202 type = 2;
1204 else
1206 type = 4;
1209 if (msg->inverttemplate) type++;
1211 bitarray = msg->template + ((msg->srcx / 16) * 2);
1212 bitmask = 0x8000 >> (msg->srcx & 0xF);
1214 buf = msg->dst + msg->y * msg->dstMod + msg->x * 3;
1216 for(y = 0; y < msg->height; y++)
1218 ULONG mask = bitmask;
1219 UWORD *array = (UWORD *)bitarray;
1220 UWORD bitword = AROS_BE2WORD(*array);
1221 UBYTE *xbuf = buf;
1223 switch(type)
1225 case 0: /* JAM1 */
1226 for(x = 0; x < msg->width; x++, xbuf += 3)
1228 if (bitword & mask)
1230 xbuf[0] = fg1;
1231 xbuf[1] = fg2;
1232 xbuf[2] = fg3;
1235 mask >>= 1;
1236 if (!mask)
1238 mask = 0x8000;
1239 array++;
1240 bitword = AROS_BE2WORD(*array);
1243 } /* for(x = 0; x < msg->width; x++) */
1244 break;
1246 case 1: /* JAM1 | INVERSVID */
1247 for(x = 0; x < msg->width; x++, xbuf += 3)
1249 if (!(bitword & mask))
1251 xbuf[0] = fg1;
1252 xbuf[1] = fg2;
1253 xbuf[2] = fg3;
1256 mask >>= 1;
1257 if (!mask)
1259 mask = 0x8000;
1260 array++;
1261 bitword = AROS_BE2WORD(*array);
1264 } /* for(x = 0; x < msg->width; x++) */
1265 break;
1267 case 2: /* COMPLEMENT */
1268 for(x = 0; x < msg->width; x++, xbuf += 3)
1270 if (bitword & mask)
1272 xbuf[0] = ~xbuf[0];
1273 xbuf[1] = ~xbuf[1];
1274 xbuf[2] = ~xbuf[2];
1277 mask >>= 1;
1278 if (!mask)
1280 mask = 0x8000;
1281 array++;
1282 bitword = AROS_BE2WORD(*array);
1284 } /* for(x = 0; x < msg->width; x++) */
1285 break;
1287 case 3: /* COMPLEMENT | INVERSVID*/
1288 for(x = 0; x < msg->width; x++, xbuf += 3)
1290 if (!(bitword & mask))
1292 xbuf[0] = ~xbuf[0];
1293 xbuf[1] = ~xbuf[1];
1294 xbuf[2] = ~xbuf[2];
1297 mask >>= 1;
1298 if (!mask)
1300 mask = 0x8000;
1301 array++;
1302 bitword = AROS_BE2WORD(*array);
1304 } /* for(x = 0; x < msg->width; x++) */
1305 break;
1307 case 4: /* JAM2 */
1308 for(x = 0; x < msg->width; x++)
1310 if (bitword & mask)
1312 *xbuf++ = fg1;
1313 *xbuf++ = fg2;
1314 *xbuf++ = fg3;
1316 else
1318 *xbuf++ = bg1;
1319 *xbuf++ = bg2;
1320 *xbuf++ = bg3;
1323 mask >>= 1;
1324 if (!mask)
1326 mask = 0x8000;
1327 array++;
1328 bitword = AROS_BE2WORD(*array);
1331 } /* for(x = 0; x < msg->width; x++) */
1332 break;
1334 case 5: /* JAM2 | INVERSVID */
1335 for(x = 0; x < msg->width; x++)
1337 if (bitword & mask)
1339 *xbuf++ = bg1;
1340 *xbuf++ = bg2;
1341 *xbuf++ = bg3;
1343 else
1345 *xbuf++ = fg1;
1346 *xbuf++ = fg2;
1347 *xbuf++ = fg3;
1350 mask >>= 1;
1351 if (!mask)
1353 mask = 0x8000;
1354 array++;
1355 bitword = AROS_BE2WORD(*array);
1357 } /* for(x = 0; x < msg->width; x++) */
1358 break;
1360 } /* switch(type) */
1362 buf += msg->dstMod;
1363 bitarray += msg->modulo;
1365 } /* for(y = 0; y < msg->height; y++) */
1369 /****************************************************************************************/
1371 VOID BM__Hidd_BitMap__PutMemTemplate32(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMemTemplate32 *msg)
1373 WORD x, y;
1374 UBYTE *bitarray, *buf;
1375 UWORD bitmask;
1376 OOP_Object *gc = msg->gc;
1377 ULONG fg = GC_FG(gc);
1378 ULONG bg = GC_BG(gc);
1379 WORD type = 0;
1381 if (msg->width <= 0 || msg->height <= 0)
1382 return;
1384 if (GC_COLEXP(gc) == vHidd_GC_ColExp_Transparent)
1386 type = 0;
1388 else if (GC_DRMD(gc) == vHidd_GC_DrawMode_Invert)
1390 type = 2;
1392 else
1394 type = 4;
1397 if (msg->inverttemplate) type++;
1399 bitarray = msg->template + ((msg->srcx / 16) * 2);
1400 bitmask = 0x8000 >> (msg->srcx & 0xF);
1402 buf = msg->dst + msg->y * msg->dstMod + msg->x * 4;
1404 for(y = 0; y < msg->height; y++)
1406 ULONG mask = bitmask;
1407 UWORD *array = (UWORD *)bitarray;
1408 UWORD bitword = AROS_BE2WORD(*array);
1409 ULONG *xbuf = (ULONG *)buf;
1411 switch(type)
1413 case 0: /* JAM1 */
1414 for(x = 0; x < msg->width; x++, xbuf++)
1416 if (bitword & mask) *xbuf = fg;
1418 mask >>= 1;
1419 if (!mask)
1421 mask = 0x8000;
1422 array++;
1423 bitword = AROS_BE2WORD(*array);
1426 } /* for(x = 0; x < msg->width; x++) */
1427 break;
1429 case 1: /* JAM1 | INVERSVID */
1430 for(x = 0; x < msg->width; x++, xbuf++)
1432 if (!(bitword & mask)) *xbuf = fg;
1434 mask >>= 1;
1435 if (!mask)
1437 mask = 0x8000;
1438 array++;
1439 bitword = AROS_BE2WORD(*array);
1442 } /* for(x = 0; x < msg->width; x++) */
1443 break;
1445 case 2: /* COMPLEMENT */
1446 for(x = 0; x < msg->width; x++, xbuf++)
1448 if (bitword & mask) *xbuf = ~(*xbuf);
1450 mask >>= 1;
1451 if (!mask)
1453 mask = 0x8000;
1454 array++;
1455 bitword = AROS_BE2WORD(*array);
1457 } /* for(x = 0; x < msg->width; x++) */
1458 break;
1460 case 3: /* COMPLEMENT | INVERSVID*/
1461 for(x = 0; x < msg->width; x++, xbuf++)
1463 if (!(bitword & mask)) *xbuf = ~(*xbuf);
1465 mask >>= 1;
1466 if (!mask)
1468 mask = 0x8000;
1469 array++;
1470 bitword = AROS_BE2WORD(*array);
1472 } /* for(x = 0; x < msg->width; x++) */
1473 break;
1475 case 4: /* JAM2 */
1476 for(x = 0; x < msg->width; x++)
1478 *xbuf++ = (bitword & mask) ? fg : bg;
1480 mask >>= 1;
1481 if (!mask)
1483 mask = 0x8000;
1484 array++;
1485 bitword = AROS_BE2WORD(*array);
1488 } /* for(x = 0; x < msg->width; x++) */
1489 break;
1491 case 5: /* JAM2 | INVERSVID */
1492 for(x = 0; x < msg->width; x++)
1494 *xbuf++ = (bitword & mask) ? bg : fg;
1496 mask >>= 1;
1497 if (!mask)
1499 mask = 0x8000;
1500 array++;
1501 bitword = AROS_BE2WORD(*array);
1503 } /* for(x = 0; x < msg->width; x++) */
1504 break;
1506 } /* switch(type) */
1508 buf += msg->dstMod;
1509 bitarray += msg->modulo;
1511 } /* for(y = 0; y < msg->height; y++) */
1515 /****************************************************************************************/
1517 VOID BM__Hidd_BitMap__PutMemPattern8(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMemPattern8 *msg)
1519 WORD x, y;
1520 UBYTE *patarray, *buf, *maskarray = 0;
1521 UWORD patmask, maskmask;
1522 OOP_Object *gc = msg->gc;
1523 ULONG fg = GC_FG(gc);
1524 ULONG bg = GC_BG(gc);
1525 WORD type = 0;
1527 if (msg->width <= 0 || msg->height <= 0)
1528 return;
1530 if (msg->patterndepth > 1)
1532 type = 6;
1534 else
1536 if (GC_COLEXP(gc) == vHidd_GC_ColExp_Transparent)
1538 type = 0;
1540 else if (GC_DRMD(gc) == vHidd_GC_DrawMode_Invert)
1542 type = 2;
1544 else
1546 type = 4;
1549 if (msg->invertpattern) type++;
1552 patarray = msg->pattern;
1553 patmask = 0x8000 >> (msg->patternsrcx & 0xF);
1555 if ((maskarray = msg->mask))
1557 maskarray += (msg->masksrcx / 16) * 2;
1558 maskmask = 0x8000 >> (msg->masksrcx & 0xF);
1561 buf = msg->dst + msg->y * msg->dstMod + msg->x;
1563 for(y = 0; y < msg->height; y++)
1565 UWORD pmask = patmask;
1566 UWORD mmask = maskmask;
1567 UWORD *parray = ((UWORD *)patarray) + ((y + msg->patternsrcy) % msg->patternheight);
1568 UWORD patword = AROS_BE2WORD(*parray);
1569 UWORD *marray;
1570 UWORD maskword;
1571 UBYTE *xbuf = (UBYTE *)buf;
1573 if (maskarray)
1575 marray = (UWORD *)maskarray;
1576 maskword = AROS_BE2WORD(*marray);
1579 switch(type)
1581 case 0: /* JAM1 */
1582 for(x = 0; x < msg->width; x++, xbuf++)
1584 if (!maskarray || (maskword & mmask))
1586 if (patword & pmask) *xbuf = fg;
1589 if (maskarray)
1591 mmask >>= 1;
1592 if (!mmask)
1594 mmask = 0x8000;
1595 marray++;
1596 maskword = AROS_BE2WORD(*marray);
1600 pmask >>= 1;
1601 if (!pmask) pmask = 0x8000;
1603 } /* for(x = 0; x < msg->width; x++) */
1604 break;
1606 case 1: /* JAM1 | INVERSVID */
1607 for(x = 0; x < msg->width; x++, xbuf++)
1609 if (!maskarray || (maskword & mmask))
1611 if (!(patword & pmask)) *xbuf = fg;
1614 if (maskarray)
1616 mmask >>= 1;
1617 if (!mmask)
1619 mmask = 0x8000;
1620 marray++;
1621 maskword = AROS_BE2WORD(*marray);
1625 pmask >>= 1;
1626 if (!pmask) pmask = 0x8000;
1627 } /* for(x = 0; x < msg->width; x++) */
1628 break;
1630 case 2: /* COMPLEMENT */
1631 for(x = 0; x < msg->width; x++, xbuf++)
1633 if (!maskarray || (maskword & mmask))
1635 if (patword & pmask) *xbuf = ~(*xbuf);
1638 if (maskarray)
1640 mmask >>= 1;
1641 if (!mmask)
1643 mmask = 0x8000;
1644 marray++;
1645 maskword = AROS_BE2WORD(*marray);
1649 pmask >>= 1;
1650 if (!pmask) pmask = 0x8000;
1652 } /* for(x = 0; x < msg->width; x++) */
1653 break;
1655 case 3: /* COMPLEMENT | INVERSVID*/
1656 for(x = 0; x < msg->width; x++, xbuf++)
1658 if (!maskarray || (maskword & mmask))
1660 if (!(patword & pmask)) *xbuf = ~(*xbuf);
1663 if (maskarray)
1665 mmask >>= 1;
1666 if (!mmask)
1668 mmask = 0x8000;
1669 marray++;
1670 maskword = AROS_BE2WORD(*marray);
1674 pmask >>= 1;
1675 if (!pmask) pmask = 0x8000;
1677 } /* for(x = 0; x < msg->width; x++) */
1678 break;
1680 case 4: /* JAM2 */
1681 for(x = 0; x < msg->width; x++)
1683 if (!maskarray || (maskword & mmask))
1685 xbuf[x] = (patword & pmask) ? fg : bg;
1688 if (maskarray)
1690 mmask >>= 1;
1691 if (!mmask)
1693 mmask = 0x8000;
1694 marray++;
1695 maskword = AROS_BE2WORD(*marray);
1699 pmask >>= 1;
1700 if (!pmask) pmask = 0x8000;
1702 } /* for(x = 0; x < msg->width; x++) */
1703 break;
1705 case 5: /* JAM2 | INVERSVID */
1706 for(x = 0; x < msg->width; x++)
1708 if (!maskarray || (maskword & mmask))
1710 xbuf[x] = (patword & pmask) ? bg : fg;
1713 if (maskarray)
1715 mmask >>= 1;
1716 if (!mmask)
1718 mmask = 0x8000;
1719 marray++;
1720 maskword = AROS_BE2WORD(*marray);
1724 pmask >>= 1;
1725 if (!pmask) pmask = 0x8000;
1727 } /* for(x = 0; x < msg->width; x++) */
1728 break;
1730 case 6: /* multi color pattern */
1731 for(x = 0; x < msg->width; x++)
1733 if (!maskarray || (maskword & mmask))
1735 WORD plane;
1736 ULONG pixel = (patword & pmask) ? 1 : 0;
1738 for(plane = 1; plane < msg->patterndepth; plane++)
1740 UWORD *_parray = parray + plane * msg->patternheight;
1741 UWORD _patword = AROS_BE2WORD(*_parray);
1743 if (_patword & pmask) pixel |= 1L << plane;
1746 if (msg->patternlut) pixel = msg->patternlut->pixels[pixel];
1748 xbuf[x] = pixel;
1751 if (maskarray)
1753 mmask >>= 1;
1754 if (!mmask)
1756 mmask = 0x8000;
1757 marray++;
1758 maskword = AROS_BE2WORD(*marray);
1762 pmask >>= 1;
1763 if (!pmask) pmask = 0x8000;
1765 } /* for(x = 0; x < msg->width; x++) */
1766 break;
1768 } /* switch(type) */
1770 buf += msg->dstMod;
1771 if (maskarray) maskarray += msg->maskmodulo;
1773 } /* for(y = 0; y < msg->height; y++) */
1777 /****************************************************************************************/
1779 VOID BM__Hidd_BitMap__PutMemPattern16(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMemPattern16 *msg)
1781 WORD x, y;
1782 UBYTE *patarray, *buf, *maskarray = 0;
1783 UWORD patmask, maskmask;
1784 OOP_Object *gc = msg->gc;
1785 ULONG fg = GC_FG(gc);
1786 ULONG bg = GC_BG(gc);
1787 WORD type = 0;
1789 if (msg->width <= 0 || msg->height <= 0)
1790 return;
1792 if (msg->patterndepth > 1)
1794 type = 6;
1796 else
1798 if (GC_COLEXP(gc) == vHidd_GC_ColExp_Transparent)
1800 type = 0;
1802 else if (GC_DRMD(gc) == vHidd_GC_DrawMode_Invert)
1804 type = 2;
1806 else
1808 type = 4;
1811 if (msg->invertpattern) type++;
1814 patarray = msg->pattern;
1815 patmask = 0x8000 >> (msg->patternsrcx & 0xF);
1817 if ((maskarray = msg->mask))
1819 maskarray += (msg->masksrcx / 16) * 2;
1820 maskmask = 0x8000 >> (msg->masksrcx & 0xF);
1823 buf = msg->dst + msg->y * msg->dstMod + msg->x * 2;
1825 for(y = 0; y < msg->height; y++)
1827 UWORD pmask = patmask;
1828 UWORD mmask = maskmask;
1829 UWORD *parray = ((UWORD *)patarray) + ((y + msg->patternsrcy) % msg->patternheight);
1830 UWORD patword = AROS_BE2WORD(*parray);
1831 UWORD *marray;
1832 UWORD maskword;
1833 UWORD *xbuf = (UWORD *)buf;
1835 if (maskarray)
1837 marray = (UWORD *)maskarray;
1838 maskword = AROS_BE2WORD(*marray);
1841 switch(type)
1843 case 0: /* JAM1 */
1844 for(x = 0; x < msg->width; x++, xbuf++)
1846 if (!maskarray || (maskword & mmask))
1848 if (patword & pmask) *xbuf = fg;
1851 if (maskarray)
1853 mmask >>= 1;
1854 if (!mmask)
1856 mmask = 0x8000;
1857 marray++;
1858 maskword = AROS_BE2WORD(*marray);
1862 pmask >>= 1;
1863 if (!pmask) pmask = 0x8000;
1865 } /* for(x = 0; x < msg->width; x++) */
1866 break;
1868 case 1: /* JAM1 | INVERSVID */
1869 for(x = 0; x < msg->width; x++, xbuf++)
1871 if (!maskarray || (maskword & mmask))
1873 if (!(patword & pmask)) *xbuf = fg;
1876 if (maskarray)
1878 mmask >>= 1;
1879 if (!mmask)
1881 mmask = 0x8000;
1882 marray++;
1883 maskword = AROS_BE2WORD(*marray);
1887 pmask >>= 1;
1888 if (!pmask) pmask = 0x8000;
1889 } /* for(x = 0; x < msg->width; x++) */
1890 break;
1892 case 2: /* COMPLEMENT */
1893 for(x = 0; x < msg->width; x++, xbuf++)
1895 if (!maskarray || (maskword & mmask))
1897 if (patword & pmask) *xbuf = ~(*xbuf);
1900 if (maskarray)
1902 mmask >>= 1;
1903 if (!mmask)
1905 mmask = 0x8000;
1906 marray++;
1907 maskword = AROS_BE2WORD(*marray);
1911 pmask >>= 1;
1912 if (!pmask) pmask = 0x8000;
1914 } /* for(x = 0; x < msg->width; x++) */
1915 break;
1917 case 3: /* COMPLEMENT | INVERSVID*/
1918 for(x = 0; x < msg->width; x++, xbuf++)
1920 if (!maskarray || (maskword & mmask))
1922 if (!(patword & pmask)) *xbuf = ~(*xbuf);
1925 if (maskarray)
1927 mmask >>= 1;
1928 if (!mmask)
1930 mmask = 0x8000;
1931 marray++;
1932 maskword = AROS_BE2WORD(*marray);
1936 pmask >>= 1;
1937 if (!pmask) pmask = 0x8000;
1939 } /* for(x = 0; x < msg->width; x++) */
1940 break;
1942 case 4: /* JAM2 */
1943 for(x = 0; x < msg->width; x++)
1945 if (!maskarray || (maskword & mmask))
1947 xbuf[x] = (patword & pmask) ? fg : bg;
1950 if (maskarray)
1952 mmask >>= 1;
1953 if (!mmask)
1955 mmask = 0x8000;
1956 marray++;
1957 maskword = AROS_BE2WORD(*marray);
1961 pmask >>= 1;
1962 if (!pmask) pmask = 0x8000;
1964 } /* for(x = 0; x < msg->width; x++) */
1965 break;
1967 case 5: /* JAM2 | INVERSVID */
1968 for(x = 0; x < msg->width; x++)
1970 if (!maskarray || (maskword & mmask))
1972 xbuf[x] = (patword & pmask) ? bg : fg;
1975 if (maskarray)
1977 mmask >>= 1;
1978 if (!mmask)
1980 mmask = 0x8000;
1981 marray++;
1982 maskword = AROS_BE2WORD(*marray);
1986 pmask >>= 1;
1987 if (!pmask) pmask = 0x8000;
1989 } /* for(x = 0; x < msg->width; x++) */
1990 break;
1992 case 6: /* multi color pattern */
1993 for(x = 0; x < msg->width; x++)
1995 if (!maskarray || (maskword & mmask))
1997 WORD plane;
1998 ULONG pixel = (patword & pmask) ? 1 : 0;
2000 for(plane = 1; plane < msg->patterndepth; plane++)
2002 UWORD *_parray = parray + plane * msg->patternheight;
2003 UWORD _patword = AROS_BE2WORD(*_parray);
2005 if (_patword & pmask) pixel |= 1L << plane;
2008 if (msg->patternlut) pixel = msg->patternlut->pixels[pixel];
2010 xbuf[x] = pixel;
2013 if (maskarray)
2015 mmask >>= 1;
2016 if (!mmask)
2018 mmask = 0x8000;
2019 marray++;
2020 maskword = AROS_BE2WORD(*marray);
2024 pmask >>= 1;
2025 if (!pmask) pmask = 0x8000;
2027 } /* for(x = 0; x < msg->width; x++) */
2028 break;
2030 } /* switch(type) */
2032 buf += msg->dstMod;
2033 if (maskarray) maskarray += msg->maskmodulo;
2035 } /* for(y = 0; y < msg->height; y++) */
2038 /****************************************************************************************/
2040 VOID BM__Hidd_BitMap__PutMemPattern24(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMemPattern24 *msg)
2042 WORD x, y;
2043 UBYTE *patarray, *buf, *maskarray = 0;
2044 UWORD patmask, maskmask;
2045 OOP_Object *gc = msg->gc;
2046 ULONG fg = GC_FG(gc);
2047 UBYTE fg1, fg2, fg3;
2048 ULONG bg = GC_BG(gc);
2049 UBYTE bg1, bg2, bg3;
2050 WORD type = 0;
2052 if (msg->width <= 0 || msg->height <= 0)
2053 return;
2055 #if AROS_BIG_ENDIAN
2056 fg1 = (fg >> 16) & 0xFF;
2057 fg2 = (fg >> 8) & 0xFF;
2058 fg3 = fg & 0xFF;
2060 bg1 = (bg >> 16) & 0xFF;
2061 bg2 = (bg >> 8) & 0xFF;
2062 bg3 = bg & 0xFF;
2063 #else
2064 fg1 = fg & 0xFF;
2065 fg2 = (fg >> 8) & 0xFF;
2066 fg3 = (fg >> 16) & 0xFF;
2068 bg1 = bg & 0xFF;
2069 bg2 = (bg >> 8) & 0xFF;
2070 bg3 = (bg >> 16) & 0xFF;
2071 #endif
2073 if (msg->patterndepth > 1)
2075 type = 6;
2077 else
2079 if (GC_COLEXP(gc) == vHidd_GC_ColExp_Transparent)
2081 type = 0;
2083 else if (GC_DRMD(gc) == vHidd_GC_DrawMode_Invert)
2085 type = 2;
2087 else
2089 type = 4;
2092 if (msg->invertpattern) type++;
2095 patarray = msg->pattern;
2096 patmask = 0x8000 >> (msg->patternsrcx & 0xF);
2098 if ((maskarray = msg->mask))
2100 maskarray += (msg->masksrcx / 16) * 2;
2101 maskmask = 0x8000 >> (msg->masksrcx & 0xF);
2104 buf = msg->dst + msg->y * msg->dstMod + msg->x * 3;
2106 for(y = 0; y < msg->height; y++)
2108 UWORD pmask = patmask;
2109 UWORD mmask = maskmask;
2110 UWORD *parray = ((UWORD *)patarray) + ((y + msg->patternsrcy) % msg->patternheight);
2111 UWORD patword = AROS_BE2WORD(*parray);
2112 UWORD *marray;
2113 UWORD maskword;
2114 UBYTE *xbuf = (UBYTE *)buf;
2116 if (maskarray)
2118 marray = (UWORD *)maskarray;
2119 maskword = AROS_BE2WORD(*marray);
2122 switch(type)
2124 case 0: /* JAM1 */
2125 for(x = 0; x < msg->width; x++, xbuf += 3)
2127 if (!maskarray || (maskword & mmask))
2129 if (patword & pmask)
2131 xbuf[0] = fg1;
2132 xbuf[1] = fg2;
2133 xbuf[2] = fg3;
2137 if (maskarray)
2139 mmask >>= 1;
2140 if (!mmask)
2142 mmask = 0x8000;
2143 marray++;
2144 maskword = AROS_BE2WORD(*marray);
2148 pmask >>= 1;
2149 if (!pmask) pmask = 0x8000;
2151 } /* for(x = 0; x < msg->width; x++) */
2152 break;
2154 case 1: /* JAM1 | INVERSVID */
2155 for(x = 0; x < msg->width; x++, xbuf += 3)
2157 if (!maskarray || (maskword & mmask))
2159 if (!(patword & pmask))
2161 xbuf[0] = fg1;
2162 xbuf[1] = fg2;
2163 xbuf[2] = fg3;
2168 if (maskarray)
2170 mmask >>= 1;
2171 if (!mmask)
2173 mmask = 0x8000;
2174 marray++;
2175 maskword = AROS_BE2WORD(*marray);
2179 pmask >>= 1;
2180 if (!pmask) pmask = 0x8000;
2181 } /* for(x = 0; x < msg->width; x++) */
2182 break;
2184 case 2: /* COMPLEMENT */
2185 for(x = 0; x < msg->width; x++, xbuf += 3)
2187 if (!maskarray || (maskword & mmask))
2189 if (patword & pmask)
2191 xbuf[0] = ~xbuf[0];
2192 xbuf[1] = ~xbuf[1];
2193 xbuf[2] = ~xbuf[2];
2197 if (maskarray)
2199 mmask >>= 1;
2200 if (!mmask)
2202 mmask = 0x8000;
2203 marray++;
2204 maskword = AROS_BE2WORD(*marray);
2208 pmask >>= 1;
2209 if (!pmask) pmask = 0x8000;
2211 } /* for(x = 0; x < msg->width; x++) */
2212 break;
2214 case 3: /* COMPLEMENT | INVERSVID*/
2215 for(x = 0; x < msg->width; x++, xbuf += 3)
2217 if (!maskarray || (maskword & mmask))
2219 if (!(patword & pmask))
2221 xbuf[0] = ~xbuf[0];
2222 xbuf[1] = ~xbuf[1];
2223 xbuf[2] = ~xbuf[2];
2227 if (maskarray)
2229 mmask >>= 1;
2230 if (!mmask)
2232 mmask = 0x8000;
2233 marray++;
2234 maskword = AROS_BE2WORD(*marray);
2238 pmask >>= 1;
2239 if (!pmask) pmask = 0x8000;
2241 } /* for(x = 0; x < msg->width; x++) */
2242 break;
2244 case 4: /* JAM2 */
2245 for(x = 0; x < msg->width; x++, xbuf += 3)
2247 if (!maskarray || (maskword & mmask))
2249 if (patword & pmask)
2251 xbuf[0] = fg1;
2252 xbuf[1] = fg2;
2253 xbuf[2] = fg3;
2255 else
2257 xbuf[0] = bg1;
2258 xbuf[1] = bg2;
2259 xbuf[2] = bg3;
2264 if (maskarray)
2266 mmask >>= 1;
2267 if (!mmask)
2269 mmask = 0x8000;
2270 marray++;
2271 maskword = AROS_BE2WORD(*marray);
2275 pmask >>= 1;
2276 if (!pmask) pmask = 0x8000;
2278 } /* for(x = 0; x < msg->width; x++) */
2279 break;
2281 case 5: /* JAM2 | INVERSVID */
2282 for(x = 0; x < msg->width; x++, xbuf += 3)
2284 if (!maskarray || (maskword & mmask))
2286 if (patword & pmask)
2288 xbuf[0] = bg1;
2289 xbuf[1] = bg2;
2290 xbuf[2] = bg3;
2292 else
2294 xbuf[0] = fg1;
2295 xbuf[1] = fg2;
2296 xbuf[2] = fg3;
2301 if (maskarray)
2303 mmask >>= 1;
2304 if (!mmask)
2306 mmask = 0x8000;
2307 marray++;
2308 maskword = AROS_BE2WORD(*marray);
2312 pmask >>= 1;
2313 if (!pmask) pmask = 0x8000;
2315 } /* for(x = 0; x < msg->width; x++) */
2316 break;
2318 case 6: /* multi color pattern */
2319 for(x = 0; x < msg->width; x++, xbuf += 3)
2321 if (!maskarray || (maskword & mmask))
2323 WORD plane;
2324 ULONG pixel = (patword & pmask) ? 1 : 0;
2326 for(plane = 1; plane < msg->patterndepth; plane++)
2328 UWORD *_parray = parray + plane * msg->patternheight;
2329 UWORD _patword = AROS_BE2WORD(*_parray);
2331 if (_patword & pmask) pixel |= 1L << plane;
2334 if (msg->patternlut) pixel = msg->patternlut->pixels[pixel];
2336 #if AROS_BIG_ENDIAN
2337 xbuf[0] = (pixel >> 16) & 0xFF;
2338 xbuf[1] = (pixel >> 8) & 0xFF;
2339 xbuf[2] = (pixel) & 0xFF;
2340 #else
2341 xbuf[0] = (pixel) & 0xFF;
2342 xbuf[1] = (pixel >> 8) & 0xFF;
2343 xbuf[2] = (pixel >> 16) & 0xFF;
2344 #endif
2347 if (maskarray)
2349 mmask >>= 1;
2350 if (!mmask)
2352 mmask = 0x8000;
2353 marray++;
2354 maskword = AROS_BE2WORD(*marray);
2358 pmask >>= 1;
2359 if (!pmask) pmask = 0x8000;
2361 } /* for(x = 0; x < msg->width; x++) */
2362 break;
2364 } /* switch(type) */
2366 buf += msg->dstMod;
2367 if (maskarray) maskarray += msg->maskmodulo;
2369 } /* for(y = 0; y < msg->height; y++) */
2373 /****************************************************************************************/
2375 VOID BM__Hidd_BitMap__PutMemPattern32(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutMemPattern32 *msg)
2377 WORD x, y;
2378 UBYTE *patarray, *buf, *maskarray = 0;
2379 UWORD patmask, maskmask;
2380 OOP_Object *gc = msg->gc;
2381 ULONG fg = GC_FG(gc);
2382 ULONG bg = GC_BG(gc);
2383 WORD type = 0;
2385 if (msg->width <= 0 || msg->height <= 0)
2386 return;
2388 if (msg->patterndepth > 1)
2390 type = 6;
2392 else
2394 if (GC_COLEXP(gc) == vHidd_GC_ColExp_Transparent)
2396 type = 0;
2398 else if (GC_DRMD(gc) == vHidd_GC_DrawMode_Invert)
2400 type = 2;
2402 else
2404 type = 4;
2407 if (msg->invertpattern) type++;
2410 patarray = msg->pattern;
2411 patmask = 0x8000 >> (msg->patternsrcx & 0xF);
2413 if ((maskarray = msg->mask))
2415 maskarray += (msg->masksrcx / 16) * 2;
2416 maskmask = 0x8000 >> (msg->masksrcx & 0xF);
2419 buf = msg->dst + msg->y * msg->dstMod + msg->x * 4;
2421 for(y = 0; y < msg->height; y++)
2423 UWORD pmask = patmask;
2424 UWORD mmask = maskmask;
2425 UWORD *parray = ((UWORD *)patarray) + ((y + msg->patternsrcy) % msg->patternheight);
2426 UWORD patword = AROS_BE2WORD(*parray);
2427 UWORD *marray;
2428 UWORD maskword;
2429 ULONG *xbuf = (ULONG *)buf;
2431 if (maskarray)
2433 marray = (UWORD *)maskarray;
2434 maskword = AROS_BE2WORD(*marray);
2437 switch(type)
2439 case 0: /* JAM1 */
2440 for(x = 0; x < msg->width; x++, xbuf++)
2442 if (!maskarray || (maskword & mmask))
2444 if (patword & pmask) *xbuf = fg;
2447 if (maskarray)
2449 mmask >>= 1;
2450 if (!mmask)
2452 mmask = 0x8000;
2453 marray++;
2454 maskword = AROS_BE2WORD(*marray);
2458 pmask >>= 1;
2459 if (!pmask) pmask = 0x8000;
2461 } /* for(x = 0; x < msg->width; x++) */
2462 break;
2464 case 1: /* JAM1 | INVERSVID */
2465 for(x = 0; x < msg->width; x++, xbuf++)
2467 if (!maskarray || (maskword & mmask))
2469 if (!(patword & pmask)) *xbuf = fg;
2472 if (maskarray)
2474 mmask >>= 1;
2475 if (!mmask)
2477 mmask = 0x8000;
2478 marray++;
2479 maskword = AROS_BE2WORD(*marray);
2483 pmask >>= 1;
2484 if (!pmask) pmask = 0x8000;
2485 } /* for(x = 0; x < msg->width; x++) */
2486 break;
2488 case 2: /* COMPLEMENT */
2489 for(x = 0; x < msg->width; x++, xbuf++)
2491 if (!maskarray || (maskword & mmask))
2493 if (patword & pmask) *xbuf = ~(*xbuf);
2496 if (maskarray)
2498 mmask >>= 1;
2499 if (!mmask)
2501 mmask = 0x8000;
2502 marray++;
2503 maskword = AROS_BE2WORD(*marray);
2507 pmask >>= 1;
2508 if (!pmask) pmask = 0x8000;
2510 } /* for(x = 0; x < msg->width; x++) */
2511 break;
2513 case 3: /* COMPLEMENT | INVERSVID*/
2514 for(x = 0; x < msg->width; x++, xbuf++)
2516 if (!maskarray || (maskword & mmask))
2518 if (!(patword & pmask)) *xbuf = ~(*xbuf);
2521 if (maskarray)
2523 mmask >>= 1;
2524 if (!mmask)
2526 mmask = 0x8000;
2527 marray++;
2528 maskword = AROS_BE2WORD(*marray);
2532 pmask >>= 1;
2533 if (!pmask) pmask = 0x8000;
2535 } /* for(x = 0; x < msg->width; x++) */
2536 break;
2538 case 4: /* JAM2 */
2539 for(x = 0; x < msg->width; x++)
2541 if (!maskarray || (maskword & mmask))
2543 xbuf[x] = (patword & pmask) ? fg : bg;
2546 if (maskarray)
2548 mmask >>= 1;
2549 if (!mmask)
2551 mmask = 0x8000;
2552 marray++;
2553 maskword = AROS_BE2WORD(*marray);
2557 pmask >>= 1;
2558 if (!pmask) pmask = 0x8000;
2560 } /* for(x = 0; x < msg->width; x++) */
2561 break;
2563 case 5: /* JAM2 | INVERSVID */
2564 for(x = 0; x < msg->width; x++)
2566 if (!maskarray || (maskword & mmask))
2568 xbuf[x] = (patword & pmask) ? bg : fg;
2571 if (maskarray)
2573 mmask >>= 1;
2574 if (!mmask)
2576 mmask = 0x8000;
2577 marray++;
2578 maskword = AROS_BE2WORD(*marray);
2582 pmask >>= 1;
2583 if (!pmask) pmask = 0x8000;
2585 } /* for(x = 0; x < msg->width; x++) */
2586 break;
2588 case 6: /* multi color pattern */
2589 for(x = 0; x < msg->width; x++)
2591 if (!maskarray || (maskword & mmask))
2593 WORD plane;
2594 ULONG pixel = (patword & pmask) ? 1 : 0;
2596 for(plane = 1; plane < msg->patterndepth; plane++)
2598 UWORD *_parray = parray + plane * msg->patternheight;
2599 UWORD _patword = AROS_BE2WORD(*_parray);
2601 if (_patword & pmask) pixel |= 1L << plane;
2604 if (msg->patternlut) pixel = msg->patternlut->pixels[pixel];
2606 xbuf[x] = pixel;
2609 if (maskarray)
2611 mmask >>= 1;
2612 if (!mmask)
2614 mmask = 0x8000;
2615 marray++;
2616 maskword = AROS_BE2WORD(*marray);
2620 pmask >>= 1;
2621 if (!pmask) pmask = 0x8000;
2623 } /* for(x = 0; x < msg->width; x++) */
2624 break;
2626 } /* switch(type) */
2628 buf += msg->dstMod;
2629 if (maskarray) maskarray += msg->maskmodulo;
2631 } /* for(y = 0; y < msg->height; y++) */
2635 /****************************************************************************************/