Implements OleLoadPicturePath.
[wine] / dlls / mscms / transform.c
1 /*
2  * MSCMS - Color Management System for Wine
3  *
4  * Copyright 2005 Hans Leidekker
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 #include "wine/debug.h"
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "icm.h"
32
33 #define LCMS_API_FUNCTION(f) extern typeof(f) * p##f;
34 #include "lcms_api.h"
35 #undef LCMS_API_FUNCTION
36
37 WINE_DEFAULT_DEBUG_CHANNEL(mscms);
38
39 HTRANSFORM WINAPI CreateColorTransformA( LPLOGCOLORSPACEA space, HPROFILE dest,
40     HPROFILE target, DWORD flags )
41 {
42     LOGCOLORSPACEW spaceW;
43     DWORD len;
44
45     TRACE( "( %p, %p, %p, 0x%08lx )\n", space, dest, target, flags );
46
47     if (!space || !dest) return FALSE;
48
49     memcpy( &spaceW, space, FIELD_OFFSET(LOGCOLORSPACEA, lcsFilename) );
50     spaceW.lcsSize = sizeof(LOGCOLORSPACEW);
51
52     len = MultiByteToWideChar( CP_ACP, 0, space->lcsFilename, -1, NULL, 0 );
53     MultiByteToWideChar( CP_ACP, 0, space->lcsFilename, -1, spaceW.lcsFilename, len );
54
55     return CreateColorTransformW( &spaceW, dest, target, flags );
56 }
57
58 HTRANSFORM WINAPI CreateColorTransformW( LPLOGCOLORSPACEW space, HPROFILE dest,
59     HPROFILE target, DWORD flags )
60 {
61     HTRANSFORM ret = NULL;
62 #ifdef HAVE_LCMS_H
63     cmsHTRANSFORM cmstransform;
64     cmsHPROFILE cmsprofiles[3];
65
66     TRACE( "( %p, %p, %p, 0x%08lx )\n", space, dest, target, flags );
67
68     if (!space || !dest) return FALSE;
69
70     cmsprofiles[0] = cmsCreate_sRGBProfile(); /* FIXME: create from supplied color space */
71     cmsprofiles[1] = MSCMS_hprofile2cmsprofile( dest ); 
72
73     if (target)
74     {
75         cmsprofiles[2] = MSCMS_hprofile2cmsprofile( target );
76         cmstransform = cmsCreateMultiprofileTransform( cmsprofiles, 3, TYPE_BGR_8,
77                                                        TYPE_BGR_8, space->lcsIntent, 0 );
78     }
79     else
80     {
81         cmstransform = cmsCreateTransform( cmsprofiles[0], TYPE_BGR_8, cmsprofiles[1],
82                                            TYPE_BGR_8, space->lcsIntent, 0 );
83     }
84
85     ret = MSCMS_create_htransform_handle( cmstransform );
86
87 #endif /* HAVE_LCMS_H */
88     return ret;
89 }
90
91 HTRANSFORM WINAPI CreateMultiProfileTransform( PHPROFILE profiles, DWORD nprofiles,
92     PDWORD intents, DWORD nintents, DWORD flags, DWORD cmm )
93 {
94     HTRANSFORM ret = NULL;
95 #ifdef HAVE_LCMS_H
96     cmsHPROFILE *cmsprofiles;
97     cmsHTRANSFORM cmstransform;
98     DWORD i;
99
100     TRACE( "( %p, 0x%08lx, %p, 0x%08lx, 0x%08lx, 0x%08lx ) stub\n",
101            profiles, nprofiles, intents, nintents, flags, cmm );
102
103     if (!profiles || !intents) return NULL;
104
105     cmsprofiles = HeapAlloc( GetProcessHeap(), 0, nprofiles * sizeof(cmsHPROFILE) );
106
107     if (cmsprofiles)
108     {
109         for (i = 0; i < nprofiles; i++)
110             cmsprofiles[i] = MSCMS_hprofile2cmsprofile( profiles[i] );
111     }
112
113     cmstransform = cmsCreateMultiprofileTransform( cmsprofiles, nprofiles, TYPE_BGR_8,
114                                                    TYPE_BGR_8, *intents, 0 );
115     HeapFree( GetProcessHeap(), 0, cmsprofiles );
116     ret = MSCMS_create_htransform_handle( cmstransform );
117
118 #endif /* HAVE_LCMS_H */
119     return ret;
120 }
121
122 BOOL WINAPI DeleteColorTransform( HTRANSFORM transform )
123 {
124     BOOL ret = FALSE;
125 #ifdef HAVE_LCMS_H
126     cmsHTRANSFORM cmstransform;
127
128     TRACE( "( %p )\n", transform );
129
130     cmstransform = MSCMS_htransform2cmstransform( transform );
131     cmsDeleteTransform( cmstransform );
132
133     MSCMS_destroy_htransform_handle( transform );
134     ret = TRUE;
135
136 #endif /* HAVE_LCMS_H */
137     return ret;
138 }