X11 atom for display profile

Lubos Lunak l.lunak at suse.cz
Fri Jun 24 12:36:17 BST 2005


On Friday 24 of June 2005 12:17, Boudewijn Rempt wrote:
> This was discussed on the openicc list and I want Krita to support it.
> Basically, there's an X11 atom (whatever that my be) that you use in some
> way that's not clear to me to get a chunk of data that we can feed to lcms.
> This would be a handy way to set the display profile by default.
>
> The gdk code is like this:
>
> static cmsHPROFILE *
> get_screen_profile (GdkScreen *screen)
> {
>        Display *dpy;
>        Atom icc_atom, type;
>        int format;
>        gulong nitems;
>        gulong bytes_after;
>        guchar *str;
>        int result;
>        cmsHPROFILE *profile;
>
>        g_return_val_if_fail (screen != NULL, NULL);
>
>        dpy = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen));
>        icc_atom = gdk_x11_get_xatom_by_name_for_display
> gdk_screen_get_display (screen), "_ICC_PROFILE");
>
>        result = XGetWindowProperty (dpy, GDK_WINDOW_XID
> 				    (gdk_screen_get_root_window (screen)),
>                                     icc_atom, 0, G_MAXLONG,
>                                     False, XA_CARDINAL, &type, &format,
> 				    &nitems,
>                                     &bytes_after, (guchar **)&str);
>
>        if (nitems) {
>                profile = cmsOpenProfileFromMem(str, nitems);
>                XFree (str);
>                return profile;
>        } else {
>                g_printerr("No profile, not correcting\n");
>                return NULL;
>        }
> }
>
> I can translate most of this without problems, I don't know what the right
> (Qt) way for getting the atom and the screen.

 There's no Qt way, you need to simply use Xlib directly.

static cmsHPROFILE *
get_screen_profile (int screen)
{
       Display *dpy;
       Atom icc_atom, type;
       int format;
       long nitems;
       long bytes_after;
       unsigned char *str;
       int result;
       cmsHPROFILE *profile = NULL;

       static Atom icc_atom = XInternAtom( qt_xdisplay(), "_ICC_PROFILE", 
False );

       if( XGetWindowProperty ( qt_xdisplay(), qt_xrootwin( screen ), 
icc_atom, 0, INT_MAX, False, XA_CARDINAL, &type, &format, &nitems, 
&bytes_after, (unsigned char **)&str)) {
	if( nitems )
                   profile = cmsOpenProfileFromMem(str, nitems);
               XFree (str);
               return profile;
       } else {
               kdDebug() << "No profile, not correcting" << endl;
               return NULL;
       }
}

 The screen argument is generally just -1. This is written directly in KMail, 
so I hope there are no typos.

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak at suse.cz , l.lunak at kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/




More information about the kde-core-devel mailing list