mscms: Null ID can make GetStandardColorSpaceProfile*() succeed.
[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 #include "mscms_priv.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(mscms);
36
37 HTRANSFORM WINAPI CreateColorTransformA( LPLOGCOLORSPACEA space, HPROFILE dest,
38     HPROFILE target, DWORD flags )
39 {
40     LOGCOLORSPACEW spaceW;
41     DWORD len;
42
43     TRACE( "( %p, %p, %p, 0x%08lx )\n", space, dest, target, flags );
44
45     if (!space || !dest) return FALSE;
46
47     memcpy( &spaceW, space, FIELD_OFFSET(LOGCOLORSPACEA, lcsFilename) );
48     spaceW.lcsSize = sizeof(LOGCOLORSPACEW);
49
50     len = MultiByteToWideChar( CP_ACP, 0, space->lcsFilename, -1, NULL, 0 );
51     MultiByteToWideChar( CP_ACP, 0, space->lcsFilename, -1, spaceW.lcsFilename, len );
52
53     return CreateColorTransformW( &spaceW, dest, target, flags );
54 }
55
56 HTRANSFORM WINAPI CreateColorTransformW( LPLOGCOLORSPACEW space, HPROFILE dest,
57     HPROFILE target, DWORD flags )
58 {
59     HTRANSFORM ret = NULL;
60 #ifdef HAVE_LCMS
61     cmsHTRANSFORM cmstransform;
62     cmsHPROFILE cmsprofiles[3];
63     int intent;
64
65     TRACE( "( %p, %p, %p, 0x%08lx )\n", space, dest, target, flags );
66
67     if (!space || !dest) return FALSE;
68
69     intent = space->lcsIntent > 3 ? INTENT_PERCEPTUAL : space->lcsIntent;
70
71     cmsprofiles[0] = cmsCreate_sRGBProfile(); /* FIXME: create from supplied color space */
72     cmsprofiles[1] = MSCMS_hprofile2cmsprofile( dest ); 
73
74     if (target)
75     {
76         cmsprofiles[2] = MSCMS_hprofile2cmsprofile( target );
77         cmstransform = cmsCreateMultiprofileTransform( cmsprofiles, 3, TYPE_BGR_8,
78                                                        TYPE_BGR_8, intent, 0 );
79     }
80     else
81     {
82         cmstransform = cmsCreateTransform( cmsprofiles[0], TYPE_BGR_8, cmsprofiles[1],
83                                            TYPE_BGR_8, intent, 0 );
84     }
85     ret = MSCMS_create_htransform_handle( cmstransform );
86
87 #endif /* HAVE_LCMS */
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
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 */
119     return ret;
120 }
121
122 BOOL WINAPI DeleteColorTransform( HTRANSFORM transform )
123 {
124     BOOL ret = FALSE;
125 #ifdef HAVE_LCMS
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 */
137     return ret;
138 }
139
140 BOOL WINAPI TranslateBitmapBits( HTRANSFORM transform, PVOID srcbits, BMFORMAT input,
141     DWORD width, DWORD height, DWORD inputstride, PVOID destbits, BMFORMAT output,
142     DWORD outputstride, PBMCALLBACKFN callback, ULONG data )
143 {
144     BOOL ret = FALSE;
145 #ifdef HAVE_LCMS
146     cmsHTRANSFORM cmstransform;
147
148     TRACE( "( %p, %p, 0x%08x, 0x%08lx, 0x%08lx, 0x%08lx, %p, 0x%08x, 0x%08lx, %p, 0x%08lx )\n",
149            transform, srcbits, input, width, height, inputstride, destbits, output,
150            outputstride, callback, data );
151
152     cmstransform = MSCMS_htransform2cmstransform( transform );
153
154     cmsDoTransform( cmstransform, srcbits, destbits, width * height );
155     ret = TRUE;
156
157 #endif /* HAVE_LCMS */
158     return ret;
159 }