Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / arch / i386-pc / drivers / vesa.hidd / bitmap_common.c
blobac454414bf6fab1481645e577672e9f3d8c60c63
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English.
7 */
9 #include <exec/alerts.h>
10 #include <string.h> // memset() prototype
11 #include <aros/macros.h>
13 #undef DEBUG
14 #define DEBUG 0
15 #include <aros/debug.h>
17 /********* BitMap::PutPixel() ***************************/
19 VOID MNAME_BM(PutPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutPixel *msg)
21 struct BitmapData *data = OOP_INST_DATA(cl, o);
22 ULONG offset;
23 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
24 ULONG offset2;
25 #endif
26 HIDDT_Pixel pixel = msg->pixel;
27 UBYTE *mem;
28 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
29 UBYTE *mem2;
30 #endif
32 offset = (msg->x * data->bytesperpix) + (msg->y * data->bytesperline);
33 mem = data->VideoData + offset;
35 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
36 offset2 = (msg->x * data->bytesperpix) + (msg->y * data->data->bytesperline);
37 mem2 = data->data->framebuffer + offset2;
38 #endif
40 switch(data->bytesperpix)
42 case 1:
43 *(UBYTE *)mem = pixel;
44 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
45 *(UBYTE *)mem2 = pixel;
46 #endif
47 break;
49 case 2:
50 *(UWORD *)mem = pixel;
51 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
52 *(UWORD *)mem2 = pixel;
53 #endif
54 break;
56 case 3:
57 #if AROS_BIG_ENDIAN
58 *(UBYTE *)(mem) = pixel >> 16;
59 *(UBYTE *)(mem + 1) = pixel >> 8;
60 *(UBYTE *)(mem + 2) = pixel;
61 #else
62 *(UBYTE *)(mem) = pixel;
63 *(UBYTE *)(mem + 1) = pixel >> 8;
64 *(UBYTE *)(mem + 2) = pixel >> 16;
65 #endif
67 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
68 #if AROS_BIG_ENDIAN
69 *(UBYTE *)(mem2) = pixel >> 16;
70 *(UBYTE *)(mem2 + 1) = pixel >> 8;
71 *(UBYTE *)(mem2 + 2) = pixel;
72 #else
73 *(UBYTE *)(mem2) = pixel;
74 *(UBYTE *)(mem2 + 1) = pixel >> 8;
75 *(UBYTE *)(mem2 + 2) = pixel >> 16;
76 #endif
77 #endif
78 break;
80 case 4:
81 *(ULONG *)mem = pixel;
82 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
83 *(ULONG *)mem2 = pixel;
84 #endif
85 break;
88 return;
91 /********* BitMap::GetPixel() *********************************/
93 HIDDT_Pixel MNAME_BM(GetPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetPixel *msg)
95 struct BitmapData *data = OOP_INST_DATA(cl, o);
96 HIDDT_Pixel pixel;
97 ULONG offset;
98 UBYTE *mem;
100 offset = (msg->x * data->bytesperpix) +(msg->y * data->bytesperline);
101 mem = data->VideoData + offset;
103 switch(data->bytesperpix)
105 case 1:
106 pixel = *(UBYTE *)mem;
107 break;
109 case 2:
110 pixel = *(UWORD *)mem;
111 break;
113 case 3:
114 #if AROS_BIG_ENDIAN
115 pixel = (mem[0] << 16) | (mem[1] << 8) | mem[2];
116 #else
117 pixel = (mem[2] << 16) | (mem[1] << 8) | mem[0];
118 #endif
119 break;
121 case 4:
122 pixel = *(ULONG *)mem;
123 break;
125 default:
126 pixel = 0;
127 break;
131 return pixel;
134 /********* BitMap::FillRect() ***************************/
136 VOID MNAME_BM(FillRect)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_DrawRect *msg)
138 struct BitmapData *data =OOP_INST_DATA(cl, o);
139 HIDDT_Pixel fg = GC_FG(msg->gc);
140 HIDDT_DrawMode mode = GC_DRMD(msg->gc);
141 ULONG mod;
143 mod = data->bytesperline;
145 switch(mode)
147 case vHidd_GC_DrawMode_Copy:
148 switch(data->bytesperpix)
150 case 1:
151 HIDD_BM_FillMemRect8(o,
152 data->VideoData,
153 msg->minX,
154 msg->minY,
155 msg->maxX,
156 msg->maxY,
157 mod,
158 fg);
159 break;
161 case 2:
162 HIDD_BM_FillMemRect16(o,
163 data->VideoData,
164 msg->minX,
165 msg->minY,
166 msg->maxX,
167 msg->maxY,
168 mod,
169 fg);
170 break;
172 case 3:
173 HIDD_BM_FillMemRect24(o,
174 data->VideoData,
175 msg->minX,
176 msg->minY,
177 msg->maxX,
178 msg->maxY,
179 mod,
180 fg);
181 break;
183 case 4:
184 HIDD_BM_FillMemRect32(o,
185 data->VideoData,
186 msg->minX,
187 msg->minY,
188 msg->maxX,
189 msg->maxY,
190 mod,
191 fg);
192 break;
195 break;
197 case vHidd_GC_DrawMode_Invert:
198 HIDD_BM_InvertMemRect(o,
199 data->VideoData,
200 msg->minX * data->bytesperpix,
201 msg->minY,
202 msg->maxX * data->bytesperpix + data->bytesperpix - 1,
203 msg->maxY,
204 mod);
205 break;
207 default:
208 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
209 break;
211 } /* switch(mode) */
213 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
214 LOCK_FRAMEBUFFER(XSD(cl));
215 vesaRefreshArea(data, msg->minX, msg->minY, msg->maxX, msg->maxY);
216 UNLOCK_FRAMEBUFFER(XSD(cl));
217 #endif
220 /********* BitMap::PutImage() ***************************/
222 VOID MNAME_BM(PutImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImage *msg)
224 struct BitmapData *data = OOP_INST_DATA(cl, o);
226 switch(msg->pixFmt)
228 case vHidd_StdPixFmt_Native:
229 switch(data->bytesperpix)
231 case 1:
232 HIDD_BM_CopyMemBox8(o,
233 msg->pixels,
236 data->VideoData,
237 msg->x,
238 msg->y,
239 msg->width,
240 msg->height,
241 msg->modulo,
242 data->bytesperline);
243 break;
245 case 2:
246 HIDD_BM_CopyMemBox16(o,
247 msg->pixels,
250 data->VideoData,
251 msg->x,
252 msg->y,
253 msg->width,
254 msg->height,
255 msg->modulo,
256 data->bytesperline);
257 break;
259 case 3:
260 HIDD_BM_CopyMemBox24(o,
261 msg->pixels,
264 data->VideoData,
265 msg->x,
266 msg->y,
267 msg->width,
268 msg->height,
269 msg->modulo,
270 data->bytesperline);
271 break;
273 case 4:
274 HIDD_BM_CopyMemBox32(o,
275 msg->pixels,
278 data->VideoData,
279 msg->x,
280 msg->y,
281 msg->width,
282 msg->height,
283 msg->modulo,
284 data->bytesperline);
285 break;
287 } /* switch(data->bytesperpix) */
288 break;
290 case vHidd_StdPixFmt_Native32:
291 switch(data->bytesperpix)
293 case 1:
294 HIDD_BM_PutMem32Image8(o,
295 msg->pixels,
296 data->VideoData,
297 msg->x,
298 msg->y,
299 msg->width,
300 msg->height,
301 msg->modulo,
302 data->bytesperline);
303 break;
305 case 2:
306 HIDD_BM_PutMem32Image16(o,
307 msg->pixels,
308 data->VideoData,
309 msg->x,
310 msg->y,
311 msg->width,
312 msg->height,
313 msg->modulo,
314 data->bytesperline);
315 break;
317 case 3:
318 HIDD_BM_PutMem32Image24(o,
319 msg->pixels,
320 data->VideoData,
321 msg->x,
322 msg->y,
323 msg->width,
324 msg->height,
325 msg->modulo,
326 data->bytesperline);
327 break;
329 case 4:
330 HIDD_BM_CopyMemBox32(o,
331 msg->pixels,
334 data->VideoData,
335 msg->x,
336 msg->y,
337 msg->width,
338 msg->height,
339 msg->modulo,
340 data->bytesperline);
341 break;
343 } /* switch(data->bytesperpix) */
344 break;
346 default:
347 #if 1
349 APTR pixels = msg->pixels;
350 APTR dstBuf = data->VideoData + msg->y * data->bytesperline + msg->x * data->bytesperpix;
351 OOP_Object *srcpf;
353 srcpf = HIDD_Gfx_GetPixFmt(data->gfxhidd, msg->pixFmt);
355 HIDD_BM_ConvertPixels(o, &pixels, (HIDDT_PixelFormat *)srcpf, msg->modulo,
356 &dstBuf, (HIDDT_PixelFormat *)data->pixfmtobj, data->bytesperline,
357 msg->width, msg->height, NULL);
360 #else
361 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
362 #endif
363 break;
365 } /* switch(msg->pixFmt) */
367 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
368 LOCK_FRAMEBUFFER(XSD(cl));
369 vesaRefreshArea(data, msg->x, msg->y, msg->x + msg->width - 1, msg->y + msg->height - 1);
370 UNLOCK_FRAMEBUFFER(XSD(cl));
371 #endif
375 /********* BitMap::GetImage() ***************************/
377 VOID MNAME_BM(GetImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImage *msg)
379 struct BitmapData *data = OOP_INST_DATA(cl, o);
381 switch(msg->pixFmt)
383 case vHidd_StdPixFmt_Native:
384 switch(data->bytesperpix)
386 case 1:
387 HIDD_BM_CopyMemBox8(o,
388 data->VideoData,
389 msg->x,
390 msg->y,
391 msg->pixels,
394 msg->width,
395 msg->height,
396 data->bytesperline,
397 msg->modulo);
398 break;
400 case 2:
401 HIDD_BM_CopyMemBox16(o,
402 data->VideoData,
403 msg->x,
404 msg->y,
405 msg->pixels,
408 msg->width,
409 msg->height,
410 data->bytesperline,
411 msg->modulo);
412 break;
414 case 3:
415 HIDD_BM_CopyMemBox24(o,
416 data->VideoData,
417 msg->x,
418 msg->y,
419 msg->pixels,
422 msg->width,
423 msg->height,
424 data->bytesperline,
425 msg->modulo);
426 break;
428 case 4:
429 HIDD_BM_CopyMemBox32(o,
430 data->VideoData,
431 msg->x,
432 msg->y,
433 msg->pixels,
436 msg->width,
437 msg->height,
438 data->bytesperline,
439 msg->modulo);
440 break;
442 } /* switch(data->bytesperpix) */
443 break;
445 case vHidd_StdPixFmt_Native32:
446 switch(data->bytesperpix)
448 case 1:
449 HIDD_BM_GetMem32Image8(o,
450 data->VideoData,
451 msg->x,
452 msg->y,
453 msg->pixels,
454 msg->width,
455 msg->height,
456 data->bytesperline,
457 msg->modulo);
458 break;
460 case 2:
461 HIDD_BM_GetMem32Image16(o,
462 data->VideoData,
463 msg->x,
464 msg->y,
465 msg->pixels,
466 msg->width,
467 msg->height,
468 data->bytesperline,
469 msg->modulo);
470 break;
472 case 3:
473 HIDD_BM_GetMem32Image24(o,
474 data->VideoData,
475 msg->x,
476 msg->y,
477 msg->pixels,
478 msg->width,
479 msg->height,
480 data->bytesperline,
481 msg->modulo);
482 break;
484 case 4:
485 HIDD_BM_CopyMemBox32(o,
486 data->VideoData,
487 msg->x,
488 msg->y,
489 msg->pixels,
492 msg->width,
493 msg->height,
494 data->bytesperline,
495 msg->modulo);
496 break;
498 } /* switch(data->bytesperpix) */
499 break;
501 default:
502 #if 1
504 APTR pixels = msg->pixels;
505 APTR srcPixels = data->VideoData + msg->y * data->bytesperline + msg->x * data->bytesperpix;
506 OOP_Object *dstpf;
508 dstpf = HIDD_Gfx_GetPixFmt(data->gfxhidd, msg->pixFmt);
510 HIDD_BM_ConvertPixels(o, &srcPixels, (HIDDT_PixelFormat *)data->pixfmtobj, data->bytesperline,
511 &pixels, (HIDDT_PixelFormat *)dstpf, msg->modulo,
512 msg->width, msg->height, NULL);
514 #else
515 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
516 #endif
517 break;
519 } /* switch(msg->pixFmt) */
523 VOID MNAME_BM(PutImageLUT)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImageLUT *msg)
525 struct BitmapData *data = OOP_INST_DATA(cl, o);
527 switch(data->bytesperpix)
529 case 2:
530 HIDD_BM_CopyLUTMemBox16(o,
531 msg->pixels,
534 data->VideoData,
535 msg->x,
536 msg->y,
537 msg->width,
538 msg->height,
539 msg->modulo,
540 data->bytesperline,
541 msg->pixlut);
542 break;
544 case 3:
545 HIDD_BM_CopyLUTMemBox24(o,
546 msg->pixels,
549 data->VideoData,
550 msg->x,
551 msg->y,
552 msg->width,
553 msg->height,
554 msg->modulo,
555 data->bytesperline,
556 msg->pixlut);
557 break;
559 case 4:
560 HIDD_BM_CopyLUTMemBox32(o,
561 msg->pixels,
564 data->VideoData,
565 msg->x,
566 msg->y,
567 msg->width,
568 msg->height,
569 msg->modulo,
570 data->bytesperline,
571 msg->pixlut);
572 break;
574 default:
575 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
576 break;
578 } /* switch(data->bytesperpix) */
580 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
581 LOCK_FRAMEBUFFER(XSD(cl));
582 vesaRefreshArea(data, msg->x, msg->y, msg->x + msg->width - 1, msg->y + msg->height - 1);
583 UNLOCK_FRAMEBUFFER(XSD(cl));
584 #endif
588 /*** BitMap::BlitColorExpansion() **********************************************/
589 VOID MNAME_BM(BlitColorExpansion)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_BlitColorExpansion *msg)
591 struct BitmapData *data = OOP_INST_DATA(cl, o);
592 HIDDT_Pixel fg, bg, pix;
593 ULONG cemd;
594 LONG x, y;
595 ULONG mod, bpp;
596 UBYTE *mem;
597 BOOL opaque;
599 fg = GC_FG(msg->gc);
600 bg = GC_BG(msg->gc);
601 cemd = GC_COLEXP(msg->gc);
603 bpp = data->bytesperpix;
605 mem = data->VideoData + msg->destY * data->bytesperline + msg->destX * bpp;
606 mod = data->bytesperline - msg->width * bpp;
608 opaque = (cemd & vHidd_GC_ColExp_Opaque) ? TRUE : FALSE;
610 for (y = 0; y < msg->height; y ++)
612 for (x = 0; x < msg->width; x ++)
614 ULONG is_set;
616 is_set = HIDD_BM_GetPixel(msg->srcBitMap, x + msg->srcX, y + msg->srcY);
617 if (is_set)
619 pix = fg;
621 else if (opaque)
623 pix = bg;
625 else
627 mem += bpp;
628 continue;
631 switch(bpp)
633 case 1:
634 *mem++ = pix;
635 break;
637 case 2:
638 *((UWORD *)mem) = pix;
639 mem += 2;
640 break;
642 case 3:
643 #if AROS_BIG_ENDIAN
644 mem[0] = pix >> 16;
645 mem[1] = pix >> 8;
646 mem[2] = pix;
647 #else
648 mem[0] = pix;
649 mem[1] = pix >> 8;
650 mem[2] = pix >> 16;
651 #endif
652 mem += 3;
653 break;
655 case 4:
656 *((ULONG *)mem) = pix;
657 mem += 4;
658 break;
662 } /* for (each x) */
664 mem += mod;
666 } /* for (each y) */
668 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
669 LOCK_FRAMEBUFFER(XSD(cl));
670 vesaRefreshArea(data, msg->destX, msg->destY, msg->destX + msg->width - 1, msg->destY + msg->height - 1);
671 UNLOCK_FRAMEBUFFER(XSD(cl));
672 #endif
675 /*** BitMap::PutTemplate() **********************************************/
677 VOID MNAME_BM(PutTemplate)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutTemplate *msg)
679 struct BitmapData *data = OOP_INST_DATA(cl, o);
681 switch(data->bytesperpix)
683 case 1:
684 HIDD_BM_PutMemTemplate8(o,
685 msg->gc,
686 msg->template,
687 msg->modulo,
688 msg->srcx,
689 data->VideoData,
690 data->bytesperline,
691 msg->x,
692 msg->y,
693 msg->width,
694 msg->height,
695 msg->inverttemplate);
696 break;
698 case 2:
699 HIDD_BM_PutMemTemplate16(o,
700 msg->gc,
701 msg->template,
702 msg->modulo,
703 msg->srcx,
704 data->VideoData,
705 data->bytesperline,
706 msg->x,
707 msg->y,
708 msg->width,
709 msg->height,
710 msg->inverttemplate);
711 break;
713 case 3:
714 HIDD_BM_PutMemTemplate24(o,
715 msg->gc,
716 msg->template,
717 msg->modulo,
718 msg->srcx,
719 data->VideoData,
720 data->bytesperline,
721 msg->x,
722 msg->y,
723 msg->width,
724 msg->height,
725 msg->inverttemplate);
726 break;
728 case 4:
729 HIDD_BM_PutMemTemplate32(o,
730 msg->gc,
731 msg->template,
732 msg->modulo,
733 msg->srcx,
734 data->VideoData,
735 data->bytesperline,
736 msg->x,
737 msg->y,
738 msg->width,
739 msg->height,
740 msg->inverttemplate);
741 break;
743 default:
744 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
745 break;
747 } /* switch(data->bytesperpix) */
749 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
750 LOCK_FRAMEBUFFER(XSD(cl));
751 vesaRefreshArea(data, msg->x, msg->y, msg->x + msg->width - 1, msg->y + msg->height - 1);
752 UNLOCK_FRAMEBUFFER(XSD(cl));
753 #endif
757 /*** BitMap::PutPattern() **********************************************/
759 VOID MNAME_BM(PutPattern)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutPattern *msg)
761 struct BitmapData *data = OOP_INST_DATA(cl, o);
763 switch(data->bytesperpix)
765 case 1:
766 HIDD_BM_PutMemPattern8(o,
767 msg->gc,
768 msg->pattern,
769 msg->patternsrcx,
770 msg->patternsrcy,
771 msg->patternheight,
772 msg->patterndepth,
773 msg->patternlut,
774 msg->invertpattern,
775 msg->mask,
776 msg->maskmodulo,
777 msg->masksrcx,
778 data->VideoData,
779 data->bytesperline,
780 msg->x,
781 msg->y,
782 msg->width,
783 msg->height);
784 break;
786 case 2:
787 HIDD_BM_PutMemPattern16(o,
788 msg->gc,
789 msg->pattern,
790 msg->patternsrcx,
791 msg->patternsrcy,
792 msg->patternheight,
793 msg->patterndepth,
794 msg->patternlut,
795 msg->invertpattern,
796 msg->mask,
797 msg->maskmodulo,
798 msg->masksrcx,
799 data->VideoData,
800 data->bytesperline,
801 msg->x,
802 msg->y,
803 msg->width,
804 msg->height);
805 break;
807 case 3:
808 HIDD_BM_PutMemPattern24(o,
809 msg->gc,
810 msg->pattern,
811 msg->patternsrcx,
812 msg->patternsrcy,
813 msg->patternheight,
814 msg->patterndepth,
815 msg->patternlut,
816 msg->invertpattern,
817 msg->mask,
818 msg->maskmodulo,
819 msg->masksrcx,
820 data->VideoData,
821 data->bytesperline,
822 msg->x,
823 msg->y,
824 msg->width,
825 msg->height);
826 break;
828 case 4:
829 HIDD_BM_PutMemPattern32(o,
830 msg->gc,
831 msg->pattern,
832 msg->patternsrcx,
833 msg->patternsrcy,
834 msg->patternheight,
835 msg->patterndepth,
836 msg->patternlut,
837 msg->invertpattern,
838 msg->mask,
839 msg->maskmodulo,
840 msg->masksrcx,
841 data->VideoData,
842 data->bytesperline,
843 msg->x,
844 msg->y,
845 msg->width,
846 msg->height);
847 break;
849 default:
850 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
851 break;
853 } /* switch(data->bytesperpix) */
855 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
856 LOCK_FRAMEBUFFER(XSD(cl));
857 vesaRefreshArea(data, msg->x, msg->y, msg->x + msg->width - 1, msg->y + msg->height - 1);
858 UNLOCK_FRAMEBUFFER(XSD(cl));
859 #endif
864 /*** BitMap::Get() *******************************************/
866 VOID MNAME_ROOT(Get)(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
868 struct BitmapData *data = OOP_INST_DATA(cl, o);
869 ULONG idx;
871 if (IS_VesaGfxBM_ATTR(msg->attrID, idx))
873 switch (idx)
875 case aoHidd_VesaGfxBitMap_Drawable:
876 *msg->storage = (ULONG)data->VideoData;
877 break;
878 default:
879 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
882 else
884 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
888 /*** BitMap::SetColors() *************************************/
890 BOOL MNAME_BM(SetColors)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_SetColors *msg)
892 struct BitmapData *data = OOP_INST_DATA(cl, o);
893 struct HWData *hwdata = &XSD(cl)->data;
894 HIDDT_PixelFormat *pf;
896 ULONG xc_i, col_i;
897 UBYTE p_shift;
899 HIDDT_Pixel red, green, blue;
901 D(bug("[VESA] SetColors(%u, %u)\n", msg->firstColor, msg->numColors));
902 pf = BM_PIXFMT(o);
904 if ( vHidd_ColorModel_StaticPalette == HIDD_PF_COLMODEL(pf)
905 || vHidd_ColorModel_TrueColor == HIDD_PF_COLMODEL(pf) ) {
906 D(bug("[VESA] SetColors: not a palette bitmap\n"));
908 /* Superclass takes care of this case */
910 return OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
913 /* We have a vHidd_GT_Palette bitmap */
915 if (!OOP_DoSuperMethod(cl, o, (OOP_Msg)msg)) {
916 D(bug("[VESA] DoSuperMethod() failed\n"));
917 return FALSE;
920 if ((msg->firstColor + msg->numColors) > (1 << data->bpp))
921 return FALSE;
923 for ( xc_i = msg->firstColor, col_i = 0;
924 col_i < msg->numColors;
925 xc_i ++, col_i ++ )
927 red = msg->colors[col_i].red >> 8;
928 green = msg->colors[col_i].green >> 8;
929 blue = msg->colors[col_i].blue >> 8;
931 /* Set given color as allocated */
932 data->cmap[xc_i] = 0x01000000 | red | (green << 8) | (blue << 16);
934 /* Update DAC registers */
935 p_shift = 8 - hwdata->palettewidth;
936 hwdata->DAC[xc_i*3] = red >> p_shift;
937 hwdata->DAC[xc_i*3+1] = green >> p_shift;
938 hwdata->DAC[xc_i*3+2] = blue >> p_shift;
940 msg->colors[col_i].pixval = xc_i;
943 /* Upload palette to the DAC if OnBitmap */
944 #ifdef OnBitmap
945 #ifdef TRACK_POINTER_PALETTE
946 if ((msg->firstColor <= 20) && (msg->firstColor + msg->numColors - 1 >= 17))
947 bug("%d colors from %d changed\n", msg->firstColor, msg->numColors);
948 #endif
949 ObtainSemaphore(&XSD(cl)->HW_acc);
950 DACLoad(hwdata, msg->firstColor, msg->numColors);
951 ReleaseSemaphore(&XSD(cl)->HW_acc);
952 #endif /* OnBitmap */
954 return TRUE;