<div dir="ltr"><div dir="ltr"><div>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<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
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.<br></div><div> I print with code like this:</div><div><br></div><div>
<div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(204,204,204)"><br></span></div><div><span style="color:rgb(204,204,204)"><br></span></div><div><span style="color:rgb(204,204,204)"><br></span></div><div>
<div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.ICMMethod </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DMICMMETHOD_DEVICE</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># have device do color management </span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.ICMIntent </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DMICM_SATURATE</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.Fields </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.Fields </span><span style="color:rgb(212,212,212)">|</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_PAPERSIZE</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">|</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_ORIENTATION</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.Fields </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.Fields </span><span style="color:rgb(212,212,212)">|</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_PRINTQUALITY</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">|</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_MEDIATYPE</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">|</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_YRESOLUTION</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(106,153,85)"># | win32con.DMPAPER_USER</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.Fields </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.Fields </span><span style="color:rgb(212,212,212)">|</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_ICMMETHOD</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.Fields </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">.Fields </span><span style="color:rgb(212,212,212)">|</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_ICMINTENT</span></div><div><span style="color:rgb(204,204,204)"></span></div></div>
and later:
<div style="color:rgb(204,204,204);background-color:rgb(31,31,31);font-family:Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">result</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32print</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">DocumentProperties</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(86,156,214)">None</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">handle</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">device_name</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(156,220,254)">devmode</span><span style="color:rgb(204,204,204)">, </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_IN_PROMPT</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">|</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_IN_BUFFER</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">|</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">win32con</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">DM_OUT_BUFFER</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"></span></div></div>
and later:
<span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">self</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">hDC</span><span style="color:rgb(204,204,204)">.StartDoc (</span><span style="color:rgb(206,145,120)">'my doc'</span><span style="color:rgb(204,204,204)">)</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">self</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">hDC</span><span style="color:rgb(204,204,204)">.StartPage ()</span></div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">dib</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(212,212,212)">=</span><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(78,201,176)">ImageWin</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(78,201,176)">Dib</span><span style="color:rgb(204,204,204)"> (</span><span style="color:rgb(156,220,254)">image</span><span style="color:rgb(204,204,204)">)</span><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">dib</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(220,220,170)">expose</span><span style="color:rgb(204,204,204)">(</span><span style="color:rgb(156,220,254)">self</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">hDC</span><span style="color:rgb(204,204,204)">.GetHandleAttrib())</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">self</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">hDC</span><span style="color:rgb(204,204,204)">.EndPage ()</span></div><div><span style="color:rgb(204,204,204)"> </span><span style="color:rgb(156,220,254)">self</span><span style="color:rgb(204,204,204)">.</span><span style="color:rgb(156,220,254)">hDC</span><span style="color:rgb(204,204,204)">.EndDoc ()</span></div><div><span style="color:rgb(204,204,204)"></span></div></div>
</div><div><br></div><div>Setting up the devmode structure with ICCMode
and ICCMethod helped to get better printout than a dithered color, but
still the color was wrong.<br>
</div><div><br></div><div>Microsoft <u>Image Color Management</u> (ICM) helps 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 described here:<br></div><div><a href="https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-seticmmode" target="_blank">https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-seticmmode</a></div><div>It
turns color management on or off in a device context, for example, the
printer. More information about routines for color management appears
here:</div><div><a href="https://learn.microsoft.com/en-us/windows/win32/wcs/basic-functions-for-use-within-a-device-context" target="_blank">https://learn.microsoft.com/en-us/windows/win32/wcs/basic-functions-for-use-within-a-device-context</a></div><div><br></div><div>The
problem is there is very little to be found even in other programming
languages about SetICMMode() and nothing for Python win32con.</div><div>Here is a link to a C++ example</div><div><a href="https://cpp.hotexamples.com/site/file?hash=0x9943faca5c529ef258b31b19e70a8cb36341839e74a62560916846e745948643&fullName=wine-master/dlls/gdi32/icm.c&project=r6144/wine" target="_blank">https://cpp.hotexamples.com/site/file?hash=0x9943faca5c529ef258b31b19e70a8cb36341839e74a62560916846e745948643&fullName=wine-master/dlls/gdi32/icm.c&project=r6144/wine</a></div><div><br></div><div>I also grep'ed through the win32 lib files in my Python installation but could not find SetICMMode().<br></div><div><br></div><div>Thank you for any help</div><div>M Lewis<br></div><div><table aria-label="Basic Functions for Use Within a Device Context"><tbody><tr><td><br></td>
<td><br></td></tr></tbody></table></div></div>
</div>