How from Python do I call the win32 GDI function SetICMMode()
m Lewis <[email protected]> Tue, 19 Dec 2023 10:56:19 -0800
| Newsgroups | gmane.comp.python.windows |
|---|---|
| Message-ID | <CADWJgRRxvi8998u_KTcGVXXqEk1vzG9=9hgA-LYfN-7SQ-Esmw@mail.gmail.com> |
--===============8001095038674476171==
Content-Type: multipart/alternative; boundary="000000000000adc6a4060ce16c9b"
--000000000000adc6a4060ce16c9b
Content-Type: text/plain; charset="UTF-8"
How, from Python win32 modules, do I call the GDI function SetICMMode() ? I
can't find which module it is in or which object it is supposed to be part
of, other than it probably should be in wingdi
My Python program uses the Python Pillow package to compose an image, save
it to a PDF file, and then it uses the *win32con, win32ui, win32print*
packages to send the image to the printer. My problem is that when I send
the image to the printer, the colors are different from when I print the
PDF file from a program like Adobe Acrobat, which renders the colors just
as I expect and need. For example, my Green RGB (0,128,0) on the Display,
and the PDF are good, but when printing from python to color is closer to
Yellowish-Olive. Apparently Adobe Acrobat is using Color Management
successfully.
I print with code like this:
devmode.ICMMethod = win32con.DMICMMETHOD_DEVICE # have device do
color management
devmode.ICMIntent = win32con.DMICM_SATURATE
devmode.Fields = devmode.Fields | win32con.DM_PAPERSIZE | win32con.
DM_ORIENTATION
devmode.Fields = devmode.Fields | win32con.DM_PRINTQUALITY |
win32con.DM_MEDIATYPE | win32con.DM_YRESOLUTION # | win32con.DMPAPER_USER
devmode.Fields = devmode.Fields | win32con.DM_ICMMETHOD
devmode.Fields = devmode.Fields | win32con.DM_ICMINTENT
and later:
result = win32print.DocumentProperties(None, handle, device_name,
devmode, devmode, win32con.DM_IN_PROMPT | win32con.DM_IN_BUFFER | win32con.
DM_OUT_BUFFER)
and later: self.hDC.StartDoc ('my doc')
self.hDC.StartPage ()
dib = ImageWin.Dib (image)
dib.expose(self.hDC.GetHandleAttrib())
self.hDC.EndPage ()
self.hDC.EndDoc ()
Setting up the devmode structure with ICCMode and ICCMethod helped to get
better printout than a dithered color, but still the color was wrong.
Microsoft *Image Color Management* (ICM) helps to ensure colors appear on a
printer as close as possible as they do on the display.
The wingdi function *SetICMMode()* is described here:
https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-seticmmode
It turns color management on or off in a device context, for example, the
printer. More information about routines for color management appears here:
https://learn.microsoft.com/en-us/windows/win32/wcs/basic-functions-for-use-within-a-device-context
The problem is there is very little to be found even in other programming
languages about SetICMMode() and nothing for Python win32con.
Here is a link to a C++ example
https://cpp.hotexamples.com/site/file?hash=0x9943faca5c529ef258b31b19e70a8cb36341839e74a62560916846e745948643&fullName=wine-master/dlls/gdi32/icm.c&project=r6144/wine
I also grep'ed through the win32 lib files in my Python installation but
could not find SetICMMode().
Thank you for any help
M Lewis
--000000000000adc6a4060ce16c9b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div dir=3D"ltr"><div>How,
from Python win32 modules, do I call the GDI function SetICMMode() ? I can=
't=20
find which module it is in or which object it is supposed to be part of,
other than it probably should be in wingdi<br></div><div><br></div><div>My=
Python program uses the Python Pillow package to compose an image, save it=
to a PDF file, and then it uses
the <b>win32con, win32ui, win32print</b> packages to send the image to=20
the printer. My problem is that when I send the image to the printer,=20
the colors are different from when I print the PDF file from a program=20
like Adobe Acrobat, which renders the colors just as I expect and need. For=
example, my=20
Green RGB (0,128,0) on the Display, and the PDF are good, but when=20
printing from python to color is closer to Yellowish-Olive. Apparently=20
Adobe Acrobat is using Color Management successfully.<br></div><div>=C2=A0I=
print with code like this:</div><div><br></div><div>
<div style=3D"color:rgb(204,204,204);background-color:rgb(31,31,31);font-fa=
mily:Consolas,"Courier New",monospace;font-weight:normal;font-siz=
e:14px;line-height:19px;white-space:pre-wrap"><div><span style=3D"color:rgb=
(204,204,204)"><br></span></div><div><span style=3D"color:rgb(204,204,204)"=
><br></span></div><div><span style=3D"color:rgb(204,204,204)"><br></span></=
div><div>
<div style=3D"color:rgb(204,204,204);background-color:rgb(31,31,31);font-fa=
mily:Consolas,"Courier New",monospace;font-weight:normal;font-siz=
e:14px;line-height:19px;white-space:pre-wrap"><div><span style=3D"color:rgb=
(204,204,204)"> =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:rgb(156,2=
20,254)">devmode</span><span style=3D"color:rgb(204,204,204)">.ICMMethod </=
span><span style=3D"color:rgb(212,212,212)">=3D</span><span style=3D"color:=
rgb(204,204,204)"> </span><span style=3D"color:rgb(78,201,176)">win32con</s=
pan><span style=3D"color:rgb(204,204,204)">.</span><span style=3D"color:rgb=
(156,220,254)">DMICMMETHOD_DEVICE</span><span style=3D"color:rgb(204,204,20=
4)"> </span><span style=3D"color:rgb(106,153,85)"># have device do color ma=
nagement </span></div><div><span style=3D"color:rgb(204,204,204)">=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:rgb(156,220,254)">devmode<=
/span><span style=3D"color:rgb(204,204,204)">.ICMIntent </span><span style=
=3D"color:rgb(212,212,212)">=3D</span><span style=3D"color:rgb(204,204,204)=
"> </span><span style=3D"color:rgb(78,201,176)">win32con</span><span style=
=3D"color:rgb(204,204,204)">.</span><span style=3D"color:rgb(156,220,254)">=
DMICM_SATURATE</span></div><div><span style=3D"color:rgb(204,204,204)">=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:rgb(156,220,254)">devm=
ode</span><span style=3D"color:rgb(204,204,204)">.Fields </span><span style=
=3D"color:rgb(212,212,212)">=3D</span><span style=3D"color:rgb(204,204,204)=
"> </span><span style=3D"color:rgb(156,220,254)">devmode</span><span style=
=3D"color:rgb(204,204,204)">.Fields </span><span style=3D"color:rgb(212,212=
,212)">|</span><span style=3D"color:rgb(204,204,204)"> </span><span style=
=3D"color:rgb(78,201,176)">win32con</span><span style=3D"color:rgb(204,204,=
204)">.</span><span style=3D"color:rgb(156,220,254)">DM_PAPERSIZE</span><sp=
an style=3D"color:rgb(204,204,204)"> </span><span style=3D"color:rgb(212,21=
2,212)">|</span><span style=3D"color:rgb(204,204,204)"> </span><span style=
=3D"color:rgb(78,201,176)">win32con</span><span style=3D"color:rgb(204,204,=
204)">.</span><span style=3D"color:rgb(156,220,254)">DM_ORIENTATION</span><=
/div><div><span style=3D"color:rgb(204,204,204)">=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 </span><span style=3D"color:rgb(156,220,254)">devmode</span><span style=
=3D"color:rgb(204,204,204)">.Fields </span><span style=3D"color:rgb(212,212=
,212)">=3D</span><span style=3D"color:rgb(204,204,204)"> </span><span style=
=3D"color:rgb(156,220,254)">devmode</span><span style=3D"color:rgb(204,204,=
204)">.Fields </span><span style=3D"color:rgb(212,212,212)">|</span><span s=
tyle=3D"color:rgb(204,204,204)"> </span><span style=3D"color:rgb(78,201,176=
)">win32con</span><span style=3D"color:rgb(204,204,204)">.</span><span styl=
e=3D"color:rgb(156,220,254)">DM_PRINTQUALITY</span><span style=3D"color:rgb=
(204,204,204)"> </span><span style=3D"color:rgb(212,212,212)">|</span><span=
style=3D"color:rgb(204,204,204)"> </span><span style=3D"color:rgb(78,201,1=
76)">win32con</span><span style=3D"color:rgb(204,204,204)">.</span><span st=
yle=3D"color:rgb(156,220,254)">DM_MEDIATYPE</span><span style=3D"color:rgb(=
204,204,204)"> </span><span style=3D"color:rgb(212,212,212)">|</span><span =
style=3D"color:rgb(204,204,204)"> </span><span style=3D"color:rgb(78,201,17=
6)">win32con</span><span style=3D"color:rgb(204,204,204)">.</span><span sty=
le=3D"color:rgb(156,220,254)">DM_YRESOLUTION</span><span style=3D"color:rgb=
(204,204,204)"> </span><span style=3D"color:rgb(106,153,85)"># | win32con.D=
MPAPER_USER</span></div><div><span style=3D"color:rgb(204,204,204)">=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:rgb(156,220,254)">devmode<=
/span><span style=3D"color:rgb(204,204,204)">.Fields </span><span style=3D"=
color:rgb(212,212,212)">=3D</span><span style=3D"color:rgb(204,204,204)"> <=
/span><span style=3D"color:rgb(156,220,254)">devmode</span><span style=3D"c=
olor:rgb(204,204,204)">.Fields </span><span style=3D"color:rgb(212,212,212)=
">|</span><span style=3D"color:rgb(204,204,204)"> </span><span style=3D"col=
or:rgb(78,201,176)">win32con</span><span style=3D"color:rgb(204,204,204)">.=
</span><span style=3D"color:rgb(156,220,254)">DM_ICMMETHOD</span></div><div=
><span style=3D"color:rgb(204,204,204)">=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span>=
<span style=3D"color:rgb(156,220,254)">devmode</span><span style=3D"color:r=
gb(204,204,204)">.Fields </span><span style=3D"color:rgb(212,212,212)">=3D<=
/span><span style=3D"color:rgb(204,204,204)"> </span><span style=3D"color:r=
gb(156,220,254)">devmode</span><span style=3D"color:rgb(204,204,204)">.Fiel=
ds </span><span style=3D"color:rgb(212,212,212)">|</span><span style=3D"col=
or:rgb(204,204,204)"> </span><span style=3D"color:rgb(78,201,176)">win32con=
</span><span style=3D"color:rgb(204,204,204)">.</span><span style=3D"color:=
rgb(156,220,254)">DM_ICMINTENT</span></div><div><span style=3D"color:rgb(20=
4,204,204)"></span></div></div>
and later:
<div style=3D"color:rgb(204,204,204);background-color:rgb(31,31,31);font-fa=
mily:Consolas,"Courier New",monospace;font-weight:normal;font-siz=
e:14px;line-height:19px;white-space:pre-wrap"><div><span style=3D"color:rgb=
(204,204,204)">=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:rgb(=
156,220,254)">result</span><span style=3D"color:rgb(204,204,204)"> </span><=
span style=3D"color:rgb(212,212,212)">=3D</span><span style=3D"color:rgb(20=
4,204,204)"> </span><span style=3D"color:rgb(78,201,176)">win32print</span>=
<span style=3D"color:rgb(204,204,204)">.</span><span style=3D"color:rgb(220=
,220,170)">DocumentProperties</span><span style=3D"color:rgb(204,204,204)">=
(</span><span style=3D"color:rgb(86,156,214)">None</span><span style=3D"col=
or:rgb(204,204,204)">, </span><span style=3D"color:rgb(156,220,254)">handle=
</span><span style=3D"color:rgb(204,204,204)">, </span><span style=3D"color=
:rgb(156,220,254)">device_name</span><span style=3D"color:rgb(204,204,204)"=
>, </span><span style=3D"color:rgb(156,220,254)">devmode</span><span style=
=3D"color:rgb(204,204,204)">, </span><span style=3D"color:rgb(156,220,254)"=
>devmode</span><span style=3D"color:rgb(204,204,204)">, </span><span style=
=3D"color:rgb(78,201,176)">win32con</span><span style=3D"color:rgb(204,204,=
204)">.</span><span style=3D"color:rgb(156,220,254)">DM_IN_PROMPT</span><sp=
an style=3D"color:rgb(204,204,204)"> </span><span style=3D"color:rgb(212,21=
2,212)">|</span><span style=3D"color:rgb(204,204,204)"> </span><span style=
=3D"color:rgb(78,201,176)">win32con</span><span style=3D"color:rgb(204,204,=
204)">.</span><span style=3D"color:rgb(156,220,254)">DM_IN_BUFFER</span><sp=
an style=3D"color:rgb(204,204,204)"> </span><span style=3D"color:rgb(212,21=
2,212)">|</span><span style=3D"color:rgb(204,204,204)"> </span><span style=
=3D"color:rgb(78,201,176)">win32con</span><span style=3D"color:rgb(204,204,=
204)">.</span><span style=3D"color:rgb(156,220,254)">DM_OUT_BUFFER</span><s=
pan style=3D"color:rgb(204,204,204)">)</span></div><div><span style=3D"colo=
r:rgb(204,204,204)"></span></div></div>
and later:
<span style=3D"color:rgb(204,204,204)">=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><=
span style=3D"color:rgb(156,220,254)">self</span><span style=3D"color:rgb(2=
04,204,204)">.</span><span style=3D"color:rgb(156,220,254)">hDC</span><span=
style=3D"color:rgb(204,204,204)">.StartDoc (</span><span style=3D"color:rg=
b(206,145,120)">'my doc'</span><span style=3D"color:rgb(204,204,204=
)">)</span></div><div><span style=3D"color:rgb(204,204,204)">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span><span style=3D"color:rgb(156,220,254)">self</span><spa=
n style=3D"color:rgb(204,204,204)">.</span><span style=3D"color:rgb(156,220=
,254)">hDC</span><span style=3D"color:rgb(204,204,204)">.StartPage ()</span=
></div><span style=3D"color:rgb(204,204,204)">=C2=A0 =C2=A0 =C2=A0 =C2=A0 <=
/span><span style=3D"color:rgb(156,220,254)">dib</span><span style=3D"color=
:rgb(204,204,204)"> </span><span style=3D"color:rgb(212,212,212)">=3D</span=
><span style=3D"color:rgb(204,204,204)"> </span><span style=3D"color:rgb(78=
,201,176)">ImageWin</span><span style=3D"color:rgb(204,204,204)">.</span><s=
pan style=3D"color:rgb(78,201,176)">Dib</span><span style=3D"color:rgb(204,=
204,204)"> (</span><span style=3D"color:rgb(156,220,254)">image</span><span=
style=3D"color:rgb(204,204,204)">)</span><div><span style=3D"color:rgb(204=
,204,204)">=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:rgb(156,=
220,254)">dib</span><span style=3D"color:rgb(204,204,204)">.</span><span st=
yle=3D"color:rgb(220,220,170)">expose</span><span style=3D"color:rgb(204,20=
4,204)">(</span><span style=3D"color:rgb(156,220,254)">self</span><span sty=
le=3D"color:rgb(204,204,204)">.</span><span style=3D"color:rgb(156,220,254)=
">hDC</span><span style=3D"color:rgb(204,204,204)">.GetHandleAttrib())</spa=
n></div><div><span style=3D"color:rgb(204,204,204)">=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 </span><span style=3D"color:rgb(156,220,254)">self</span><span style=
=3D"color:rgb(204,204,204)">.</span><span style=3D"color:rgb(156,220,254)">=
hDC</span><span style=3D"color:rgb(204,204,204)">.EndPage ()</span></div><d=
iv><span style=3D"color:rgb(204,204,204)">=C2=A0 =C2=A0 =C2=A0 =C2=A0 </spa=
n><span style=3D"color:rgb(156,220,254)">self</span><span style=3D"color:rg=
b(204,204,204)">.</span><span style=3D"color:rgb(156,220,254)">hDC</span><s=
pan style=3D"color:rgb(204,204,204)">.EndDoc ()</span></div><div><span styl=
e=3D"color:rgb(204,204,204)"></span></div></div>
</div><div><br></div><div>Setting up the devmode structure with ICCMode=20
and ICCMethod helped to get better printout than a dithered color, but=20
still the color was wrong.<br>
</div><div><br></div><div>Microsoft <u>Image Color Management</u> (ICM) hel=
ps to ensure colors appear on a
printer as close as possible as they do on the display.
</div><div><br></div><div>The wingdi function <b>SetICMMode()</b> is descri=
bed here:<br></div><div><a href=3D"https://learn.microsoft.com/en-us/window=
s/win32/api/wingdi/nf-wingdi-seticmmode" target=3D"_blank">https://learn.mi=
crosoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-seticmmode</a></div><d=
iv>It
turns color management on or off in a device context, for example, the=20
printer. More information about routines for color management appears=20
here:</div><div><a href=3D"https://learn.microsoft.com/en-us/windows/win32/=
wcs/basic-functions-for-use-within-a-device-context" target=3D"_blank">http=
s://learn.microsoft.com/en-us/windows/win32/wcs/basic-functions-for-use-wit=
hin-a-device-context</a></div><div><br></div><div>The
problem is there is very little to be found even in other programming=20
languages about SetICMMode() and nothing for Python win32con.</div><div>Her=
e is a link to a C++ example</div><div><a href=3D"https://cpp.hotexamples.c=
om/site/file?hash=3D0x9943faca5c529ef258b31b19e70a8cb36341839e74a6256091684=
6e745948643&fullName=3Dwine-master/dlls/gdi32/icm.c&project=3Dr6144=
/wine" target=3D"_blank">https://cpp.hotexamples.com/site/file?hash=3D0x994=
3faca5c529ef258b31b19e70a8cb36341839e74a62560916846e745948643&fullName=
=3Dwine-master/dlls/gdi32/icm.c&project=3Dr6144/wine</a></div><div><br>=
</div><div>I also grep'ed through the win32 lib files in my Python inst=
allation but could not find SetICMMode().<br></div><div><br></div><div>Than=
k you for any help</div><div>M Lewis<br></div><div><table aria-label=3D"Bas=
ic Functions for Use Within a Device Context"><tbody><tr><td><br></td>
<td><br></td></tr></tbody></table></div></div>
</div>
--000000000000adc6a4060ce16c9b--
--===============8001095038674476171==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32
--===============8001095038674476171==--