[NtGdi]
[reactos.git] / reactos / win32ss / gdi / ntgdi / dcutil.c
1 #include <win32k.h>
2
3 #define NDEBUG
4 #include <debug.h>
5
6 BOOL FASTCALL
7 GreDPtoLP(HDC hdc, LPPOINT lpPoints, INT nCount)
8 {
9 PDC dc;
10 if (!(dc = DC_LockDc(hdc)))
11 {
12 EngSetLastError(ERROR_INVALID_HANDLE);
13 return FALSE;
14 }
15 IntDPtoLP(dc, lpPoints, nCount);
16 DC_UnlockDc(dc);
17 return TRUE;
18 }
19
20 BOOL FASTCALL
21 GreLPtoDP(HDC hdc, LPPOINT lpPoints, INT nCount)
22 {
23 PDC dc;
24 if (!(dc = DC_LockDc(hdc)))
25 {
26 EngSetLastError(ERROR_INVALID_HANDLE);
27 return FALSE;
28 }
29 IntLPtoDP(dc, lpPoints, nCount);
30 DC_UnlockDc(dc);
31 return TRUE;
32 }
33
34 int FASTCALL
35 GreGetBkMode(HDC hdc)
36 {
37 PDC dc;
38 LONG lBkMode;
39 if (!(dc = DC_LockDc(hdc)))
40 {
41 EngSetLastError(ERROR_INVALID_HANDLE);
42 return CLR_INVALID;
43 }
44 lBkMode = dc->pdcattr->lBkMode;
45 DC_UnlockDc(dc);
46 return lBkMode;
47 }
48
49 COLORREF FASTCALL
50 GreGetBkColor(HDC hdc)
51 {
52 PDC dc;
53 COLORREF crBk;
54 if (!(dc = DC_LockDc(hdc)))
55 {
56 EngSetLastError(ERROR_INVALID_HANDLE);
57 return CLR_INVALID;
58 }
59 crBk = dc->pdcattr->ulBackgroundClr;
60 DC_UnlockDc(dc);
61 return crBk;
62 }
63
64 int FASTCALL
65 GreGetMapMode(HDC hdc)
66 {
67 PDC dc;
68 INT iMapMode;
69 if (!(dc = DC_LockDc(hdc)))
70 {
71 EngSetLastError(ERROR_INVALID_HANDLE);
72 return CLR_INVALID;
73 }
74 iMapMode = dc->pdcattr->iMapMode;
75 DC_UnlockDc(dc);
76 return iMapMode;
77 }
78
79 COLORREF FASTCALL
80 GreGetTextColor(HDC hdc)
81 {
82 PDC dc;
83 ULONG ulForegroundClr;
84 if (!(dc = DC_LockDc(hdc)))
85 {
86 EngSetLastError(ERROR_INVALID_HANDLE);
87 return CLR_INVALID;
88 }
89 ulForegroundClr = dc->pdcattr->ulForegroundClr;
90 DC_UnlockDc(dc);
91 return ulForegroundClr;
92 }
93
94 COLORREF FASTCALL
95 IntGdiSetBkColor(HDC hDC, COLORREF color)
96 {
97 COLORREF oldColor;
98 PDC dc;
99 PDC_ATTR pdcattr;
100 HBRUSH hBrush;
101
102 if (!(dc = DC_LockDc(hDC)))
103 {
104 EngSetLastError(ERROR_INVALID_HANDLE);
105 return CLR_INVALID;
106 }
107 pdcattr = dc->pdcattr;
108 oldColor = pdcattr->crBackgroundClr;
109 pdcattr->crBackgroundClr = color;
110 pdcattr->ulBackgroundClr = (ULONG)color;
111 pdcattr->ulDirty_ |= DIRTY_BACKGROUND|DIRTY_LINE|DIRTY_FILL; // Clear Flag if set.
112 hBrush = pdcattr->hbrush;
113 DC_UnlockDc(dc);
114 NtGdiSelectBrush(hDC, hBrush);
115 return oldColor;
116 }
117
118 INT FASTCALL
119 IntGdiSetBkMode(HDC hDC, INT Mode)
120 {
121 COLORREF oldMode;
122 PDC dc;
123 PDC_ATTR pdcattr;
124
125 if (!(dc = DC_LockDc(hDC)))
126 {
127 EngSetLastError(ERROR_INVALID_HANDLE);
128 return CLR_INVALID;
129 }
130 pdcattr = dc->pdcattr;
131 oldMode = pdcattr->lBkMode;
132 pdcattr->jBkMode = Mode;
133 pdcattr->lBkMode = Mode;
134 DC_UnlockDc(dc);
135 return oldMode;
136 }
137
138 UINT
139 FASTCALL
140 IntGdiSetTextAlign(HDC hDC,
141 UINT Mode)
142 {
143 UINT prevAlign;
144 DC *dc;
145 PDC_ATTR pdcattr;
146
147 dc = DC_LockDc(hDC);
148 if (!dc)
149 {
150 EngSetLastError(ERROR_INVALID_HANDLE);
151 return GDI_ERROR;
152 }
153 pdcattr = dc->pdcattr;
154 prevAlign = pdcattr->lTextAlign;
155 pdcattr->lTextAlign = Mode;
156 DC_UnlockDc(dc);
157 return prevAlign;
158 }
159
160 COLORREF
161 FASTCALL
162 IntGdiSetTextColor(HDC hDC,
163 COLORREF color)
164 {
165 COLORREF crOldColor;
166 PDC pdc;
167 PDC_ATTR pdcattr;
168
169 pdc = DC_LockDc(hDC);
170 if (!pdc)
171 {
172 EngSetLastError(ERROR_INVALID_HANDLE);
173 return CLR_INVALID;
174 }
175 pdcattr = pdc->pdcattr;
176
177 crOldColor = (COLORREF) pdcattr->ulForegroundClr;
178 pdcattr->ulForegroundClr = (ULONG)color;
179
180 if (pdcattr->crForegroundClr != color)
181 {
182 pdcattr->ulDirty_ |= (DIRTY_TEXT|DIRTY_LINE|DIRTY_FILL);
183 pdcattr->crForegroundClr = color;
184 }
185
186 DC_vUpdateTextBrush(pdc);
187
188 DC_UnlockDc(pdc);
189
190 return crOldColor;
191 }
192
193 COLORREF FASTCALL
194 IntSetDCBrushColor(HDC hdc, COLORREF crColor)
195 {
196 COLORREF OldColor = CLR_INVALID;
197 PDC dc;
198 if (!(dc = DC_LockDc(hdc)))
199 {
200 EngSetLastError(ERROR_INVALID_HANDLE);
201 return CLR_INVALID;
202 }
203 else
204 {
205 OldColor = (COLORREF) dc->pdcattr->ulBrushClr;
206 dc->pdcattr->ulBrushClr = (ULONG) crColor;
207
208 if ( dc->pdcattr->crBrushClr != crColor )
209 {
210 dc->pdcattr->ulDirty_ |= DIRTY_FILL;
211 dc->pdcattr->crBrushClr = crColor;
212 }
213 }
214 DC_UnlockDc(dc);
215 return OldColor;
216 }
217
218 COLORREF FASTCALL
219 IntSetDCPenColor(HDC hdc, COLORREF crColor)
220 {
221 COLORREF OldColor;
222 PDC dc;
223 if (!(dc = DC_LockDc(hdc)))
224 {
225 EngSetLastError(ERROR_INVALID_PARAMETER);
226 return CLR_INVALID;
227 }
228
229 OldColor = (COLORREF)dc->pdcattr->ulPenClr;
230 dc->pdcattr->ulPenClr = (ULONG)crColor;
231
232 if (dc->pdcattr->crPenClr != crColor)
233 {
234 dc->pdcattr->ulDirty_ |= DIRTY_LINE;
235 dc->pdcattr->crPenClr = crColor;
236 }
237 DC_UnlockDc(dc);
238 return OldColor;
239 }
240
241 int
242 FASTCALL
243 GreSetStretchBltMode(HDC hDC, int iStretchMode)
244 {
245 PDC pdc;
246 PDC_ATTR pdcattr;
247 INT oSMode = 0;
248
249 pdc = DC_LockDc(hDC);
250 if (pdc)
251 {
252 pdcattr = pdc->pdcattr;
253 oSMode = pdcattr->lStretchBltMode;
254 pdcattr->lStretchBltMode = iStretchMode;
255
256 // Wine returns an error here. We set the default.
257 if ((iStretchMode <= 0) || (iStretchMode > MAXSTRETCHBLTMODE)) iStretchMode = WHITEONBLACK;
258
259 pdcattr->jStretchBltMode = iStretchMode;
260 DC_UnlockDc(pdc);
261 }
262 return oSMode;
263 }
264
265 int FASTCALL
266 GreGetGraphicsMode(HDC hdc)
267 {
268 PDC dc;
269 int GraphicsMode;
270 if (!(dc = DC_LockDc(hdc)))
271 {
272 EngSetLastError(ERROR_INVALID_HANDLE);
273 return CLR_INVALID;
274 }
275 GraphicsMode = dc->pdcattr->iGraphicsMode;;
276 DC_UnlockDc(dc);
277 return GraphicsMode;
278 }
279
280 VOID
281 FASTCALL
282 DCU_SetDcUndeletable(HDC hDC)
283 {
284 PDC dc = DC_LockDc(hDC);
285 if (!dc)
286 {
287 EngSetLastError(ERROR_INVALID_HANDLE);
288 return;
289 }
290
291 dc->fs |= DC_FLAG_PERMANENT;
292 DC_UnlockDc(dc);
293 return;
294 }
295
296 #if 0
297 BOOL FASTCALL
298 IntIsPrimarySurface(SURFOBJ *SurfObj)
299 {
300 if (PrimarySurface.pSurface == NULL)
301 {
302 return FALSE;
303 }
304 return SurfObj->hsurf == PrimarySurface.pSurface; // <- FIXME: WTF?
305 }
306 #endif
307
308 BOOL
309 FASTCALL
310 IntSetDefaultRegion(PDC pdc)
311 {
312 PSURFACE pSurface;
313 PREGION prgn;
314 RECTL rclWnd, rclClip;
315
316 IntGdiReleaseRaoRgn(pdc);
317
318 rclWnd.left = 0;
319 rclWnd.top = 0;
320 rclWnd.right = pdc->dclevel.sizl.cx;
321 rclWnd.bottom = pdc->dclevel.sizl.cy;
322 rclClip = rclWnd;
323
324 //EngAcquireSemaphoreShared(pdc->ppdev->hsemDevLock);
325 if (pdc->ppdev->flFlags & PDEV_META_DEVICE)
326 {
327 pSurface = pdc->dclevel.pSurface;
328 if (pSurface && pSurface->flags & PDEV_SURFACE)
329 {
330 rclClip.left += pdc->ppdev->ptlOrigion.x;
331 rclClip.top += pdc->ppdev->ptlOrigion.y;
332 rclClip.right += pdc->ppdev->ptlOrigion.x;
333 rclClip.bottom += pdc->ppdev->ptlOrigion.y;
334 }
335 }
336 //EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
337
338 prgn = pdc->prgnVis;
339
340 if (prgn && prgn != prgnDefault)
341 {
342 REGION_SetRectRgn( prgn,
343 rclClip.left,
344 rclClip.top,
345 rclClip.right ,
346 rclClip.bottom );
347 }
348 else
349 {
350 prgn = IntSysCreateRectpRgn( rclClip.left,
351 rclClip.top,
352 rclClip.right ,
353 rclClip.bottom );
354 pdc->prgnVis = prgn;
355 }
356
357 if (prgn)
358 {
359 pdc->ptlDCOrig.x = 0;
360 pdc->ptlDCOrig.y = 0;
361 pdc->erclWindow = rclWnd;
362 pdc->erclClip = rclClip;
363 /* Might be an InitDC or DCE... */
364 pdc->ptlFillOrigin.x = pdc->dcattr.VisRectRegion.Rect.right;
365 pdc->ptlFillOrigin.y = pdc->dcattr.VisRectRegion.Rect.bottom;
366 return TRUE;
367 }
368
369 pdc->prgnVis = prgnDefault;
370 return FALSE;
371 }
372
373
374 BOOL APIENTRY
375 NtGdiCancelDC(HDC hDC)
376 {
377 UNIMPLEMENTED;
378 return FALSE;
379 }
380
381
382 WORD APIENTRY
383 IntGdiSetHookFlags(HDC hDC, WORD Flags)
384 {
385 WORD wRet;
386 DC *dc = DC_LockDc(hDC);
387
388 if (NULL == dc)
389 {
390 EngSetLastError(ERROR_INVALID_HANDLE);
391 return 0;
392 }
393
394 wRet = dc->fs & DC_FLAG_DIRTY_RAO; // FIXME: Wrong flag!
395
396 /* Info in "Undocumented Windows" is slightly confusing. */
397 DPRINT("DC %p, Flags %04x\n", hDC, Flags);
398
399 if (Flags & DCHF_INVALIDATEVISRGN)
400 {
401 /* hVisRgn has to be updated */
402 dc->fs |= DC_FLAG_DIRTY_RAO;
403 }
404 else if (Flags & DCHF_VALIDATEVISRGN || 0 == Flags)
405 {
406 //dc->fs &= ~DC_FLAG_DIRTY_RAO;
407 }
408
409 DC_UnlockDc(dc);
410
411 return wRet;
412 }
413
414
415 BOOL
416 APIENTRY
417 NtGdiGetDCDword(
418 HDC hDC,
419 UINT u,
420 DWORD *Result)
421 {
422 BOOL Ret = TRUE;
423 PDC pdc;
424 PDC_ATTR pdcattr;
425
426 DWORD SafeResult = 0;
427 NTSTATUS Status = STATUS_SUCCESS;
428
429 if (!Result)
430 {
431 EngSetLastError(ERROR_INVALID_PARAMETER);
432 return FALSE;
433 }
434
435 pdc = DC_LockDc(hDC);
436 if (!pdc)
437 {
438 EngSetLastError(ERROR_INVALID_HANDLE);
439 return FALSE;
440 }
441 pdcattr = pdc->pdcattr;
442
443 switch (u)
444 {
445 case GdiGetJournal:
446 break;
447
448 case GdiGetRelAbs:
449 SafeResult = pdcattr->lRelAbs;
450 break;
451
452 case GdiGetBreakExtra:
453 SafeResult = pdcattr->lBreakExtra;
454 break;
455
456 case GdiGerCharBreak:
457 SafeResult = pdcattr->cBreak;
458 break;
459
460 case GdiGetArcDirection:
461 if (pdcattr->dwLayout & LAYOUT_RTL)
462 SafeResult = AD_CLOCKWISE - ((pdc->dclevel.flPath & DCPATH_CLOCKWISE) != 0);
463 else
464 SafeResult = ((pdc->dclevel.flPath & DCPATH_CLOCKWISE) != 0) + AD_COUNTERCLOCKWISE;
465 break;
466
467 case GdiGetEMFRestorDc:
468 SafeResult = pdc->dclevel.lSaveDepth;
469 break;
470
471 case GdiGetFontLanguageInfo:
472 SafeResult = IntGetFontLanguageInfo(pdc);
473 break;
474
475 case GdiGetIsMemDc:
476 SafeResult = pdc->dctype;
477 break;
478
479 case GdiGetMapMode:
480 SafeResult = pdcattr->iMapMode;
481 break;
482
483 case GdiGetTextCharExtra:
484 SafeResult = pdcattr->lTextExtra;
485 break;
486
487 default:
488 EngSetLastError(ERROR_INVALID_PARAMETER);
489 Ret = FALSE;
490 break;
491 }
492
493 if (Ret)
494 {
495 _SEH2_TRY
496 {
497 ProbeForWrite(Result, sizeof(DWORD), 1);
498 *Result = SafeResult;
499 }
500 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
501 {
502 Status = _SEH2_GetExceptionCode();
503 }
504 _SEH2_END;
505
506 if (!NT_SUCCESS(Status))
507 {
508 SetLastNtError(Status);
509 Ret = FALSE;
510 }
511 }
512
513 DC_UnlockDc(pdc);
514 return Ret;
515 }
516
517 _Success_(return != FALSE)
518 BOOL
519 APIENTRY
520 NtGdiGetAndSetDCDword(
521 _In_ HDC hdc,
522 _In_ UINT u,
523 _In_ DWORD dwIn,
524 _Out_ DWORD *pdwResult)
525 {
526 BOOL Ret = TRUE;
527 PDC pdc;
528 PDC_ATTR pdcattr;
529
530 DWORD SafeResult = 0;
531 NTSTATUS Status = STATUS_SUCCESS;
532
533 if (!pdwResult)
534 {
535 EngSetLastError(ERROR_INVALID_PARAMETER);
536 return FALSE;
537 }
538
539 pdc = DC_LockDc(hdc);
540 if (!pdc)
541 {
542 EngSetLastError(ERROR_INVALID_HANDLE);
543 return FALSE;
544 }
545 pdcattr = pdc->pdcattr;
546
547 switch (u)
548 {
549 case GdiGetSetCopyCount:
550 SafeResult = pdc->ulCopyCount;
551 pdc->ulCopyCount = dwIn;
552 break;
553
554 case GdiGetSetTextAlign:
555 SafeResult = pdcattr->lTextAlign;
556 pdcattr->lTextAlign = dwIn;
557 // pdcattr->flTextAlign = dwIn; // Flags!
558 break;
559
560 case GdiGetSetRelAbs:
561 SafeResult = pdcattr->lRelAbs;
562 pdcattr->lRelAbs = dwIn;
563 break;
564
565 case GdiGetSetTextCharExtra:
566 SafeResult = pdcattr->lTextExtra;
567 pdcattr->lTextExtra = dwIn;
568 break;
569
570 case GdiGetSetSelectFont:
571 break;
572
573 case GdiGetSetMapperFlagsInternal:
574 if (dwIn & ~1)
575 {
576 EngSetLastError(ERROR_INVALID_PARAMETER);
577 Ret = FALSE;
578 break;
579 }
580 SafeResult = pdcattr->flFontMapper;
581 pdcattr->flFontMapper = dwIn;
582 break;
583
584 case GdiGetSetMapMode:
585 SafeResult = IntGdiSetMapMode(pdc, dwIn);
586 break;
587
588 case GdiGetSetArcDirection:
589 if (dwIn != AD_COUNTERCLOCKWISE && dwIn != AD_CLOCKWISE)
590 {
591 EngSetLastError(ERROR_INVALID_PARAMETER);
592 Ret = FALSE;
593 break;
594 }
595 if (pdcattr->dwLayout & LAYOUT_RTL) // Right to Left
596 {
597 SafeResult = AD_CLOCKWISE - ((pdc->dclevel.flPath & DCPATH_CLOCKWISE) != 0);
598 if (dwIn == AD_CLOCKWISE)
599 {
600 pdc->dclevel.flPath &= ~DCPATH_CLOCKWISE;
601 break;
602 }
603 pdc->dclevel.flPath |= DCPATH_CLOCKWISE;
604 }
605 else // Left to Right
606 {
607 SafeResult = ((pdc->dclevel.flPath & DCPATH_CLOCKWISE) != 0) +
608 AD_COUNTERCLOCKWISE;
609 if (dwIn == AD_COUNTERCLOCKWISE)
610 {
611 pdc->dclevel.flPath &= ~DCPATH_CLOCKWISE;
612 break;
613 }
614 pdc->dclevel.flPath |= DCPATH_CLOCKWISE;
615 }
616 break;
617
618 default:
619 EngSetLastError(ERROR_INVALID_PARAMETER);
620 Ret = FALSE;
621 break;
622 }
623
624 if (Ret)
625 {
626 _SEH2_TRY
627 {
628 ProbeForWrite(pdwResult, sizeof(DWORD), 1);
629 *pdwResult = SafeResult;
630 }
631 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
632 {
633 Status = _SEH2_GetExceptionCode();
634 }
635 _SEH2_END;
636
637 if (!NT_SUCCESS(Status))
638 {
639 SetLastNtError(Status);
640 Ret = FALSE;
641 }
642 }
643
644 DC_UnlockDc(pdc);
645 return Ret;
646 }
647
648 DWORD
649 APIENTRY
650 NtGdiGetBoundsRect(
651 IN HDC hdc,
652 OUT LPRECT prc,
653 IN DWORD flags)
654 {
655 DWORD ret;
656 PDC pdc;
657
658 /* Lock the DC */
659 if (!(pdc = DC_LockDc(hdc))) return 0;
660
661 /* Get the return value */
662 ret = pdc->fs & DC_ACCUM_APP ? DCB_ENABLE : DCB_DISABLE;
663 ret |= RECTL_bIsEmptyRect(&pdc->erclBoundsApp) ? DCB_RESET : DCB_SET;
664
665 /* Copy the rect to the caller */
666 _SEH2_TRY
667 {
668 ProbeForWrite(prc, sizeof(RECT), 1);
669 *prc = pdc->erclBoundsApp;
670 }
671 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
672 {
673 ret = 0;
674 }
675 _SEH2_END;
676
677 if (flags & DCB_RESET)
678 {
679 RECTL_vSetEmptyRect(&pdc->erclBoundsApp);
680 }
681
682 DC_UnlockDc(pdc);
683 return ret;
684 }
685
686
687 DWORD
688 APIENTRY
689 NtGdiSetBoundsRect(
690 IN HDC hdc,
691 IN LPRECT prc,
692 IN DWORD flags)
693 {
694 DWORD ret;
695 PDC pdc;
696 RECTL rcl;
697
698 /* Verify arguments */
699 if ((flags & DCB_ENABLE) && (flags & DCB_DISABLE)) return 0;
700
701 /* Lock the DC */
702 if (!(pdc = DC_LockDc(hdc))) return 0;
703
704 /* Get the return value */
705 ret = pdc->fs & DC_ACCUM_APP ? DCB_ENABLE : DCB_DISABLE;
706 ret |= RECTL_bIsEmptyRect(&pdc->erclBoundsApp) ? DCB_RESET : DCB_SET;
707
708 if (flags & DCB_RESET)
709 {
710 RECTL_vSetEmptyRect(&pdc->erclBoundsApp);
711 }
712
713 if (flags & DCB_ACCUMULATE && prc != NULL)
714 {
715 /* Capture the rect */
716 _SEH2_TRY
717 {
718 ProbeForRead(prc, sizeof(RECT), 1);
719 rcl = *prc;
720 }
721 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
722 {
723 DC_UnlockDc(pdc);
724 _SEH2_YIELD(return 0;)
725 }
726 _SEH2_END;
727
728 RECTL_vMakeWellOrdered(&rcl);
729 RECTL_bUnionRect(&pdc->erclBoundsApp, &pdc->erclBoundsApp, &rcl);
730 }
731
732 if (flags & DCB_ENABLE) pdc->fs |= DC_ACCUM_APP;
733 if (flags & DCB_DISABLE) pdc->fs &= ~DC_ACCUM_APP;
734 DC_UnlockDc(pdc);
735 return ret;
736 }
737
738 /* Translates a COLORREF to the right color in the specified DC color space */
739 ULONG
740 TranslateCOLORREF(PDC pdc, COLORREF crColor)
741 {
742 PSURFACE psurfDC;
743 PPALETTE ppalDC;
744 ULONG index, ulColor, iBitmapFormat;
745 EXLATEOBJ exlo;
746
747 /* Get the DC surface */
748 psurfDC = pdc->dclevel.pSurface;
749
750 /* If no surface is selected, use the default bitmap */
751 if (!psurfDC)
752 psurfDC = psurfDefaultBitmap;
753
754 /* Check what color type this is */
755 switch (crColor >> 24)
756 {
757 case 0x00: /* RGB color */
758 break;
759
760 case 0x01: /* PALETTEINDEX */
761 index = crColor & 0xFFFFFF;
762 ppalDC = pdc->dclevel.ppal;
763 if (index >= ppalDC->NumColors) index = 0;
764
765 /* Get the RGB value */
766 crColor = PALETTE_ulGetRGBColorFromIndex(ppalDC, index);
767 break;
768
769 case 0x02: /* PALETTERGB */
770
771 if (pdc->dclevel.hpal != StockObjects[DEFAULT_PALETTE])
772 {
773 /* First find the nearest index in the dc palette */
774 ppalDC = pdc->dclevel.ppal;
775 index = PALETTE_ulGetNearestIndex(ppalDC, crColor & 0xFFFFFF);
776
777 /* Get the RGB value */
778 crColor = PALETTE_ulGetRGBColorFromIndex(ppalDC, index);
779 }
780 else
781 {
782 /* Use the pure color */
783 crColor = crColor & 0x00FFFFFF;
784 }
785 break;
786
787 case 0x10: /* DIBINDEX */
788 /* Mask the value to match the target bpp */
789 iBitmapFormat = psurfDC->SurfObj.iBitmapFormat;
790 if (iBitmapFormat == BMF_1BPP) index = crColor & 0x1;
791 else if (iBitmapFormat == BMF_4BPP) index = crColor & 0xf;
792 else if (iBitmapFormat == BMF_8BPP) index = crColor & 0xFF;
793 else if (iBitmapFormat == BMF_16BPP) index = crColor & 0xFFFF;
794 else index = crColor & 0xFFFFFF;
795 return index;
796
797 default:
798 DPRINT("Unsupported color type %u passed\n", crColor >> 24);
799 crColor &= 0xFFFFFF;
800 }
801
802 /* Initialize an XLATEOBJ from RGB to the target surface */
803 EXLATEOBJ_vInitialize(&exlo, &gpalRGB, psurfDC->ppal, 0xFFFFFF, 0, 0);
804
805 /* Translate the color to the target format */
806 ulColor = XLATEOBJ_iXlate(&exlo.xlo, crColor);
807
808 /* Cleanup the XLATEOBJ */
809 EXLATEOBJ_vCleanup(&exlo);
810
811 return ulColor;
812 }
813
814