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.
28 NtGdiColorMatchToTarget(HDC hDC
,
38 NtGdiCreateColorSpace(
39 IN PLOGCOLORSPACEEXW pLogColorSpace
)
47 NtGdiDeleteColorSpace(
48 IN HANDLE hColorSpace
)
56 NtGdiEnumICMProfiles(HDC hDC
,
61 * FIXME - build list of file names into lpstrBuffer.
62 * (MULTI-SZ would probably be best format)
63 * return (needed) length of buffer in bytes
71 NtGdiGetColorSpace(HDC hDC
)
73 /* FIXME: Need to to whatever GetColorSpace actually does */
79 IntGetDeviceGammaRamp(HDEV hPDev
, PGAMMARAMP Ramp
)
81 PGDIDEVICE pGDev
= (PGDIDEVICE
) hPDev
;
84 if (!(pGDev
->flFlags
& PDEV_DISPLAY
)) return FALSE
;
86 if ((pGDev
->DevInfo
.iDitherFormat
== BMF_8BPP
) ||
87 (pGDev
->DevInfo
.iDitherFormat
== BMF_16BPP
) ||
88 (pGDev
->DevInfo
.iDitherFormat
== BMF_24BPP
) ||
89 (pGDev
->DevInfo
.iDitherFormat
== BMF_32BPP
))
91 if (pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
)
96 // Generate the 256-colors array
99 int NewValue
= i
* 256;
100 if (NewValue
> 65535) NewValue
= 65535;
102 Ramp
->Red
[i
] = Ramp
->Green
[i
] = Ramp
->Blue
[i
] = ((WORD
)NewValue
);
112 NtGdiGetDeviceGammaRamp(HDC hDC
,
117 NTSTATUS Status
= STATUS_SUCCESS
;
120 if (!Ramp
) return FALSE
;
125 SetLastWin32Error(ERROR_INVALID_HANDLE
);
129 SafeRamp
= ExAllocatePool(PagedPool
, sizeof(GAMMARAMP
));
133 SetLastWin32Error(STATUS_NO_MEMORY
);
137 Ret
= IntGetDeviceGammaRamp((HDEV
)dc
->pPDev
, SafeRamp
);
139 if (!Ret
) return Ret
;
152 Status
= _SEH_GetExceptionCode();
157 ExFreePool(SafeRamp
);
159 if (!NT_SUCCESS(Status
))
161 SetLastNtError(Status
);
169 NtGdiGetICMProfile(HDC hDC
,
179 NtGdiGetLogColorSpace(HCOLORSPACE hColorSpace
,
180 LPLOGCOLORSPACEW Buffer
,
189 NtGdiSetColorSpace(IN HDC hdc
,
190 IN HCOLORSPACE hColorSpace
)
198 UpdateDeviceGammaRamp( HDEV hPDev
)
203 PGDIDEVICE pGDev
= (PGDIDEVICE
) hPDev
;
205 if ((pGDev
->DevInfo
.iDitherFormat
== BMF_8BPP
) ||
206 (pGDev
->DevInfo
.iDitherFormat
== BMF_16BPP
) ||
207 (pGDev
->DevInfo
.iDitherFormat
== BMF_24BPP
) ||
208 (pGDev
->DevInfo
.iDitherFormat
== BMF_32BPP
))
210 if (pGDev
->DriverFunctions
.IcmSetDeviceGammaRamp
)
211 return pGDev
->DriverFunctions
.IcmSetDeviceGammaRamp( pGDev
->PDev
,
215 if ( (pGDev
->DevInfo
.iDitherFormat
!= BMF_8BPP
) ||
216 !(pGDev
->GDIInfo
.flRaster
& RC_PALETTE
)) return FALSE
;
218 if (!(pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
)) return FALSE
;
220 palGDI
= PALETTE_LockPalette(pGDev
->DevInfo
.hpalDefault
);
221 if(!palGDI
) return FALSE
;
222 palPtr
= (PALOBJ
*) palGDI
;
224 if (pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
)
225 palGDI
->Mode
|= PAL_GAMMACORRECTION
;
227 palGDI
->Mode
&= ~PAL_GAMMACORRECTION
;
229 if (!(pGDev
->flFlags
& PDEV_DRIVER_PUNTED_CALL
)) // No punting, we hook
232 // PALOBJ_cGetColors check mode flags and update Gamma Correction.
233 // Set the HDEV to pal and go.
234 palGDI
->hPDev
= hPDev
;
235 Ret
= pGDev
->DriverFunctions
.SetPalette(pGDev
->PDev
,
241 PALETTE_UnlockPalette(palGDI
);
249 // ICM registry subkey sets internal brightness range, gamma range is 128 or
250 // 256 when icm is init.
251 INT IcmGammaRangeSet
= 128; // <- make it global
255 IntSetDeviceGammaRamp(HDEV hPDev
, PGAMMARAMP Ramp
, BOOL Test
)
257 WORD IcmGR
, i
, R
, G
, B
;
258 BOOL Ret
= FALSE
, TstPeak
;
259 PGDIDEVICE pGDev
= (PGDIDEVICE
) hPDev
;
261 if (!hPDev
) return FALSE
;
263 if (!(pGDev
->flFlags
& PDEV_DISPLAY
)) return FALSE
;
265 if ((pGDev
->DevInfo
.iDitherFormat
== BMF_8BPP
) ||
266 (pGDev
->DevInfo
.iDitherFormat
== BMF_16BPP
) ||
267 (pGDev
->DevInfo
.iDitherFormat
== BMF_24BPP
) ||
268 (pGDev
->DevInfo
.iDitherFormat
== BMF_32BPP
))
270 if (!pGDev
->DriverFunctions
.IcmSetDeviceGammaRamp
)
271 { // No driver support
272 if (!(pGDev
->DevInfo
.flGraphicsCaps2
& GCAPS2_CHANGEGAMMARAMP
))
273 { // Driver does not support Gamma Ramp, so test to see we
274 // have BMF_8BPP only and palette operation support.
275 if ((pGDev
->DevInfo
.iDitherFormat
!= BMF_8BPP
) ||
276 !(pGDev
->GDIInfo
.flRaster
& RC_PALETTE
)) return FALSE
;
280 if (pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
)
281 if (RtlCompareMemory( pGDev
->pvGammaRamp
, Ramp
, sizeof(GAMMARAMP
)) ==
282 sizeof(GAMMARAMP
)) return TRUE
;
283 // Verify Ramp is inside range.
284 IcmGR
= -IcmGammaRangeSet
;
285 TstPeak
= (Test
== FALSE
);
286 for (i
= 0; i
< 256; i
++)
288 R
= Ramp
->Red
[i
] / 256;
289 G
= Ramp
->Green
[i
] / 256;
290 B
= Ramp
->Blue
[i
] / 256;
293 if ( R
<= IcmGammaRangeSet
+ i
)
296 (G
<= IcmGammaRangeSet
+ i
) &&
298 (B
<= IcmGammaRangeSet
+ i
) ) continue;
301 if (Test
) return Ret
; // Don't set and return.
302 // No test override, check max range
305 if ( R
!= (IcmGR
* 256) ||
306 G
!= (IcmGR
* 256) ||
307 B
!= (IcmGR
* 256) ) TstPeak
= FALSE
; // W/i range.
310 // ReactOS allocates a ramp even if it is 8BPP and Palette only.
311 // This way we have a record of the change in memory.
312 if (!pGDev
->pvGammaRamp
&& !(pGDev
->flFlags
& PDEV_GAMMARAMP_TABLE
))
313 { // If the above is true and we have nothing allocated, create it.
314 pGDev
->pvGammaRamp
= ExAllocatePoolWithTag(PagedPool
, sizeof(GAMMARAMP
), TAG_GDIICM
);
315 pGDev
->flFlags
|= PDEV_GAMMARAMP_TABLE
;
317 RtlCopyMemory( pGDev
->pvGammaRamp
, Ramp
, sizeof(GAMMARAMP
));
319 Ret
= UpdateDeviceGammaRamp(hPDev
);
329 NtGdiSetDeviceGammaRamp(HDC hDC
,
334 NTSTATUS Status
= STATUS_SUCCESS
;
336 if (!Ramp
) return FALSE
;
341 SetLastWin32Error(ERROR_INVALID_HANDLE
);
345 SafeRamp
= ExAllocatePool(PagedPool
, sizeof(GAMMARAMP
));
349 SetLastWin32Error(STATUS_NO_MEMORY
);
357 RtlCopyMemory( SafeRamp
,
363 Status
= _SEH_GetExceptionCode();
367 if (!NT_SUCCESS(Status
))
370 ExFreePool(SafeRamp
);
371 SetLastNtError(Status
);
375 Ret
= IntSetDeviceGammaRamp((HDEV
)dc
->pPDev
, SafeRamp
, TRUE
);
377 ExFreePool(SafeRamp
);
383 NtGdiSetIcmMode(HDC hDC
,
385 ULONG EnableICM
) // ulMode
387 /* FIXME: this should be coded someday */
388 if (EnableICM
== ICM_OFF
)
392 if (EnableICM
== ICM_ON
)
396 if (EnableICM
== ICM_QUERY
)
406 NtGdiSetICMProfile(HDC hDC
,
415 NtGdiUpdateICMRegKey(DWORD Reserved
,