2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 HCOLORSPACE hStockColorSpace
= NULL
;
30 IntGdiCreateColorSpace(
31 PLOGCOLORSPACEEXW pLogColorSpace
)
36 pCS
= COLORSPACEOBJ_AllocCSWithHandle();
37 hCS
= pCS
->BaseObject
.hHmgr
;
39 pCS
->lcsColorSpace
= pLogColorSpace
->lcsColorSpace
;
40 pCS
->dwFlags
= pLogColorSpace
->dwFlags
;
42 COLORSPACEOBJ_UnlockCS(pCS
);
48 IntGdiDeleteColorSpace(
49 HCOLORSPACE hColorSpace
)
53 if ( hColorSpace
!= hStockColorSpace
)
55 Ret
= COLORSPACEOBJ_FreeCSByHandle(hColorSpace
);
56 if ( !Ret
) SetLastWin32Error(ERROR_INVALID_PARAMETER
);
63 NtGdiCreateColorSpace(
64 IN PLOGCOLORSPACEEXW pLogColorSpace
)
66 LOGCOLORSPACEEXW Safelcs
;
67 NTSTATUS Status
= STATUS_SUCCESS
;
71 ProbeForRead( pLogColorSpace
,
72 sizeof(LOGCOLORSPACEEXW
),
74 RtlCopyMemory(&Safelcs
, pLogColorSpace
, sizeof(LOGCOLORSPACEEXW
));
78 Status
= _SEH_GetExceptionCode();
82 if (!NT_SUCCESS(Status
))
84 SetLastNtError(Status
);
87 return IntGdiCreateColorSpace(&Safelcs
);
92 NtGdiDeleteColorSpace(
93 IN HANDLE hColorSpace
)
95 return IntGdiDeleteColorSpace(hColorSpace
);
100 IntGetDeviceGammaRamp(HDEV hPDev
, PGAMMARAMP Ramp
)
102 PGDIDEVICE pGDev
= (PGDIDEVICE
) hPDev
;
105 if (!(pGDev
->flFlags
& PDEV_DISPLAY
)) return FALSE
;
107 if ((pGDev
->DevInfo
.iDitherFormat
== BMF_8BPP
) ||
108 (pGDev
->DevInfo
.iDitherFormat
== BMF_16BPP
) ||
109 (pGDev
->DevInfo
.iDitherFormat
== BMF_24BPP
) ||
110 (pGDev
->DevInfo
.iDitherFormat
== BMF_32BPP
))
112 if (pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
)
117 // Generate the 256-colors array
118 for(i
=0; i
<256; i
++ )
120 int NewValue
= i
* 256;
121 if (NewValue
> 65535) NewValue
= 65535;
123 Ramp
->Red
[i
] = Ramp
->Green
[i
] = Ramp
->Blue
[i
] = ((WORD
)NewValue
);
133 NtGdiGetDeviceGammaRamp(HDC hDC
,
138 NTSTATUS Status
= STATUS_SUCCESS
;
141 if (!Ramp
) return FALSE
;
146 SetLastWin32Error(ERROR_INVALID_HANDLE
);
150 SafeRamp
= ExAllocatePool(PagedPool
, sizeof(GAMMARAMP
));
154 SetLastWin32Error(STATUS_NO_MEMORY
);
158 Ret
= IntGetDeviceGammaRamp((HDEV
)dc
->pPDev
, SafeRamp
);
160 if (!Ret
) return Ret
;
173 Status
= _SEH_GetExceptionCode();
178 ExFreePool(SafeRamp
);
180 if (!NT_SUCCESS(Status
))
182 SetLastNtError(Status
);
190 NtGdiSetColorSpace(IN HDC hdc
,
191 IN HCOLORSPACE hColorSpace
)
197 pDC
= DC_LockDc(hdc
);
200 SetLastWin32Error(ERROR_INVALID_HANDLE
);
203 pDc_Attr
= pDC
->pDc_Attr
;
204 if(!pDc_Attr
) pDc_Attr
= &pDC
->Dc_Attr
;
206 if (pDc_Attr
->hColorSpace
== hColorSpace
)
212 pCS
= COLORSPACEOBJ_LockCS(hColorSpace
);
215 SetLastWin32Error(ERROR_INVALID_HANDLE
);
219 if (pDC
->DcLevel
.pColorSpace
)
221 GDIOBJ_ShareUnlockObjByPtr((POBJ
) pDC
->DcLevel
.pColorSpace
);
224 pDC
->DcLevel
.pColorSpace
= pCS
;
225 pDc_Attr
->hColorSpace
= hColorSpace
;
227 COLORSPACEOBJ_UnlockCS(pCS
);
234 UpdateDeviceGammaRamp( HDEV hPDev
)
239 PGDIDEVICE pGDev
= (PGDIDEVICE
) hPDev
;
241 if ((pGDev
->DevInfo
.iDitherFormat
== BMF_8BPP
) ||
242 (pGDev
->DevInfo
.iDitherFormat
== BMF_16BPP
) ||
243 (pGDev
->DevInfo
.iDitherFormat
== BMF_24BPP
) ||
244 (pGDev
->DevInfo
.iDitherFormat
== BMF_32BPP
))
246 if (pGDev
->DriverFunctions
.IcmSetDeviceGammaRamp
)
247 return pGDev
->DriverFunctions
.IcmSetDeviceGammaRamp( pGDev
->hPDev
,
251 if ( (pGDev
->DevInfo
.iDitherFormat
!= BMF_8BPP
) ||
252 !(pGDev
->GDIInfo
.flRaster
& RC_PALETTE
)) return FALSE
;
254 if (!(pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
)) return FALSE
;
256 palGDI
= PALETTE_LockPalette(pGDev
->DevInfo
.hpalDefault
);
257 if(!palGDI
) return FALSE
;
258 palPtr
= (PALOBJ
*) palGDI
;
260 if (pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
)
261 palGDI
->Mode
|= PAL_GAMMACORRECTION
;
263 palGDI
->Mode
&= ~PAL_GAMMACORRECTION
;
265 if (!(pGDev
->flFlags
& PDEV_DRIVER_PUNTED_CALL
)) // No punting, we hook
268 // PALOBJ_cGetColors check mode flags and update Gamma Correction.
269 // Set the HDEV to pal and go.
270 palGDI
->hPDev
= hPDev
;
271 Ret
= pGDev
->DriverFunctions
.SetPalette(pGDev
->hPDev
,
277 PALETTE_UnlockPalette(palGDI
);
285 // ICM registry subkey sets internal brightness range, gamma range is 128 or
286 // 256 when icm is init.
287 INT IcmGammaRangeSet
= 128; // <- make it global
291 IntSetDeviceGammaRamp(HDEV hPDev
, PGAMMARAMP Ramp
, BOOL Test
)
293 WORD IcmGR
, i
, R
, G
, B
;
294 BOOL Ret
= FALSE
, TstPeak
;
295 PGDIDEVICE pGDev
= (PGDIDEVICE
) hPDev
;
297 if (!hPDev
) return FALSE
;
299 if (!(pGDev
->flFlags
& PDEV_DISPLAY
)) return FALSE
;
301 if ((pGDev
->DevInfo
.iDitherFormat
== BMF_8BPP
) ||
302 (pGDev
->DevInfo
.iDitherFormat
== BMF_16BPP
) ||
303 (pGDev
->DevInfo
.iDitherFormat
== BMF_24BPP
) ||
304 (pGDev
->DevInfo
.iDitherFormat
== BMF_32BPP
))
306 if (!pGDev
->DriverFunctions
.IcmSetDeviceGammaRamp
)
307 { // No driver support
308 if (!(pGDev
->DevInfo
.flGraphicsCaps2
& GCAPS2_CHANGEGAMMARAMP
))
309 { // Driver does not support Gamma Ramp, so test to see we
310 // have BMF_8BPP only and palette operation support.
311 if ((pGDev
->DevInfo
.iDitherFormat
!= BMF_8BPP
) ||
312 !(pGDev
->GDIInfo
.flRaster
& RC_PALETTE
)) return FALSE
;
316 if (pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
)
317 if (RtlCompareMemory( pGDev
->pvGammaRamp
, Ramp
, sizeof(GAMMARAMP
)) ==
318 sizeof(GAMMARAMP
)) return TRUE
;
319 // Verify Ramp is inside range.
320 IcmGR
= -IcmGammaRangeSet
;
321 TstPeak
= (Test
== FALSE
);
322 for (i
= 0; i
< 256; i
++)
324 R
= Ramp
->Red
[i
] / 256;
325 G
= Ramp
->Green
[i
] / 256;
326 B
= Ramp
->Blue
[i
] / 256;
329 if ( R
<= IcmGammaRangeSet
+ i
)
332 (G
<= IcmGammaRangeSet
+ i
) &&
334 (B
<= IcmGammaRangeSet
+ i
) ) continue;
337 if (Test
) return Ret
; // Don't set and return.
338 // No test override, check max range
341 if ( R
!= (IcmGR
* 256) ||
342 G
!= (IcmGR
* 256) ||
343 B
!= (IcmGR
* 256) ) TstPeak
= FALSE
; // W/i range.
346 // ReactOS allocates a ramp even if it is 8BPP and Palette only.
347 // This way we have a record of the change in memory.
348 if (!pGDev
->pvGammaRamp
&& !(pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
))
349 { // If the above is true and we have nothing allocated, create it.
350 pGDev
->pvGammaRamp
= ExAllocatePoolWithTag(PagedPool
, sizeof(GAMMARAMP
), TAG_GDIICM
);
351 pGDev
->flFlags
|= PDEV_GAMMARAMP_TABLE
;
353 RtlCopyMemory( pGDev
->pvGammaRamp
, Ramp
, sizeof(GAMMARAMP
));
355 Ret
= UpdateDeviceGammaRamp(hPDev
);
365 NtGdiSetDeviceGammaRamp(HDC hDC
,
370 NTSTATUS Status
= STATUS_SUCCESS
;
372 if (!Ramp
) return FALSE
;
377 SetLastWin32Error(ERROR_INVALID_HANDLE
);
381 SafeRamp
= ExAllocatePool(PagedPool
, sizeof(GAMMARAMP
));
385 SetLastWin32Error(STATUS_NO_MEMORY
);
393 RtlCopyMemory( SafeRamp
,
399 Status
= _SEH_GetExceptionCode();
403 if (!NT_SUCCESS(Status
))
406 ExFreePool(SafeRamp
);
407 SetLastNtError(Status
);
411 Ret
= IntSetDeviceGammaRamp((HDEV
)dc
->pPDev
, SafeRamp
, TRUE
);
413 ExFreePool(SafeRamp
);
419 NtGdiSetIcmMode(HDC hDC
,
421 ULONG EnableICM
) // ulMode
423 /* FIXME: this should be coded someday */
424 if (EnableICM
== ICM_OFF
)
428 if (EnableICM
== ICM_ON
)
432 if (EnableICM
== ICM_QUERY
)