Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * MSCMS - Color Management System for Wine |
| 3 | * |
Hans Leidekker | a5e361e | 2005-02-21 18:38:15 +0000 | [diff] [blame^] | 4 | * Copyright 2004, 2005 Hans Leidekker |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 23 | #include "wine/port.h" |
| 24 | #include "wine/debug.h" |
| 25 | #include "wine/library.h" |
| 26 | |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 27 | #include <stdarg.h> |
| 28 | |
| 29 | #include "windef.h" |
| 30 | #include "winbase.h" |
| 31 | #include "wingdi.h" |
Francois Gouget | b2e8b36 | 2004-10-22 19:56:51 +0000 | [diff] [blame] | 32 | #include "winuser.h" |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 33 | #include "icm.h" |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 34 | |
| 35 | #define LCMS_API_NO_REDEFINE |
| 36 | #define LCMS_API_FUNCTION(f) typeof(f) * p##f; |
| 37 | #include "lcms_api.h" |
| 38 | #undef LCMS_API_FUNCTION |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 39 | |
| 40 | WINE_DEFAULT_DEBUG_CHANNEL(mscms); |
| 41 | |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 42 | #ifdef HAVE_LCMS_H |
| 43 | #ifndef SONAME_LIBLCMS |
| 44 | #define SONAME_LIBLCMS "liblcms.so" |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 45 | #endif |
| 46 | |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 47 | static void *lcmshandle = NULL; |
| 48 | #endif /* HAVE_LCMS_H */ |
| 49 | |
| 50 | static BOOL MSCMS_init_lcms() |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 51 | { |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 52 | #ifdef HAVE_LCMS_H |
| 53 | /* dynamically load lcms if not yet loaded */ |
| 54 | if (!lcmshandle) |
| 55 | { |
| 56 | lcmshandle = wine_dlopen( SONAME_LIBLCMS, RTLD_NOW, NULL, 0 ); |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 57 | |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 58 | /* We can't really do anything useful without liblcms */ |
| 59 | if (!lcmshandle) |
| 60 | { |
| 61 | WINE_MESSAGE( |
| 62 | "Wine cannot find the LittleCMS library. To enable Wine to use color\n" |
| 63 | "management functions please install a version of LittleCMS greater\n" |
| 64 | "than or equal to 1.13.\n" |
| 65 | "http://www.littlecms.com\n" ); |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 66 | |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 67 | return FALSE; |
| 68 | } |
| 69 | } |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 70 | |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 71 | #define LOAD_FUNCPTR(f) \ |
| 72 | if ((p##f = wine_dlsym( lcmshandle, #f, NULL, 0 )) == NULL) \ |
| 73 | goto sym_not_found; |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 74 | |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 75 | LOAD_FUNCPTR(cmsCloseProfile); |
Hans Leidekker | a5e361e | 2005-02-21 18:38:15 +0000 | [diff] [blame^] | 76 | LOAD_FUNCPTR(cmsCreate_sRGBProfile); |
| 77 | LOAD_FUNCPTR(cmsCreateMultiprofileTransform); |
| 78 | LOAD_FUNCPTR(cmsCreateTransform); |
| 79 | LOAD_FUNCPTR(cmsDeleteTransform); |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 80 | LOAD_FUNCPTR(cmsOpenProfileFromMem); |
| 81 | #undef LOAD_FUNCPTR |
| 82 | |
| 83 | return TRUE; |
| 84 | |
| 85 | sym_not_found: |
| 86 | WINE_MESSAGE( |
| 87 | "Wine cannot find certain functions that it needs inside the LittleCMS\n" |
| 88 | "library. To enable Wine to use LittleCMS for color management please\n" |
| 89 | "upgrade liblcms to at least version 1.13.\n" |
| 90 | "http://www.littlecms.com\n" ); |
| 91 | |
| 92 | wine_dlclose( lcmshandle, NULL, 0 ); |
| 93 | lcmshandle = NULL; |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 94 | |
| 95 | return FALSE; |
Hans Leidekker | 081b250 | 2004-10-07 19:12:41 +0000 | [diff] [blame] | 96 | |
| 97 | #endif /* HAVE_LCMS_H */ |
| 98 | WINE_MESSAGE( |
| 99 | "This version of Wine was compiled without support for color management\n" |
| 100 | "functions. This means many color functions are empty stubs and you should\n" |
| 101 | "expect your application to fail. To enable Wine to use LittleCMS for color\n" |
| 102 | "management please install a liblcms development package version 1.13 or\n" |
| 103 | "higher and rebuild Wine.\n" |
| 104 | "http://www.littlecms.com\n" ); |
| 105 | |
| 106 | return TRUE; |
| 107 | } |
| 108 | |
| 109 | static void MSCMS_deinit_lcms() |
| 110 | { |
| 111 | #ifdef HAVE_LCMS_H |
| 112 | if (lcmshandle) |
| 113 | { |
| 114 | wine_dlclose( lcmshandle, NULL, 0 ); |
| 115 | lcmshandle = NULL; |
| 116 | } |
| 117 | #endif /* HAVE_LCMS_H */ |
| 118 | } |
| 119 | |
| 120 | BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved ) |
| 121 | { |
| 122 | TRACE( "(%p, 0x%08lx, %p)\n", hinst, reason, reserved ); |
| 123 | |
| 124 | switch (reason) |
| 125 | { |
| 126 | case DLL_PROCESS_ATTACH: |
| 127 | return MSCMS_init_lcms(); |
| 128 | |
| 129 | case DLL_PROCESS_DETACH: |
| 130 | MSCMS_deinit_lcms(); |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | return TRUE; |
Hans Leidekker | 5164757 | 2004-09-22 04:08:38 +0000 | [diff] [blame] | 135 | } |